Hi All,
I’m trying to get the below code working on a Uno with a Keyes USB shield. I’m getting the following errors with the line ‘HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);’
BarcodeScanner:19: error: expected constructor, destructor, or type conversion before ‘<’ token
BarcodeScanner:22: error: expected class-name before ‘{’ token
BarcodeScanner.ino: In member function ‘virtual void KbdRptParser::OnKeyDown(uint8_t, uint8_t)’:
BarcodeScanner:31: error: ‘OemToAscii’ was not declared in this scope
BarcodeScanner.ino: In function ‘void setup()’:
BarcodeScanner:73: error: ‘Keyboard’ was not declared in this scope
BarcodeScanner:73: error: ‘HIDReportParser’ was not declared in this scope
BarcodeScanner:73: error: expected primary-expression before ‘)’ token
I’d appreciate some assistance!
Thanks.
/*
Portable barcode scanner. Uses USB HID barcode scanner, Arduino Board, USB Host Shield and I2C LCD display
Original code from http://www.circuitsathome.com/mcu/connecting-barcode-scanner-arduino-usb-host-shield
Written by Oleg Mazurov
Mods by Shane Frost 20 Aug 2014
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <avr/pgmspace.h>
#include <Usb.h>
#define DISPLAY_WIDTH 16
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
USB Usb;
//USBHub Hub(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);
class KbdRptParser : public KeyboardReportParser
{
protected:
virtual void OnKeyDown (uint8_t mod, uint8_t key);
virtual void OnKeyPressed(uint8_t key);
};
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
uint8_t c = OemToAscii(mod, key);
if (c)
OnKeyPressed(c);
}
/* what to do when symbol arrives */
void KbdRptParser::OnKeyPressed(uint8_t key)
{
static uint32_t next_time = 0; //watchdog
static uint8_t current_cursor = 0; //tracks current cursor position
if( millis() > next_time ) {
lcd.clear();
current_cursor = 0;
delay( 5 ); //LCD-specific
lcd.setCursor( 0,0 );
}//if( millis() > next_time ...
next_time = millis() + 200; //reset watchdog
if( current_cursor++ == ( DISPLAY_WIDTH + 1 )) { //switch to second line if cursor outside the screen
lcd.setCursor( 0,1 );
}
Serial.println( key );
lcd.print( key );
};
KbdRptParser Prs;
void setup()
{
Serial.begin( 115200 );
Serial.println("Start");
if (Usb.Init() == -1) {
Serial.println("OSC did not start.");
}
delay( 200 );
Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);
// set up the LCD's number of columns and rows:
lcd.begin(DISPLAY_WIDTH, 2);
lcd.clear();
lcd.noAutoscroll();
lcd.print("Ready");
delay( 200 );
}
void loop()
{
Usb.Task();
}