コード例 #1
0
ファイル: main.c プロジェクト: FerhatAkgun/OpenHR20
/*!
 *******************************************************************************
 * Load default values from eeprom
 *
 * \todo EEPROM management, until now values are fix
 ******************************************************************************/
void load_defauls(void)
{
    uint8_t i;

    //! Set Time and date
    RTC_SetDay   (BOOT_DD);
    RTC_SetMonth (BOOT_MM);
    RTC_SetYear  (BOOT_YY);
    RTC_SetHour  (BOOT_hh);
    RTC_SetMinute(BOOT_mm);
    RTC_SetSecond(0);

    //! m_reftemps (high and low)
    m_reftemp_mem[0] = DEG_2_UINT8 (BOOT_TEMP_H);
    m_reftemp_mem[1] = DEG_2_UINT8 (BOOT_TEMP_L);

    //! DOW times
    for (i=0; i<7; i++){
        RTC_DowTimerSet(i, 0, BOOT_ON1);
        RTC_DowTimerSet(i, 1, BOOT_OFF1);
        RTC_DowTimerSet(i, 2, BOOT_ON2);
        RTC_DowTimerSet(i, 3, BOOT_OFF2);
    }

    //! motor speed
    m_speed = full;

    //! initial keystates
    m_key_action = false;
    m_state_keys = 0;
    m_state_keys_prev = 0;
    m_state_wheel = 0;
    m_state_wheel_prev = 0;

    //! serial number        
    serialNumber = 0; // Zero = Not set !

}
コード例 #2
0
ファイル: menu.c プロジェクト: robots/openhr20
/*!
 *******************************************************************************
 * \brief menu Controller
 * 
 * \returns true for controler restart  
 ******************************************************************************/
bool menu_controller(bool new_state) {
    int8_t wheel = wheel_proccess(); //signed number
	bool ret = false;
    switch (menu_state) {
    case menu_startup:
        if (new_state) {
            menu_auto_update_timeout=2;
        }
        if (menu_auto_update_timeout==0) {
            menu_state = menu_version;
            ret=true;
        }
        break;
    case menu_version:
        if (new_state) {
            menu_auto_update_timeout=2;
        }
        if (menu_auto_update_timeout==0) {
            #if (DEBUG_SKIP_DATETIME_SETTING_AFTER_RESET) || (REMOTE_SETTING_ONLY)
                menu_state = menu_home;
            #else
                menu_state = menu_set_year;
            #endif
            ret=true;
        }
        break;
#if (! REMOTE_SETTING_ONLY)
    case menu_set_year:
        if (wheel != 0) RTC_SetYear(RTC_GetYearYY()+wheel);
        if ( kb_events & KB_EVENT_PROG) {
            menu_state = menu_set_month;
            CTL_update_temp_auto();
            ret=true;
        }
        break;
    case menu_set_month:
        if (wheel != 0) RTC_SetMonth(RTC_GetMonth()+wheel);
        if ( kb_events & KB_EVENT_PROG ) {
            menu_state = menu_set_day;
            CTL_update_temp_auto();
            ret=true;
        }
        break;
    case menu_set_day:
        if (wheel != 0) RTC_SetDay(RTC_GetDay()+wheel);
        if ( kb_events & KB_EVENT_PROG ) {
            menu_state = menu_set_hour;
            CTL_update_temp_auto();
            ret=true;
        }
        break;
    case menu_set_hour:
        if (wheel != 0) RTC_SetHour(RTC_GetHour()+wheel);
        if ( kb_events & KB_EVENT_PROG ) {
            menu_state = menu_set_minute;
            CTL_update_temp_auto();
            ret=true;
        }
        break;
    case menu_set_minute:
        if (wheel != 0) {
            RTC_SetMinute(RTC_GetMinute()+wheel);
            RTC_SetSecond(0);
        }
        if ( kb_events & KB_EVENT_PROG ) {
            menu_state = menu_home;
            CTL_update_temp_auto();
            ret=true;
        }
        break;
#endif
    case menu_home_no_alter: // same as home screen, but without alternate contend
    case menu_home:         // home screen
    case menu_home2:        // alternate version, real temperature
    case menu_home3:        // alternate version, valve pos
    case menu_home4:        // alternate version, time    
#if MENU_SHOW_BATTERY
    case menu_home5:        // alternate version, battery    
#endif
        if ( kb_events & KB_EVENT_C ) {
            menu_state++;       // go to next alternate home screen
#if MENU_SHOW_BATTERY
            if (menu_state > menu_home5) menu_state=menu_home;
#else
            if (menu_state > menu_home4) menu_state=menu_home;
#endif
            ret=true; 
        } else {
            if (menu_locked) {
                if ( kb_events & (
                        KB_EVENT_WHEEL_PLUS  | KB_EVENT_WHEEL_MINUS | KB_EVENT_PROG
                        | KB_EVENT_AUTO | KB_EVENT_PROG_REWOKE | KB_EVENT_C_REWOKE | KB_EVENT_AUTO_REWOKE
                        | KB_EVENT_PROG_LONG | KB_EVENT_C_LONG | KB_EVENT_AUTO_LONG )) {
                    menu_auto_update_timeout=LONG_PRESS_THLD+1;
                    menu_state=menu_lock;
                    ret=true;
                    }
            } else { // not locked
                if ((menu_state == menu_home) || (menu_state == menu_home_no_alter)) {
                    if (wheel != 0) {
                        CTL_temp_change_inc(wheel);
                        menu_state = menu_home_no_alter;
						ret=true; 
                    } 			 
                    if ( kb_events & KB_EVENT_AUTO ) {
                        CTL_change_mode(CTL_CHANGE_MODE); // change mode
                        menu_state=menu_home_no_alter;
						ret=true; 
                    } else if ( kb_events & KB_EVENT_AUTO_REWOKE ) {
                        CTL_change_mode(CTL_CHANGE_MODE_REWOKE); // change mode
                        menu_state=menu_home_no_alter;
						ret=true; 
                    }
                } else {
                    if ( kb_events & (
                        KB_EVENT_WHEEL_PLUS  | KB_EVENT_WHEEL_MINUS | KB_EVENT_PROG
                        | KB_EVENT_AUTO | KB_EVENT_PROG_REWOKE | KB_EVENT_C_REWOKE | KB_EVENT_AUTO_REWOKE
                        | KB_EVENT_PROG_LONG | KB_EVENT_C_LONG | KB_EVENT_AUTO_LONG )) {
                            menu_state = menu_home;
							ret = true;
                    }
                }
                // TODO ....  
            }
        } 
        break;
#if (! REMOTE_SETTING_ONLY)
    case menu_set_timmer_dow_start:
        if (new_state) menu_set_dow=((config.timer_mode==1)?RTC_GetDayOfWeek():0);
        menu_state = menu_set_timmer_dow;
        // do not use break here
    case menu_set_timmer_dow:
        if (wheel != 0) menu_set_dow=(menu_set_dow+wheel+8)%8;
        if ( kb_events & KB_EVENT_PROG ) {
            menu_state=menu_set_timmer;
            menu_set_slot=0;
            config.timer_mode = (menu_set_dow>0);
            eeprom_config_save((uint16_t)(&config.timer_mode)-(uint16_t)(&config)); // save value to eeprom
                // update hourbar
            menu_update_hourbar((config.timer_mode==1)?RTC_GetDayOfWeek():0);
            ret=true; 
        } else if ( kb_events & KB_EVENT_AUTO ) { // exit without save
            menu_state=menu_home;
            ret=true; 
        }
        break;        
    case menu_set_timmer:
        if (new_state) {
            menu_set_time= RTC_DowTimerGet(menu_set_dow, menu_set_slot, &menu_set_mode);
            if (menu_set_time>24*60) menu_set_time=24*60;
        }
        if (wheel != 0) {
            menu_set_time=((menu_set_time/10+(24*6+1)+wheel)%(24*6+1))*10;
        }
        if ( kb_events & KB_EVENT_C ) {
            menu_set_mode=(menu_set_mode+5)%4;
        } else if ( kb_events & KB_EVENT_PROG ) {
            RTC_DowTimerSet(menu_set_dow, menu_set_slot, menu_set_time, menu_set_mode);
            if (++menu_set_slot>=RTC_TIMERS_PER_DOW) {
                if (menu_set_dow!=0) menu_set_dow=menu_set_dow%7+1; 
                menu_state=menu_set_timmer_dow;
            }
            CTL_update_temp_auto();
            menu_update_hourbar((config.timer_mode==1)?RTC_GetDayOfWeek():0);
            ret=true; 
        } else if ( kb_events & KB_EVENT_AUTO ) { // exit without save
            menu_state=menu_home;
            ret=true; 
        }
        break;
#endif
#if (! REMOTE_SETTING_ONLY)
    case menu_preset_temp0:
    case menu_preset_temp1:
    case menu_preset_temp2:
    case menu_preset_temp3:
        if (new_state) menu_set_temp=temperature_table[menu_state-menu_preset_temp0];
        if (wheel != 0) {
            menu_set_temp+=wheel;
            if (menu_set_temp > TEMP_MAX+1) menu_set_temp = TEMP_MAX+1;
            if (menu_set_temp < TEMP_MIN-1) menu_set_temp = TEMP_MIN-1;
        }
        if ( kb_events & KB_EVENT_PROG ) {
            temperature_table[menu_state-menu_preset_temp0]=menu_set_temp;
            eeprom_config_save(menu_state+((temperature_table-config_raw)-menu_preset_temp0));
            menu_state++; // menu_preset_temp3+1 == menu_home
            CTL_update_temp_auto();
            ret=true; 
        } else if ( kb_events & KB_EVENT_AUTO ) { // exit without save
            menu_state=menu_home;
            ret=true; 
        }
        break;
#endif
    default:
    case menu_lock:        // "bloc" message
        if (menu_auto_update_timeout==0) { menu_state=menu_home; ret=true; } 
        break;        
    case menu_service1:     // service menu        
    case menu_service2:        
        if (kb_events & KB_EVENT_AUTO) { 
            menu_state=menu_home; 
            ret=true;
        } else if (kb_events & KB_EVENT_C) { 
            menu_state=menu_service_watch; 
            ret=true;
        } else if (kb_events & KB_EVENT_PROG) {
            if (menu_state == menu_service2) {
                eeprom_config_save(service_idx); // save current value
                menu_state = menu_service1;
            } else {
                menu_state = menu_service2;
            }
        } else {
            if (menu_state == menu_service1) {
                // change index
                service_idx = (service_idx+wheel+CONFIG_RAW_SIZE)%CONFIG_RAW_SIZE;
            } else {
                // change value in RAM, to save press PROG
                int16_t min = (int16_t)config_min(service_idx);
                int16_t max_min_1 = (int16_t)(config_max(service_idx))-min+1;
                config_raw[service_idx] = (uint8_t) (
                        ((int16_t)(config_raw[service_idx])+(int16_t)wheel-min+max_min_1)%max_min_1+min);
                if (service_idx==0) LCD_Init();
            }
        }
        break;        
    case menu_service_watch:
        if (kb_events & KB_EVENT_AUTO) { 
            menu_state=menu_home; 
            ret=true;
        } else if (kb_events & KB_EVENT_C) { 
            menu_state=menu_service1; 
            ret=true;
        } else {
            service_watch_n=(service_watch_n+wheel+WATCH_N)%WATCH_N;
            if (wheel != 0) ret=true;
        }
        break;
    }
    if (events_common()) ret=true;
    if (ret && (service_idx<CONFIG_RAW_SIZE)) {
        // back config to default value
        config_raw[service_idx] = config_value(service_idx);
        service_idx = CONFIG_RAW_SIZE;
    }
    kb_events = 0; // clear unused keys
    return ret;
} 
コード例 #3
0
ファイル: rtc.c プロジェクト: apaikan/myCub
int main(void)
{
	RTC_STRUCT stClock;
	RTC_Init(&stClock);
	printf("---Default Time---\n");
	RTC_PrintTime(&stClock);
	
	// Test boundary conditions (using leap years)
	// 1) Normal, non leap-year
	printf("---No leap year, Feb-March rollover ---\n");
	RTC_SetMonth(&stClock, MONTH_FEBRUARY);
	RTC_SetDay(&stClock, 28);
	RTC_SetHour(&stClock, 23);
	RTC_SetMinute(&stClock, 59);
	RTC_SetSecond(&stClock, 59);
	RTC_PrintTime(&stClock);
	
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
	
	// 2) Leap year, 4/year modulo
	printf("---Leap year, Feb 29 test (4 yr)---\n");
	RTC_SetMonth(&stClock, MONTH_FEBRUARY);
	RTC_SetYear(&stClock, 2008);
	RTC_SetDay(&stClock, 28);
	RTC_SetHour(&stClock, 23);
	RTC_SetMinute(&stClock, 59);
	RTC_SetSecond(&stClock, 59);
	RTC_PrintTime(&stClock);
	
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
	
	// Verify leap-year month rollover
	printf("---leap year, month rollover ---\n");
	RTC_SetHour(&stClock, 23);
	RTC_SetMinute(&stClock, 59);
	RTC_SetSecond(&stClock, 59);
	RTC_PrintTime(&stClock);
	
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
	
	// 3) No leap year, 100/year modulo
	printf("---No Leap year, rollover test (100 yr)---\n");
	RTC_SetMonth(&stClock, MONTH_FEBRUARY);
	RTC_SetYear(&stClock, 2100);
	RTC_SetDay(&stClock, 28);
	RTC_SetHour(&stClock, 23);
	RTC_SetMinute(&stClock, 59);
	RTC_SetSecond(&stClock, 59);
	RTC_PrintTime(&stClock);
	
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
		
	// 4) Leap year, 400/year modulo
	printf("---Leap year, Feb 29 test (400 yr)---\n");
	RTC_SetMonth(&stClock, MONTH_FEBRUARY);
	RTC_SetYear(&stClock, 2000);
	RTC_SetDay(&stClock, 28);
	RTC_SetHour(&stClock, 23);
	RTC_SetMinute(&stClock, 59);
	RTC_SetSecond(&stClock, 59);
	RTC_PrintTime(&stClock);
	
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
	
	// 4) End of year test
	printf("---End of year---\n");
	RTC_SetMonth(&stClock, MONTH_DECEMBER);
	RTC_SetYear(&stClock, 2009);
	RTC_SetDay(&stClock, 31);
	RTC_SetHour(&stClock, 23);
	RTC_SetMinute(&stClock, 59);
	RTC_SetSecond(&stClock, 59);
	RTC_PrintTime(&stClock);
	
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
	RTC_AddTime(&stClock, 750);
	RTC_PrintTime(&stClock);
		
	return 0;
}