diff --git a/lib/battery/battery.cpp b/lib/battery/battery.cpp index 33010b99..473306bd 100644 --- a/lib/battery/battery.cpp +++ b/lib/battery/battery.cpp @@ -9,73 +9,71 @@ #include "battery.hpp" -/** - * @brief Battery values - * - */ -uint8_t battLevel = 0; -uint8_t battLevelOld = 0; -float batteryMax = 4.2; // maximum voltage of battery -float batteryMin = 3.6; // minimum voltage of battery before shutdown +Battery::Battery() {} /** * @brief Configure ADC Channel for battery reading * */ -void initADC() +void Battery::initADC() { - // When VDD_A is 3.3V: - // 0dB attenuation (ADC_ATTEN_DB_0) gives full-scale voltage 1.1V - // 2.5dB attenuation (ADC_ATTEN_DB_2_5) gives full-scale voltage 1.5V - // 6dB attenuation (ADC_ATTEN_DB_6) gives full-scale voltage 2.2V - // 12dB attenuation (ADC_ATTEN_DB_12) gives full-scale voltage 3.9V - - #ifdef ADC1 +#ifdef ADC1 adc1_config_width(ADC_WIDTH_BIT_12); - adc1_config_channel_atten(BATT_PIN, ADC_ATTEN_DB_12); - #endif + adc1_config_channel_atten(BATT_PIN, ADC_ATTEN_DB_12); +#endif - #ifdef ADC2 +#ifdef ADC2 adc2_config_channel_atten(BATT_PIN, ADC_ATTEN_DB_12); - #endif +#endif +} + +/** + * @brief Set battery voltage levels + * + * @param maxVoltage -> Full Charge voltage + * @param minVoltage -> Min Charge voltage + */ +void Battery::setBatteryLevels(float maxVoltage, float minVoltage) +{ + batteryMax = maxVoltage; + batteryMin = minVoltage; } /** - * @brief Read battery charge and return % + * @brief Read battery charge and return %. * * @return float -> % Charge */ -float batteryRead() +float Battery::readBattery() { - long sum = 0; // sum of samples taken - float voltage = 0.0; // calculated voltage - float output = 0.0; // output value - for (int i = 0; i < 100; i++) - { + long sum = 0; // Sum of samples taken + float voltage = 0.0; // Calculated voltage + float output = 0.0; // Output value + + for (int i = 0; i < 100; i++) + { + #ifdef ADC1 + sum += static_cast(adc1_get_raw(BATT_PIN)); + #endif + + #ifdef ADC2 + int readRaw; + esp_err_t r = adc2_get_raw(BATT_PIN, ADC_WIDTH_BIT_12, &readRaw); + if (r == ESP_OK) + sum += static_cast(readRaw); + #endif - #ifdef ADC1 - sum += (long)adc1_get_raw(BATT_PIN); - #endif + delayMicroseconds(150); + } - #ifdef ADC2 - int readRaw; - esp_err_t r = adc2_get_raw(BATT_PIN, ADC_WIDTH_BIT_12, &readRaw); - if (r == ESP_OK) - sum += (long)readRaw; - #endif + voltage = sum / 100.0; + // Custom board has a divider circuit + constexpr float R1 = 100000.0; // Resistance of R1 (100K) + constexpr float R2 = 100000.0; // Resistance of R2 (100K) + voltage = (voltage * V_REF) / 4096.0; + voltage = voltage / (R2 / (R1 + R2)); + voltage = roundf(voltage * 100) / 100; - delayMicroseconds(150); - } - voltage = sum / (float)100; - // custom board has a divider circuit - float R1 = 100000.0; // resistance of R1 (100K) - float R2 = 100000.0; // resistance of R2 (100K) - voltage = (voltage * V_REF) / 4096.0; - voltage = voltage / (R2 / (R1 + R2)); - voltage = roundf(voltage * 100) / 100; - output = ((voltage - batteryMin) / (batteryMax - batteryMin)) * 100; - if (output <= 160) - return output; - else - return 0.0f; + output = ((voltage - batteryMin) / (batteryMax - batteryMin)) * 100; + return (output <= 160) ? output : 0.0f; } diff --git a/lib/battery/battery.hpp b/lib/battery/battery.hpp index b972fe63..072f360e 100644 --- a/lib/battery/battery.hpp +++ b/lib/battery/battery.hpp @@ -13,16 +13,19 @@ #include #include -static esp_adc_cal_characteristics_t characteristics; -#define V_REF 3.9 // ADC reference voltage +class Battery +{ +private: + float batteryMax; + float batteryMin; + static constexpr float V_REF = 3.9; // ADC reference voltage -extern float batteryMax; // 4.2; // maximum voltage of battery -extern float batteryMin; // 3.6; // minimum voltage of battery before shutdown +public: + Battery(); -extern uint8_t battLevel; -extern uint8_t battLevelOld; - -void initADC(); -float batteryRead(); + void initADC(); + void setBatteryLevels(float maxVoltage, float minVoltage); + float readBattery(); +}; #endif diff --git a/lib/cli/cli.cpp b/lib/cli/cli.cpp index 55895c8d..e0be1bd6 100644 --- a/lib/cli/cli.cpp +++ b/lib/cli/cli.cpp @@ -22,6 +22,8 @@ const char logo[] = "" ; +extern Power power; + /** * @brief Reboot ESP */ @@ -35,7 +37,7 @@ void wcli_reboot(char *args, Stream *response) */ void wcli_poweroff(char *args, Stream *response) { - deviceShutdown(); + power.deviceShutdown(); } /** diff --git a/lib/gpx/src/addWaypoint.cpp b/lib/gpx/src/addWaypoint.cpp index 4e9a5d48..b2355171 100644 --- a/lib/gpx/src/addWaypoint.cpp +++ b/lib/gpx/src/addWaypoint.cpp @@ -8,7 +8,7 @@ #include "addWaypoint.hpp" -extern const int SD_CS; +extern const uint8_t SD_CS; wayPoint addWpt = {0, 0, 0, (char *)"", (char *)"", (char *)"", (char *)"", (char *)"", (char *)"", 0, 0, 0, 0}; wayPoint loadWpt = {0, 0, 0, (char *)"", (char *)"", (char *)"", (char *)"", (char *)"", (char *)"", 0, 0, 0, 0}; diff --git a/lib/gpx/src/addWaypoint.hpp b/lib/gpx/src/addWaypoint.hpp index 9a01b9cd..2ae526cf 100644 --- a/lib/gpx/src/addWaypoint.hpp +++ b/lib/gpx/src/addWaypoint.hpp @@ -9,12 +9,8 @@ #ifndef ADDWAYPOINT_HPP #define ADDWAYPOINT_HPP -#include "globalGpxDef.h" #include "SD.h" -#include "FS.h" -#include "tft.hpp" -#include "storage.hpp" -#include "lvgl.h" +#include "globalGpxDef.h" extern wayPoint addWpt; diff --git a/lib/gpx/src/deleteWaypoint.hpp b/lib/gpx/src/deleteWaypoint.hpp index 1111f5a0..a610cf04 100644 --- a/lib/gpx/src/deleteWaypoint.hpp +++ b/lib/gpx/src/deleteWaypoint.hpp @@ -10,10 +10,6 @@ #define DELETEWAYPOINT_HPP #include "SD.h" -#include "FS.h" -#include "tft.hpp" -#include "storage.hpp" -#include "globalGuiDef.h" #include "globalGpxDef.h" void deleteWaypointName(char * wpt); diff --git a/lib/gpx/src/editWaypoint.hpp b/lib/gpx/src/editWaypoint.hpp index 281742e0..e8b9ee31 100644 --- a/lib/gpx/src/editWaypoint.hpp +++ b/lib/gpx/src/editWaypoint.hpp @@ -10,10 +10,6 @@ #define EDITWAYPOINT_HPP #include "SD.h" -#include "FS.h" -#include "tft.hpp" -#include "storage.hpp" -#include "globalGuiDef.h" #include "globalGpxDef.h" void editWaypointName(char* oldName, char *newName); diff --git a/lib/gpx/src/loadWaypoint.hpp b/lib/gpx/src/loadWaypoint.hpp index f27460b5..1fcfadf7 100644 --- a/lib/gpx/src/loadWaypoint.hpp +++ b/lib/gpx/src/loadWaypoint.hpp @@ -9,11 +9,6 @@ #ifndef LOADWAYPOINT_HPP #define LOADWAYPOINT_HPP -#include "SD.h" -#include "FS.h" -#include "tft.hpp" -#include "storage.hpp" -#include "globalGuiDef.h" #include "globalGpxDef.h" extern wayPoint loadWpt; diff --git a/lib/gui/src/buttonBar.cpp b/lib/gui/src/buttonBar.cpp index 46aa87d1..f7bc133e 100644 --- a/lib/gui/src/buttonBar.cpp +++ b/lib/gui/src/buttonBar.cpp @@ -7,10 +7,6 @@ */ #include "buttonBar.hpp" -#include "waypointScr.hpp" -#include "waypointListScr.hpp" -#include "display/lv_display.h" -#include "globalGuiDef.h" bool isWaypointOpt = false; bool isTrackOpt = false; @@ -59,7 +55,6 @@ void buttonBarEvent(lv_event_t *event) if (strcmp(option,"waypoint") == 0) { log_v("Waypoint"); - // isMainScreen = false; isWaypointOpt = true; isTrackOpt = false; if (!isOptionLoaded) diff --git a/lib/gui/src/buttonBar.hpp b/lib/gui/src/buttonBar.hpp index 24f9a1db..30a579f3 100644 --- a/lib/gui/src/buttonBar.hpp +++ b/lib/gui/src/buttonBar.hpp @@ -11,6 +11,8 @@ #include "globalGuiDef.h" #include "mainScr.hpp" +#include "waypointScr.hpp" +#include "waypointListScr.hpp" static const char *waypointIconFile PROGMEM = "/wpt.bin"; // Waypoint icon static const char *trackIconFile PROGMEM = "/track.bin"; // Track icon diff --git a/lib/gui/src/deviceSettingsScr.cpp b/lib/gui/src/deviceSettingsScr.cpp index 00c2b7c3..3ad66778 100644 --- a/lib/gui/src/deviceSettingsScr.cpp +++ b/lib/gui/src/deviceSettingsScr.cpp @@ -7,7 +7,6 @@ */ #include "deviceSettingsScr.hpp" -#include "globalGuiDef.h" lv_obj_t *deviceSettingsScreen; // Device Settings Screen diff --git a/lib/gui/src/deviceSettingsScr.hpp b/lib/gui/src/deviceSettingsScr.hpp index 248d6147..5ecec47d 100644 --- a/lib/gui/src/deviceSettingsScr.hpp +++ b/lib/gui/src/deviceSettingsScr.hpp @@ -10,8 +10,6 @@ #define DEVICESETTINGSCR_HPP #include "globalGuiDef.h" -#include "gps.hpp" -#include "settings.hpp" #include "lvglSetup.hpp" static lv_obj_t *deviceSettingsOptions; diff --git a/lib/gui/src/globalGuiDef.h b/lib/gui/src/globalGuiDef.h index 92a12d53..858caf17 100644 --- a/lib/gui/src/globalGuiDef.h +++ b/lib/gui/src/globalGuiDef.h @@ -89,14 +89,9 @@ static bool getPngSize(const char* filename, uint16_t *width, uint16_t *height) return false; } - byte table[32]; + uint8_t table[32]; - // for (int i = 0; file.available() && i < 32; i++) - // { - // table[i] = file.read(); - // } - - fread(table, sizeof(byte), 32, file); + fread(table, sizeof(uint8_t), 32, file); *width=table[16]*256*256*256+table[17]*256*256+table[18]*256+table[19]; *height=table[20]*256*256*256+table[21]*256*256+table[22]*256+table[23]; diff --git a/lib/gui/src/mainScr.cpp b/lib/gui/src/mainScr.cpp index 1627d2d1..dab9ec3f 100644 --- a/lib/gui/src/mainScr.cpp +++ b/lib/gui/src/mainScr.cpp @@ -7,16 +7,6 @@ */ #include "mainScr.hpp" -#include "buttonBar.hpp" -#include "core/lv_obj.h" -#include "core/lv_obj_pos.h" -#include "globalGuiDef.h" -#include "globalMapsDef.h" -#include "settings.hpp" -#include "tft.hpp" - -extern const int SD_CS; -extern const uint8_t TFT_SPI_CS; bool isMainScreen = false; // Flag to indicate main screen is selected bool isScrolled = true; // Flag to indicate when tileview was scrolled @@ -27,12 +17,12 @@ uint8_t wptAction = WPT_NONE; // Current Waypoint Action int wptPosX, wptPosY = 0; // Waypoint position on map #ifdef LARGE_SCREEN - int toolBarOffset = 100; - int toolBarSpace = 60; + uint8_t toolBarOffset = 100; + uint8_t toolBarSpace = 60; #endif #ifndef LARGE_SCREEN - int toolBarOffset = 80; - int toolBarSpace = 50; + uint8_t toolBarOffset = 80; + uint8_t toolBarSpace = 50; #endif lv_obj_t *tilesScreen; @@ -59,10 +49,8 @@ void updateCompassScr(lv_event_t * event) lv_obj_t *obj = (lv_obj_t *)lv_event_get_current_target(event); if (obj==compassHeading) { - //#ifdef ENABLE_COMPASS lv_label_set_text_fmt(compassHeading, "%5d\xC2\xB0", heading); lv_img_set_angle(compassImg, -(heading * 10)); - //#endif } if (obj==latitude) lv_label_set_text_fmt(latitude, "%s", latFormatString(gpsData.latitude)); @@ -86,11 +74,6 @@ void getActTile(lv_event_t *event) isScrolled = true; redrawMap = true; - if (activeTile == SATTRACK) - { - // createSatSprite(spriteSat); - // createConstelSprite(constelSprite); - } if (activeTile == MAP) { createMapScrSprites(); @@ -206,7 +189,6 @@ void updateMainScreen(lv_timer_t *t) */ void gestureEvent(lv_event_t *event) { - lv_obj_t *screen = (lv_obj_t *)lv_event_get_current_target(event); lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act()); if (activeTile == MAP && isMainScreen) { @@ -241,8 +223,6 @@ void updateMap(lv_event_t *event) getMapBlocks(viewPort.bbox, memCache); - // deleteMapScrSprites(); - // createMapScrSprites(); generateVectorMap(viewPort, memCache, mapTempSprite); isPosMoved = false; @@ -419,9 +399,7 @@ void updateNavEvent(lv_event_t *event) if (wptDistance == 0) { lv_img_set_src(arrowNav, &navfinish); - //#ifdef ENABLE_COMPASS lv_img_set_angle(arrowNav, 0); - //#endif } else { diff --git a/lib/gui/src/mainScr.hpp b/lib/gui/src/mainScr.hpp index 4d8c9f2e..a147f139 100644 --- a/lib/gui/src/mainScr.hpp +++ b/lib/gui/src/mainScr.hpp @@ -10,13 +10,9 @@ #define MAINSCR_HPP #include "globalGuiDef.h" -#include "lvglFuncs.hpp" -#include "misc/lv_color.h" -#include "notifyBar.hpp" #include "buttonBar.hpp" #include "renderMaps.hpp" #include "vectorMaps.hpp" -#include "addWaypoint.hpp" #include "loadWaypoint.hpp" #include "deleteWaypoint.hpp" #include "editWaypoint.hpp" @@ -57,13 +53,14 @@ extern lv_obj_t *satTrackTile; extern lv_obj_t *btnFullScreen; extern lv_obj_t *btnZoomIn; extern lv_obj_t *btnZoomOut; -extern int toolBarOffset; -extern int toolBarSpace; +extern uint8_t toolBarOffset; +extern uint8_t toolBarSpace; void updateCompassScr(lv_event_t * event); void deleteMapScrSprites(); void createMapScrSprites(); +void displayMap(uint16_t tileSize); void getActTile(lv_event_t *event); void scrollTile(lv_event_t *event); diff --git a/lib/gui/src/mapSettingsScr.cpp b/lib/gui/src/mapSettingsScr.cpp index 110ff6a2..29db0312 100644 --- a/lib/gui/src/mapSettingsScr.cpp +++ b/lib/gui/src/mapSettingsScr.cpp @@ -7,8 +7,6 @@ */ #include "mapSettingsScr.hpp" -#include "core/lv_obj.h" -#include "settings.hpp" lv_obj_t *mapSettingsScreen; // Map Settings Screen diff --git a/lib/gui/src/mapSettingsScr.hpp b/lib/gui/src/mapSettingsScr.hpp index e09a6eac..6168abf5 100644 --- a/lib/gui/src/mapSettingsScr.hpp +++ b/lib/gui/src/mapSettingsScr.hpp @@ -10,7 +10,6 @@ #define MAPSETTINGSCR_HPP #include "globalGuiDef.h" -#include "settings.hpp" #include "lvglFuncs.hpp" #include "vectorMaps.hpp" #include "renderMaps.hpp" diff --git a/lib/gui/src/navScr.hpp b/lib/gui/src/navScr.hpp index b53b8f69..5fea2489 100644 --- a/lib/gui/src/navScr.hpp +++ b/lib/gui/src/navScr.hpp @@ -9,7 +9,6 @@ #ifndef NAVSCR_HPP #define NAVSCR_HPP -#include "lvgl.h" #include "globalGuiDef.h" #include "navup.c" diff --git a/lib/gui/src/notifyBar.cpp b/lib/gui/src/notifyBar.cpp index cbcebce9..507d67fd 100644 --- a/lib/gui/src/notifyBar.cpp +++ b/lib/gui/src/notifyBar.cpp @@ -7,13 +7,14 @@ */ #include "notifyBar.hpp" -#include "font/lv_symbol_def.h" -#include "misc/lv_event.h" lv_obj_t *mainScreen; lv_obj_t *notifyBarIcons; lv_obj_t *notifyBarHour; +Storage storage; +Battery battery; + /** * @brief Update notify bar event * @@ -34,7 +35,7 @@ void updateNotifyBar(lv_event_t *event) if (obj == gpsCount) lv_label_set_text_fmt(obj, LV_SYMBOL_GPS "%2d", gpsData.satellites); - if (obj == battery) + if (obj == battIcon) { if (battLevel <= 160 && battLevel > 140) lv_label_set_text_static(obj, " " LV_SYMBOL_CHARGE); @@ -115,10 +116,10 @@ void updateNotifyBarTimer(lv_timer_t *t) } #endif - battLevel = batteryRead(); + battLevel = battery.readBattery(); if (battLevel != battLevelOld) { - lv_obj_send_event(battery, LV_EVENT_VALUE_CHANGED, NULL); + lv_obj_send_event(battIcon, LV_EVENT_VALUE_CHANGED, NULL); battLevelOld = battLevel; } } @@ -151,8 +152,6 @@ void createNotifyBar() lv_obj_add_style(notifyBarIcons, &styleBar, LV_PART_MAIN); lv_obj_add_style(notifyBarHour, &styleBar, LV_PART_MAIN); - lv_obj_t *label; - gpsTime = lv_label_create(notifyBarHour); lv_obj_set_style_text_font(gpsTime, fontLarge, 0); lv_label_set_text_fmt(gpsTime, timeFormat, 0, 0, 0); @@ -168,7 +167,7 @@ void createNotifyBar() lv_obj_add_event_cb(temp, updateNotifyBar, LV_EVENT_VALUE_CHANGED, NULL); #endif - if (isSdLoaded) + if (storage.getSdLoaded()) { sdCard = lv_label_create(notifyBarIcons); lv_label_set_text_static(sdCard, LV_SYMBOL_SD_CARD); @@ -188,9 +187,9 @@ void createNotifyBar() lv_label_set_text_static(gpsFixMode, "----"); lv_obj_add_event_cb(gpsFixMode, updateNotifyBar, LV_EVENT_VALUE_CHANGED, NULL); - battery = lv_label_create(notifyBarIcons); - lv_label_set_text_static(battery, LV_SYMBOL_BATTERY_EMPTY); - lv_obj_add_event_cb(battery, updateNotifyBar, LV_EVENT_VALUE_CHANGED, NULL); + battIcon = lv_label_create(notifyBarIcons); + lv_label_set_text_static(battIcon, LV_SYMBOL_BATTERY_EMPTY); + lv_obj_add_event_cb(battIcon, updateNotifyBar, LV_EVENT_VALUE_CHANGED, NULL); lv_timer_t *timerNotifyBar = lv_timer_create(updateNotifyBarTimer, UPDATE_NOTIFY_PERIOD, NULL); lv_timer_ready(timerNotifyBar); diff --git a/lib/gui/src/notifyBar.hpp b/lib/gui/src/notifyBar.hpp index 470bb14d..cb7c5e7b 100644 --- a/lib/gui/src/notifyBar.hpp +++ b/lib/gui/src/notifyBar.hpp @@ -9,10 +9,11 @@ #ifndef NOTIFYBAR_HPP #define NOTIFYBAR_HPP -#include #include "globalGuiDef.h" #include "tasks.hpp" #include "storage.hpp" +#include "battery.hpp" +#include "settings.hpp" /** * @brief Notify Bar screen objects @@ -22,11 +23,14 @@ static lv_obj_t *gpsTime; // Time static lv_obj_t *gpsCount; // Satellite count static lv_obj_t *gpsFix; // Satellite fix static lv_obj_t *gpsFixMode; // Satellite fix mode -static lv_obj_t *battery; // Battery level +static lv_obj_t *battIcon; // Battery level static lv_obj_t *sdCard; // SD card icon static lv_obj_t *temp; // Temperature static lv_obj_t *wifi; // Wifi +static float battLevel = 0; +static float battLevelOld = 0; + #define UPDATE_NOTIFY_PERIOD 1000 // Notify Bar update time /** diff --git a/lib/gui/src/satInfoScr.cpp b/lib/gui/src/satInfoScr.cpp index c418a9b0..cfd41f9b 100644 --- a/lib/gui/src/satInfoScr.cpp +++ b/lib/gui/src/satInfoScr.cpp @@ -35,7 +35,6 @@ void drawTextOnLayer(const char * text, lv_layer_t * layer, lv_point_t * p, lv_a lv_draw_rect_dsc_t draw_rect_dsc; lv_draw_rect_dsc_init(&draw_rect_dsc); - //draw_rect_dsc.bg_color = lv_color_black(); draw_rect_dsc.bg_opa = LV_OPA_TRANSP; draw_rect_dsc.radius = 0; draw_rect_dsc.bg_image_symbol_font = font; diff --git a/lib/gui/src/satInfoScr.hpp b/lib/gui/src/satInfoScr.hpp index e66c44e4..ac98ccfd 100644 --- a/lib/gui/src/satInfoScr.hpp +++ b/lib/gui/src/satInfoScr.hpp @@ -9,7 +9,6 @@ #ifndef SATINFOSCR_HPP #define SATINFOSCR_HPP -#include "lvgl.h" #include "globalGuiDef.h" #include "gps.hpp" diff --git a/lib/gui/src/searchSatScr.cpp b/lib/gui/src/searchSatScr.cpp index 87bdb7b3..596e92ab 100644 --- a/lib/gui/src/searchSatScr.cpp +++ b/lib/gui/src/searchSatScr.cpp @@ -26,7 +26,6 @@ void buttonEvent(lv_event_t *event) } if (strcmp(option,"settings") == 0) { - //isMainScreen = false; lv_screen_load(settingsScreen); } } diff --git a/lib/gui/src/searchSatScr.hpp b/lib/gui/src/searchSatScr.hpp index 489b8335..5f211cac 100644 --- a/lib/gui/src/searchSatScr.hpp +++ b/lib/gui/src/searchSatScr.hpp @@ -9,7 +9,6 @@ #ifndef SEARCHSATSCR_HPP #define SEARCHSATSCR_HPP -#include #include "gps.hpp" #include "globalGuiDef.h" diff --git a/lib/gui/src/settingsScr.cpp b/lib/gui/src/settingsScr.cpp index 37fb9ae0..c55e26b9 100644 --- a/lib/gui/src/settingsScr.cpp +++ b/lib/gui/src/settingsScr.cpp @@ -7,7 +7,6 @@ */ #include "settingsScr.hpp" -#include "globalGuiDef.h" bool needReboot = false; diff --git a/lib/gui/src/settingsScr.hpp b/lib/gui/src/settingsScr.hpp index 40ee59b7..c68ee7bf 100644 --- a/lib/gui/src/settingsScr.hpp +++ b/lib/gui/src/settingsScr.hpp @@ -11,9 +11,7 @@ #include "globalGuiDef.h" #include "mainScr.hpp" -#include "compass.hpp" #include "searchSatScr.hpp" -#include "settings.hpp" void loadMainScreen(); diff --git a/lib/gui/src/splashScr.hpp b/lib/gui/src/splashScr.hpp index b1519785..61d22b61 100644 --- a/lib/gui/src/splashScr.hpp +++ b/lib/gui/src/splashScr.hpp @@ -9,7 +9,6 @@ #ifndef SPLASHSCR_HPP #define SPLASHSCR_HPP -#include "tft.hpp" #include "globalGuiDef.h" #include "settings.hpp" diff --git a/lib/gui/src/waypointListScr.hpp b/lib/gui/src/waypointListScr.hpp index 31f566ae..db3599b9 100644 --- a/lib/gui/src/waypointListScr.hpp +++ b/lib/gui/src/waypointListScr.hpp @@ -9,11 +9,7 @@ #ifndef WAYPOINTLISTSCR_HPP #define WAYPOINTLISTSCR_HPP -#include "globalGuiDef.h" -#include "globalGpxDef.h" #include "mainScr.hpp" -#include "storage.hpp" -#include void loadMainScreen(); void updateWaypointPos(); diff --git a/lib/gui/src/waypointScr.cpp b/lib/gui/src/waypointScr.cpp index e8bcb441..aed687a0 100644 --- a/lib/gui/src/waypointScr.cpp +++ b/lib/gui/src/waypointScr.cpp @@ -7,11 +7,6 @@ */ #include "waypointScr.hpp" -#include "core/lv_obj_pos.h" -#include "display/lv_display.h" -#include "globalGuiDef.h" -#include "tft.hpp" -#include "addWaypoint.hpp" lv_obj_t *waypointScreen; // Add Waypoint Screen lv_obj_t *waypointName; @@ -238,7 +233,6 @@ void createWaypointScreen() #ifdef TDECK_ESP32S3 lv_group_add_obj(scrGroup, waypointName); lv_group_focus_obj(waypointName); - //lv_group_add_obj(scrGroup, waypointScreen); #endif #ifndef TDECK_ESP32S3 diff --git a/lib/gui/src/waypointScr.hpp b/lib/gui/src/waypointScr.hpp index 593be18b..4a2fff4d 100644 --- a/lib/gui/src/waypointScr.hpp +++ b/lib/gui/src/waypointScr.hpp @@ -9,7 +9,7 @@ #ifndef waypointScr_HPP #define waypointScr_HPP -#include "globalGuiDef.h" +#include "addWaypoint.hpp" #include "mainScr.hpp" extern lv_obj_t *waypointName; diff --git a/lib/gui/src/widgets.hpp b/lib/gui/src/widgets.hpp index b3e7bfc3..5e15f6ee 100644 --- a/lib/gui/src/widgets.hpp +++ b/lib/gui/src/widgets.hpp @@ -9,8 +9,6 @@ #ifndef WIDGETS_HPP #define WIDGETS_HPP -#include "lvgl.h" -#include "globalGuiDef.h" #include "globalMapsDef.h" #include "lvglFuncs.hpp" #include "gpsMath.hpp" diff --git a/lib/lvgl/src/lvglFuncs.hpp b/lib/lvgl/src/lvglFuncs.hpp index 1f8cf7b5..0df59194 100644 --- a/lib/lvgl/src/lvglFuncs.hpp +++ b/lib/lvgl/src/lvglFuncs.hpp @@ -9,9 +9,6 @@ #ifndef LVGLFUNCS_HPP #define LVGLFUNCS_HPP -#include -#include "tft.hpp" -#include "lvgl.h" #include "globalGuiDef.h" void objHideCursor(_lv_obj_t *obj); diff --git a/lib/lvgl/src/lvglSetup.cpp b/lib/lvgl/src/lvglSetup.cpp index 45b9af48..32819911 100644 --- a/lib/lvgl/src/lvglSetup.cpp +++ b/lib/lvgl/src/lvglSetup.cpp @@ -6,11 +6,7 @@ * @date 2024-11 */ -#include "lvgl_private.h" #include "lvglSetup.hpp" -#include "waypointScr.hpp" -#include "waypointListScr.hpp" -#include "globalGuiDef.h" ViewPort viewPort; // Vector map viewport MemCache memCache; // Vector map Memory Cache @@ -26,6 +22,8 @@ lv_group_t *scrGroup; // Screen group lv_group_t *keyGroup; // GPIO group lv_obj_t *powerMsg; // Power Message +Power power; + /** * @brief LVGL display update * @@ -137,7 +135,6 @@ void IRAM_ATTR gpioRead(lv_indev_t *indev_driver, lv_indev_data_t *data) */ void gpioLongEvent(lv_event_t *event) { - lv_event_code_t code = lv_event_get_code(event); log_v("Shuting down device"); powerMsg = lv_msgbox_create(lv_scr_act()); lv_obj_set_width(powerMsg,TFT_WIDTH); @@ -149,7 +146,7 @@ void gpioLongEvent(lv_event_t *event) lv_obj_invalidate(powerMsg); lv_refr_now(display); vTaskDelay(2000); - deviceShutdown(); + power.deviceShutdown(); } /** @@ -158,7 +155,6 @@ void gpioLongEvent(lv_event_t *event) */ void gpioClickEvent(lv_event_t *event) { - lv_event_code_t code = lv_event_get_code(event); lv_indev_reset_long_press(lv_indev_active()); lv_indev_reset(NULL,lv_scr_act()); log_v("Entering sleep mode"); @@ -172,7 +168,7 @@ void gpioClickEvent(lv_event_t *event) lv_obj_invalidate(powerMsg); lv_refr_now(display); vTaskDelay(2000); - deviceSuspend(); + power.deviceSuspend(); } /** diff --git a/lib/lvgl/src/lvglSetup.hpp b/lib/lvgl/src/lvglSetup.hpp index f38c237e..386e02d9 100644 --- a/lib/lvgl/src/lvglSetup.hpp +++ b/lib/lvgl/src/lvglSetup.hpp @@ -9,28 +9,17 @@ #ifndef LVGLSETUP_HPP #define LVGLSETUP_HPP -#include - -#include "esp_attr.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#ifdef TDECK_ESP32S3 - #include "Wire.h" -#endif - #define LV_TICK_PERIOD_MS 5 -#include "globalGuiDef.h" +#include "lvgl_private.h" +// #ifdef TDECK_ESP32S3 +// #include "Wire.h" +// #endif #include "splashScr.hpp" -#include "searchSatScr.hpp" #include "notifyBar.hpp" -#include "widgets.hpp" -#include "mainScr.hpp" -#include "buttonBar.hpp" #include "settingsScr.hpp" #include "deviceSettingsScr.hpp" #include "mapSettingsScr.hpp" -#include "waypointScr.hpp" /** * @brief Default display driver definition diff --git a/lib/maps/src/mapsDrawFunc.h b/lib/maps/src/mapsDrawFunc.h index fffdff20..b8428995 100644 --- a/lib/maps/src/mapsDrawFunc.h +++ b/lib/maps/src/mapsDrawFunc.h @@ -94,8 +94,8 @@ static void drawMapWidgets() mapHeight = MAP_HEIGHT; - int toolBarOffset = 0; - int toolBarSpace = 0; + uint8_t toolBarOffset = 0; + uint8_t toolBarSpace = 0; #ifdef LARGE_SCREEN toolBarOffset = 100; toolBarSpace = 60; diff --git a/lib/maps/src/renderMaps.cpp b/lib/maps/src/renderMaps.cpp index ca28d0dc..fe8ef46a 100644 --- a/lib/maps/src/renderMaps.cpp +++ b/lib/maps/src/renderMaps.cpp @@ -7,9 +7,6 @@ */ #include "renderMaps.hpp" -#include "mapsDrawFunc.h" - -extern const int SD_CS; MapTile oldMapTile = {(char*)"", 0, 0, 0}; // Old Map tile coordinates and zoom MapTile currentMapTile = {(char*)"", 0, 0, 0}; // Current Map tile coordinates and zoom @@ -20,8 +17,6 @@ bool isMapFound = false; tileBounds totalBounds = { 90.0, -90.0, 180.0, -180.0}; - - /** * @brief Tile size for position calculation * @@ -172,9 +167,6 @@ void generateRenderMap() if (strcmp(currentMapTile.file, oldMapTile.file) != 0 || currentMapTile.zoom != oldMapTile.zoom || currentMapTile.tilex != oldMapTile.tilex || currentMapTile.tiley != oldMapTile.tiley) { - // deleteMapScrSprites(); - // createMapScrSprites(); - isMapFound = mapTempSprite.drawPngFile(SD, currentMapTile.file, tileSize, tileSize); if (!isMapFound) diff --git a/lib/maps/src/renderMaps.hpp b/lib/maps/src/renderMaps.hpp index 677ed4a7..e225b12b 100644 --- a/lib/maps/src/renderMaps.hpp +++ b/lib/maps/src/renderMaps.hpp @@ -9,11 +9,7 @@ #ifndef RENDERMAPS_HPP #define RENDERMAPS_HPP -#include -#include "tft.hpp" -#include "compass.hpp" #include "settings.hpp" -#include "globalMapsDef.h" #include "mapsDrawFunc.h" /** @@ -45,8 +41,6 @@ tileBounds getTileBounds(uint32_t tileX, uint32_t tileY, uint8_t zoom); bool isCoordInBounds(double lat, double lon, tileBounds bound); void coords2map(double lat, double lon, tileBounds bound, int *pixelX, int *pixelY); MapTile getMapTile(double lon, double lat, uint8_t zoomLevel, int16_t offsetX, int16_t offsetY); -void drawMapWidgets(); void generateRenderMap(); -void initSD(); #endif diff --git a/lib/maps/src/vectorMaps.cpp b/lib/maps/src/vectorMaps.cpp index 85f1de10..b6e5339b 100644 --- a/lib/maps/src/vectorMaps.cpp +++ b/lib/maps/src/vectorMaps.cpp @@ -204,7 +204,6 @@ BBox parseBbox(String str) MapBlock *readMapBlock(String fileName) { log_d("readMapBlock: %s", fileName.c_str()); - char c; char str[30]; MapBlock *mblock = new MapBlock(); fs::File file_ = SD.open(fileName + ".fmp"); @@ -236,7 +235,6 @@ MapBlock *readMapBlock(String fileName) uint32_t totalPoints = 0; Polygon polygon; Point16 p; - int16_t maxVectorZoom;// = 4; while (count > 0) { // log_d("line: %i", line); diff --git a/lib/maps/src/vectorMaps.hpp b/lib/maps/src/vectorMaps.hpp index a17d78ab..2fa746d6 100644 --- a/lib/maps/src/vectorMaps.hpp +++ b/lib/maps/src/vectorMaps.hpp @@ -9,17 +9,10 @@ #ifndef VECTORMAPS_HPP #define VECTORMAPS_HPP -#include -#include #include -#include -#include #include -#include -#include #include #include "globalMapsDef.h" -#include "tft.hpp" #include "gpsMath.hpp" #include "settings.hpp" diff --git a/lib/power/power.cpp b/lib/power/power.cpp index faa2ed60..62bdb978 100644 --- a/lib/power/power.cpp +++ b/lib/power/power.cpp @@ -10,11 +10,22 @@ extern const uint8_t BOARD_BOOT_PIN; +Power::Power() +{ + #ifdef DISABLE_RADIO + WiFi.disconnect(true); + WiFi.mode(WIFI_OFF); + btStop(); + esp_wifi_stop(); + esp_bt_controller_disable(); + #endif +} + /** * @brief Deep Sleep Mode * */ -void powerDeepSleep() +void Power::powerDeepSleep() { esp_bluedroid_disable(); esp_bt_controller_disable(); @@ -38,7 +49,7 @@ void powerDeepSleep() * * @param millis */ -void powerLightSleepTimer(int millis) +void Power::powerLightSleepTimer(int millis) { esp_sleep_enable_timer_wakeup(millis * 1000); esp_err_t rtc_gpio_hold_en(gpio_num_t GPIO_NUM_5); @@ -49,16 +60,27 @@ void powerLightSleepTimer(int millis) * @brief Sleep Mode * */ -void powerLightSleep() +void Power::powerLightSleep() { esp_sleep_enable_ext1_wakeup(1ull << BOARD_BOOT_PIN, ESP_EXT1_WAKEUP_ANY_LOW); esp_light_sleep_start(); } +/** + * @brief Power off peripherals devices + */ +void Power::powerOffPeripherals() +{ + tftOff(); + tft.fillScreen(TFT_BLACK); + SPI.end(); + Wire.end(); +} + /** * @brief Core light suspend and TFT off */ -void deviceSuspend() +void Power::deviceSuspend() { int brightness = tft.getBrightness(); lv_msgbox_close(powerMsg); @@ -75,35 +97,27 @@ void deviceSuspend() /** * @brief Power off peripherals and deep sleep + * */ -void deviceShutdown() +void Power::deviceShutdown() { powerOffPeripherals(); powerDeepSleep(); } -/** - * @brief Power off peripherals devices - */ -void powerOffPeripherals() -{ - tftOff(); - tft.fillScreen(TFT_BLACK); - SPI.end(); - Wire.end(); -} -/** - * @brief On Mode - * - */ -void powerOn() -{ -#ifdef DISABLE_RADIO - WiFi.disconnect(true); - WiFi.mode(WIFI_OFF); - btStop(); - esp_wifi_stop(); - esp_bt_controller_disable(); -#endif -} + +// /** +// * @brief On Mode +// * +// */ +// void powerOn() +// { +// #ifdef DISABLE_RADIO +// WiFi.disconnect(true); +// WiFi.mode(WIFI_OFF); +// btStop(); +// esp_wifi_stop(); +// esp_bt_controller_disable(); +// #endif +// } diff --git a/lib/power/power.hpp b/lib/power/power.hpp index 78192ab7..3c421a4d 100644 --- a/lib/power/power.hpp +++ b/lib/power/power.hpp @@ -19,12 +19,20 @@ #include "lvgl.h" #include "globalGuiDef.h" -void powerDeepSeep(); -void powerLightSleepTimer(int millis); -void powerLightSleep(); -void powerOffPeripherals(); -void deviceSuspend(); -void deviceShutdown(); -void powerOn(); +class Power +{ +private: + void powerDeepSleep(); + void powerLightSleepTimer(int millis); + void powerLightSleep(); + void powerOffPeripherals(); + +public: + Power(); + + void deviceSuspend(); + void deviceShutdown(); +}; + #endif \ No newline at end of file diff --git a/lib/settings/settings.cpp b/lib/settings/settings.cpp index 2aa5697c..7a92c9c0 100644 --- a/lib/settings/settings.cpp +++ b/lib/settings/settings.cpp @@ -51,6 +51,7 @@ uint16_t speedPosY = 0; // Speed widget position Y bool enableWeb = true; // Enable/disable web file server bool showToolBar = false; // Show Map Toolbar int8_t tempOffset = 0; // BME Temperature offset +extern Battery battery; String defDST = "NONE"; // default DST zone bool calculateDST = false; // Calculate DST flag // float batteryMax = 0.0; // 4.2; // maximum voltage of battery @@ -116,17 +117,7 @@ void loadPreferences() speedPosY = cfg.isKey(CONFKEYS::KSPEED_Y) ? cfg.getInt(CONFKEYS::KSPEED_Y, speedPosY) : 94; #endif - batteryMax = cfg.getFloat(PKEYS::KVMAX_BATT,4.2); - batteryMin = cfg.getFloat(PKEYS::KVMIN_BATT,3.6); - - // compassPosX = 60; - // compassPosY = 82; - // coordPosX = 66; - // coordPosY = 29; - // altitudePosX = 8; - // altitudePosY = 293; - // speedPosX = 1; - // speedPosY = 337; + battery.setBatteryLevels(cfg.getFloat(PKEYS::KVMAX_BATT,4.2),cfg.getFloat(PKEYS::KVMIN_BATT,3.6)); defDST = cfg.getString(PKEYS::KDST_ZONE, "EU"); if (defDST.equals("NONE")) diff --git a/lib/settings/settings.hpp b/lib/settings/settings.hpp index 9bd16196..88e321f5 100644 --- a/lib/settings/settings.hpp +++ b/lib/settings/settings.hpp @@ -21,8 +21,6 @@ extern uint8_t defZoomRender; // Default Zoom Level for render map extern uint8_t defZoomVector; // Default Zoom Level for vector map extern uint8_t zoom; // Actual Zoom Level extern uint8_t defBright; // Default brightness -extern float batteryMax; // 4.2; // maximum voltage of battery -extern float batteryMin; // 3.6; // minimum voltage of battery before shutdown extern bool isMapRotation; // Map Compass Rotation extern uint8_t defaultZoom; // Default Zoom Value diff --git a/lib/storage/storage.cpp b/lib/storage/storage.cpp index 8a26730e..df920ad6 100644 --- a/lib/storage/storage.cpp +++ b/lib/storage/storage.cpp @@ -7,77 +7,85 @@ */ #include "storage.hpp" -#include "esp_err.h" -#include "esp_spiffs.h" -bool isSdLoaded = false; -extern const int SD_CS; -extern const int SD_MISO; -extern const int SD_MOSI; -extern const int SD_CLK; -extern const int BOARD_TFT_CS; -extern const int RADIO_CS_PIN; +// Pin definitions (should be configurable if needed) +extern const uint8_t SD_CS; +extern const uint8_t SD_MISO; +extern const uint8_t SD_MOSI; +extern const uint8_t SD_CLK; + +Storage::Storage() : isSdLoaded(false) {} + /** * @brief SD Card init * */ -void initSD() +void Storage::initSD() { - bool SDInitOk = false; - pinMode(SD_CS,OUTPUT); - digitalWrite(SD_CS,LOW); + pinMode(SD_CS, OUTPUT); + digitalWrite(SD_CS, LOW); - SPI.begin(SD_CLK, SD_MISO, SD_MOSI); - SDInitOk = SD.begin(SD_CS, SPI, sdFreq); - - if (!SDInitOk) - { - log_e("SD Card Mount Failed"); - return; - } - else - { - log_v("SD Card Mounted"); - isSdLoaded = true; - } - } + SPI.begin(SD_CLK, SD_MISO, SD_MOSI); + + if (!SD.begin(SD_CS, SPI, sdFreq)) + { + log_e("SD Card Mount Failed"); + isSdLoaded = false; + } + else + { + log_v("SD Card Mounted"); + isSdLoaded = true; + } +} /** - * @brief SPIFFS Init + * @brief SPIFFS initialization * + * @return esp_err_t Error code for SPIFFS setup */ -esp_err_t initSPIFFS() +esp_err_t Storage::initSPIFFS() { - log_i("Initializing SPIFFS"); + log_i("Initializing SPIFFS"); - esp_vfs_spiffs_conf_t conf = { - .base_path = "/spiffs", - .partition_label = NULL, - .max_files = 5, - .format_if_mount_failed = false - }; + esp_vfs_spiffs_conf_t conf = + { + .base_path = "/spiffs", + .partition_label = NULL, + .max_files = 5, + .format_if_mount_failed = false + }; - esp_err_t ret = esp_vfs_spiffs_register(&conf); + esp_err_t ret = esp_vfs_spiffs_register(&conf); - if (ret !=ESP_OK) - { - if (ret == ESP_FAIL) - log_e("Failed to mount or format filesystem"); - else if (ret == ESP_ERR_NOT_FOUND) - log_e("Failed to find SPIFFS partition"); + if (ret != ESP_OK) + { + if (ret == ESP_FAIL) + log_e("Failed to mount or format filesystem"); + else if (ret == ESP_ERR_NOT_FOUND) + log_e("Failed to find SPIFFS partition"); + else + log_e("Failed to initialize SPIFFS (%s)", esp_err_to_name(ret)); + return ESP_FAIL; + } + + size_t total = 0, used = 0; + ret = esp_spiffs_info(NULL, &total, &used); + if (ret != ESP_OK) + log_e("Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret)); else - log_e("Failed to initialize SPIFFS (%s)",esp_err_to_name(ret)); - return ESP_FAIL; - } + log_i("Partition size: total: %d used: %d", total, used); - size_t total = 0, used = 0; - ret = esp_spiffs_info(NULL, &total, &used); - if (ret!= ESP_OK) - log_e("Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret)); - else - log_i("Partition size: total: %d used: %d", total, used); - - return ESP_OK; + return ESP_OK; } +/** + * @brief Get SD status + * + * @return true if SD card is loaded, false otherwise + */ +bool Storage::getSdLoaded() const +{ + return isSdLoaded; +} diff --git a/lib/storage/storage.hpp b/lib/storage/storage.hpp index ec754c21..b6e88cba 100644 --- a/lib/storage/storage.hpp +++ b/lib/storage/storage.hpp @@ -10,15 +10,21 @@ #define STORAGE_HPP #include "esp_spiffs.h" +#include "esp_err.h" #include -#include -#include -static uint32_t sdFreq = 40000000; +class Storage +{ +private: + bool isSdLoaded; + static const uint32_t sdFreq = 40000000; -extern bool isSdLoaded; +public: + Storage(); -void initSD(); -esp_err_t initSPIFFS(); + void initSD(); + esp_err_t initSPIFFS(); + bool getSdLoaded() const; +}; #endif diff --git a/lib/tasks/tasks.cpp b/lib/tasks/tasks.cpp index fe654cc3..37296df7 100644 --- a/lib/tasks/tasks.cpp +++ b/lib/tasks/tasks.cpp @@ -7,8 +7,6 @@ */ #include "tasks.hpp" -#include "Arduino.h" -#include "freertos/FreeRTOS.h" TaskHandle_t LVGLTaskHandler; xSemaphoreHandle gpsMutex; diff --git a/lib/tasks/tasks.hpp b/lib/tasks/tasks.hpp index 0283d7d0..df460316 100644 --- a/lib/tasks/tasks.hpp +++ b/lib/tasks/tasks.hpp @@ -24,6 +24,10 @@ void gpsTask(void *pvParameters); void initGpsTask(); -void initCLITask(); + +#ifndef DISABLE_CLI + void cliTask(void *param); + void initCLITask(); +#endif #endif diff --git a/lib/tft/tft.cpp b/lib/tft/tft.cpp index 9df780ca..565fb761 100644 --- a/lib/tft/tft.cpp +++ b/lib/tft/tft.cpp @@ -14,12 +14,6 @@ uint16_t TFT_WIDTH = 0; uint16_t TFT_HEIGHT = 0; bool waitScreenRefresh = false; -#ifdef TDECK_ESP32S3 - extern const uint8_t TFT_SPI_BL; -#endif - - - /** * @brief Turn on TFT Sleep Mode for ILI9488 * diff --git a/lib/webfile/src/webserver.h b/lib/webfile/src/webserver.h index 600236b8..a27abb39 100644 --- a/lib/webfile/src/webserver.h +++ b/lib/webfile/src/webserver.h @@ -237,7 +237,6 @@ String listFiles(bool ishtml, int page = 0) { String returnText = ""; - int fileIndex = 0; int startIdx = page * FILES_PER_PAGE; int endIdx = startIdx + FILES_PER_PAGE; diff --git a/src/main.cpp b/src/main.cpp index ff18c3ea..f768ccd3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,10 +45,16 @@ extern xSemaphoreHandle gpsMutex; #include "webserver.h" #include "battery.hpp" #include "power.hpp" + +extern Storage storage; +extern Battery battery; +extern Power power; + #include "settings.hpp" #include "lvglSetup.hpp" #include "tasks.hpp" + /** * @brief Setup * @@ -96,14 +102,15 @@ void setup() initCompass(); #endif - powerOn(); - initSD(); - initSPIFFS(); + // powerOn(); + storage.initSD(); + storage.initSPIFFS(); + battery.initADC(); initTFT(); loadPreferences(); initGPS(); initLVGL(); - initADC(); + // Reserve PSRAM for buffer map mapTempSprite.deleteSprite();