Englebert
2 years ago
10 changed files with 416 additions and 25 deletions
-
5README.md
-
92src/ESPNow.cpp
-
11src/ESPNow2.h
-
229src/ESPNowRC.cpp
-
36src/ESPNowRC.h
-
1src/ESPPair.cpp
-
33src/Screen.cpp
-
5src/Screen.h
-
27src/main.cpp
-
2src/main.h
@ -0,0 +1,229 @@ |
|||
#include "ESPNowRC.h"
|
|||
|
|||
ESPNowRC::ESPNowRC(void) { |
|||
updated = true; |
|||
} |
|||
|
|||
void ESPNowRC::begin(void) { |
|||
updated = true; |
|||
} |
|||
|
|||
void ESPNowRC::draw_gimbal(TFT_eSprite *m, uint16_t x, uint16_t y) { |
|||
// Top
|
|||
m->drawFastHLine(x, y, 90, TFT_DARKGREEN); |
|||
// Bottom
|
|||
m->drawFastHLine(x, y + 89, 90, TFT_DARKGREEN); |
|||
// Left
|
|||
m->drawFastVLine(x, y, 90, TFT_DARKGREEN); |
|||
// Right
|
|||
m->drawFastVLine(x + 89, y, 90, TFT_DARKGREEN); |
|||
|
|||
// Middle dotted lines
|
|||
for(uint16_t x1 = x; x1 < x + 90; x1 += 10) { |
|||
m->drawFastHLine(x1, y + 45, 5, TFT_DARKGREEN); |
|||
} |
|||
for(uint16_t y1 = y; y1 < y + 90; y1 += 10) { |
|||
m->drawFastVLine(x + 45, y1, 5, TFT_DARKGREEN); |
|||
} |
|||
} |
|||
|
|||
void ESPNowRC::show(TFT_eSprite *m) { |
|||
if(espnow2.espnow_begin == false) { |
|||
espnow2.espnow_begin = true; |
|||
Serial.println("ESPNOW Begin"); |
|||
} |
|||
|
|||
if((uint32_t) (millis() - last_updated) > 50) { |
|||
updated = true; |
|||
} |
|||
|
|||
if((uint32_t) (millis() - last_voltage_read) > 500) { |
|||
voltage = roundf(M5.Axp.GetBatVoltage() * 10)/10; |
|||
current = M5.Axp.GetBatCurrent(); |
|||
|
|||
last_voltage_read = millis(); |
|||
} |
|||
|
|||
if(updated) { |
|||
m->fillRect(0, 0, 320, 240, BLACK); |
|||
m->setTextColor(WHITE, BLACK); |
|||
m->setTextSize(2); |
|||
m->setCursor(0, 0); |
|||
m->print("P:"); |
|||
m->print(String(espnow2.sent_counter)); |
|||
|
|||
m->setCursor(240, 0); |
|||
m->printf("CH:%d", espnow2.espnow_channel); |
|||
|
|||
m->setCursor(74, 0); |
|||
m->printf("B:%.1fV %.0fmA", voltage, current); |
|||
// m->printf(String(voltage) + "V " + String(current) + "mA");
|
|||
|
|||
// 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, 90, 0); |
|||
uint16_t left_gimbal_x = map(inputs.yaw, stickcalibration.yaw_min, stickcalibration.yaw_max, 90, 0); |
|||
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(!espnow2.data_to_send.aux[0]) { |
|||
m->drawRect(0, 40, 60, 60, TFT_BLUE); // Button 1 - OFF
|
|||
} else { |
|||
m->drawRect(0, 40, 60, 60, TFT_BLUE); // Button 1 - ON
|
|||
m->fillRect(1, 41, 60, 60, TFT_BLUE); |
|||
} |
|||
|
|||
if(!espnow2.data_to_send.aux[1]) { |
|||
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(!espnow2.data_to_send.aux[2]) { |
|||
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(!espnow2.data_to_send.aux[3]) { |
|||
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(!espnow2.data_to_send.aux[4]) { |
|||
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("ESPNowRC"); |
|||
|
|||
m->pushSprite(0,0); |
|||
|
|||
updated = false; |
|||
last_updated = millis(); |
|||
} |
|||
|
|||
|
|||
// Key Input Handler
|
|||
if(M5.BtnC.wasPressed()) { |
|||
if(espnow2.espnow_begin) { |
|||
espnow2.espnow_begin = false; |
|||
// ble.end();
|
|||
} |
|||
|
|||
screen.current_screen = SCREEN_MENU; |
|||
screen.updated = true; |
|||
} |
|||
|
|||
// 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) { |
|||
espnow2.data_to_send.aux[0] = !espnow2.data_to_send.aux[0]; // Flip Switch 0
|
|||
} else if(e.to.x >= 65 && e.to.x <= 125 && e.to.y >= 40 && e.to.y <= 100) { |
|||
espnow2.data_to_send.aux[1] = !espnow2.data_to_send.aux[1]; // Flip Switch 1
|
|||
} else if(e.to.x >= 130 && e.to.x <= 190 && e.to.y >= 40 && e.to.y <= 100) { |
|||
espnow2.data_to_send.aux[2] = !espnow2.data_to_send.aux[2]; // Flip Switch 2
|
|||
} else if(e.to.x >= 195 && e.to.x <= 255 && e.to.y >= 40 && e.to.y <= 100) { |
|||
espnow2.data_to_send.aux[3] = !espnow2.data_to_send.aux[3]; // Flip Switch 3
|
|||
} else if(e.to.x >= 260 && e.to.x <= 310 && e.to.y >= 40 && e.to.y <= 100) { |
|||
espnow2.data_to_send.aux[4] = !espnow2.data_to_send.aux[4]; // Flip Switch 4
|
|||
} |
|||
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); |
|||
***/ |
|||
} |
|||
|
|||
ESPNowRC espnowrc; |
@ -0,0 +1,36 @@ |
|||
#ifndef _ESPNOWRC_H |
|||
#define _ESPNOWRC_H |
|||
|
|||
#include <Arduino.h> |
|||
#include <M5Core2.h> |
|||
#include "ESPNow2.h" |
|||
#include "Inputs.h" |
|||
#include "Screen.h" |
|||
|
|||
class ESPNowRC { |
|||
public: |
|||
TouchPoint_t coordinate; |
|||
uint32_t touch_time = 0; |
|||
bool updated = false; |
|||
float voltage = 0.00; |
|||
float current = 0.00; |
|||
|
|||
uint32_t last_button1 = 0; |
|||
uint32_t last_button2 = 0; |
|||
uint32_t last_button3 = 0; |
|||
uint32_t last_button4 = 0; |
|||
uint32_t last_button5 = 0; |
|||
uint32_t last_button6 = 0; |
|||
|
|||
ESPNowRC(void); |
|||
void begin(void); |
|||
void show(TFT_eSprite *m); |
|||
void draw_gimbal(TFT_eSprite *m, uint16_t x, uint16_t y); |
|||
|
|||
private: |
|||
uint32_t last_updated = 0; |
|||
uint32_t last_voltage_read = 0; |
|||
}; |
|||
|
|||
extern ESPNowRC espnowrc; |
|||
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue