diff --git a/flipcontrol_esp32/include/image.h b/flipcontrol_esp32/include/image.h index 915fb79..9b7c24a 100644 --- a/flipcontrol_esp32/include/image.h +++ b/flipcontrol_esp32/include/image.h @@ -29,6 +29,7 @@ private: uint16_t backBuffer[COLUMNS]; bool flag_updating; //when true, display flip is in progress. frontBuffer does not match backBuffer + bool flag_redraw; //when set true, settings for updating are overwritten such that all dots are cleared and set uint8_t update_counter; //used for keeping track of progress for updating @@ -75,6 +76,8 @@ public: void loop_testDots(); void loop_drawClearTest(); + void redraw(); + unsigned long updateDuration; //for statistics and debugging. time it took for one update (max) diff --git a/flipcontrol_esp32/src/image.cpp b/flipcontrol_esp32/src/image.cpp index edb2e29..0119dfd 100644 --- a/flipcontrol_esp32/src/image.cpp +++ b/flipcontrol_esp32/src/image.cpp @@ -830,11 +830,17 @@ void Image::shuffleOrder(uint8_t iterations) { UpdateReturn Image::updateByColumn(bool clearFirst, bool optimizeClear, bool optimizeSet) { /* - clearFirst : if True, go through all columns and clear them (by set order). Then go through same order and set dots. + clearFirst : if True, go through all columns and clear them (by set order). Then go through same order and set dots. If False, clear one column then set it immediately afterwards. optimizeClear : if True, do not clear columns where dots need to be set or no change is happening. if False, clear every column optimizeSet : if True, do not set already set dots again. */ + if (flag_redraw) { + clearFirst=false; + optimizeClear=false; + optimizeSet=false; + } + if (!flag_updating) { return nochange; //finished } @@ -898,6 +904,7 @@ UpdateReturn Image::updateByColumn(bool clearFirst, bool optimizeClear, bool opt if (update_counter/2>=getW()) { //reached last column flag_updating=false; update_counter=0; + flag_redraw=false; return finished; //finished } return updating; //not finished @@ -1038,4 +1045,7 @@ void Image::loop_drawClearTest() { } - +void Image::redraw() { + flag_redraw=true; + flag_updating=true; +} \ No newline at end of file diff --git a/flipcontrol_esp32/src/main.cpp b/flipcontrol_esp32/src/main.cpp index c84292d..a0e7b16 100644 --- a/flipcontrol_esp32/src/main.cpp +++ b/flipcontrol_esp32/src/main.cpp @@ -26,6 +26,7 @@ uint8_t stringToBool(String s); bool presetHandler(const HomieRange& range, const String& value); bool orderHandler(const HomieRange& range, const String& value); bool dataHandler(const HomieRange& range, const String& value); +bool controlHandler(const HomieRange& range, const String& value); bool clearFirstHandler(const HomieRange& range, const String& value); bool optimizeClearHandler(const HomieRange& range, const String& value); @@ -49,6 +50,7 @@ void setup() { flipdotNode.advertise("preset").settable(presetHandler); flipdotNode.advertise("data").settable(dataHandler); flipdotNode.advertise("order").settable(orderHandler); + flipdotNode.advertise("control").settable(controlHandler); settingsNode.advertise("clearfirst").settable(clearFirstHandler); settingsNode.advertise("optimizeclear").settable(optimizeClearHandler); settingsNode.advertise("optimizeset").settable(optimizeSetHandler); @@ -140,13 +142,11 @@ void loop() { } */ - UpdateReturn result=flip.updateByColumn(clearFirst,optimizeClear,optimizeSet); //0=not finished, 1=finished //UpdateReturn result=flip.updateByColumn(true,false,false); //0=not finished, 1=finished <- most simple static UpdateReturn last_result=finished; if (last_result==nochange && result!=last_result) { //was finished but has just started updating again last_change=loopmillis; //display started changing dots. set starting time. - Serial.print("Reset Time to "); Serial.println(last_change); } last_result=result; if (result == finished) //just finished @@ -157,6 +157,7 @@ void loop() { resultNode.setProperty("duration").send((String)duration); resultNode.setProperty("updateduration").send((String)flip.updateDuration); flip.updateDuration=0; //reset + } @@ -312,4 +313,23 @@ uint8_t stringToBool(String s) { return 2; } } - \ No newline at end of file + + + + +bool controlHandler(const HomieRange& range, const String& value) { + Serial.print("Control payload="); Serial.println(value); + if (value == "redraw"){ + flip.redraw(); + }else if(value == "black"){ + flip.setBuffer_solid(0); + flip.redraw(); + }else{ + error="preset \""+value+"\" not found"; + return false; + } + + flipdotNode.setProperty("control").send(value); + + return true; +} \ No newline at end of file