Compiling error

I'm trying to compile some sample code, but can't work it out. I'd really appreciate some help please!

This line

HIDBoot <HID_PROTOCOL_KEYBOARD>    Keyboard(&Usb);

throws the following error:
BarcodeScanner:19: error: expected constructor, destructor, or type conversion before '<' token

It's referencing the Usb.h library, which in turn references the hidboot library.

hidboot.h (19.3 KB)

hidboot.cpp (8.74 KB)

Hi, post your complete code please.

Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom...... :slight_smile:

Thanks Tom, as requested.

Pretty much everything is commented out until I can get this line sorted.

#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();

HIDBoot <HID_PROTOCOL_KEYBOARD>    Keyboard(&Usb);
//HIDBoot 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 );
    lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight
    lcd.clear();
    lcd.backlight();
    lcd.print("Barcode Reader");
    lcd.setCursor(0,1);
    lcd.print("Uno Version");
 
//    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();
}

Where did you get the code from and why are there angle brackets in this

HIDBoot <HID_PROTOCOL_KEYBOARD>    Keyboard(&Usb);

There are 2 similar lines

HIDBoot <HID_PROTOCOL_KEYBOARD>    Keyboard(&Usb);
//HIDBoot Keyboard(&Usb);

Perhaps the wrong one is commented out?

...R

Hi Robin,

Thanks for the response. I've no idea what the angle brackets are doing, and the comment on the line is original. This is why I'm stumped! Apparently other people have managed to get this working, but I can't even get it to compile.....

The source is from http://www.circuitsathome.com/mcu/connecting-barcode-scanner-arduino-usb-host-shieldand it is:

/*
 
Portable barcode scanner. Uses USB HID barcode scanner, Arduino Board, USB Host Shield and HD44780-compatible LCD display
 
  The circuit:
 * LCD RS pin to digital pin 7
 * LCD Enable pin to digital pin 6
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
*/
 
#include <LiquidCrystal.h>
#include <avr/pgmspace.h>
 
#include <avrpins.h>
#include <max3421e.h>
#include <usbhost.h>
#include <usb_ch9.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <address.h>
#include <hidboot.h>
 
#include <printhex.h>
#include <message.h>
#include <hexdump.h>
#include <parsetools.h>
 
#define DISPLAY_WIDTH 16
 
// initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
 
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();
}

The only actual changes that I've made are from a parallel LCD to I2C, and commented out most of the body to try and pinpoint the error.

Thanks for your help.

why are there angle brackets in this

Because there is a template involved. The HIDBoot template is trying to create an instance of the class that can deal with the type HID_PROTOCOL_KEYBOARD.

Thanks Robin, though I don't understand what you mean by a template. I understand how constructors & instances work, but I've never seen anything passed through the use of <>.

Any chance of expanding on it, as I've been trying everything that I can think of to resolve this, but failed miserably.

Thanks,
Shane

What version of the IDE do you use?

I get a different error:

error: no matching function for call to 'HIDBoot<1u>::HIDBoot(USB (*)())'

USB Usb();

HIDBoot <HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);

It compiles after removing the empty brackets. ( its not doing what you think. Compare it to the declaration of void loop(); for example ).

G'day pYro_65,

Mate, I'm using the Arduino 1.0.5-r2. IDE.

Shane

I had to add

#include <hidboot.h>

And, still there are problems. Which Arduino are you trying to compile this code for?

beerbotboffin:
and the comment on the line is original.

But did you try swapping the comment with the other line? and what happened?

Thanks Robin, though I don't understand what you mean by a template.

It was @PaulS who mentioned templates and I hope he will expand because I don't know either.

USB     Usb();

HIDBoot <HID_PROTOCOL_KEYBOARD>    Keyboard(&Usb);




It compiles after removing the empty brackets. ( **its not doing what you think**.

This is an example of a common usage that drives me nuts - calling the instance of a class by the same name as the class. It gives the novice user the impression that the name of the instance is significant when it could be any old name.

...R

This is an example of a common usage that drives me nuts - calling the instance of a class by the same name as the class. It gives the novice user the impression that the name of the instance is significant when it could be any old name.

Could be worse. They could have called the instance myUsb. Now, there's something that drives me nuts.

Yep, removing the empty brackets solved the problem. :slight_smile:

Thank you very much guys and kudos to the both of you for sparing the time to help me out.

I am having the same problem. This is the beginning of my code. I added hidboot.h but nothing changes. The error is the following:

sketch_jan26a:47: error: 'HID_PROTOCOL_KEYBOARD' was not declared in this scope

/*
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>
#include <hidboot.h>


USB     Usb();
//USBHub     Hub(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD>    Keyboard(&Usb);