asd
This commit is contained in:
parent
7e2cbbe370
commit
dc7f72f6ef
3
Makefile
3
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
|
||||
|
|
|
@ -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
44
src/modules/timesince.c
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user