Hello everyone,
I've bought the USB 2.0 shield from www.circuitsathome.com to play with a barcode scanner.
The scanner behaves like a hid keyboard so I used the demo keyboard code and took
everything out which I didn't need. (see attached code)
This code now gives in the serial monitor the value of the barcode ending
with an enter and a ctrl-j (ctrl-j seems to be an new line?)
So far so good, but... every time it sent a single character to the serial port.
After that the character is gone. I would like to have a returned value which
I can use in the loop. What is the best way to do this?
Any help would be highly appreciated
Thanks in advance! Roland
#include <hidboot.h>
#include <usbhub.h>
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endifclass KbdRptParser : public KeyboardReportParser
{
protected:
void OnKeyDown (uint8_t mod, uint8_t key);
void OnKeyPressed(uint8_t key);
};void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
uint8_t c = OemToAscii(mod, key);
if (c)
OnKeyPressed(c);
}void KbdRptParser::OnKeyPressed(uint8_t key)
{
Serial.print((char)key);
}USB Usb;
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
uint32_t next_time;
KbdRptParser Prs;void setup()
{
Serial.begin( 115200 );
#if !defined(MIPSEL)
while (!Serial); // Wait for serial port to connect
#endif
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
next_time = millis() + 5000;
HidKeyboard.SetReportParser(0, &Prs);}
void loop()
{
Usb.Task();
}