view src/timer.c @ 12:dd427b7cc459 default tip

json: replace with nxjson library more lightweight, reduces the binary size by about 40 kb
author Paper <paper@paper.us.eu.org>
date Fri, 15 Mar 2024 20:46:18 -0400
parents e6a594f16403
children
line wrap: on
line source

#include "timer.h"

#include <assert.h>

void timer_init(struct timer* restrict timer, UINT interval, TIMERPROC timer_proc) {
	timer->id = 0;
	timer->interval = interval;
	timer->timer_proc = timer_proc;
}

int timer_set(struct timer* restrict timer) {
	assert(!timer->id);

	return !!(timer->id = SetTimer(NULL, timer->id, timer->interval, timer->timer_proc));
}

int timer_stop(struct timer* restrict timer) {
	assert(timer->id);

	BOOL ret = KillTimer(NULL, timer->id);
	timer->id = 0;
	return ret;
}