From 771925a3d2e56f25e589d3bc618e19dcd15ec3ad Mon Sep 17 00:00:00 2001 From: Englebert <=> Date: Tue, 21 Mar 2023 23:55:24 +0800 Subject: [PATCH] Running ESPNow --- openscad/BoxMode.scad | 23 ++++++++++++----------- src/ESPNow.cpp | 9 +++++---- src/ESPNowRC.cpp | 9 +++++++++ src/ESPNowRC.h | 2 ++ src/Screen.cpp | 4 ++++ 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/openscad/BoxMode.scad b/openscad/BoxMode.scad index b702e8a..15b7f93 100644 --- a/openscad/BoxMode.scad +++ b/openscad/BoxMode.scad @@ -58,11 +58,12 @@ translate([-23.5,-70,13]) /******* Modules *******/ module gimbal_back() { difference() { - cube([70,70,13], center=true); + translate([0,0,-2]) + cube([70,70,9], center=true); translate([0,0,0.76]) cube([62.5,62.5,11.5], center=true); translate([0,30,4]) - cube([20,20,7], center=true); + cube([20,20,12], center=true); // Corners @@ -80,18 +81,18 @@ module gimbal_back() { cube([10,10,40], center=true); } - translate([0,-30.7,4]) - cube([62,1,20], center=true); - translate([0,30.7,4]) + translate([0,-30.7,1]) + cube([62,1,12], center=true); + translate([0,30.7,1]) difference() { - cube([62,1,20], center=true); + cube([62,1,12], center=true); translate([0,0,0]); - cube([25,20,100], center=true); + cube([20,20,100], center=true); } - translate([30.7,0,4]) - cube([1,62.4,20], center=true); - translate([-30.7,0,4]) - cube([1,62.4,20], center=true); + translate([30.7,0,1]) + cube([1,62.4,12], center=true); + translate([-30.7,0,1]) + cube([1,62.4,12], center=true); } module m5_back() { diff --git a/src/ESPNow.cpp b/src/ESPNow.cpp index b65e987..de3594a 100644 --- a/src/ESPNow.cpp +++ b/src/ESPNow.cpp @@ -90,10 +90,11 @@ void ESPNow2::update(void) { } else { if((uint32_t)(millis() - last_updated) > 1) { data_to_send.message_type = DATA; - data_to_send.throttle = map(inputs.throttle, 0, 4096, 1000, 2000); // Throttle - data_to_send.yaw = map(inputs.yaw, 0, 4096, 1000, 2000); // Yaw - data_to_send.pitch = map(inputs.pitch, 0, 4096, 1000, 2000); // Pitch - data_to_send.roll = map(inputs.roll, 0, 4096, 1000, 2000); // Roll + + data_to_send.throttle = map(inputs.throttle, stickcalibration.throttle_min, stickcalibration.throttle_max, 1000, 2000); // Throttle + data_to_send.yaw = map(inputs.yaw, stickcalibration.yaw_min, stickcalibration.yaw_max, 1000, 2000); // Yaw + data_to_send.pitch = map(inputs.pitch, stickcalibration.pitch_min, stickcalibration.pitch_max, 1000, 2000); // Pitch + data_to_send.roll = map(inputs.roll, stickcalibration.roll_min, stickcalibration.roll_max, 1000, 2000); // Roll // Sending Data esp_now_send(destination_server_address, (uint8_t *) &data_to_send, sizeof(data_to_send)); diff --git a/src/ESPNowRC.cpp b/src/ESPNowRC.cpp index ad2fbca..dc45c1d 100644 --- a/src/ESPNowRC.cpp +++ b/src/ESPNowRC.cpp @@ -28,6 +28,12 @@ void ESPNowRC::draw_gimbal(TFT_eSprite *m, uint16_t x, uint16_t y) { } void ESPNowRC::show(TFT_eSprite *m) { + if((uint32_t) (millis() - last_uptime) >= 1000) { + uptime++; + + last_uptime = millis(); + } + if(espnow2.espnow_begin == false) { espnow2.espnow_begin = true; Serial.println("ESPNOW Begin"); @@ -55,6 +61,9 @@ void ESPNowRC::show(TFT_eSprite *m) { m->setCursor(240, 0); m->printf("CH:%d", espnow2.espnow_channel); + m->setCursor(0, 16); + m->printf("Uptime: %d", uptime); + m->setCursor(74, 0); m->printf("B:%.1fV %.0fmA", voltage, current); // m->printf(String(voltage) + "V " + String(current) + "mA"); diff --git a/src/ESPNowRC.h b/src/ESPNowRC.h index 25b9f56..916f6c6 100644 --- a/src/ESPNowRC.h +++ b/src/ESPNowRC.h @@ -30,6 +30,8 @@ class ESPNowRC { private: uint32_t last_updated = 0; uint32_t last_voltage_read = 0; + uint32_t uptime = 0; + uint32_t last_uptime = 0; }; extern ESPNowRC espnowrc; diff --git a/src/Screen.cpp b/src/Screen.cpp index 66bd96b..31cd4c8 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -140,10 +140,12 @@ void Screen::menu(void) { mainscreen_buffer.drawFastHLine(250, 239, 20, TFT_WHITE); // Just Title + /** mainscreen_buffer.setTextColor(WHITE, RED); mainscreen_buffer.setTextSize(4); mainscreen_buffer.setCursor(0, 183); mainscreen_buffer.printf("FPVController"); + **/ mainscreen_buffer.pushSprite(0,0); @@ -214,6 +216,7 @@ void Screen::menu_reboot(void) { mainscreen_buffer.fillRoundRect(51, 51, 218, 138, 10, DIALOGBOX_BACKGROUND); // Show Text + mainscreen_buffer.setTextSize(2); mainscreen_buffer.setTextColor(DIALOGBOX_FOREGROUND, DIALOGBOX_BACKGROUND); mainscreen_buffer.setCursor(68, 110); mainscreen_buffer.print("Reboot Now? "); @@ -267,6 +270,7 @@ void Screen::menu_poweroff(void) { mainscreen_buffer.fillRoundRect(51, 51, 218, 138, 10, DIALOGBOX_BACKGROUND); // Show Text + mainscreen_buffer.setTextSize(2); mainscreen_buffer.setTextColor(DIALOGBOX_FOREGROUND, DIALOGBOX_BACKGROUND); mainscreen_buffer.setCursor(68, 110); mainscreen_buffer.print("Power Off? ");