Skip to content

Commit

Permalink
Request sync
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner committed Oct 22, 2023
1 parent 551f9fc commit 7dc5911
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
6 changes: 3 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ monitor_speed = 115200
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 @@ -33,7 +33,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 @@ -49,7 +49,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
26 changes: 24 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,30 @@ 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 "));
Serial.println(data);
clock.adjust(DateTime(data));
stateMachine.transition(SHOWING);
if (showAfterSet)
{
stateMachine.transition(SHOWING);
}
timeSet = true;
return true;
}

Expand All @@ -70,7 +88,11 @@ bool setSchedule(EvtListener *, EvtContext *, long data)
Serial.print(F("Command: SET SCHEDULE "));
Serial.println(data);
displaySchedule.update(data);
stateMachine.transition(SHOWING);
if (showAfterSet)
{
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;

void onInterrupt();
void render();
Expand All @@ -52,6 +57,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 7dc5911

Please sign in to comment.