diff options
-rw-r--r-- | usb-i2c-sl018/tuer-rfid.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/usb-i2c-sl018/tuer-rfid.c b/usb-i2c-sl018/tuer-rfid.c index 1d85fbe..878e731 100644 --- a/usb-i2c-sl018/tuer-rfid.c +++ b/usb-i2c-sl018/tuer-rfid.c @@ -159,19 +159,27 @@ void flash_eeprom_from_usb(void) {
keyslot_t keyslot;
uint8_t keyslot_pos=0;
- fprintf(usb,"Flashing keys: ");
-
+ uint8_t byte_pos=0;
+ fprintf(usb,"Flashing keys:\n\r");
+ fflush(usb);
for(keyslot_pos=0;keyslot_pos<EEPROM_SIZE/sizeof(keyslot);)
{
int16_t BytesReceived = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface);
- while(BytesReceived >= sizeof(keyslot)) {
- fread(&keyslot,sizeof(keyslot),1,usb);
- eeprom_update_block(&keyslot,&keyslots[keyslot_pos],sizeof(keyslot));
- BytesReceived-=sizeof(keyslot);
- keyslot_pos++;
- led_toggle();
- fprintf(usb,".");
+ while(BytesReceived >0) {
+ keyslot[byte_pos++]=fgetc(usb);
+ BytesReceived--;
+ if (byte_pos == sizeof(keyslot))
+ {
+ byte_pos=0;
+ eeprom_write_block(&keyslot,&keyslots[keyslot_pos],sizeof(keyslot));
+ keyslot_pos++;
+ fprintf(usb,".");
+ fflush(usb);
+ led_toggle();
+ }
}
+ CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
+ USB_USBTask();
}
fprintf(usb,"\n");
}
@@ -265,7 +273,6 @@ int main(void) cpu_init();
led_init();
- led_on();
USB_Init();
TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 200000));
sei();
|