feat(refactor): Restructure project for improved modularity and clarity
This commit introduces a major refactoring of the project structure to align with Zephyr's recommended multi-application and library organization. Key changes include: - Relocation of custom modules from 'software/modules/' to 'software/lib/'. - Introduction of a central 'software/CMakeLists.txt' to manage application and library subdirectories. - Creation of new Kconfig files for 'software/' and 'software/apps/slave_node/' to define project-wide and application-specific configurations. - Removal of the 'gateway' and 'stm32g431_tests' applications. - Removal of 'shell_modbus.c' and 'shell_system.c' from 'slave_node' application's direct source files, indicating a shift towards library-based shell commands. - Updates to 'software/apps/slave_node/CMakeLists.txt', 'prj.conf', and 'boards/bluepill_f103rb.conf' to reflect the new structure and dependencies.
This commit is contained in:
1
software/lib/valve/CMakeLists.txt
Normal file
1
software/lib/valve/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
zephyr_library_sources(valve.c)
|
||||
5
software/lib/valve/Kconfig
Normal file
5
software/lib/valve/Kconfig
Normal file
@@ -0,0 +1,5 @@
|
||||
config LIB_VALVE
|
||||
bool "Enable Valve Library"
|
||||
default y
|
||||
help
|
||||
Enable the Valve Library.
|
||||
62
software/lib/valve/valve.c
Normal file
62
software/lib/valve/valve.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/settings/settings.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <lib/valve.h>
|
||||
|
||||
LOG_MODULE_REGISTER(valve, LOG_LEVEL_INF);
|
||||
|
||||
static enum valve_state current_state = VALVE_STATE_CLOSED;
|
||||
static enum valve_movement current_movement = VALVE_MOVEMENT_IDLE;
|
||||
static uint16_t max_opening_time_s = 60;
|
||||
static uint16_t max_closing_time_s = 60;
|
||||
static struct k_work_delayable valve_work;
|
||||
|
||||
static void valve_work_handler(struct k_work *work)
|
||||
{
|
||||
if (current_movement == VALVE_MOVEMENT_OPENING) {
|
||||
LOG_INF("Virtual valve finished opening");
|
||||
} else if (current_movement == VALVE_MOVEMENT_CLOSING) {
|
||||
current_state = VALVE_STATE_CLOSED;
|
||||
LOG_INF("Virtual valve finished closing");
|
||||
}
|
||||
current_movement = VALVE_MOVEMENT_IDLE;
|
||||
}
|
||||
|
||||
void valve_init(void)
|
||||
{
|
||||
k_work_init_delayable(&valve_work, valve_work_handler);
|
||||
settings_load_one("valve/max_open_time", &max_opening_time_s, sizeof(max_opening_time_s));
|
||||
settings_load_one("valve/max_close_time", &max_closing_time_s, sizeof(max_closing_time_s));
|
||||
}
|
||||
|
||||
void valve_open(void)
|
||||
{
|
||||
if (current_state == VALVE_STATE_CLOSED) {
|
||||
current_state = VALVE_STATE_OPEN;
|
||||
current_movement = VALVE_MOVEMENT_OPENING;
|
||||
k_work_schedule(&valve_work, K_SECONDS(max_opening_time_s));
|
||||
}
|
||||
}
|
||||
|
||||
void valve_close(void)
|
||||
{
|
||||
if (current_state == VALVE_STATE_OPEN) {
|
||||
current_movement = VALVE_MOVEMENT_CLOSING;
|
||||
k_work_schedule(&valve_work, K_SECONDS(max_closing_time_s));
|
||||
}
|
||||
}
|
||||
|
||||
void valve_stop(void)
|
||||
{
|
||||
k_work_cancel_delayable(&valve_work);
|
||||
current_movement = VALVE_MOVEMENT_IDLE;
|
||||
}
|
||||
|
||||
enum valve_state valve_get_state(void) { return current_state; }
|
||||
enum valve_movement valve_get_movement(void) { return current_movement; }
|
||||
uint16_t valve_get_motor_current(void) { return (current_movement != VALVE_MOVEMENT_IDLE) ? 150 : 10; }
|
||||
|
||||
void valve_set_max_open_time(uint16_t seconds) { max_opening_time_s = seconds; settings_save_one("valve/max_open_time", &max_opening_time_s, sizeof(max_opening_time_s)); }
|
||||
void valve_set_max_close_time(uint16_t seconds) { max_closing_time_s = seconds; settings_save_one("valve/max_close_time", &max_closing_time_s, sizeof(max_closing_time_s)); }
|
||||
uint16_t valve_get_max_open_time(void) { return max_opening_time_s; }
|
||||
uint16_t valve_get_max_close_time(void) { return max_closing_time_s; }
|
||||
Reference in New Issue
Block a user