SystemAgent/src/main.c

54 lines
1.2 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;
user_spi_driver_t g_spi;
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;
}
user_config_init(&g_config, "config.cfg");
if(user_spi_driver_init(&g_spi, "/dev/spidev0.0") != USER_SPI_OK) {
USER_LOG(USER_LOG_FATAL, "Failed to initialize SPI driver.");
return -2;
}
2021-03-14 07:00:33 +00:00
user_lvgl_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-03-14 07:00:33 +00:00
user_lvgl_task_deinit();
2021-03-14 15:47:28 +00:00
user_spi_driver_deinit(&g_spi);
user_config_deinit(&g_config);
USER_LOG(USER_LOG_INFO, "Application exit.");
2021-03-14 07:00:33 +00:00
return 0;
}