-fix button unresponsive issue
-introduce subtle flashing for keepaliev detection
This commit is contained in:
17
src/main.cpp
17
src/main.cpp
@@ -5,12 +5,13 @@
|
|||||||
// GPIOs
|
// GPIOs
|
||||||
#define GPIO_EMERGENCY_LED 5
|
#define GPIO_EMERGENCY_LED 5
|
||||||
#define GPIO_SYNC_LED 19
|
#define GPIO_SYNC_LED 19
|
||||||
|
#define GPIO_REQUESTED_STATE_LED 2
|
||||||
#define GPIO_EMERGENCY_BUTTON 16
|
#define GPIO_EMERGENCY_BUTTON 16
|
||||||
|
|
||||||
// Software Parameters
|
// Software Parameters
|
||||||
#define LOOP_DELAY 1
|
#define LOOP_DELAY 1
|
||||||
#define PING_TIMEOUT_NUM_LOOPS 2
|
#define PING_TIMEOUT_NUM_LOOPS 2
|
||||||
#define EMERGENCY_BUTTON_SCAN_RATE_SECONDS 2
|
#define EMERGENCY_BUTTON_SCAN_RATE_SECONDS 1
|
||||||
|
|
||||||
String macList[2] = {"24:6F:28:B1:EE:74", "24:6F:28:B2:40:8C"};
|
String macList[2] = {"24:6F:28:B1:EE:74", "24:6F:28:B2:40:8C"};
|
||||||
String macLocal,macRemote;
|
String macLocal,macRemote;
|
||||||
@@ -64,6 +65,7 @@ void OnButtonPushed(){
|
|||||||
Serial.println("BUTTON PUSH CALLBACK.");
|
Serial.println("BUTTON PUSH CALLBACK.");
|
||||||
if((getUptimeInSeconds()-lastButtonPushUptimeInSeconds)>EMERGENCY_BUTTON_SCAN_RATE_SECONDS){
|
if((getUptimeInSeconds()-lastButtonPushUptimeInSeconds)>EMERGENCY_BUTTON_SCAN_RATE_SECONDS){
|
||||||
isSenderEmergency=!isSenderEmergency;
|
isSenderEmergency=!isSenderEmergency;
|
||||||
|
digitalWrite(GPIO_REQUESTED_STATE_LED,isSenderEmergency?HIGH:LOW);
|
||||||
lastButtonPushUptimeInSeconds=getUptimeInSeconds();
|
lastButtonPushUptimeInSeconds=getUptimeInSeconds();
|
||||||
Serial.println("BUTTON PUSH EXEC.");
|
Serial.println("BUTTON PUSH EXEC.");
|
||||||
}
|
}
|
||||||
@@ -141,6 +143,9 @@ void setup(){
|
|||||||
esp_now_register_recv_cb(OnDataRecv);
|
esp_now_register_recv_cb(OnDataRecv);
|
||||||
|
|
||||||
pinMode(GPIO_EMERGENCY_LED, OUTPUT);
|
pinMode(GPIO_EMERGENCY_LED, OUTPUT);
|
||||||
|
pinMode(GPIO_REQUESTED_STATE_LED, OUTPUT);
|
||||||
|
|
||||||
|
digitalWrite(GPIO_REQUESTED_STATE_LED,LOW);
|
||||||
digitalWrite(GPIO_EMERGENCY_LED,LOW);
|
digitalWrite(GPIO_EMERGENCY_LED,LOW);
|
||||||
pinMode(GPIO_SYNC_LED,OUTPUT);
|
pinMode(GPIO_SYNC_LED,OUTPUT);
|
||||||
digitalWrite(GPIO_SYNC_LED,LOW);
|
digitalWrite(GPIO_SYNC_LED,LOW);
|
||||||
@@ -159,11 +164,12 @@ void setup(){
|
|||||||
void loop(){
|
void loop(){
|
||||||
// Send message via ESP-NOW
|
// Send message via ESP-NOW
|
||||||
sleep(LOOP_DELAY);
|
sleep(LOOP_DELAY);
|
||||||
|
|
||||||
boolean isButtonPushed = (HIGH== digitalRead(GPIO_EMERGENCY_BUTTON));
|
boolean isButtonPushed = (HIGH== digitalRead(GPIO_EMERGENCY_BUTTON));
|
||||||
Serial.println(isButtonPushed?"PUSHED":"RELEASED");
|
Serial.println(isButtonPushed?"PUSHED":"RELEASED");
|
||||||
|
|
||||||
// only one device has a button, the origin will tell the recipient to revert back the status.
|
// only one device has a button, the origin will tell the recipient to revert back the status.
|
||||||
if (isButtonPushed) {
|
if (isSenderEmergency) {
|
||||||
myData.macOfSender=macLocal;
|
myData.macOfSender=macLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,12 +184,11 @@ void loop(){
|
|||||||
Serial.println(myData.isEmergency?"EMERGENGY ON":"EMERGENCY OFF");
|
Serial.println(myData.isEmergency?"EMERGENGY ON":"EMERGENCY OFF");
|
||||||
Serial.println((isSenderEmergency==1)?"SEN EMERG ON":"SEN EMERG OFF");
|
Serial.println((isSenderEmergency==1)?"SEN EMERG ON":"SEN EMERG OFF");
|
||||||
|
|
||||||
|
digitalWrite(GPIO_SYNC_LED,LOW);
|
||||||
if ((getUptimeInSeconds()-lastPingUptimeInSeconds) < (LOOP_DELAY*PING_TIMEOUT_NUM_LOOPS)) {
|
if ((getUptimeInSeconds()-lastPingUptimeInSeconds) < (LOOP_DELAY*PING_TIMEOUT_NUM_LOOPS)) {
|
||||||
|
delay(3);
|
||||||
digitalWrite(GPIO_SYNC_LED,HIGH);
|
digitalWrite(GPIO_SYNC_LED,HIGH);
|
||||||
} else {
|
}
|
||||||
digitalWrite(GPIO_SYNC_LED,LOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case ESP_OK:
|
case ESP_OK:
|
||||||
|
|||||||
Reference in New Issue
Block a user