Exemple #1
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

}
void TempStats::clearStats() {
	storage->dh_clear();
	dit.reset();
	initTemp(&ap.temp);
}
Exemple #3
0
/**
 * main function in input
 */
void inputData()
{
	#ifdef NEED_MACHINE_EDGE
	initTemp(&temp);
	#endif
	jobVertexCount = 0;
	jobEdgeCount = 0;
	tabuLength = currentTabuLength = 0;
	currentT = currentNo = 0;
	isInitialSolution = true;
	memset(jobVertex, 0, sizeof(jobVertex));
	memset(jobEdge, 0, sizeof(jobEdge));
	memset(machineSequence, 0, sizeof(machineSequence));
	longestTime = 0, smallestTime = 0x7fffffff;
	// printf("input the number of the job and the machine\n");
	scanf("%d%d", &jobNumber, &machineNumber);
	getchar();
	for(int i = 1; i <= jobNumber; ++i)
	{
		// puts("input the number of the process");
		int k = 0;
		int _machine, _duration;

		// the test input which is easy to input
		#ifdef TEST_INPUT
		scanf("%d", &k);

		for(int j = 1; j <= k; ++j)
		{
			// puts("machine, duration");
			scanf("%d%d", &_machine, &_duration);
			buildJobVertex(_machine, i);

			#ifdef NEED_MACHINE_EDGE
			insertTemp(_machine, _duration, jobVertexCount);
			#endif

			if(j == 1)
			{
				headVertex[i] = jobVertexCount;
			}
			if(j == k)
			{
				tailVertex[i] = jobVertexCount;
			}
			buildJobEdge(i, _duration);
		}
		#endif

		// the release(required) input which is hard and confucious
		// and some info useless
		#ifdef RELEASE_INPUT

		char inputString[500];
		gets(inputString);
		int l = strlen(inputString);
		int t = 0;
		// while(isdigit(inputString[t])) ++t;
		for(; t < l; ++t)
		{
			if(isdigit(inputString[t]))
			{
				++k;
				_machine = 0;
				_duration = 0;
				while(isdigit(inputString[t]))
				{
					_machine *= 10;
					_machine += inputString[t] - '0';
					++t;
				}
				while(!isdigit(inputString[t])) ++t;
				while(isdigit(inputString[t]))
				{
					_duration *= 10;
					_duration += inputString[t] - '0';
					++t;
				}
				buildJobVertex(_machine, i);
				if(k == 1)
				{
					headVertex[i] = jobVertexCount;
				}
				buildJobEdge(i, _duration);
			}
		}
		tailVertex[i] = jobVertexCount;

		#endif
	}
	/*
	#ifdef RELEASE_INPUT
	int useless;
	scanf("%d", &useless);
	#endif
	*/
	// buildHeadJobEdge();
	// buildHeadJobVertex();
	buildTailJobEdge();

	#ifdef NEED_MACHINE_EDGE
	// is it necessary to build machineEdge?
	viewTemp();
	free(temp);
	temp = NULL;
	printGraph();
	#endif
}
void TempStats::init() {
	initTemp(&ap.temp);
}