void conserve_power(bool conserve) { if (conserve == g_conserve) return; g_conserve = conserve; if (conserve) { tick_timer_service_unsubscribe(); tick_timer_service_subscribe(MINUTE_UNIT, &handle_tick); layer_set_hidden(second_display_layer, true); } else { tick_timer_service_unsubscribe(); tick_timer_service_subscribe(SECOND_UNIT, &handle_tick); layer_set_hidden(second_display_layer, false); } }
static void pause() { tick_timer_service_unsubscribe(); state.running = 0; text_layer_set_text(ui.top_text, "PAUSED"); }
/* dealloc */ void handle_deinit( void ) { // Unsubscribe from services tick_timer_service_unsubscribe(); battery_state_service_unsubscribe(); bluetooth_connection_service_unsubscribe(); // Destroy image objects destroy_graphics( background_image, background_layer ); destroy_graphics( battery_image, battery_layer ); destroy_graphics( bluetooth_image, bluetooth_layer ); destroy_graphics( icon_bitmap, icon_layer ); // Destroy text objects text_layer_destroy( text_time_layer ); text_layer_destroy( text_ampm_layer ); text_layer_destroy( text_secs_layer ); text_layer_destroy( text_days_layer ); text_layer_destroy( text_date_layer ); text_layer_destroy( text_week_layer ); text_layer_destroy( temp_layer ); // Destroy inverter layer inverter_layer_destroy( currentDayLayer ); // Destroy font objects fonts_unload_custom_font( font_time ); fonts_unload_custom_font( font_days ); fonts_unload_custom_font( font_date ); // Clean up AppSync system app_sync_deinit( &app ); // Destroy window window_destroy( window ); }
void shake_handler(AccelAxisType axis, int32_t direction){ switch(main_settings.shakeAction){ case SHAKE_USE_CHANGE_SWEAR_WORD: app_timer_cancel(animate_word_timer); app_timer_cancel(update_word_timer); animate_word_timer = app_timer_register(50, fire_animation_callback, NULL); update_word_timer = app_timer_register(850, update_word_callback, NULL); break; case SHAKE_USE_LAUNCH_EXTRA_SCREEN: if(!extra_window_is_loaded()){ extra_window_update_settings(main_settings); window_stack_push(extra_window_get_window(), true); } else{ window_stack_pop(true); } break; case SHAKE_USE_SIMPLICITY: if(simplicity_is_loaded()){ simplicity_pop(); tick_timer_service_subscribe(SECOND_UNIT, tick_handler); } else{ tick_timer_service_unsubscribe(); simplicity_push(); } break; } }
void handle_deinit(void) { tick_timer_service_unsubscribe(); persist_write_string(MESSAGE_KEY_DATE_FORMAT_KEY, PersistDateFormat); persist_write_int(MESSAGE_KEY_BT_VIBRATE_KEY, PersistBTLoss); persist_write_int(MESSAGE_KEY_LOW_BATTERY_KEY, PersistLow_Batt); battery_state_service_unsubscribe(); bluetooth_connection_service_unsubscribe(); app_focus_service_unsubscribe(); text_layer_destroy(text_time_layer); text_layer_destroy(text_date_layer); text_layer_destroy(text_dayname_layer); text_layer_destroy(text_battery_layer); layer_destroy(BatteryLineLayer); layer_destroy(BTLayer); gbitmap_destroy(image); bitmap_layer_destroy(image_layer); fonts_unload_custom_font(fontHelvNewLight20); fonts_unload_custom_font(fontRobotoBoldSubset40); fonts_unload_custom_font(fontRobotoBoldSubset45); window_destroy(window); }
static void deinit() { window_destroy(window); text_layer_destroy(label_layer_time); tick_timer_service_unsubscribe(); app_message_deregister_callbacks(); }
static void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) { switch (key) { case BLINK_KEY: blink = new_tuple->value->uint8; tick_timer_service_unsubscribe(); if(blink) { tick_timer_service_subscribe(SECOND_UNIT, handle_tick); } else { tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); } break; case INVERT_KEY: invert = new_tuple->value->uint8; change_background(invert); break; case BLUETOOTHVIBE_KEY: bluetoothvibe = new_tuple->value->uint8; break; case HOURLYVIBE_KEY: hourlyvibe = new_tuple->value->uint8; break; } }
void psUnload(Window *window) { // Stop keeping track of time/chrono elapsed. tick_timer_service_unsubscribe(); // Stop timers if running. if (resetStartTimerHandle != NULL) { app_timer_cancel(resetStartTimerHandle); resetStartTimerHandle = NULL; } if (resetEndTimerHandle != NULL) { app_timer_cancel(resetEndTimerHandle); resetEndTimerHandle = NULL; } bitmap_layer_destroy(ssIconLayer); text_layer_destroy(psChronoLayer); text_layer_destroy(psSplitsLayer); window_destroy(psWindow); //psSavePersistentData(); chronoCloseTm = time(NULL); }
void disable_seconds() { layer_remove_from_parent(bitmap_layer_get_layer((BitmapLayer*) white_second_layer)); layer_remove_from_parent(bitmap_layer_get_layer((BitmapLayer*) black_second_layer)); tick_timer_service_unsubscribe(); tick_timer_service_subscribe(MINUTE_UNIT, &handle_tick); }
// Clean up void tic_tock_toe_deinit(void) { window_destroy(window); layer_destroy(boardLayer); layer_destroy(playersLayer); text_layer_destroy(timeLayer); tick_timer_service_unsubscribe(); }
void download_complete_handler(NetDownload *download) { printf("Loaded image with %lu bytes", download->length); printf("Heap free is %u bytes", heap_bytes_free()); #ifdef PBL_PLATFORM_APLITE GBitmap *bmp = gbitmap_create_with_png_data(download->data, download->length); #else GBitmap *bmp = gbitmap_create_from_png_data(download->data, download->length); #endif bitmap_layer_set_bitmap(bitmap_layer, bmp); // Save pointer to currently shown bitmap (to free it) if (current_bmp) { gbitmap_destroy(current_bmp); } current_bmp = bmp; // Free the memory now #ifdef PBL_PLATFORM_APLITE // gbitmap_create_with_png_data will free download->data #else free(download->data); #endif // We null it out now to avoid a double free download->data = NULL; netdownload_destroy(download); // Change tick handler to every minute now to save some battery tick_timer_service_unsubscribe(); tick_timer_service_subscribe(MINUTE_UNIT, tick_handler); time_t temp = time(NULL); last_check = localtime(&temp); }
static void main_window_unload(Window *window) { // Destroy TextLayer text_layer_destroy(s_time_layer); text_layer_destroy(s_bg_layer); text_layer_destroy(am_layer); text_layer_destroy(date_layer); text_layer_destroy(s_battery_layer); text_layer_destroy(hour_layer); text_layer_destroy(min_layer); text_layer_destroy(condition_layer); text_layer_destroy(temp_layer); text_layer_destroy(city_layer); text_layer_destroy(battery_text_layer); /*text_layer_destroy(s_temperature_layer); bitmap_layer_destroy(s_bitmap_layer); bitmap_layer_destroy(s_icon_layer); bitmap_layer_destroy(bt_layer);*/ fonts_unload_custom_font(s_custom_font_24); fonts_unload_custom_font(s_custom_font_18); fonts_unload_custom_font(s_custom_font_12); //gbitmap_destroy(blank_bitmap); //gbitmap_destroy(bt_bitmap); gbitmap_destroy(no_phone_bitmap); bitmap_layer_destroy(no_phone_layer); bluetooth_connection_service_unsubscribe(); battery_state_service_unsubscribe(); tick_timer_service_unsubscribe(); }
void handle_deinit(void) { fonts_unload_custom_font(mTimeFont); //fonts_unload_custom_font(mDateFont); fonts_unload_custom_font(mTemperatureFont); //fonts_unload_custom_font(mHighLowFont); layer_remove_from_parent(bitmap_layer_get_layer(mWeatherIconLayer)); bitmap_layer_destroy(mWeatherIconLayer); gbitmap_destroy(mWeatherIcon); layer_remove_from_parent(bitmap_layer_get_layer(battery_image_layer)); bitmap_layer_destroy(battery_image_layer); gbitmap_destroy(battery_image); battery_image = NULL; tick_timer_service_unsubscribe(); bluetooth_connection_service_unsubscribe(); battery_state_service_unsubscribe(); text_layer_destroy(mHighLowLayer); text_layer_destroy(mTimeSeparatorLayer); text_layer_destroy(mTemperatureLayer); text_layer_destroy(mDateLayer); text_layer_destroy(mTimeMinutesLayer); text_layer_destroy(mTimeHourLayer); layer_destroy(mTimeLayer); layer_destroy(mBackgroundLayer); remove_invert_top(); remove_invert_bottom(); window_destroy(mWindow); }
void handle_deinit(void) { tick_timer_service_unsubscribe(); accel_tap_service_unsubscribe(); text_layer_destroy(time_layer); text_layer_destroy(date_layer); window_destroy(my_window); }
void handle_deinit(void) { tick_timer_service_unsubscribe(); for (int i = 0; i < NUMBER_OF_IMAGES; i++) { gbitmap_destroy(images[i]); } bitmap_layer_destroy(dlayers[topbar_layer]); bitmap_layer_destroy(dlayers[month_tens_layer]); bitmap_layer_destroy(dlayers[month_ones_layer]); bitmap_layer_destroy(dlayers[month_seperator_layer]); bitmap_layer_destroy(dlayers[day_tens_layer]); bitmap_layer_destroy(dlayers[day_ones_layer]); bitmap_layer_destroy(dlayers[day_text_layer]); bitmap_layer_destroy(dlayers[secs_tens_layer]); bitmap_layer_destroy(dlayers[secs_ones_layer]); bitmap_layer_destroy(dlayers[ampm_layer]); bitmap_layer_destroy(dlayers[hours_tens_layer]); bitmap_layer_destroy(dlayers[hours_ones_layer]); bitmap_layer_destroy(dlayers[time_seperator_layer]); bitmap_layer_destroy(dlayers[mins_tens_layer]); bitmap_layer_destroy(dlayers[mins_ones_layer]); window_destroy(window); }
void remove_callback_handler(void *data) { Menu *temp = data; menu = temp; tick_timer_service_unsubscribe(); appmessage_clear_nearby_station(); }
void handle_battery(BatteryChargeState charge_state) { #if DEBUG //strftime(debug_buffer, DEBUG_BUFFER_BYTES, "%d.%m.%Y %H:%M:%S", now); snprintf(debug_buffer, DEBUG_BUFFER_BYTES, "%s%d%%", charge_state.is_charging ? "+" : "", charge_state.charge_percent); text_layer_set_text(debug_layer, debug_buffer); #endif #if SCREENSHOT bitmap_layer_set_bitmap(battery_layer, battery_images[1]); bool showSeconds = seconds_mode != SECONDS_MODE_NEVER; bool showBattery = battery_mode != BATTERY_MODE_NEVER; bool showDate = date_mode != DATE_MODE_NEVER; #else bitmap_layer_set_bitmap(battery_layer, battery_images[ (charge_state.is_charging ? 11 : 0) + min(charge_state.charge_percent / 9, 10)]); // 90% is max bool battery_is_low = charge_state.charge_percent <= 10; bool showSeconds = seconds_mode == SECONDS_MODE_ALWAYS || (seconds_mode == SECONDS_MODE_IFNOTLOW && (!battery_is_low || charge_state.is_charging)); bool showBattery = battery_mode == BATTERY_MODE_ALWAYS || (battery_mode == BATTERY_MODE_IF_LOW && battery_is_low) || charge_state.is_charging; bool showDate = date_mode != DATE_MODE_NEVER; #endif if (hide_seconds != !showSeconds) { hide_seconds = !showSeconds; tick_timer_service_unsubscribe(); tick_timer_service_subscribe(hide_seconds ? MINUTE_UNIT : SECOND_UNIT, &handle_tick); } layer_set_hidden(bitmap_layer_get_layer(battery_layer), !showBattery); if (layer_get_hidden(date_layer) != !showDate) { layer_set_hidden(date_layer, !showDate); layer_set_frame(background_layer, GRect(0, showDate ? 0 : 12, 144, 144)); } }
static void do_deinit(void) { tick_timer_service_unsubscribe(); text_layer_destroy(s_data.text_date_layer); text_layer_destroy(s_data.text_time_layer); layer_destroy(s_data.line_layer); window_destroy(s_data.window); }
void handle_deinit() { app_message_deregister_callbacks(); battery_state_service_unsubscribe(); tick_timer_service_unsubscribe(); if (has_config) { persist_write_int(SECONDS_MODE, seconds_mode); persist_write_int(BATTERY_MODE, battery_mode); persist_write_int(DATE_MODE, date_mode); persist_write_int(BLUETOOTH_MODE, bluetooth_mode); APP_LOG(APP_LOG_LEVEL_DEBUG, "Wrote config"); } else { APP_LOG(APP_LOG_LEVEL_DEBUG, "Did not write config"); } fonts_unload_custom_font(font); gpath_destroy(sec_path); gpath_destroy(min_path); gpath_destroy(hour_path); inverter_layer_destroy(inverter_layer); #if DEBUG text_layer_destroy(debug_layer); #endif layer_destroy(hands_layer); bitmap_layer_destroy(logo_layer); gbitmap_destroy(logo); bitmap_layer_destroy(battery_layer); for (int i = 0; i < 22; i++) gbitmap_destroy(battery_images[i]); bitmap_layer_destroy(bluetooth_layer); for (int i = 0; i < 2; i++) gbitmap_destroy(bluetooth_images[i]); layer_destroy(background_layer); layer_destroy(date_layer); window_destroy(window); }
static void worker_message_handler(uint16_t type, AppWorkerMessage *data) { static AppWorkerMessage msg_data; switch(type) { case WORKER_MSG_ECHO: #if !ECHO_CMDS // Construct a data packet msg_data.data0 = data->data0; // Send the data to the foreground app app_worker_send_message(WORKER_MSG_ECHO, &msg_data); #endif break; case WORKER_MSG_ACCEL_START: accel_data_service_subscribe(data->data0, worker_accel_data_handler); accel_service_set_sampling_rate(data->data1); worker_accel_enabled = true; break; case WORKER_MSG_ACCEL_STOP: accel_data_service_unsubscribe(); worker_accel_enabled = false; break; case WORKER_MSG_ACCEL_MODIFY: accel_service_set_samples_per_update(data->data0); accel_service_set_sampling_rate(data->data1); break; case WORKER_MSG_TICK_START: if ( data->data0 != 0 ) tickRate = data->data0; // how often do we want updates. tick_timer_service_subscribe(SECOND_UNIT, worker_tick_handler); worker_tick_enabled = true; break; case WORKER_MSG_TICK_STOP: tick_timer_service_unsubscribe(); worker_tick_enabled = false; break; case WORKER_MSG_LOGGING_START: datalog_ref = data_logging_create(SLEEP_DATA_LOG_TAG, DATA_LOGGING_BYTE_ARRAY, sizeof(struct AccelData), true); worker_logging_enabled = true; break; case WORKER_MSG_LOGGING_STOP: data_logging_finish(datalog_ref); worker_logging_enabled = false; break; case WORKER_MSG_STATUS_RQST: worker_send_status_resp(); break; } #if ECHO_CMDS msg_data.data0 = type; app_worker_send_message(WORKER_MSG_ECHO,&msg_data); #endif }
static void reset() { tick_timer_service_unsubscribe(); state.running = 0; state.round = 0; if (!stretch_settings.program) { layer_set_hidden(text_layer_get_layer(ui.middle_text), true); Layer *image_layer = text_layer_get_layer(ui.time_text); GRect image_frame = layer_get_frame(image_layer); image_frame.origin.x = (ui.bounds.size.w / 2) - 40; image_frame.origin.y = (ui.bounds.size.h / 2) - 25; layer_set_frame(image_layer, image_frame); } if (stretch_settings.prepare == 0) { state.round_time = stretch_settings.time; state.stretch = 1; } else { state.round_time = stretch_settings.prepare; state.stretch = 0; } update_ui(); }
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { static char s_uptime_buffer[32]; vibes_short_pulse(); alert_time--; if(alert_time <= 0 ){ //TODO: write notification code tick_timer_service_unsubscribe(); vibes_cancel(); text_layer_set_text(s_alert_text_layer, "Timout Reached\n:("); // Prepare dictionary DictionaryIterator *iterator; app_message_outbox_begin(&iterator); // Write data char buff[100]; if(persist_exists(PERSIST_KEY_PHONE_NUMBER)){ persist_read_string(PERSIST_KEY_PHONE_NUMBER, buff, 100); dict_write_cstring(iterator, PERSIST_KEY_PHONE_NUMBER, buff); } if(persist_exists(PERSIST_KEY_NAME)){ persist_read_string(PERSIST_KEY_NAME, buff, 100); dict_write_cstring(iterator, PERSIST_KEY_NAME, buff); } // Send the data! app_message_outbox_send(); } else { snprintf(s_uptime_buffer, sizeof(s_uptime_buffer), BANNER_TEXT "\n" CLOCK_FORMAT_STRING, alert_time/60, alert_time%60); text_layer_set_text(s_alert_text_layer, s_uptime_buffer); } }
void handle_deinit(void) { tick_timer_service_unsubscribe(); layer_destroy(bitmap_layer_get_layer(background_image_layer)); layer_destroy(display_layer); window_destroy(window); }
void handle_layout() { BatteryChargeState charge_state = battery_state_service_peek(); bool battery_is_low = charge_state.charge_percent <= 20; bool showSeconds = seconds_mode == SECONDS_MODE_ALWAYS || (seconds_mode == SECONDS_MODE_IFNOTLOW && (!battery_is_low || charge_state.is_plugged)); bool showBattery = battery_mode == BATTERY_MODE_ALWAYS || (battery_mode == BATTERY_MODE_IF_LOW && battery_is_low) || charge_state.is_plugged; int face_top = PBL_IF_ROUND_ELSE(0, date_pos == DATE_POS_BOTTOM ? 0 : date_pos == DATE_POS_OFF ? 12 : 24); int date_top = date_pos == DATE_POS_TOP ? 0 : EXTENT; int battery_top = date_pos == DATE_POS_TOP ? 168-10-3 : 3; if (hide_seconds != !showSeconds) { hide_seconds = !showSeconds; tick_timer_service_unsubscribe(); tick_timer_service_subscribe(hide_seconds ? MINUTE_UNIT : SECOND_UNIT, &handle_tick); } layer_set_hidden(date_layer, date_pos == DATE_POS_OFF); layer_set_hidden(battery_layer, !showBattery); layer_set_frame(background_layer, GRect(0, face_top, EXTENT, EXTENT)); layer_set_frame(date_layer, GRect(0, date_top, EXTENT, 24)); layer_set_frame(battery_layer, GRect(EXTENT-22-3, battery_top, 22, 10)); FG_COLOR = graphics_mode == GRAPHICS_MODE_INVERT ? GColorBlack : GColorWhite; BG_COLOR = graphics_mode == GRAPHICS_MODE_INVERT ? GColorWhite : GColorBlack; window_set_background_color(window, BG_COLOR); }
static void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) { switch (key) { case BLINK_KEY: blink = new_tuple->value->uint8; tick_timer_service_unsubscribe(); if(blink) { tick_timer_service_subscribe(SECOND_UNIT, handle_tick); } else { tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); } break; case BLUETOOTHVIBE_KEY: bluetoothvibe = new_tuple->value->uint8; break; case HOURLYVIBE_KEY: hourlyvibe = new_tuple->value->uint8; break; case SHOW_24H_ICON_KEY: //n3v3r switch_show_24h_icon = new_tuple->value->uint8; break; case SHOW_BATT_PERCENT_KEY: //n3v3r switch_show_batt_percent = new_tuple->value->uint8; break; } }
void handle_deinit() { tick_timer_service_unsubscribe(); animation_unschedule_all(); property_animation_destroy(mario_animation_beg); property_animation_destroy(mario_animation_end); property_animation_destroy(block_animation_beg); property_animation_destroy(block_animation_end); property_animation_destroy(hour_animation_slide_in); property_animation_destroy(hour_animation_slide_away); property_animation_destroy(minute_animation_slide_in); property_animation_destroy(minute_animation_slide_away); gbitmap_destroy(mario_normal_bmp); gbitmap_destroy(mario_jump_bmp); gbitmap_destroy(ground_bmp); text_layer_destroy(date_layer); text_layer_destroy(text_minute_layer); text_layer_destroy(text_hour_layer); layer_destroy(ground_layer); layer_destroy(mario_layer); layer_destroy(blocks_layer); window_destroy(window); }
static void inbox_received_callback(DictionaryIterator *iterator, void *context) { APP_LOG(APP_LOG_LEVEL_INFO, "inbox"); //seconds Tuple *t = dict_find(iterator, 0); seconds = (int)t->value->int32 == 1; tick_timer_service_unsubscribe(); tick_timer_service_subscribe(seconds?SECOND_UNIT:MINUTE_UNIT, (TickHandler) tick); //weekday t = dict_find(iterator, 1); weekday = (int)t->value->int32 == 1; //date t = dict_find(iterator, 2); date = (int)t->value->int32 == 1; //month t = dict_find(iterator, 3); month = (int)t->value->int32 == 1; //redraw layer_mark_dirty(layer); }
static void handle_deinit() { app_message_deregister_callbacks(); battery_state_service_unsubscribe(); tick_timer_service_unsubscribe(); fonts_unload_custom_font(font); fonts_unload_custom_font(font2); gpath_destroy(min_path); gpath_destroy(hour_path); gpath_destroy(hour_in_path); text_layer_destroy(battp_layer); text_layer_destroy(date_layer); text_layer_destroy(day_layer); text_layer_destroy(time_layer); layer_destroy(hands_layer); bitmap_layer_destroy(logo_layer); gbitmap_destroy(logo); bitmap_layer_destroy(battery_layer); for (int i = 0; i < 22; i++) gbitmap_destroy(battery_images[i]); bitmap_layer_destroy(bluetooth_layer); for (int i = 0; i < 2; i++) gbitmap_destroy(bluetooth_images[i]); layer_destroy(background_layer); window_destroy(window); }
void deinit() { tick_timer_service_unsubscribe(); window_destroy(window); }
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); }