예제 #1
0
int main(){
	int i = 0;
	PLL_Init();
	SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | 
	SYSCTL_XTAL_8MHZ); // 50 MHz 
	DisableInterrupts();
	SYSCTL_RCGC1_R |= SYSCTL_RCGC1_TIMER0;// activate timer0
	SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF+SYSCTL_RCGC2_GPIOG; // activate ports F and G
	Output_Init(); 
	SysTick_InitSeconds(1);
	PolledButtons_Init();
	EnableInterrupts();
	displayMode = 0;
	ringAlarms = 0;
	timeMode = 0;
		
	while(1){
		if (ringAlarms && !soundPlaying && (alarmActive || timeMode == 4))	{
			playSound();
		}
		else if ((ringAlarms==0 || !alarmActive) && soundPlaying) {
			stopSound();
		}
		if(displayMode==0) {
			displayClock();
		}
		else if(displayMode==1){
			displaySet();
		}
	}
}
예제 #2
0
파일: menu.c 프로젝트: pseudoblau/Versuch1
/*! \brief Starts the passed program
 *
 * \param programIndex Index of the program to start.
 */
void start(uint8_t programIndex)
{
	// initialize and start the passed 'program'
	switch (programIndex)
	{
	case 0:
		lcd_clear();
		helloWorld();
		break;
	case 1:
		activateLedMask = 0xFFFF;	// use all LEDs
		initLedBar();
		initClock();
		displayClock();
		break;
	case 2:
		activateLedMask = 0xFFFE;	// don't use led 0
		initLedBar();
		initAdc();
		displayAdc();
		break;
	default:
		break;
	}

	// do not resume to the menu until all buttons are released
	os_waitForNoInput();
}
예제 #3
0
//run the clock state machine. call this function frequently from the main loop.
void GoldieClock::run(time_t utc)
{
    static clockStates_t CLOCK_STATE;

    btnSet.read();
    btnIncr.read();

    switch ( CLOCK_STATE)
    {
    case RUN_CLOCK:
        if ( btnSet.pressedFor(SET_LONGPRESS) )
        {
            CLOCK_STATE = SET_CLOCK;
        }
        else if ( btnIncr.wasReleased() )      //toggle the quarter-hour rainbows
        {
            if ( _showRainbows = !_showRainbows )
            {
                rainbowCycle(2, 1);            //show a rainbow if rainbow mode is on
            }
            else
            {
                clear();                       //else just blank the display for a second
                show();
                delay(1000);
            }
        }
        else
        {
            displayClock(utc);
        }
        break;

    case SET_CLOCK:
        if ( setClock() )    //returns true when setting complete
        {
            CLOCK_STATE = RUN_CLOCK;
        }
        break;
    }
}
예제 #4
0
파일: cci.c 프로젝트: y36ding/Barby2
void cci_process()
{
	CCI_DISPLAY_ENV = request_msg_env();
	MsgEnv *cci_env = request_msg_env();
	MsgEnv*  a_env = request_msg_env(); // this wont be released as process A will release it later
	char formatted_msg[1000];
	int retVal;

	while(1)
	{
		const int twait = 500000;
		cci_print("CCI: ");
		//cci_env = request_msg_env();
		get_console_chars(cci_env);

		cci_env = receive_message();
		while(cci_env->msg_type != CONSOLE_INPUT)
		{
			release_message_env(cci_env);
			cci_env = receive_message();
		}

		//Obtained keyboard input
		char command [MAXCHAR];
		int offset = sprintf(command,  cci_env->data);
		// Check atleast 2 characters even if user entered 1.
		if (offset < 2)
			offset = 2;

		// Send a message to process A. This only happens once. If it has already been sent, then prompt user.
		if (strncasecmp(command, "s", offset) == 0)
		{
			if (a_env != NULL)
			{
				retVal = send_message(PROCA_ID, a_env);
				if (retVal != SUCCESS)
						cci_print("Failed to send message envlope and start A\n");
				a_env = NULL;
			}
			else
			{
				cci_print("A has already started.\n");
			}
		}
		else if(strncasecmp(command, "ps", offset ) == 0)
		{
			retVal = request_process_status(cci_env);
			if (retVal != SUCCESS)
				cci_print("Failed to request process status");
			sprintf(formatted_msg,  cci_env->data);
			cci_print(formatted_msg);
		}
		else if(strncasecmp(command, "cd", offset) == 0)
		{
			displayClock(1);
		}
		else if(strncasecmp(command, "ct", offset) == 0)
		{
			displayClock(0);
		}
		// Display Trace Buffers
		else if(strncasecmp(command, "b", offset) == 0)
		{
			retVal = get_trace_buffers(cci_env);
			if (retVal != SUCCESS)
				cci_print("Failed to get trace buffers");
			sprintf(formatted_msg, "%s", cci_env->data);
			cci_print(formatted_msg);
		}
		else if(strncasecmp(command, "c", 2) == 0)
		{
			if(command[4] != ':' || command[7] != ':' || strlen(command) != 10)
			{
				sprintf(formatted_msg, "Invalid format for command %s. It should be: c <hh>:<mm>:<ss>\n", "c");
				cci_print(formatted_msg);
			}
			else
			{
				const char * rawTimeString = command+2;
			    char hourString [3] = { '0', '0', '\0'};
			    char minString [3] = { '0', '0', '\0'};
			    char secString [3] = { '0', '0', '\0'};
			    int i, hr, min, sec;
			    for (i=0;i<2;i++)
			    {
			        hourString[i] =rawTimeString[i];
			        minString[i]=rawTimeString[3+i];
			        secString[i]=rawTimeString[6+i];
			    }

			    hour = atoi(hourString);
			    min = atoi(minString);
			    sec = atoi(secString);

			    if (hour>23 || min>59 || sec > 59)
			    {
			    	sprintf(formatted_msg, "Invalid input."
			    			" Ensure hh not greater than 23, mm not greater than 59, ss not greater than 59.\n");
			    	cci_print(formatted_msg);
			    }
			    else
			    	setClock(hour, min, sec);   // offset the "c " (c-space)
			}
		}
		else if(strncasecmp(command, "n", 1) == 0)
		{

			int priority, pid;
			// extract priority and pid from the command
			if (sscanf(command, "%*s %i %i", &priority, &pid)!=2)
			{
				sprintf(formatted_msg, "Invalid format for command %s. It should be: n <priority> <process id>\n", "n");
				cci_print(formatted_msg);
			}
			else
			{
				retVal = change_priority(priority, pid);
				sprintf(formatted_msg, "Priority: %i, Pid: %i\n", priority, pid);
				cci_print(formatted_msg);
				if (retVal == ILLEGAL_ARGUMENT)
				{
					sprintf(formatted_msg, "Invalid arguments. Ensure that the priority is between [0-3], and the process ID is a valid"
							"process ID other than the NULL process ID\n");
					cci_print(formatted_msg);
				}
				else if (retVal != SUCCESS)
				{
					cci_print("Priority of specified process could not be changed\n");
				}
			}
		}
		else if(strncasecmp(command, "t", offset) == 0)
		{
			// no need to release envelopes as terminate will free all memory from MSG_LIST
			terminate();
		}
		// debugging function. find where all the envelopes are.
		else if(strncasecmp(command, "en", offset) == 0)
		{
			int offset = sprintf(formatted_msg, "\nEnvelope Num\tHeld By\n");
			int i;
			for (i  = 0; i < MSG_ENV_COUNT; ++i)
			{
				const char* pcb_name;
				switch(MSG_LIST[i]->dest_pid)
				{
					case(-1):
						pcb_name = "NONE\0";
						break;
					default:
						pcb_name = PCB_LIST[MSG_LIST[i]->dest_pid]->name;
				}
				offset += sprintf(formatted_msg+offset, "%i\t\t%s\n", i+1, pcb_name);
			}
			cci_print(formatted_msg);
		}
		// debugging, check all queues
		else if(strncasecmp(command, "cq", offset) == 0)
		{
			int offset = 0;
			offset += sprintf(formatted_msg, "\nREADY QUEUE");
			int rdy_queues = proc_pq_get_num_prorities(RDY_PROC_QUEUE);
			int i;
			for (i = 0; i < rdy_queues; ++i)
			{

				offset+= sprintf(formatted_msg+offset, "\nPriority %i: ", i);
				pcb* head = RDY_PROC_QUEUE->priority_queues[i]->head;
				while (head != NULL)
				{
					offset += sprintf(formatted_msg+offset, "%s->", head->name);
					head = head->next;
				}
			}

			offset += sprintf(formatted_msg+offset, "\n\nBLOCKED QUEUE: ");
			pcb* head = BLOCKED_QUEUE->head;
			while(head!=NULL)
			{
				offset += sprintf(formatted_msg+offset, "%s->", head->name);
				head = head->next;
			}
			offset += sprintf(formatted_msg + offset, "\n\n");

			cci_print(formatted_msg);
		}
		// One space and enter results in CCI: being printed again
		else if(strncasecmp(command, " ", offset) == 0)
		{
		}
		// If enter is directly pressed, display a different error
		else if(strcmp(command, "") == 0)
		{
			cci_print("Enter a command!\n");
		}
		// Default error message
		else
		{
			sprintf(formatted_msg, "The command %s is not supported\n", command);
			cci_print(formatted_msg);
		}
		//printf("releasing %p\n", cci_env);
		//release_message_env(cci_env);
	}
	fflush(stdout);
	printf("=====================WTH! CCI came out of while loop!");
	fflush(stdout);
	terminate();
}
예제 #5
0
//run the time setting state machine. must be called frequently while in set mode.
//returns true when setting is complete or has timed out.
bool GoldieClock::setClock(void)
{
    static setStates_t SET_STATE;
    static time_t utc, local;
    static uint8_t newTzIndex;
    static int y, mth, d, h, m, maxDays;
    static uint16_t pixel;
    static uint32_t rpt;
    bool retval = false;

    //see if user wants to cancel set mode or if set mode has timed out
    if ( SET_STATE != SET_INIT )
    {
        if ( btnSet.pressedFor(SET_LONGPRESS) )
        {
            SET_STATE = SET_INIT;
            displayClock( getUTC() );
            while ( btnSet.isPressed() ) btnSet.read();    //wait for user to release the button
            return true;
        }
        uint32_t ms = millis();
        if ( (ms - btnSet.lastChange() >= SET_TIMEOUT) && (ms - btnIncr.lastChange() >= SET_TIMEOUT) )
        {
            SET_STATE = SET_INIT;
            return true;
        }
    }

    switch ( SET_STATE )
    {
    case SET_INIT:
        SET_STATE = SET_TZ;
        rpt = REPEAT_FIRST;
        utc = getUTC();
        local = (*tz).toLocal(utc, &tcr);
        newTzIndex = tzIndex;
        displaySet( newTzIndex, WHITE );
        while ( btnSet.isPressed() ) btnSet.read();    //wait for user to release the button
        break;

    case SET_TZ:
        if ( btnSet.wasReleased() )                    //then move on to set year
        {
            SET_STATE = SET_YEAR;
            rpt = REPEAT_FIRST;
            if ( newTzIndex != tzIndex )
            {
                tzIndex = newTzIndex;
                tz = timezones[tzIndex];
                eeprom_write_byte( &ee_tzIndex, tzIndex);
                Serial << F("Time zone changed to ") << tzNames[tzIndex] << endl;
            }
            y = year(local);
            if ( y < 2015 || y > 2074 ) y = 2015;      //year must be in range 2015-2074
            pixel = y - 2000;                          //map to pixel
            if ( pixel > 60 ) pixel -= 60;
            displaySet( pixel, MAGENTA );
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++newTzIndex >= sizeof(tzNames) / sizeof(tzNames[0]) ) newTzIndex = 0;
            displaySet( newTzIndex, WHITE );
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++newTzIndex >= sizeof(tzNames) / sizeof(tzNames[0]) ) newTzIndex = 0;
            displaySet( newTzIndex, WHITE );
        }
        break;

    case SET_YEAR:
        if ( btnSet.wasReleased() )
        {
            SET_STATE = SET_MON;
            rpt = REPEAT_FIRST;
            mth = month(local);
            displaySet( mth, CYAN );
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++pixel > LAST_PIXEL ) pixel = 0;
            displaySet( pixel, MAGENTA );
            y = pixel < 15 ? 2060 + pixel : 2000 + pixel;    //map pixel to year
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++pixel > LAST_PIXEL ) pixel = 0;
            displaySet( pixel, MAGENTA );
            y = pixel < 15 ? 2060 + pixel : 2000 + pixel;    //map pixel to year
        }
        break;

    case SET_MON:
        if ( btnSet.wasReleased() )
        {
            SET_STATE = SET_DAY;
            rpt = REPEAT_FIRST;
            d = day(local);
            maxDays = monthDays[mth-1];                      //number of days in the month
            if (mth == 2 && isLeap(y)) ++maxDays;            //account for leap year
            if ( d > maxDays ) d = maxDays;
            displaySet( d, YELLOW );
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++mth > 12 ) mth = 1;                       //wrap from dec back to jan
            displaySet( mth, CYAN );
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++mth > 12 ) mth = 1;
            displaySet( mth, CYAN );
        }
        break;

    case SET_DAY:
        if ( btnSet.wasReleased() )
        {
            SET_STATE = SET_HOUR;
            rpt = REPEAT_FIRST;
            h = hour(local);
            displaySet( h, RED );
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++d > maxDays ) d = 1;
            displaySet( d, YELLOW );
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++d > maxDays ) d = 1;
            displaySet( d, YELLOW );
        }
        break;

    case SET_HOUR:
        if ( btnSet.wasReleased() )
        {
            SET_STATE = SET_MIN;
            rpt = REPEAT_FIRST;
            m = minute(local);
            displaySet( m, BLUE );
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++h > 23 ) h = 0;
            displaySet( h, RED );
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++h > 23 ) h = 0;
            displaySet( h, RED );
        }
        break;

    case SET_MIN:
        if ( btnSet.wasReleased() )
        {
            SET_STATE = SET_INIT;
            rpt = REPEAT_FIRST;
            tmElements_t tm;
            tm.Year = CalendarYrToTm(y);
            tm.Month = mth;
            tm.Day = d;
            tm.Hour = h;
            tm.Minute = m;
            tm.Second = 0;
            local = makeTime(tm);
            utc = (*tz).toUTC(local);
            RTC.set(utc);
            setUTC(utc);
            Serial << F("\nTime set to:\n");
            printDateTime(utc);
            Serial << F("UTC") << endl;
            printDateTime(local);
            Serial << tcr -> abbrev << endl;
            retval = true;
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++m > 59 ) m = 0;
            displaySet( m, BLUE );
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++m > 59 ) m = 0;
            displaySet( m, BLUE );
        }
        break;
    }
    return retval;
}
예제 #6
0
파일: main.c 프로젝트: markusk/direcs
/**
**===========================================================================
**
**  Abstract: main program
**
**===========================================================================
*/
int main(void)
{
	if (SysTick_Config(SystemCoreClock / 1000))
	{
	    /* Capture error */
	    while (1);
	}

	/* Initialisiere SPI2 */
	D_SPI_Init();
	/* Initialisiere Display */
	lcd_reset();
	/* Hintergrundbeleuchtung einschalten */
	D_SPI_LEDHigh();
	/* SPI Speed auf Max einstellen */
	D_SPI_ChangeSPISpeed(SPI_BaudRatePrescaler_2);



	lcd_clear(COLOR_BLACK);

	/*
	// Beispiele für die TFT Lib
	lcd_fillRect(0,0,50,50, COLOR_RED);
	lcd_fillRect(55,0,105,50, COLOR_BLUE);
	lcd_fillRect(110,0,160,50, COLOR_GREEN);
	lcd_drawRect(165,0,215,100, COLOR_BLACK);


	lcd_verticalLine(10, 120, 60, COLOR_RED);
	lcd_verticalLine(20, 60, 120, COLOR_BLACK);

	lcd_horizontalLine(0, 130, 110, COLOR_BLUE);
	lcd_horizontalLine(0, 80, 60, COLOR_YELLOW);

	lcd_horizontalLine(0, 200, 110, COLOR_GREEN);
	lcd_horizontalLine(120, 200, 60, COLOR_YELLOW);

	lcd_drawLine(160, 120, 200, 90, COLOR_BLACK);

	lcd_drawCircle(160, 120, 55, COLOR_BLACK);
	lcd_fillCircle(250, 40, 20, COLOR_RED);

	lcd_drawChar(10, 6, 'H', FONT8X12, COLOR_WHITE, COLOR_RED);
	lcd_drawChar(18, 6, 'i', FONT8X12, COLOR_WHITE, COLOR_RED);
	lcd_drawChar(26, 6, ' ', FONT8X12, COLOR_WHITE, COLOR_RED);
	lcd_drawChar(34, 6, '!', FONT8X12, COLOR_WHITE, COLOR_RED);

	lcd_drawString(10, 18, "Seb is", FONT8X8, COLOR_WHITE, COLOR_RED);
	lcd_drawString(10, 26, "awesome", FONT8X8, COLOR_WHITE, COLOR_RED);

	lcd_drawInt(10, 34, -1234, FONT8X8, COLOR_BLUE, COLOR_RED);
	lcd_drawHex(10, 42, 4154, FONT8X12, COLOR_BLUE, COLOR_RED);
	*/

	sek = 0;
	min = 20;
	hour = 14;
	flag = 1;

	Init_Timer2();
	NVIC_Configuration();

	/* Infinite loop */
	while (1)
	{
		//Bildschirm wird refresht
		displayClock();
	}
}