Ejemplo n.º 1
0
void VESPERSBeamline::openAllValvesHelper()
{
	openValve(valveIndex_--);

	if (valveIndex_ >= 0)
		QTimer::singleShot(150, this, SLOT(openAllValvesHelper()));
}
Ejemplo n.º 2
0
void doProbe( void )
{
	runstate = PROBING_STATE;
	
	ADMUX = (1<<REFS0)|(1<<MUX1);					// ref. voltage = AVcc, channel = ADC2
	ADCSRA = (1<<ADPS2)|(1<<ADIE);					// 1:16 prescaler
	
	_delay_ms( 300 );
	
	ADCSRA |= (1<<ADEN);							// enable ADC
	ADCSRA |= (1<<ADSC);							// start first conversion
	
	probingphase = PROBING_START;
	
	// take some time to take a measurement without the motor running, go to sleep and wake up if the measurements are done
	set_sleep_mode( SLEEP_MODE_ADC );
	sleep_mode();
	
	OPTO_SENSOR_ON;
	
	openValve();
	
	while( !okButtonPressed() ) ;
	
	closeValve();
	
	while( !okButtonPressed() ) ;

	openValve();
	
	probingphase = PROBING_END;

	ADCSRA &= ~((1<<ADEN)|(1<<ADIE));				// disable ADC

	OPTO_SENSOR_OFF;
	
	_delay_ms( 300 );

	runstate = NORMAL_STATE;
}	
Ejemplo n.º 3
0
void ValveController::changeValveToSuggestedState()
{
  switch(m_suggestedState)
  {
    case OPEN:
      openValve();
      break;
    case CLOSED:
      closeValve();
      break;
    case UNDEF:
      return;
    default:
      break;
  }
  m_suggestedState = UNDEF;
}
Ejemplo n.º 4
0
void high_isr(void)
{
	
	//Timer for servo
	if(INTCONbits.TMR0IF)  
	{						
		PORTBbits.RB3 = 1;
		if(servoState == 0){
			Delay1TCY();
  	 	  	Delay1TCY();
  	 	  	//Delay10TCYx(6);
		}else{
			Delay1TCY();
      		Delay1TCY();
      		Delay1TCY();
      		Delay1TCY();
      		Delay1TCY();
      		Delay1TCY();
      		Delay1TCY();
  	 	  	Delay10TCYx(5);
  	 	  	Delay100TCYx(4);
  		}	 
  		PORTBbits.RB3 = 0;	  
		INTCONbits.TMR0IF = 0;	// Clear interrupt flag for timer 0
		WriteTimer0(64911);

	}
	//code for servo state = 1 and regular timer
	if(PIR1bits.TMR1IF && servoState == 1){
		valveCounter++;	
		if(valveCounter == valveTotalTick){
			closeValve();	
			valveCounter = 0;
		}	
		PIR1bits.TMR1IF = 0;	// Clear interrupt flag for timer 0
	}
	else if(PIR1bits.TMR1IF && plantTimerCount == totalTimerCount){
		//Waters all the plants	
	
		moveToLocation(plantBeingWatered);
		openValve();
		
		if(plantBeingWatered == totalplants){
			plantTimerCount = 0;
			plantBeingWatered = -1;
		}
	
		plantBeingWatered++;
		PIR1bits.TMR1IF = 0;	// Clear interrupt flag for timer 0
	}	
	
	//Timer for timed water sequence
	else if(PIR1bits.TMR1IF)  
	{		
		plantTimerCount++;
		PIR1bits.TMR1IF = 0;	// Clear interrupt flag for timer 0
	}
	
	// interupt for button to water plant 0
	if(INTCONbits.INT0IF){
		moveToLocation(0);
		openValve();
		INTCONbits.INT0IF = 0;
		
		
	}	
	// interupt for button to water plant 1
	if(INTCON3bits.INT1IF){
		moveToLocation(1);
		openValve();
		INTCON3bits.INT1IF = 0;

	}	
	// interupt for button to water plant 2
	if(INTCON3bits.INT2IF){
		moveToLocation(2);
		openValve();
		INTCON3bits.INT2IF = 0;
	}	
}
Ejemplo n.º 5
0
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

}