void dispatch() /* Set up a connection to database and dispatch control * based on hgpDo type var. */ { struct sqlConnection *conn = sqlConnect(visiDb); if (cartVarExists(cart, hgpDoThumbnails)) doThumbnails(conn); else if (cartVarExists(cart, hgpDoImage)) doImage(conn); else if (cartVarExists(cart, hgpDoProbe)) doProbe(conn); else if (cartVarExists(cart, hgpDoControls)) doControls(conn); else if (cartVarExists(cart, hgpDoId)) doId(conn); #ifdef SOON else if (cartVarExists(cart, hgpDoConfig)) configPage(conn); #endif /* SOON */ else if (cartVarExists(cart, hgpDoSearch)) doDefault(conn, TRUE); else { char *oldListSpec = hashFindVal(oldCart, hgpListSpec); char *newListSpec = cartOptionalString(cart, hgpListSpec); boolean isNew = differentStringNullOk(oldListSpec, newListSpec); doDefault(conn, isNew); } cartRemovePrefix(cart, hgpDoPrefix); }
int main(void) { initRTC(); initControls(); initLCD(); initValve(); // timer0 is being used as a global 'heartbeat' // i.e. for blinking in the LCD // and for running a temperature check at regular intervals TCCR0A = (1<<CS02)|(1<<CS00); // timer clock = system clock / 1024 TIFR0 = (1<<TOV0); // clear pending interrupts TIMSK0 = (1<<TOIE0); // enable timer0 overflow Interrupt sei(); // Enable Global Interrupts // start a probe run to find the "fully open" and "fully closed" positions doProbe(); // initialize the NTC sensor and start the 1st measurement // consequent measurements will be done every tick initTemp(); runstate = NORMAL_STATE; while (1) { if( adcTemp < targetTemp && valvestate != VALVE_OPEN ) { openValve(); } else if( valvestate != VALVE_CLOSED ) { closeValve(); } if( menuButtonPressed() ) { switch( runstate ) { case NORMAL_STATE : runstate = MENU_STATE; break; default : runstate = NORMAL_STATE; break; } } // end if( menuButtonPressed ) if( timeButtonPressed() ) { switch( runstate ) { case NORMAL_STATE : runstate = TIMESET_STATE; timesetphase = TIMESET_START; _delay_ms( 500 ); // show time with hours blinking timesetphase = TIMESET_YEAR; break; default : runstate = NORMAL_STATE; break; } } // end if( timeButtonPressed ) if( okButtonPressed() ) { switch( runstate ) { case MENU_STATE : switch( mainmenu ) { case TEMP : runstate = TEMPSET_STATE; break; case TIME : runstate = TIMESET_STATE; timesetphase = TIMESET_START; _delay_ms( 500 ); // show time with hours blinking timesetphase = TIMESET_YEAR; break; default: break; } break; case TEMPSET_STATE : runstate = MENU_STATE; break; case TIMESET_STATE : switch( timesetphase ) { case TIMESET_YEAR : timesetphase = TIMESET_MONTH; break; case TIMESET_MONTH : timesetphase = TIMESET_DATE; break; case TIMESET_DATE : timesetphase = TIMESET_HOURS; break; case TIMESET_HOURS : timesetphase = TIMESET_MINUTES; break; case TIMESET_MINUTES : timesetphase = TIMESET_YEAR; break; default : break; } break; default : break; } } // end if( okButtonPressed ) ROTARYBUTTON rotaryButton = readRotaryButton(); if( rotaryButton == ROTARY_UP ) { switch( runstate ) { case NORMAL_STATE : case MENU_STATE : mainmenu++; if( mainmenu == LAST_ITEM ) mainmenu = 0; break; case TIMESET_STATE : increaseClock( timesetphase ); break; case TEMPSET_STATE : if( targetTemp >= 500 ) targetTemp = 0; else targetTemp += 5; break; default : break; } } // end if( BUTTON_UP_PRESSED ) if( rotaryButton == ROTARY_DOWN ) { switch( runstate ) { case NORMAL_STATE : case MENU_STATE : if( mainmenu == 0 ) mainmenu = LAST_ITEM; mainmenu--; break; case TIMESET_STATE : decreaseClock( timesetphase ); break; case TEMPSET_STATE : if( targetTemp == 0 ) targetTemp = MAXTEMP; else targetTemp -= 5; break; default : break; } } // end if( BUTTON_DOWN_PRESSED ) // go to sleep but wake up if any button is pressed set_sleep_mode( SLEEP_MODE_ADC ); sleep_mode(); } // end while forever }