diff --git a/platformio.ini b/platformio.ini index 3267f18..75e9b8a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,7 +24,7 @@ build_flags = lib_deps = fastled/FastLED@^3.4.0 adafruit/RTClib@^1.14.1 - matthewturner/Eventually2@^2.0 + matthewturner/Eventually2@^2.1.0 matthewturner/EventuallyCommand@^0.4.0 matthewturner/EventuallyStateMachine@^0.3.0 featherfly/SoftwareSerial@^1.0 @@ -37,7 +37,7 @@ platform = native lib_deps = fastled/FastLED@^3.4.0 adafruit/RTClib@^1.14.1 - matthewturner/Eventually2@^2.0 + matthewturner/Eventually2@^2.1.0 matthewturner/EventuallyCommand@^0.4.0 matthewturner/EventuallyStateMachine@^0.3.0 featherfly/SoftwareSerial@^1.0 @@ -53,7 +53,7 @@ debug_test = test_schedule lib_deps = fastled/FastLED@^3.4.0 adafruit/RTClib@^1.14.1 - matthewturner/Eventually2@^2.0 + matthewturner/Eventually2@^2.1.0 matthewturner/EventuallyCommand@^0.4.0 matthewturner/EventuallyStateMachine@^0.3.0 featherfly/SoftwareSerial@^1.0 diff --git a/src/main.cpp b/src/main.cpp index cd57c28..0807643 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,6 +56,20 @@ bool show() return true; } +bool requestSync() +{ + if (timeSet && scheduleSet) + { + Serial.println(F("Already synchronized, backing off to main sync schedule...")); + requestSyncListener.setInterval(REQUEST_SYNC_SCHEDULE); + return true; + } + + Serial.println(F("Requesting sync...")); + bluetoothSerial.println(F(">request-sync!")); + return true; +} + bool set(EvtListener *, EvtContext *, long data) { Serial.print(F("Command: SET ")); @@ -65,6 +79,7 @@ bool set(EvtListener *, EvtContext *, long data) { stateMachine.transition(SHOWING); } + timeSet = true; return true; } @@ -77,6 +92,7 @@ bool setSchedule(EvtListener *, EvtContext *, long data) { stateMachine.transition(SHOWING); } + scheduleSet = true; return true; } diff --git a/src/main.h b/src/main.h index 2cbdb2e..60d7337 100644 --- a/src/main.h +++ b/src/main.h @@ -14,6 +14,8 @@ #include const short SHOW_TEMPORARILY_DURATION = 3000; +const int REQUEST_SYNC_INITIAL_SCHEDULE = 1000 * 60; // 1 minute +const int REQUEST_SYNC_SCHEDULE = 1000 * 60 * 60 * 24; // 24 hours const byte DATA_PIN = 3; const byte CLOCK_PIN = 13; @@ -42,8 +44,11 @@ Schedule colorSchedule(0); Schedule displaySchedule(Flags::NONE, 1); SoftwareSerial bluetoothSerial(RECEIVE_PIN, TRANSMIT_PIN); EvtCommandListener commandListener(&bluetoothSerial, 20); +EvtTimeListener requestSyncListener(REQUEST_SYNC_INITIAL_SCHEDULE, true, (EvtAction)requestSync); EvtStateMachineListener stateMachine; bool showAfterSet = false; +bool timeSet = false; +bool scheduleSet = false; bool showAfterSet = false; @@ -53,6 +58,7 @@ bool updating(); bool idle(); bool showing(); bool show(); +bool requestSync(); bool set(EvtListener *, EvtContext *, long data); bool setSchedule(EvtListener *, EvtContext *, long data); bool setOptions(EvtListener *, EvtContext *, long data);