SystemAgent/src/main.c

62 lines
1.4 KiB
C
Raw Normal View History

2021-03-14 07:00:33 +00:00
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
2021-03-14 15:47:28 +00:00
#include "drivers/user_config_driver.h"
#include "drivers/user_spi_driver.h"
#include "utils/user_log_util.h"
2021-03-14 07:00:33 +00:00
#include "tasks/user_tasks.h"
uint8_t g_running = 1;
2021-03-14 15:47:28 +00:00
user_config_t g_config;
static void signal_handler(int signo) {
if(signo == SIGINT) {
g_running = 0;
}
USER_LOG(USER_LOG_INFO, "Signal %d captured, stopping.", signo);
}
2021-03-14 07:00:33 +00:00
int main(int argc, const char *argv[]) {
2021-03-14 15:47:28 +00:00
USER_LOG(USER_LOG_INFO, "Application started.");
if(signal(SIGINT, signal_handler) == SIG_ERR) {
USER_LOG(USER_LOG_FATAL, "Cannot register signal handler.");
return -1;
}
2021-03-21 16:01:12 +00:00
if(user_config_init(&g_config, "config.cfg") != 0) {
USER_LOG(USER_LOG_FATAL, "Failed to load config file.");
return -2;
}
2021-06-22 17:40:28 +00:00
user_log_level_t log_level = USER_LOG_INFO;
user_config_lookup_int(&g_config, "agent.common.log_level", (int *)&log_level);
user_log_set_level(log_level);
2021-03-14 07:00:33 +00:00
user_lvgl_task_init();
2021-07-05 16:03:09 +00:00
user_base_task_init();
user_clock_task_init();
2021-07-06 17:40:58 +00:00
user_dht_task_init();
2021-03-14 15:47:28 +00:00
USER_LOG(USER_LOG_INFO, "Initialized, main thread sleeping.");
2021-03-14 07:00:33 +00:00
while(g_running) {
sleep(1);
}
2021-03-14 15:47:28 +00:00
2021-07-06 17:40:58 +00:00
user_dht_task_deinit();
user_clock_task_deinit();
2021-07-05 16:03:09 +00:00
user_base_task_deinit();
2021-03-14 07:00:33 +00:00
user_lvgl_task_deinit();
2021-03-14 15:47:28 +00:00
user_config_deinit(&g_config);
USER_LOG(USER_LOG_INFO, "Application exit.");
2021-03-14 07:00:33 +00:00
return 0;
}