// start processing of jobs void rcrackiThread::rcrackiThreadEntryPoint() { #if GPU if(gpu != 0 && cudaGetDevice(&cudaDevId) == CUDA_SUCCESS) { cudaBuffCount = 0x2000; cudaChainSize = 100; cudaDeviceProp deviceProp; if(cudaGetDeviceProperties(&deviceProp, cudaDevId) == CUDA_SUCCESS) { switch(deviceProp.major) { case 1: ; break; case 2: cudaBuffCount = 0x4000; cudaChainSize = 200; break; } } cudaBuffCount = rcuda::GetChainsBufferSize(cudaBuffCount); } else #endif cudaDevId = -1; if (falseAlarmChecker) { if (falseAlarmCheckerO) { CheckAlarmO(); } else { CheckAlarm(); } } else { PreCalculate(); } }
boolean UpdateClock() { boolean b = false; while (millis()-lastMilli >= millisOnSecond) { b = true; lastMilli += millisOnSecond; clockSecond++; if (clockSecond >= 60) { clockSecond = 0; clockMinute++; if (clockMinute >= 60) { clockMinute = 0; clockHour++; if (clockHour >= 24) { clockHour = 0; clockDayOfWeek++; if (clockDayOfWeek >= 7) { clockDayOfWeek = 0; } sq_clock_weekday_updated( clockDayOfWeek ); } sq_clock_hour_updated( clockHour ); } sq_clock_minute_updated( clockMinute ); } if ((clockSecond % 10) == 0) sq_clock_second_updated( clockSecond); CheckAlarm(alarms[0]); CheckAlarm(alarms[1]); CheckAlarm(alarms[2]); CheckAlarm(alarms[3]); CheckAlarm(alarms[4]); CheckAlarm(alarms[5]); CheckAlarm(alarms[6]); CheckAlarm(alarms[7]); } return b; }
int main(void) { structSchedule test_sched = {0,0,0}; int init1 = 0; int init2 = 0; int day = 0; int hour = 0; int minute = 0; int dispense = 0; int recentlySavedDay = 0; int recentlySavedHour = 0; int recentlySavedMinute = 0; int recentlySavedDispenseCycle = 0; int scheduleState = 0; //int alarmState = 0; int alarmMinute = 0; char test[10]; Initialization(); LCDDisplayText(5, 0, "Running Mode"); sprintf(test, "%d", currentTime.day); LCDDisplayText(0, 0, test); sprintf(test, "%0.2d:%0.2d:%0.2d", currentTime.hour, currentTime.minute, currentTime.second); LCDDisplayText(1, 0, test); /* SaveSchedule(); ReadStoredScheduleIntoMemory(10); LookAtSpecificCycle(&test_sched, 10); sprintf(test, "%0.2d:%0.2d:%0.2d", test_sched.savedScheduleDay, test_sched.savedScheduleHour, test_sched.savedScheduleMinute); LCDDisplayText(4, 0, test); while (1){}; //test dummy loop // commented out for testing */ while (1) { if (PBHandlerInProgramMode() == 0) { if (init1 != 0) { LCDClear(); PBHandlerResetSelections(); init1 = 0; day = 0; hour = 0; minute = 0; dispense = 0; } if (init2 == 0) { LCDDisplayText(5, 0, "Running Mode"); LCDDisplayCurrentAlarmTime(0, 0, 0, 0, -1); } else if (init2 == 1) { LCDDisplayText(5, 0, "Running Mode"); LCDDisplayCurrentAlarmTime(recentlySavedDay, recentlySavedHour, recentlySavedMinute, recentlySavedDispenseCycle, -1); } } else if (PBHandlerInProgramMode() == 1) { if (PBHandlerIncrementSelection() == 1) { if (PBHandlerCurrentlySelectedLine() == 0) { day++; if (day == 7) { day = 0; } } else if (PBHandlerCurrentlySelectedLine() == 1) { hour++; if (hour == 24) { hour = 0; } } else if (PBHandlerCurrentlySelectedLine() == 2) { minute++; if (minute >= 5) { minute = 0; } } else if (PBHandlerCurrentlySelectedLine() == 3) { dispense++; if (dispense >= 28) { dispense = 0; } } } LCDDisplayText(5, 0, "Program Mode"); LCDDisplayCurrentAlarmTime(day, hour, minute, dispense, PBHandlerCurrentlySelectedLine()); if (PBHandlerUserWantsToSave() == 1) { SetScheduledAlarms(day, hour, minute, dispense); recentlySavedDay = day; recentlySavedHour = hour; recentlySavedMinute = minute; recentlySavedDispenseCycle = dispense; init2 = 1; } } if (timerInterrupt != 0) { timerInterrupt = 0; currentTime.second++; if (currentTime.second >= 60) { currentTime.second = 0; currentTime.minute++; if (currentTime.minute >= 60) { currentTime.minute = 0; currentTime.hour++; if (currentTime.hour >= 24) { currentTime.hour = 0; currentTime.day++; if (currentTime.day >= 6) { currentTime.day = 0; } } } } } if (currentTime.second == 50) { if (CheckCartridgeSetupTime(currentTime) == ALARM_EXISTS) { MoveOneSection(); } } sprintf(test, "%d", currentTime.day); LCDDisplayText(0, 0, test); sprintf(test, "%0.2d:%0.2d:%0.2d", currentTime.hour, currentTime.minute, currentTime.second); LCDDisplayText(1, 0, test); if (PBHandlerUserWantsToReset() == 1) { scheduleState = 1; LCDDisplayText(2, 0, "Schedule Enabled"); } if (CheckAlarm(currentTime) == ALARM_EXISTS && scheduleState == 1) { if (alarmState == 0) { LCDDisplayText(3, 0, "ALARM: ACTIVATE!"); ActivateVisualAlert(); ActivateAudioAlert(); //MoveOneSection(); alarmMinute = currentTime.minute; } alarmState = 1; } //SM test //if (PBHandlerUserPressedDispenseButton() == 1) //{ // MoveOneSection(); //} if (alarmState == 1) { if (currentTime.second >= 10)//if (currentTime.minute >= alarmMinute + 20) { DeactivateVisualAlert(); DeactivateAudioAlert(); LCDDisplayText(3, 0, " "); LCDDisplayText(4, 0, " "); alarmState = 0; } if (PBHandlerUserPressedDispenseButton() == 1) { //turn off alarm/reset things/dispense pill LCDDisplayText(4, 0, "Dispense"); DeactivateVisualAlert(); DeactivateAudioAlert(); MoveOneSection(); LCDDisplayText(3, 0, " "); LCDDisplayText(4, 0, " "); alarmState = 0; } } } }
/** Main loop */ void main() { unsigned char actionCounter=0xFF; InitMCU(); LCD_Init3V(); LCD_SetContrast(Read_EEPROM(EEAddr_LCDContrast)); LCD_SendString("LCD ok "); SetupRTC(); RefreshTime=1; LCD_SendString("RTC ok "); //load RAM values from EEPROM Brightness_start[0]=Read_EEPROM(EEAddr_DispBrightness); ReceiverMode=Read_EEPROM(EEAddr_ReceiverMode); SenderMode=Read_EEPROM(EEAddr_SenderMode); RC5Addr=Read_EEPROM(EEAddr_RC5Addr); Update_PWM_Offset(1); Update_PWM_Offset(2); // Infinite loop while(1) { if (TimerFlag) { PWM_StepDim(); // do next dimming step TimerFlag=0; ++actionCounter; // check keys here since we can have only new input if timerflag was set by the keys interrupt program // Select key is pressed, show preview of action // need to check each time to generate single events directly from KeyPressDuration counter if (KeySelect == KeyState) { SwBackLightOn(fadetime); //switch on or stay on if (Minutes2Signal) { if(0 == KeyPressDuration) { LCD_SendStringFill2ndLine("Set Snooze End"); } else if (KeyPressLong == KeyPressDuration) { LCD_SendStringFill2ndLine("End Alarm"); Beep(); } } else if (KeyPressShort == KeyPressDuration) if (LightOn) { LCD_SendStringFill2ndLine("Enter Standby"); Beep(); } else { LCD_SendStringFill2ndLine("Switch All On"); Beep(); } else if (KeyPressLong == KeyPressDuration) { LCD_SendStringFill2ndLine("Enter Options"); Beep(); } else if (KeyPressLonger == KeyPressDuration) { LCD_SendStringFill2ndLine(&Canceltext[0]); Beep(); } } switch (actionCounter) { case 0: DecodeRemote(); Alarm_StepDim_all(); if (1 < DisplayDimCnt) // LCD backlight fadout count down { --DisplayDimCnt; } else if (1 == DisplayDimCnt) // switch display backlight off? { SwLightOff(0); DisplayDimCnt=0; //set lsb, so we can use the encode to switch on again without changing alarm settings skipAlarmCnt = (skipAlarmCnt & skipAlarmMask) | skipAlarmhalfStep; } else // do not measure intensity with backlight on { MeasureExtBrightness(); } break; case 1: if (RefreshTime || RefreshTimeRTC) { GetTimeDateRTC(); LCD_SendTime(); if (RefreshTimeRTC) //execute only once(!) every minute or we can not leave the alarm during its first minute { CheckAlarm(); } if (0==LightOn) { LCD_NextAlarm(); } if (1 < Minutes2Signal) { LCD_SnoozeTime(); if (RefreshTimeRTC) { --Minutes2Signal; } } else if (1 == Minutes2Signal) { SwBackLightOn(1); //switch on now LCD_SendStringFill2ndLine(&Alarmtext[0]); if (AcousticDDSAlarm()) { Minutes2Signal=Read_EEPROM(EEAddr_AlarmTimeSnooze); //button was pressed, start snooze } else { AlarmEnd(); //timeout occured, terminate alarm and switch off SwAllLightOff(); LCD_SendStringFill2ndLine("Alarm Time Out"); } } RefreshTime=0; RefreshTimeRTC=0; } break; case 2: // A Key was pressed if OldKeyState != 0 and Keystate = 0 // OldKeyState = 0 must be set by receiving program after decoding as a flag if ((KeySelect == OldKeyState) && (0 == KeyState)) { OldKeyState=0; //Ack any key anyway if (Minutes2Signal) { if (KeyPressLong > KeyPressDuration) { AlarmSnoozeEnd(); } else { AlarmEnd(); LCD_SendBrightness(FocusBacklight+1); } } else if (KeyPressShort > KeyPressDuration) { if (LightOn) { FocusBacklight=!FocusBacklight; LCD_SendBrightness(FocusBacklight+1); } else { SendRC5(RC5Addr_com, RC5Cmd_On, 1, ComModeAll, RC5Cmd_Repeats); SwAllLightOn(); } } else if (KeyPressLong > KeyPressDuration) { if (LightOn) { SendRC5(RC5Addr_com, RC5Cmd_Off, 1, ComModeAll, RC5Cmd_Repeats); SwAllLightOff(); } else { if (ComModeConditional<=SenderMode) //reset to eeprom value in swalllightoff() { SenderMode=ComModeAll; } SendRC5(RC5Addr_com, RC5Cmd_On, 1, ComModeAll, RC5Cmd_Repeats); SwAllLightOn(); } } else if (KeyPressLonger > KeyPressDuration) { Alarmflag=0; Options(); } else { if (LightOn) // Cancel key pressing, refresh display { LCD_SendBrightness(FocusBacklight+1); } RefreshTime=1; } } break; case 3: // A Rotation occured if EncoderSteps!= 0 // EncoderSteps = 0 must be set by receiving program after decoding if (EncoderSteps) { Alarmflag=0; SwBackLightOn(fadetime); if (LightOn) { PWM_SetupDim(FocusBacklight+1, Brightness_steps, EncoderSteps); EncoderSteps = 0; //ack any steps LCD_SendBrightness(FocusBacklight+1); SendRC5(RC5Addr_front+FocusBacklight, (Brightness[FocusBacklight+1]>>1) & 0x3F, Brightness[FocusBacklight+1] & 0x01, ComModeAll, RC5Value_Repeats); } else { EncoderSetupValue(&skipAlarmCnt, maxskipAlarmCnt, 0); RefreshTime=1; } } actionCounter=0xFF; //last time slot, do reset counter with increment to 0 break; } } PCON=MCUIdle; //go idel, wake up by any int }