Browse Source

Added more buttons with different screens

master
Englebert 3 years ago
parent
commit
61f431ca81
  1. 3
      src/Inputs.cpp
  2. 294
      src/RCController.cpp
  3. 16
      src/RCController.h
  4. 2
      src/main.cpp
  5. 5
      src/main.h

3
src/Inputs.cpp

@ -26,6 +26,9 @@ void Inputs::begin(void) {
// Activate low volume mode....
if(pitch_raw > 3000) speak.low_volume = true;
// Temporary silent....
speak.silent = true;
}

294
src/RCController.cpp

@ -1,5 +1,6 @@
#include "RCController.h"
String version_string = "M5CORE2TX - " + String(VERSION_MAJOR) + "." + String(VERSION_MINOR) + "." + String(VERSION_BUILD);
// Data Structure:
// Old format:
@ -72,7 +73,7 @@ void RCController::update(void) {
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 = button1 << 7 | button2 << 6 | button3 << 5 | button4 << 4 | button5 << 3 | button6 << 2 | button7 << 1 | button8;
txmessage.Byte01 = 1 << 7 | (raw_data1 >> 4);
txmessage.Byte01 = button9 << 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;
txmessage.Byte03 = (raw_data2 & 0x00FF);
@ -147,69 +148,111 @@ void RCController::show(TFT_eSprite *m) {
m->print("Bat: ");
m->print(String(voltage) + "V " + String(current) + "mA " + String(nrf_profiling));
m->setCursor(0, 16);
m->print(version_string);
// Draw the gimbal box
draw_gimbal(m, 69, 150);
draw_gimbal(m, 161, 150);
// Show the position of the left and right gimbal
// Convert the throttle and raw to x and y
// Temporary assume 4096 = max
uint16_t left_gimbal_y = map(inputs.throttle, stickcalibration.throttle_min, stickcalibration.throttle_max, 0, 90);
uint16_t left_gimbal_x = map(inputs.yaw, stickcalibration.yaw_min, stickcalibration.yaw_max, 0, 90);
m->fillCircle(left_gimbal_x + 69, left_gimbal_y + 150, 5, TFT_YELLOW);
uint16_t right_gimbal_y = map(inputs.pitch, stickcalibration.pitch_min, stickcalibration.pitch_max, 0, 90);
uint16_t right_gimbal_x = map(inputs.roll, stickcalibration.roll_min, stickcalibration.roll_max, 0, 90);
m->fillCircle(right_gimbal_x + 161, right_gimbal_y + 150, 5, TFT_YELLOW);
// Draw the switches
uint32_t last_millis = millis();
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(rc_screens == RC_SCREEN_GIMBAL) {
// Showing the settings
draw_gimbal(m, 69, 150);
draw_gimbal(m, 161, 150);
// Show the position of the left and right gimbal
// Convert the throttle and raw to x and y
// Temporary assume 4096 = max
uint16_t left_gimbal_y = map(inputs.throttle, stickcalibration.throttle_min, stickcalibration.throttle_max, 0, 90);
uint16_t left_gimbal_x = map(inputs.yaw, stickcalibration.yaw_min, stickcalibration.yaw_max, 0, 90);
m->fillCircle(left_gimbal_x + 69, left_gimbal_y + 150, 5, TFT_YELLOW);
uint16_t right_gimbal_y = map(inputs.pitch, stickcalibration.pitch_min, stickcalibration.pitch_max, 0, 90);
uint16_t right_gimbal_x = map(inputs.roll, stickcalibration.roll_min, stickcalibration.roll_max, 0, 90);
m->fillCircle(right_gimbal_x + 161, right_gimbal_y + 150, 5, TFT_YELLOW);
} if(rc_screens == RC_SCREEN_MAIN) {
// Draw the switches
uint32_t last_millis = millis();
if((uint32_t)(last_millis - last_button1) > 50) {
if(!button1) {
m->drawRect(0, 40, 60, 125, TFT_BLUE); // Button 1
} else {
m->drawRect(0, 40, 60, 125, TFT_BLUE); // Button 1
m->fillRect(1, 41, 58, 123, 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) > 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) > 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) > 50) {
if(!button5) {
m->drawRect(260, 40, 60, 125, TFT_BLUE); // Button 5
} else {
m->drawRect(260, 40, 60, 125, TFT_BLUE); // Button 5
m->fillRect(261, 41, 58, 123, 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_button6) > 50) {
if(!button6) {
m->drawRect(65, 105, 60, 60, TFT_BLUE); // Button 6
} else {
m->drawRect(65, 105, 60, 60, TFT_BLUE); // Button 6
m->fillRect(66, 106, 58, 58, 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_button7) > 50) {
if(!button7) {
m->drawRect(130, 105, 60, 60, TFT_BLUE); // Button 7
} else {
m->drawRect(130, 105, 60, 60, TFT_BLUE); // Button 7
m->fillRect(131, 106, 58, 58, 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_button8) > 50) {
if(!button8) {
m->drawRect(195, 105, 60, 60, TFT_BLUE); // Button 8
} else {
m->drawRect(195, 105, 60, 60, TFT_BLUE); // Button 8
m->fillRect(195, 106, 58, 58, 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);
if((uint32_t)(last_millis - last_button9) > 50) {
if(!button9) {
m->drawRect(0, 170, 320, 60, TFT_BLUE); // Button 9
} else {
m->drawRect(0, 170, 320, 60, TFT_BLUE); // Button 9
m->fillRect(1, 168, 318, 58, TFT_BLUE);
}
}
}
m->setCursor(90, 130);
m->print("M5CORE2TX");
m->pushSprite(0,0);
updated = false;
@ -228,6 +271,13 @@ void RCController::show(TFT_eSprite *m) {
screen.updated = true;
}
if(M5.BtnB.wasPressed()) {
//// show_settings = !show_settings;
rc_screens++;
if(rc_screens == RC_SCREEN_MAX)
rc_screens = RC_SCREEN_MAIN;
}
// Temporary connect from here...
if(M5.BtnA.wasPressed()) {
}
@ -263,67 +313,85 @@ void RCController::show(TFT_eSprite *m) {
// - MinY: 150
// - MaxX: 160
// - MaxY: 190
if(e.to.x >= 110 && e.to.x <= 120 && e.to.y >= 140 && e.to.y <= 180) {
// Minus throttle
// Serial.printf("Left: TOP\n");
inputs.trim_throttle-=20;
speak.speak_trim_word = TRIM_THROTTLE_INCREASE;
speak.speak_now_trim = true;
} else if(e.to.x >= 110 && e.to.x <= 170 && e.to.y >= 200 && e.to.y <= 220) {
// Add throttle
// Serial.printf("Left: BOTTOM\n");
inputs.trim_throttle+=20;
speak.speak_trim_word = TRIM_THROTTLE_DECREASE;
speak.speak_now_trim = true;
} else if(e.to.x >= 60 && e.to.x <= 105 && e.to.y >= 180 && e.to.y <= 210) {
// Minus Yaw
// Serial.printf("Left: LEFT\n");
inputs.trim_yaw-=20;
speak.speak_trim_word = TRIM_YAW_DECREASE;
speak.speak_now_trim = true;
} else if(e.to.x >= 110 && e.to.x <= 160 && e.to.y >= 150 && e.to.y <= 190) {
// Add Yaw
// Serial.printf("Left: RIGHT\n");
inputs.trim_yaw+=20;
speak.speak_trim_word = TRIM_YAW_INCREASE;
speak.speak_now_trim = true;
} else if(e.to.x >= 250 && e.to.x <= 230 && e.to.y >= 187 && e.to.y <= 197) {
// Add Row
inputs.trim_roll+=20;
speak.speak_trim_word = TRIM_ROLL_INCREASE;
speak.speak_now_trim = true;
} else if(e.to.x >= 180 && e.to.x <= 175 && e.to.y >= 187 && e.to.y <= 197) {
// Minus Row
inputs.trim_roll+=20;
speak.speak_trim_word = TRIM_ROLL_DECREASE;
speak.speak_now_trim = true;
// TODO: Continue the rest.....
} else if(e.to.x >= 0 && e.to.x <= 60 && e.to.y >= 40 && e.to.y <= 100) {
// Button 1
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
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
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
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
last_button5 = millis(); // For remembering last press on UI
button5 = !button5;
//// ble.button5 = true; // Send to BLE let the process to run through
if(rc_screens == RC_SCREEN_GIMBAL) {
if(e.to.x >= 110 && e.to.x <= 120 && e.to.y >= 140 && e.to.y <= 180) {
// Minus throttle
// Serial.printf("Left: TOP\n");
inputs.trim_throttle-=20;
speak.speak_trim_word = TRIM_THROTTLE_INCREASE;
speak.speak_now_trim = true;
} else if(e.to.x >= 110 && e.to.x <= 170 && e.to.y >= 200 && e.to.y <= 220) {
// Add throttle
// Serial.printf("Left: BOTTOM\n");
inputs.trim_throttle+=20;
speak.speak_trim_word = TRIM_THROTTLE_DECREASE;
speak.speak_now_trim = true;
} else if(e.to.x >= 60 && e.to.x <= 105 && e.to.y >= 180 && e.to.y <= 210) {
// Minus Yaw
// Serial.printf("Left: LEFT\n");
inputs.trim_yaw-=20;
speak.speak_trim_word = TRIM_YAW_DECREASE;
speak.speak_now_trim = true;
} else if(e.to.x >= 110 && e.to.x <= 160 && e.to.y >= 150 && e.to.y <= 190) {
// Add Yaw
// Serial.printf("Left: RIGHT\n");
inputs.trim_yaw+=20;
speak.speak_trim_word = TRIM_YAW_INCREASE;
speak.speak_now_trim = true;
} else if(e.to.x >= 250 && e.to.x <= 230 && e.to.y >= 187 && e.to.y <= 197) {
// Add Row
inputs.trim_roll+=20;
speak.speak_trim_word = TRIM_ROLL_INCREASE;
speak.speak_now_trim = true;
} else if(e.to.x >= 180 && e.to.x <= 175 && e.to.y >= 187 && e.to.y <= 197) {
// Minus Row
inputs.trim_roll+=20;
speak.speak_trim_word = TRIM_ROLL_DECREASE;
speak.speak_now_trim = true;
}
} else if(rc_screens == RC_SCREEN_MAIN) {
if(e.to.x >= 0 && e.to.x <= 60 && e.to.y >= 40 && e.to.y <= 165) {
// Button 1
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
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
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
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 <= 320 && e.to.y >= 40 && e.to.y <= 165) {
// Button 5
last_button5 = millis(); // For remembering last press on UI
button5 = !button5;
//// ble.button5 = true; // Send to BLE let the process to run through
} else if(e.to.x >= 65 && e.to.x <= 125 && e.to.y >= 105 && e.to.y <= 165) {
// Button 6
last_button6 = millis(); // For remembering last press on UI
button6 = !button6;
} else if(e.to.x >= 130 && e.to.x <= 190 && e.to.y >= 105 && e.to.y <= 165) {
// Button 7
last_button7 = millis(); // For remembering last press on UI
button7 = !button7;
} else if(e.to.x >= 195 && e.to.x <= 255 && e.to.y >= 105 && e.to.y <= 165) {
// Button 8
last_button8 = millis(); // For remembering last press on UI
button8 = !button8;
} else if(e.to.x >= 0 && e.to.x <= 320 && e.to.y >= 170 && e.to.y <= 230) {
// Button 9
last_button9 = millis(); // For remembering last press on UI
button9 = !button9;
}
}
touch_time = millis();
}

16
src/RCController.h

@ -8,6 +8,13 @@
#include "Speak.h"
#include "nrf24l01.h"
#include "StickCalibration.h"
#include "main.h"
enum rc_controller_screens {
RC_SCREEN_MAIN = 0,
RC_SCREEN_GIMBAL,
RC_SCREEN_MAX
};
class RCController {
@ -30,6 +37,14 @@ class RCController {
uint32_t last_button3 = 0;
uint32_t last_button4 = 0;
uint32_t last_button5 = 0;
uint32_t last_button6 = 0;
uint32_t last_button7 = 0;
uint32_t last_button8 = 0;
uint32_t last_button9 = 0;
bool show_settings = false;
uint8_t rc_screens = RC_SCREEN_MAIN;
bool button1 = false;
bool button2 = false;
bool button3 = false;
@ -38,6 +53,7 @@ class RCController {
bool button6 = false;
bool button7 = false;
bool button8 = false;
bool button9 = false;
RCController(void);
void begin(void);

2
src/main.cpp

@ -151,7 +151,7 @@ void taskCharger(void *pvParameters) {
}
}
vTaskDelay(200);
vTaskDelay(1000);
}
}

5
src/main.h

@ -5,6 +5,11 @@
#define CPU_1 1
#define CPU_0 0
// VERSION
#define VERSION_MAJOR 1
#define VERSION_MINOR 0
#define VERSION_BUILD 9
#include <M5Core2.h>
#include "Inputs.h"
#include "BLE.h"

Loading…
Cancel
Save