Hi,
I am trying to use a library from Playing with Fusion to read temperature data from a MAX31865 chip. When I use the library in the .ino file it works, but when I try to encapsulate the access into a separate class, I get a compiler error that I do not understand. I am using Atmel studio 6.2 with the Visual Micro plugin, but the same compiler error occurs when I use the Arduino IDE. Here are the relevant parts of code.
The library defines in it's header file a constructor that accepts a pin number for the chip select line:
class PWFusion_MAX31865_RTD
{
public:
// constructor
PWFusion_MAX31865_RTD(int8_t CSx);
// skipping the rest
};
I made a new class, and this is the header file:
// need to use absolute path otherwise the library is not found
// somehow the path is not set correct, but this is a different problem
#include "C:/.../PlayingWithFusion_MAX31865.h"
#include "C:/...PlayingWithFusion_MAX31865_STRUCT.h"
// skipping some more includes
class TemperatureClass
{
protected:
const int8_t CS0_PIN = 9;
// this causes a compile error: 'CS0_PIN' is not a type
PWFusion_MAX31865_RTD rtd_ch0(CS0_PIN);
// skipping the rest
};
// this was suggested by the Visual Micro template, not sure
// why this construct is used
extern TemperatureClass Temperature;
Why is the compiler expecting a type? Am I not instantiating a variable rtd_ch0 by calling the constructor of class PWFusion_MAX31865_RTD in the line that causes the compile error?
I need to access variable rtd_ch0 from multiple methods, so it should be a member variable of the Temperature class. I could probably declare a pointer to class PWFusion_MAX31865_RTD and instantiate an object in the constructor of Temperature class, but I would still like to understand what I am doing wrong, as it would be the more elegant solution.
Thanks,
Kurt