Added support for DE200C VFD
[lcdproc-de200c.git] / server / drivers / de200c-vfd / clients / vfdclock.c
blob878dbe0d252bbb81acbe9acfde0af32751062fbd
1 // ****************************************************************************
2 // vfdclock.c (C) 1992-2003 Christophe de Dinechin (ddd)
3 // VFD800 project
4 // ****************************************************************************
5 //
6 // File Description:
7 //
8 // Analog clock using the VFD800 server
9 //
10 //
11 //
12 //
13 //
14 //
15 //
16 //
17 // ****************************************************************************
18 // This document is confidential.
19 // Do not redistribute without written permission
20 // ****************************************************************************
21 // * File : $RCSFile$
22 // * Revision : $Revision$
23 // * Date : $Date$
24 // ****************************************************************************
26 #include <math.h>
27 #include <time.h>
29 #define VFDCLIENT "vfdclock"
30 #define VFDOPTIONS "vfdclock.tbl"
31 #define VFDCONFIG "clock"
32 #include "vfdclient.h"
35 void RunClock(int vfd, char *config)
36 // ----------------------------------------------------------------------------
37 // Loop, displaying the clock
38 // ----------------------------------------------------------------------------
40 char line[256];
41 vfd_configuration cfg;
42 int x, y, w, h;
43 int first = 1;
45 // Wait for the configuration to actually display something
48 if (!first)
49 sleep(1);
50 first = 0;
51 cfg = vfd_configure(vfd, config);
52 } while (cfg.w < 10 || cfg.h < 10);
53 x = cfg.x; y = cfg.y; w = cfg.w; h = cfg.h;
55 // Set mask to cover the clock itself
56 vfd_select_mask(vfd);
57 vfd_clear(vfd);
58 vfd_fill_ellipse(vfd, x, y, w, h);
59 vfd_select_display(vfd);
61 // Display inner circle
62 w -= 2;
63 h -= 2;
64 x += 1;
65 y += 1;
66 vfd_ellipse(vfd, x, y, w, h);
68 while (1)
70 time_t t = time(NULL);
71 struct tm *tm = localtime(&t);
73 int x0 = x + w/2;
74 int y0 = y + h/2;
76 int wsec = w / 2.5 * sin(tm->tm_sec / 60.0 * M_PI * 2);
77 int hsec = -h / 2.5 * cos(tm->tm_sec / 60.0 * M_PI * 2);
79 int wmin = w / 3.0 * sin(tm->tm_min / 60.0 * M_PI * 2);
80 int hmin = -h / 3.0 * cos(tm->tm_min / 60.0 * M_PI * 2);
82 int whr = w / 3.5 * sin(tm->tm_hour / 12.0 * M_PI * 2);
83 int hhr = -h / 3.5 * cos(tm->tm_hour / 12.0 * M_PI * 2);
85 // Draw the hands
86 vfd_set_color(vfd, 1);
87 vfd_line(vfd, x0, y0, whr, hhr);
88 vfd_line(vfd, x0, y0, wmin, hmin);
89 vfd_line(vfd, x0, y0, wsec, hsec);
90 vfd_update(vfd);
92 // Print date, time
94 // Sleep
95 usleep(1000000);
97 // Erase the hands (don't update to avoid blinking)
98 vfd_set_color(vfd, 0);
99 vfd_line(vfd, x0, y0, whr, hhr);
100 vfd_line(vfd, x0, y0, wmin, hmin);
101 vfd_line(vfd, x0, y0, wsec, hsec);
106 int main(int argc, char *argv[])
107 // ----------------------------------------------------------------------------
108 // Main entry point
109 // ----------------------------------------------------------------------------
111 int vfd;
112 vfd_options(argc, argv);
113 vfd = vfd_open(server, port);
114 RunClock(vfd, cfg);
115 return 0;