void save_charge_log(ChargeLog* charge_log) { int32_t log_count = 0; int32_t log_index = 0; if (persist_exists(PERSIST_KEY_LOG_COUNT)) { log_count = persist_read_int(PERSIST_KEY_LOG_COUNT); } if (persist_exists(PERSIST_KEY_LOG_INDEX)) { log_index = persist_read_int(PERSIST_KEY_LOG_INDEX); } log_count++; uint32_t key_log = PERSIST_KEY_LOG_BASE + (log_index + log_count - 1) % MAX_LOG_COUNT; if (log_count > MAX_LOG_COUNT) { log_count--; log_index++; } persist_write_int(PERSIST_KEY_LOG_COUNT, log_count); persist_write_int(PERSIST_KEY_LOG_INDEX, log_index); persist_write_data(key_log, charge_log, sizeof(*charge_log)); if (launch_reason() != APP_LAUNCH_WAKEUP) { layer_mark_dirty(s_graph_layer); } }
static void init() { // Subscribe to Wakeup API wakeup_service_subscribe(wakeup_handler); // 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); app_message_open(400,400); // Was this a wakeup launch? if (launch_reason() == APP_LAUNCH_WAKEUP) { // The app was started by a wakeup WakeupId id = 0; int32_t reason = 0; // Get details and handle the wakeup wakeup_get_launch_event(&id, &reason); wakeup_handler(id, reason); } else { // Launch main page init_main_window(); // Launch the splash page init_splash_window(); } }
int main() { s_result_text[0] = '\0'; s_load_screen = create_load_screen(); window_stack_push(s_load_screen, true); s_result_screen = create_result_screen(); events_app_message_request_inbox_size(2048); events_app_message_request_outbox_size(32); s_app_message_event_handle = events_app_message_register_inbox_received(&message_received, NULL); events_app_message_open(); /* * 0 APP_LAUNCH_SYSTEM App launched by the system * 1 APP_LAUNCH_USER App launched by user selection in launcher menu * 2 APP_LAUNCH_PHONE App launched by mobile or companion app * 3 APP_LAUNCH_WAKEUP App launched by wakeup event * 4 APP_LAUNCH_WORKER App launched by worker calling worker_launch_app() * 5 APP_LAUNCH_QUICK_LAUNCH App launched by user using quick launch * 6 APP_LAUNCH_TIMELINE_ACTION App launched by user opening it from a pin * 7 APP_LAUNCH_SMARTSTRAP App launched by a smartstrap */ s_launch_reason = launch_reason(); APP_LOG(APP_LOG_LEVEL_DEBUG, "launch reason #%d", s_launch_reason); app_event_loop(); window_destroy(s_load_screen); window_destroy(s_result_screen); }
int main(void) { appmessage_max_size = app_message_inbox_size_maximum(); if (appmessage_max_size > 4096) appmessage_max_size = 4096; //Limit inbox size to conserve RAM. #ifdef PBL_PLATFORM_APLITE //Aplite has so little memory, we can't squeeze much more than that out of appmessage buffer. appmessage_max_size = 124; #endif app_message_register_inbox_received(received_data); app_message_register_outbox_sent(sent_data); app_message_open(appmessage_max_size, 408); loadingMode = true; send_initial_packet(); app_timer_register(3000, loading_retry_timer, NULL); switchWindow(0); app_event_loop(); window_stack_pop_all(false); free(config_periodicVibrationPattern); AppLaunchReason appLaunchReason = launch_reason(); if (appLaunchReason == APP_LAUNCH_PHONE && !config_dontClose) { // If app was launched by phone and close to last app is disabled, always exit to the watchface instead of to the menu exit_reason_set(APP_EXIT_ACTION_PERFORMED_SUCCESSFULLY); } return 0; }
/* * Create main window */ static void handle_init() { // Check which defines are defined #ifdef PBL_SDK_3 LOG_INFO("PBL_SDK_3"); #endif #ifdef PBL_PLATFORM_APLITE LOG_INFO("PBL_PLATFORM_APLITE"); #endif #ifdef PBL_PLATFORM_BASALT LOG_INFO("PBL_PLATFORM_BASALT"); #endif #ifdef PBL_PLATFORM_CHALK LOG_INFO("PBL_PLATFORM_CHALK"); #endif #ifdef PBL_COLOR LOG_INFO("PBL_COLOR"); #endif #ifdef PBL_BW LOG_INFO("PBL_BW"); #endif #ifdef PBL_ROUND LOG_INFO("PBL_ROUND"); #endif #ifdef PBL_RECT LOG_INFO("PBL_RECT"); #endif // Create primary window ui.primary_window = window_create(); // Go straight to chart if needed #ifdef ENABLE_CHART_VIEWER if (launch_reason() == APP_LAUNCH_TIMELINE_ACTION && launch_get_args() == TIMELINE_LAUNCH_CHART) { window_set_window_handlers(ui.primary_window, (WindowHandlers ) { .load = chart_load, .unload = chart_unload });
MenuIndex get_current_session_from_time() { time_t now = time(NULL); struct tm *tm_now = localtime(&now); MenuIndex current = {.section = 0, .row = 0}; if (tm_now->tm_mon != event_month - 1 || tm_now->tm_mday != event_day) { return current; } for(int ts_idx=0; ts_idx<schedule.num_slots; ts_idx++) { TimeSlot *ts = &schedule.slots[ts_idx]; if (tm_now->tm_hour < ts->start_hour) { break; } else if(tm_now->tm_hour == ts->start_hour && tm_now->tm_min < ts->start_min) { break; } current.section = ts_idx; } return current; } MenuIndex get_current_session_from_args() { int args = launch_get_args(); MenuIndex current = {.section = args / 10, .row = args % 10}; return current; } MenuIndex get_current_session() { #ifdef PBL_COLOR if (launch_reason() == APP_LAUNCH_TIMELINE_ACTION && launch_get_args() > 0) { return get_current_session_from_args(); } #endif return get_current_session_from_time(); } static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); menu_schedule = menu_layer_create(bounds); #ifdef PBL_COLOR menu_layer_set_normal_colors(menu_schedule, ROW_BG_COLOR, ROW_FG_COLOR); menu_layer_set_highlight_colors(menu_schedule, HIGHLIGHT_BG_COLOR, HIGHLIGHT_FG_COLOR); #endif menu_layer_set_callbacks(menu_schedule, NULL, (MenuLayerCallbacks) { .get_num_sections = menu_get_num_sections_callback, .get_num_rows = menu_get_num_rows_callback, .get_header_height = menu_get_header_height_callback, .get_cell_height = menu_get_height_callback, .draw_header = menu_draw_header_callback, .draw_row = menu_draw_row_callback, .select_click = menu_select_callback, }); menu_layer_set_click_config_onto_window(menu_schedule, window); MenuIndex idx = get_current_session(); menu_layer_set_selected_index(menu_schedule, idx, MenuRowAlignCenter, false); layer_add_child(window_layer, menu_layer_get_layer(menu_schedule)); }
int main(void) { locale_init(); handle_init(); app_event_loop(); if(launch_reason() == APP_LAUNCH_TIMELINE_ACTION) { //lastIdFromAppLaunch = (int)launch_get_args(); // Start voice dictation UI //dictation_session_start(s_dictation_session); } handle_deinit(); }
int main(void) { if (launch_reason() == APP_LAUNCH_WAKEUP) { APP_LOG(APP_LOG_LEVEL_DEBUG, "launch wakeup"); wakeup_service_subscribe(NULL); BatteryChargeState charge_state = battery_state_service_peek(); save_charge_state(&charge_state); schedule_wakeup_measure_battery_state(); app_event_loop(); } else { handle_init(); app_event_loop(); handle_deinit(); } }
static void received_config(DictionaryIterator *received) { loadingMode = false; uint8_t* data = dict_find(received, 2)->value->data; uint16_t supportedVersion = (data[8] << 8) | (data[9]); if (supportedVersion > PROTOCOL_VERSION) { show_old_watchapp_error(); return; } else if (supportedVersion < PROTOCOL_VERSION) { show_old_android_error(); return; } config_timeout = (data[3] << 8) | (data[4]); config_dontClose = (data[7] & 0x02) != 0; config_showActive = (data[7] & 0x04) != 0; main_noMenu = (data[7] & 0x08) != 0; config_lightScreen = (data[7] & 0x10) != 0; config_dontVibrateWhenCharging = (data[7] & 0x20) != 0; config_disableNotifications = (data[7] & 0x80) != 0; config_whiteText = (data[7] & 0x740) != 0; config_disableVibration = (data[7] & 0x01) != 0; config_displayScrollShadow = (data[13] & 0x01) != 0; config_scrollByPage = PBL_IF_ROUND_ELSE(true, (data[13] & 0x02) != 0); config_disconnectedNotification = (data[13] & 0x04) != 0; config_gestures = (data[13] & 0x08) != 0; config_periodicTimeout = (data[11] << 8) | (data[12]); config_lightTimeout = data[5]; config_periodicVibrationPatternSize = data[14]; config_periodicVibrationTotalDuration = 0; config_periodicVibrationPattern = malloc(config_periodicVibrationPatternSize / 2 * sizeof(uint32_t)); for (int i = 0; i < config_periodicVibrationPatternSize; i+= 2) { config_periodicVibrationPattern[i / 2] = data[15 + i] | (data[16 + i] << 8); config_periodicVibrationTotalDuration += config_periodicVibrationPattern[i / 2]; } #if PBL_COLOR config_skew_background_image_colors = (data[13] & 0x10) != 0; #endif loadingMode = false; gotConfig = true; bool respectQuietTime = (data[13] & 0x20) != 0; if (respectQuietTime && quiet_time_is_active()) { AppLaunchReason launchReason = launch_reason(); if (launchReason == APP_LAUNCH_PHONE) { // App was launched by phone, but quiet time is active. Lets bail out. closingMode = true; rejectNotifications = true; gotConfig = false; } } if (rejectNotifications) { show_quitting(); } else if (!main_noMenu) { show_menu(); } }