Skip to content

Commit

Permalink
Request sync
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner committed Nov 4, 2023
1 parent 1f2d715 commit d902aff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "));
Expand All @@ -65,6 +79,7 @@ bool set(EvtListener *, EvtContext *, long data)
{
stateMachine.transition(SHOWING);
}
timeSet = true;
return true;
}

Expand All @@ -77,6 +92,7 @@ bool setSchedule(EvtListener *, EvtContext *, long data)
{
stateMachine.transition(SHOWING);
}
scheduleSet = true;
return true;
}

Expand Down
6 changes: 6 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <SoftwareSerial.h>

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;
Expand Down Expand Up @@ -42,8 +44,11 @@ Schedule<byte> colorSchedule(0);
Schedule<Flags> 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;

Expand All @@ -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);
Expand Down

0 comments on commit d902aff

Please sign in to comment.