Ejemplo n.º 1
0
void poll_clock(void)
{
  if (mode == PLAY_MODE)
  {
    uint8_t id;
    uint8_t force_update;
    uint8_t num_ids;
    if (is_second_control_fitted())
    {
      num_ids = 4;
    }
    else
    {
      num_ids = 2;
      if (countdown_is_running(COUNTDOWN_3) || countdown_is_running(COUNTDOWN_4))
      {
        stop_countdown(COUNTDOWN_3);
        stop_countdown(COUNTDOWN_4);
        update_display = 1;
      }
    }

    id = 0;
    while (id < num_ids)
    {
      ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
      {
        if (countdown_has_expired(id))
        {
          mode = WON_MODE;
          for (id = 0; id < NUM_COUNTDOWNS; id++)
          {
            stop_countdown(id);
            turnled_off(id);
          }
          update_display = 1;
          play(tada);
        }
      }
      id++;
    } /* end for all countdowns */

    ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
    {
      force_update = update_display;
      update_display = 0;
    }
    for (id = 0; id < NUM_COUNTDOWNS; id++)
    {
      if (force_update || prev_second[id] != Countdown[id].seconds)
      {
        update_play(id);
        prev_second[id] = Countdown[id].seconds;
      }
    } /* end for all countdowns */
  } /* end if play mode */
Ejemplo n.º 2
0
// *************************************************************************************************
// @fn          wakeup_event
// @brief       Process external / internal wakeup events.
// @param       none
// @return      none
// *************************************************************************************************
void wakeup_event(void)
{
	// Enable idle timeout
	sys.flag.idle_timeout_enabled = 1;

	// If buttons are locked, only display "buttons are locked" message
	if (button.all_flags && sys.flag.lock_buttons)
	{
		// Show "buttons are locked" message synchronously with next second tick
		if (!(BUTTON_NUM_IS_PRESSED && BUTTON_DOWN_IS_PRESSED))
		{
			message.flag.prepare     = 1;
			message.flag.type_locked = 1;
		}
		
		// Clear buttons
		button.all_flags = 0;	
	}
	// Process long button press event (while button is held)
	else if (button.flag.up_long)
	{
		// Clear button event
		button.flag.up_long = 0;

		// Call sub menu function
		//ptrMenu_L1->mx_function(LINE1);

		// Set display update flag
		//display.flag.full_update = 1;
	}
	else if (button.flag.down_long)
	{
		// Clear button event
		button.flag.down_long = 0;

		// Call sub menu function
		//ptrMenu_L2->mx_function(LINE2);

		// Stop Countdown and Countup
		stop_countdown();
		stop_countup();

		// Reset Countdown and Countup
		reset_countdown();
		reset_countup();

		// Set display update flag
		display.flag.full_update = 1;	
	}
	// Process single button press event (after button was released)
	else if (button.all_flags)
	{
		// M1 button event ---------------------------------------------------------------------
		// (Short) Advance to next menu item
		if(button.flag.star) 
		{
			/*
			// SW1 IS NOW LOCATED IN PORTS.C FOR IMPROVED RESPONSE
			*/

			// Clean up display before activating next menu item 
			//fptr_lcd_function_line1(LINE1, DISPLAY_LINE_CLEAR);
			
			// Go to next menu entry
			//ptrMenu_L1 = ptrMenu_L1->next;
				
			// Assign new display function
			//fptr_lcd_function_line1 = ptrMenu_L1->display_function;

			// Set Line1 display update flag
			//display.flag.line1_full_update = 1;

			// Clear button flag
			button.flag.star = 0;
		}
		// NUM button event ---------------------------------------------------------------------
		// (Short) Advance to next menu item
		else if(button.flag.num || button.flag.num_long)
		{
			// SW2
			// Enable buzzer
			sCountdown.buzzer = 1;

			// Clean up display before activating next menu item 
			//fptr_lcd_function_line2(LINE2, DISPLAY_LINE_CLEAR);

			// Go to next menu entry
			//ptrMenu_L2 = ptrMenu_L2->next;

			// Assign new display function
			//fptr_lcd_function_line2 = ptrMenu_L2->display_function;

			// Set Line2 display update flag
			//display.flag.line2_full_update = 1;

			// Clear button flag
			button.flag.num_long = 0;
			button.flag.num = 0;
		}	
		// UP button event ---------------------------------------------------------------------
		// Activate user function for Line1 menu item
		else if(button.flag.up) 	
		{
			// Call direct function
			//ptrMenu_L1->sx_function(LINE1);

			// UP BUTTON
			// Start / pause / reset Countdown and Countup
			if (sCountdown.mode == COUNTDOWN_MODE_OFF || sCountdown.mode == COUNTDOWN_MODE_RESET)
			{
				if (sCountdown.minute == 0 && sCountdown.second == 0 || sCountup.minute == 10 && sCountup.second == 0)
				{
					reset_countdown();
					reset_countup();
					display.flag.full_update = 1;
				}
				else {
					// Start Countdown and Countup
					start_countdown();
					start_countup();
				}
			}
			else
			{
				// Stop Countdown and Countup
				stop_countdown();
				//stop_countup();
			}


			// Set Line1 display update flag
			//display.flag.line1_full_update = 1;
	
			// Clear button flag	
			button.flag.up = 0;
		}			
		// DOWN button event ---------------------------------------------------------------------
		// Activate user function for Line2 menu item
		else if(button.flag.down) 	
		{
			// Call direct function
			//ptrMenu_L2->sx_function(LINE2);

			// DOWN BUTTON
			// Enable power saving using drawFlag
			sCountdown.drawFlag = 1;

			// When in COUNTDOWN_MODE_RESET state, allow alteration of Countdown start point
			if (sCountdown.mode == COUNTDOWN_MODE_RESET)
			{
				// Decrement minutes
				sCountdown.minute--;

				// Stop decrements at 0 or below
				if (sCountdown.minute == 0)
				{
					sCountdown.minute = 10;
				}

				sCountdown.drawFlag = 2;
				display.flag.update_countdown = 1;
			}

			// Set Line1 display update flag
			//display.flag.line2_full_update = 1;
	
			// Clear button flag	
			button.flag.down = 0;
		}			
	}
	
	// Process internal events
	if (sys.all_flags)
	{
		// Idle timeout ---------------------------------------------------------------------
		if (sys.flag.idle_timeout)
		{
			// Clear timeout flag	
			sys.flag.idle_timeout = 0;	
			
			// Clear display
			clear_display();	

			// Set display update flags
			display.flag.full_update = 1;
		}
	}
	
	// Disable idle timeout
	sys.flag.idle_timeout_enabled = 0;
}