!7 module TimerModule > DynBigNumber { bool active; long setAt, setTill; start { dm_onTopInput(voidfunc(fS s) { new Matches m; if "* minutes" { switch to q(); int minutes = parseEnglishNumberOrInt($1); if (minutes <= 0) ret; setFields(active := true, setAt := now(), setTill := now()+fromMinutes(minutes)); print("Timer set to " + minutes + " from now"); } }); doEvery(1.0, r updateMe); } void update { long now = now(); if (setTill == 0 || !active) ret with setValue(""); if (setTill <= now) { setValue("ALARM!"); vmBus_send('timerAlarm, module()); ret; } else { long seconds = iround(toSeconds(setTill-now)); setValue(seconds/60 + ":" + formatInt(mod(seconds, 60), 2)); } } // API void reset enter { setFields(active := false, setAt := 0L, setTill := 0L); update(); } }