diff options
Diffstat (limited to 'src/text.c')
| -rw-r--r-- | src/text.c | 59 |
1 files changed, 46 insertions, 13 deletions
@@ -5,6 +5,9 @@ #include "modules/pulse.h" #include "modules/time.h" #include "modules/battery.h" +#include "modules/cpu.h" +#include "modules/memory.h" +#include "modules/brightness.h" #include <stdio.h> #include <stdlib.h> @@ -12,18 +15,32 @@ #include <time.h> #include <tgmath.h> +#define VALUE_SIZE TEXT_SIZE + +struct text { + char value[VALUE_SIZE]; + + struct battery * battery; + struct pulse * pulse; + struct time * time; + struct cpu * cpu; + struct memory * memory; + struct brightness * brightness; +}; + struct text * text_new() { struct text * t = malloc(sizeof(struct text)); - memset(t->value, '\0', TEXT_SIZE); - - t->last_update = 0; + memset(t->value, '\0', VALUE_SIZE); t->battery = battery_new(); t->time = time_new(); t->pulse = pulse_new(); + t->cpu = cpu_new(); + t->memory = memory_new(); + t->brightness = brightness_new(); return t; } @@ -34,6 +51,10 @@ text_free(struct text * t) time_free(t->time); pulse_free(t->pulse); battery_free(t->battery); + cpu_free(t->cpu); + memory_free(t->memory); + brightness_free(t->brightness); + free(t); } @@ -41,25 +62,37 @@ 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) { + cpu_update(t->cpu); + memory_update(t->memory); + + if(should_update || pulse_should_update(t->pulse, now_time, 4)) { pulse_update(t->pulse); } - if(should_update || time_diff > 5) { + if(should_update || battery_should_update(t->battery, now_time, 10)) { battery_update(t->battery); } + if(should_update) { + brightness_update(t->brightness); + } + snprintf( - t->value, TEXT_SIZE, - "VOL: %s | BAT: %s | %s", - t->pulse->value, - t->battery->value, - t->time->value); + t->value, VALUE_SIZE, + "%s | %s | %s | %s | %s", + pulse_get_val(t->pulse), + cpu_get_val(t->cpu), + memory_get_val(t->memory), + battery_get_val(t->battery), + time_get_val(t->time)); +} + +const char * +text_get_val(struct text * t) +{ + return t->value; } |
