Skip to content

Commit

Permalink
Implement ping
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner committed Oct 27, 2023
1 parent 735c59d commit 3aca13f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void setup()
pinMode(WIFI_RECEIVE_PIN, INPUT);
pinMode(WIFI_TRANSMIT_PIN, OUTPUT);
wifiSerial.begin(9600);
wifiSerial.listen();

pinMode(SHOW_PIN, INPUT_PULLUP);

Expand All @@ -29,22 +30,17 @@ void setup()
wifiCommandListener.when("set-schedule", (EvtCommandAction)relaySetSchedule);
wifiCommandListener.when("set", (EvtCommandAction)relaySet);
wifiCommandListener.when("ping", (EvtCommandAction)pingReceived);
wifiCommandListener.when("pong", (EvtCommandAction)pongReceived);

mgr.addListener(&bluetoothCommandListener);
mgr.addListener(&wifiCommandListener);
mgr.addListener(&stateMachine);

attachInterrupt(digitalPinToInterrupt(SHOW_PIN), onInterrupt, FALLING);

Serial.println(F("Setup complete. Waiting for wifi..."));

wifiSerial.listen();
while (wifiSerial.available() > 0)
{
Serial.print((char)wifiSerial.read());
}
Serial.println(F("Setup complete. Continuing..."));

Serial.println(F("Wifi is connected"));
wifiSerial.println(F(">ping!"));
}

bool idle()
Expand All @@ -59,6 +55,13 @@ bool idle()
bool pingReceived()
{
Serial.println(F("Ping received!"));
pingLastReceived = millis();
return true;
}

bool pongReceived()
{
Serial.println(F("Pong received!"));
return true;
}

Expand Down Expand Up @@ -104,11 +107,6 @@ bool relaySetSchedule(IEvtListener *, IEvtContext *, long data)

void loop()
{
bluetoothSerial.listen();
mgr.loopIteration();

wifiSerial.listen();

mgr.loopIteration();
}

Expand Down
3 changes: 3 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ SoftwareSerial wifiSerial(WIFI_RECEIVE_PIN, WIFI_TRANSMIT_PIN);
EvtCommandListener bluetoothCommandListener(&bluetoothSerial, 20);
EvtCommandListener wifiCommandListener(&wifiSerial, 20);

unsigned long pingLastReceived = 0;

void onInterrupt();
bool idle();
bool sending();
Expand All @@ -37,5 +39,6 @@ bool relayRequestSync();
bool relaySet(IEvtListener *, IEvtContext *, long data);
bool relaySetSchedule(IEvtListener *, IEvtContext *, long data);
bool pingReceived();
bool pongReceived();

#endif

0 comments on commit 3aca13f

Please sign in to comment.