1 // ****************************************************************************
2 // vfdclock.c (C) 1992-2003 Christophe de Dinechin (ddd)
4 // ****************************************************************************
8 // Analog clock using the VFD800 server
17 // ****************************************************************************
18 // This document is confidential.
19 // Do not redistribute without written permission
20 // ****************************************************************************
22 // * Revision : $Revision$
24 // ****************************************************************************
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 // ----------------------------------------------------------------------------
41 vfd_configuration cfg
;
45 // Wait for the configuration to actually display something
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
58 vfd_fill_ellipse(vfd
, x
, y
, w
, h
);
59 vfd_select_display(vfd
);
61 // Display inner circle
66 vfd_ellipse(vfd
, x
, y
, w
, h
);
70 time_t t
= time(NULL
);
71 struct tm
*tm
= localtime(&t
);
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);
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
);
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 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
112 vfd_options(argc
, argv
);
113 vfd
= vfd_open(server
, port
);