USB BARCODE READER
Diff: main.cpp
- Revision:
- 5:e163f0e428ac
- Parent:
- 3:a2c477c9da16
--- 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;