#include "text.h" #include "signal.h" #include "modules/pulse.h" #include "modules/time.h" #include "modules/battery.h" #include #include #include #include #include struct text * text_new() { struct text * t = malloc(sizeof(struct text)); memset(t->value, '\0', TEXT_SIZE); t->last_update = 0; t->battery = battery_new(); t->time = time_new(); t->pulse = pulse_new(); return t; } void text_free(struct text * t) { time_free(t->time); pulse_free(t->pulse); battery_free(t->battery); free(t); } void text_update(struct text * t) { time_t now_time = time(NULL); double time_diff = difftime(now_time, t->last_update); bool should_update = signal_should_update(); t->last_update = now_time; time_update(t->time); if(should_update || time_diff > 3) { pulse_update(t->pulse); } if(should_update || time_diff > 5) { battery_update(t->battery); } snprintf( t->value, TEXT_SIZE, "VOL: %s | BAT: %s | %s", t->pulse->value, t->battery->value, t->time->value); }