Browse Source

Added buttons handling

master
Englebert 3 years ago
parent
commit
fe7fceb7b4
  1. 74
      src/RCController.cpp
  2. 8
      src/RCController.h

74
src/RCController.cpp

@ -71,7 +71,7 @@ void RCController::update(void) {
// Byte00 ~ Byte06 - START
raw_data1 = map(inputs.throttle, stickcalibration.throttle_min, stickcalibration.throttle_max, 1000, 2000);
//// txmessage.Byte00 = sw1 << 7 | sw2 << 6 | sw3 << 5 | sw4 << 4 | sw5 << 3 | sw6 << 2 | sw7 << 1 | sw8;
txmessage.Byte00 = 0x00;
txmessage.Byte00 = button1 << 7 | button2 << 6 | button3 << 5 | button4 << 4 | button5 << 3 | button6 << 2 | button7 << 1 | button8;
txmessage.Byte01 = 1 << 7 | (raw_data1 >> 4);
raw_data2 = map(inputs.yaw, stickcalibration.yaw_min, stickcalibration.yaw_max, 2000, 1000);
txmessage.Byte02 = (raw_data1 & 0x000F) << 4 | raw_data2 >> 8;
@ -122,7 +122,7 @@ void RCController::show(TFT_eSprite *m) {
Serial.println("nrf tx started.");
}
if((uint32_t) (millis() - last_updated) > 50) {
if((uint32_t) (millis() - last_updated) > 25) {
updated = true;
}
@ -162,39 +162,49 @@ void RCController::show(TFT_eSprite *m) {
// Draw the switches
uint32_t last_millis = millis();
if((uint32_t)(last_millis - last_button1) > 500) {
m->drawRect(0, 40, 60, 60, TFT_BLUE); // Button 1
} else {
m->drawRect(0, 40, 60, 60, TFT_BLUE); // Button 1
m->fillRect(1, 41, 60, 60, TFT_BLUE);
if((uint32_t)(last_millis - last_button1) > 50) {
if(!button1) {
m->drawRect(0, 40, 60, 60, TFT_BLUE); // Button 1
} else {
m->drawRect(0, 40, 60, 60, TFT_BLUE); // Button 1
m->fillRect(1, 41, 58, 58, TFT_BLUE);
}
}
if((uint32_t)(last_millis - last_button2) > 500) {
m->drawRect(65, 40, 60, 60, TFT_BLUE); // Button 2
} else {
m->drawRect(65, 40, 60, 60, TFT_BLUE); // Button 2
m->fillRect(66, 41, 60, 60, TFT_BLUE);
if((uint32_t)(last_millis - last_button2) > 50) {
if(!button2) {
m->drawRect(65, 40, 60, 60, TFT_BLUE); // Button 2
} else {
m->drawRect(65, 40, 60, 60, TFT_BLUE); // Button 2
m->fillRect(66, 41, 58, 58, TFT_BLUE);
}
}
if((uint32_t)(last_millis - last_button3) > 500) {
m->drawRect(130, 40, 60, 60, TFT_BLUE); // Button 3
} else {
m->drawRect(130, 40, 60, 60, TFT_BLUE); // Button 3
m->fillRect(131, 41, 60, 60, TFT_BLUE);
if((uint32_t)(last_millis - last_button3) > 50) {
if(!button3) {
m->drawRect(130, 40, 60, 60, TFT_BLUE); // Button 3
} else {
m->drawRect(130, 40, 60, 60, TFT_BLUE); // Button 3
m->fillRect(131, 41, 58, 58, TFT_BLUE);
}
}
if((uint32_t)(last_millis - last_button4) > 500) {
m->drawRect(195, 40, 60, 60, TFT_BLUE); // Button 4
} else {
m->drawRect(195, 40, 60, 60, TFT_BLUE); // Button 4
m->fillRect(196, 41, 60, 60, TFT_BLUE);
if((uint32_t)(last_millis - last_button4) > 50) {
if(!button4) {
m->drawRect(195, 40, 60, 60, TFT_BLUE); // Button 4
} else {
m->drawRect(195, 40, 60, 60, TFT_BLUE); // Button 4
m->fillRect(196, 41, 58, 58, TFT_BLUE);
}
}
if((uint32_t)(last_millis - last_button5) > 500) {
m->drawRect(260, 40, 60, 60, TFT_BLUE); // Button 5
} else {
m->drawRect(260, 40, 60, 60, TFT_BLUE); // Button 5
m->fillRect(261, 41, 60, 60, TFT_BLUE);
if((uint32_t)(last_millis - last_button5) > 50) {
if(!button5) {
m->drawRect(260, 40, 60, 60, TFT_BLUE); // Button 5
} else {
m->drawRect(260, 40, 60, 60, TFT_BLUE); // Button 5
m->fillRect(261, 41, 58, 58, TFT_BLUE);
}
}
m->setCursor(90, 130);
@ -291,28 +301,28 @@ void RCController::show(TFT_eSprite *m) {
// TODO: Continue the rest.....
} else if(e.to.x >= 0 && e.to.x <= 60 && e.to.y >= 40 && e.to.y <= 100) {
// Button 1
//// ble.last_button1 = millis(); // Setting the time so the system knows how long to trigger
last_button1 = millis();; // For remembering last press on UI
button1 = !button1;
/// ble.button1 = true; // Send to BLE let the process to run through
} else if(e.to.x >= 65 && e.to.x <= 125 && e.to.y >= 40 && e.to.y <= 100) {
// Button 2
//// ble.last_button2 = millis(); // Setting the time so the system knows how long to trigger
last_button2 = millis(); // For remembering last press on UI
button2 = !button2;
//// ble.button2 = true; // Send to BLE let the process to run through
} else if(e.to.x >= 130 && e.to.x <= 190 && e.to.y >= 40 && e.to.y <= 100) {
// Button 3
//// ble.last_button3 = millis(); // Setting the time so the system knows how long to trigger
last_button3 = millis(); // For remembering last press on UI
button3 = !button3;
//// ble.button3 = true; // Send to BLE let the process to run through
} else if(e.to.x >= 195 && e.to.x <= 255 && e.to.y >= 40 && e.to.y <= 100) {
// Button 4
//// ble.last_button4 = millis(); // Setting the time so the system knows how long to trigger
last_button4 = millis(); // For remembering last press on UI
button4 = !button4;
//// ble.button4 = true; // Send to BLE let the process to run through
} else if(e.to.x >= 260 && e.to.x <= 310 && e.to.y >= 40 && e.to.y <= 100) {
// Button 5
//// ble.last_button5 = millis(); // Setting the time so the system knows how long to trigger
last_button5 = millis(); // For remembering last press on UI
button5 = !button5;
//// ble.button5 = true; // Send to BLE let the process to run through
}
touch_time = millis();

8
src/RCController.h

@ -30,6 +30,14 @@ class RCController {
uint32_t last_button3 = 0;
uint32_t last_button4 = 0;
uint32_t last_button5 = 0;
bool button1 = false;
bool button2 = false;
bool button3 = false;
bool button4 = false;
bool button5 = false;
bool button6 = false;
bool button7 = false;
bool button8 = false;
RCController(void);
void begin(void);

Loading…
Cancel
Save