void beat( void ) { if( should_stop_beating( num_beats++ ) ) { // This stops beating. handle_run_click( 0, 0 ); return; } // tempo = beats per min // beat_interval = ms per beat // 60,000 ms per min // // ms_per_min / tempo = ms/min / beats/min // = ms/beat // layer_mark_dirty( &visual_beat_layer ); draw_beat = 1; // This integer division will be off by up to 1ms. beat_interval = 60000 / tempo; beat_timer = app_timer_send_event( my_ctx, beat_interval, 0 ); clear_beat_timer = app_timer_send_event( my_ctx, beat_interval / 2, 0 ); if( vibe_enabled ) { vibes_enqueue_custom_pattern( vibe_pat ); } }
void handle_timer(AppContextRef ctx, AppTimerHandle handle, uint32_t cookie) { (void)ctx; (void)handle; if (cookie == COOKIE_MY_TIMER) { if(init_anim == ANIM_START) { init_anim = ANIM_HOURS; timer_handle = app_timer_send_event(ctx, 50 /* milliseconds */, COOKIE_MY_TIMER); } else if(init_anim==ANIM_HOURS) { layer_mark_dirty(&hour_display_layer); timer_handle = app_timer_send_event(ctx, 50 /* milliseconds */, COOKIE_MY_TIMER); } else if(init_anim==ANIM_MINUTES) { layer_mark_dirty(&minute_display_layer); timer_handle = app_timer_send_event(ctx, 50 /* milliseconds */, COOKIE_MY_TIMER); } #if DISPLAY_SECONDS else if(init_anim==ANIM_SECONDS) { layer_mark_dirty(&second_display_layer); timer_handle = app_timer_send_event(ctx, 50 /* milliseconds */, COOKIE_MY_TIMER); } #endif } }
// ---------------------------------------------------------------------------- // handle_timer() // // The following section of code handles despatching timer ticks to the // program splash page handler until the maximum number of required ticks // is reached or the user pushes any key, at which time the splash page // processing is aborted. This is signaled by setting the tf_skip_start // flag in the Splash Page Window click handlers. // // Note: This section should probably me moved off to the page_start.c // module and serviced by a call from handle_timer() to // that module. // ---------------------------------------------------------------------------- void handle_timer(AppContextRef ctx, AppTimerHandle handle, uint32_t cookie) { app_timer_cancel_event(tf_app_context, tf_timer); // no more ticks, please if(tf_splash_done) { // error handler in case we miss a timer tick return; } if((tf_skip_start) && !(tf_splash_done)) { // flag set by click handlers in page_start module finish_splash_page(); return; } // else we be animating... if(tf_tick_count < NUMBER_OF_IMAGES) { // animate graphics page_start_tick(tf_tick_count++); tf_timer = app_timer_send_event(tf_app_context, 250, 42); } else if(tf_tick_count < (NUMBER_OF_IMAGES + 3)) { // animate graphics page_start_tick(tf_tick_count++); tf_timer = app_timer_send_event(tf_app_context, 1200, 42); } else { finish_splash_page(); // clean up & display program menu window } } // handle_timer()
void http_capture_send(int wait) { if (http_capture_sending) return; if (wait) { http_capture_sending = true; app_timer_send_event(http_capture_app_context_ref, wait, http_capture_COOKIE_start); } else { http_capture_make_framebuffer_copy(); http_capture_sending = true; app_timer_send_event(http_capture_app_context_ref, 10, http_capture_COOKIE_send); } }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "Main"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); resource_init_current_app(&APP_RESOURCES); frame_animation_init(&gif_animation, &window.layer, GPoint(0,0), RESOURCE_ID_FRAME_1, 12, false, true); timer_handle = app_timer_send_event(ctx, 100, 1); text_layer_init(&text_time_layer, GRect(0, 5, 144, 30)); text_layer_set_text_color(&text_time_layer, GColorWhite); text_layer_set_background_color(&text_time_layer, GColorClear); text_layer_set_text_alignment(&text_time_layer, GTextAlignmentCenter); text_layer_set_font(&text_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); layer_add_child(&window.layer, &text_time_layer.layer); text_layer_init(&date_layer, GRect(0, 130, 144, 30)); text_layer_set_text_color(&date_layer, GColorWhite); text_layer_set_background_color(&date_layer, GColorClear); text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter); text_layer_set_font(&date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); layer_add_child(&window.layer, &date_layer.layer); }
void handle_tick(AppContextRef ctx, PebbleTickEvent *t){ (void)t; (void)ctx; if(init_anim == ANIM_IDLE) { init_anim = ANIM_START; timer_handle = app_timer_send_event(ctx, 50 /* milliseconds */, COOKIE_MY_TIMER); } else if(init_anim == ANIM_DONE) { 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(t->tick_time->tm_min==0&&t->tick_time->tm_hour==0) { draw_date(); } } } } layer_mark_dirty(&second_display_layer); } }
void animate_moon(AppContextRef ctx, AppTimerHandle handle, uint32_t cookie) { (void)ctx; (void)handle; animationCount++; if(animationCount*animationStep <= 1 ){ phasePercent += animationStep; if(phasePercent>=1)phasePercent--; layer_mark_dirty(&shadow_layer); timer_handle = app_timer_send_event(ctx, animationSpeed, 1); } else{ PblTm t; get_time(&t); setPhase(daysSinceNewMoon(t.tm_year+1900,t.tm_yday,t.tm_hour)); curHour=t.tm_hour; curMin=t.tm_min; curSec=t.tm_sec; layer_mark_dirty(&shadow_layer); layer_mark_dirty(&phase_layer); if(showHours){ layer_mark_dirty(&hour_layer); layer_mark_dirty(&minute_layer); layer_mark_dirty(&top_layer); } } }
void handle_init(AppContextRef ctx) { Layer *rootLayer; int i; window_init(&window, "Squared"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorBlack); rootLayer = window_get_root_layer(&window); for (i=0; i<NUMSLOTS; i++) { initSlot(i, rootLayer); } animImpl.setup = NULL; animImpl.update = animateDigits; animImpl.teardown = NULL; animation_init(&anim); animation_set_delay(&anim, 0); animation_set_duration(&anim, DIGIT_CHANGE_ANIM_DURATION); animation_set_implementation(&anim, &animImpl); app_timer_send_event(ctx, STARTDELAY /* milliseconds */, 0); }
void update_shot() { thishole++; mini_snprintf(s_shots_hole, 25, "Shots: %d", thishole); text_layer_set_text(&shots_hole, s_shots_hole); update_total(); text_layer_set_text(&club, "Shot Recorded"); timer_handle = app_timer_send_event(g_ctx, 1500 /* milliseconds */, COOKIE_MY_TIMER); }
/* * Get the calendar running */ void calendar_init(AppContextRef ctx) { g_app_context = ctx; for (uint8_t i=0; i < (MAX_EVENTS * 2); i++) { g_timer_rec[i].active = false; } memset(&g_events, 0, sizeof(Event) * MAX_EVENTS); app_timer_send_event(ctx, ROTATE_EVENT_INTERVAL_MS, ROTATE_EVENT); }
void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *t) { (void)ctx; (void)t; update_hand_positions(&hour_hand_image_container, &minute_hand_image_container); timer_handle = app_timer_send_event(ctx, 100, 1); // Send a timer to start the blink animation }
void handle_init(AppContextRef ctx) { window_init(&window, "Demo"); window_stack_push(&window, true /* Animated */); text_layer_init(&text_layer, window.layer.frame); text_layer_set_text(&text_layer, "Waiting for timer..."); layer_add_child(&window.layer, &text_layer.layer); timer_handle = app_timer_send_event(ctx, 1500 /* milliseconds */, COOKIE_MY_TIMER); }
void spinner_long_down_handler( ClickRecognizerRef recognizer, void* ctx ) { spinner* spin = (spinner*) ctx; spin->fast_down_timer = app_timer_send_event( spin->ctx, spin->repeat_interval, (uint32_t) spin ); spin->num_fast_changes = 0; (*spin->down_handler)( recognizer, ctx ); }
void handle_timer(AppContextRef ctx, AppTimerHandle handle, uint32_t cookie) { (void)ctx; (void)handle; if (cookie == COOKIE) { vibes_short_pulse(); if (on && power > 0) { timer_handle = app_timer_send_event(ctx, 200 * (6 - power) /* milliseconds */, COOKIE); } } }
void select_click_handler(ClickRecognizerRef recognizer, Window *window) { _isPlaying = !_isPlaying; if(_isPlaying) { layer_set_hidden(&_greyBmp[0].layer.layer, true); _timer_handle = app_timer_send_event(_storedctx, _base_interval /* milliseconds */, 0); } else { layer_set_hidden(&_greyBmp[_currentShown].layer.layer, true); layer_set_hidden(&_greyBmp[0].layer.layer, false); } }
void handle_timer(AppContextRef ctx, AppTimerHandle handle, uint32_t ignored) { layer_set_hidden(&_greyBmp[_currentShown].layer.layer, true); _currentShown++; if(_currentShown==3) _currentShown=1; layer_set_hidden(&_greyBmp[_currentShown].layer.layer, false); if(_isPlaying) { _timer_handle = app_timer_send_event(ctx, _base_interval /* milliseconds */, 0); } }
void handle_timer(AppContextRef ctx, AppTimerHandle handle, uint32_t cookie) { // This implementation assumes only one type of timer used in the app. current_layer_angle = (current_layer_angle + 2) % 360; // This will automatically mark the layer dirty and update it. rotbmp_pair_layer_set_angle(&bitmap_container.layer, TRIG_MAX_ANGLE * current_layer_angle / 360); app_timer_send_event(ctx, 50 /* milliseconds */, cookie); }
void handle_second_tick(AppContextRef ctx, PebbleTickEvent *t) { (void)t; (void)ctx; //Load the Colon Image layer_set_hidden(&cursor_layer.layer.layer, false); timer_handle = app_timer_send_event(ctx, 500 /* milliseconds */, COOKIE_MY_TIMER); if((t->units_changed & MINUTE_UNIT) != 0) { update_display(t->tick_time); } }
void select_single_click_handler(ClickRecognizerRef recognizer, Window *window) { (void)recognizer; (void)window; on = !on; if (on) { timer_handle = app_timer_send_event(app_ctx, 100 /* milliseconds */, COOKIE); } else { app_timer_cancel_event(app_ctx, timer_handle); } layer_mark_dirty(&bars_layer); }
bool spinner_handle_timeout( AppContextRef app_ctx, AppTimerHandle handle, uint32_t cookie ) { spinner* spin = (spinner*) cookie; uint32_t timeout; if( spin == 0 ) { return false; } timeout = spin->repeat_interval; if( handle == spin->fast_up_timer || handle == spin->fast_down_timer ) { if( ++spin->num_fast_changes > spin->start_fast_repeat_count ) { timeout = spin->fast_repeat_interval; } if( handle == spin->fast_up_timer ) { spinner_up_handler( (ClickRecognizerRef) NULL, (void*) spin ); spin->fast_up_timer = app_timer_send_event( app_ctx, timeout, cookie ); } else if( handle == spin->fast_down_timer ) { spinner_down_handler( (ClickRecognizerRef) NULL, (void*) spin ); spin->fast_down_timer = app_timer_send_event( app_ctx, timeout, cookie ); } return true; } return false; }
void reschedule_locTimer() { if (locTimer) app_timer_cancel_event(app, locTimer); // schedule the next update based on zoom level uint32_t poll; if (zoom < 5) { poll = 600e3; } else if (zoom < 10) { poll = 60e3; } else if (zoom < 14) { poll = 15e3; } else { poll = 7e3; } locTimer = app_timer_send_event(app, poll, 0); }
/* * Clock syncronised timer */ void sync_timed_event(int tm_min, AppContextRef ctx) { // Only on the 10 minute clicks (importantly includes midnight) if (tm_min % 10 != 0 && !g_first_time) return; if (g_first_time) { g_first_time = false; calendar_request(); } else { // Delay for 35 seconds after the minute to ensure that alerts have already happened app_timer_send_event(ctx, 35000, REQUEST_CALENDAR_KEY); } }
/* * Queue an alert */ void queue_alert(int num, int32_t alarm_time, char *title, int32_t alert_event, char *location) { // work out relative time char relative_temp[21]; if (alarm_time == 0) strncpy(relative_temp, TEXT_NOW, sizeof(relative_temp)); else if (alarm_time < 3600) snprintf(relative_temp, sizeof(relative_temp), TEXT_MINS, alarm_time / 60); else snprintf(relative_temp, sizeof(relative_temp), TEXT_HRS, alarm_time / 3600); // Create an alert g_timer_rec[num].handle = app_timer_send_event(g_app_context, alert_event, ALERT_EVENT + num); g_timer_rec[num].active = true; strncpy(g_timer_rec[num].event_desc, title, BASIC_SIZE); strncpy(g_timer_rec[num].relative_desc, relative_temp, BASIC_SIZE); strncpy(g_timer_rec[num].location, location, BASIC_SIZE); }
void handle_tempo_tap( ClickRecognizerRef recognizer, Window* win ) { if( measuring_tempo ) { // This is in 1ms units. uint32_t tap_time = hw_timer_get_time(); uint32_t tap_interval = tap_time - last_tap_time; last_tap_time = tap_time; // Push num ticks, calc curr and avg tempo. if( num_tap_intervals < MAX_TAP_INTERVALS ) { tap_intervals[num_tap_intervals++] = tap_interval; } else { uint32_t sum = tap_intervals[0]; uint32_t avg; for( int t = 1; t < MAX_TAP_INTERVALS; t++ ) { sum += tap_intervals[t]; tap_intervals[t-1] = tap_intervals[t]; } tap_intervals[MAX_TAP_INTERVALS-1] = tap_interval; avg = sum / 4; avg_tempo = 60000 / avg; snprintf( avg_tempo_str, 4, "%d", avg_tempo ); text_layer_set_text( &avg_tempo_lay, avg_tempo_str ); } if( num_tap_intervals > 1 ) { curr_tempo = 60000 / tap_interval; snprintf( curr_tempo_str, 4, "%d", curr_tempo ); text_layer_set_text( &curr_tempo_lay, curr_tempo_str ); } } else { num_tap_intervals = 0; hw_timer_start(); last_tap_time = hw_timer_get_time(); text_layer_set_text( &measuring_lay, measuring_active_str ); layer_set_hidden( (Layer*) &measuring_inverter_lay, false ); memset( tap_intervals, 0, ARRAY_LENGTH(tap_intervals) * sizeof(*tap_intervals) ); measuring_tempo = true; } stop_measuring_timer = app_timer_send_event( my_ctx, STOP_MEASURING_TIMEOUT, 0 ); }
void handle_init(AppContextRef ctx) { // makes sure the light is enabled at the beginning of the app light_enable_interaction(); window_init(&window, "Torch"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorWhite); // window_set_fullscreen(&window, true); // removes the clock displayed on the top of the screen. text_layer_init(&textLayer, window.layer.frame); text_layer_set_text(&textLayer, "Backlight is ON as long as this screen is displayed."); text_layer_set_font(&textLayer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text_alignment(&textLayer, GTextAlignmentCenter); layer_add_child(&window.layer, &textLayer.layer); // TODO : set text in thé midole of thé screen app_timer_send_event(ctx, REFRESH_LIGHT_TIMEOUT /* milliseconds */, 0 /* Not using a cookie value */); }
void set_timer(AppContextRef ctx) { /*app_timer_send_event(ctx, 1800000, 1); // if these are ms, then is this 30 min, rather than 15 min?*/ // just trying something: if(timerHandle != APP_TIMER_INVALID_HANDLE) { // likely that we already have a timer scheduled. cancel it first bool result = app_timer_cancel_event(ctx, timerHandle); if(result == false) { // there was either no timer to cancel, or something went wrong. // nevertheless, do nothing for now. } timerHandle = APP_TIMER_INVALID_HANDLE; } AppTimerHandle _timerHandle = app_timer_send_event(ctx, 300000, 1); // 5 min. if(_timerHandle != APP_TIMER_INVALID_HANDLE) { timerHandle = _timerHandle; } }
void handle_init(AppContextRef ctx) { window_init(&window, "Demo"); window_stack_push(&window, false /* Not animated */); // We do this to account for the offset due to the status bar // at the top of the app window. GRect layer_frame_description = layer_get_frame(&window.layer); layer_frame_description.origin.x = 0; layer_frame_description.origin.y = 0; // Add some background content to help demonstrate transparency. text_layer_init(&text_layer, layer_frame_description); text_layer_set_text(&text_layer, "pandamonium pandamon\n" "ium pandamonium panda\n" "monium pandamonium\n" "pandamonium pandamon\n" "ium pandamonium panda\n" "monium pandamonium\n" "pandamonium pandamon\n" "ium pandamonium panda\n" "monium pandamonium p\n" "andamonium pandamoni\n" ); layer_add_child(&window.layer, &text_layer.layer); // Display the black and white image with transparency. resource_init_current_app(&APP_RESOURCES); rotbmp_pair_init_container(RESOURCE_ID_IMAGE_PANDA_WHITE, RESOURCE_ID_IMAGE_PANDA_BLACK, &bitmap_container); layer_add_child(&window.layer, &bitmap_container.layer.layer); // Start the animation. app_timer_send_event(ctx, 50 /* milliseconds */, 0 /* Not using a cookie value */); }
void handle_tick(AppContextRef ctx, PebbleTickEvent *t){ (void)t; (void)ctx; if(init_anim == ANIM_IDLE) { init_anim = ANIM_START; timer_handle = app_timer_send_event(ctx, 50 /* milliseconds */, COOKIE_MY_TIMER); } else if(init_anim == ANIM_DONE) { 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(t->tick_time->tm_min==0&&t->tick_time->tm_hour==0) { draw_date(); } #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 set_timer(AppContextRef ctx) { app_timer_send_event(ctx, 1740000, 1); }
void handle_init(AppContextRef ctx) { //(void)ctx; // ------------------------------------------------- // set up state and global graphics // ------------------------------------------------- tf_app_context = ctx; // TODO: when we have persistent storage we'll reload it here // ---------------------------------------------- // set up arrays of images for animated logos // ---------------------------------------------- // Set up to access the animation image resources resource_init_current_app(&APP_RESOURCES); // now init bitmap containers (remember to deinit on exit!) // (Note: Logos used for animation, Icons used for Action Bar menus) // logo_image_container[] used for small logos on feature pages, // page_start_logo_data[] used for large logos on Splash Page shown on launch for(int i=0; i<NUMBER_OF_IMAGES; i++) { bmp_init_container(IMAGE_RESOURCE_IDS[i], &calc_logo_data.image_container[i]); bmp_init_container(IMAGE_RESOURCE_IDS[i], &stop_logo_data.image_container[i]); bmp_init_container(IMAGE_RESOURCE_IDS[i], &timer_logo_data.image_container[i]); bmp_init_container(IMAGE_RESOURCE_LARGE_IDS[i], &page_start_logo_data.image_container[i]); } for(int i=0; i<NUMBER_OF_ICONS; i++) { bmp_init_container(IMAGE_RESOURCE_ICONS[i], &tf_icon_container[i]); } // --------------------------------------------------- // Initialize program modules // Note: we create first window in menu_program_init() // --------------------------------------------------- // init program feature modules feature_calc_init(); // init Calculator feature feature_stop_init(); // init Stopwatch feature feature_timer_init(); // init countdown Timer feature feature_analog_init(); // init Analog Clock feature // init various menu modules menu_program_init(); // init program Home Page menu menu_calc_init(); // init program Main config menu menu_stop_init(); // (reserved for future use) menu_timer_init(); // (reserved for future use) // menu_settings_init(); // (reserved for future use) // menu_defaults_init(); // r(eserved for future use) // init program support pages modules page_start_init(); // init start page page_about_init(); // init about page page_help_init(); // init page // page_timer_init(); // // and now launch the program via the splash page page_start_show_page(); // and start the splash pager timer tf_timer = app_timer_send_event(tf_app_context, 1000, 42); } // handle_init()