This commit is contained in:
Gvidas Juknevičius 2024-05-31 21:06:32 +03:00
parent 7e2cbbe370
commit dc7f72f6ef
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
3 changed files with 47 additions and 1 deletions

View File

@ -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

View File

@ -15,6 +15,7 @@ void* plug_init(void) {
assert(p);
p->name = "example";
p->version = "0.0.1";
// Return NULL if error
return p;
}

44
src/modules/timesince.c Normal file
View File

@ -0,0 +1,44 @@
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <time.h>
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
}