diff --git a/src/main.cpp b/src/main.cpp index a6d6db3..535c494 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,9 +4,9 @@ void setup() { Serial.begin(115200); - // pinMode(BT_RECEIVE_PIN, INPUT); - // pinMode(BT_TRANSMIT_PIN, OUTPUT); - // bluetoothSerial.begin(9600); + pinMode(BT_RECEIVE_PIN, INPUT); + pinMode(BT_TRANSMIT_PIN, OUTPUT); + bluetoothSerial.begin(9600); pinMode(WIFI_RECEIVE_PIN, INPUT); pinMode(WIFI_TRANSMIT_PIN, OUTPUT); @@ -28,22 +28,37 @@ void setup() wifiCommandListener.when("set-schedule", (EvtCommandAction)relaySetSchedule); wifiCommandListener.when("set", (EvtCommandAction)relaySet); + wifiCommandListener.when("ping", (EvtCommandAction)pingReceived); - // mgr.addListener(&bluetoothCommandListener); + mgr.addListener(&bluetoothCommandListener); mgr.addListener(&wifiCommandListener); mgr.addListener(&stateMachine); attachInterrupt(digitalPinToInterrupt(SHOW_PIN), onInterrupt, FALLING); - Serial.println(F("Setup complete. Continuing...")); + Serial.println(F("Setup complete. Waiting for wifi...")); + + wifiSerial.listen(); + while (wifiSerial.available() > 0) + { + Serial.print((char)wifiSerial.read()); + } + + Serial.println(F("Wifi is connected")); } bool idle() { - Serial.println(F("Sleeping...")); - Serial.flush(); - LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, - SPI_OFF, USART0_OFF, TWI_OFF); + // Serial.println(F("Sleeping...")); + // Serial.flush(); + // LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, + // SPI_OFF, USART0_OFF, TWI_OFF); + return true; +} + +bool pingReceived() +{ + Serial.println(F("Ping received!")); return true; } @@ -69,9 +84,9 @@ bool relaySet(IEvtListener *, IEvtContext *, long data) { Serial.println(F("Relaying set command...")); - // bluetoothSerial.print(F(">set:")); - // bluetoothSerial.print(data); - // bluetoothSerial.println(F("!")); + bluetoothSerial.print(F(">set:")); + bluetoothSerial.print(data); + bluetoothSerial.println(F("!")); return true; } @@ -80,15 +95,20 @@ bool relaySetSchedule(IEvtListener *, IEvtContext *, long data) { Serial.println(F("Relaying set-schedule command...")); - // bluetoothSerial.print(F(">set-schedule:")); - // bluetoothSerial.print(data); - // bluetoothSerial.println(F("!")); + bluetoothSerial.print(F(">set-schedule:")); + bluetoothSerial.print(data); + bluetoothSerial.println(F("!")); return true; } void loop() { + bluetoothSerial.listen(); + mgr.loopIteration(); + + wifiSerial.listen(); + mgr.loopIteration(); } diff --git a/src/main.h b/src/main.h index bfa4d56..f980727 100644 --- a/src/main.h +++ b/src/main.h @@ -36,5 +36,6 @@ bool sending(); bool relayRequestSync(); bool relaySet(IEvtListener *, IEvtContext *, long data); bool relaySetSchedule(IEvtListener *, IEvtContext *, long data); +bool pingReceived(); #endif \ No newline at end of file