|
|
@ -26,10 +26,12 @@ RCController::RCController(void) { |
|
|
|
updated = true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RCController::begin(void) { |
|
|
|
updated = true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RCController::draw_gimbal(TFT_eSprite *m, uint16_t x, uint16_t y) { |
|
|
|
// Top
|
|
|
|
m->drawFastHLine(x, y, 90, TFT_DARKGREEN); |
|
|
@ -50,6 +52,26 @@ void RCController::draw_gimbal(TFT_eSprite *m, uint16_t x, uint16_t y) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RCController::draw_gimbal_huge(TFT_eSprite *m, uint16_t x, uint16_t y) { |
|
|
|
// Top
|
|
|
|
m->drawFastHLine(x, y, 120, TFT_DARKGREEN); |
|
|
|
// Bottom
|
|
|
|
m->drawFastHLine(x, y + 119, 120, TFT_DARKGREEN); |
|
|
|
// Left
|
|
|
|
m->drawFastVLine(x, y, 120, TFT_DARKGREEN); |
|
|
|
// Right
|
|
|
|
m->drawFastVLine(x + 119, y, 120, TFT_DARKGREEN); |
|
|
|
|
|
|
|
// Middle dotted lines
|
|
|
|
for(uint16_t x1 = x; x1 < x + 120; x1 += 10) { |
|
|
|
m->drawFastHLine(x1, y + 60, 5, TFT_DARKGREEN); |
|
|
|
} |
|
|
|
for(uint16_t y1 = y; y1 < y + 120; y1 += 10) { |
|
|
|
m->drawFastVLine(x + 60, y1, 5, TFT_DARKGREEN); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RCController::update(void) { |
|
|
|
if(!nrf_begin) { |
|
|
|
return; |
|
|
@ -100,10 +122,33 @@ void RCController::show(TFT_eSprite *m) { |
|
|
|
tx.begin(); |
|
|
|
tx.setAutoAck(false); |
|
|
|
tx.setPayloadSize(sizeof(TxMessage)); |
|
|
|
tx.setChannel(8); ///// Temporary hard code first
|
|
|
|
|
|
|
|
// Reading from File...
|
|
|
|
String channel_str = ""; |
|
|
|
String filename = "/NRF_CHANNEL"; |
|
|
|
if(!storage.exists(filename)) { |
|
|
|
// Default to channel 8. Lucky number?
|
|
|
|
channel = 8; |
|
|
|
storage.writeFile(LITTLEFS, filename, String(channel)); |
|
|
|
} else { |
|
|
|
channel_str = storage.readFile(LITTLEFS, filename); |
|
|
|
channel = channel_str.toInt(); |
|
|
|
} |
|
|
|
tx.setChannel(channel); // Load from settings.
|
|
|
|
tx.setDataRate(RF24_250KBPS); // Lowest.. at 250kbps
|
|
|
|
|
|
|
|
switch(txpower) { // Set the transmit power
|
|
|
|
|
|
|
|
|
|
|
|
String txpower_str = ""; |
|
|
|
filename = "/TXPOWER"; |
|
|
|
if(!storage.exists(filename)) { |
|
|
|
storage.writeFile(LITTLEFS, filename, String(txpower)); |
|
|
|
} else { |
|
|
|
txpower_str = storage.readFile(LITTLEFS, filename); |
|
|
|
txpower = txpower_str.toInt(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch(txpower) { // Set the transmit power
|
|
|
|
case 0: |
|
|
|
tx.setPALevel(RF24_PA_MIN); |
|
|
|
break; |
|
|
@ -154,18 +199,52 @@ void RCController::show(TFT_eSprite *m) { |
|
|
|
// Draw the gimbal box
|
|
|
|
if(rc_screens == RC_SCREEN_GIMBAL) { |
|
|
|
// Showing the settings
|
|
|
|
draw_gimbal(m, 69, 150); |
|
|
|
draw_gimbal(m, 161, 150); |
|
|
|
// draw_gimbal(m, 69, 150);
|
|
|
|
// draw_gimbal(m, 161, 150);
|
|
|
|
draw_gimbal_huge(m, 39, 60); |
|
|
|
draw_gimbal_huge(m, 161, 60); |
|
|
|
|
|
|
|
// 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); |
|
|
|
uint16_t left_gimbal_y = map(inputs.throttle, stickcalibration.throttle_min, stickcalibration.throttle_max, 0, 120); |
|
|
|
uint16_t left_gimbal_x = map(inputs.yaw, stickcalibration.yaw_min, stickcalibration.yaw_max, 0, 120); |
|
|
|
// Invert it
|
|
|
|
left_gimbal_y = 120-left_gimbal_y; |
|
|
|
left_gimbal_x = 120-left_gimbal_x; |
|
|
|
|
|
|
|
m->fillCircle(left_gimbal_x + 39, left_gimbal_y + 60, 5, TFT_YELLOW); |
|
|
|
uint16_t right_gimbal_y = map(inputs.pitch, stickcalibration.pitch_min, stickcalibration.pitch_max, 0, 120); |
|
|
|
uint16_t right_gimbal_x = map(inputs.roll, stickcalibration.roll_min, stickcalibration.roll_max, 0, 120); |
|
|
|
m->fillCircle(right_gimbal_x + 161, right_gimbal_y + 60, 5, TFT_YELLOW); |
|
|
|
|
|
|
|
} if(rc_screens == RC_SCREEN_RADIOSETTINGS) { |
|
|
|
// Display and set the frequency channel and power level
|
|
|
|
m->setCursor(0, 40); |
|
|
|
m->print("Channel: "); |
|
|
|
m->print(String(channel)); |
|
|
|
|
|
|
|
m->setCursor(0, 90); |
|
|
|
m->print("TX Power: "); |
|
|
|
switch(txpower) { |
|
|
|
case 0: |
|
|
|
m->print("MIN"); |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
m->print("LOW"); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
m->print("HIGH"); |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
m->print("MAX"); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
m->drawRect(220, 40, 40, 40, TFT_BLUE); // Channel Increase
|
|
|
|
m->drawRect(280, 40, 40, 40, TFT_BLUE); // Channel Decrease
|
|
|
|
m->drawRect(220, 90, 40, 40, TFT_BLUE); // POWER Increase
|
|
|
|
m->drawRect(280, 90, 40, 40, TFT_BLUE); // POWER Decrease
|
|
|
|
|
|
|
|
} if(rc_screens == RC_SCREEN_MAIN) { |
|
|
|
|
|
|
@ -173,9 +252,9 @@ void RCController::show(TFT_eSprite *m) { |
|
|
|
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
|
|
|
|
m->drawRect(0, 40, 60, 125, TFT_BLUE); // Button 1
|
|
|
|
} else { |
|
|
|
m->drawRect(0, 40, 60, 125, TFT_BLUE); // Button 1
|
|
|
|
m->drawRect(0, 40, 60, 125, TFT_BLUE); // Button 1
|
|
|
|
m->fillRect(1, 41, 58, 123, TFT_BLUE); |
|
|
|
} |
|
|
|
} |
|
|
@ -314,41 +393,125 @@ void RCController::show(TFT_eSprite *m) { |
|
|
|
// - MaxX: 160
|
|
|
|
// - MaxY: 190
|
|
|
|
if(rc_screens == RC_SCREEN_GIMBAL) { |
|
|
|
if(e.to.x >= 110 && e.to.x <= 120 && e.to.y >= 140 && e.to.y <= 180) { |
|
|
|
if(e.to.x >= 60 && e.to.x <= 140 && e.to.y >= 60 && e.to.y <= 110) { |
|
|
|
// Minus throttle
|
|
|
|
// Serial.printf("Left: TOP\n");
|
|
|
|
inputs.trim_throttle-=20; |
|
|
|
inputs.trim_throttle+=10; |
|
|
|
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) { |
|
|
|
storage.writeFile(LITTLEFS, "/TRIM_THROTTLE", String(inputs.trim_throttle)); |
|
|
|
|
|
|
|
} else if(e.to.x >= 60 && e.to.x <= 140 && e.to.y >= 130 && e.to.y <= 180) { |
|
|
|
// Add throttle
|
|
|
|
// Serial.printf("Left: BOTTOM\n");
|
|
|
|
inputs.trim_throttle+=20; |
|
|
|
inputs.trim_throttle-=10; |
|
|
|
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) { |
|
|
|
storage.writeFile(LITTLEFS, "/TRIM_THROTTLE", String(inputs.trim_throttle)); |
|
|
|
|
|
|
|
} else if(e.to.x >= 40 && e.to.x <= 90 && e.to.y >= 80 && e.to.y <= 160) { |
|
|
|
// Minus Yaw
|
|
|
|
// Serial.printf("Left: LEFT\n");
|
|
|
|
inputs.trim_yaw-=20; |
|
|
|
inputs.trim_yaw+=10; |
|
|
|
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) { |
|
|
|
storage.writeFile(LITTLEFS, "/TRIM_YAW", String(inputs.trim_yaw)); |
|
|
|
|
|
|
|
} else if(e.to.x >= 110 && e.to.x <= 160 && e.to.y >= 80 && e.to.y <= 160) { |
|
|
|
// Add Yaw
|
|
|
|
// Serial.printf("Left: RIGHT\n");
|
|
|
|
inputs.trim_yaw+=20; |
|
|
|
inputs.trim_yaw-=10; |
|
|
|
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; |
|
|
|
storage.writeFile(LITTLEFS, "/TRIM_YAW", String(inputs.trim_yaw)); |
|
|
|
|
|
|
|
} else if(e.to.x >= 230 && e.to.x <= 280 && e.to.y >= 80 && e.to.y <= 160) { |
|
|
|
// Add Roll
|
|
|
|
inputs.trim_roll+=10; |
|
|
|
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; |
|
|
|
storage.writeFile(LITTLEFS, "/TRIM_ROLL", String(inputs.trim_roll)); |
|
|
|
|
|
|
|
} else if(e.to.x >= 160 && e.to.x <= 210 && e.to.y >= 80 && e.to.y <= 160) { |
|
|
|
// Minus Roll
|
|
|
|
inputs.trim_roll-=10; |
|
|
|
speak.speak_trim_word = TRIM_ROLL_DECREASE; |
|
|
|
speak.speak_now_trim = true; |
|
|
|
storage.writeFile(LITTLEFS, "/TRIM_ROLL", String(inputs.trim_roll)); |
|
|
|
|
|
|
|
} else if(e.to.x >= 180 && e.to.x <= 260 && e.to.y >= 60 && e.to.y <= 110) { |
|
|
|
// Add Pitch
|
|
|
|
inputs.trim_pitch-=10; |
|
|
|
speak.speak_trim_word = TRIM_PITCH_INCREASE; |
|
|
|
speak.speak_now_trim = true; |
|
|
|
storage.writeFile(LITTLEFS, "/TRIM_PITCH", String(inputs.trim_pitch)); |
|
|
|
|
|
|
|
} else if(e.to.x >= 180 && e.to.x <= 260 && e.to.y >= 130 && e.to.y <= 180) { |
|
|
|
// Minus Pitch
|
|
|
|
inputs.trim_pitch+=10; |
|
|
|
speak.speak_trim_word = TRIM_PITCH_DECREASE; |
|
|
|
speak.speak_now_trim = true; |
|
|
|
storage.writeFile(LITTLEFS, "/TRIM_PITCH", String(inputs.trim_pitch)); |
|
|
|
|
|
|
|
} |
|
|
|
} else if(rc_screens == RC_SCREEN_RADIOSETTINGS) { |
|
|
|
if(e.to.x >= 220 && e.to.x <= 260 && e.to.y >= 40 && e.to.y <= 80) { |
|
|
|
channel++; |
|
|
|
if(channel > 125) channel = 125; |
|
|
|
String filename = "/NRF_CHANNEL"; |
|
|
|
storage.writeFile(LITTLEFS, filename, String(channel)); |
|
|
|
tx.setChannel(channel); |
|
|
|
} else if(e.to.x >= 280 && e.to.x <= 320 && e.to.y >= 40 && e.to.y <= 80) { |
|
|
|
channel--; |
|
|
|
if(channel == 0) channel++; |
|
|
|
String filename = "/NRF_CHANNEL"; |
|
|
|
storage.writeFile(LITTLEFS, filename, String(channel)); |
|
|
|
tx.setChannel(channel); |
|
|
|
} else if(e.to.x >= 220 && e.to.x <= 260 && e.to.y >= 90 && e.to.y <= 130) { |
|
|
|
txpower++; |
|
|
|
if(txpower == 4) { |
|
|
|
txpower = 3; |
|
|
|
} else { |
|
|
|
String filename = "/TXPOWER"; |
|
|
|
storage.writeFile(LITTLEFS, filename, String(txpower)); |
|
|
|
switch(txpower) { // Set the transmit power
|
|
|
|
case 0: |
|
|
|
tx.setPALevel(RF24_PA_MIN); |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
tx.setPALevel(RF24_PA_LOW); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
tx.setPALevel(RF24_PA_HIGH); |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
tx.setPALevel(RF24_PA_MAX); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if(e.to.x >= 280 && e.to.x <= 320 && e.to.y >= 90 && e.to.y <= 130) { |
|
|
|
if(txpower != 0) { |
|
|
|
txpower--; |
|
|
|
String filename = "/TXPOWER"; |
|
|
|
storage.writeFile(LITTLEFS, filename, String(txpower)); |
|
|
|
switch(txpower) { // Set the transmit power
|
|
|
|
case 0: |
|
|
|
tx.setPALevel(RF24_PA_MIN); |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
tx.setPALevel(RF24_PA_LOW); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
tx.setPALevel(RF24_PA_HIGH); |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
tx.setPALevel(RF24_PA_MAX); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} 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
|
|
|
|