5 #include "oswald_main.h"
7 #include "LcdDisplay.h"
8 #include "oswald_hal.h"
9 #include "oswald_graphics.h"
11 #include "oswald_watch_faces.h"
13 #if defined(__GNUC__) && (__MSP430X__ > 0)
14 __attribute__((__far__))
16 #include "bitmaps/battery0_icon.xbm"
17 #if defined(__GNUC__) && (__MSP430X__ > 0)
18 __attribute__((__far__))
20 #include "bitmaps/battery25_icon.xbm"
21 #if defined(__GNUC__) && (__MSP430X__ > 0)
22 __attribute__((__far__))
24 #include "bitmaps/battery50_icon.xbm"
25 #if defined(__GNUC__) && (__MSP430X__ > 0)
26 __attribute__((__far__))
28 #include "bitmaps/battery75_icon.xbm"
29 #if defined(__GNUC__) && (__MSP430X__ > 0)
30 __attribute__((__far__))
32 #include "bitmaps/battery100_icon.xbm"
33 #if defined(__GNUC__) && (__MSP430X__ > 0)
34 __attribute__((__far__))
36 #include "bitmaps/charger_icon.xbm"
37 #if defined(__GNUC__) && (__MSP430X__ > 0)
38 __attribute__((__far__))
40 #include "bitmaps/bluetooth_icon.xbm"
41 #if defined(__GNUC__) && (__MSP430X__ > 0)
42 __attribute__((__far__))
44 #include "bitmaps/bluetooth_con_icon.xbm"
47 /* sine table, per degree, factor 100 */
48 #if defined(__GNUC__) && (__MSP430X__ > 0)
49 __attribute__((__far__))
52 0, 2, 3, 5, 7, 9, 10, 12, 14, 16,
53 17, 19, 21, 22, 24, 26, 28, 29, 31, 33,
54 34, 36, 37, 39, 41, 42, 44, 45, 47, 48,
55 50, 52, 53, 54, 56, 57, 59, 60, 62, 63,
56 64, 66, 67, 68, 69, 71, 72, 73, 74, 75,
57 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
58 87, 87, 88, 89, 90, 91, 91, 92, 93, 93,
59 94, 95, 95, 96, 96, 97, 97, 97, 98, 98,
60 98, 99, 99, 99, 99, 100, 100, 100, 100, 100,
61 100, 100, 100, 100, 100, 100, 99, 99, 99, 99,
62 98, 98, 98, 97, 97, 97, 96, 96, 95, 95,
63 94, 93, 93, 92, 91, 91, 90, 89, 88, 87,
64 87, 86, 85, 84, 83, 82, 81, 80, 79, 78,
65 77, 75, 74, 73, 72, 71, 69, 68, 67, 66,
66 64, 63, 62, 60, 59, 57, 56, 54, 53, 52,
67 50, 48, 47, 45, 44, 42, 41, 39, 37, 36,
68 34, 33, 31, 29, 28, 26, 24, 22, 21, 19,
69 17, 16, 14, 12, 10, 9, 7, 5, 3, 2,
70 0, -2, -3, -5, -7, -9, -10, -12, -14, -16,
71 -17, -19, -21, -22, -24, -26, -28, -29, -31, -33,
72 -34, -36, -37, -39, -41, -42, -44, -45, -47, -48,
73 -50, -52, -53, -54, -56, -57, -59, -60, -62, -63,
74 -64, -66, -67, -68, -69, -71, -72, -73, -74, -75,
75 -77, -78, -79, -80, -81, -82, -83, -84, -85, -86,
76 -87, -87, -88, -89, -90, -91, -91, -92, -93, -93,
77 -94, -95, -95, -96, -96, -97, -97, -97, -98, -98,
78 -98, -99, -99, -99, -99,-100,-100,-100,-100,-100,
79 -100,-100,-100,-100,-100,-100, -99, -99, -99, -99,
80 -98, -98, -98, -97, -97, -97, -96, -96, -95, -95,
81 -94, -93, -93, -92, -91, -91, -90, -89, -88, -87,
82 -87, -86, -85, -84, -83, -82, -81, -80, -79, -78,
83 -77, -75, -74, -73, -72, -71, -69, -68, -67, -66,
84 -64, -63, -62, -60, -59, -57, -56, -54, -53, -52,
85 -50, -48, -47, -45, -44, -42, -41, -39, -37, -36,
86 -34, -33, -31, -29, -28, -26, -24, -22, -21, -19,
87 -17, -16, -14, -12, -10, -9, -7, -5, -3, -2
90 int16_t f_sin(int16_t v)
96 int16_t f_cos(int16_t v)
103 void draw_status_icons(void)
105 static uint8_t ci = 0;
107 if (OswaldPowerState.source) {
108 oswald_draw_bitmap(81, 0, charger_icon_width, charger_icon_height, charger_icon_bits);
110 if (OswaldPowerState.charge_state != POWER_CHARGER_DONE) {
111 if (ci==0) oswald_draw_bitmap(81, 0, battery0_icon_width, battery0_icon_height, battery0_icon_bits);
112 else if (ci==1) oswald_draw_bitmap(81, 0, battery25_icon_width, battery25_icon_height, battery25_icon_bits);
113 else if (ci==2) oswald_draw_bitmap(81, 0, battery50_icon_width, battery50_icon_height, battery50_icon_bits);
114 else if (ci==3) oswald_draw_bitmap(81, 0, battery75_icon_width, battery75_icon_height, battery75_icon_bits);
115 else if (ci==4) oswald_draw_bitmap(81, 0, battery100_icon_width, battery100_icon_height, battery100_icon_bits);
119 oswald_draw_bitmap(81, 0, battery100_icon_width, battery100_icon_height, battery100_icon_bits);
122 if (OswaldPowerState.percent > 75)
123 oswald_draw_bitmap_offset(81, 0, 0,0, battery100_icon_width, battery100_icon_height, battery100_icon_bits);
124 else if (OswaldPowerState.percent > 50)
125 oswald_draw_bitmap_offset(81, 0, 0,0, battery75_icon_width, battery75_icon_height, battery75_icon_bits);
126 else if (OswaldPowerState.percent > 25)
127 oswald_draw_bitmap_offset(81, 0, 0,0, battery50_icon_width, battery50_icon_height, battery50_icon_bits);
128 else if (OswaldPowerState.percent > 5)
129 oswald_draw_bitmap_offset(81, 0, 0,0, battery25_icon_width, battery25_icon_height, battery25_icon_bits);
131 oswald_draw_bitmap_offset(81, 0, 0,0, battery0_icon_width, battery0_icon_height, battery0_icon_bits);
134 if (hal_bluetooth_get_state() == BLUETOOTH_ON)
135 oswald_draw_bitmap(81, 0, bluetooth_icon_width, bluetooth_icon_height, bluetooth_icon_bits);
136 else if (hal_bluetooth_get_state() == BLUETOOTH_CONNECTED)
137 oswald_draw_bitmap(81, 0, bluetooth_con_icon_width, bluetooth_con_icon_height, bluetooth_con_icon_bits);
140 void DrawLcdAnaClock(boolean show_seconds)
142 int16_t i, x, y, x2, y2;
144 int8_t hour, minute, seconds;
147 hour = OswaldClk.hour;
148 minute = OswaldClk.minute;
149 seconds = OswaldClk.second;
154 // mf = (1. / 59.) * (double)minute;
162 hal_lcd_clear_display();
164 snprintf(tstr, 16, "%02d", OswaldClk.day);
166 SetFont(MetaWatch16);
167 WriteLcdString(70, 40, tstr);
169 oswald_write_string(70, 43, FONT_7x12b, tstr);
173 // plot(R*cos(360° * i/N), R*sin(360° * i/N))
174 for (i=0; i<12; i++) {
175 x = 47 + ((43 * f_cos((360 / 12) * i)) / 100);
176 y = 47 + ((43 * f_sin((360 / 12) * i)) / 100);
177 x2 = 47 + ((47 * f_cos((360 / 12) * i)) / 100);
178 y2 = 47 + ((47 * f_sin((360 / 12) * i)) / 100);
179 oswald_draw_line_ww(x, y, x2, y2, 2);
180 // g_printerr("br %d,%d %d,%d\n", x,y,x2,y2);
184 tmp = 47 + (30 * f_cos(((360 / 12) * hour) + ((OswaldClk.minute * 360) /12 / 60)) / 100);
186 tmp = 47 + (30 * f_sin(((360 / 12) * hour) + ((OswaldClk.minute * 360) /12 / 60)) / 100);
188 oswald_draw_line_ww(47, 47, x, y, 2);
191 tmp = 47 + ((40 * f_cos((360 / 60) * minute)) / 100);
193 tmp = 47 + ((40 * f_sin((360 / 60) * minute)) / 100);
195 oswald_draw_line_ww(47, 47, x, y, 2);
199 tmp = 47 + ((40 * f_cos((360 / 60) * seconds)) / 100);
201 tmp = 47 + ((40 * f_sin((360 / 60) * seconds)) / 100);
203 oswald_draw_line(47, 47, x, y);
208 hal_lcd_update_display();
211 void DrawLcdDigitalClock(boolean show_seconds)
219 SetFont(MetaWatchTime);
221 hal_lcd_clear_display();
222 //gRow += WriteLcdCharacter(ui, gRow, gColumn, TIME_CHARACTER_SPACE_INDEX);
223 if (OswaldClk.clk24hr) {
224 gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.hour / 10));
225 gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.hour % 10));
227 unsigned char val = OswaldClk.hour;
230 gRow += WriteLcdCharacter(gRow, gColumn, (val / 10));
231 gRow += WriteLcdCharacter(gRow, gColumn, (val % 10));
233 gRow += WriteLcdCharacter(gRow, gColumn, TIME_CHARACTER_COLON_INDEX);
234 gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.minute / 10));
235 gRow += WriteLcdCharacter(gRow, gColumn, (OswaldClk.minute % 10));
239 SetFont(MetaWatch16);
240 snprintf(tstr, 16, "%02d", OswaldClk.second);
241 WriteLcdString(gRow, 9, tstr);
246 if (!OswaldClk.clk24hr) {
247 if (OswaldClk.hour > 12) {
248 WriteLcdString(gRow, 3, "PM");
250 WriteLcdString(gRow, 3, "AM");
254 SetFont(MetaWatch16);
256 if (OswaldClk.day_first)
257 snprintf(tstr, 16, "%d.%d.%d", OswaldClk.day, OswaldClk.month, OswaldClk.year);
259 snprintf(tstr, 16, "%d/%d %d", OswaldClk.month, OswaldClk.day, OswaldClk.year);
260 WriteLcdString(3, 25, tstr);
267 for (i=0; i<strlen(MainMessage); i++) {
268 gRow += WriteLcdCharacter(gRow, gColumn, MainMessage[i]);
277 snprintf(tstr, 16, "%d%% (%dmV)", OswaldPowerState.percent, OswaldPowerState.level);
278 WriteLcdString(2, 48, tstr);
279 WriteLcdString(2, 64, OswaldPowerState.source ? "ext" : "bat");
281 /* this makes only sense when the charger is active */
282 if (OswaldPowerState.source) {
283 switch (OswaldPowerState.charge_state) {
284 case POWER_CHARGER_DONE:
285 WriteLcdString(2, 80, "charge done");
287 case POWER_CHARGER_PRECHARGE:
288 WriteLcdString(2, 80, "precharging");
290 case POWER_CHARGER_CHARGING:
291 WriteLcdString(2, 80, "charging");
293 case POWER_CHARGER_UNK:
294 WriteLcdString(2, 80, "charge unkn.");
302 hal_lcd_clear_display();
303 snprintf(tstr, 16, "%02d", OswaldClk.hour);
304 oswald_write_string(0, 0, FONT_16x26, tstr);
305 oswald_write_character(26, 0, FONT_16x26, ':');
306 snprintf(tstr, 16, "%02d", OswaldClk.minute);
307 oswald_write_string(36, 0, FONT_16x26, tstr);
309 if (OswaldClk.day_first)
310 snprintf(tstr, 16, "%d.%d.%d", OswaldClk.day, OswaldClk.month, OswaldClk.year);
312 snprintf(tstr, 16, "%d/%d %d", OswaldClk.month, OswaldClk.day, OswaldClk.year);
313 oswald_write_string(0, 25, FONT_7x12b, tstr);
317 for (i=0; i<strlen(MainMessage); i++) {
318 gRow += oswald_write_character(gRow, gColumn, FONT_6x8, MainMessage[i]);
329 hal_lcd_update_display();