From 4dc9ef1db7c94c434fb15ec9e5a2e9d0e3abaf0f Mon Sep 17 00:00:00 2001 From: Robin Cerny Date: Wed, 26 Feb 2025 16:50:57 +0100 Subject: [PATCH] refactored and added rumble mode, added 'pit hold by ref' --- ROFLS_Arena_Controller/Input_Handler.ino | 2 +- ROFLS_Arena_Controller/Output_Handler.ino | 6 + .../ROFLS_Arena_Controller.ino | 154 ++++++++++-------- 3 files changed, 91 insertions(+), 71 deletions(-) diff --git a/ROFLS_Arena_Controller/Input_Handler.ino b/ROFLS_Arena_Controller/Input_Handler.ino index 5097ec5..313739a 100644 --- a/ROFLS_Arena_Controller/Input_Handler.ino +++ b/ROFLS_Arena_Controller/Input_Handler.ino @@ -13,7 +13,7 @@ void pollInput (){ buttonSTARTforced = buttonSTART.longPress(); buttonPAUSEvar = buttonPAUSE.singleClick(); buttonPITvar = buttonPIT.singleClick(); - buttonPIThold = buttonPIT.longPress(); + buttonPIThold = buttonPIT.on(); buttonRESETvar = buttonRESET.longPress(); // if (buttonREDTEAM.pushed()) { diff --git a/ROFLS_Arena_Controller/Output_Handler.ino b/ROFLS_Arena_Controller/Output_Handler.ino index bf09416..8247b80 100644 --- a/ROFLS_Arena_Controller/Output_Handler.ino +++ b/ROFLS_Arena_Controller/Output_Handler.ino @@ -12,6 +12,12 @@ void openPIT() { } } +void openPITmanually() { + PITreleased = true; + PITopenTimestamp = millis(); + digitalWrite(PIT_RELEASE_PIN, HIGH); +} + // usage: blink_LED_BlueTeam(); // void blink_LED_BlueTeam(int BLINK_INTERVAL) { // EVERY_N_MILLISECONDS(BLINK_INTERVAL) { diff --git a/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino b/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino index a32f671..a4f29ba 100644 --- a/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino +++ b/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino @@ -49,7 +49,7 @@ bool countdownPAUSED = false; CountDown FightCountDown[1]; // Rumble stopwatch -StopWatch rumbleTIME; +StopWatch rumbleTIME(StopWatch::SECONDS); int CLOCK_LED_BRIGHTNESS = 16; // 64 is okay @@ -166,7 +166,6 @@ void setup() { Serial.begin(115200); // set outputs pinMode(PIT_RELEASE_PIN, OUTPUT); - digitalWrite(PIT_RELEASE_PIN, LOW); // Set device as a Wi-Fi Station @@ -180,7 +179,7 @@ void setup() { //------------------------------------------------------------------------------------ // ESP Now send part: // Once ESPNow is successfully Init, we will register for Send CB to - // get the status of Trasnmitted packet + // get the status of Transmitted packet esp_now_register_send_cb(OnDataSent); // Register peer @@ -216,83 +215,98 @@ void loop() { // deactivate solenoids if needed checkPIT(); - // Normal fight routine - while (!switchRUMBLE.on()) { - // poll all the switch/button inputs - pollInput(); - // deactivate solenoids if needed - checkPIT(); - // start button logic - if (buttonSTARTvar) { - buttonSTARTvar = false; - if (!FightCountDown[0].isRunning() && countdownPAUSED == false) { - if (buttonREDTEAMvar && buttonBLUETEAMvar) { - buttonREDTEAMvar = false; - buttonBLUETEAMvar = false; - FightCountDown[0].start(0,0,countdownTIME,0); - } - } - else { - if (buttonREDTEAMvar && buttonBLUETEAMvar) { - buttonREDTEAMvar = false; - buttonBLUETEAMvar = false; - countdownPAUSED = false; - FightCountDown[0].cont(); - } - } - } - // forced start of countdown - if (buttonSTARTforced) { - buttonSTARTforced = false; - if (!FightCountDown[0].isRunning() && countdownPAUSED == false) { + // start button logic + if (buttonSTARTvar) { + buttonSTARTvar = false; + if (!FightCountDown[0].isRunning() && !rumbleTIME.isRunning() && countdownPAUSED == false) { + if (switchRUMBLE.on()) { + buttonREDTEAMvar = false; + buttonBLUETEAMvar = false; + rumbleTIME.start(); + } else if (buttonREDTEAMvar && buttonBLUETEAMvar && !switchRUMBLE.on()) { buttonREDTEAMvar = false; buttonBLUETEAMvar = false; FightCountDown[0].start(0,0,countdownTIME,0); } - else { + } + else { + if (buttonREDTEAMvar && buttonBLUETEAMvar && !switchRUMBLE.on()) { buttonREDTEAMvar = false; buttonBLUETEAMvar = false; countdownPAUSED = false; FightCountDown[0].cont(); + } else if (switchRUMBLE.on()) { + buttonREDTEAMvar = false; + buttonBLUETEAMvar = false; + countdownPAUSED = false; + rumbleTIME.start(); } } - // pause button logic - if (buttonPAUSEvar) { - buttonPAUSEvar = false; - if (FightCountDown[0].isRunning()) { - countdownPAUSED = true; - FightCountDown[0].stop(); - } - } - // pit button logic - if (buttonPITvar) { - buttonPITvar = false; - openPIT(); - } - // automatic pit release - if (FightCountDown[0].remaining() <= PITreleaseTime && FightCountDown[0].remaining() > 0 && switchPIT.on()) { - openPIT(); - } - // reset button logic - if (buttonRESETvar) { - buttonRESETvar = false; - PITreleased = false; - ESP.restart(); - } - //blink_LED_RedTeam(200); - //blink_LED_BlueTeam(200); - // update the LED Display - sendTimeDisplay((FightCountDown[0].remaining()/60%10), (FightCountDown[0].remaining()%60), 0, XDAS, 0, CLOCK_LED_BRIGHTNESS); } - - - // Rumble fightroutine - while (switchRUMBLE.on()) { - // poll all the switch/button inputs - pollInput(); - // deactivate solenoids if needed - checkPIT(); - // update the LED Display - sendTimeDisplay(12, 34, XDAS, 0, XDAS, CLOCK_LED_BRIGHTNESS); + // forced start of countdown + if (buttonSTARTforced) { + buttonSTARTforced = false; + if (!FightCountDown[0].isRunning() && !rumbleTIME.isRunning() && countdownPAUSED == false) { + buttonREDTEAMvar = false; + buttonBLUETEAMvar = false; + if (!switchRUMBLE.on()) { + FightCountDown[0].start(0,0,countdownTIME,0); + } else if (switchRUMBLE.on()) { + rumbleTIME.start(); + } + } + else { + buttonREDTEAMvar = false; + buttonBLUETEAMvar = false; + countdownPAUSED = false; + if (!switchRUMBLE.on()) { + FightCountDown[0].cont(); + } else if (switchRUMBLE.on()) { + rumbleTIME.start(); + } + } + } + // pause button logic + if (buttonPAUSEvar) { + buttonPAUSEvar = false; + if (FightCountDown[0].isRunning()) { + countdownPAUSED = true; + FightCountDown[0].stop(); + } + if (rumbleTIME.isRunning()) { + countdownPAUSED = true; + rumbleTIME.stop(); + } + } + // pit button logic + if (buttonPITvar) { + buttonPITvar = false; + buttonPIThold = false; + openPITmanually(); + } + // automatic pit release + if (FightCountDown[0].remaining() == PITreleaseTime && switchPIT.on() && buttonPIThold == false) { + openPIT(); + } + if (rumbleTIME.elapsed() == PITreleaseTime && switchPIT.on() && buttonPIThold == false) { + openPIT(); + } + // reset button logic + if (buttonRESETvar) { + buttonRESETvar = false; + PITreleased = false; + ESP.restart(); + } + //blink_LED_RedTeam(200); + //blink_LED_BlueTeam(200); + // update the LED Display + if (!switchRUMBLE.on()) { + if (!FightCountDown[0].isRunning() && countdownPAUSED == false) { + sendTimeDisplay(countdownTIME, 0, 0, XDAS, 0, CLOCK_LED_BRIGHTNESS); + } else { + sendTimeDisplay((FightCountDown[0].remaining()/60%10), (FightCountDown[0].remaining()%60), 0, XDAS, 0, CLOCK_LED_BRIGHTNESS); + } + } else if (switchRUMBLE.on()) { + sendTimeDisplay((rumbleTIME.elapsed()/60%10), (rumbleTIME.elapsed()%60), 0, XDAS, XDAS, CLOCK_LED_BRIGHTNESS); } }