chiark / gitweb /
Factor out code to raise and lower output line from pulse().
authorBen Harris <bjh21@bjh21.me.uk>
Fri, 9 Nov 2018 18:55:22 +0000 (18:55 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Fri, 9 Nov 2018 18:55:22 +0000 (18:55 +0000)
The timing code in pulse is slightly twiddly and will probably be the
same for all output implementations.

clunk.c

diff --git a/clunk.c b/clunk.c
index 669c8b89e5621286feac42c1661630422e536a78..f3582499c2a3e0c1a22a689d740cc3cbc68d1744 100644 (file)
--- a/clunk.c
+++ b/clunk.c
@@ -18,15 +18,28 @@ static int const maxadvance = (10 * 3600) + (50 * 60);
 
 static struct tm displayed;
 
+static void
+dummy_out(bool state)
+{
+
+       /* Dummy implementation */
+       if (state) {
+               printf("ker...");
+               fflush(stdout);
+       } else {
+               printf("chunk!\n");
+               fflush(stdout);
+       }
+}
+
 static void
 pulse()
 {
        struct timespec const ts = { 0, pulsewidth };
-       /* Dummy implementation */
-       printf("ker...");
-       fflush(stdout);
+
+       dummy_out(true);
        clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
-       printf("chunk!");
+       dummy_out(false);
        displayed.tm_sec += 30;
        while (displayed.tm_sec >= 60) {
                displayed.tm_min++;