Hi,
I'm creating a project to turn on & off my home's heat tapes (to melt snow on the roof to prevent ice dams) daily using the TimeAlarms.h library.
I'd like to create a HeatTape class that manages everything internally, including passing the onTickHandler (which is a function called by alarmRepeat). I'd like to define the onTickHandler within the HeatTape class because it uses a variable set within the class.
In my code below, I'd like to pass the HeatTapeClass::turnOn and HeatTapeClass::TurnOff functions to Alarm.alarmRepeat, but can not seem to do so. I've tried many variations including &HeatTape::turnOn without success.
Any suggestions are appreciated.
Thanks!
#include <Time.h>
#include <TimeAlarms.h>
class HeatTapeClass {
public:
// Properties
char name[10];
byte powerPin;
byte programPin;
byte hourOnLocation;
byte minuteOnLocation;
byte hourOffLocation;
byte minuteOffLocation;
AlarmId startAlarm;
AlarmId endAlarm;
// Methods
void init(char *theName,
byte thePowerPin,
byte theProgramPin,
byte theHourOnLocation,
byte theMinuteOnLocation,
byte theHourOffLocation,
byte theMinuteOffLocation
) {
strcpy(name, theName);
powerPin = thePowerPin;
programPin = theProgramPin;
hourOnLocation = theHourOnLocation;
minuteOnLocation = theMinuteOnLocation;
hourOffLocation = theHourOffLocation;
minuteOffLocation = theMinuteOffLocation;
startAlarm = Alarm.alarmRepeat( getHourOn(),
getMinuteOn(),
00, // seconds
turnOn // <----- how do I pass the HeatTapeClass::turnOn function here?
);
endAlarm = Alarm.alarmRepeat( getHourOff(),
getMinuteOff(),
00, // seconds
turnOff
);
};
boolean isOn() {
return digitalRead(powerPin);
};
void turnOn() {
digitalWrite(powerPin, HIGH);
};
void turnOff() {
digitalWrite(powerPin, LOW);
};
void toggleOnOff() {
digitalWrite(powerPin, !(isOn()));
};
boolean isProgramEnabled() {
return digitalRead(programPin);
};
void enableProgram() {
Alarm.enable(startAlarm);
Alarm.enable(endAlarm);
digitalWrite(progamPin, HIGH);
};
void disableProgram() {
Alarm.disable(startAlarm);
Alarm.disable(endAlarm);
digitalWrite(programPin, LOW);
};
byte getHourOn() { return EEPROM.read(hourOnLocation); };
byte getMinuteOn() { return EEPROM.read(minuteOnLocation); };
byte getHourOff() { return EEPROM.read(hourOffLocation); };
byte getMinuteOff() { return EEPROM.read(minuteOffLocation); };
void setHourOn(byte value) { EEPROM.write(hourOnLocation, value); };
void setMinuteOn(byte value) { EEPROM.write(minuteOnLocation, value); };
void setHourOff(byte value) { EEPROM.write(hourOffLocation, value); };
void setMinuteOff(byte value) { EEPROM.write(minuteOffLocation, value); };
};