Arduino Library error: expected ')' before '*'

Hello,

I am getting a compiler error when I include a particular library and would appreciate ay help you may be able to offer. I am creating a program that will use P.I. Engineering Xkeys (HID USB Device) to control various pieces of equipment over a network. To get started I was adding all the libraries and doing what I could to make everything compatible but I am getting one error I do not understand. The library that causes the error is the XKeys library I got from here: GitHub - tstrausb/XKeys-Library-for-Arduino: A library to allow use of an X-Keys device on an Arduino microcontroller (used in conjunction with Circuits at Home USB Host Shield 2.0). I am trying to use and Arduino M0 pro.

This is the error:

In file included from /Users/Dan/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:69:0,
                from /Users/Dan/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/samd.h:105,
                from /Users/Dan/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/sam.h:470,
                from /Users/Dan/Library/Arduino15/packages/arduino/hardware/samd/1.6.17/cores/arduino/Arduino.h:48,
                from /var/folders/fg/sn_rc8791wz_bf661wmhj4pw0000gn/T/arduino_build_584621/sketch/Holy_Macros.ino.cpp:1:
/Users/Dan/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:516:38: error: expected ')' before '*' token
#define USB               ((Usb      *)0x41005000UL) /**< \brief (USB) APB Base Address */
                                     ^
/Users/Dan/Documents/Arduino/libraries/XKeys-Library-for-Arduino-master/hidxkeysrptparser.h:103:2: note: in expansion of macro 'USB'
 USB Usb;
 ^
/Users/Dan/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:516:38: error: expected ')' before '*' token
#define USB               ((Usb      *)0x41005000UL) /**< \brief (USB) APB Base Address */
                                     ^
/Users/Dan/Documents/Arduino/libraries/XKeys-Library-for-Arduino-master/hidxkeysrptparser.h:103:2: note: in expansion of macro 'USB'
 USB Usb;
 ^
Multiple libraries were found for "hid.h"
Used: /Users/Dan/Library/Arduino15/packages/arduino/hardware/samd/1.6.17/libraries/USBHost
Not used: /Users/Dan/Documents/Arduino/libraries/USBHost

This is my code (just includes):

#include <hidxkeysrptparser.h>
#include "Usb.h"    //USB Library for X-Keys

#include <MenuBackend.h>  //To create Menu
#include <Encoder.h>    //To read 2-bit quadrature encoder for Menu Navigation *Use pins with interrupts

#include <ClientBMDVideohubTCP.h>   //BlackMagic Videohub Router Library
#include <ClientBMDHyperdeckStudio.h>   //BlackMagic Hyperdeck Library
#include <ATEM.h>   //BlackMagic ATEM Video Switcher Library

#include <Adafruit_GFX.h> //Adafruit Graphic OLED Support
#include <Adafruit_SSD1306.h> //Adafruit Graphic OLED Support

#include <Wire.h>   //Wire for OLED display
#include <SPI.h>    //SPI for Ethernet Shield

#include <EthernetUdp2.h>   //Ethernet W5500
#include <EthernetClient.h>   //Ethernet W5500
#include <Dhcp.h>   //Ethernet W5500
#include <EthernetServer.h>   //Ethernet W5500
#include <Ethernet2.h>  //Ethernet W5500
#include <util.h> //Ethernet W5500
#include <Dns.h> //Ethernet W5500
#include <Twitter.h> //Ethernet W5500

void setup() {

}

void loop() {
  // put your main code here, to run repeatedly:
}

This is the header file of the library causing the error:

// (C) 2014 Thomas Strausbaugh
// See the README for additional credit where credit is due!

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// of the License.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

#if !defined(__HIDXKEYSRPTPARSER_H__)
#define __HIDXKEYSPARSER_H__

#if defined(ARDUINO) && ARDUINO >=100
#include "Arduino.h"
#else
#include <WProgram.h>
#endif

#include "hid.h"
#include "hiduniversal.h"
#include "Usb.h"

/****************************
Supported models are XK 4/8/16 
stick and XK 24/60/80/128.
****************************/

#define RPT_XKEYS_LEN		18
#define OUT_RPT_LEN		35
#define BL_BLUE			0
#define BL_RED			1
#define MODE_OFF		0
#define MODE_ON			1
#define MODE_FLASH		2
#define LED_GREEN		6
#define LED_RED			7

class XkeysReportParser : public HIDReportParser
{
public:

	uint8_t	STICK;
	uint8_t	PADSIZE;

	/**********If the public methods are called from within the class
	(i.e. from the OnKey methods), you do not need to denote them with
	<class_instance>.method. See example.***************************/


	XkeysReportParser();
	void init();
	virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
	void runLoop();

	/**********BL stepping methods are only supported on XK128 or on "Plus" or "Mobile" versions of other pads.************/
	void setBLSteps(uint8_t color, uint8_t *steps);
	  // use an array of 10 steps
	  // color: 0 for blue, 1 for red, 255 to reset all to factory default
	  // stepX: 0-255 for each
	void stepBLIntensity(uint8_t color, uint8_t incDec, uint8_t wrap);
	  // color: 0 for blue, 1 for red; incDec: 0 for lower, 1 for higher; wrap: 0 to wrap around, 1 to stop at limit
	/*****************************************************************************/

	void indexSetLEDs(uint8_t led, uint8_t state);
	void setFlashFreq(uint8_t freq); 
        // 0 is fastest, 255 is slowest (approx. 4 seconds)
	void indexSetBL(uint8_t keyId, uint8_t color, uint8_t mode); 
        // Xkeys sticks only have blue backlights--color is disregarded in this case but you must enter something
	void setRowBL(uint8_t row, uint8_t color, uint8_t mode); 
        // Xkeys sticks only have blue backlights--what you pass as color MUST evaluate to 0 and row must evaluate to 1
        // rows are 1 - 8 from top to bottom (entering row 0 will cause an error)
	void toggleBLs();
	  // any BLs that are on will go off. the same ones will come back on. Does not "reverse" the BLs.
	void setLEDs(boolean green, boolean red);
        // true for on and false for off
        // must use indexSetLEDs for flash mode
	void setBLintensity(uint8_t color, uint8_t intensity);
        // 0 is off and 255 is brightest
	void setUnitID(uint8_t unitID);
	  // 0 - 255
	void saveBLStateEEPROM(uint8_t save);
	  // anything other than 0 will save the current BL state as new startup default
	  // ********limited number of times this can be done! Use sparingly!**********
	void enableTimeStamp(uint8_t endis);
	  // 0 to disable, 1 to enable
	void reboot();
	  // supported on "Plus" or "Mobile" versions

protected:
	// Subclass XkeysReportParser and define these methods to receive events
	virtual void OnKeyUp(uint8_t keyId) {}; 
	virtual void OnKeyDown(uint8_t keyId) {};

private:
	USB Usb;
	HIDUniversal Hid;
	void sendCommand();
	void wipeArray();
	uint8_t		_blueIntensity;
	uint8_t		_redIntensity;
	uint8_t		_rowsBlue;
	uint8_t		_rowsRed;
	uint8_t		oldRpt[RPT_XKEYS_LEN];
	uint32_t		oldButtons[4];
	uint8_t		rpt[OUT_RPT_LEN];

};

#endif // __HIDXKEYSRPTPARSER_H__

Thanks for taking a look.

Either you will need to find another library that works and that does not have syntax errors in it, or you will have to go in and edit the library source files yourself and remove the syntax error.

Are you using Arduino IDE on windows? Or some other device/operating system?

Hello boylesg.

Unfortunately I could not find another library. I am using the Arduino IDE and use Xcode to view/edit the library files.

Based on the error code I got do you have any ideas on what the error may be. I may be in a little over my head with the level of coding used in libraries.

dwrigglesworth:
Hello boylesg.

Unfortunately I could not find another library. I am using the Arduino IDE and use Xcode to view/edit the library files.

Based on the error code I got do you have any ideas on what the error may be. I may be in a little over my head with the level of coding used in libraries.

It is just a bog standard compiler error.

If you are using a windows PC or laptop got to C:\Users\Greg\Documents\Arduino\libraries....except replace 'Greg' with what ever your windows login name is.

Open windows explorer and find 'My documents' if you are not confident navigating the Windows folder structure. In there you should find a folder named 'Arduino' and in that folder a subfolder called 'libraries'.

In there you will find all your arduino libraires that appear in the IDE menu - usually the name in the menu is the same as the folder name.

Find your library and open the source file specied in the compiler error and go to the line number specified in the compiler error and fix the syntax error.

Easily done!

Suggest you download and install 'Notepad++' It is a souped up version of Windows notepad that does programming language syntax highlighting and makes the above a bit easier.

A much more effective way to edit and debug the library would be to move the .h and .cpp files from the libraries folder to the sketch folder containing your .ino file.

Start the IDE and those files will appear as tabs along with your .ino sketch.

Then, change:

#include <hidxkeysrptparser.h>

To:

#include "hidxkeysrptparser.h"

Now, you’ll be able to fix the library errors and compile the results for testing.

After everything’s working, you can move the .h and .cpp files back to the libraries folder. Or, if this is the only sketch that is ever going to use them, just leave them where they are.

I am trying to use and Arduino M0 pro

The M0 has a #define statement that defines the name USB with some value. The other Arduinos do not.

The library you are using expects to define a class called USB. When the preprocessor sees the name USB, it substitutes the value that the M0 as defined for USB in place of the name. That is certainly not what the library author expected to have happen.

Some significant changes are going to be needed to the library to make it work with the M0.

Thank you all for the help. I learned a lot and I took a stab at it but I don't understand C++ enough yet to fix this.

Still I appreciate your responses. Editing library files in Arduino IDE is awesome!

I think the problem is a name conflict. The author of samd21g18a.h had the genius idea of creating a macro named USB (how original):

dwrigglesworth:

/Users/Dan/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:516:38: error: expected ')' before '*' token

#define USB              ((Usb      *)0x41005000UL) /**< \brief (USB) APB Base Address */

Then somewhere in the USB_Host_Shield_2 library there is an object type named USB, which is used by the XKeys library:

dwrigglesworth:

/Users/Dan/Documents/Arduino/libraries/XKeys-Library-for-Arduino-master/hidxkeysrptparser.h:103:2: note: in expansion of macro 'USB'

USB Usb;
^

Two completely different things with the same name, thus error.

I think the problem is a name conflict.

Sure it is. The solution is to rename the macro in one file, and find and change all the uses, or rename the class in the other file, and change all the instances to be instances of the new class.

Renaming the class seems easier to me, since there can only be one instance of it, and the instance name doesn't need to change.

I would like try and fix this. I could use some more help though. I admit that this is a little beyond me but I am trying to understand.

In the header file for the X keys library there is this line.

private:
	USB Usb;

I tried changing USB to USBX

private:
	USBX Usb;

But then I still get this error:

In file included from /Users/Dan/Documents/Arduino/Holy_Macros/Holy_Macros.ino:1:0:
hidxkeysrptparser.h:103: error: 'USBX' does not name a type
  USBX Usb;
  ^
exit status 1
'USBX' does not name a type

I dont know what to do from there. Any help would be appreciated.

The problem is the X-keys library is designed to be used with the USB Host Library 2.0 (UHL20) for the MAX3421E chip.

The Arduino SAMD boards have built-in USB OTG controllers (host or device) which are not compatible with the MAX3421E. The USB host API for Arduino SAMD boards is not compatible with the API for UHL20.

Even if the library compiles it may not work because of other differences. I have tried and am ready to give up porting over the USBH_MIDI driver to Zero.

But I have some tips that might help.

Change references to the USB class to the USBHost class.

For example,

old: USB Usb;
new: USBHost Usb;

Some API functions have been modified to return uint32_t instead of uint8_t. This results in compiler errors so more changes are required.

Understood. Thanks for the explanation.