Added first message task on gps lock !UNTESTED!
This commit is contained in:
@@ -17,6 +17,7 @@ enum module_id : uint8_t {
|
|||||||
enum task_type : uint8_t {
|
enum task_type : uint8_t {
|
||||||
TASK_NULL,
|
TASK_NULL,
|
||||||
TASK_DISPLAY_GPS_DEBUG,
|
TASK_DISPLAY_GPS_DEBUG,
|
||||||
|
TASK_DISPLAY_MSG_GPS_FIX,
|
||||||
TASK_CONFIG_TRACK_DETECT,
|
TASK_CONFIG_TRACK_DETECT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ struct gps_data {
|
|||||||
gps_sub_data lng;
|
gps_sub_data lng;
|
||||||
gps_sub_data speed;
|
gps_sub_data speed;
|
||||||
gps_sub_data course;
|
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) {
|
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.lng, src.lng);
|
||||||
gps_sub_copy_from_volatile(dst.speed, src.speed);
|
gps_sub_copy_from_volatile(dst.speed, src.speed);
|
||||||
gps_sub_copy_from_volatile(dst.course, src.course);
|
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) {
|
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.lng, src.lng);
|
||||||
gps_sub_copy_to_volatile(dst.speed, src.speed);
|
gps_sub_copy_to_volatile(dst.speed, src.speed);
|
||||||
gps_sub_copy_to_volatile(dst.course, src.course);
|
gps_sub_copy_to_volatile(dst.course, src.course);
|
||||||
|
dst.num_fix = src.num_fix;
|
||||||
}
|
}
|
||||||
@@ -18,10 +18,13 @@ private:
|
|||||||
track_data _loaded_track;
|
track_data _loaded_track;
|
||||||
ring_buffer<Task, 16> _queue;
|
ring_buffer<Task, 16> _queue;
|
||||||
Task _active_task = {};
|
Task _active_task = {};
|
||||||
|
uint8_t _task_memory[64];
|
||||||
|
bool _task_memory_stale = true;
|
||||||
int read_cfg();
|
int read_cfg();
|
||||||
int write_cfg();
|
int write_cfg();
|
||||||
int write_cfg(const vehicle_config &new_config);
|
int write_cfg(const vehicle_config &new_config);
|
||||||
int handle_active_task();
|
int handle_active_task(unsigned long timeout_ms);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int push(const Task &task) override;
|
int push(const Task &task) override;
|
||||||
@@ -49,9 +52,10 @@ int config::write_cfg(const vehicle_config &new_config) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int config::handle_active_task() {
|
int config::handle_active_task(unsigned long timeout_ms) {
|
||||||
//TODO: handle active task
|
unsigned long now = millis();
|
||||||
return 0;
|
unsigned long task_timeout = now + timeout_ms;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int config::auto_init() {
|
int config::auto_init() {
|
||||||
@@ -79,13 +83,14 @@ int config::auto_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int config::loop(unsigned long timeout_ms) {
|
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) {
|
if (_active_task.type != TASK_NULL && _active_task.target != MOD_NULL) {
|
||||||
this->handle_active_task();
|
this->handle_active_task(timeout_ms);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
_queue.pop(_active_task);
|
int res = _queue.pop(_active_task);
|
||||||
this->handle_active_task();
|
if (res == 0) {
|
||||||
|
|
||||||
|
this->handle_active_task(timeout_ms);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "base/ring_buffer.h"
|
#include "base/ring_buffer.h"
|
||||||
#include "base/module_base.h"
|
#include "base/module_base.h"
|
||||||
#include "data/gps_store.h"
|
#include "data/gps_store.h"
|
||||||
|
#include "base/router.h"
|
||||||
#define MOD "modules/gps/gps.h"
|
#define MOD "modules/gps/gps.h"
|
||||||
|
|
||||||
class gps : public module_base{
|
class gps : public module_base{
|
||||||
@@ -18,6 +19,7 @@ private:
|
|||||||
HardwareSerial *_data_stream;
|
HardwareSerial *_data_stream;
|
||||||
system_logger *_logger;
|
system_logger *_logger;
|
||||||
ring_buffer<Task, 16> _queue;
|
ring_buffer<Task, 16> _queue;
|
||||||
|
uint32_t _last_fix_val = 0;
|
||||||
public:
|
public:
|
||||||
int push(const Task& task) override;
|
int push(const Task& task) override;
|
||||||
gps(HardwareSerial *data_stream);
|
gps(HardwareSerial *data_stream);
|
||||||
@@ -60,6 +62,11 @@ int gps::loop(unsigned long timeout_ms) {
|
|||||||
while (_data_stream->available() > 0) {
|
while (_data_stream->available() > 0) {
|
||||||
if (_gps->encode(_data_stream->read())) {
|
if (_gps->encode(_data_stream->read())) {
|
||||||
gps_global_write(this->get_data());
|
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) {
|
if (millis() > timeout) {
|
||||||
return 1;
|
return 1;
|
||||||
@@ -91,6 +98,8 @@ gps_data gps::get_data() {
|
|||||||
output.course.valid = _gps->course.isValid();
|
output.course.valid = _gps->course.isValid();
|
||||||
output.course.value = _gps->course.deg();
|
output.course.value = _gps->course.deg();
|
||||||
|
|
||||||
|
output.num_fix = _gps->sentencesWithFix();
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
#undef MOD
|
#undef MOD
|
||||||
@@ -18,6 +18,7 @@ namespace screen
|
|||||||
typedef enum lcd_screen {
|
typedef enum lcd_screen {
|
||||||
blank,
|
blank,
|
||||||
gps_debug,
|
gps_debug,
|
||||||
|
msg_gps_fix,
|
||||||
};
|
};
|
||||||
} // namespace screen
|
} // namespace screen
|
||||||
|
|
||||||
@@ -27,9 +28,12 @@ private:
|
|||||||
bool _dispaly_cleared;
|
bool _dispaly_cleared;
|
||||||
system_logger *_logger = nullptr;
|
system_logger *_logger = nullptr;
|
||||||
screen::lcd_screen _screen;
|
screen::lcd_screen _screen;
|
||||||
|
screen::lcd_screen _previous_screen;
|
||||||
unsigned long _last_render;
|
unsigned long _last_render;
|
||||||
unsigned long _frame_duration;
|
unsigned long _frame_duration;
|
||||||
|
long _hold_till_frame = -1;
|
||||||
ring_buffer<Task, 16> _queue;
|
ring_buffer<Task, 16> _queue;
|
||||||
|
uint32_t _frame_ctr = 0;
|
||||||
void clear();
|
void clear();
|
||||||
void print(const String& msg);
|
void print(const String& msg);
|
||||||
void print(char);
|
void print(char);
|
||||||
@@ -41,6 +45,7 @@ private:
|
|||||||
void print(int val, int base);
|
void print(int val, int base);
|
||||||
|
|
||||||
int render_gps_debug();
|
int render_gps_debug();
|
||||||
|
int render_msg_gps_fix();
|
||||||
public:
|
public:
|
||||||
int push(const Task& task) override;
|
int push(const Task& task) override;
|
||||||
lcd();
|
lcd();
|
||||||
@@ -135,6 +140,17 @@ int lcd::render_gps_debug() {
|
|||||||
} else {
|
} else {
|
||||||
this->print("not valid");
|
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) {
|
int lcd::push(const Task& task) {
|
||||||
@@ -259,9 +275,20 @@ int lcd::loop(unsigned long timeout_ms) {
|
|||||||
switch (next_task.type)
|
switch (next_task.type)
|
||||||
{
|
{
|
||||||
case TASK_DISPLAY_GPS_DEBUG:
|
case TASK_DISPLAY_GPS_DEBUG:
|
||||||
|
_previous_screen = _screen;
|
||||||
_screen = screen::gps_debug;
|
_screen = screen::gps_debug;
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -273,6 +300,11 @@ int lcd::loop(unsigned long timeout_ms) {
|
|||||||
if (now < _last_render + _frame_duration) {
|
if (now < _last_render + _frame_duration) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_frame_ctr == _hold_till_frame) {
|
||||||
|
_screen = _previous_screen;
|
||||||
|
_hold_till_frame = -1;
|
||||||
|
}
|
||||||
switch (_screen)
|
switch (_screen)
|
||||||
{
|
{
|
||||||
case screen::blank:
|
case screen::blank:
|
||||||
@@ -283,10 +315,15 @@ int lcd::loop(unsigned long timeout_ms) {
|
|||||||
this->render_gps_debug();
|
this->render_gps_debug();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case screen::msg_gps_fix:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_last_render = millis();
|
_last_render = millis();
|
||||||
|
_frame_ctr++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user