// This is called regularly to stop the watch "going to sleep"; all we
// want to do here is cancel our existing timer and create a new one
void mode_displaysleep_update_power_down(int iPowerDownMS) {
  multi_debug("mode_displaysleep_update_power_down %i\n", iPowerDownMS);

  // Ensure our own personal "active" loop is cancelled
  pulse_cancel_timer(&modeDisplaysleepingTimerID); 
  assert(modeDisplaysleepingTimerID == -1);

  pulse_cancel_timer(&modeDisplaysleepPowerDownTimerID); // pulse
  assert(modeDisplaysleepPowerDownTimerID == -1);

  modeDisplaysleepPowerDownTimerID = pulse_register_timer(iPowerDownMS,
                   &mode_displaysleep_power_down, 0); // pulse
  assert(modeDisplaysleepPowerDownTimerID != -1);
}
Beispiel #2
0
void main_app_handle_button_down()
{
    pulse_blank_canvas();
    
    if (state == 0)
		get_ready();
	else if (state == 1)
	{
		pulse_cancel_timer(&hold_timer_value);
		state = 0;
		printf("XXX Too soon XXX\n\n");
		printf("click to try \nagain");
		printf("\n\n\n\n\n\n\n\n\n\n\nBest: %dms",best_time);
	}
	else if (state == 2)
	{
		state = 0;
		
		int reaction_time = (int)pulse_get_millis() - start_time;
		printf("You reacted in \n\n%d millisecs\n\n",reaction_time);
		printf("Click to try \nagain");
		
		if (reaction_time < best_time)
			best_time = reaction_time;
		
		printf("\n\n\n\n\n\n\n\n\n\nBest: %dms",best_time);
	}		
}
Beispiel #3
0
void main_app_handle_button_up()
{
    if (!button_held)
    {
        pulse_cancel_timer(&button_timer_id);

        if (current_screen == SCREEN_CLOCK)
        {
            cancel_sleep();
            reset_game();
            pulse_blank_canvas();
            current_screen = SCREEN_GAME_OVER;
            printf("Click to start.\n\n\nClick while \nyou're in the \nair to do a \ndouble jump!");
            prepare_to_sleep();
        }
        else if (current_screen == SCREEN_GAME_OVER)
        {
            time_now_ms = pulse_get_millis();
            if (time_now_ms - time_last_box_drawn_ms >= 500) {
                cancel_sleep();
                pulse_blank_canvas();
                current_screen = SCREEN_GAMEPLAY;
            }
        }
        else if (current_screen == SCREEN_GAMEPLAY)
            press = false;
    }
    else
        button_held = false;
}
Beispiel #4
0
void main_app_handle_button_up()
{
	if (!button_held)
	{
		pulse_cancel_timer(&button_timer_id);
		
		if (current_screen == SCREEN_CLOCK)
		{
			cancel_sleep();
			pulse_blank_canvas();
			reset_game();
			current_screen = SCREEN_GAME_OVER;
			printf("\n\n\n\n\n Click to start");
			prepare_to_sleep();				
		}
		else if (current_screen == SCREEN_GAME_OVER)
		{
			time_now_ms = pulse_get_millis();
		    // Check if it's been at least 500 ms since the game ended to prevent accidental clicks
		    if (time_now_ms - time_last_box_drawn_ms > 500) 
		    {
				cancel_sleep();
				pulse_blank_canvas();
				current_screen = SCREEN_GAMEPLAY;
			}
		}
		else if (current_screen == SCREEN_GAMEPLAY)
			press = false;
	}
	else
		button_held = false;
}
void mode_displaysleep_tick_tock() {
  multi_debug("mode_displaysleep_tick_tock\n");

  pulse_cancel_timer(&modeDisplaysleepingTimerID); 
  assert(modeDisplaysleepingTimerID == -1);

  modeDisplaysleepingTimerID = pulse_register_timer(10000, // slow
                   &mode_displaysleep_tick_tock, 0); // pulse
  assert(modeDisplaysleepingTimerID != -1);

  mode_displaysleep_draw_digit(0, multiTimeNow.tm_hour / 10); // Digit *?:??
  mode_displaysleep_draw_digit(1, multiTimeNow.tm_hour % 10); // Digit ?*:??
  // position 2 has the colon!
  mode_displaysleep_draw_digit(3, multiTimeNow.tm_min / 10);  // Digit ??:*?
  mode_displaysleep_draw_digit(4, multiTimeNow.tm_min % 10);  // Digit ??:?*
}
Beispiel #6
0
void main_app_handle_button_up()
{
    if(current_screen == SCREEN_NOTIFICATION_LIST)
    {
        // Button was not a hold
        pulse_cancel_timer(&button_timer_id);

        // Select next message in list
        notification_selected++;
        if(notification_selected == notification_list_size)
        {
            notification_selected = 0;
        }

        // Update screen
        latest_notifications_screen(notification_selected);
    }
}
// It's time to sleep!
void mode_displaysleep_power_down() {
  multi_debug("mode_displaysleep_power_down - time to sleep\n");
  // Immediately stop the watch doing anything else
  multi_external_sleep_init();

  pulse_cancel_timer(&modeDisplaysleepPowerDownTimerID); // pulse

  // Clear the display
  pulse_blank_canvas();

  pulse_oled_set_brightness(0); // dark

  // Clear our positions
  for (int i=0; i<MODE_DISPLAYSLEEP_DIGIT_POS_SIZE; i++) {
    modeDisplaysleepCurrentlyDisplayed[i] = MODE_DISPLAYSLEEP_NO_DIGIT;
  }

  // Display the colon
  mode_displaysleep_draw_digit(2, 10); // Digit ??*?? <-- colon

  // Now start the proper loop
  mode_displaysleep_tick_tock(); 
}
Beispiel #8
0
// Cancel call to put processor to sleep
void cancel_sleep()
{
    pulse_cancel_timer(&sleep_timer_id);
}
Beispiel #9
0
// Will put processor to sleep in predetermined number of ms
void prepare_to_sleep()
{
    pulse_cancel_timer(&sleep_timer_id);
    sleep_timer_id = pulse_register_timer(TIME_BEFORE_SLEEP, &pulse_update_power_down_timer, 0);
}