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 0000000..3243bca Binary files /dev/null and b/speed/resources/src/fonts/DIGITALDREAMNARROW.ttf differ diff --git a/speed/resources/src/fonts/Orbitron SIL OFL Font License 1.1.txt b/speed/resources/src/fonts/Orbitron SIL OFL Font License 1.1.txt new file mode 100644 index 0000000..934ac57 --- /dev/null +++ b/speed/resources/src/fonts/Orbitron SIL OFL Font License 1.1.txt @@ -0,0 +1,94 @@ +Copyright (c) 2009, Matt McInerney (), +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 0000000..a3d0994 Binary files /dev/null and b/speed/resources/src/images/speed_background.png differ diff --git a/speed/resources/src/images/speed_logo.png b/speed/resources/src/images/speed_logo.png new file mode 100644 index 0000000..20788e5 Binary files /dev/null and b/speed/resources/src/images/speed_logo.png differ diff --git a/speed/resources/src/resource_map.json b/speed/resources/src/resource_map.json new file mode 100644 index 0000000..c3d6eed --- /dev/null +++ b/speed/resources/src/resource_map.json @@ -0,0 +1,21 @@ + +{"friendlyVersion": "VERSION", + "versionDefName": "APP_RESOURCES", + "media": [ + { + "type":"png", + "defName":"IMAGE_BACKGROUND", + "file":"images/speed_background.png" + }, + { + "type":"png", + "defName":"IMAGE_MENU_ICON", + "file":"images/speed_logo.png" + }, + { + "type": "font", + "defName": "FONT_DIGITALDREAM_NARROW_14", + "file": "fonts/DIGITALDREAMNARROW.ttf" + } + ] +} diff --git a/speed/resources/src/resource_map.json~ b/speed/resources/src/resource_map.json~ new file mode 100644 index 0000000..29029c8 --- /dev/null +++ b/speed/resources/src/resource_map.json~ @@ -0,0 +1,21 @@ + +{"friendlyVersion": "VERSION", + "versionDefName": "APP_RESOURCES", + "media": [ + { + "type":"png", + "defName":"IMAGE_BACKGROUND", + "file":"images/speed_background.png" + }, + { + "type":"png", + "defName":"IMAGE_MENU_ICON", + "file":"images/speed_logo.png" + }, + { + "type": "font", + "defName": "FONT_ANONYMOUS_14", + "file": "fonts/Anonymous.ttf" + } + ] +} diff --git a/speed/src/speed.c b/speed/src/speed.c new file mode 100644 index 0000000..74ed689 --- /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[] = "WED 24"; +#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); +} 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); +}