/*********************************************************** * * uiPowerTimeOut * ***********************************************************/ void TTUI::uiPowerTimeOut() { if(state_UIPower == true) { #ifndef TT_SHIELD //if not TT shield if((millis() - previousMillis_UIPower) > UI_SLEEP_MS) { uiPowerOff(); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); sei(); //make sure interrupts are on! detachInterrupt(0); attachInterrupt(0,sleepHandler, FALLING); sleep_mode(); //sleep now //----------------------------- ZZZZZZ sleeping here---------------------- sleep_disable(); //disable sleep, awake now attachInterrupt(0,startDownHandler,FALLING); //trigger ISR function on start button press. uiPowerOn(); } #endif //end TT_Shield } }
/*********************************************************** * * initStart * ***********************************************************/ void TTUI::initStart(unsigned long startTime) { if(currentTrigger < NUM_OF_SENSORS) //only start if you are on a sensor menu, not system menu! { trapActive_ = !trapActive_; //flip boolean status if(trapActive_ == true) { #ifdef SERIAL_DEBUG Serial.println("Active"); #endif activeRefreshTime = startTime/100; //100ms triggers[currentTrigger]->saveState(); //save the values of active trigger to eeprom triggers[0]->saveSystem(); //save system menu settings, to trigger 0. triggers[currentTrigger]->start(startTime); //set start time for the active trigger uiPowerOff(); } else if(trapActive_ == false) { #ifdef SERIAL_DEBUG Serial.println("Inactive"); #endif triggers[currentTrigger]->resetFocus(true); triggers[currentTrigger]->resetShutter(true); //don't want to leave the shutter high forever triggers[currentTrigger]->stop(); //set abortTrigger to true uiPowerOn(); //restore screen to so current select menu and value, better to show mode+select? //set the value title in line 1 clear(); printSelect(0); printInc(1,0); //inc 0 so just display, don't actually increment } } }
TTUI::TTUI():LiquidCrystal_SR_LCD3(11, 10, 12 ,2) #else TTUI::TTUI():LiquidCrystal(A3,4,5, 6, 7, 8, 9) #endif { pTTUI = this; //the ptr points to this object trapActive_ = false; } /*********************************************************** * * begin * ***********************************************************/ void TTUI::setup(Trigger *sensors[]) { #ifdef SERIAL_DEBUG Serial.begin(9600); #endif #ifndef SERIAL_DEBUG // USB Serial port configure as input, disable pullup pinMode (0, INPUT); pinMode (1, INPUT); digitalWrite(0, LOW); digitalWrite(1, LOW); #endif analogReference(INTERNAL); //assign sensor[] pointers to triggers[] array for(int i=0;i<NUM_OF_SENSORS;++i) { triggers[i] = sensors[i]; } //TODO: move system menu eeprom settings out of Trigger.cpp into TTUI.cpp triggers[0]->restoreSystem(); //restore system menu settings from trigger 0. Could work with any trigger though boolean focusSetting = triggers[0]->getFocus(); boolean shutterSetting = triggers[0]->getShutter(); boolean hdrshutterSetting = triggers[0]->getHDRShutter(); boolean IRSetting = triggers[0]->getIRShutter(); lcdContrast = triggers[0]->getContrast(); for(uint8_t i=0;i<NUM_OF_SENSORS;++i) { triggers[i]->setIndex(i); triggers[i]->restoreState(); triggers[i]->focusOn(focusSetting); triggers[i]->shutterOn(shutterSetting); triggers[i]->hdrshutterOn(hdrshutterSetting); triggers[i]->IRShutterOn(IRSetting); } systemMenu = NUM_OF_SENSORS; //system Menu is always the last menu, even if you add more sensors incSystemOption = 0; //the current system option menu state trapActive_ = false; startBttnHold = false; currentTrigger = 0; //configure start button pinMode(START_BUTTON, INPUT); // Start Button digitalWrite(START_BUTTON, HIGH); // turn on pullup resistor for Start button #ifdef TT_SHIELD PCintPort::attachInterrupt(START_BUTTON,startDownHandler,FALLING); #else attachInterrupt(0,startDownHandler,FALLING); //trigger ISR function on start button press. #endif //Shutter and Focus pins set to output pinMode(FOCUS_TRIGGER_PIN, OUTPUT); pinMode(SHUTTER_TRIGGER_PIN, OUTPUT); digitalWrite(FOCUS_TRIGGER_PIN, HIGH); // is off digitalWrite(SHUTTER_TRIGGER_PIN, HIGH); // is off //set UI Power #ifndef TT_SHIELD //if TT is normal not Shield DDRB |= (1<<PORTB7); //pinMode(KEY_PAD_LEDS, OUTPUT); // LED on UI DDRB |= (1<<PORTB6); //pinMode(POWER_UI,OUTPUT); #endif state_UIPower = false; uiPowerOn(); //turn on power at startup previousMillis_UIPower = 0; #ifdef TT_SHIELD touch.begin(); #else touch.begin(KEY_CHANGE); //init touch UI with key change interrupt #endif //TT_SHIELD endif activeMenu == START_MESSAGE; //this class inherits from LCD, so call lcd functions as part of this class #ifndef TT_SHIELD //if TT is normal not Shield //LCD Stuff TCCR1B = TCCR1B & 0b11111000 | 0x01; //-- sets the pwm base //pinMode (10, OUTPUT); // lcd contrast output not required to set output for analogWrite if(batteryPower() == true) { // under certain conditions ADC doesnot resart from deep sleep ADCSRA |= (1 << ADEN); // Enable ADC if(lcdContrast == 30) //probably means its from a blank eeprom. { lcdContrast = analogRead(A1); lcdContrast = analogRead(A1); // read twice, toss first // case switch to handle non-linear contrast curve switch (lcdContrast) { case 1 ... 613: // 0v0 to 3v1 lcdContrast = map(lcdContrast, 550, 613, 128, 61); break; case 614 ... 791: // 3v1 to 4v0 lcdContrast = map(lcdContrast, 614, 791, 60, 35); break; case 792 ... 1023: // 4v0 to 5v2 lcdContrast = map(lcdContrast, 792, 1023, 36, 1); break; default: break; } }
TTUI::TTUI():LiquidCrystal_SR_LCD3(11, 10, 12 ,2) #else TTUI::TTUI():LiquidCrystal(A3,4,5, 6, 7, 8, 9) #endif { pTTUI = this; //the ptr points to this object trapActive_ = false; } /*********************************************************** * * begin * ***********************************************************/ void TTUI::setup(Trigger& laser, Trigger& sound, Trigger& light,Trigger& timeLapse, Trigger& aux) { #ifdef SERIAL_DEBUG Serial.begin(9600); #endif #ifndef SERIAL_DEBUG // USB Serial port configure as input, disable pullup pinMode (0, INPUT); pinMode (1, INPUT); digitalWrite(0, LOW); digitalWrite(1, LOW); #endif analogReference(INTERNAL); //set triggers into array triggers[0] = &laser; triggers[1] = &sound; triggers[2] = &light; triggers[3] = &timeLapse; triggers[4] = &aux; triggers[0]->restoreSystem(); //restore system menu settings from trigger 0. Could work with any trigger though boolean focusSetting = triggers[0]->getFocus(); boolean shutterSetting = triggers[0]->getShutter(); boolean IRSetting = triggers[0]->getIRShutter(); for(uint8_t i=0;i<NUM_OF_SENSORS;++i) { triggers[i]->setIndex(i); triggers[i]->restoreState(); triggers[i]->focusOn(focusSetting); triggers[i]->shutterOn(shutterSetting); triggers[i]->IRShutterOn(IRSetting); } systemMenu = NUM_OF_SENSORS; //system Menu is always the last menu, even if you add more sensors incSystemOption = 0; //the current system option menu state trapActive_ = false; startBttnHold = false; currentTrigger = 0; //configure start button pinMode(START_BUTTON, INPUT); // Start Button digitalWrite(START_BUTTON, HIGH); // turn on pullup resistor for Start button #ifdef TT_SHIELD PCintPort::attachInterrupt(START_BUTTON,startDownHandler,FALLING); #else attachInterrupt(0,startDownHandler,FALLING); //trigger ISR function on start button press. #endif //Shutter and Focus pins set to output pinMode(FOCUS_TRIGGER_PIN, OUTPUT); pinMode(SHUTTER_TRIGGER_PIN, OUTPUT); digitalWrite(FOCUS_TRIGGER_PIN, HIGH); // is off digitalWrite(SHUTTER_TRIGGER_PIN, HIGH); // is off //set UI Power #ifndef TT_SHIELD //if TT is normal not Shield DDRB |= (1<<PORTB7); //pinMode(KEY_PAD_LEDS, OUTPUT); // LED on UI DDRB |= (1<<PORTB6); //pinMode(POWER_UI,OUTPUT); #endif state_UIPower = false; uiPowerOn(); //turn on power at startup previousMillis_UIPower = 0; #ifdef TT_SHIELD touch.begin(); #else touch.begin(KEY_CHANGE); //init touch UI with key change interrupt #endif //TT_SHIELD endif activeMenu == START_MESSAGE; //this class inherits from LCD, so call lcd functions as part of this class #ifndef TT_SHIELD //if TT is normal not Shield //LCD Stuff TCCR1B = TCCR1B & 0b11111000 | 0x01; //-- sets the pwm base pinMode (10, OUTPUT); // lcd contrast output if(batteryPower() == true) { long lcdContrast = analogRead(A1); lcdContrast = 175 - ((lcdContrast * 5) / 32); analogWrite (10, lcdContrast); } else { byte lcdContrast = 25; analogWrite (10, lcdContrast); } #endif // END TT if begin(8, 2); // Print a message to the LCD. print("TrigTrap"); setCursor(0,1); print("v"); print(FIRMWARE_VERSION); #ifdef SERIAL_DEBUG Serial.print("TT v"); Serial.println(FIRMWARE_VERSION); #endif interrupts(); //make sure interrupts are on }