I am building a sketch that uses multiple class libraries. The classes are located in the library folder, each class in its own folder. In development, I occasionally encounter cases where one of the class libraries cannot find arduino.h and some other class definitions. Here is the entire sketch (slimmed down a bit):
//GenericRemoteController.ino
#include <GenericRemoteController.h>
GenericRemoteController *controller;
#if JOYSTICK_TYPE_SHIELD
#include <JoystickShield.h>
#elif JOYSTICK_TYPE_SIMPLE
#include <SimpleJoystick.h>
#endif
void setup()
{
Serial.begin(115200);
Serial.println(F("Initializing"));
controller = new GenericRemoteController();
controller->begin();
}
void loop(){}
Here is GenericRemoteController.h:
#ifndef _GENERICREMOTECONTROLLER_h
#define _GENERICREMOTECONTROLLER_h
#include "arduino.h"
#define JOYSTICK_TYPE_SIMPLE true
#define JOYSTICK_TYPE_SHIELD false
#if JOYSTICK_TYPE_SHIELD
#include <JoystickShield.h>
#elif JOYSTICK_TYPE_SIMPLE
#include <SimpleJoystick.h>
SimpleJoystick *joystick;
#endif
// Define buffer sizes
#define COMMAND_BUFFER_SIZE 30
#define REPLY_BUFFER_SIZE 10
class GenericRemoteController {
public:
// Constructor
GenericRemoteController();
// Called from within setup function
void begin();
// Called from within loop function
void process();
// Communications buffers - used to construct
// messages to robot and replies to those messages.
char commandBuffer[COMMAND_BUFFER_SIZE];
int commandBufferIndex = 0;
char replyBuffer[REPLY_BUFFER_SIZE];
};
#endif
Here is SimpleJoystick.h:
#ifndef _SIMPLEJOYSTICK_h
#define _SIMPLEJOYSTICK_h
#include "arduino.h"
class SimpleJoystick
{
public:
SimpleJoystick();
void begin();
};
#endif
And here is the compiler error list:
Severity Code Description File Line
Warning In member function void GenericRemoteController::begin() D:\Documents\Arduino\GenericRemoteController\GenericRemoteController.ino -1
Error 16:2: error: expected ';' before 'joystick D:\Documents\Arduino\GenericRemoteController\GenericRemoteController.ino 16
Error (active) E1696 cannot open source file "arduino.h" d:\Documents\Arduino\libraries\SimpleJoystick\SimpleJoystick.h 6
Warning joystick = new SimpleJoystick()
The "expected ';' before 'joystick may be the culprit. If you can spot why this error is occurring or can help me make this better, I appreciate.