From 62a54fe376d0e1325a8eb2b411005e523473f5b2 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 28 Jan 2013 01:21:08 +0000 Subject: renamed usb stream to stdio git-svn-id: https://svn.spreadspace.org/avr/trunk@89 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- usb-i2c-sl018/tuer-rfid.c | 62 +++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/usb-i2c-sl018/tuer-rfid.c b/usb-i2c-sl018/tuer-rfid.c index ec36d6e..492d32d 100644 --- a/usb-i2c-sl018/tuer-rfid.c +++ b/usb-i2c-sl018/tuer-rfid.c @@ -77,8 +77,8 @@ typedef struct __attribute__((__packed__)) SL018CMD_MESSAGE * twi_message = (SL018CMD_MESSAGE *) &twi_rcv_buff; uint8_t card_status =0; -FILE usb_stream; -FILE * usb = &usb_stream; +FILE stdio_stream; +FILE * stdio = &stdio_stream; #define KEY_LEN_MAX (sizeof(keyslot_t) - 1) @@ -127,7 +127,7 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = void EVENT_USB_Device_ConfigurationChanged(void) { CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface); - CDC_Device_CreateStream(&VirtualSerial_CDC_Interface,usb); + CDC_Device_CreateStream(&VirtualSerial_CDC_Interface,stdio); } void EVENT_USB_Device_ControlRequest(void) @@ -137,7 +137,7 @@ void EVENT_USB_Device_ControlRequest(void) void EVENT_USB_Device_Disconnect(void) { - Serial_CreateStream(usb); + Serial_CreateStream(stdio); } /* end LUFA CDC-ACM specific definitions*/ @@ -207,36 +207,36 @@ bool check_card(unsigned char * uid, uint8_t uid_len) return 0; } -void flash_eeprom_from_usb(void) +void flash_eeprom_from_stdio(void) { keyslot_t keyslot; uint8_t keyslot_pos=0; uint8_t byte_pos=0; - fprintf(usb,"Flashing keys:\n\r"); - fflush(usb); + fprintf(stdio,"Flashing keys:\n\r"); + fflush(stdio); for(keyslot_pos=0;keyslot_pos0) { - keyslot.byte[byte_pos++]=fgetc(usb); + keyslot.byte[byte_pos++]=fgetc(stdio); BytesReceived--; if (byte_pos == sizeof(keyslot)) { byte_pos=0; eeprom_update_block(&keyslot,&keyslots[keyslot_pos],sizeof(keyslot)); keyslot_pos++; - fprintf(usb,"."); - fflush(usb); + fprintf(stdio,"."); + fflush(stdio); led_toggle(); } } CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); } - fprintf(usb,"\n"); + fprintf(stdio,"\n"); } -void dump_eeprom_to_usb(void) +void dump_eeprom_to_stdio(void) { keyslot_t keyslot; uint8_t keyslot_pos=0; @@ -245,8 +245,8 @@ void dump_eeprom_to_usb(void) { eeprom_read_block(&keyslot,&keyslots[keyslot_pos],sizeof(keyslot)); for (uint8_t i=0; i< sizeof(keyslot); i++) - fprintf(usb,"%02X",keyslot.byte[i]); - fprintf(usb,"\n\r"); + fprintf(stdio,"%02X",keyslot.byte[i]); + fprintf(stdio,"\n\r"); } } @@ -255,17 +255,17 @@ bool sl018_send_buffer_check_error(const unsigned char * buffer) SL018CMD_MESSAGE * send_twi_message = (SL018CMD_MESSAGE *) (buffer+1); if(sl018_send_buffer(buffer)) { - fprintf(usb, "I2C error\n\r"); + fprintf(stdio, "I2C error\n\r"); return 0; } else { if(twi_message->status) { - fprintf(usb,"SL018 Cmd,Error: %02X,%02X\n\r",twi_message->command,twi_message->status); + fprintf(stdio,"SL018 Cmd,Error: %02X,%02X\n\r",twi_message->command,twi_message->status); return 0; } if(send_twi_message->command != twi_message->command) { - fprintf(usb,"SL018 Cmd missmatch: send, rcv: %02X,%02X\n\r",send_twi_message->command,twi_message->command); + fprintf(stdio,"SL018 Cmd missmatch: send, rcv: %02X,%02X\n\r",send_twi_message->command,twi_message->command); } } return 1; @@ -279,53 +279,53 @@ void handle_cmd(uint8_t cmd) case 'f': //get cardreader firmware version if(sl018_send_buffer_check_error(SL018CMD_ComGetFirmwareVersion)) { - fprintf(usb, "%s\n\r",twi_message->data); + fprintf(stdio, "%s\n\r",twi_message->data); } break; case '4': //turn cardreader led off if(sl018_send_buffer_check_error(SL018CMD_ComRedLedOff)) - fprintf(usb, "ok\n\r"); + fprintf(stdio, "ok\n\r"); break; case '5': //turn cardreader led on if(sl018_send_buffer_check_error(SL018CMD_ComRedLedOn)) - fprintf(usb, "ok\n\r"); + fprintf(stdio, "ok\n\r"); break; case 'e': //flash eeprom - flash_eeprom_from_usb(); + flash_eeprom_from_stdio(); break; case 'd': //flash eeprom - dump_eeprom_to_usb(); + dump_eeprom_to_stdio(); break; case 's': //get eeprom size - fprintf(usb,"%d\n\r",EEPROM_SIZE); + fprintf(stdio,"%d\n\r",EEPROM_SIZE); break; - default: fprintf(usb, "error, unknown command %02X\n\r",cmd); return; + default: fprintf(stdio, "error, unknown command %02X\n\r",cmd); return; } } void card_in_action(void) { uint8_t pos; - fprintf(usb, "CARD IN: "); + fprintf(stdio, "CARD IN: "); if(sl018_send_buffer_check_error(SL018CMD_ComSelectCard)) { for (pos=twi_message->len - 4 ; pos< 255; pos--) { - fprintf(usb,"%02X",twi_message->data[pos]); + fprintf(stdio,"%02X",twi_message->data[pos]); } - fprintf(usb, "\n\r"); + fprintf(stdio, "\n\r"); uint8_t type = twi_message->data[twi_message->len-1-sizeof(twi_message->command)-sizeof(twi_message->status)]; if (0data[0],twi_message->len-1-sizeof(twi_message->command)-sizeof(twi_message->status))) { sl018_send_buffer_check_error(SL018CMD_ComRedLedOn); - fprintf(usb,"open\n\r"); + fprintf(stdio,"open\n\r"); _delay_ms(255); sl018_send_buffer_check_error(SL018CMD_ComRedLedOff); } } else { - fprintf(usb,"Unknown Card Type %02x\n\r",type); + fprintf(stdio,"Unknown Card Type %02x\n\r",type); } } } @@ -341,11 +341,11 @@ int main(void) TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 200000)); sei(); Serial_Init(115200,false); - Serial_CreateStream(usb); + Serial_CreateStream(stdio); for(;;) { int16_t BytesReceived = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); if(BytesReceived > 0) { - handle_cmd(fgetc(usb)); + handle_cmd(fgetc(stdio)); } if(CARD_BOOL != card_status) { -- cgit v1.2.3