From 79fd3af970dbae42b96188fe4a302f0bfa421ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Zalewski?= Date: Wed, 24 Apr 2013 18:25:00 +0200 Subject: [PATCH] speed commit --- fancy/src/fancy.c | 6 +- fancy/src/fancy.c~ | 2 +- .../src/fonts/DIGITALDREAMNARROW.ttf | Bin 0 -> 29380 bytes .../Orbitron SIL OFL Font License 1.1.txt | 94 +++++++ .../resources/src/images/speed_background.png | Bin 0 -> 1340 bytes speed/resources/src/images/speed_logo.png | Bin 0 -> 400 bytes speed/resources/src/resource_map.json | 21 ++ speed/resources/src/resource_map.json~ | 21 ++ speed/src/speed.c | 245 ++++++++++++++++++ speed/src/speed.c~ | 245 ++++++++++++++++++ 10 files changed, 630 insertions(+), 4 deletions(-) create mode 100644 speed/resources/src/fonts/DIGITALDREAMNARROW.ttf create mode 100644 speed/resources/src/fonts/Orbitron SIL OFL Font License 1.1.txt create mode 100644 speed/resources/src/images/speed_background.png create mode 100644 speed/resources/src/images/speed_logo.png create mode 100644 speed/resources/src/resource_map.json create mode 100644 speed/resources/src/resource_map.json~ create mode 100644 speed/src/speed.c create mode 100644 speed/src/speed.c~ diff --git a/fancy/src/fancy.c b/fancy/src/fancy.c index 722e8e4..87ad257 100644 --- a/fancy/src/fancy.c +++ b/fancy/src/fancy.c @@ -15,9 +15,9 @@ DISPLAY_DATE - draws date HOUR_VIBRATION - short vibration every hour between 8:00 and 22:00 */ -#define DISPLAY_SECONDS true -#define HOUR_VIBRATION true -#define DISPLAY_DATE true +#define DISPLAY_SECONDS false +#define HOUR_VIBRATION false +#define DISPLAY_DATE false #define HOUR_VIBRATION_START 8 #define HOUR_VIBRATION_END 20 diff --git a/fancy/src/fancy.c~ b/fancy/src/fancy.c~ index 72ac2a9..216f705 100644 --- a/fancy/src/fancy.c~ +++ b/fancy/src/fancy.c~ @@ -16,7 +16,7 @@ HOUR_VIBRATION - short vibration every hour between 8:00 and 22:00 */ #define DISPLAY_SECONDS false -#define HOUR_VIBRATION true +#define HOUR_VIBRATION false #define DISPLAY_DATE true #define HOUR_VIBRATION_START 8 #define HOUR_VIBRATION_END 20 diff --git a/speed/resources/src/fonts/DIGITALDREAMNARROW.ttf b/speed/resources/src/fonts/DIGITALDREAMNARROW.ttf new file mode 100644 index 0000000000000000000000000000000000000000..3243bca228444a7194ae3d67a8a00700ee0f9b6e GIT binary patch literal 29380 zcmeHQdvIJ=dH>G6yLaF3)vlynNmp9QdRUfZ8~G8GS zou2=f7vJ$C+`owB>tB4}!875H{o~&Q%)f&7-?q3kzxWmNh*?M;>`(Z1KLw9-BM<(DC`P<0tJ+ z_MRDgdgidb=fI)Evj?ub%;{MZEeL{>{O0cnH^d7{kw#c*iDO z_rMH(PUGiceslm1;odA9fa~BE+}n$1Z^NU*upjTCGdAqvTRNVFLA>9FgLvO8+=TZX z!oLG}Wg2?-+;`%>Gjpfx<4f~%r|s#vrKJZR!ROrvCvZK3f4&mpg3m_|4hf`}Dj21BNV zeGiXsZ-?=z@u}=G{j>3@Wjt7(g3S}`z{2OSA4Cr<%subS-o7KZ{c{jqeR0PfTXVg+ zf!kx(MQj$z+o zN%7cg$Fs|9e3?IPOg=9OdHs2LdLD}m=C+p$MXT1gVe(Dewr(l0J$9en*I{>d+C7y@ z4_g==WxGa4FaEePHdd)_+(;$K86mcZmn4BDDYInKNdYfN!ZKpfcqqbHv|fK-&7+Xi zOOli&ncQB^utEG3W%v)f*X}hYMn~VN{*hvkTRmq?8s9`JB#;he=z<#d&T;sVvzJXw zIGbT?sG}5Nz1^8)ThYWqmGfZ}hWityWejeJnbGl)F0121TXQE|n-ztH+U;%bgp$%ye{{{t^8YYVP}JTGqI z6{1QR|BB_Ozm>jb6`>3C$No-KZ#lm18clBBYDQ}KSg{h zyL#&_uvY7cYsRi`-Fjj9zb@SWZT4fT&szgpB(RmJ83AIvjbedqBwI+(-OpU2+#HwUO81~wEv_U^EPpd{?`Fj;9Qp%&A|6pvBro13|Br}PF z^e5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Xe%T2<6!6$%dj5dbRXS+$%QAnXo|`M`2Rlc8goYB)EcyTHHdiyEVszKKZe4)Qu?3EjL8ybJQ9bJ8pWu1O-PDi zB7BkvJ~gR6Hcz|l0%Zm_n|5*K^Ei%+kEd5^%R?tV!33YcSY{J@uJVHnrWc(plNq`-Fxc&jaPJDO9RqqFQGydKb-h1^5z%>^E90y<*uGd`yu=_fIJ^KOn;&=C9 zxv$4M@5kRbfX}-Dzk4G->n1GYO}L%@A;8Ql0Qg!An2qE54S+-c4R9FK&~LdNUn?;M zaN8dN+v`lI!E85V|}ZBOP!}MDp8AZQ+9LH2A zan9m2z6%DWHsqmz-*1Bw&dk*g9XRt^1*-T~fNtmk8+xG+YS0e@umRtjF@$dl7=ev2 zitphVLo_u3n_&xV#rLaB!Zz3rJ76bVh4V5^;hbOBz_sAu3{BU;ZhV8rUf73oHSNdu zY}^1h!dr0GCVGFzL1gt=oWJQXzMbP%d}qh)IFr+z@K$&m9D%!VPN#eDtrH)DKZd8N zR`gm37Ghy$F`WOG#TXh_EE&aD&nzx%p4hB*wuFx@Y?*u$|D5EX+xX}92)}cu+U}6Y zJJlB__-#ArQ6_yLm3K(0R`Cqd7mqEYN>>=ZDT21z!qm4^yJ*+EyW*SPRzZPyg>KdRTp|I9E4<{BNl0GdrSJwkvzSUj>IyGyZ@@E4=`^IT@KVlXAajM6_BY^}z)YKc z5D`2WUof6Tjrswx#rFhm!2w~ogy=&o61j?ln|AGax z@zAt!hFiD?jBgqb9hdLFv*ogi%l6gPl|2WppPiTxzskRlzww3deElbPXQqCFzkqft zzzZj9e^}qH7I0o#8;>#iA)kofF>NXbSuk*;G3k~B5Bajh&n#hK1b#3OOF3w), +with Reserved Font Name Orbitron. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/speed/resources/src/images/speed_background.png b/speed/resources/src/images/speed_background.png new file mode 100644 index 0000000000000000000000000000000000000000..a3d099458a949a7cbf4b0305945db91ac4aa20f8 GIT binary patch literal 1340 zcmV-C1;hG@P)(_`g8%^e{{R4h=>PzAFaQARU;qF*m;eA5Z<1fd zMgRZ=!bwCyRCwC#o!gG#4_CfV^O9C?``}=g{>^!KT(Mkri-QPm?LXVP1!AGYzi) zy{r#?>yf5Y>*aKC*vB7@1kjkT{?hxt_ZmQ{i&~#Q+#_3LsBF>xu>@;)Ss~NE8wCdXmeaajX>9FFFo)NSQuX zNGw`baIcatUEA&wk%KR_R_o7WRmrhTb&tTocad6jNU!&-dMg#C}Wj!-Pn!AZW=4z;==}*HbPo>H~jvdr`?8ZyYly*$Ep^?dI2xI6C zeVJX{zi)WkOiU@C>B&qtZuw&U?z>py=w(VVdy_)L*JR2L-1HZ_{DBwMd`yxna9HUz zM%ef;k;$qA(<~C^uS&(JoUNKWCq2#>GC3@h@KCE&6xG*<6o;jnUCvx9yG!ba4}xKQ z0000000000004kDAvJH7gb4&gGcPW83_O0w`C*fRV3V;KTnRV~5N!F7SX1XvH->c= z4ttZsFjjnbZI|;nSkqzPp57imB!|sb)@K4MDQdu!h9tv9!p!Ot76JeO0000000000 z0000JjW#t&ySBdh@o2j(wzY?rp2rc}z>8`5JWyz?oVm5%a;D;@eHUP=#AMYh^+GfcvnjYZCs zwK=S`>p6tGv_P{Z7txQ1^NC_2!oqy8)yf28n%r8p;zLUd)<{sRfo%4PGYcH?iOuct zN=zgiGaZiBs8?buZm#6gT@o~DykUIJ1~RW!21&I_5F9tM&u~mmb6#vOLTl@ zE9QL70(Y)*O%l>?NMQuIzVNB>2sBR^R&04HS|rag8W(&d<$F z%`0JWE=o--Nlj5G&n(GMaQE~L2yf&Q2P%5)>EamTaeQl-r_d1v4wh5@>t|Z}M7nNB zHN5C8wD@jLuaTf;tc=ric9nq8A8S|je@|vgt82Jfxqq3jL8Gq3r!(tsPVDWPEqtOn zp>d+4i_4$*#iy6uZOi$wH|MkobKk%BHWU3^Lk@9F?n$cgdel304c7#*RVu5z77NLR zObXOf<21g!f=ey<_m;Yk3l^X93ffzq?B~Myjjg1s@#>qJXjc#6BJP^NPqV)X2-d!0 z%zA%GG>E;%l7AmV`&y={3GF(sQs>;&TJvSC+8g66#Y>$l+1Ia#w(@frame); + GPoint counter_second = GPoint(center.x + counter_second_hand_length * sin_lookup(counter_second_angle)/0xffff, + center.y + (-counter_second_hand_length) * cos_lookup(counter_second_angle)/0xffff); + GPoint second = GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff, + center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff); + + graphics_draw_line(ctx, counter_second, second); +} +#endif +void center_display_layer_update_callback(Layer *me, GContext* ctx) { + (void)me; + + GPoint center = grect_center_point(&me->frame); + graphics_context_set_fill_color(ctx, GColorWhite); + graphics_fill_circle(ctx, center, 10); + graphics_context_set_fill_color(ctx, GColorBlack); + graphics_fill_circle(ctx, center, 9); +} + +void minute_display_layer_update_callback(Layer *me, GContext* ctx) { + (void)me; + + PblTm t; + + get_time(&t); + + unsigned int angle = t.tm_min * 6 + t.tm_sec / 10; + gpath_rotate_to(&minute_hand_path, (TRIG_MAX_ANGLE / 360) * angle); + + graphics_context_set_fill_color(ctx, GColorWhite); + gpath_draw_filled(ctx, &minute_hand_path); + graphics_context_set_stroke_color(ctx, GColorBlack); + gpath_draw_outline(ctx, &minute_hand_path); +} + +void hour_display_layer_update_callback(Layer *me, GContext* ctx) { + (void)me; + + PblTm t; + + get_time(&t); + + unsigned int angle = t.tm_hour * 30 + t.tm_min / 2; + gpath_rotate_to(&hour_hand_path, (TRIG_MAX_ANGLE / 360) * angle); + + graphics_context_set_fill_color(ctx, GColorWhite); + gpath_draw_filled(ctx, &hour_hand_path); + graphics_context_set_stroke_color(ctx, GColorBlack); + gpath_draw_outline(ctx, &hour_hand_path); +} +#if DISPLAY_DATE +void draw_date(){ + PblTm t; + get_time(&t); + + string_format_time(date_text, sizeof(date_text), "%a %d", &t); + text_layer_set_text(&date_layer, date_text); +} +#endif + +void handle_init(AppContextRef ctx) { + (void)ctx; + + window_init(&window, "Speed Watch"); + window_stack_push(&window, true /* Animated */); + resource_init_current_app(&APP_RESOURCES); + + bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container); + layer_add_child(&window.layer, &background_image_container.layer.layer); + +#if DISPLAY_DATE + date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIGITALDREAM_NARROW_14)); + text_layer_init(&date_layer, GRect(27, 45, 90, 30)); + text_layer_set_text_color(&date_layer, GColorWhite); + text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter); + text_layer_set_background_color(&date_layer, GColorClear); + text_layer_set_font(&date_layer, date_font); + layer_add_child(&window.layer, &date_layer.layer); + + draw_date(); +#endif + layer_init(&hour_display_layer, window.layer.frame); + hour_display_layer.update_proc = &hour_display_layer_update_callback; + layer_add_child(&window.layer, &hour_display_layer); + + gpath_init(&hour_hand_path, &HOUR_HAND_PATH_POINTS); + gpath_move_to(&hour_hand_path, grect_center_point(&hour_display_layer.frame)); + + layer_init(&minute_display_layer, window.layer.frame); + minute_display_layer.update_proc = &minute_display_layer_update_callback; + layer_add_child(&window.layer, &minute_display_layer); + + gpath_init(&minute_hand_path, &MINUTE_HAND_PATH_POINTS); + gpath_move_to(&minute_hand_path, grect_center_point(&minute_display_layer.frame)); +#if DISPLAY_SECONDS + layer_init(&second_display_layer, window.layer.frame); + second_display_layer.update_proc = &second_display_layer_update_callback; + layer_add_child(&window.layer, &second_display_layer); +#endif + + layer_init(¢er_display_layer, window.layer.frame); + center_display_layer.update_proc = ¢er_display_layer_update_callback; + layer_add_child(&window.layer, ¢er_display_layer); +} + +void handle_deinit(AppContextRef ctx) { + (void)ctx; + + bmp_deinit_container(&background_image_container); +#if DISPLAY_DATE + fonts_unload_custom_font(date_font); +#endif +} + +void handle_tick(AppContextRef ctx, PebbleTickEvent *t){ + (void)t; + (void)ctx; + + if(t->tick_time->tm_sec%10==0) + { + layer_mark_dirty(&minute_display_layer); + + if(t->tick_time->tm_sec==0) + { + if(t->tick_time->tm_min%2==0) + { + layer_mark_dirty(&hour_display_layer); +#if DISPLAY_DATE + if(t->tick_time->tm_min==0&&t->tick_time->tm_hour==0) + { + draw_date(); + } +#endif +#if HOUR_VIBRATION + if(t->tick_time->tm_min==0 + &&t->tick_time->tm_hour>=HOUR_VIBRATION_START + &&t->tick_time->tm_hour<=HOUR_VIBRATION_END) + { + vibes_double_pulse(); + } +#endif + } + } + } + +#if DISPLAY_SECONDS + layer_mark_dirty(&second_display_layer); +#endif +} + +void pbl_main(void *params) { + PebbleAppHandlers handlers = { + .init_handler = &handle_init, + .deinit_handler = &handle_deinit, + .tick_info = { + .tick_handler = &handle_tick, +#if DISPLAY_SECONDS + .tick_units = SECOND_UNIT +#else + .tick_units = MINUTE_UNIT +#endif + } + }; + app_event_loop(params, &handlers); +} diff --git a/speed/src/speed.c~ b/speed/src/speed.c~ new file mode 100644 index 0000000..a0ef09d --- /dev/null +++ b/speed/src/speed.c~ @@ -0,0 +1,245 @@ +#include "pebble_os.h" +#include "pebble_app.h" +#include "pebble_fonts.h" + + +#define MY_UUID { 0xE5, 0x5F, 0x45, 0xB9, 0xF1, 0x57, 0x4B, 0x97, 0xBB, 0x46, 0x72, 0xF2, 0xC3, 0xC8, 0x54, 0xBB } +PBL_APP_INFO(MY_UUID, + "Speed", "Zalew", + 1, 0, /* App version */ + RESOURCE_ID_IMAGE_MENU_ICON, + APP_INFO_WATCH_FACE); +/*preprocessor conditions: +DISPLAY_SECONDS - draws seconds hand +DISPLAY_DATE - draws date +HOUR_VIBRATION - short vibration every hour between 8:00 and 22:00 +*/ + +#define DISPLAY_SECONDS true +#define DISPLAY_DATE true +#define HOUR_VIBRATION true +#define HOUR_VIBRATION_START 8 +#define HOUR_VIBRATION_END 20 + +Window window; +BmpContainer background_image_container; + +Layer minute_display_layer; +Layer hour_display_layer; +Layer center_display_layer; +Layer second_display_layer; +#if DISPLAY_DATE +TextLayer date_layer; +GFont date_font; +static char date_text[] = "12-04-13"; +#endif + +const GPathInfo MINUTE_HAND_PATH_POINTS = { + 4, + (GPoint []) { + {-5, 15}, + {5, 15}, + {3, -60}, + {-3, -60}, + } +}; + +const GPathInfo HOUR_HAND_PATH_POINTS = { + 4, + (GPoint []) { + {-5, 15}, + {5, 15}, + {3, -40}, + {-3, -40}, + } +}; +GPath hour_hand_path; +GPath minute_hand_path; + +#if DISPLAY_SECONDS +void second_display_layer_update_callback(Layer *me, GContext* ctx) { + (void)me; + + PblTm t; + get_time(&t); + + int32_t second_angle = t.tm_sec * (0xffff/60); + int32_t counter_second_angle = t.tm_sec * (0xffff/60); + if(t.tm_sec<30) + { + counter_second_angle += 0xffff/2; + } + else + { + counter_second_angle -= 0xffff/2; + } + int second_hand_length = 60; + int counter_second_hand_length = 15; + + graphics_context_set_fill_color(ctx, GColorWhite); + + GPoint center = grect_center_point(&me->frame); + GPoint counter_second = GPoint(center.x + counter_second_hand_length * sin_lookup(counter_second_angle)/0xffff, + center.y + (-counter_second_hand_length) * cos_lookup(counter_second_angle)/0xffff); + GPoint second = GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff, + center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff); + + graphics_draw_line(ctx, counter_second, second); +} +#endif +void center_display_layer_update_callback(Layer *me, GContext* ctx) { + (void)me; + + GPoint center = grect_center_point(&me->frame); + graphics_context_set_fill_color(ctx, GColorWhite); + graphics_fill_circle(ctx, center, 10); + graphics_context_set_fill_color(ctx, GColorBlack); + graphics_fill_circle(ctx, center, 9); +} + +void minute_display_layer_update_callback(Layer *me, GContext* ctx) { + (void)me; + + PblTm t; + + get_time(&t); + + unsigned int angle = t.tm_min * 6 + t.tm_sec / 10; + gpath_rotate_to(&minute_hand_path, (TRIG_MAX_ANGLE / 360) * angle); + + graphics_context_set_fill_color(ctx, GColorWhite); + gpath_draw_filled(ctx, &minute_hand_path); + graphics_context_set_stroke_color(ctx, GColorBlack); + gpath_draw_outline(ctx, &minute_hand_path); +} + +void hour_display_layer_update_callback(Layer *me, GContext* ctx) { + (void)me; + + PblTm t; + + get_time(&t); + + unsigned int angle = t.tm_hour * 30 + t.tm_min / 2; + gpath_rotate_to(&hour_hand_path, (TRIG_MAX_ANGLE / 360) * angle); + + graphics_context_set_fill_color(ctx, GColorWhite); + gpath_draw_filled(ctx, &hour_hand_path); + graphics_context_set_stroke_color(ctx, GColorBlack); + gpath_draw_outline(ctx, &hour_hand_path); +} +#if DISPLAY_DATE +void draw_date(){ + PblTm t; + get_time(&t); + + string_format_time(date_text, sizeof(date_text), "%a %d", &t); + text_layer_set_text(&date_layer, date_text); +} +#endif + +void handle_init(AppContextRef ctx) { + (void)ctx; + + window_init(&window, "Speed Watch"); + window_stack_push(&window, true /* Animated */); + resource_init_current_app(&APP_RESOURCES); + + bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container); + layer_add_child(&window.layer, &background_image_container.layer.layer); + +#if DISPLAY_DATE + date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIGITALDREAM_NARROW_14)); + text_layer_init(&date_layer, GRect(27, 45, 90, 30)); + text_layer_set_text_color(&date_layer, GColorWhite); + text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter); + text_layer_set_background_color(&date_layer, GColorClear); + text_layer_set_font(&date_layer, date_font); + layer_add_child(&window.layer, &date_layer.layer); + + draw_date(); +#endif + layer_init(&hour_display_layer, window.layer.frame); + hour_display_layer.update_proc = &hour_display_layer_update_callback; + layer_add_child(&window.layer, &hour_display_layer); + + gpath_init(&hour_hand_path, &HOUR_HAND_PATH_POINTS); + gpath_move_to(&hour_hand_path, grect_center_point(&hour_display_layer.frame)); + + layer_init(&minute_display_layer, window.layer.frame); + minute_display_layer.update_proc = &minute_display_layer_update_callback; + layer_add_child(&window.layer, &minute_display_layer); + + gpath_init(&minute_hand_path, &MINUTE_HAND_PATH_POINTS); + gpath_move_to(&minute_hand_path, grect_center_point(&minute_display_layer.frame)); +#if DISPLAY_SECONDS + layer_init(&second_display_layer, window.layer.frame); + second_display_layer.update_proc = &second_display_layer_update_callback; + layer_add_child(&window.layer, &second_display_layer); +#endif + + layer_init(¢er_display_layer, window.layer.frame); + center_display_layer.update_proc = ¢er_display_layer_update_callback; + layer_add_child(&window.layer, ¢er_display_layer); +} + +void handle_deinit(AppContextRef ctx) { + (void)ctx; + + bmp_deinit_container(&background_image_container); +#if DISPLAY_DATE + fonts_unload_custom_font(date_font); +#endif +} + +void handle_tick(AppContextRef ctx, PebbleTickEvent *t){ + (void)t; + (void)ctx; + + if(t->tick_time->tm_sec%10==0) + { + layer_mark_dirty(&minute_display_layer); + + if(t->tick_time->tm_sec==0) + { + if(t->tick_time->tm_min%2==0) + { + layer_mark_dirty(&hour_display_layer); +#if DISPLAY_DATE + if(t->tick_time->tm_min==0&&t->tick_time->tm_hour==0) + { + draw_date(); + } +#endif +#if HOUR_VIBRATION + if(t->tick_time->tm_min==0 + &&t->tick_time->tm_hour>=HOUR_VIBRATION_START + &&t->tick_time->tm_hour<=HOUR_VIBRATION_END) + { + vibes_double_pulse(); + } +#endif + } + } + } + +#if DISPLAY_SECONDS + layer_mark_dirty(&second_display_layer); +#endif +} + +void pbl_main(void *params) { + PebbleAppHandlers handlers = { + .init_handler = &handle_init, + .deinit_handler = &handle_deinit, + .tick_info = { + .tick_handler = &handle_tick, +#if DISPLAY_SECONDS + .tick_units = SECOND_UNIT +#else + .tick_units = MINUTE_UNIT +#endif + } + }; + app_event_loop(params, &handlers); +}