From a107982e04f759d0148b4f4e07db1b32a0f6edfb Mon Sep 17 00:00:00 2001 From: lewisxhe Date: Fri, 20 Jun 2025 10:10:54 +0800 Subject: [PATCH] Factory example recording GPS completion takes time --- examples/UnitTest/UnitTest.ino | 23 ++++++++++++++++++----- examples/UnitTest/ui.cpp | 12 +++++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/examples/UnitTest/UnitTest.ino b/examples/UnitTest/UnitTest.ino index 97036d6..3965cc1 100644 --- a/examples/UnitTest/UnitTest.ino +++ b/examples/UnitTest/UnitTest.ino @@ -98,7 +98,7 @@ TouchDrvGT911 touch; lv_indev_t *kb_indev = NULL; lv_indev_t *mouse_indev = NULL; lv_indev_t *touch_indev = NULL; - +uint32_t gps_start_ms = 0; LV_IMG_DECLARE(image_emoji); @@ -155,7 +155,7 @@ static bool GPS_Recovery(); extern void updateGPS(double lat, double lng, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, - double speed, uint32_t rx_char ); + double speed, uint32_t rx_char, uint32_t use_sec); extern void updateNoiseLabel(uint32_t cnt); extern void setLoRaMessage(const char *text); extern void setupUI(void); @@ -471,10 +471,12 @@ void taskPlaySong(void *p) } } +uint32_t gps_update_interval = 0; +bool update_use_second = false; +uint32_t gps_use_second = 0; + void loopGPS() { - static uint32_t gps_update_interval = 0; - unsigned long start = millis(); do { while (SerialGPS.available()) { @@ -485,6 +487,14 @@ void loopGPS() } while (millis() - start < 20); if (gps_update_interval < millis()) { + + bool location = gps.location.isValid(); + bool datetime = (gps.date.year() > 2000); + if (location && datetime && !update_use_second) { + update_use_second = true; + gps_use_second = (millis() - gps_start_ms) / 1000; + } + updateGPS(gps.location.lat(), gps.location.lng(), gps.date.year(), @@ -494,7 +504,8 @@ void loopGPS() gps.time.minute(), gps.time.second(), gps.speed.value(), - gps.charsProcessed()); + gps.charsProcessed(), + gps_use_second); gps_update_interval = millis() + 3000; } } @@ -1039,6 +1050,8 @@ void setup() } } + // Record GPS start time + gps_start_ms = millis(); lv_obj_del(logo); diff --git a/examples/UnitTest/ui.cpp b/examples/UnitTest/ui.cpp index a5001f6..ee253f0 100644 --- a/examples/UnitTest/ui.cpp +++ b/examples/UnitTest/ui.cpp @@ -23,6 +23,7 @@ typedef struct { lv_obj_t *label_time; lv_obj_t *label_speed; lv_obj_t *label_processchar; + lv_obj_t *label_use_seconds; } Deck_GPS_t; Deck_GPS_t sub_gps_val; @@ -36,7 +37,7 @@ typedef struct { Deck_Radio_t sub_radio_val; static lv_obj_t *sound_vad_label; -std::vectorsub_section; +std::vector < lv_obj_t * > sub_section; enum { LV_MENU_ITEM_BUILDER_VARIANT_1, @@ -130,11 +131,15 @@ void setLoRaMessage(const char *text) void updateGPS(double lat, double lng, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, - double speed, uint32_t rx_char ) + double speed, uint32_t rx_char, uint32_t use_sec) { + if (use_sec == 0) { + lv_label_set_text_fmt(sub_gps_val.label_use_seconds, "N.A"); + } else { + lv_label_set_text_fmt(sub_gps_val.label_use_seconds, "%u", use_sec); + } lv_label_set_text_fmt(sub_gps_val.label_lng, "%.6f", lng); lv_label_set_text_fmt(sub_gps_val.label_lat, "%.6f", lat); - lv_label_set_text_fmt(sub_gps_val.label_date, "%u/%u/%u", year, month, day); lv_label_set_text_fmt(sub_gps_val.label_time, "%u:%u:%u", hour, minute, second); lv_label_set_text_fmt(sub_gps_val.label_speed, "%.6f", speed); @@ -339,6 +344,7 @@ void setupUI(void) sub_section.push_back(section); create_label(section, LV_SYMBOL_GPS, "Model", gps_model.c_str()); + sub_gps_val.label_use_seconds = create_label(section, LV_SYMBOL_GPS, "Use Seconds", "N.A"); sub_gps_val.label_lat = create_label(section, LV_SYMBOL_GPS, "lat", "N.A"); sub_gps_val.label_lng = create_label(section, LV_SYMBOL_GPS, "lng", "N.A"); sub_gps_val.label_speed = create_label(section, LV_SYMBOL_SETTINGS, "Speed", "N.A");