fixed remote PitHold, added persistant boardID
This commit is contained in:
@@ -9,13 +9,15 @@ void pollInput (){
|
|||||||
switchRUMBLE.poll();
|
switchRUMBLE.poll();
|
||||||
switchPIT.poll();
|
switchPIT.poll();
|
||||||
|
|
||||||
buttonSTARTvar = buttonSTART.singleClick();
|
// only set the var if the button was actually pushed or released, to prevent overriding data from the remote
|
||||||
buttonSTARTforced = buttonSTART.longPress();
|
if (buttonSTART.singleClick() || buttonSTART.longPress() || buttonPAUSE.singleClick() || buttonPIT.singleClick() || buttonPIT.switched() || buttonRESET.longPress()) {
|
||||||
buttonPAUSEvar = buttonPAUSE.singleClick();
|
buttonSTARTvar = buttonSTART.singleClick();
|
||||||
buttonPITvar = buttonPIT.singleClick();
|
buttonSTARTforced = buttonSTART.longPress();
|
||||||
buttonPIThold = buttonPIT.on();
|
buttonPAUSEvar = buttonPAUSE.singleClick();
|
||||||
buttonRESETvar = buttonRESET.longPress();
|
buttonPITvar = buttonPIT.singleClick();
|
||||||
|
buttonPIThold = buttonPIT.on();
|
||||||
|
buttonRESETvar = buttonRESET.longPress();
|
||||||
|
}
|
||||||
// if (buttonREDTEAM.pushed()) {
|
// if (buttonREDTEAM.pushed()) {
|
||||||
// buttonREDTEAMvar = true;
|
// buttonREDTEAMvar = true;
|
||||||
// if (ARENA_READY && !REDTEAM_READY) {
|
// if (ARENA_READY && !REDTEAM_READY) {
|
||||||
|
|||||||
@@ -78,15 +78,8 @@ typedef struct struct_message_Clock {
|
|||||||
struct_message_Clock sendClockDATA;
|
struct_message_Clock sendClockDATA;
|
||||||
|
|
||||||
// send config, pilot buttons:
|
// send config, pilot buttons:
|
||||||
uint8_t broadcastAddressREDTEAMbutton[] = {0x48, 0x27, 0xE2, 0x5D, 0xB6, 0x84};
|
uint8_t broadcastAddressREDTEAMbutton[] = {0x84, 0xFC, 0xE6, 0xC7, 0x27, 0x14};
|
||||||
uint8_t broadcastAddressBLUETEAMbutton[] = {0x48, 0x27, 0xE2, 0x5D, 0xB6, 0x84};
|
uint8_t broadcastAddressBLUETEAMbutton[] = {0x84, 0xFC, 0xE6, 0xC7, 0x1A, 0x02};
|
||||||
// struct for pilot button data:
|
|
||||||
typedef struct struct_message_TEAMButton {
|
|
||||||
bool REDTEAMButtonLED;
|
|
||||||
bool BLUETEAMButtonLED;
|
|
||||||
} struct_message_TEAMButton;
|
|
||||||
|
|
||||||
struct_message_TEAMButton sendTEAMButtonDATA;
|
|
||||||
|
|
||||||
esp_now_peer_info_t peerInfo;
|
esp_now_peer_info_t peerInfo;
|
||||||
|
|
||||||
@@ -285,10 +278,10 @@ void loop() {
|
|||||||
openPITmanually();
|
openPITmanually();
|
||||||
}
|
}
|
||||||
// automatic pit release
|
// automatic pit release
|
||||||
if (FightCountDown[0].remaining() == PITreleaseTime && switchPIT.on() && buttonPIThold == false) {
|
if (FightCountDown[0].remaining() <= PITreleaseTime && FightCountDown[0].remaining() != 0 && !switchRUMBLE.on() && switchPIT.on() && buttonPIThold == false) {
|
||||||
openPIT();
|
openPIT();
|
||||||
}
|
}
|
||||||
if (rumbleTIME.elapsed() == PITreleaseTime && switchPIT.on() && buttonPIThold == false) {
|
if (rumbleTIME.elapsed() >= PITreleaseTime && switchRUMBLE.on() && switchPIT.on() && buttonPIThold == false) {
|
||||||
openPIT();
|
openPIT();
|
||||||
}
|
}
|
||||||
// reset button logic
|
// reset button logic
|
||||||
|
|||||||
@@ -6,17 +6,23 @@ void pollInput (){
|
|||||||
buttonPAUSE.poll();
|
buttonPAUSE.poll();
|
||||||
buttonPIT.poll();
|
buttonPIT.poll();
|
||||||
buttonRESET.poll();
|
buttonRESET.poll();
|
||||||
|
buttonTEAM.poll();
|
||||||
|
|
||||||
if (buttonSTART.pushed()) {
|
// only set the var if the button was actually pushed or released, to prevent overriding data from the controller
|
||||||
buttonSTARTvar = true;
|
if (buttonSTART.singleClick() || buttonSTART.longPress() || buttonPAUSE.singleClick() || buttonPIT.singleClick() || buttonPIT.switched() || buttonRESET.longPress() || buttonTEAM.singleClick() || buttonTEAM.longPress()) {
|
||||||
}
|
sendDATAvar = true;
|
||||||
if (buttonPAUSE.pushed()) {
|
buttonSTARTvar = buttonSTART.singleClick();
|
||||||
buttonPAUSEvar = true;
|
buttonSTARTforced = buttonSTART.longPress();
|
||||||
}
|
buttonPAUSEvar = buttonPAUSE.singleClick();
|
||||||
if (buttonPIT.pushed()) {
|
buttonPITvar = buttonPIT.singleClick();
|
||||||
buttonPITvar = true;
|
buttonPIThold = buttonPIT.on();
|
||||||
}
|
buttonRESETvar = buttonRESET.longPress();
|
||||||
if (buttonRESET.pushed()) {
|
if (boardID == 1) {
|
||||||
buttonRESETvar = true;
|
buttonREDTEAMvar = buttonTEAM.singleClick();
|
||||||
|
buttonREDTEAMtapout = buttonTEAM.longPress();
|
||||||
|
} else if (boardID == 2) {
|
||||||
|
buttonBLUETEAMvar = buttonTEAM.singleClick();
|
||||||
|
buttonBLUETEAMtapout = buttonTEAM.longPress();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,30 +5,43 @@
|
|||||||
#include <Preferences.h> // automatically installed for ESP32 boards
|
#include <Preferences.h> // automatically installed for ESP32 boards
|
||||||
#include <avdweb_Switch.h> // https://github.com/avdwebLibraries/avdweb_Switch
|
#include <avdweb_Switch.h> // https://github.com/avdwebLibraries/avdweb_Switch
|
||||||
|
|
||||||
|
// set board ID
|
||||||
|
// This is only needed for the initial flashing, as it writes the ID in to the ESPs internal flash
|
||||||
|
//
|
||||||
|
// 0 = referee remote
|
||||||
|
// 1 = Red Team Button
|
||||||
|
// 2 = Blue Team Button
|
||||||
|
const bool writeBoardID = false;
|
||||||
|
int boardID = 0;
|
||||||
|
|
||||||
|
|
||||||
// Hardware connections
|
// Hardware connections
|
||||||
#define START_BTN_PIN 1
|
#define START_BTN_PIN 1
|
||||||
#define PAUSE_BTN_PIN 2
|
#define PAUSE_BTN_PIN 2
|
||||||
#define PIT_BTN_PIN 3
|
#define PIT_BTN_PIN 3
|
||||||
#define RESET_BTN_PIN 4
|
#define RESET_BTN_PIN 4
|
||||||
#define REDTEAM_BTN_PIN 5
|
#define TEAM_BTN_PIN 16
|
||||||
#define BLUETEAM_BTN_PIN 6
|
#define TEAM_LED_PIN 17
|
||||||
#define REDTEAM_LED_PIN 39
|
|
||||||
#define BLUETEAM_LED_PIN 40
|
|
||||||
|
|
||||||
// define buttons and switches
|
// define buttons and switches
|
||||||
Switch buttonSTART = Switch(START_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
|
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, INPUT_PULLUP, LOW, 50, 1000);
|
Switch buttonPIT = Switch(PIT_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
|
||||||
Switch buttonRESET = Switch(RESET_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
|
Switch buttonRESET = Switch(RESET_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
|
||||||
Switch buttonREDTEAM = Switch(REDTEAM_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
|
Switch buttonTEAM = Switch(TEAM_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 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 buttonREDTEAMtapout = false;
|
||||||
|
bool buttonBLUETEAMvar = false;
|
||||||
|
bool buttonBLUETEAMtapout = false;
|
||||||
|
|
||||||
bool sendDATA = false;
|
bool sendDATAvar = false;
|
||||||
|
|
||||||
// ESP-NOW config
|
// ESP-NOW config
|
||||||
|
|
||||||
@@ -56,6 +69,8 @@ struct_message_send sendDATA;
|
|||||||
|
|
||||||
esp_now_peer_info_t peerInfo;
|
esp_now_peer_info_t peerInfo;
|
||||||
|
|
||||||
|
Preferences preferences;
|
||||||
|
|
||||||
// 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");
|
||||||
@@ -65,6 +80,23 @@ void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
|
|||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
// write boardID to internal Flash if needed
|
||||||
|
if (writeBoardID) {
|
||||||
|
// open preferences, namespace, RW mode = false
|
||||||
|
preferences.begin("Arena-remote", false);
|
||||||
|
preferences.putUInt("boardID", boardID);
|
||||||
|
} else {
|
||||||
|
// open preferences, namespace, RO mode = true
|
||||||
|
preferences.begin("Arena-remote", true);
|
||||||
|
}
|
||||||
|
// read board ID from internal flash
|
||||||
|
boardID = preferences.getUInt("boardID", 0);
|
||||||
|
preferences.end();
|
||||||
|
|
||||||
|
// configure and set the LED output pin
|
||||||
|
pinMode(TEAM_LED_PIN, OUTPUT);
|
||||||
|
digitalWrite(TEAM_LED_PIN, LOW);
|
||||||
|
|
||||||
// Set device as a Wi-Fi Station
|
// Set device as a Wi-Fi Station
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
|
|
||||||
@@ -74,8 +106,8 @@ void setup() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Once ESPNow is successfully Init, we will register for Send CB to
|
// 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);
|
esp_now_register_send_cb(OnDataSent);
|
||||||
|
|
||||||
// Register peer
|
// Register peer
|
||||||
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
|
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
|
||||||
@@ -86,69 +118,51 @@ void setup() {
|
|||||||
Serial.println("Failed to add peer");
|
Serial.println("Failed to add peer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// populate sendDATA struct with some data:
|
||||||
|
sendDATA.boardID = boardID;
|
||||||
|
sendDATA.buttonSTART = false;
|
||||||
|
sendDATA.buttonSTARTforced = false;
|
||||||
|
sendDATA.buttonPAUSE = false;
|
||||||
|
sendDATA.buttonPIT = false;
|
||||||
|
sendDATA.buttonPIThold = false;
|
||||||
|
sendDATA.buttonRESET = false;
|
||||||
|
sendDATA.buttonREDTEAM = false;
|
||||||
|
sendDATA.buttonREDTEAMtapout = false;
|
||||||
|
sendDATA.buttonBLUETEAM = false;
|
||||||
|
sendDATA.buttonBLUETEAMtapout = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendDATA_to_controller() {
|
||||||
|
// if ((sendDATA.buttonSTART != buttonSTARTvar) || (sendDATA.buttonSTARTforced != buttonSTARTforced) || (sendDATA.buttonPAUSE !=buttonPAUSEvar) || (sendDATA.buttonPIT != buttonPITvar) || (sendDATA.buttonPIThold != buttonPIThold) || (sendDATA.buttonRESET != buttonRESETvar) || (sendDATA.buttonREDTEAM != buttonREDTEAMvar) || (sendDATA.buttonREDTEAMtapout != buttonREDTEAMtapout) || (sendDATA.buttonBLUETEAM != buttonBLUETEAMvar) || (sendDATA.buttonBLUETEAMtapout != buttonBLUETEAMtapout)) {
|
||||||
|
if (sendDATAvar) {
|
||||||
|
sendDATAvar = false;
|
||||||
|
// prepare sendDATA data
|
||||||
|
sendDATA.boardID = boardID;
|
||||||
|
sendDATA.buttonSTART = buttonSTARTvar;
|
||||||
|
sendDATA.buttonSTARTforced = buttonSTARTforced;
|
||||||
|
sendDATA.buttonPAUSE = buttonPAUSEvar;
|
||||||
|
sendDATA.buttonPIT = buttonPITvar;
|
||||||
|
sendDATA.buttonPIThold = buttonPIThold;
|
||||||
|
sendDATA.buttonRESET = buttonRESETvar;
|
||||||
|
sendDATA.buttonREDTEAM = buttonREDTEAMvar;
|
||||||
|
sendDATA.buttonREDTEAMtapout = buttonREDTEAMtapout;
|
||||||
|
sendDATA.buttonBLUETEAM = buttonBLUETEAMvar;
|
||||||
|
sendDATA.buttonBLUETEAMtapout = buttonBLUETEAMtapout;
|
||||||
|
// send data
|
||||||
|
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &sendDATA, sizeof(sendDATA));
|
||||||
|
// check if transmission was successfull
|
||||||
|
// if (result == ESP_OK) {
|
||||||
|
// Serial.println("Sent with success");
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// Serial.println("Error sending the data");
|
||||||
|
// }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// poll all the switch/button inputs
|
// poll all the switch/button inputs
|
||||||
pollInput();
|
pollInput();
|
||||||
// start button logic
|
sendDATA_to_controller();
|
||||||
if (buttonSTARTvar) {
|
|
||||||
buttonSTARTvar = false;
|
|
||||||
remoteDATA.buttonSTARTremote = true;
|
|
||||||
sendDATA = true;
|
|
||||||
}
|
|
||||||
// pause button logic
|
|
||||||
if (buttonPAUSEvar) {
|
|
||||||
buttonPAUSEvar = false;
|
|
||||||
remoteDATA.buttonPAUSEremote = true;
|
|
||||||
sendDATA = true;
|
|
||||||
}
|
|
||||||
// pit button logic
|
|
||||||
if (buttonPITvar) {
|
|
||||||
buttonPITvar = false;
|
|
||||||
remoteDATA.buttonPITremote = true;
|
|
||||||
sendDATA = true;
|
|
||||||
}
|
|
||||||
// reset button logic
|
|
||||||
if (buttonRESETvar) {
|
|
||||||
buttonRESETvar = false;
|
|
||||||
remoteDATA.buttonRESETremote = true;
|
|
||||||
sendDATA = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set values to send
|
|
||||||
//remoteDATA.buttonSTARTremote = false;
|
|
||||||
//remoteDATA.buttonPAUSEremote = false;
|
|
||||||
//remoteDATA.buttonPITremote = false;
|
|
||||||
//remoteDATA.buttonRESETremote = false;
|
|
||||||
|
|
||||||
// Send message via ESP-NOW
|
|
||||||
//esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &remoteDATA, sizeof(remoteDATA));
|
|
||||||
if (sendDATA == true) {
|
|
||||||
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &remoteDATA, sizeof(remoteDATA));
|
|
||||||
sendDATA = false;
|
|
||||||
// clear remoteDATA struct
|
|
||||||
remoteDATA.buttonSTARTremote = false;
|
|
||||||
remoteDATA.buttonPAUSEremote = false;
|
|
||||||
remoteDATA.buttonPITremote = false;
|
|
||||||
remoteDATA.buttonRESETremote = false;
|
|
||||||
|
|
||||||
if (result == ESP_OK) {
|
|
||||||
Serial.println("Sent with success");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Serial.println("Error sending the data");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (result == ESP_OK) {
|
|
||||||
Serial.println("Sent with success");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Serial.println("Error sending the data");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//delay(2000);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user