From 70d4b3886dcd8ad0ce1a4cdd31e9b68b34e3045f Mon Sep 17 00:00:00 2001 From: Robin Cerny Date: Tue, 8 Apr 2025 09:30:22 +0200 Subject: [PATCH] added preliminary implementation of Team Button LEDs --- .../ROFLS_Arena_Controller.ino | 42 +++++++++++++++---- ROFLS_Arena_Remote/ROFLS_Arena_Remote.ino | 22 +++++++++- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino b/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino index e734e62..cd32488 100644 --- a/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino +++ b/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino @@ -96,9 +96,18 @@ typedef struct struct_message_Clock { struct_message_Clock sendClockDATA; // send config, pilot buttons: -uint8_t broadcastAddressREDTEAMbutton[] = {0x84, 0xFC, 0xE6, 0xC7, 0x27, 0x14}; +uint8_t broadcastAddressREDTEAMbutton[] = {0x84, 0xFC, 0xE6, 0xC7, 0x23, 0x14}; uint8_t broadcastAddressBLUETEAMbutton[] = {0x84, 0xFC, 0xE6, 0xC7, 0x1A, 0x02}; +// Structure for sending data +typedef struct struct_message_send { + bool TEAMLED; // LED state +} struct_message_send; + +// Create struct_message instances for sending to both receivers +struct_message_send sendToREDTEAMbutton; +struct_message_send sendToBLUETEAMbutton; + esp_now_peer_info_t peerInfo; // callback when data is sent @@ -206,7 +215,7 @@ void setup() { // get the status of Transmitted packet esp_now_register_send_cb(OnDataSent); - // Register peer + // Register clock peer memcpy(peerInfo.peer_addr, broadcastAddressClock, 6); peerInfo.channel = 0; peerInfo.encrypt = false; @@ -216,19 +225,38 @@ void setup() { return; } - // set rumble stopwatch resolution to seconds - esp_err_t result = esp_now_send(broadcastAddressClock, (uint8_t *) &sendClockDATA, sizeof(sendClockDATA)); + // Register Red Team Button peer + memcpy(peerInfo.peer_addr, broadcastAddressREDTEAMbutton, 6); + peerInfo.channel = 0; + peerInfo.encrypt = false; + if (esp_now_add_peer(&peerInfo) != ESP_OK) { + Serial.println("Failed to add receiver 1"); + return; + } + + // Register Blue Team Button peer + memcpy(peerInfo.peer_addr, broadcastAddressBLUETEAMbutton, 6); + peerInfo.channel = 0; + peerInfo.encrypt = false; + if (esp_now_add_peer(&peerInfo) != ESP_OK) { + Serial.println("Failed to add receiver 2"); + return; + } + + // Initialize both Team button LED states + sendToREDTEAMbutton.TEAMLED = false; + sendToBLUETEAMbutton.TEAMLED = false; + // reset remote button LEDs + esp_now_send(broadcastAddressREDTEAMbutton, (uint8_t *)&sendToREDTEAMbutton, sizeof(sendToREDTEAMbutton)); + esp_now_send(broadcastAddressBLUETEAMbutton, (uint8_t *)&sendToBLUETEAMbutton, sizeof(sendToBLUETEAMbutton)); //------------------------------------------------------------------------------------ // ESP Now receive part: // Once ESPNow is successfully Init, we will register for recv CB to // get recv packer info esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv)); - - - // set rumble stopwatch resolution to seconds } int XDAS = 255; diff --git a/ROFLS_Arena_Remote/ROFLS_Arena_Remote.ino b/ROFLS_Arena_Remote/ROFLS_Arena_Remote.ino index 7f79955..7c52cad 100644 --- a/ROFLS_Arena_Remote/ROFLS_Arena_Remote.ino +++ b/ROFLS_Arena_Remote/ROFLS_Arena_Remote.ino @@ -14,7 +14,6 @@ const bool writeBoardID = false; int boardID = 0; - // Hardware connections #define START_BTN_PIN 10 #define PAUSE_BTN_PIN 8 @@ -67,6 +66,14 @@ typedef struct struct_message_send { // Create a struct_message called myData struct_message_send sendDATA; +// Add struct for receiving ESP-NOW data +typedef struct struct_message_receive { + bool TEAMLED; // Boolean to control the team LED +} struct_message_receive; + +// Create instance for receiving ESP-NOW data +struct_message_receive receiveDATA; + esp_now_peer_info_t peerInfo; Preferences preferences; @@ -77,6 +84,16 @@ void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); } +// Callback function for receiving ESP-NOW data +void OnDataReceive(const esp_now_recv_info *recv_info, const uint8_t *incomingData, int len) { + // Copy the received data into the struct + memcpy(&receiveDATA, incomingData, sizeof(receiveDATA)); + + // Update the LED state based on received data + digitalWrite(TEAM_LED_PIN, receiveDATA.TEAMLED ? HIGH : LOW); +} + + void setup() { Serial.begin(115200); @@ -119,6 +136,9 @@ void setup() { return; } + // Register receive callback + esp_now_register_recv_cb(OnDataReceive); + // populate sendDATA struct with some data: sendDATA.boardID = boardID; sendDATA.buttonSTART = false;