Sorry I'm a total newb to c++ and boy does it have some interesting error messages compared to java and c#
I have the following: where RainMaker is a public property on a
Rain maker looks like so:
Unfortunately I'm getting an error:
error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&WeatherCloud::RainComplete' [-fpermissive]
rainMaker.Initialise(&RainComplete);
I was wondering the best way to correct this?
I'd prefer only the cloud knows about the rain etc but I am new to c++ syntax which is throwing me..
Thanks
I have the following: where RainMaker is a public property on a
Code:
class WeatherCloud : public Stepper
{
public:
WeatherCloud(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, void (*callback)())
:Stepper(20, pin1, pin2, pin3, pin4)
{
OnComplete = callback;
stepperStatus = STOPPED;
TotalSteps = STEPS;
}
StepperStatus stepperStatus; //Direction to run the motor
RainMaker rainMaker;
void(*OnComplete)(); //completion callback
private:
unsigned long lastUpdate; //last update of position
uint16_t TotalSteps; //Total number of steps
uint16_t Index; //current step within pattern
byte bottomHallSensorState; // hall sensor state
volatile int topStepperSwitchState = 0; //volatile because is triggered by an interrupt as the motor was straining
public:
void Initialise() {
Serial.println("--Init CLOUD--");
//Hall Setup For Stops
pinMode(BOTTOM_HALL, INPUT);
pinMode(TOP_SWITCH, INPUT);
//Rain peristaltic pump relay init
pinMode(PUMP_PIN, OUTPUT);
bottomHallSensorState = digitalRead(BOTTOM_HALL);
// The screw pitch is 0.5mm so total length is 80mm, so 160 revolution is the total length of the stepper shaft.
while (bottomHallSensorState == HIGH)
{
step(-20 * 40);
bottomHallSensorState = digitalRead(BOTTOM_HALL);
Serial.println("--no hall found--");
}
stepperStatus = STOPPED;
Serial.println("--End Init CLOUD--");
Serial.println("--Init Pump--");
rainMaker.Initialise(&RainComplete);
Serial.println("--End Init Pump--");
}
void RainComplete() {
Serial.println("--RAIN COMPLETE--");
}
};
Rain maker looks like so:
Code:
class RainMaker
{
public:
void(*OnComplete)(); //completion callback
int pumpState = LOW;
private:
long lastTimePumpCameOn = 0; //Store the last time the pump was updated
const long pumpInterval = 2000;
public:
RainMaker() {
}
void Initialise(void(*callback)()) {
digitalWrite(PUMP_PIN, pumpState);
OnComplete = callback;
}
void MakeItRain() {
lastTimePumpCameOn = millis();
pumpState = HIGH;
digitalWrite(PUMP_PIN, pumpState);
}
void Update() {
unsigned long currentMillis = millis();
//If it is raining
if(pumpState == HIGH) {
if(currentMillis - lastTimePumpCameOn > pumpInterval) {
pumpState = LOW;
digitalWrite(PUMP_PIN, pumpState);
// save the last time the pump was turned off
lastTimePumpCameOn = currentMillis;
OnComplete();
}
}
}
};
Unfortunately I'm getting an error:
error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&WeatherCloud::RainComplete' [-fpermissive]
rainMaker.Initialise(&RainComplete);
I was wondering the best way to correct this?
I'd prefer only the cloud knows about the rain etc but I am new to c++ syntax which is throwing me..
Thanks