Connect USB HID Barcode Scanner and Scan any product. Add a case for storing your products in the database

Dependencies:   USBHost mbed

Fork of USBHostKeyboard_HelloWorld by Samuel Mokrani

Revision:
7:4e0c80b26ba6
Parent:
1:2063e3713a99
--- a/main.cpp	Thu Mar 14 14:22:49 2013 +0000
+++ b/main.cpp	Sun Mar 15 11:37:05 2015 +0000
@@ -1,12 +1,39 @@
 #include "mbed.h"
 #include "USBHostKeyboard.h"
-
+int price=0,items=0,temp=0;
+unsigned long long int code=0;
 DigitalOut led(LED1);
-
+void update_price(int p);
 void onKey(uint8_t key) {
-    printf("Key: %c\r\n", key);
+    printf("%c", key);
+    if(key!=0x0A)
+    {
+    temp=key;
+    temp-=48;
+    code=temp+code*10;
+    }
+    else
+    {
+    switch(code)
+    {
+        case 42204268: update_price(200);
+        break;
+        case 8906002080021: update_price(25);
+        break;
+        case 8904043901015: update_price(17);
+        break;
+        case 8904004403756:update_price(36);
+        break;
 }
-
+code=0;
+}
+}
+void update_price(int p)
+{
+                        items++;
+                        price+=p;
+                        printf("No. of items=%d\tPrice=Rs.%d\n",items,price);
+                        }
 void keyboard_task(void const *) {
     
     USBHostKeyboard keyboard;