diff --git a/include/logger.h b/include/logger.h index 2573ec7..3740f1c 100644 --- a/include/logger.h +++ b/include/logger.h @@ -8,6 +8,13 @@ #include #include +#define COLOR_TRACE COLOR_GREEN +#define COLOR_DEBUG COLOR_BLUE +#define COLOR_INFO COLOR_CYAN +#define COLOR_WARN COLOR_YELLOW +#define COLOR_ERROR COLOR_RED +#define COLOR_FATAL COLOR_MAGENTA + #define _LOGGER_TIMESTAMP_SIZE 32 char _LOGGER_TIMESTAMP[_LOGGER_TIMESTAMP_SIZE]; @@ -17,37 +24,37 @@ logger_get_timestamp(); #define _LOGGER_MESSAGE(msg) COLOR_NONE " %s %s:%d:%s: " msg "\n", logger_get_timestamp(), __FILENAME__, __LINE__, __func__ #if LOG_LEVEL >= LOG_LEVEL_TRACE - #define LOG_TRACE(msg, ...) fprintf(stdout, COLOR_GREEN "[TRACE]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) + #define LOG_TRACE(msg, ...) fprintf(stdout, COLOR_TRACE "[TRACE]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #else #define LOG_TRACE(msg, ...) #endif #if LOG_LEVEL >= LOG_LEVEL_DEBUG - #define LOG_DEBUG(msg, ...) fprintf(stdout, COLOR_BLUE "[DEBUG]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) + #define LOG_DEBUG(msg, ...) fprintf(stdout, COLOR_DEBUG "[DEBUG]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #else #define LOG_DEBUG(msg, ...) #endif #if LOG_LEVEL >= LOG_LEVEL_INFO - #define LOG_INFO(msg, ...) fprintf(stdout, COLOR_CYAN "[ INFO]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) + #define LOG_INFO(msg, ...) fprintf(stdout, COLOR_INFO "[ INFO]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #else #define LOG_INFO(msg, ...) #endif #if LOG_LEVEL >= LOG_LEVEL_WARN - #define LOG_WARN(msg, ...) fprintf(stdout, COLOR_YELLOW "[ WARN]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) + #define LOG_WARN(msg, ...) fprintf(stdout, COLOR_WARN "[ WARN]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #else #define LOG_WARN(msg, ...) #endif #if LOG_LEVEL >= LOG_LEVEL_ERROR - #define LOG_ERROR(msg, ...) fprintf(stderr, COLOR_RED "[ERROR]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) + #define LOG_ERROR(msg, ...) fprintf(stderr, COLOR_ERROR "[ERROR]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #else #define LOG_ERROR(msg, ...) #endif #if LOG_LEVEL >= LOG_LEVEL_FATAL - #define LOG_FATAL(msg, ...) fprintf(stderr, COLOR_MAGENTA "[FATAL]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) + #define LOG_FATAL(msg, ...) fprintf(stderr, COLOR_FATAL "[FATAL]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #else #define LOG_FATAL(msg, ...) #endif diff --git a/include/wiring_debug.h b/include/wiring_debug.h index 290ede0..664d88b 100644 --- a/include/wiring_debug.h +++ b/include/wiring_debug.h @@ -3,13 +3,15 @@ #include -#ifdef WIRING_PI_DEBUG - #define wiringPiSetup() LOG_INFO("wiringPi wiringPiSetup()") - #define wiringPiSetupSys() LOG_INFO("wiringPi wiringPiSetupSys()") - #define pinMode(x,y) LOG_INFO("wiringPi pinMode(%d, %d)", x, y) - #define digitalWrite(x,y) LOG_INFO("wiringPi digitalWrite(%d, %d)", x, y) +#define LOG_WIRING_DEBUG(x, ...) LOG_DEBUG(x, ##__VA_ARGS__) - #define piFaceSetup(x) LOG_INFO("wiringPi piFaceSetup(%d)", x) +#ifdef WIRING_PI_DEBUG + #define wiringPiSetup() LOG_WIRING_DEBUG("wiringPi wiringPiSetup()") + #define wiringPiSetupSys() LOG_WIRING_DEBUG("wiringPi wiringPiSetupSys()") + #define pinMode(x,y) LOG_WIRING_DEBUG("wiringPi pinMode(%d, %d)", x, y) + #define digitalWrite(x,y) LOG_WIRING_DEBUG("wiringPi digitalWrite(%d, %d)", x, y) + + #define piFaceSetup(x) LOG_WIRING_DEBUG("wiringPi piFaceSetup(%d)", x) #endif #endif /* CONTROLLER_WIRING_DEBUG_H */ diff --git a/main.c b/main.c index 7d8e642..9d39f47 100644 --- a/main.c +++ b/main.c @@ -130,13 +130,13 @@ main(int argc, char** argv) /******************** START MAIN LOOP ********************/ - while(1) + for(;;) { ret = poll(fds, fd_count, timeout_msecs); if(ret == 0) { - LOG_TRACE("idle loop"); + LOG_DEBUG("===== IDLE LOOP START ====="); for(uint_fast8_t i = 0; i < this_controller->relay_count; ++i) { relay_t *relay = this_controller->relays[i];