Esempio n. 1
0
int main(void) {
    int number_presses = 0;

    /* Initialize all of the LEDs */
    ledInitAll();
    /* Initialize both of the pushbuttons */
    pushbuttonInitAll();

    /* initially orange LED should be on and all others should be off */
    ledOrangeOn();

    while(1) {
        if (sw1In()) {
            /* avoid contact bounce */
            delay(DELAY_LIMIT);

            number_presses++;
            if (number_presses == 4) {
                number_presses = 0;
            }

            if (number_presses == 0) {
                ledOrangeOn();
            } else {
                ledOrangeOff();
            }

            if (number_presses == 1) {
                ledYellowOn();
            } else {
                ledYellowOff();
            }

            if (number_presses == 2) {
                ledGreenOn();
            } else {
                ledGreenOff();
            }

            if (number_presses == 3) {
                ledBlueOn();
            } else {
                ledBlueOff();
            }

            /* wait until button released before checking if pushed again */
            while(sw1In()) { ; }
        }
    }

    return 0;
}
Esempio n. 2
0
int fgetc_button(Stream *stream) {
    if (stream->device_instance == BUTTON_SW1) {
        if (sw1In()) {
            /* wait until button released before checking if pushed again */
            while(sw1In()) { ; }
            return 1;
        }
        return 0;
    }
    if (stream->device_instance == BUTTON_SW2) {
        if (sw2In()) {
            /* wait until button released before checking if pushed again */
            while(sw2In()) { ; }
            return 1;
        }
        return 0;
    }
    return INVALID_BUTTON;
}
Esempio n. 3
0
/*
* increment counter value in circular manner, call changestate()
* which turns on one LED and turns off others depending upon
* counter value.
*/
void rotate()
{
	const unsigned long int delayCount = 0x7ffff;
	int counter = 0;
	changestate(counter);
	while(1) 
	{
		if(sw1In()) 
		{
			counter = ((counter + 1) % 4);//move to next led
			changestate(counter);
			delay(delayCount);//wait for switch to be depressed
		}
	}
}
Esempio n. 4
0
/*
*   Implements read interface.
*   Parameters:
*       o void *fp - stream to read.
*       o char* buff - character read into buff.
*       Return : Number of bytes read
*/
int btn_read(void *fp,char* buff)
{
	struct btn_stream* stream = (struct btn_stream*)fp;
	int result = 0;
	switch(stream->minor)
	{
		case ONE:
			result = sw1In();				
			break;
		case TWO:
			result = sw2In();				
			break;
		default:
			return 0;
	}
	*buff = (result > 0) ? '1' : '0';
	return 1;
}
Esempio n. 5
0
static int cmd_therm2ser(int argc, char *argv[])
{
	if(argc > 1)
	{
		my_errno = TOO_MANY_ARGUMENTS;
		return 1;
	}
	int rfd = svc_open("/ttr",'r');
	if(rfd > 0)
	{
		char buff;int val;
		val = svc_read(rfd,&buff);
		while(!sw1In())
		{
			char temp[8];
			sprintf(temp,"%d\r\n",val);
			uprintf(temp);
			val = svc_read(rfd,&buff);
		}
		svc_close(rfd);
		return 0;
	}
	return 1;
}