void handle_init(AppContextRef ctx) { Layer *rootLayer; int i; window_init(&window, "Minimalist"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); clock12 = !clock_is_24h_style(); resource_init_current_app(&APP_RESOURCES); for (i=0; i<NUM_IMAGES; i++) { heap_bitmap_init(&digitBmp[i], digitId[i]); #if WHITE_BACKGROUND bmpNegative(&digitBmp[i].bmp); #endif } rootLayer = window_get_root_layer(&window); layer_init(&layer, GRect(0,0,SCREENW,SCREENH)); layer_set_update_proc(&layer, &update_display); layer_add_child(rootLayer, &layer); handle_tick(ctx, NULL); //layer_mark_dirty(&layer); }
void tap_timeout() { tap_timer = NULL; // Put back normal value to Date text layer time_t now = time(NULL); handle_tick(localtime(&now), DAY_UNIT); }
static void init(void) { window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); weather_data = malloc(sizeof(WeatherData)); init_network(weather_data); font_date = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FUTURA_18)); font_time = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FUTURA_CONDENSED_53)); time_layer = text_layer_create(TIME_FRAME); text_layer_set_text_color(time_layer, GColorWhite); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_font(time_layer, font_time); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer)); date_layer = text_layer_create(DATE_FRAME); text_layer_set_text_color(date_layer, GColorWhite); text_layer_set_background_color(date_layer, GColorClear); text_layer_set_font(date_layer, font_date); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer)); // Add weather layer weather_layer = weather_layer_create(GRect(0, 90, 144, 80)); layer_add_child(window_get_root_layer(window), weather_layer); // Update the screen right away time_t now = time(NULL); handle_tick(localtime(&now), SECOND_UNIT | MINUTE_UNIT | HOUR_UNIT | DAY_UNIT ); // And then every second tick_timer_service_subscribe(SECOND_UNIT, handle_tick); }
static void in_received_handler(DictionaryIterator *received, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Received config"); Tuple *tuple = dict_find(received, MSG_START_TIME); if (tuple) { start_time = tuple->value->int32; persist_write_int(MSG_START_TIME, start_time); } tuple = dict_find(received, MSG_END_TIME); if (tuple) { end_time = tuple->value->int32; persist_write_int(MSG_END_TIME, end_time); } tuple = dict_find(received, MSG_TEXT_OTSLUJIL); if (tuple) { strcpy(text_otslujul, tuple->value->cstring); persist_write_string(MSG_TEXT_OTSLUJIL, text_otslujul); } tuple = dict_find(received, MSG_TEXT_OSTALOS); if (tuple) { strcpy(text_ostalos, tuple->value->cstring); persist_write_string(MSG_TEXT_OSTALOS, text_ostalos); } tuple = dict_find(received, MSG_TEXT_UJE); if (tuple) { strcpy(text_uje, tuple->value->cstring); persist_write_string(MSG_TEXT_UJE, text_uje); } time_t now = time(NULL); handle_tick(localtime(&now), 0); }
void init(void) { window = window_create(); window_stack_push(window, true); s_time_layer = text_layer_create(GRect(0, 15, 144, 40)); text_layer_set_background_color(s_time_layer, GColorBlack); text_layer_set_text_color(s_time_layer, GColorWhite); text_layer_set_text(s_time_layer, "00:00:00"); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21)); layer_add_child(window_get_root_layer(window), (Layer *)s_time_layer); //Somebody set us up the CLOCK time_t now = time(NULL); struct tm *tick_time = localtime(&now); handle_tick(tick_time, SECOND_UNIT); //tick_timer_service_subscribe(SECOND_UNIT, handle_tick); Layer *window_layer = window_get_root_layer(window); layer_set_update_proc(window_layer, bg_update_proc); // Register AppMessage handlers //app_message_register_inbox_received(in_received_handler); //app_message_register_inbox_dropped(in_dropped_handler); //app_message_register_outbox_failed(out_failed_handler); //app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); //send_message(); }
static void init(void) { APP_LOG(APP_LOG_LEVEL_DEBUG, "init started"); window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); weather_data = malloc(sizeof(WeatherData)); init_network(weather_data); // Setup our layers time_layer_create(TIME_FRAME, window); date_layer_create(DATE_FRAME, window); weather_layer_create(WEATHER_FRAME, window); debug_layer_create(DEBUG_FRAME, window); battery_layer_create(BATTERY_FRAME, window); load_persisted_values(weather_data); // Kickoff our weather loading 'dot' animation weather_animate(weather_data); // Setup a timer incase we miss or don't receive js_ready to manually try ourselves initial_jsready_timer = app_timer_register(MAX_JS_READY_WAIT, initial_jsready_callback, NULL); // Update the screen right away time_t now = time(NULL); handle_tick(localtime(&now), MINUTE_UNIT | DAY_UNIT ); // And then every minute tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); }
static void init(void) { memset(&time_digits_layers, 0, sizeof(time_digits_layers)); memset(&time_digits_images, 0, sizeof(time_digits_images)); const int inbound_size = 64; const int outbound_size = 64; app_message_open(inbound_size, outbound_size); window = window_create(); if (window == NULL) { return; } window_set_background_color(window, GColorBlack); canvas = layer_create(GRect(0, 0, 144, 168)); layer_set_update_proc(canvas, (LayerUpdateProc) render); layer_add_child(window_get_root_layer(window), canvas); window_stack_push(window, true); Layer *window_layer = window_get_root_layer(window); load_settings(); // Open AppMessage connection app_message_register_inbox_received(inbox_received_handler); app_message_open(128, 128); //owm_weather_init(5ba77aab84470992ddc7e49e4985aeab); //events_app_message_open(); //owm_weather_fetch(); handle_weather(); handle_battery(battery_state_service_peek()); battery_state_service_subscribe(handle_battery); // Create time and date layers GRect dummy_frame = { {0, 0}, {0, 0} }; for (int i = 0; i < TOTAL_TIME_DIGITS; i++) { time_digits_layers[i] = bitmap_layer_create(dummy_frame); layer_add_child(window_layer, bitmap_layer_get_layer(time_digits_layers[i])); } mFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_20)); mDayText = malloc(mDayTextSize); mWeatherText = malloc(mWeatherTextSize); mBatteryText = malloc(mBatteryTextSize); // Avoids a blank screen on watch start. time_t now = time(NULL); struct tm *tick_time = localtime(&now); handle_tick(tick_time, DAY_UNIT + HOUR_UNIT + MINUTE_UNIT); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); }
/* Force update of time */ void update_time() { // Get current time time_t now = time( NULL ); struct tm *tick_time = localtime( &now ); // Force update to avoid a blank screen at startup of the watchface handle_tick( tick_time, SECOND_UNIT ); }
static void *itimer_thread_func(void *_handle_tick) { TickProc handle_tick = _handle_tick; uint64_t nticks; int timerfd = -1; #if defined(USE_TIMERFD_FOR_ITIMER) && USE_TIMERFD_FOR_ITIMER struct itimerspec it; it.it_value.tv_sec = TimeToSeconds(itimer_interval); it.it_value.tv_nsec = TimeToNS(itimer_interval) % 1000000000; it.it_interval = it.it_value; timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); if (timerfd == -1) { sysErrorBelch("timerfd_create"); stg_exit(EXIT_FAILURE); } if (!TFD_CLOEXEC) { fcntl(timerfd, F_SETFD, FD_CLOEXEC); } if (timerfd_settime(timerfd, 0, &it, NULL)) { sysErrorBelch("timerfd_settime"); stg_exit(EXIT_FAILURE); } #endif while (!exited) { if (USE_TIMERFD_FOR_ITIMER) { if (read(timerfd, &nticks, sizeof(nticks)) != sizeof(nticks)) { if (errno != EINTR) { sysErrorBelch("Itimer: read(timerfd) failed"); } } } else { if (usleep(TimeToUS(itimer_interval)) != 0 && errno != EINTR) { sysErrorBelch("usleep(TimeToUS(itimer_interval) failed"); } } // first try a cheap test if (stopped) { ACQUIRE_LOCK(&mutex); // should we really stop? if (stopped) { waitCondition(&start_cond, &mutex); } RELEASE_LOCK(&mutex); } else { handle_tick(0); } } if (USE_TIMERFD_FOR_ITIMER) close(timerfd); closeMutex(&mutex); closeCondition(&start_cond); return NULL; }
void do_update() { time_t curTime; struct tm *now; splashEnded = true; curTime = time(NULL); now = localtime(&curTime); handle_tick(now, 0); }
void handle_timer(void *data) { time_t curTime; struct tm *now; splashEnded = true; curTime = time(NULL); now = localtime(&curTime); handle_tick(now, 0); }
static void *itimer_thread_func(void *_handle_tick) { TickProc handle_tick = _handle_tick; while (1) { usleep(TimeToUS(itimer_interval)); switch (itimer_enabled) { case 1: handle_tick(0); break; case 2: itimer_enabled = 0; } } return NULL; }
static void s_sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) { //APP_LOG(APP_LOG_LEVEL_DEBUG, "sync_tuple_changed_callback, key: %lu", key); //APP_LOG(APP_LOG_LEVEL_DEBUG, "sync_tuple_changed_callback, new_tuple->value->cstring: %s", new_tuple->value->cstring); switch (key) { case DialColor_KEY: strcpy(configs.dialcolor, new_tuple->value->cstring); load_background_image(); break; case SecondHandOption_KEY: strcpy(configs.secondhandoption, new_tuple->value->cstring); if (strcmp(configs.secondhandoption, "quartz") == 0) { tick_timer_service_unsubscribe(); tick_timer_service_subscribe(SECOND_UNIT, handle_tick); } else if (strcmp(configs.secondhandoption, "stop2go") == 0) { tick_timer_service_unsubscribe(); tick_timer_service_subscribe(SECOND_UNIT, handle_tick); } else if (strcmp(configs.secondhandoption, "off") == 0) { tick_timer_service_unsubscribe(); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); } break; case DateOption_KEY: strcpy(configs.dateoption, new_tuple->value->cstring); break; case HourlyVibration_KEY: strcpy(configs.hourlyvibration, new_tuple->value->cstring); break; case BluetoothStatusDetection_KEY: configs.bluetoothstatusdetection = new_tuple->value->uint8; break; } time_t now = time(NULL); struct tm *t = localtime(&now); handle_tick(t, HOUR_UNIT + MINUTE_UNIT + SECOND_UNIT); }
void Bridge::objRun() { set(true); TimeScope time_scope(100_msec); for(;;) switch( msem.take(time_scope) ) { case Event_Timeout : if( time_scope.nextScope_skip() ) handle_tick(); break; case Event_Stop : return; case Event_ToServer : handle_to_server(); break; case Event_ToClient : handle_to_client(); break; } }
static void window_load(Window *window) { window_layer = window_get_root_layer(window); //s_font_teko_sb_20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TEKO_SB_20)); //date_text_layer = text_layer_create(GRect(77, 145, 144, 50)); //text_layer_set_text_color(date_text_layer, GColorMalachite); //text_layer_set_background_color(date_text_layer, GColorClear); //text_layer_set_text(date_text_layer, date_text); //text_layer_set_font(date_text_layer, s_font_teko_sb_20); //layer_add_child(window_layer, text_layer_get_layer(date_text_layer)); time_t now = time(NULL); struct tm *tick_time = localtime(&now); handle_tick(tick_time, MINUTE_UNIT); }
static void inbox_received_handler(DictionaryIterator *iter, void *context) { // Read preferences Tuple* big_hour_t = dict_find(iter, MESSAGE_KEY_BigHour); if (big_hour_t) { mBigHour = big_hour_t->value->int32 == 1; // Save the setting. APP_LOG(APP_LOG_LEVEL_DEBUG, "load_settings - setting set: %d", mBigHour); persist_write_bool(0, mBigHour); // Force a redraw with updated settings. time_t now = time(NULL); struct tm *tick_time = localtime(&now); handle_tick(tick_time, DAY_UNIT + HOUR_UNIT + MINUTE_UNIT); } }
static void init_clock(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); time_layer = text_layer_create(GRect(0, 30, bounds.size.w, bounds.size.h-100)); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); text_layer_set_text_color(time_layer, GColorWhite); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49)); time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_tick(current_time, MINUTE_UNIT); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer)); temp_layer = text_layer_create(GRect(0, 130, (bounds.size.w/2), bounds.size.h-130)); text_layer_set_text_color(temp_layer, GColorBlack); text_layer_set_text_alignment(temp_layer, GTextAlignmentCenter); text_layer_set_background_color(temp_layer, GColorWhite); text_layer_set_overflow_mode(temp_layer, GTextOverflowModeFill); text_layer_set_font(temp_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(temp_layer)); aqi_value_layer = text_layer_create(GRect(bounds.size.w/2, 130, (bounds.size.w/2), bounds.size.h-130)); text_layer_set_text_color(aqi_value_layer, GColorBlack); text_layer_set_text_alignment(aqi_value_layer, GTextAlignmentCenter); text_layer_set_background_color(aqi_value_layer, GColorWhite); text_layer_set_overflow_mode(aqi_value_layer, GTextOverflowModeFill); text_layer_set_font(aqi_value_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); layer_add_child(window_layer, text_layer_get_layer(aqi_value_layer)); int aqi = persist_exists(AQI) ? persist_read_int(AQI) : -1; int temperature = persist_exists(TEMPERATURE) ? persist_read_int(TEMPERATURE) : -1; Tuplet initial_values[] = { TupletInteger(AQI, aqi), TupletInteger(TEMPERATURE, temperature) }; app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL); }
static void init(void) { // Create window window = window_create(); window_stack_push(window, true); // Load images bg_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG); pony_black_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PONY_BLACK); pony_white_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PONY_WHITE); hour_black_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HOUR_BLACK); hour_white_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HOUR_WHITE); minute_black_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MINUTE_BLACK); minute_white_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MINUTE_WHITE); // Create bg layer bg_layer = bitmap_layer_create(GRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); bitmap_layer_set_bitmap(bg_layer, bg_image); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bg_layer)); // Create minute_layer minute_layer = trans_rot_bitmap_layer_create(minute_black_image, minute_white_image); trans_rot_bitmap_layer_set_frame(minute_layer, GRect(-39, -27, 221, 221)); trans_rot_bitmap_layer_add_child(bitmap_layer_get_layer(bg_layer), minute_layer); // Create pony layer pony_layer = trans_bitmap_layer_create(pony_black_image, pony_white_image, GRect(PONY_X, PONY_Y, PONY_WIDTH, SCREEN_WIDTH)); //trans_rot_bitmap_layer_set_frame(pony_layer, GRect(-39, -27, 221, 221)); trans_bitmap_layer_add_child(bitmap_layer_get_layer(bg_layer), pony_layer); // Create hour layer hour_layer = trans_rot_bitmap_layer_create(hour_black_image, hour_white_image); trans_rot_bitmap_layer_set_frame(hour_layer, GRect(-39, -27, 221, 221)); trans_rot_bitmap_layer_add_child(bitmap_layer_get_layer(bg_layer), hour_layer); time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_tick(current_time, MINUTE_UNIT); // Subscribe minute handler tick_timer_service_subscribe(MINUTE_UNIT, &handle_tick); }
static void main_window_load(Window *window) { /* initialize UI */ Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); s_time_font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD); s_face = layer_create(bounds); layer_set_update_proc(s_face, draw_face_layer); time_t ts = time(NULL); struct tm* now = localtime(&ts); update_window_color(); s_hand = layer_create(bounds); layer_set_update_proc(s_hand, draw_hand_layer); layer_add_child(window_layer, s_face); layer_add_child(window_layer, s_hand); /* initial draw of the face */ layer_mark_dirty(s_face); static const AnimationImplementation impl = { .update = draw_animation_frame }; s_my_animation_ptr = animation_create(); animation_set_implementation(s_my_animation_ptr, &impl); animation_set_duration(s_my_animation_ptr, 1000); animation_schedule(s_my_animation_ptr); /* initialize event handlers */ handle_tick(now, MINUTE_UNIT); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); }
static void window_load(Window *window) { static time_t tm; window_layer = window_get_root_layer(window); time_layer = text_layer_create(GRect(0, 0, 144, 55)); text_layer_set_text_color(time_layer, GColorWhite); text_layer_set_background_color(time_layer, GColorBlack); text_layer_set_font(time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FUTURA_CONDENSED_53))); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(time_layer)); date_layer = text_layer_create(GRect(0, 55, 144, 33)); text_layer_set_text_color(date_layer, GColorWhite); text_layer_set_background_color(date_layer, GColorBlack); text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(date_layer)); icon_layer = bitmap_layer_create(GRect(0, 88, 60, 60)); layer_add_child(window_layer, bitmap_layer_get_layer(icon_layer)); temperature_layer = text_layer_create(GRect(61, 88, 83, 60)); text_layer_set_text_color(temperature_layer, GColorBlack); text_layer_set_background_color(temperature_layer, GColorWhite); //text_layer_set_font(temperature_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FUTURA_40))); text_layer_set_font(temperature_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); text_layer_set_text_alignment(temperature_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(temperature_layer)); city_layer = text_layer_create(GRect(0, 142, 144, 28)); text_layer_set_text_color(city_layer, GColorBlack); text_layer_set_background_color(city_layer, GColorWhite); text_layer_set_font(city_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); // text_layer_set_font(city_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FUTURA_18))); text_layer_set_text_alignment(city_layer, GTextAlignmentLeft); layer_add_child(window_layer, text_layer_get_layer(city_layer)); // Status setup icon_battery = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_ICON); icon_battery_charge = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGE); icon_bluetooth = gbitmap_create_with_resource(RESOURCE_ID_BLUETOOTH); BatteryChargeState initial = battery_state_service_peek(); battery_level = initial.charge_percent; battery_plugged = initial.is_plugged; battery_layer = layer_create(GRect(0,70,24,12)); //24*12 layer_set_update_proc(battery_layer, &battery_layer_update_callback); layer_add_child(window_layer, battery_layer); bluetooth_ok = bluetooth_connection_service_peek(); bluetooth_layer = layer_create(GRect(130,70,9,12)); //9*12 layer_set_update_proc(bluetooth_layer, &bluetooth_layer_update_callback); layer_add_child(window_layer, bluetooth_layer); // Initial Weather Display //icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_ICON_CLOUD_ERROR); //bitmap_layer_set_bitmap(icon_layer, icon_bitmap); // Init notification icons icon_refresh = gbitmap_create_with_resource(RESOURCE_ID_REFRESH); icon_warning = gbitmap_create_with_resource(RESOURCE_ID_WARNING); icon_error = gbitmap_create_with_resource(RESOURCE_ID_ERROR); icon_waiting = gbitmap_create_with_resource(RESOURCE_ID_WAITING); icon_empty = gbitmap_create_with_resource(RESOURCE_ID_EMPTY); // Init notification layer notify_layer = bitmap_layer_create(GRect(124, 148, 20, 20)); bitmap_layer_set_background_color(notify_layer, GColorClear); bitmap_layer_set_alignment(notify_layer, GAlignTop); layer_add_child(window_layer, bitmap_layer_get_layer(notify_layer)); // Force Refresh time handle_tick(localtime(&tm), SECOND_UNIT | MINUTE_UNIT | HOUR_UNIT | DAY_UNIT); }
static void handle_init(void) { time_t rawtime; time (&rawtime); struct tm * tick_time; tick_time = localtime(&rawtime); tick_time->tm_year = 2014 - 1900; tick_time->tm_mon = 12 - 1; tick_time->tm_mday = 9; tick_time->tm_hour = 12 - 1; tick_time->tm_min = 0; tick_time->tm_sec = 0; start_time = mktime(tick_time); tick_time = localtime(&rawtime); tick_time->tm_year = 2015 - 1900; tick_time->tm_mon = 12 - 1; tick_time->tm_mday = 9; tick_time->tm_hour = 12 - 1; tick_time->tm_min = 0; tick_time->tm_sec = 0; end_time = mktime(tick_time); strcpy(text_otslujul, "Ты отслужил"); strcpy(text_ostalos, "До дембеля осталось"); strcpy(text_uje, "Ты дембель уже"); // Read stored settings if (persist_exists(MSG_START_TIME)) start_time = persist_read_int(MSG_START_TIME); if (persist_exists(MSG_END_TIME)) end_time = persist_read_int(MSG_END_TIME); if (persist_exists(MSG_TEXT_OTSLUJIL)) persist_read_string(MSG_TEXT_OTSLUJIL, text_otslujul, sizeof(text_otslujul)); if (persist_exists(MSG_TEXT_OSTALOS)) persist_read_string(MSG_TEXT_OSTALOS, text_ostalos, sizeof(text_ostalos)); if (persist_exists(MSG_TEXT_UJE)) persist_read_string(MSG_TEXT_UJE, text_uje, sizeof(text_uje)); // Open communication channel app_message_register_inbox_received(in_received_handler); app_message_open(256, 256); // Create a window and text layer window = window_create(); // Current time layer time_layer = text_layer_create(GRect(0, 0, 144, 50)); // Set the text, font, and text alignment text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); // Add the text layer to the window layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer)); // Left time layer left_time_layer = text_layer_create(GRect(0, 47, 144, 80)); // Set the text, font, and text alignment text_layer_set_font(left_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_background_color(left_time_layer, GColorClear); text_layer_set_text_alignment(left_time_layer, GTextAlignmentCenter); // Add the text layer to the window layer_add_child(window_get_root_layer(window), text_layer_get_layer(left_time_layer)); // Another Left time layer left_time_layer2 = text_layer_create(GRect(0, 67, 144, 80)); // Set the text, font, and text alignment text_layer_set_font(left_time_layer2, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_background_color(left_time_layer2, GColorClear); text_layer_set_text_alignment(left_time_layer2, GTextAlignmentCenter); // Add the text layer to the window layer_add_child(window_get_root_layer(window), text_layer_get_layer(left_time_layer2)); // Percent layer percent_layer = text_layer_create(GRect(0, 130, 144, 80)); // Set the text, font, and text alignment text_layer_set_font(percent_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_background_color(percent_layer, GColorClear); text_layer_set_text_alignment(percent_layer, GTextAlignmentCenter); // Add the text layer to the window layer_add_child(window_get_root_layer(window), text_layer_get_layer(percent_layer)); // Create progress bar progress_layer = layer_create(GRect(2, 150, 140, 15)); layer_set_update_proc(progress_layer, &progress_layer_update_callback); layer_add_child(window_get_root_layer(window), progress_layer); time_t now = time(NULL); handle_tick(localtime(&now), 0); // Push the window window_stack_push(window, true); // Subscribe to time updates tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); //light_enable(true); // For taking photos only! }
static void init(void) { memset(&time_digits_layers, 0, sizeof(time_digits_layers)); memset(&time_digits_images, 0, sizeof(time_digits_images)); memset(&date_digits_layers, 0, sizeof(date_digits_layers)); memset(&date_digits_images, 0, sizeof(date_digits_images)); // Setup messaging const int inbound_size = 128; const int outbound_size = 128; app_message_open(inbound_size, outbound_size); window = window_create(); if (window == NULL) { //APP_LOG(APP_LOG_LEVEL_DEBUG, "OOM: couldn't allocate window"); return; } window_set_background_color(window, GColorBlack); window_stack_push(window, true /* Animated */); window_layer = window_get_root_layer(window); // resources custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SQUARE_26)); img_battery_100 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_090_100); img_battery_90 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_080_090); img_battery_80 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_070_080); img_battery_70 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_060_070); img_battery_60 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_050_060); img_battery_50 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_040_050); img_battery_40 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_030_040); img_battery_30 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_020_030); img_battery_20 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_010_020); img_battery_10 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_000_010); img_battery_charge = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_CHARGING); // layers layer_batt_img = bitmap_layer_create(GRect(132, 5, 9, 98)); bitmap_layer_set_bitmap(layer_batt_img, img_battery_100); layer_add_child(window_layer, bitmap_layer_get_layer(layer_batt_img)); separator_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SEPARATOR); #ifdef PBL_PLATFORM_BASALT GRect bitmap_bounds = gbitmap_get_bounds(separator_image); #else GRect bitmap_bounds = separator_image->bounds; #endif GRect frame = GRect(68, 81, bitmap_bounds.size.w, bitmap_bounds.size.h); separator_layer = bitmap_layer_create(frame); bitmap_layer_set_bitmap(separator_layer, separator_image); layer_add_child(window_layer, bitmap_layer_get_layer(separator_layer)); bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH); #ifdef PBL_PLATFORM_BASALT GRect bitmap_bounds2 = gbitmap_get_bounds(bluetooth_image); #else GRect bitmap_bounds2 = bluetooth_image->bounds; #endif GRect frame2 = GRect(128, 112, bitmap_bounds2.size.w, bitmap_bounds2.size.h); bluetooth_layer = bitmap_layer_create(frame2); bitmap_layer_set_bitmap(bluetooth_layer, bluetooth_image); layer_add_child(window_layer, bitmap_layer_get_layer(bluetooth_layer)); Layer *weather_holder = layer_create(GRect(0, 0, 144, 168 )); layer_add_child(window_layer, weather_holder); icon_layer = bitmap_layer_create(GRect(-3, 100, 60, 75)); layer_add_child(weather_holder, bitmap_layer_get_layer(icon_layer)); // Create time and date layers GRect dummy_frame = { {0, 0}, {0, 0} }; day_name_layer = bitmap_layer_create(dummy_frame); layer_add_child(window_layer, bitmap_layer_get_layer(day_name_layer)); month_layer = bitmap_layer_create(dummy_frame); layer_add_child(window_layer, bitmap_layer_get_layer(month_layer)); for (int i = 0; i < TOTAL_TIME_DIGITS; ++i) { time_digits_layers[i] = bitmap_layer_create(dummy_frame); layer_add_child(window_layer, bitmap_layer_get_layer(time_digits_layers[i])); } for (int i = 0; i < TOTAL_DATE_DIGITS; ++i) { date_digits_layers[i] = bitmap_layer_create(dummy_frame); layer_add_child(window_layer, bitmap_layer_get_layer(date_digits_layers[i])); } for (int i = 0; i < TOTAL_SECONDS_DIGITS; ++i) { seconds_digits_layers[i] = bitmap_layer_create(dummy_frame); layer_add_child(window_layer, bitmap_layer_get_layer(seconds_digits_layers[i])); } temp_layer = text_layer_create(GRect(120, 135, 40, 40)); text_layer_set_text_color(temp_layer, GColorWhite); #ifdef PBL_COLOR text_layer_set_text_color(temp_layer, GColorVividCerulean ); #endif text_layer_set_background_color(temp_layer, GColorClear); // text_layer_set_font(temp_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_font(temp_layer, custom_font); text_layer_set_text_alignment(temp_layer, GTextAlignmentLeft); layer_add_child(weather_holder, text_layer_get_layer(temp_layer)); // creating effect layer to rotate temp effect_layer_2 = effect_layer_create(GRect(115,135,33,33)); effect_layer_add_effect(effect_layer_2, effect_rotate_90_degrees, (void *)false); layer_add_child(window_get_root_layer(window), effect_layer_get_layer(effect_layer_2)); Tuplet initial_values[] = { TupletInteger(WEATHER_ICON_KEY, (uint8_t) 14), TupletInteger(INVERT_COLOR_KEY, persist_read_bool(INVERT_COLOR_KEY)), TupletInteger(BLUETOOTHVIBE_KEY, persist_read_bool(BLUETOOTHVIBE_KEY)), TupletInteger(STYLE_KEY, persist_read_bool(STYLE_KEY)), TupletInteger(HOURLYVIBE_KEY, persist_read_bool(HOURLYVIBE_KEY)), TupletInteger(HIDE_BATT_KEY, persist_read_bool(HIDE_BATT_KEY)), TupletInteger(HIDE_DATE_KEY, persist_read_bool(HIDE_DATE_KEY)), TupletInteger(HIDE_WEATHER_KEY, persist_read_bool(HIDE_WEATHER_KEY)), TupletCString(WEATHER_TEMPERATURE_KEY, ""), }; app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, NULL, NULL); appStarted = true; // Avoids a blank screen on watch start. time_t now = time(NULL); struct tm *tick_time = localtime(&now); handle_tick(tick_time, MONTH_UNIT + DAY_UNIT + HOUR_UNIT + MINUTE_UNIT + SECOND_UNIT); tick_timer_service_subscribe(SECOND_UNIT, handle_tick); // handlers battery_state_service_subscribe(&handle_battery); bluetooth_connection_service_subscribe(&handle_bluetooth); // draw first frame force_update(); }
//----------------------------------------------------------------------------------------------------------------------- static void update_configuration(void) { if (persist_exists(CONFIG_KEY_THEME)) { int32_t theme = persist_read_int(CONFIG_KEY_THEME); CfgData.circle = (theme == 0); } else CfgData.circle = false; if (persist_exists(CONFIG_KEY_FSM)) CfgData.fsm = persist_read_bool(CONFIG_KEY_FSM); else CfgData.fsm = false; if (persist_exists(CONFIG_KEY_INV)) CfgData.inv = !CfgData.circle && persist_read_bool(CONFIG_KEY_INV); else CfgData.inv = true; if (persist_exists(CONFIG_KEY_ANIM)) CfgData.anim = persist_read_bool(CONFIG_KEY_ANIM); else CfgData.anim = true; if (persist_exists(CONFIG_KEY_SEP)) CfgData.sep = persist_read_bool(CONFIG_KEY_SEP); else CfgData.sep = true; if (persist_exists(CONFIG_KEY_DATEFMT)) CfgData.datefmt = (int16_t)persist_read_int(CONFIG_KEY_DATEFMT); else CfgData.datefmt = 0; if (persist_exists(CONFIG_KEY_SMART)) CfgData.smart = persist_read_bool(CONFIG_KEY_SMART); else CfgData.smart = true; if (persist_exists(CONFIG_KEY_VIBR)) CfgData.vibr = persist_read_bool(CONFIG_KEY_VIBR); else CfgData.vibr = false; app_log(APP_LOG_LEVEL_DEBUG, __FILE__, __LINE__, "Curr Conf: circle:%d, fsm:%d, inv:%d, anim:%d, sep:%d, datefmt:%d, smart:%d, vibr:%d", CfgData.circle, CfgData.fsm, CfgData.inv, CfgData.anim, CfgData.sep, CfgData.datefmt, CfgData.smart, CfgData.vibr); gbitmap_destroy(batteryAll); batteryAll = gbitmap_create_with_resource(CfgData.inv ? RESOURCE_ID_IMAGE_BATTERY_INV : RESOURCE_ID_IMAGE_BATTERY); bitmap_layer_set_bitmap(radio_layer, NULL); gbitmap_destroy(bmp_radio); bmp_radio = gbitmap_create_as_sub_bitmap(batteryAll, GRect(110, 0, 10, 20)); bitmap_layer_set_bitmap(radio_layer, bmp_radio); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_get_root_layer(window)); window_set_background_color(window, CfgData.inv ? GColorWhite : GColorBlack); //Face Layer first on round layer_remove_from_parent(face_layer); layer_destroy(face_layer); #if defined(PBL_RECT) face_layer = layer_create(GRect(0, 0, bounds.size.w, CfgData.fsm ? bounds.size.h : bounds.size.h-n_bottom_margin)); layer_set_update_proc(face_layer, face_update_proc); #elif defined(PBL_ROUND) face_layer = layer_create(GRect(0, 0, bounds.size.w, bounds.size.h)); layer_set_update_proc(face_layer, face_update_proc); layer_add_child(window_layer, face_layer); #endif //Bottom Layer next, then Radio and Battery layer_remove_from_parent(text_layer_get_layer(date_layer)); layer_remove_from_parent(bitmap_layer_get_layer(radio_layer)); layer_remove_from_parent(bitmap_layer_get_layer(battery_layer)); #if defined(PBL_RECT) if (!CfgData.fsm) #endif { #if defined(PBL_RECT) layer_add_child(window_layer, text_layer_get_layer(date_layer)); #ifdef PBL_COLOR text_layer_set_text_color(date_layer, CfgData.inv ? GColorDarkGray : GColorLightGray); #else text_layer_set_text_color(date_layer, CfgData.inv ? GColorBlack : GColorWhite); #endif text_layer_set_background_color(date_layer, CfgData.inv ? GColorWhite : GColorBlack); #endif if (CfgData.smart) { layer_add_child(window_layer, bitmap_layer_get_layer(radio_layer)); layer_add_child(window_layer, bitmap_layer_get_layer(battery_layer)); } } //On Rect later #if defined(PBL_RECT) layer_add_child(window_layer, face_layer); #endif //Get a time structure so that it doesn't start blank time_t temp = time(NULL); struct tm *t = localtime(&temp); //Manually call the tick handler when the window is loading aktHH = t->tm_hour; aktMM = t->tm_min; handle_tick(t, MINUTE_UNIT); //Set Battery state BatteryChargeState btchg = battery_state_service_peek(); battery_state_service_handler(btchg); //Set Bluetooth state bool connected = bluetooth_connection_service_peek(); bluetooth_connection_handler(connected); }
static void handle_init() { time_t clock = time(NULL); now = localtime(&clock); window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); Layer *window_layer = window_get_root_layer(window); background_layer = layer_create(GRect(0, 0, 144, 144)); layer_set_update_proc(background_layer, background_layer_update_callback); layer_add_child(window_layer, background_layer); hands_layer = layer_create(layer_get_frame(background_layer)); layer_set_update_proc(hands_layer, hands_layer_update_callback); layer_add_child(background_layer, hands_layer); for (int i = 0; i < 22; i++) { battery_images[i] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_0 + i); } battery_layer = bitmap_layer_create(GRect(144-16-3, 3, 16, 10)); layer_add_child(window_layer, bitmap_layer_get_layer(battery_layer)); for (int i = 0; i < 2; i++) bluetooth_images[i] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH_OFF + i); bluetooth_layer = bitmap_layer_create(GRect(66, 0, 13, 13)); layer_add_child(background_layer, bitmap_layer_get_layer(bluetooth_layer)); battp_layer = text_layer_create(GRect(0, 0, 32, 16)); text_layer_set_text_color(battp_layer, GColorWhite); text_layer_set_background_color(battp_layer, GColorBlack); layer_add_child(window_layer, text_layer_get_layer(battp_layer)); hour_path = gpath_create(&HOUR_POINTS); hour_in_path = gpath_create(&HOUR_IN_POINTS); gpath_move_to(hour_path, GPoint(CENTER_X, CENTER_Y)); gpath_move_to(hour_in_path, GPoint(CENTER_X, CENTER_Y)); min_path = gpath_create(&MIN_POINTS); gpath_move_to(min_path, GPoint(CENTER_X, CENTER_Y)); font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_20)); font2 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_28)); time_layer = text_layer_create(GRect(25,146,94,24)); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); text_layer_set_text_color(time_layer, GColorWhite); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_font(time_layer, font); layer_add_child(window_layer, text_layer_get_layer(time_layer)); date_layer = text_layer_create(GRect(94, 136, 50, 50)); text_layer_set_text_alignment(date_layer, GTextAlignmentRight); text_layer_set_text_color(date_layer, GColorWhite); text_layer_set_background_color(date_layer, GColorClear); text_layer_set_font(date_layer, font2); layer_add_child(window_layer, text_layer_get_layer(date_layer)); day_layer = text_layer_create(GRect(0, 146, 50, 24)); text_layer_set_text_alignment(day_layer, GTextAlignmentLeft); text_layer_set_text_color(day_layer, GColorWhite); text_layer_set_background_color(day_layer, GColorClear); text_layer_set_font(day_layer, font); layer_add_child(window_layer, text_layer_get_layer(day_layer)); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); battery_state_service_subscribe(&handle_battery); handle_battery(battery_state_service_peek()); bluetooth_connection_service_subscribe(&handle_bluetooth); handle_bluetooth(bluetooth_connection_service_peek()); handle_tick(now,1); }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, APP_NAME); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); resource_init_current_app(&APP_RESOURCES); // Initialise 12/24h flag. At time of writing, it's not possible to // switch between 12/24h while the face is running, so it's okay to // set this at initialisation. However, time_format depends on this. is_24h = clock_is_24h_style(); // If there's a digital readout, then we initialise the string format // here. As mentioned above, this might need to be moved into // something in the main loop if it becomes possible to change format // mid-run. if (digital_time) { if (is_24h) { if (seconds) { time_format = "%R:%S"; } else { time_format = "%R"; } } else { if (seconds) { time_format = "%I:%M:%S"; } else { time_format = "%I:%M"; } } } // Load bitmap for watch face background bmp_init_container(RESOURCE_ID_IMAGE_WATCHFACE, &watchface_container); // Not unexpectedly, most coordinates for the face, hands, etc. are // relative to the watchface size and position. watchface_frame = layer_get_frame(&watchface_container.layer.layer); if(big) { // BBCWatch, ie. just analogue: stretches the full width of the // watch, and is vertically centered. watchface_frame.origin.x = 0; watchface_frame.origin.y = 12; } else { // BeebWatch, ie. a mix of analogue and digital. The watch face is // narrower, and so needs to be horizontally centered. Vertical // positioning is determined by whether or not there's a digital // readout of the time. watchface_frame.origin.x = 16; if(digital_time) watchface_frame.origin.y = 0; else watchface_frame.origin.y = 14; } layer_set_frame(&watchface_container.layer.layer, watchface_frame); // The center of the watchface (relative to the origin of the frame) // is used in laying out the hands. watchface_center = GPoint(watchface_frame.size.w/2, watchface_frame.size.h/2); // Add the background layer to the window. layer_add_child(&window.layer, &watchface_container.layer.layer); if(!big) { // Date. This is intentionally formatted the same way Teletext // formatted it: Day Date Mon, with Date padded with spaces. text_layer_init(&date_layer, GRect(13, 146, 144-13, 20)); text_layer_set_text_color(&date_layer, GColorWhite); text_layer_set_background_color(&date_layer, GColorClear); text_layer_set_text_alignment(&date_layer, GTextAlignmentLeft); small_font = fonts_load_custom_font(resource_get_handle(FONT_SMALL)); text_layer_set_font(&date_layer, small_font); layer_add_child(&window.layer, &date_layer.layer); // If there's a digital time readout, then set up a layer to print // the time: if(digital_time) { // If there's no seconds, then the bounding box is // shifted. However, this does mess up the nice neat // Teletext-style monospaced layout. Oh well. if(seconds) text_layer_init(&time_layer, GRect(25, 112, 144-25, 33)); else text_layer_init(&time_layer, GRect(43, 112, 144-43, 33)); text_layer_set_text_color(&time_layer, GColorWhite); text_layer_set_background_color(&time_layer, GColorClear); text_layer_set_text_alignment(&time_layer, GTextAlignmentLeft); large_font = fonts_load_custom_font(resource_get_handle(FONT_LARGE)); text_layer_set_font(&time_layer, large_font); layer_add_child(&window.layer, &time_layer.layer); } } // Hands: To make updates easier (as hours and minutes are always // updated at the same time due to slew on the hour hand through the // hour), the hour- and minute-hand are separate image sublayers of a // generic layer for both hands. This means they share the same update // routine. layer_init(&hmhands_layer, watchface_frame); hmhands_layer.update_proc = &hmhands_update_proc; // It would be better to do both hour- and minute-hand with polygons, // but polygon-drawing in PebbleOS 1.10 is broken: it can't do narrow // polygons worth a damn. Contrary to initial assumptions, it's not // down to rotation error. To test this, I generated all positions of // the minute hand with known-good coordinates without resorting to // Pebble trig or rotation, and it couldn't draw them well. // // So, instead, we use Pebble's crazy-ass rotbmp system instead. rotbmp_init_container(RESOURCE_ID_IMAGE_HOURHAND, &hourhand_container); layer_add_child(&hmhands_layer, &hourhand_container.layer.layer); // The bounding boxes of RotBmpLayers are a mystery to me, so I'm just // going to copy what everyone else seems to do: if(big) rot_bitmap_set_src_ic(&hourhand_container.layer, GPoint(3, 49)); else rot_bitmap_set_src_ic(&hourhand_container.layer, GPoint(2, 37)); hourhand_container.layer.layer.frame.origin.x = watchface_center.x - hourhand_container.layer.layer.frame.size.w/2; hourhand_container.layer.layer.frame.origin.y = watchface_center.y - hourhand_container.layer.layer.frame.size.h/2; // Same as with minute hands... rotbmp_init_container(RESOURCE_ID_IMAGE_MINUTEHAND, &minutehand_container); layer_add_child(&hmhands_layer, &minutehand_container.layer.layer); if(big) rot_bitmap_set_src_ic(&minutehand_container.layer, GPoint(2, 72)); else rot_bitmap_set_src_ic(&minutehand_container.layer, GPoint(1, 56)); minutehand_container.layer.layer.frame.origin.x = watchface_center.x - minutehand_container.layer.layer.frame.size.w/2; minutehand_container.layer.layer.frame.origin.y = watchface_center.y - minutehand_container.layer.layer.frame.size.h/2; // Add the combined hands layer to the window layer_add_child(&window.layer, &hmhands_layer); // Second-hand, if there is one: if(seconds) { layer_init(&sechand_layer, watchface_frame); sechand_layer.update_proc = &sechand_update_proc; layer_add_child(&window.layer, &sechand_layer); } // Load bitmap for center dot background bmp_init_container(RESOURCE_ID_IMAGE_CENTERDOT, ¢erdot_container); // Center-align it on the watchface center GRect centerdot_frame = layer_get_frame(¢erdot_container.layer.layer); centerdot_frame.origin.x = watchface_frame.origin.x + watchface_center.x - centerdot_frame.size.w / 2; centerdot_frame.origin.y = watchface_frame.origin.y + watchface_center.y - centerdot_frame.size.h / 2; layer_set_frame(¢erdot_container.layer.layer, centerdot_frame); // Add it to the window. layer_add_child(&window.layer, ¢erdot_container.layer.layer); // Finally, do the rest of the initialisation by calling the tick // event handler directly (for this first run): handle_tick(NULL, NULL); }
void handle_init(void) { APP_LOG(APP_LOG_LEVEL_ERROR, "In Init * * * * * "); GColor BGCOLOR = COLOR_FALLBACK(GColorDukeBlue, GColorBlack); BGColorHold = BGCOLOR; GColor TEXTCOLOR = COLOR_FALLBACK(GColorWhite, GColorWhite); TextColorHold = TEXTCOLOR; window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, BGCOLOR); fontHelvNewLight20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELV_NEW_LIGHT_20)); fontRobotoBoldSubset40 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_40)); fontRobotoBoldSubset45 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_45)); Layer *window_layer = window_get_root_layer(window); // Register callbacks app_message_register_inbox_received(inbox_received_callback); app_message_register_inbox_dropped(inbox_dropped_callback); app_message_register_outbox_failed(outbox_failed_callback); app_message_register_outbox_sent(outbox_sent_callback); // Open AppMessage app_message_open(64, 64); // Date #ifdef PBL_PLATFORM_CHALK text_date_layer = text_layer_create(GRect(1, 94, 180, 28)); #else text_date_layer = text_layer_create(GRect(1, 94, 144, 28)); #endif text_layer_set_text_color(text_date_layer, TEXTCOLOR); text_layer_set_background_color(text_date_layer, BGCOLOR); text_layer_set_text_alignment(text_date_layer, GTextAlignmentCenter);; text_layer_set_font(text_date_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21)); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); //Persistent Value Date Format: if (persist_exists(MESSAGE_KEY_DATE_FORMAT_KEY)) { persist_read_string(MESSAGE_KEY_DATE_FORMAT_KEY , PersistDateFormat, sizeof(PersistDateFormat)); APP_LOG(APP_LOG_LEVEL_INFO, " Set Date Format to %s - Persistent - 0 = US, 1 = Int'l", PersistDateFormat); } else { APP_LOG(APP_LOG_LEVEL_INFO, " Set Date Format to 0 - Default - US"); strcpy(PersistDateFormat, "0"); //Default } if (strcmp(PersistDateFormat, "0") == 0) { // US strcpy(date_format, "%b %e %Y"); } else { strcpy(date_format, "%e %b %Y"); } //Persistent Value Vib On BTLoss if(persist_exists(MESSAGE_KEY_BT_VIBRATE_KEY)) { PersistBTLoss = persist_read_int(MESSAGE_KEY_BT_VIBRATE_KEY); APP_LOG(APP_LOG_LEVEL_INFO, " Set BT Vibrate To %d - Persistent - 0 = NO Vib, 1 = Vib", PersistBTLoss); } else { PersistBTLoss = 0; // Default APP_LOG(APP_LOG_LEVEL_INFO, " Set BT Vibrate To 0 - Default - No Vibrate"); } //Persistent Value Vib on Low Batt if(persist_exists(MESSAGE_KEY_LOW_BATTERY_KEY)) { PersistLow_Batt = persist_read_int(MESSAGE_KEY_LOW_BATTERY_KEY); APP_LOG(APP_LOG_LEVEL_INFO, " Set Low Batt Vibrate To %d - Persistent - 0 = NO Vib, 1 = Vib", PersistLow_Batt); } else { PersistLow_Batt = 0; // Default APP_LOG(APP_LOG_LEVEL_INFO, " Set Low Batt Vibrate To 0 - Default - No Vibrate"); } // Time of Day #ifdef PBL_PLATFORM_CHALK text_time_layer = text_layer_create(GRect(1, 120, 180, 45)); text_layer_set_font(text_time_layer,fontRobotoBoldSubset40); #else text_time_layer = text_layer_create(GRect(1, 120, 144, 45)); text_layer_set_font(text_time_layer,fontRobotoBoldSubset45); #endif text_layer_set_text_color(text_time_layer, TEXTCOLOR); text_layer_set_background_color(text_time_layer, BGCOLOR); text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(text_time_layer)); // Dayname #ifdef PBL_PLATFORM_CHALK text_dayname_layer = text_layer_create(GRect(1, 74, 180, 26)); #else text_dayname_layer = text_layer_create(GRect(1, 74, 144, 26)); #endif text_layer_set_text_color(text_dayname_layer, TEXTCOLOR); text_layer_set_text_alignment(text_dayname_layer, GTextAlignmentCenter); text_layer_set_background_color(text_dayname_layer, BGCOLOR); text_layer_set_font(text_dayname_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21)); layer_add_child(window_layer, text_layer_get_layer(text_dayname_layer)); // Planetary Logo image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PLANETARY_LOGO); #ifdef PBL_PLATFORM_CHALK image_layer = bitmap_layer_create(GRect(1, 29, 180, 49)); #else image_layer = bitmap_layer_create(GRect(1, 29, 144, 49)); #endif bitmap_layer_set_bitmap(image_layer, image); bitmap_layer_set_alignment(image_layer, GAlignCenter); layer_add_child(window_layer, bitmap_layer_get_layer(image_layer)); // Line #ifdef PBL_PLATFORM_CHALK GRect line_frame = GRect(38, 122, 104, 6); #else GRect line_frame = GRect(22, 122, 104, 6); #endif BatteryLineLayer = layer_create(line_frame); layer_set_update_proc(BatteryLineLayer, battery_line_layer_update_callback); layer_add_child(window_layer, BatteryLineLayer); tick_timer_service_subscribe(SECOND_UNIT, handle_tick); //Bluetooth Logo Setup area #ifdef PBL_PLATFORM_CHALK GRect BTArea = GRect(55, 5, 20, 20); #else GRect BTArea = GRect(1, 5, 20, 20); #endif BTLayer = layer_create(BTArea); layer_add_child(window_layer, BTLayer); layer_set_update_proc(BTLayer, BTLine_update_callback); bluetooth_connection_service_subscribe(&handle_bluetooth); //Battery Text #ifdef PBL_PLATFORM_CHALK text_battery_layer = text_layer_create(GRect(80,2,55,28)); #else text_battery_layer = text_layer_create(GRect(85,2,55,28)); #endif text_layer_set_text_color(text_battery_layer, TEXTCOLOR); text_layer_set_background_color(text_battery_layer, BGCOLOR); text_layer_set_font(text_battery_layer, fontHelvNewLight20 ); text_layer_set_text_alignment(text_battery_layer, GTextAlignmentRight); layer_add_child(window_layer, text_layer_get_layer(text_battery_layer)); battery_state_service_subscribe(&handle_battery); bluetooth_connection_service_subscribe(&handle_bluetooth); app_focus_service_subscribe(&handle_appfocus); handle_battery(battery_state_service_peek()); handle_bluetooth(bluetooth_connection_service_peek()); // Ensures time is displayed immediately (will break if NULL tick event accessed). // (This is why it's a good idea to have a separate routine to do the update itself.) time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_tick(current_time, SECOND_UNIT); }
void Player::process_tick() { handle_tick(); mixer->set_callback_interval( 2500000/control.tempo ); }
//********************************** Handle Init ************************** void handle_init(void) { if (quiet_time_is_active()) { QuietTimeColor = GColorYellow; } else { QuietTimeColor = GColorRed; } GColor BGCOLOR = COLOR_FALLBACK(GColorDukeBlue, GColorBlack); BGColorHold = BGCOLOR; GColor TEXTCOLOR = COLOR_FALLBACK(GColorWhite, GColorWhite); TextColorHold = TEXTCOLOR; window = window_create(); window_set_background_color(window, BGCOLOR); window_stack_push(window, true /* Animated */); fontHelvNewLight20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELV_NEW_LIGHT_20)); fontRobotoCondensed20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_20)); fontRobotoCondensed21 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21)); fontRobotoBoldSubset37 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_37)); fontRobotoBoldSubset49 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49)); Layer *window_layer = window_get_root_layer(window); // Register callbacks app_message_register_inbox_received(inbox_received_callback); app_message_register_inbox_dropped(inbox_dropped_callback); app_message_register_outbox_failed(outbox_failed_callback); app_message_register_outbox_sent(outbox_sent_callback); // Open AppMessage app_message_open(128, 128); //degrees text_degrees_layer = text_layer_create(GRect(30, 1, 60, 200)); text_layer_set_text_alignment(text_degrees_layer, GTextAlignmentCenter); text_layer_set_text(text_degrees_layer, degreesstr); text_layer_set_font(text_degrees_layer, fontRobotoCondensed20); text_layer_set_background_color(text_degrees_layer, BGCOLOR); text_layer_set_text_color(text_degrees_layer, TEXTCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_degrees_layer)); //degrees inside text_degrees_inside_layer = text_layer_create(GRect(85, 2, 55, 26)); text_layer_set_text_alignment(text_degrees_inside_layer, GTextAlignmentRight); text_layer_set_text(text_degrees_inside_layer, degreesstr); text_layer_set_font(text_degrees_inside_layer, fontRobotoCondensed20); text_layer_set_background_color(text_degrees_inside_layer, BGCOLOR); text_layer_set_text_color(text_degrees_inside_layer, TEXTCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_degrees_inside_layer)); // WA1OUI text_wa1oui_layer = text_layer_create(GRect(1,25, 144, 148)); text_layer_set_text_alignment(text_wa1oui_layer, GTextAlignmentCenter); text_layer_set_text(text_wa1oui_layer, "WA1OUI"); text_layer_set_font(text_wa1oui_layer, fontRobotoBoldSubset37); text_layer_set_text_color(text_wa1oui_layer, TEXTCOLOR); text_layer_set_background_color(text_wa1oui_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_wa1oui_layer)); // Dayname text_dayname_layer = text_layer_create(GRect(1, 65, 35, 168-65)); text_layer_set_text_alignment(text_dayname_layer, GTextAlignmentLeft); text_layer_set_font(text_dayname_layer, fontRobotoCondensed20); text_layer_set_text_color(text_dayname_layer, TEXTCOLOR); text_layer_set_background_color(text_dayname_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_dayname_layer)); // wind text_wind_layer = text_layer_create(GRect(37, 65, 60, 168-65)); text_layer_set_text_alignment(text_wind_layer, GTextAlignmentCenter); text_layer_set_font(text_wind_layer, fontRobotoCondensed20); text_layer_set_text_color(text_wind_layer, TEXTCOLOR); text_layer_set_background_color(text_wind_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_wind_layer)); // Rain text_rain_layer = text_layer_create(GRect(95, 65, 49, 168-65)); text_layer_set_text_alignment(text_rain_layer, GTextAlignmentRight); text_layer_set_font(text_rain_layer, fontRobotoCondensed21); text_layer_set_text_color(text_rain_layer, TEXTCOLOR); text_layer_set_background_color(text_rain_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_rain_layer)); // Date text_date_layer = text_layer_create(GRect(8, 88, 144-8, 168-88)); text_layer_set_text_alignment(text_date_layer, GTextAlignmentCenter); text_layer_set_font(text_date_layer, fontRobotoCondensed21); text_layer_set_text_color(text_date_layer, TEXTCOLOR); text_layer_set_background_color(text_date_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); // Time of Day text_time_layer = text_layer_create(GRect(7, 116, 144-7, 168-116)); text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter); text_layer_set_font(text_time_layer, fontRobotoBoldSubset49); text_layer_set_text_color(text_time_layer, TEXTCOLOR); text_layer_set_background_color(text_time_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_time_layer)); // Red Line GRect red_line_frame = GRect(10, 28, 124, 2); RedLineLayer = layer_create(red_line_frame); layer_set_update_proc(RedLineLayer, red_line_layer_update_callback); layer_add_child(window_layer, RedLineLayer); // Battery Line GRect line_frame = GRect(22, 118, 104, 6); LineLayer = layer_create(line_frame); layer_set_update_proc(LineLayer, line_layer_update_callback); layer_add_child(window_layer, LineLayer); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); //Bluetooth Logo Setup area GRect BTArea = GRect(1, 5, 20, 20); BTLayer1 = layer_create(BTArea); layer_add_child(window_layer, BTLayer1); layer_set_update_proc(BTLayer1, BTLine_update_callback); bluetooth_connection_service_subscribe(&handle_bluetooth); handle_bluetooth(bluetooth_connection_service_peek()); handle_battery(battery_state_service_peek()); //app focus service subscribe app_focus_service_subscribe(&handle_appfocus); // Ensures time is displayed immediately (will break if NULL tick event accessed). // (This is why it's a good idea to have a separate routine to do the update itself.) time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_tick(current_time, SECOND_UNIT); }
void handle_timer(AppContextRef ctx, AppTimerHandle handle, uint32_t cookie) { splashEnded = true; handle_tick(ctx, NULL); }
void handle_init(void) { //fonts GFont bold18 = fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD); GFont norm18 = fonts_get_system_font(FONT_KEY_GOTHIC_14); GFont g28 = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD); GFont g24 = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD); //init buffers s_data.day_buffer[0] = '\0'; s_data.num_buffer[0] = '\0'; //s_data.sec_buffer[0] = '\0'; s_data.min_buffer[0] = '\0'; s_data.hour_buffer[0] = '\0'; Tuplet tuples[] = { TupletInteger(setting_secondHand, secHandsDisp), TupletInteger(setting_BT, BTDisp), TupletInteger(setting_vibrate, vibrate), TupletInteger(setting_bat, batDisp) }; app_sync_init(&app, buffer, sizeof(buffer), tuples, ARRAY_LENGTH(tuples), tuple_changed_callback, app_error_callback, NULL); //APP_LOG(APP_LOG_LEVEL_DEBUG, "app sync init"); // Create a window and text layer s_data.window = window_create(); window_set_fullscreen(s_data.window, true); s_data.bg_layer = layer_create(layer_get_frame(window_get_root_layer(s_data.window))); s_data.date_layer = layer_create(layer_get_frame(s_data.bg_layer)); s_data.hands_layer = layer_create(layer_get_frame(s_data.bg_layer)); //APP_LOG(APP_LOG_LEVEL_DEBUG, "created window and layers"); // init clock face paths for (int i = 0; i < NUM_CLOCK_TICKS; ++i) { s_data.tick_paths[i] = gpath_create(&ANALOG_BG_POINTS[i]); } //APP_LOG(APP_LOG_LEVEL_DEBUG, "init clock face paths"); // init BT icon paths for (int i = 0; i < NUM_BT_LINES; ++i) { s_data.bt_paths[i] = gpath_create(&BLUETOOTH_POINTS[i]); } //APP_LOG(APP_LOG_LEVEL_DEBUG, "init bt icon paths"); // init BT icon paths for (int i = 0; i < NUM_BAT_LINES; ++i) { s_data.bat_paths[i] = gpath_create(&BATTERY_POINTS[i]); } //APP_LOG(APP_LOG_LEVEL_DEBUG, "init bt icon paths"); // init day s_data.day_label = text_layer_create(GRect(2, 151, 40, 20)); text_layer_set_text(s_data.day_label, s_data.day_buffer); text_layer_set_background_color(s_data.day_label, GColorClear); text_layer_set_text_color(s_data.day_label, GColorWhite); text_layer_set_font(s_data.day_label, norm18); layer_add_child(s_data.date_layer, text_layer_get_layer(s_data.day_label)); //APP_LOG(APP_LOG_LEVEL_DEBUG, "created day_label textLayer"); // init num s_data.num_label = text_layer_create(GRect(144 - 16, 151, 18, 20)); text_layer_set_text(s_data.num_label, s_data.num_buffer); text_layer_set_background_color(s_data.num_label, GColorClear); text_layer_set_text_color(s_data.num_label, GColorWhite); text_layer_set_font(s_data.num_label, norm18); layer_add_child(s_data.date_layer, text_layer_get_layer(s_data.num_label)); //APP_LOG(APP_LOG_LEVEL_DEBUG, "created num_label textLayer"); //init sec -> child layer of hands_layer s_data.sec_layer = text_layer_create(GRect(1, 1, secTextBoxSize, secTextBoxSize)); text_layer_set_text(s_data.sec_layer, s_data.sec_buffer); text_layer_set_text_alignment(s_data.sec_layer, GTextAlignmentCenter); text_layer_set_background_color(s_data.sec_layer, GColorClear); text_layer_set_text_color(s_data.sec_layer, GColorWhite); text_layer_set_font(s_data.sec_layer, norm18); layer_add_child(s_data.hands_layer, text_layer_get_layer(s_data.sec_layer)); //APP_LOG(APP_LOG_LEVEL_DEBUG, "created sec_label textLayer"); //init min -> child layer of hands_layer s_data.min_layer = text_layer_create(GRect(1, 1, minTextBoxSize, minTextBoxSize)); text_layer_set_text(s_data.min_layer, s_data.min_buffer); text_layer_set_text_alignment(s_data.min_layer, GTextAlignmentCenter); text_layer_set_background_color(s_data.min_layer, GColorClear); text_layer_set_text_color(s_data.min_layer, GColorWhite); text_layer_set_font(s_data.min_layer, g28); layer_add_child(s_data.hands_layer, text_layer_get_layer(s_data.min_layer)); //APP_LOG(APP_LOG_LEVEL_DEBUG, "created min_label textLayer"); //init hour -> child layer of hands_layer s_data.hour_layer = text_layer_create(GRect(1, 1, hourTextBoxSize, hourTextBoxSize)); text_layer_set_text(s_data.hour_layer, s_data.hour_buffer); text_layer_set_text_alignment(s_data.hour_layer, GTextAlignmentCenter); text_layer_set_background_color(s_data.hour_layer, GColorClear); text_layer_set_text_color(s_data.hour_layer, GColorWhite); text_layer_set_font(s_data.hour_layer, g24); layer_add_child(s_data.hands_layer, text_layer_get_layer(s_data.hour_layer)); //APP_LOG(APP_LOG_LEVEL_DEBUG, "created hour_label textLayer"); //update proc layer_set_update_proc(s_data.bg_layer, bg_update_proc); layer_set_update_proc(s_data.date_layer, date_update_proc); layer_set_update_proc(s_data.hands_layer, hands_update_proc); //APP_LOG(APP_LOG_LEVEL_DEBUG, "set update_procs"); //add layers to window layer_add_child(s_data.bg_layer, s_data.date_layer); layer_add_child(s_data.bg_layer, s_data.hands_layer); layer_add_child(window_get_root_layer(s_data.window), s_data.bg_layer); //APP_LOG(APP_LOG_LEVEL_DEBUG, "finished Layer setup"); // Push the window window_stack_push(s_data.window, true); //APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!"); APP_LOG(APP_LOG_LEVEL_DEBUG, "secHandsDisp %d", secHandsDisp); APP_LOG(APP_LOG_LEVEL_DEBUG, "BTDisp %d", BTDisp); APP_LOG(APP_LOG_LEVEL_DEBUG, "vibrate %d", vibrate); APP_LOG(APP_LOG_LEVEL_DEBUG, "batDisp %d", batDisp); if(secHandsDisp) { APP_LOG(APP_LOG_LEVEL_DEBUG, "handle second tick"); handle_tick(NULL, SECOND_UNIT); tick_timer_service_subscribe(SECOND_UNIT, handle_tick); } else { APP_LOG(APP_LOG_LEVEL_DEBUG, "handle minute tick"); handle_tick(NULL, MINUTE_UNIT); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); } bluetooth_connection_service_subscribe(handle_bluetooth); }