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; }
/* * 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; }