
USB BARCODE READER
Revision 5:e163f0e428ac, committed 2018-07-02
- Comitter:
- shivanandgowdakr
- Date:
- Mon Jul 02 12:11:51 2018 +0000
- Parent:
- 4:2ca820a42fd5
- Commit message:
- USB BARCODE READER
Changed in this revision
USBHOST.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/USBHOST.lib Fri Apr 28 08:03:04 2017 +0000 +++ b/USBHOST.lib Mon Jul 02 12:11:51 2018 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/USBHOST/#d3ac9e1c0035 +https://os.mbed.com/users/shivanandgowdakr/code/USBHOST/#ccd0ac9ae1c9
--- a/main.cpp Fri Apr 28 08:03:04 2017 +0000 +++ b/main.cpp Mon Jul 02 12:11:51 2018 +0000 @@ -7,6 +7,8 @@ DigitalOut led(LED1); + int index=0; +char Barcode[50]; void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) { printf("buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z); } @@ -31,22 +33,57 @@ } } void onKey(uint8_t key) { - printf("Key: %c\r\n", key); + + // printf("%c\r", key); + + if(index>=51) + { + + + printf(" Limit Exceeded \r\n "); + printf(" Please Re Enter \r\n "); + index=0; + memset(Barcode,'\0',50); + return; + } + if((key!=0x0A)) + { + Barcode[index]=key; + index++; + //printf("%s \r\n",Barcode); + } + + else if((key==0x0A) &&(index<=50)) + { + Barcode[index]='\0'; + printf("BARCODE : %s \r\n",Barcode); + memset(Barcode,'\0',50); + index=0; + } + + else if((key==0x0A) && (index>=51)) + { + + printf(" Too Many Charecters : %s \r\n",Barcode); + printf(" Invalid Barcode\r\n"); + + } + } -void keyboard_task(void const *) { + + +void BarCodeReader_task(void const *) { - USBHostKeyboard keyboard; + USBHostKeyboard BarCodeReader; while(1) { // try to connect a USB keyboard - while(!keyboard.connect()) + while(!BarCodeReader.connect()) Thread::wait(500); - // when connected, attach handler called on keyboard event - keyboard.attach(onKey); - + BarCodeReader.attach(onKey); // wait until the keyboard is disconnected - while(keyboard.connected()) + while(BarCodeReader.connected()) Thread::wait(500); } } @@ -105,9 +142,11 @@ } int main() { - Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4); - Thread mouseTask(mouse_task, NULL, osPriorityNormal, 1024* 4); - Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 1024 * 4); + + memset(Barcode,'\0',20); + Thread msdTask(msd_task, NULL, osPriorityNormal, 4096); + Thread mouseTask(mouse_task, NULL, osPriorityNormal, 4096); + Thread BarCodeTask(BarCodeReader_task, NULL, osPriorityNormal, 4096); while(1) { led=!led;