diff --git a/src/jpeg.c b/src/jpeg.c index e4e24ce..2bad8e4 100644 --- a/src/jpeg.c +++ b/src/jpeg.c @@ -1,7 +1,5 @@ #include "jpeg.h" -#define tag "[jpeg] " - int jpeg_index; bool jpeg_module_init = false; @@ -22,11 +20,9 @@ int jpeg_init() { jpeg_index = take_next_free_channel(false); if (ret = create_channel(jpeg_index, app_config.jpeg_width, app_config.jpeg_height, 1, 1)) { - printf( - tag "Creating channel %d failed with %#x!\n%s\n", - jpeg_index, ret, errstr(ret)); pthread_mutex_unlock(&jpeg_mutex); - return EXIT_FAILURE; + HAL_ERROR("jpeg", "Creating channel %d failed with %#x!\n%s\n", + jpeg_index, ret, errstr(ret)); } { @@ -53,18 +49,16 @@ int jpeg_init() { } if (ret) { - printf( - tag "Creating encoder %d failed with %#x!\n%s\n", - jpeg_index, ret, errstr(ret)); pthread_mutex_unlock(&jpeg_mutex); - return EXIT_FAILURE; + HAL_ERROR("jpeg", "Creating encoder %d failed with %#x!\n%s\n", + jpeg_index, ret, errstr(ret)); } } active: jpeg_module_init = true; pthread_mutex_unlock(&jpeg_mutex); - printf(tag "Module enabled!\n"); + HAL_INFO("jpeg", "Module enabled!\n"); return EXIT_SUCCESS; } @@ -95,7 +89,7 @@ void jpeg_deinit() { active: jpeg_module_init = false; pthread_mutex_unlock(&jpeg_mutex); - printf(tag "Module disabled!\n"); + HAL_INFO("jpeg", "Module disabled!\n"); } int jpeg_get(short width, short height, char quality, char grayscale, @@ -103,8 +97,7 @@ int jpeg_get(short width, short height, char quality, char grayscale, pthread_mutex_lock(&jpeg_mutex); if (!jpeg_module_init) { pthread_mutex_unlock(&jpeg_mutex); - printf(tag "Module is not enabled!\n"); - return EXIT_FAILURE; + HAL_ERROR("jpeg", "Module is not enabled!\n"); } int ret; diff --git a/src/media.c b/src/media.c index a640d6e..9290543 100644 --- a/src/media.c +++ b/src/media.c @@ -305,14 +305,12 @@ int enable_audio(void) { case HAL_PLATFORM_T31: ret = t31_audio_init(app_config.audio_srate); break; #endif } - if (ret) { - fprintf(stderr, "Audio initialization failed with %#x!\n%s\n", + if (ret) + HAL_ERROR("media", "Audio initialization failed with %#x!\n%s\n", ret, errstr(ret)); - return EXIT_FAILURE; - } if (shine_check_config(app_config.audio_srate, app_config.audio_bitrate) < 0) - fprintf(stderr, "Unsupported samplerate/bitrate configuration!\n"); + HAL_ERROR("media", "MP3 samplerate/bitrate configuration is unsupported!\n"); else { mp3Cnf.mpeg.mode = MONO; mp3Cnf.mpeg.bitr = app_config.audio_bitrate; @@ -321,10 +319,9 @@ int enable_audio(void) { mp3Cnf.mpeg.original = 1; mp3Cnf.wave.channels = PCM_MONO; mp3Cnf.wave.samplerate = app_config.audio_srate; - if (!(mp3Enc = shine_initialise(&mp3Cnf))) { - fprintf(stderr, "MP3 encoder initialization failed!\n"); - return EXIT_FAILURE; - } + if (!(mp3Enc = shine_initialise(&mp3Cnf))) + HAL_ERROR("media", "MP3 encoder initialization failed!\n"); + pcmSamp = shine_samples_per_pass(mp3Enc); } @@ -333,32 +330,25 @@ int enable_audio(void) { size_t stacksize; pthread_attr_getstacksize(&thread_attr, &stacksize); size_t new_stacksize = 16384; - if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) { - fprintf(stderr, "Can't set stack size %zu\n", new_stacksize); - } + if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) + HAL_DANGER("media", "Can't set stack size %zu\n", new_stacksize); if (pthread_create( &audPid, &thread_attr, (void *(*)(void *))aud_thread, NULL)) { - fprintf(stderr, "Starting the audio capture thread failed!\n"); - return EXIT_FAILURE; - } - if (pthread_attr_setstacksize(&thread_attr, stacksize)) { - fprintf(stderr, "Can't set stack size %zu\n", stacksize); + HAL_ERROR("media", "Starting the audio capture thread failed!\n"); } + if (pthread_attr_setstacksize(&thread_attr, stacksize)) + HAL_DANGER("media", "Can't set stack size %zu\n", stacksize); pthread_attr_destroy(&thread_attr); pthread_attr_init(&thread_attr); pthread_attr_getstacksize(&thread_attr, &stacksize); - if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) { - fprintf(stderr, "Can't set stack size %zu\n", new_stacksize); - } + if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) + HAL_DANGER("media", "Can't set stack size %zu\n", new_stacksize); if (pthread_create( - &aencPid, &thread_attr, (void *(*)(void *))aenc_thread, NULL)) { - fprintf(stderr, "Starting the audio encoding thread failed!\n"); - return EXIT_FAILURE; - } - if (pthread_attr_setstacksize(&thread_attr, stacksize)) { - fprintf(stderr, "Can't set stack size %zu\n", stacksize); - } + &aencPid, &thread_attr, (void *(*)(void *))aenc_thread, NULL)) + HAL_ERROR("media", "Starting the audio encoding thread failed!\n"); + if (pthread_attr_setstacksize(&thread_attr, stacksize)) + HAL_DANGER("media", "Can't set stack size %zu\n", stacksize); pthread_attr_destroy(&thread_attr); return ret; @@ -371,19 +361,13 @@ int disable_mjpeg(void) { if (!chnState[i].enable) continue; if (chnState[i].payload != HAL_VIDCODEC_MJPG) continue; - if (ret = unbind_channel(i, 1)) { - fprintf(stderr, - "Unbinding channel %d failed with %#x!\n%s\n", + if (ret = unbind_channel(i, 1)) + HAL_ERROR("media", "Unbinding channel %d failed with %#x!\n%s\n", i, ret, errstr(ret)); - return EXIT_FAILURE; - } - if (ret = disable_video(i, 1)) { - fprintf(stderr, - "Disabling encoder %d failed with %#x!\n%s\n", + if (ret = disable_video(i, 1)) + HAL_ERROR("media", "Disabling encoder %d failed with %#x!\n%s\n", i, ret, errstr(ret)); - return EXIT_FAILURE; - } } return EXIT_SUCCESS; @@ -394,13 +378,10 @@ int enable_mjpeg(void) { int index = take_next_free_channel(true); - if (ret = create_channel(index, app_config.mjpeg_width, - app_config.mjpeg_height, app_config.mjpeg_fps, 1)) { - fprintf(stderr, - "Creating channel %d failed with %#x!\n%s\n", + if (ret = create_channel(index, app_config.mjpeg_width, + app_config.mjpeg_height, app_config.mjpeg_fps, 1)) + HAL_ERROR("media", "Creating channel %d failed with %#x!\n%s\n", index, ret, errstr(ret)); - return EXIT_FAILURE; - } { hal_vidconfig config; @@ -425,20 +406,14 @@ int enable_mjpeg(void) { #endif } - if (ret) { - fprintf(stderr, - "Creating encoder %d failed with %#x!\n%s\n", + if (ret) + HAL_ERROR("media", "Creating encoder %d failed with %#x!\n%s\n", index, ret, errstr(ret)); - return EXIT_FAILURE; - } } - if (ret = bind_channel(index, app_config.mjpeg_fps, 1)) { - fprintf(stderr, - "Binding channel %d failed with %#x!\n%s\n", + if (ret = bind_channel(index, app_config.mjpeg_fps, 1)) + HAL_ERROR("media", "Binding channel %d failed with %#x!\n%s\n", index, ret, errstr(ret)); - return EXIT_FAILURE; - } return EXIT_SUCCESS; } @@ -451,19 +426,13 @@ int disable_mp4(void) { if (chnState[i].payload != HAL_VIDCODEC_H264 || chnState[i].payload != HAL_VIDCODEC_H265) continue; - if (ret = unbind_channel(i, 1)) { - fprintf(stderr, - "Unbinding channel %d failed with %#x!\n%s\n", + if (ret = unbind_channel(i, 1)) + HAL_ERROR("media", "Unbinding channel %d failed with %#x!\n%s\n", i, ret, errstr(ret)); - return EXIT_FAILURE; - } - if (ret = disable_video(i, 1)) { - fprintf(stderr, - "Disabling encoder %d failed with %#x!\n%s\n", + if (ret = disable_video(i, 1)) + HAL_ERROR("media", "Disabling encoder %d failed with %#x!\n%s\n", i, ret, errstr(ret)); - return EXIT_FAILURE; - } } return EXIT_SUCCESS; @@ -475,12 +444,9 @@ int enable_mp4(void) { int index = take_next_free_channel(true); if (ret = create_channel(index, app_config.mp4_width, - app_config.mp4_height, app_config.mp4_fps, 0)) { - fprintf(stderr, - "Creating channel %d failed with %#x!\n%s\n", + app_config.mp4_height, app_config.mp4_fps, 0)) + HAL_ERROR("media", "Creating channel %d failed with %#x!\n%s\n", index, ret, errstr(ret)); - return EXIT_FAILURE; - } { hal_vidconfig config; @@ -508,24 +474,19 @@ int enable_mp4(void) { #endif } - if (ret) { - fprintf(stderr, - "Creating encoder %d failed with %#x!\n%s\n", + if (ret) + HAL_ERROR("media", "Creating encoder %d failed with %#x!\n%s\n", index, ret, errstr(ret)); return EXIT_FAILURE; - } mp4_set_config(app_config.mp4_width, app_config.mp4_height, app_config.mp4_fps, app_config.audio_enable ? HAL_AUDCODEC_MP3 : HAL_AUDCODEC_UNSPEC, app_config.audio_bitrate, app_config.audio_srate); } - if (ret = bind_channel(index, app_config.mp4_fps, 0)) { - fprintf(stderr, - "Binding channel %d failed with %#x!\n%s\n", + if (ret = bind_channel(index, app_config.mp4_fps, 0)) + HAL_ERROR("media", "Binding channel %d failed with %#x!\n%s\n", index, ret, errstr(ret)); - return EXIT_FAILURE; - } return EXIT_SUCCESS; } @@ -545,11 +506,9 @@ int start_sdk(void) { case HAL_PLATFORM_T31: ret = t31_hal_init(); break; #endif } - if (ret) { - fprintf(stderr, "HAL initialization failed with %#x!\n%s\n", + if (ret) + HAL_ERROR("media", "HAL initialization failed with %#x!\n%s\n", ret, errstr(ret)); - return EXIT_FAILURE; - } switch (plat) { #if defined(__arm__) @@ -594,19 +553,15 @@ int start_sdk(void) { case HAL_PLATFORM_T31: ret = t31_system_init(); break; #endif } - if (ret) { - fprintf(stderr, "System initialization failed with %#x!\n%s\n", + if (ret) + HAL_ERROR("media", "System initialization failed with %#x!\n%s\n", ret, errstr(ret)); - return EXIT_FAILURE; - } if (app_config.audio_enable) { ret = enable_audio(); - if (ret) { - fprintf(stderr, "Audio initialization failed with %#x!\n%s\n", + if (ret) + HAL_ERROR("media", "Audio initialization failed with %#x!\n%s\n", ret, errstr(ret)); - return EXIT_FAILURE; - } } short width = MAX(app_config.mp4_width, app_config.mjpeg_width); @@ -630,11 +585,9 @@ int start_sdk(void) { app_config.flip, app_config.antiflicker, framerate); break; #endif } - if (ret) { - fprintf(stderr, "Pipeline creation failed with %#x!\n%s\n", + if (ret) + HAL_ERROR("media", "Pipeline creation failed with %#x!\n%s\n", ret, errstr(ret)); - return EXIT_FAILURE; - } if (isp_thread) { pthread_attr_t thread_attr; @@ -642,42 +595,33 @@ int start_sdk(void) { size_t stacksize; pthread_attr_getstacksize(&thread_attr, &stacksize); size_t new_stacksize = app_config.isp_thread_stack_size; - if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) { - fprintf(stderr, "Can't set stack size %zu!\n", new_stacksize); - } + if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) + HAL_DANGER("media", "Can't set stack size %zu!\n", new_stacksize); if (pthread_create( - &ispPid, &thread_attr, (void *(*)(void *))isp_thread, NULL)) { - fprintf(stderr, "Starting the imaging thread failed!\n"); - return EXIT_FAILURE; - } + &ispPid, &thread_attr, (void *(*)(void *))isp_thread, NULL)) + HAL_ERROR("media", "Starting the imaging thread failed!\n"); if (pthread_attr_setstacksize(&thread_attr, stacksize)) { - fprintf(stderr, "Can't set stack size %zu!\n", stacksize); + HAL_DANGER("media", "Can't set stack size %zu!\n", stacksize); } pthread_attr_destroy(&thread_attr); } if (app_config.mp4_enable) { ret = enable_mp4(); - if (ret) { - fprintf(stderr, "MP4 initialization failed with %#x!\n", ret); - return EXIT_FAILURE; - } + if (ret) + HAL_ERROR("media", "MP4 initialization failed with %#x!\n", ret); } if (app_config.mjpeg_enable) { ret = enable_mjpeg(); - if (ret) { - fprintf(stderr, "MJPEG initialization failed with %#x!\n", ret); - return EXIT_FAILURE; - } + if (ret) + HAL_ERROR("media", "MJPEG initialization failed with %#x!\n", ret); } if (app_config.jpeg_enable) { ret = jpeg_init(); - if (ret) { - fprintf(stderr, "JPEG initialization failed with %#x!\n", ret); - return EXIT_FAILURE; - } + if (ret) + HAL_ERROR("media", "JPEG initialization failed with %#x!\n", ret); } { @@ -686,17 +630,13 @@ int start_sdk(void) { size_t stacksize; pthread_attr_getstacksize(&thread_attr, &stacksize); size_t new_stacksize = app_config.venc_stream_thread_stack_size; - if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) { - fprintf(stderr, "Can't set stack size %zu\n", new_stacksize); - } + if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) + HAL_DANGER("media", "Can't set stack size %zu\n", new_stacksize); if (pthread_create( - &vidPid, &thread_attr, (void *(*)(void *))vid_thread, NULL)) { - fprintf(stderr, "Starting the video encoding thread failed!\n"); - return EXIT_FAILURE; - } - if (pthread_attr_setstacksize(&thread_attr, stacksize)) { - fprintf(stderr, "Can't set stack size %zu\n", stacksize); - } + &vidPid, &thread_attr, (void *(*)(void *))vid_thread, NULL)) + HAL_ERROR("media", "Starting the video encoding thread failed!\n"); + if (pthread_attr_setstacksize(&thread_attr, stacksize)) + HAL_DANGER("media", "Can't set stack size %zu\n", stacksize); pthread_attr_destroy(&thread_attr); } @@ -711,7 +651,7 @@ int start_sdk(void) { #endif } - fprintf(stderr, "SDK has started successfully!\n"); + HAL_INFO("media", "SDK has started successfully!\n"); return EXIT_SUCCESS; } @@ -787,6 +727,6 @@ int stop_sdk(void) { #endif } - fprintf(stderr, "SDK had stopped successfully!\n"); + HAL_INFO("media", "SDK had stopped successfully!\n"); return EXIT_SUCCESS; } \ No newline at end of file diff --git a/src/night.c b/src/night.c index 8faec30..495a2db 100644 --- a/src/night.c +++ b/src/night.c @@ -7,8 +7,6 @@ #include #include -#define tag "[night] " - static bool night_mode = false; pthread_t nightPid = 0; @@ -33,11 +31,11 @@ void ircut_off() { void set_night_mode(bool night) { if (night == night_mode) return; if (night) { - printf(tag "Changing mode to NIGHT\n"); + HAL_INFO("night", "Changing mode to NIGHT\n"); ircut_off(); set_grayscale(true); } else { - printf(tag "Changing mode to DAY\n"); + HAL_INFO("night", "Changing mode to DAY\n"); ircut_on(); set_grayscale(false); } @@ -56,7 +54,7 @@ void *night_thread(void) { int cnt = 0, tmp = 0, val; if ((adc_fd = open(app_config.adc_device, O_RDONLY | O_NONBLOCK)) <= 0) { - printf(tag "Could not open the ADC virtual device!\n"); + HAL_DANGER("night", "Could not open the ADC virtual device!\n"); return NULL; } struct timeval tv = { @@ -94,7 +92,7 @@ void *night_thread(void) { } usleep(10000); gpio_deinit(); - printf(tag "Night mode thread is closing...\n"); + HAL_INFO("night", "Night mode thread is closing...\n"); } int start_monitor_light_sensor() { @@ -104,11 +102,11 @@ int start_monitor_light_sensor() { pthread_attr_getstacksize(&thread_attr, &stacksize); size_t new_stacksize = 16 * 1024; if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) { - printf(tag "Error: Can't set stack size %zu\n", new_stacksize); + HAL_DANGER("night", "Error: Can't set stack size %zu\n", new_stacksize); } pthread_create(&nightPid, &thread_attr, (void *(*)(void *))night_thread, NULL); if (pthread_attr_setstacksize(&thread_attr, stacksize)) { - printf(tag "Error: Can't set stack size %zu\n", stacksize); + HAL_DANGER("night", "Error: Can't set stack size %zu\n", stacksize); } pthread_attr_destroy(&thread_attr); } diff --git a/src/region.c b/src/region.c index 576f9b5..d55e46d 100644 --- a/src/region.c +++ b/src/region.c @@ -1,7 +1,5 @@ #include "region.h" -#define tag "[region] " - osd osds[MAX_OSD]; pthread_t regionPid = 0; char timefmt[32] = DEF_TIMEFMT; @@ -101,13 +99,13 @@ static inline int region_open_bitmap(char *path, FILE **file) unsigned short type; if (!path) - REGION_ERROR("Filename is empty!\n"); + HAL_ERROR("region", "Filename is empty!\n"); if (!(*file = fopen(path, "rb"))) - REGION_ERROR("Opening the bitmap failed!\n"); + HAL_ERROR("region", "Opening the bitmap failed!\n"); if (fread(&type, 1, sizeof(type), *file) != sizeof(type)) - REGION_ERROR("Reading the bitmap failed!\n"); + HAL_ERROR("region", "Reading the bitmap failed!\n"); if (type != 0x4d42) - REGION_ERROR("Only bitmap files are currently supported!\n"); + HAL_ERROR("region", "Only bitmap files are currently supported!\n"); return EXIT_SUCCESS; } @@ -115,13 +113,13 @@ static inline int region_open_bitmap(char *path, FILE **file) int region_parse_bitmap(FILE **file, bitmapfile *bmpFile, bitmapinfo *bmpInfo) { if (fread(bmpFile, 1, sizeof(bitmapfile), *file) != sizeof(bitmapfile)) - REGION_ERROR("Extracting the bitmap file header failed!\n"); + HAL_ERROR("region", "Extracting the bitmap file header failed!\n"); if (fread(bmpInfo, 1, sizeof(bitmapinfo), *file) != sizeof(bitmapinfo)) - REGION_ERROR("Extracting the bitmap info failed!\n"); + HAL_ERROR("region", "Extracting the bitmap info failed!\n"); if (bmpInfo->bitCount < 24) - REGION_ERROR("Indexed or <3bpp bitmaps are not supported!\n"); + HAL_ERROR("region", "Indexed or <3bpp bitmaps are not supported!\n"); if (bmpInfo->bitCount != 32 && bmpInfo->compression) - REGION_ERROR("Bitfields and compressed modes are not supported!\n"); + HAL_ERROR("region", "Bitfields and compressed modes are not supported!\n"); return EXIT_SUCCESS; } @@ -141,25 +139,25 @@ int region_prepare_bitmap(char *path, hal_bitmap *bitmap) return EXIT_FAILURE; if (region_parse_bitmap(&file, &bmpFile, &bmpInfo)) - REGION_ERROR("Bitmap file \"%s\" cannot be processed!\n", path); + HAL_ERROR("region", "Bitmap file \"%s\" cannot be processed!\n", path); bpp = bmpInfo.bitCount / 8; size = bmpInfo.width * abs(bmpInfo.height); if (fseek(file, bmpFile.offBits, 0)) - REGION_ERROR("Navigating to the bitmap image data failed!\n"); + HAL_ERROR("region", "Navigating to the bitmap image data failed!\n"); if (!(buffer = malloc(size * bpp))) - REGION_ERROR("Allocating the bitmap input memory failed!\n"); + HAL_ERROR("region", "Allocating the bitmap input memory failed!\n"); if (fread(buffer, 1, (unsigned int)(size * bpp), file) != (unsigned int)(size * bpp)) - REGION_ERROR("Reading the bitmap image data failed!\n"); + HAL_ERROR("region", "Reading the bitmap image data failed!\n"); if (bmpInfo.height >= 0) { char *new = malloc(size * bpp); int stride = bmpInfo.width * bpp; if (!new) - REGION_ERROR("Allocating the flipped bitmap memory failed!\n"); + HAL_ERROR("region", "Allocating the flipped bitmap memory failed!\n"); for (int h = 0; h < bmpInfo.height; h++) memcpy(new + (h * stride), buffer + ((bmpInfo.height - 1) * stride) - (h * stride), @@ -169,7 +167,7 @@ int region_prepare_bitmap(char *path, hal_bitmap *bitmap) } if (!(bitmap->data = malloc(size * 2))) - REGION_ERROR("Allocating the destination buffer failed!\n"); + HAL_ERROR("region", "Allocating the destination buffer failed!\n"); start = buffer; dest = bitmap->data; @@ -347,11 +345,11 @@ int start_region_handler() { pthread_attr_getstacksize(&thread_attr, &stacksize); size_t new_stacksize = 320 * 1024; if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) { - printf(tag "Can't set stack size %zu\n", new_stacksize); + HAL_DANGER("region", "Can't set stack size %zu\n", new_stacksize); } pthread_create(®ionPid, &thread_attr, (void *(*)(void *))region_thread, NULL); if (pthread_attr_setstacksize(&thread_attr, stacksize)) { - printf(tag "Error: Can't set stack size %zu\n", stacksize); + HAL_DANGER("region", "Error: Can't set stack size %zu\n", stacksize); } pthread_attr_destroy(&thread_attr); } diff --git a/src/region.h b/src/region.h index 67c18ae..f852120 100644 --- a/src/region.h +++ b/src/region.h @@ -29,14 +29,6 @@ extern int asprintf(char **restrict strp, const char *restrict fmt, ...); #include #endif -#define REGION_ERROR(x, ...) \ - do { \ - fprintf(stderr, "[region] \033[31m"); \ - fprintf(stderr, (x), ##__VA_ARGS__); \ - fprintf(stderr, "\033[0m"); \ - return EXIT_FAILURE; \ - } while (0) - extern char keepRunning; extern int sysinfo (struct sysinfo *__info); diff --git a/src/text.c b/src/text.c index 165dd86..b08b2bd 100644 --- a/src/text.c +++ b/src/text.c @@ -88,7 +88,7 @@ int text_load_font(SFT *sft, const char *path, double size, SFT_LMetrics *lmtx) { SFT_Font *font = sft_loadfile(path); if (font == NULL) - TEXT_ERROR("sft_loadfile failed"); + HAL_ERROR("text", "sft_loadfile failed"); sft->font = font; sft->xScale = size; sft->yScale = size; @@ -96,16 +96,16 @@ int text_load_font(SFT *sft, const char *path, double size, SFT_LMetrics *lmtx) sft->yOffset = 0.0; sft->flags = SFT_DOWNWARD_Y; if (sft_lmetrics(sft, lmtx) < 0) - TEXT_ERROR("sft_lmetrics failed"); + HAL_ERROR("text", "sft_lmetrics failed"); return EXIT_SUCCESS; } int text_load_glyph(const SFT *sft, SFT_UChar codepoint, SFT_Glyph *glyph, SFT_GMetrics *metrics) { if (sft_lookup(sft, codepoint, glyph) < 0) - TEXT_ERROR("sft_lookup failed"); + HAL_ERROR("text", "sft_lookup failed"); if (sft_gmetrics(sft, *glyph, metrics) < 0) - TEXT_ERROR("sft_gmetrics failed"); + HAL_ERROR("text", "sft_gmetrics failed"); return EXIT_SUCCESS; } diff --git a/src/text.h b/src/text.h index 66a36d7..ae0430e 100644 --- a/src/text.h +++ b/src/text.h @@ -6,12 +6,4 @@ #include -#define TEXT_ERROR(x, ...) \ - do { \ - fprintf(stderr, "[text] \033[31m"); \ - fprintf(stderr, (x), ##__VA_ARGS__); \ - fprintf(stderr, "\033[0m"); \ - return EXIT_FAILURE; \ - } while (0) - hal_bitmap text_create_rendered(const char *font, double size, const char *text, int color); \ No newline at end of file diff --git a/src/watchdog.c b/src/watchdog.c index c8b67d9..3f0c537 100644 --- a/src/watchdog.c +++ b/src/watchdog.c @@ -15,13 +15,13 @@ int watchdog_start(int timeout) { while (*path) { if (access(*path++, F_OK)) continue; if ((fd = open(*(path - 1), O_WRONLY)) == -1) - WATCHDOG_ERROR("%s could not be opened!\n", *(path - 1), fd--); + HAL_ERROR("watchdog", "%s could not be opened!\n", *(path - 1), fd--); break; - } if (!fd) WATCHDOG_ERROR("No matching device has been found!\n"); + } if (!fd) HAL_ERROR("watchdog", "No matching device has been found!\n"); ioctl(fd, WDIOC_SETTIMEOUT, &timeout); - fprintf(stderr, "[watchdog] Watchdog started!\n"); + HAL_INFO("watchdog", "Watchdog started!\n"); return EXIT_SUCCESS; } @@ -31,5 +31,5 @@ void watchdog_stop(void) { close(fd); fd = 0; - fprintf(stderr, "[watchdog] Watchdog stopped!\n"); + HAL_INFO("watchdog", "Watchdog stopped!\n"); } \ No newline at end of file diff --git a/src/watchdog.h b/src/watchdog.h index 1461655..55e2171 100644 --- a/src/watchdog.h +++ b/src/watchdog.h @@ -1,5 +1,7 @@ #pragma once +#include "common.h" + #include #include #include @@ -7,14 +9,6 @@ #include #include -#define WATCHDOG_ERROR(x, ...) \ - do { \ - fprintf(stderr, "[watchdog] \033[31m"); \ - fprintf(stderr, (x), ##__VA_ARGS__); \ - fprintf(stderr, "\033[0m"); \ - return EXIT_FAILURE; \ - } while (0) - void watchdog_reset(void); int watchdog_start(int timeout); void watchdog_stop(void); \ No newline at end of file