added preliminary implementation of Team Button LEDs
This commit is contained in:
@@ -96,9 +96,18 @@ typedef struct struct_message_Clock {
|
|||||||
struct_message_Clock sendClockDATA;
|
struct_message_Clock sendClockDATA;
|
||||||
|
|
||||||
// send config, pilot buttons:
|
// 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};
|
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;
|
esp_now_peer_info_t peerInfo;
|
||||||
|
|
||||||
// callback when data is sent
|
// callback when data is sent
|
||||||
@@ -206,7 +215,7 @@ void setup() {
|
|||||||
// get the status of Transmitted packet
|
// get the status of Transmitted packet
|
||||||
esp_now_register_send_cb(OnDataSent);
|
esp_now_register_send_cb(OnDataSent);
|
||||||
|
|
||||||
// Register peer
|
// Register clock peer
|
||||||
memcpy(peerInfo.peer_addr, broadcastAddressClock, 6);
|
memcpy(peerInfo.peer_addr, broadcastAddressClock, 6);
|
||||||
peerInfo.channel = 0;
|
peerInfo.channel = 0;
|
||||||
peerInfo.encrypt = false;
|
peerInfo.encrypt = false;
|
||||||
@@ -216,19 +225,38 @@ void setup() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set rumble stopwatch resolution to seconds
|
|
||||||
|
|
||||||
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));
|
||||||
|
|
||||||
|
// 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:
|
// ESP Now receive part:
|
||||||
// Once ESPNow is successfully Init, we will register for recv CB to
|
// Once ESPNow is successfully Init, we will register for recv CB to
|
||||||
// get recv packer info
|
// get recv packer info
|
||||||
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
|
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
|
||||||
|
|
||||||
|
|
||||||
// set rumble stopwatch resolution to seconds
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int XDAS = 255;
|
int XDAS = 255;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
const bool writeBoardID = false;
|
const bool writeBoardID = false;
|
||||||
int boardID = 0;
|
int boardID = 0;
|
||||||
|
|
||||||
|
|
||||||
// Hardware connections
|
// Hardware connections
|
||||||
#define START_BTN_PIN 10
|
#define START_BTN_PIN 10
|
||||||
#define PAUSE_BTN_PIN 8
|
#define PAUSE_BTN_PIN 8
|
||||||
@@ -67,6 +66,14 @@ typedef struct struct_message_send {
|
|||||||
// Create a struct_message called myData
|
// Create a struct_message called myData
|
||||||
struct_message_send sendDATA;
|
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;
|
esp_now_peer_info_t peerInfo;
|
||||||
|
|
||||||
Preferences preferences;
|
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");
|
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() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
@@ -119,6 +136,9 @@ void setup() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register receive callback
|
||||||
|
esp_now_register_recv_cb(OnDataReceive);
|
||||||
|
|
||||||
// populate sendDATA struct with some data:
|
// populate sendDATA struct with some data:
|
||||||
sendDATA.boardID = boardID;
|
sendDATA.boardID = boardID;
|
||||||
sendDATA.buttonSTART = false;
|
sendDATA.buttonSTART = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user