/** * Initializes all of the device systems. If the clear button * is held down at the end of the initialization then defaults * are restored to all EEPROM settings. * * @return Returns 'OK' if previous data was found by data_Init(), 'ERROR' otherwise. */ status init(void) { Time time; int i; cli(); user_Init(); timer_Wait_MS(1000); // The serial port is now connected to the GSM modem, not the FTDI chip... // coms_Init(); gsm_modem_Init(); usart_Print_Num(SERIAL, UBRR1L); sensor_Init(true); data_Init(); if (user_Get_Button(BUTTON_CLEAR)) { for (i = 0; i < 50; i++) { timer_Wait_MS(50); user_Toggle_LED(LED_CLEAR); user_Toggle_LED(LED_STOP); user_Toggle_LED(LED_START); user_Toggle_LED(LED_POWER); } adx_Calibrate(); rtc_Init(); data_Reset_EEPROM(); wdt_enable(WDTO_120MS); } // Hard-coded time and date for now since we don't have // an application to set the time with... // We should really try to get this from the GSM modem time.hours = 12; // set to noon time.minutes = 0; time.seconds = 0; time.month = 2; // March time.dow = 5; // Thursday time.year = 12; // 2012 time.date = 1; // The 1st rtc_Set_Time(&time); sei(); return OK; }
/** * Initializes all of the device systems. If the clear button * is held down at the end of the initialization then defaults * are restored to all EEPROM settings. * * @return Returns 'OK' if previous data was found by data_Init(), 'ERROR' otherwise. */ status init(void) { int i; cli(); user_Init(); timer_Wait_MS(1000); coms_Init(); sensor_Init(true); data_Init(); if (user_Get_Button(BUTTON_CLEAR)) { for (i = 0; i < 50; i++) { timer_Wait_MS(50); user_Toggle_LED(LED_CLEAR); user_Toggle_LED(LED_STOP); user_Toggle_LED(LED_START); user_Toggle_LED(LED_POWER); } adx_Calibrate(); rtc_Init(); data_Reset_EEPROM(); wdt_enable(WDTO_120MS); } sei(); return OK; }
/** * Handles all actions related to button presses during operation, * including LED changes. Any change to runData to relayed through * the given pointer, such as the recording state. Also handles the * clear button implementation. * * @param runData Address of the runData structure. */ void user_Handle_Buttons(RunData *runData) { static unsigned int buttonTimer[3] = {0, 0, 0}; static unsigned int buttonLastTime[3] = {0, 0, 0}; int i; if (user_Get_Button(BUTTON_CLEAR)) { user_Set_LED(LED_CLEAR, ON); runData->liveData = false; if (timer_Job_Ready4(&buttonTimer[BUTTON_CLEAR - 1], 3000, &buttonLastTime[BUTTON_CLEAR - 1], false)) { runData->record = false; user_Set_LED(LED_STOP, ON); user_Set_LED(LED_START, OFF); data_Clear(); for (i = 0; i < 50; i++) { timer_Wait_MS(50); user_Toggle_LED(LED_CLEAR); } } } else { if ((runData->record || runData->liveData) && (runData->recordTimer > runData->recordPeriod - 5)) { user_Set_LED(BUTTON_CLEAR, ON); } else { user_Set_LED(BUTTON_CLEAR, OFF); } buttonTimer[BUTTON_CLEAR - 1] = 0; } if (user_Get_Button(BUTTON_START)) { runData->record = true; runData->liveData = false; } if (user_Get_Button(BUTTON_STOP)) { runData->record = false; runData->liveData = false; } if (runData->record || runData->liveData) { user_Set_LED(LED_START, ON); user_Set_LED(LED_STOP, OFF); } else { user_Set_LED(LED_STOP, ON); user_Set_LED(LED_START, OFF); } }