#include <stdio.h>
#include <time.h>
-long const pulsewidth = 250000000; /* nanoseconds */
+static long const pulsewidth = 250000000; /* nanoseconds */
+
+static struct tm displayed;
static void
pulse()
printf("ker...");
fflush(stdout);
clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
- printf("chunk!\n");
+ printf("chunk!");
+ displayed.tm_sec += 30;
+ while (displayed.tm_sec >= 60) {
+ displayed.tm_min++;
+ displayed.tm_sec -= 60;
+ }
+ while (displayed.tm_min >= 60) {
+ displayed.tm_hour++;
+ displayed.tm_min -= 60;
+ }
+ displayed.tm_hour %= 12;
+ printf(" (%02d:%02d:%02d)\n",
+ displayed.tm_hour, displayed.tm_min, displayed.tm_sec);
+ fflush(stdout);
+}
+
+static void
+init()
+{
+ struct timespec ts;
+
+ tzset();
+ if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
+ err (1, "clock_gettime");
+ if (localtime_r(&ts.tv_sec, &displayed) == NULL)
+ err(1, "localtime_r");
+ displayed.tm_sec = (displayed.tm_sec >= 30) ? 30 : 0;
}
+
static void
run()
main(int argc, char **argv)
{
- tzset();
+ init();
run();
return 0;
}