Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
brettwatty committed Sep 21, 2018
1 parent 6c75603 commit 7efb255
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions ASCD_Test_Barcode_Scanner.ino
@@ -0,0 +1,69 @@
#include <hidboot.h> //Barcode Scanner
#include <usbhub.h> //Barcode Scanner
#ifdef dobogusinclude //Barcode Scanner
#include <spi4teensy3.h> //Barcode Scanner
#endif


// USB Host Shield - Barcode Scanner
class KbdRptParser : public KeyboardReportParser
{

protected:
virtual void OnKeyDown (uint8_t mod, uint8_t key);
virtual void OnKeyPressed(uint8_t key);
};

KbdRptParser Prs;
USB Usb;
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);

// Get Barcode
char barcodeString[25] = "";
bool barcodeStringCompleted = false;


void setup()
{
Serial.begin(9600);
char usbInit[25];
sprintf(usbInit, "%-20s", Usb.Init() == -1 ? "USB: Did not start" : "USB: Started");
Serial.println(usbInit);
HidKeyboard.SetReportParser(0, &Prs);
}

void loop()
{

Usb.Task(); //Barcode Scanner

}

void processBarcode(int keyInput)
{
//Barcode Scanner
if (keyInput == 19) //Return Carriage ASCII Numeric 19
{
barcodeStringCompleted = true;
Serial.println(barcodeString);
strcpy(barcodeString, "");

//something here <-----------------------------------------------------------------------------
} else {
sprintf(barcodeString, "%s%c", barcodeString, (char)keyInput);
barcodeStringCompleted = false;
}
}

void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
//Barcode Scanner
uint8_t c = OemToAscii(mod, key);
if (c) OnKeyPressed(c);
}

void KbdRptParser::OnKeyPressed(uint8_t key)
{
//Barcode Scanner
processBarcode(key);
};

0 comments on commit 7efb255

Please sign in to comment.