Hello all;
I defined a struct in a library like this:
Header File:
struct srcLimits_t // source limits for DAC and Display for each source mode
{
srcLimits_t(); // a struct of arrays, 1 element for each source mode
int maxVal[4]; // maximum value for DAC = 2^n - 1 where n = no. of DAC bits
int minVal[4]; // minimum value for DAC - depends on mode
uint8_t resVal[4]; // minimum mode resolution, LSD for display, divisor for DAC Value
}
CPP File:
srcLimits_t::srcLimits_t()
{
/* Voltage Source */
maxVal[0] = 1023; //full count is 10.23V
minVal[0] = 0;
resVal[0] = 1; //each count is 10mV
/* Current Source */
maxVal[1] = 5115; //full count is 5.115A
minVal[1] = 0;
resVal[1] = 5; //each count is 5mA
/* Voltage Sink */
maxVal[2] = 1023; //full count is 10.23V
minVal[2] = 100; //1 volt minmum for voltage sink
resVal[2] = 1; //each count is 10mV
/* Current Sink */
maxVal[3] = 5120; //full count is 5.120A
minVal[3] = 5; //5mA minimum for current sink
resVal[3] = 5; //each count is 5mA
}
I use the struct in the sketch fine by declaring:
srcLimits_t srcLimits;
everything works as expected in the sketch.
But I would like to access srcLimits within a class from the same library that the struct is defined in
The header for the Class is:
class Source {
public:
//constructor
Source (byte selDAC, int ctrlDAC);
int updateSrc (uint8_t valToUpdate[], int newMode, int digit, int dir);
The CPP code is:
int Source::updateSrc (uint8_t valToUpdate[], int newMode, int digit, int dir)
.
.
if (newVal < srcLimits.minVal[newMode] || newVal > srcLimits.maxVal[newMode]) {
newVal = constrain (newVal, srcLimits.minVal[newMode], srcLimits.maxVal[newMode]);
The error I get is that srcLimits is not declared within the scope of this class. Is there a way to get global variables from a sketch visible within a library class? I would rather not have to pass the values as arguments.
Thanks ![]()