canbus, modbus working, valve has to be implemented in real
This commit is contained in:
53
software/src/main.c
Normal file
53
software/src/main.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/shell/shell.h>
|
||||
#include "canbus.h"
|
||||
#include "canbus_registers.h"
|
||||
|
||||
#ifdef CONFIG_HAS_MODBUS_WATERLEVEL_SENSOR
|
||||
// Include the water level sensor header file when the feature is enabled
|
||||
#include "waterlevel_sensor.h"
|
||||
#endif // CONFIG_HAS_MODBUS_WATERLEVEL_SENSOR
|
||||
|
||||
#ifdef CONFIG_HAS_VALVE
|
||||
#include "valve.h"
|
||||
#endif // CONFIG_HAS_VALVE
|
||||
|
||||
LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
LOG_INF("Starting main application...");
|
||||
canbus_init();
|
||||
k_sleep(K_MSEC(3000)); // Allow some time for CAN initialization
|
||||
#ifdef CONFIG_HAS_MODBUS_WATERLEVEL_SENSOR
|
||||
int rc = waterlevel_sensor_start_thread();
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG_ERR("Failed to start water level sensor thread: %d", rc);
|
||||
return rc;
|
||||
}
|
||||
#endif // CONFIG_HAS_MODBUS_WATERLEVEL_SENSOR
|
||||
|
||||
valve_cmd(VALVE_COMMAND_CLOSE); // Ensure the valve is closed at startup
|
||||
|
||||
LOG_INF("Main application started successfully.");
|
||||
return 0; // Return 0 on success
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SHELL
|
||||
#include <zephyr/shell/shell.h>
|
||||
#include <zephyr/sys/reboot.h>
|
||||
|
||||
static int reboot_shell_cmd(const struct shell *shell, size_t argc, char **argv)
|
||||
{
|
||||
ARG_UNUSED(argc);
|
||||
ARG_UNUSED(argv);
|
||||
shell_print(shell, "Rebooting the node in 1 second...");
|
||||
k_sleep(K_SECONDS(1));
|
||||
sys_reboot(SYS_REBOOT_COLD);
|
||||
return 0;
|
||||
}
|
||||
SHELL_CMD_REGISTER(reboot, NULL, "Reboot the node", reboot_shell_cmd);
|
||||
#endif // CONFIG_SHELL
|
||||
Reference in New Issue
Block a user