예제 #1
0
void Clock::sleep()
{
  if(!sleepOk) sleep_time = 0; else if(!sleepWasOk) awake();
  sleepWasOk = sleepOk;
  if(sleepOk && sleep_time >= (uint16_t) conf.sysOffTime * 10)
  {
//    lcd.off();
/*    attachInterrupt(1,wakeupFunction,LOW);
    sleep_mode();
    detachInterrupt(1);*/
    hardware_off();
    awake();
    wasSleeping = 1;
  }
  else if(backlightVal == 0 && light_time >= (uint16_t) conf.lcdBacklightTime * 10)
  {
    backlightVal = lcd.getBacklight();
    lcd.backlight(0);
  }
  if(hardware_flashlightIsOn())
  {
    if(flashlight_time >= (uint16_t) conf.flashlightOffTime * 10)
    {
      hardware_flashlight(0);
    }
  }
  else
  {
    flashlight_time = 0;
  }
}
예제 #2
0
volatile void Button::poll()
{
    uint8_t i;
    char p;

    for(i = 0; i < NUM_KEYS; i++)
    {
        p = pgm_read_byte(&button_pins[i]);
        
        if(i < 2) 
            p = (getBit(p, FB_PIN) == LOW);
        else 
            p = (getBit(p, B_PIN) == LOW);
        
        if(p)  // key is pressed
        {
            if(button_count[i] < DEBOUNCE_REPEAT_DELAY)
            {
                button_count[i]++;
                
                if(button_count[i] > DEBOUNCE_ON)
                {
                    if(button_status[i] == 0)
                    {
                        button_flag[i] = 1;
                        button_status[i] = 1; //button debounced to 'pressed' status
                        clock.awake(); // keep from sleeping since a button was pressed
                    }

                }
            }
            else
            {
                if(i + 1 == UP_KEY || i + 1 == DOWN_KEY || (verticalRepeat && (i + 1 == LEFT_KEY || i + 1 == RIGHT_KEY)))
                {
                    button_flag[i] = 1;
                    button_status[i] = 1; //button debounced to 'pressed' status
                    button_count[i] = DEBOUNCE_REPEAT_DELAY - DEBOUNCE_REPEAT_SPEED;
                }
                else if(i + 1 == FL_KEY)
                {
                    off_count++;
                    if(off_count > POWER_OFF_TIME)
                    {
                        menu.message(TEXT("Power Off"));
                        menu.task();
                        cli();
                        while(getBit(p, FB_PIN) == LOW) wdt_reset();
                        hardware_off();
                    }
                }
            }

        } 
        else // not pressed
        {
            if(i + 1 == FL_KEY) off_count = 0;
            if(button_count[i] > 0)
            {
                //button_flag[i] = 0;
                if(button_count[i] > DEBOUNCE_MAX) button_count[i] = DEBOUNCE_MAX;
                button_count[i]--;
                
                if(button_count[i] < DEBOUNCE_OFF)
                {
                    button_status[i] = 0;   //button debounced to 'released' status
                }
            }
        }
    }
}