|
|
@ -70,6 +70,43 @@ void BLEGamepad::show(TFT_eSprite *m) { |
|
|
|
uint16_t right_gimbal_x = map(inputs.roll, 0, 4096, 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) > 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_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_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_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_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); |
|
|
|
} |
|
|
|
|
|
|
|
m->setCursor(90, 130); |
|
|
|
m->print("BLE GAMEPAD"); |
|
|
|
|
|
|
@ -94,6 +131,111 @@ void BLEGamepad::show(TFT_eSprite *m) { |
|
|
|
// Temporary connect from here...
|
|
|
|
if(M5.BtnA.wasPressed()) { |
|
|
|
} |
|
|
|
|
|
|
|
// Handling inputs
|
|
|
|
Event &e = M5.Buttons.event; |
|
|
|
coordinate = M5.Touch.getPressPoint(); |
|
|
|
|
|
|
|
// Making sure not retrigger...
|
|
|
|
if((uint32_t)(millis() - touch_time) > 100) { |
|
|
|
if(e & (E_TOUCH)) { |
|
|
|
Serial.printf("E_TOUCH X:%d, Y:%d\r\n", e.to.x, e.to.y); |
|
|
|
|
|
|
|
// Determine touched positions:
|
|
|
|
// Left gimbal:
|
|
|
|
// - Top
|
|
|
|
// - MinX: 110
|
|
|
|
// - MinY: 150
|
|
|
|
// - MaxX: 120
|
|
|
|
// - MaxY: 180
|
|
|
|
// - Bottom
|
|
|
|
// - MinX: 110
|
|
|
|
// - MinY: 200
|
|
|
|
// - MaxX: 120
|
|
|
|
// - MaxY: 220
|
|
|
|
// - Left
|
|
|
|
// - MinX: 80
|
|
|
|
// - MinY: 180
|
|
|
|
// - MaxX: 105
|
|
|
|
// - MaxY: 210
|
|
|
|
// - Right
|
|
|
|
// - MinX: 110
|
|
|
|
// - 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
|
|
|
|
ble.last_button1 = millis(); // Setting the time so the system knows how long to trigger
|
|
|
|
last_button1 = ble.last_button1; // For remembering last press on UI
|
|
|
|
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 = ble.last_button2; // For remembering last press on UI
|
|
|
|
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 = ble.last_button3; // For remembering last press on UI
|
|
|
|
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 = ble.last_button4; // For remembering last press on UI
|
|
|
|
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 = ble.last_button5; // For remembering last press on UI
|
|
|
|
ble.button5 = true; // Send to BLE let the process to run through
|
|
|
|
} |
|
|
|
touch_time = millis(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/***
|
|
|
|
if(e & (E_RELEASE)) { |
|
|
|
Serial.printf("E_MOVE X:%d, Y:%d\r\n", e & E_MOVE ? e.from.x : e.to.x, e & E_MOVE ? e.from.y : e.to.y); |
|
|
|
} |
|
|
|
if(coordinate.x > 0 || coordinate.y > 0) |
|
|
|
Serial.printf("x:%d, y:%d \r\n", coordinate.x, coordinate.y); |
|
|
|
***/ |
|
|
|
} |
|
|
|
|
|
|
|
BLEGamepad blegamepad; |