]> git.karo-electronics.de Git - oswald.git/blob - ui/oswald_watch_faces.c
Oh boy... lots of changes, too many to describe
[oswald.git] / ui / oswald_watch_faces.c
1 #include <stdio.h>
2 #include <stdint.h>
3
4 #include "oswald.h"
5 #include "oswald_main.h"
6 #include "Fonts.h"
7 #include "LcdDisplay.h"
8 #include "oswald_hal.h"
9
10 #include "oswald_watch_faces.h"
11
12 int16_t sintab[]={
13             0,   2,   3,   5,   7,   9,  10,  12,  14,  16,
14            17,  19,  21,  22,  24,  26,  28,  29,  31,  33,
15            34,  36,  37,  39,  41,  42,  44,  45,  47,  48,
16            50,  52,  53,  54,  56,  57,  59,  60,  62,  63,
17            64,  66,  67,  68,  69,  71,  72,  73,  74,  75,
18            77,  78,  79,  80,  81,  82,  83,  84,  85,  86,
19            87,  87,  88,  89,  90,  91,  91,  92,  93,  93,
20            94,  95,  95,  96,  96,  97,  97,  97,  98,  98,
21            98,  99,  99,  99,  99, 100, 100, 100, 100, 100,
22           100, 100, 100, 100, 100, 100,  99,  99,  99,  99,
23            98,  98,  98,  97,  97,  97,  96,  96,  95,  95,
24            94,  93,  93,  92,  91,  91,  90,  89,  88,  87,
25            87,  86,  85,  84,  83,  82,  81,  80,  79,  78,
26            77,  75,  74,  73,  72,  71,  69,  68,  67,  66,
27            64,  63,  62,  60,  59,  57,  56,  54,  53,  52,
28            50,  48,  47,  45,  44,  42,  41,  39,  37,  36,
29            34,  33,  31,  29,  28,  26,  24,  22,  21,  19,
30            17,  16,  14,  12,  10,   9,   7,   5,   3,   2,
31             0,  -2,  -3,  -5,  -7,  -9, -10, -12, -14, -16,
32           -17, -19, -21, -22, -24, -26, -28, -29, -31, -33,
33           -34, -36, -37, -39, -41, -42, -44, -45, -47, -48,
34           -50, -52, -53, -54, -56, -57, -59, -60, -62, -63,
35           -64, -66, -67, -68, -69, -71, -72, -73, -74, -75,
36           -77, -78, -79, -80, -81, -82, -83, -84, -85, -86,
37           -87, -87, -88, -89, -90, -91, -91, -92, -93, -93,
38           -94, -95, -95, -96, -96, -97, -97, -97, -98, -98,
39           -98, -99, -99, -99, -99,-100,-100,-100,-100,-100,
40          -100,-100,-100,-100,-100,-100, -99, -99, -99, -99,
41           -98, -98, -98, -97, -97, -97, -96, -96, -95, -95,
42           -94, -93, -93, -92, -91, -91, -90, -89, -88, -87,
43           -87, -86, -85, -84, -83, -82, -81, -80, -79, -78,
44           -77, -75, -74, -73, -72, -71, -69, -68, -67, -66,
45           -64, -63, -62, -60, -59, -57, -56, -54, -53, -52,
46           -50, -48, -47, -45, -44, -42, -41, -39, -37, -36,
47           -34, -33, -31, -29, -28, -26, -24, -22, -21, -19,
48           -17, -16, -14, -12, -10,  -9,  -7,  -5,  -3,  -2
49 };
50
51 int16_t f_sin(int16_t v)
52 {
53         v %= 360;
54         return sintab[v];
55 }
56
57 int16_t f_cos(int16_t v)
58 {
59         v += 90;
60         v %= 360;
61         return sintab[v];
62 }
63
64 void DrawLcdAnaClock(boolean show_seconds)
65 {
66         int16_t i, x, y, x2, y2;
67         int16_t tmp;
68         int8_t hour, minute, seconds;
69         char tstr[16];
70
71         hour = OswaldClk.hour;
72         minute = OswaldClk.minute;
73         seconds = OswaldClk.second;
74
75         hour -= 3;
76         if (hour < 0)
77                 hour += 12;
78         // mf = (1. / 59.) * (double)minute;
79         minute -= 15;
80         if (minute < 0)
81                 minute += 60;
82         seconds -= 15;
83         if (seconds < 0)
84                 seconds += 60;
85
86         hal_lcd_clear_display();
87
88         SetFont(MetaWatch16);
89         snprintf(tstr, 16, "%02d", OswaldClk.day);
90         WriteLcdString(70, 40, tstr);
91
92         // plot(R*cos(360° * i/N), R*sin(360° * i/N))
93         for (i=0; i<12; i++) {
94                 tmp = 48 + ((43 * f_cos((360 / 12) * i)) / 100);
95                 x =  tmp;
96                 tmp = 48 + ((43 * f_sin((360 / 12) * i)) / 100);
97                 y =  tmp;
98                 tmp = 48 + ((48 * f_cos((360 / 12) * i)) / 100);
99                 x2 =  tmp;
100                 tmp = 48 + ((48 * f_sin((360 / 12) * i)) / 100);
101                 y2 =  tmp;
102                 DrawLcdLineBresenhamWW(x, y, x2, y2, 2);
103         };
104
105         // Hour
106         tmp = 48 + (30 * f_cos(((360 / 12) * hour) + ((OswaldClk.minute * 360) /12 / 60)) / 100);
107         x =  tmp;
108         tmp = 48 + (30 * f_sin(((360 / 12) * hour) + ((OswaldClk.minute * 360) /12 / 60)) / 100);
109         y =  tmp;
110         DrawLcdLineBresenhamWW(48, 48, x, y, 2);
111         // Minute
112         tmp = 48 + ((40 * f_cos((360 / 60) * minute)) / 100);
113         x =  tmp;
114         tmp = 48 + ((40 * f_sin((360 / 60) * minute)) / 100);
115         y =  tmp;
116         DrawLcdLineBresenhamWW(48, 48, x, y, 2);
117         if (show_seconds) {
118                 // Seconds
119                 tmp = 48 + ((40 * f_cos((360 / 60) * seconds)) / 100);
120                 x =  tmp;
121                 tmp = 48 + ((40 * f_sin((360 / 60) * seconds)) / 100);
122                 y =  tmp;
123                 DrawLcdLineBresenham(48, 48, x, y);
124         };
125
126         hal_lcd_update_display();
127 }
128
129 void DrawLcdDigitalClock(boolean show_seconds)
130 {
131         int gRow = 3;
132         int gColumn = 3;
133         char tstr[16];
134
135         SetFont(MetaWatchTime);
136
137         hal_lcd_clear_display();
138         //gRow += WriteLcdCharacter(ui, gRow, gColumn, TIME_CHARACTER_SPACE_INDEX);
139         if (OswaldClk.clk24hr) {
140                 gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.hour / 10));
141                 gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.hour % 10));
142         } else {
143                 unsigned char val = OswaldClk.hour;
144                 if (val > 12)
145                         val -= 12;
146                 gRow += WriteLcdCharacter(gRow, gColumn, (val / 10));
147                 gRow += WriteLcdCharacter(gRow, gColumn, (val % 10));
148         }
149         gRow += WriteLcdCharacter(gRow, gColumn, TIME_CHARACTER_COLON_INDEX);
150         gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.minute / 10));
151         gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.minute % 10));
152
153         gRow += 3;
154         if (show_seconds) {
155                 SetFont(MetaWatch16);
156                 snprintf(tstr, 16, "%02d", OswaldClk.second);
157                 WriteLcdString(gRow, 9, tstr);
158         };
159
160         SetFont(MetaWatch7);
161
162         if (!OswaldClk.clk24hr) {
163                 if (OswaldClk.hour > 12) {
164                         WriteLcdString(gRow, 3, "PM");
165                 } else {
166                         WriteLcdString(gRow, 3, "AM");
167                 }
168         }
169
170         SetFont(MetaWatch16);
171
172         if (OswaldClk.day_first)
173                 snprintf(tstr, 16, "%d.%d.%d", OswaldClk.day, OswaldClk.month, OswaldClk.year);
174         else
175                 snprintf(tstr, 16, "%d/%d %d", OswaldClk.month, OswaldClk.day, OswaldClk.year);
176         WriteLcdString(3, 25, tstr);
177
178         snprintf(tstr, 16, "%d%% (%dmV)", OswaldPowerState.percent, OswaldPowerState.level);
179         WriteLcdString(2, 48, tstr);
180         WriteLcdString(2, 64, OswaldPowerState.source ? "ext" : "bat");
181
182         /* this makes only sense when the charger is active */
183         if (OswaldPowerState.source) {
184                 switch (OswaldPowerState.charge_state) {
185                         case POWER_CHARGER_DONE:
186                                 WriteLcdString(2, 80, "charge done");
187                                 break;
188                         case POWER_CHARGER_PRECHARGE:
189                                 WriteLcdString(2, 80, "precharging");
190                                 break;
191                         case POWER_CHARGER_CHARGING:
192                                 WriteLcdString(2, 80, "charging");
193                                 break;
194                         case POWER_CHARGER_UNK:
195                                 WriteLcdString(2, 80, "charge unkn.");
196                                 break;
197                         default:
198                                 break;
199                 };
200         };
201         hal_lcd_update_display();
202 }
203