added forced start/continue, combined remote firmware

This commit is contained in:
2025-02-26 06:03:32 +01:00
parent c2bffd7a26
commit 20fe660838
3 changed files with 86 additions and 49 deletions

View File

@@ -9,18 +9,13 @@ void pollInput (){
switchRUMBLE.poll(); switchRUMBLE.poll();
switchPIT.poll(); switchPIT.poll();
if (buttonSTART.pushed()) { buttonSTARTvar = buttonSTART.singleClick();
buttonSTARTvar = true; buttonSTARTforced = buttonSTART.longPress();
} buttonPAUSEvar = buttonPAUSE.singleClick();
if (buttonPAUSE.pushed()) { buttonPITvar = buttonPIT.singleClick();
buttonPAUSEvar = true; buttonPIThold = buttonPIT.longPress();
} buttonRESETvar = buttonRESET.longPress();
if (buttonPIT.pushed()) {
buttonPITvar = true;
}
if (buttonRESET.pushed()) {
buttonRESETvar = true;
}
// if (buttonREDTEAM.pushed()) { // if (buttonREDTEAM.pushed()) {
// buttonREDTEAMvar = true; // buttonREDTEAMvar = true;
// if (ARENA_READY && !REDTEAM_READY) { // if (ARENA_READY && !REDTEAM_READY) {

View File

@@ -18,19 +18,26 @@
#define PIT_RELEASE_PIN 39 #define PIT_RELEASE_PIN 39
// define buttons and switches // define buttons and switches
Switch buttonSTART = Switch(START_BTN_PIN); //
// constructor Switch
// Parameters: byte _pin, byte PinMode = 5, bool polarity = 0, unsigned long debouncePeriod = 50, unsigned long longPressPeriod = 300, unsigned long doubleClickPeriod = 250, unsigned long deglitchPeriod = 10
Switch buttonSTART = Switch(START_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
Switch buttonPAUSE = Switch(PAUSE_BTN_PIN); Switch buttonPAUSE = Switch(PAUSE_BTN_PIN);
Switch buttonPIT = Switch(PIT_BTN_PIN); Switch buttonPIT = Switch(PIT_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
Switch buttonRESET = Switch(RESET_BTN_PIN); Switch buttonRESET = Switch(RESET_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
Switch switchRUMBLE = Switch(RUMBLE_SWITCH_PIN); Switch switchRUMBLE = Switch(RUMBLE_SWITCH_PIN);
Switch switchPIT = Switch(PIT_ENABLE_SWITCH_PIN); Switch switchPIT = Switch(PIT_ENABLE_SWITCH_PIN);
bool buttonSTARTvar = false; bool buttonSTARTvar = false;
bool buttonSTARTforced = false;
bool buttonPAUSEvar = false; bool buttonPAUSEvar = false;
bool buttonPITvar = false; bool buttonPITvar = false;
bool buttonPIThold = false;
bool buttonRESETvar = false; bool buttonRESETvar = false;
bool buttonREDTEAMvar = false; bool buttonREDTEAMvar = false;
bool buttonREDTEAMtapout = false;
bool buttonBLUETEAMvar = false; bool buttonBLUETEAMvar = false;
bool buttonBLUETEAMtapout = false;
unsigned long PITopenTimestamp = 0; unsigned long PITopenTimestamp = 0;
const long PITopenTime = 1000; // activate solenoid for 1000ms const long PITopenTime = 1000; // activate solenoid for 1000ms
bool PITreleased = false; bool PITreleased = false;
@@ -94,12 +101,17 @@ void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
// Structure example to send data // Structure example to send data
// Must match the receiver structure // Must match the receiver structure
typedef struct struct_message_receive { typedef struct struct_message_receive {
int boardID;
bool buttonSTART; bool buttonSTART;
bool buttonSTARTforced;
bool buttonPAUSE; bool buttonPAUSE;
bool buttonPIT; bool buttonPIT;
bool buttonPIThold;
bool buttonRESET; bool buttonRESET;
bool buttonREDTEAM; bool buttonREDTEAM;
bool buttonREDTEAMtapout;
bool buttonBLUETEAM; bool buttonBLUETEAM;
bool buttonBLUETEAMtapout;
} struct_message_receive; } struct_message_receive;
// Create a struct_message called receiveDATA // Create a struct_message called receiveDATA
@@ -108,23 +120,27 @@ struct_message_receive receiveDATA;
// callback function that will be executed when data is received // callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&receiveDATA, incomingData, sizeof(receiveDATA)); memcpy(&receiveDATA, incomingData, sizeof(receiveDATA));
if (receiveDATA.buttonSTART) { // only fill the data to the right vars
buttonSTARTvar = true; switch (receiveDATA.boardID) {
} case 0:
if (receiveDATA.buttonPAUSE) { // referee remote
buttonPAUSEvar = true; buttonSTARTvar = receiveDATA.buttonSTART;
} buttonSTARTforced = receiveDATA.buttonSTARTforced;
if (receiveDATA.buttonPIT) { buttonPAUSEvar = receiveDATA.buttonPAUSE;
buttonPITvar = true; buttonPITvar = receiveDATA.buttonPIT;
} buttonPIThold = receiveDATA.buttonPIThold;
if (receiveDATA.buttonRESET) { buttonRESETvar = receiveDATA.buttonRESET;
buttonRESETvar = true; break;
} case 1:
if (receiveDATA.buttonREDTEAM) { // RED team button
buttonREDTEAMvar = true; buttonREDTEAMvar = receiveDATA.buttonREDTEAM;
} buttonREDTEAMtapout = receiveDATA.buttonREDTEAMtapout;
if (receiveDATA.buttonBLUETEAM) { break;
buttonBLUETEAMvar = true; case 2:
// BLUE team button
buttonBLUETEAMvar = receiveDATA.buttonBLUETEAM;
buttonBLUETEAMtapout = receiveDATA.buttonBLUETEAMtapout;
break;
} }
} }
@@ -138,7 +154,7 @@ void sendTimeDisplay(int MINUTES, int SECONDS, int RED, int GREEN, int BLUE, int
sendClockDATA.sendGREENchannel = GREEN; sendClockDATA.sendGREENchannel = GREEN;
sendClockDATA.sendBLUEchannel = BLUE; sendClockDATA.sendBLUEchannel = BLUE;
sendClockDATA.sendBrightness = BRIGHTNESS; sendClockDATA.sendBrightness = BRIGHTNESS;
// actually send it
esp_err_t result = esp_now_send(broadcastAddressClock, (uint8_t *) &sendClockDATA, sizeof(sendClockDATA)); esp_err_t result = esp_now_send(broadcastAddressClock, (uint8_t *) &sendClockDATA, sizeof(sendClockDATA));
} }
} }
@@ -225,6 +241,21 @@ void loop() {
} }
} }
} }
// forced start of countdown
if (buttonSTARTforced) {
buttonSTARTforced = false;
if (!FightCountDown[0].isRunning() && countdownPAUSED == false) {
buttonREDTEAMvar = false;
buttonBLUETEAMvar = false;
FightCountDown[0].start(0,0,countdownTIME,0);
}
else {
buttonREDTEAMvar = false;
buttonBLUETEAMvar = false;
countdownPAUSED = false;
FightCountDown[0].cont();
}
}
// pause button logic // pause button logic
if (buttonPAUSEvar) { if (buttonPAUSEvar) {
buttonPAUSEvar = false; buttonPAUSEvar = false;

View File

@@ -6,16 +6,22 @@
#include <avdweb_Switch.h> // https://github.com/avdwebLibraries/avdweb_Switch #include <avdweb_Switch.h> // https://github.com/avdwebLibraries/avdweb_Switch
// Hardware connections // Hardware connections
#define START_BTN_PIN 4 #define START_BTN_PIN 1
#define PAUSE_BTN_PIN 3 #define PAUSE_BTN_PIN 2
#define PIT_BTN_PIN 2 #define PIT_BTN_PIN 3
#define RESET_BTN_PIN 1 #define RESET_BTN_PIN 4
#define REDTEAM_BTN_PIN 5
#define BLUETEAM_BTN_PIN 6
#define REDTEAM_LED_PIN 39
#define BLUETEAM_LED_PIN 40
// define buttons and switches // define buttons and switches
Switch buttonSTART = Switch(START_BTN_PIN); Switch buttonSTART = Switch(START_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
Switch buttonPAUSE = Switch(PAUSE_BTN_PIN); Switch buttonPAUSE = Switch(PAUSE_BTN_PIN);
Switch buttonPIT = Switch(PIT_BTN_PIN); Switch buttonPIT = Switch(PIT_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
Switch buttonRESET = Switch(RESET_BTN_PIN); Switch buttonRESET = Switch(RESET_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
Switch buttonREDTEAM = Switch(REDTEAM_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
Switch buttonBLUETEAM = Switch(BLUETEAM_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
bool buttonSTARTvar = false; bool buttonSTARTvar = false;
bool buttonPAUSEvar = false; bool buttonPAUSEvar = false;
@@ -31,25 +37,30 @@ uint8_t broadcastAddress[] = {0x84, 0xFC, 0xE6, 0xC7, 0x1A, 0x8C};
// Structure example to send data // Structure example to send data
// Must match the receiver structure // Must match the receiver structure
typedef struct struct_message { typedef struct struct_message_send {
bool buttonSTARTremote; int boardID;
bool buttonPAUSEremote; bool buttonSTART;
bool buttonPITremote; bool buttonSTARTforced;
bool buttonRESETremote; bool buttonPAUSE;
} struct_message; bool buttonPIT;
bool buttonPIThold;
bool buttonRESET;
bool buttonREDTEAM;
bool buttonREDTEAMtapout;
bool buttonBLUETEAM;
bool buttonBLUETEAMtapout;
} struct_message_send;
// Create a struct_message called myData // Create a struct_message called myData
struct_message remoteDATA; struct_message_send sendDATA;
esp_now_peer_info_t peerInfo; esp_now_peer_info_t peerInfo;
// callback when data is sent // callback when data is sent
/*
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
Serial.print("\r\nLast Packet Send Status:\t"); Serial.print("\r\nLast Packet Send Status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
} }
*/
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);