Skip to content

Commit

Permalink
Merge pull request #19 from zettaface/master
Browse files Browse the repository at this point in the history
added getNextTrigger(AlarmID_t ID), const qualifiers for methods
  • Loading branch information
PaulStoffregen committed Mar 17, 2018
2 parents 46f316c + 1c56824 commit aff8462
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
28 changes: 18 additions & 10 deletions TimeAlarms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void TimeAlarmsClass::write(AlarmID_t ID, time_t value)
}

// return the value for the given alarm ID
time_t TimeAlarmsClass::read(AlarmID_t ID)
time_t TimeAlarmsClass::read(AlarmID_t ID) const
{
if (isAllocated(ID)) {
return Alarm[ID].value ;
Expand All @@ -132,7 +132,7 @@ time_t TimeAlarmsClass::read(AlarmID_t ID)
}

// return the alarm type for the given alarm ID
dtAlarmPeriod_t TimeAlarmsClass::readType(AlarmID_t ID)
dtAlarmPeriod_t TimeAlarmsClass::readType(AlarmID_t ID) const
{
if (isAllocated(ID)) {
return (dtAlarmPeriod_t)Alarm[ID].Mode.alarmType ;
Expand All @@ -153,7 +153,7 @@ void TimeAlarmsClass::free(AlarmID_t ID)
}

// returns the number of allocated timers
uint8_t TimeAlarmsClass::count()
uint8_t TimeAlarmsClass::count() const
{
uint8_t c = 0;
for(uint8_t id = 0; id < dtNBR_ALARMS; id++) {
Expand All @@ -163,20 +163,20 @@ uint8_t TimeAlarmsClass::count()
}

// returns true only if id is allocated and the type is a time based alarm, returns false if not allocated or if its a timer
bool TimeAlarmsClass::isAlarm(AlarmID_t ID)
bool TimeAlarmsClass::isAlarm(AlarmID_t ID) const
{
return( isAllocated(ID) && dtIsAlarm(Alarm[ID].Mode.alarmType) );
}

// returns true if this id is allocated
bool TimeAlarmsClass::isAllocated(AlarmID_t ID)
bool TimeAlarmsClass::isAllocated(AlarmID_t ID) const
{
return (ID < dtNBR_ALARMS && Alarm[ID].Mode.alarmType != dtNotAllocated);
}

// returns the currently triggered alarm id
// returns dtINVALID_ALARM_ID if not invoked from within an alarm handler
AlarmID_t TimeAlarmsClass::getTriggeredAlarmId()
AlarmID_t TimeAlarmsClass::getTriggeredAlarmId() const
{
if (isServicing) {
return servicedAlarmId; // new private data member used instead of local loop variable i in serviceAlarms();
Expand Down Expand Up @@ -211,7 +211,7 @@ void TimeAlarmsClass::waitForRollover( dtUnits_t Units)
waitForDigits(0, Units);
}

uint8_t TimeAlarmsClass::getDigitsNow( dtUnits_t Units)
uint8_t TimeAlarmsClass::getDigitsNow( dtUnits_t Units) const
{
time_t time = now();
if (Units == dtSecond) return numberOfSeconds(time);
Expand All @@ -222,7 +222,7 @@ uint8_t TimeAlarmsClass::getDigitsNow( dtUnits_t Units)
}

//returns isServicing
bool TimeAlarmsClass::getIsServicing()
bool TimeAlarmsClass::getIsServicing() const
{
return isServicing;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ void TimeAlarmsClass::serviceAlarms()
}

// returns the absolute time of the next scheduled alarm, or 0 if none
time_t TimeAlarmsClass::getNextTrigger()
time_t TimeAlarmsClass::getNextTrigger() const
{
time_t nextTrigger = 0;

Expand All @@ -269,6 +269,15 @@ time_t TimeAlarmsClass::getNextTrigger()
return nextTrigger;
}

time_t TimeAlarmsClass::getNextTrigger(AlarmID_t ID) const
{
if (isAllocated(ID)) {
return Alarm[ID].nextTrigger;
} else {
return 0;
}
}

// attempt to create an alarm and return true if successful
AlarmID_t TimeAlarmsClass::create(time_t value, OnTick_t onTickHandler, uint8_t isOneShot, dtAlarmPeriod_t alarmType)
{
Expand All @@ -291,4 +300,3 @@ AlarmID_t TimeAlarmsClass::create(time_t value, OnTick_t onTickHandler, uint8_t

// make one instance for the user to use
TimeAlarmsClass Alarm = TimeAlarmsClass() ;

19 changes: 10 additions & 9 deletions TimeAlarms.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,29 @@ class TimeAlarmsClass
void delay(unsigned long ms);

// utility methods
uint8_t getDigitsNow( dtUnits_t Units); // returns the current digit value for the given time unit
uint8_t getDigitsNow( dtUnits_t Units) const; // returns the current digit value for the given time unit
void waitForDigits( uint8_t Digits, dtUnits_t Units);
void waitForRollover(dtUnits_t Units);

// low level methods
void enable(AlarmID_t ID); // enable the alarm to trigger
void disable(AlarmID_t ID); // prevent the alarm from triggering
AlarmID_t getTriggeredAlarmId(); // returns the currently triggered alarm id
bool getIsServicing(); // returns isServicing
AlarmID_t getTriggeredAlarmId() const; // returns the currently triggered alarm id
bool getIsServicing() const; // returns isServicing
void write(AlarmID_t ID, time_t value); // write the value (and enable) the alarm with the given ID
time_t read(AlarmID_t ID); // return the value for the given timer
dtAlarmPeriod_t readType(AlarmID_t ID); // return the alarm type for the given alarm ID
time_t read(AlarmID_t ID) const; // return the value for the given timer
dtAlarmPeriod_t readType(AlarmID_t ID) const; // return the alarm type for the given alarm ID

void free(AlarmID_t ID); // free the id to allow its reuse

#ifndef USE_SPECIALIST_METHODS
private: // the following methods are for testing and are not documented as part of the standard library
#endif
uint8_t count(); // returns the number of allocated timers
time_t getNextTrigger(); // returns the time of the next scheduled alarm
bool isAllocated(AlarmID_t ID); // returns true if this id is allocated
bool isAlarm(AlarmID_t ID); // returns true if id is for a time based alarm, false if its a timer or not allocated
uint8_t count() const; // returns the number of allocated timers
time_t getNextTrigger() const; // returns the time of the next scheduled alarm
time_t getNextTrigger(AlarmID_t ID) const; // returns the time of scheduled alarm
bool isAllocated(AlarmID_t ID) const; // returns true if this id is allocated
bool isAlarm(AlarmID_t ID) const; // returns true if id is for a time based alarm, false if its a timer or not allocated
};

extern TimeAlarmsClass Alarm; // make an instance for the user
Expand Down

0 comments on commit aff8462

Please sign in to comment.