From a7e20234708ef3bc154775ef5aef6be3a8d81783 Mon Sep 17 00:00:00 2001 From: Fisch Date: Thu, 29 Aug 2024 18:03:46 +0200 Subject: [PATCH] changes from camp --- .../achterbahnconfig/achterbahnconfig.pde | 4 +- otaflash.sh | 2 +- platformio.ini | 16 +++++ src/main.cpp | 67 ++++++++++++++++--- src/simpleota.cpp | 2 + src/simpleota.h | 1 + src/wagon.cpp | 4 +- 7 files changed, 83 insertions(+), 13 deletions(-) diff --git a/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde b/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde index c0504b3..edc1820 100644 --- a/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde +++ b/achterbahnconfig/achterbahnconfig/achterbahnconfig.pde @@ -164,9 +164,9 @@ void setup() { .setSize(100, 20); - - myPort = new Serial(this, "/dev/ttyUSB0", 115200); + //myPort = new Serial(this, "COM3", 115200); + myPort = new Serial(this, "/dev/ttyUSB0", 115200); } void Set() { diff --git a/otaflash.sh b/otaflash.sh index 54f51fd..767a181 100644 --- a/otaflash.sh +++ b/otaflash.sh @@ -14,5 +14,5 @@ do printf "%c" "." done printf "\n%s\n" "Device is online" -pio run -t upload --upload-port $1 +pio run -t upload --upload-port $1 -e d1_mini-ota diff --git a/platformio.ini b/platformio.ini index 962e722..8721fe5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,6 +16,22 @@ framework = arduino monitor_speed = 115200 upload_speed = 921600 + +lib_deps = + adafruit/Adafruit NeoPixel @ ^1.7.0 + +[env:d1_mini-ota] +platform = espressif8266 +board = d1_mini +framework = arduino + +monitor_speed = 115200 +upload_speed = 921600 + +upload_protocol = espota + + + lib_deps = adafruit/Adafruit NeoPixel @ ^1.7.0 diff --git a/src/main.cpp b/src/main.cpp index 5153269..aa06b65 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ //flash as Wemos D1 R2 & mini #include -#include "simpleota.h" +//#include "simpleota.h" #include #ifdef __AVR__ @@ -97,6 +97,13 @@ long last_changePersistancemode=0; #define MAXWAGONS 5 //maximum number of wagons +//Wifi + +//int port = 8888; //Port number +//WiFiServer server(port); +//WiFiClient client; +//uint8_t state_server=0; + void setup() { Serial.begin(115200); @@ -114,17 +121,24 @@ void setup() { strip.show(); // Initialize all pixels to 'off' - checkOTA(); + /*checkOTA(); + if(initOTA()) { //initialize ota if ota enabled - return; //if ota do nothing else for setup + Serial.println("OTA Initialized"); + return; } + //server.begin(); + */ + Serial.println("Started"); resetHeightmap(); - //fixed heightmap + loadHeightmapRaw(); + + interpolateHeightValues(); @@ -135,8 +149,6 @@ void setup() { Serial.print(": "); Serial.println(height[i]); }*/ - - @@ -288,7 +300,7 @@ void spawnWagon(){ //Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, side_startpos, _randomlength, side_multi*random(map(_randomlength,3,30,0,40)/10.0, map(_randomlength,3,30, 5,60))/10.0 , 0 , random(3.0,7.0) , Wheel((uint8_t)random(0,255))); //spawn new wagon //Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, side_startpos, _randomlength, side_multi*random(map(_randomlength,3,30,30,100)/10.0, map(_randomlength,3,30, 5,60))/10.0 , 0 , 1.8 , Wheel((uint8_t)random(0,255))); //spawn new wagon - Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, side_startpos, _randomlength, side_multi*random(map(_randomlength,3,30,3,10)/10.0, map(_randomlength,3,30, 1,10))/10.0 , 0 , 1.8 , Wheel((uint8_t)random(0,255))); //spawn new wagon . start from near standstill + Wagon tmpr = Wagon(maxid++,NUMPIXELS,&strip, height, side_startpos, _randomlength, side_multi*random(0,random(10,60))/10.0 , 0 , random(2,5)/10.0 , Wheel((uint8_t)random(0,255))); //spawn new wagon . start from near standstill //Mass: the lighter the faster is changes speed @@ -315,9 +327,47 @@ void spawnWagon(float pos, float wagonlength,float startvel, float startacc, flo void loop() { + //ota deactivated because of problems with exceptions/reboots. also maybe problems with eeprom and ota. + /* if (loopOTA()) { +#ifndef OTA_CONTINUOUS return; //just wait for ota +#endif } + */ + + /* + if (state_server==0) + { + client = server.available(); + + if (client) { + if(client.connected()) + { + Serial.println("Client Connected"); + state_server=1; + } + + } + } + if (state_server==1) { + if(client.connected()){ + while(client.available()>0){ + // read data from the connected client + Serial.write(client.read()); + } + //Send Data to connected client + while(Serial.available()>0) + { + client.write(Serial.read()); + } + }else{ + client.stop(); + Serial.println("Client disconnected"); + state_server=0; + } + } + */ loopmillis=millis(); @@ -684,8 +734,9 @@ void loadHeightmapRaw(){ heightraw[i]=lastvalue; c_eepromaddress++; } - interpolateHeightValues(); } + + void saveHeightmapRaw(){ int c_eepromaddress=EEPROMSTARTADDRESS_HEIGHTMAP; for (int i=0;i 100) { huehott = !huehott; mil = millis(); diff --git a/src/simpleota.h b/src/simpleota.h index af4c52e..a750897 100644 --- a/src/simpleota.h +++ b/src/simpleota.h @@ -13,6 +13,7 @@ #define OTA_WAIT_TIMEOUT 50 // in 0.1s increments -> 10s #define OTA_PASSWORD "ROLLERCOASTER" //password needed for ota flashing +//#define OTA_CONTINUOUS void checkOTA(); diff --git a/src/wagon.cpp b/src/wagon.cpp index e290df4..2fb074f 100644 --- a/src/wagon.cpp +++ b/src/wagon.cpp @@ -2,8 +2,8 @@ #define WAGONLENGTH 3 -#define EDGE_KILL -//#define EDGE_WALL +//#define EDGE_KILL +#define EDGE_WALL //#define EDGE_BOUNCE //#define EDGE_WRAP #define WRAPLEDENDPOS _numpixels //default