diff --git a/Makefile b/Makefile index b060682..22e236b 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,8 @@ CCARGS=-Isrc/include -Wall -pedantic MODULES= \ modules/clock.dim \ - modules/battery.dim + modules/battery.dim \ + modules/timesince.dim all: $(BIN) $(MODULES) compile_commands.json diff --git a/src/modules/example.c b/src/modules/example.c index 9b43516..347a5f1 100644 --- a/src/modules/example.c +++ b/src/modules/example.c @@ -15,6 +15,7 @@ void* plug_init(void) { assert(p); p->name = "example"; p->version = "0.0.1"; + // Return NULL if error return p; } diff --git a/src/modules/timesince.c b/src/modules/timesince.c new file mode 100644 index 0000000..7f8aac3 --- /dev/null +++ b/src/modules/timesince.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +typedef struct plug_t { + char* name; // Always keep these on top + char* version; +} plug_t; + + +static plug_t* p = {0}; + + +void* plug_init(void) { + p = malloc(sizeof(plug_t)); + assert(p); + p->name = "time-since"; + p->version = "0.0.1"; + return p; +} + +void* plug_pre_reload(void) { + return p; // send state to dim +} + +void plug_post_reload(void* pp) { + p = pp; // get back state +} + +void plug_poll(char* buf, size_t len) { + struct tm t = {0}; + t.tm_year = 2024 - 1900; + t.tm_mon = 2; + t.tm_mday = 8; + + time_t diff = difftime(time(0), mktime(&t)) / (60 * 60 * 24); + + snprintf(buf, len, " %ld days <3", diff); +} + +void plug_free(void) { + free(p); // free state +}