diff options
| author | Sam Light <sam@lightscale.co.uk> | 2025-09-10 19:37:28 +0100 |
|---|---|---|
| committer | Sam Light <sam@lightscale.co.uk> | 2025-09-10 19:37:28 +0100 |
| commit | 8101b1aa507795224054a752dd603ec3426c40ee (patch) | |
| tree | 79c593f1d2a8c54f380f1d373a79f21cc5fc4a06 /src/text.c | |
| parent | d9b456d738e5013d48f41f5e6315ef7c22d6acf0 (diff) | |
Created better management of updates + update on SIGUSR1
Diffstat (limited to 'src/text.c')
| -rw-r--r-- | src/text.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -1,5 +1,7 @@ #include "text.h" +#include "signal.h" + #include "modules/pulse.h" #include "modules/time.h" #include "modules/battery.h" @@ -17,6 +19,8 @@ text_new() memset(t->value, '\0', TEXT_SIZE); + t->last_update = 0; + t->battery = battery_new(); t->time = time_new(); t->pulse = pulse_new(); @@ -36,9 +40,21 @@ text_free(struct text * 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); - pulse_update(t->pulse); - battery_update(t->battery); + + 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, |
