static void ShowNumberState_10Hz( void ) { --mode_showNumberState.delay100ms; if( mode_showNumberState.delay100ms == 0 ){ quitMyself(MS_showNumber, NULL); } }
static uint8_t SetOnOffTimeState_handleIr( uint8_t cmdCode ) { if( UI_AUTOOFFTIMES_COUNT == mode_setOnOffTimeState.currentTimeToSet) // only after all times where set { if( (cmdCode == UI_DOWN) || (cmdCode == UI_UP) ) { DisplayState dispData; g_params->useAutoOffAnimation ^= 1; dispData = display_getNumberDisplayState(g_params->useAutoOffAnimation+1); display_setDisplayState(dispData, dispData); if(g_params->useAutoOffAnimation) { g_animPreview = 1; } else { g_animPreview = 0; } } if( cmdCode == UI_SET_ONOFF_TIMES ) { mode_setOnOffTimeState.prohibitLeave = FALSE; g_animPreview = 0; quitMyself( MS_setOnOffTime, NULL); } } return TRUE; }
static void TrainIrState_1Hz( void ) { if( mode_trainIrState.seconds != UINT8_MAX){ ++mode_trainIrState.seconds; if( mode_trainIrState.seconds == USER_STARTUP_WAIT_4_IR_TRAIN_s ){ log_irTrain("leave IR-wait4train\n"); quitMyself(MS_irTrain,NULL); } } }
static void SetSystemTimeState_substateFinished (e_MenuStates finishedState, const void* result) { if( finishedState == MS_enterTime) { const DATETIME* time = result; i2c_rtc_write( time ); g_dateTime = *time; mode_setSystemTimeState.prohibitLeave = FALSE; quitMyself( MS_setSystemTime, NULL); } }
static uint8_t EnterTimeState_handleIr( uint8_t cmdCode ) { uint8_t caller = g_stateStack[ g_currentIdxs[MS_enterTime] - 1]; if( ( (MS_setSystemTime == caller) && (UI_SET_TIME == cmdCode)) || ( (MS_setOnOffTime == caller) && (UI_SET_ONOFF_TIMES == cmdCode))) { if( ETS_hour == mode_enterTimeState.curSubState ){ log_time("TM\n"); mode_enterTimeState.curSubState = ETS_minutes; }else if( ETS_minutes == mode_enterTimeState.curSubState){ log_time("TS\n"); mode_enterTimeState.time.ss = 0; mode_enterTimeState.prohibitLeave = FALSE; pwm_release_brightness(); quitMyself(MS_enterTime, &(mode_enterTimeState.time)); return TRUE; } }else if( UI_UP == cmdCode || UI_DOWN == cmdCode) { log_state("CHS\n"); int8_t dir = UI_UP == cmdCode?1:-1; if( ETS_hour == mode_enterTimeState.curSubState ) { incDecRangeOverflow(&(mode_enterTimeState.time.hh), dir, 23); if( mode_enterTimeState.time.hh >=USER_ENTERTIME_DAY_NIGHT_CHANGE_HOUR && mode_enterTimeState.time.hh < USER_ENTERTIME_DAY_NIGHT_CHANGE_HOUR+12 ) { pwm_lock_brightness_val(USER_ENTERTIME_DAY_BRIGHTNESS); }else{ pwm_lock_brightness_val(USER_ENTERTIME_NIGHT_BRIGHTNESS); } }else if( ETS_minutes == mode_enterTimeState.curSubState){ if( MS_setOnOffTime == caller ){ dir *= USER_ENTER_ONOFF_TIME_STEP; } incDecRangeOverflow(&(mode_enterTimeState.time.mm), dir, 59); } }else{ //return FALSE; } dispInternalTime(&mode_enterTimeState.time, ((ETS_hour == mode_enterTimeState.curSubState) ? display_getHoursMask() : display_getMinuteMask() ) | display_getTimeSetIndicatorMask()) ; return TRUE; }
static uint8_t TrainIrState_handleIR( const IRMP_DATA* i_irCode ) { DisplayState disp; if( mode_trainIrState.curKey > 0){ // save key if( g_params->irAddress != i_irCode->address ){ log_irTrain("invalid ir-address\n"); }else{ g_params->irCommandCodes[mode_trainIrState.curKey-1] = i_irCode->command; if( mode_trainIrState.curKey == UI_COMMAND_COUNT ){ /* finished */ log_irTrain("Ir train finished\n"); wcEeprom_writeback( g_params, sizeof(*g_params) ); /* save all */ quitMyself(MS_irTrain,NULL); return TRUE; } ++mode_trainIrState.curKey; } }else{ mode_trainIrState.seconds = UINT8_MAX; g_params->irAddress = i_irCode->address; ++mode_trainIrState.curKey; } # if USER_LOG_IR_TRAIN { char buff[5]; uart_puts_P("Ir train. Enter cmd #"); byteToStrLessHundred(mode_trainIrState.curKey, buff); uart_puts(buff); uart_putc('\n'); } # endif disp = display_getNumberDisplayState(mode_trainIrState.curKey) | display_getIndicatorMask(); display_setDisplayState( disp, disp ); return TRUE; }
/** * @brief Handles the given user command * * This handles the given user command (user_command_t) either by processing * it directly, or by passing it over to the actual handler using * UserState_HandleUserCommand(). * * g_eepromSaveDelay and g_checkIfAutoOffDelay get reset every time this * function is called to make sure the appropriate functionality works as * intended. * * @param user_command The user command that should be handled * * @see UserState_HandleUserCommand() * @see g_eepromSaveDelay * @see g_checkIfAutoOffDelay */ void handle_user_command(user_command_t user_command) { if (UC_ONOFF == user_command) { log_state("OF\n"); if (user_power_state < UPS_AUTO_OFF) { user_power_state = UPS_MANUAL_OFF; pwm_off(); } else { if (user_power_state == UPS_MANUAL_OFF) { user_power_state = UPS_NORMAL_ON; } else { user_power_state = UPS_OVERRIDE_ON; } pwm_on(); user_setNewTime(NULL); } preferences_save(); } else { int8_t i; bool handled = false; for (i = g_topOfStack - 1; i >= 0 && !handled; --i) { handled |= UserState_HandleUserCommand(g_stateStack[i], user_command); } if (!handled) { if (UC_BRIGHTNESS_UP == user_command) { log_state("B+\n"); pwm_increase_brightness(); } else if (UC_BRIGHTNESS_DOWN == user_command) { log_state("B-\n"); pwm_decrease_brightness(); } else if (UC_NORMAL_MODE == user_command) { addSubState(-1, MS_normalMode, (void*)1); } else if (UC_SET_TIME == user_command) { addState(MS_setSystemTime, NULL); } else if (UC_SET_ONOFF_TIMES == user_command) { addState(MS_setOnOffTime, NULL); } else if (UC_DEMO_MODE == user_command) { menu_state_t curTop = user_get_current_menu_state(); log_state("BS\n"); if (MS_demoMode == curTop) { quitMyself(MS_demoMode, NULL); } else { addState(MS_demoMode, NULL); } } else if (UC_CALIB_BRIGHTNESS == user_command) { pwm_modifyLdrBrightness2pwmStep(); // Indicate the change to user if (pwm_is_enabled()) { pwm_off(); _delay_ms(USER_VISUAL_INDICATION_TOGGLE_MS); pwm_on(); } } else if (UC_PULSE_MODE == user_command) { menu_state_t curTop = user_get_current_menu_state(); log_state("PLS\n"); if (MS_pulse == curTop) { leaveSubState(g_topOfStack - 1); } else { if ((MS_normalMode == curTop) #if (ENABLE_RGB_SUPPORT == 1) || (MS_hueMode == curTop) #endif ) { addState(MS_pulse, NULL); } } DISPLAY_SPECIAL_USER_COMMANDS_HANDLER #if (ENABLE_RGB_SUPPORT == 1) } else if (UC_HUE_MODE == user_command) { log_state("HM"); addSubState(-1, MS_hueMode, NULL); #endif #if (ENABLE_DCF_SUPPORT == 1) } else if (UC_DCF_GET_TIME == user_command) { log_state("DCF\n"); dcf77_enable(); #endif #if (ENABLE_AMBILIGHT_SUPPORT == 1) } else if (UC_AMBILIGHT == user_command) { log_state("AL\n"); PIN(USER_AMBILIGHT) |= _BV(BIT(USER_AMBILIGHT)); #endif #if (ENABLE_BLUETOOTH_SUPPORT == 1) } else if (UC_BLUETOOTH == user_command) { log_state("BT\n"); PIN(USER_BLUETOOTH) |= _BV(BIT(USER_BLUETOOTH)); #endif #if (ENABLE_AUXPOWER_SUPPORT == 1) } else if (UC_AUXPOWER == user_command) { log_state("AUX\n"); PIN(USER_AUXPOWER) |= _BV(BIT(USER_AUXPOWER)); #endif } else { return; } }