From 898879e42753eb15de588227b070efb50b020136 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Tue, 24 Mar 2026 17:53:00 +0100 Subject: [PATCH] Added first message task on gps lock !UNTESTED! --- src/base/task.h | 1 + src/custom_types.h | 3 +++ src/modules/config/config.h | 23 ++++++++++++++--------- src/modules/gps/gps.h | 9 +++++++++ src/modules/lcd/lcd.h | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/base/task.h b/src/base/task.h index 428f82f..0d3ded9 100644 --- a/src/base/task.h +++ b/src/base/task.h @@ -17,6 +17,7 @@ enum module_id : uint8_t { enum task_type : uint8_t { TASK_NULL, TASK_DISPLAY_GPS_DEBUG, + TASK_DISPLAY_MSG_GPS_FIX, TASK_CONFIG_TRACK_DETECT, }; diff --git a/src/custom_types.h b/src/custom_types.h index 2ad56c2..e3c89f2 100644 --- a/src/custom_types.h +++ b/src/custom_types.h @@ -37,6 +37,7 @@ struct gps_data { gps_sub_data lng; gps_sub_data speed; gps_sub_data course; + uint32_t num_fix; }; inline void gps_sub_copy_from_volatile(gps_sub_data& dst, const volatile gps_sub_data& src) { @@ -57,6 +58,7 @@ inline void gps_copy_from_volatile(gps_data& dst, const volatile gps_data& src) gps_sub_copy_from_volatile(dst.lng, src.lng); gps_sub_copy_from_volatile(dst.speed, src.speed); gps_sub_copy_from_volatile(dst.course, src.course); + dst.num_fix = src.num_fix; } inline void gps_copy_to_volatile(volatile gps_data& dst, const gps_data& src) { @@ -65,4 +67,5 @@ inline void gps_copy_to_volatile(volatile gps_data& dst, const gps_data& src) { gps_sub_copy_to_volatile(dst.lng, src.lng); gps_sub_copy_to_volatile(dst.speed, src.speed); gps_sub_copy_to_volatile(dst.course, src.course); + dst.num_fix = src.num_fix; } \ No newline at end of file diff --git a/src/modules/config/config.h b/src/modules/config/config.h index 94df087..45694e3 100644 --- a/src/modules/config/config.h +++ b/src/modules/config/config.h @@ -18,10 +18,13 @@ private: track_data _loaded_track; ring_buffer _queue; Task _active_task = {}; + uint8_t _task_memory[64]; + bool _task_memory_stale = true; int read_cfg(); int write_cfg(); int write_cfg(const vehicle_config &new_config); - int handle_active_task(); + int handle_active_task(unsigned long timeout_ms); + public: int push(const Task &task) override; @@ -49,9 +52,10 @@ int config::write_cfg(const vehicle_config &new_config) { return 0; } -int config::handle_active_task() { - //TODO: handle active task - return 0; +int config::handle_active_task(unsigned long timeout_ms) { + unsigned long now = millis(); + unsigned long task_timeout = now + timeout_ms; + return 0; } int config::auto_init() { @@ -79,13 +83,14 @@ int config::auto_init() { } int config::loop(unsigned long timeout_ms) { - unsigned long now = millis(); - unsigned long task_timeout = now + timeout_ms; if (_active_task.type != TASK_NULL && _active_task.target != MOD_NULL) { - this->handle_active_task(); + this->handle_active_task(timeout_ms); return 0; } - _queue.pop(_active_task); - this->handle_active_task(); + int res = _queue.pop(_active_task); + if (res == 0) { + + this->handle_active_task(timeout_ms); + } return 0; } diff --git a/src/modules/gps/gps.h b/src/modules/gps/gps.h index 6b8d69c..94ff417 100644 --- a/src/modules/gps/gps.h +++ b/src/modules/gps/gps.h @@ -10,6 +10,7 @@ #include "base/ring_buffer.h" #include "base/module_base.h" #include "data/gps_store.h" +#include "base/router.h" #define MOD "modules/gps/gps.h" class gps : public module_base{ @@ -18,6 +19,7 @@ private: HardwareSerial *_data_stream; system_logger *_logger; ring_buffer _queue; + uint32_t _last_fix_val = 0; public: int push(const Task& task) override; gps(HardwareSerial *data_stream); @@ -60,6 +62,11 @@ int gps::loop(unsigned long timeout_ms) { while (_data_stream->available() > 0) { if (_gps->encode(_data_stream->read())) { gps_global_write(this->get_data()); + uint32_t current_fix_val = _gps->sentencesWithFix(); + if (_last_fix_val == 0 && current_fix_val > 0) { + router::send(MOD_LCD, TASK_DISPLAY_MSG_GPS_FIX, 2000); + } + _last_fix_val = current_fix_val; } if (millis() > timeout) { return 1; @@ -91,6 +98,8 @@ gps_data gps::get_data() { output.course.valid = _gps->course.isValid(); output.course.value = _gps->course.deg(); + output.num_fix = _gps->sentencesWithFix(); + return output; } #undef MOD \ No newline at end of file diff --git a/src/modules/lcd/lcd.h b/src/modules/lcd/lcd.h index 4970c9f..166c0f0 100644 --- a/src/modules/lcd/lcd.h +++ b/src/modules/lcd/lcd.h @@ -18,6 +18,7 @@ namespace screen typedef enum lcd_screen { blank, gps_debug, + msg_gps_fix, }; } // namespace screen @@ -27,9 +28,12 @@ private: bool _dispaly_cleared; system_logger *_logger = nullptr; screen::lcd_screen _screen; + screen::lcd_screen _previous_screen; unsigned long _last_render; unsigned long _frame_duration; + long _hold_till_frame = -1; ring_buffer _queue; + uint32_t _frame_ctr = 0; void clear(); void print(const String& msg); void print(char); @@ -41,6 +45,7 @@ private: void print(int val, int base); int render_gps_debug(); + int render_msg_gps_fix(); public: int push(const Task& task) override; lcd(); @@ -135,6 +140,17 @@ int lcd::render_gps_debug() { } else { this->print("not valid"); } + return 0; +} + + +int lcd::render_msg_gps_fix() { + this->clear(); + _display->setCursor(0,2); + this->print("INFO"); + _display->setCursor(0,3); + this->print("GPS FIX OK"); + return 0; } int lcd::push(const Task& task) { @@ -259,9 +275,20 @@ int lcd::loop(unsigned long timeout_ms) { switch (next_task.type) { case TASK_DISPLAY_GPS_DEBUG: + _previous_screen = _screen; _screen = screen::gps_debug; break; + case TASK_DISPLAY_MSG_GPS_FIX: + _previous_screen = _screen; + _screen = screen::msg_gps_fix; + unsigned long _msg_duration = next_task.data/_frame_duration; + if (_msg_duration == 0) { + _msg_duration == 1; + } + _hold_till_frame = _frame_ctr + 1 + _msg_duration; + break; + default: break; } @@ -273,6 +300,11 @@ int lcd::loop(unsigned long timeout_ms) { if (now < _last_render + _frame_duration) { return 1; } + + if (_frame_ctr == _hold_till_frame) { + _screen = _previous_screen; + _hold_till_frame = -1; + } switch (_screen) { case screen::blank: @@ -282,11 +314,16 @@ int lcd::loop(unsigned long timeout_ms) { case screen::gps_debug: this->render_gps_debug(); break; + + case screen::msg_gps_fix: + + break; default: break; } _last_render = millis(); + _frame_ctr++; return 1; }