Initial impl for config with queue system
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include "base/module_base.h"
|
||||
#include "base/ring_buffer.h"
|
||||
#include "base/task.h"
|
||||
#include "custom_types.h"
|
||||
#include "flags.h"
|
||||
#include "modules/logger/system_logger.h"
|
||||
#include "base/task.h"
|
||||
#include "base/ring_buffer.h"
|
||||
#include "base/module_base.h"
|
||||
#include <EEPROM.h>
|
||||
|
||||
class config : public module_base {
|
||||
@@ -17,20 +17,22 @@ private:
|
||||
bool _valid_config;
|
||||
track_data _loaded_track;
|
||||
ring_buffer<Task, 16> _queue;
|
||||
Task _active_task = {};
|
||||
int read_cfg();
|
||||
int write_cfg();
|
||||
int write_cfg(const vehicle_config &new_config);
|
||||
int handle_active_task();
|
||||
|
||||
public:
|
||||
int push(const Task &task) override;
|
||||
config();
|
||||
config(system_logger *logger);
|
||||
~config();
|
||||
int auto_init();
|
||||
int loop(unsigned long timeout_ms = 500);
|
||||
};
|
||||
|
||||
int config::push(const Task& task) {
|
||||
return _queue.push(task);
|
||||
}
|
||||
int config::push(const Task &task) { return _queue.push(task); }
|
||||
|
||||
config::config() : _logger(nullptr), _valid_config(true) {}
|
||||
config::config(system_logger *logger) : _logger(logger), _valid_config(true) {}
|
||||
@@ -47,6 +49,11 @@ int config::write_cfg(const vehicle_config& new_config) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config::handle_active_task() {
|
||||
//TODO: handle active task
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config::auto_init() {
|
||||
this->read_cfg();
|
||||
if (_config.magic != CONFIG_MAGIC) {
|
||||
@@ -70,3 +77,15 @@ int config::auto_init() {
|
||||
_valid_config = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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();
|
||||
return 0;
|
||||
}
|
||||
_queue.pop(_active_task);
|
||||
this->handle_active_task();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user