bug in the timealarm library

This post addresses the request for access to the alarm ID, I will follow up on 'day of week' in a later post.

The first version of this library was posted three years ago and did include the alarm ID in the callback.
Mellis from the Arduino team suggested that the API be simplified and I subsequently posted the current version that does not pass the alarm ID. If you are interested in the history, see this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1217881285

I had considered adding a method that could be invoked from the callback that would return the alarm id but had not seen a request for this up until now.

If you guys think it would be useful I can add the following method to the library:

AlarmID_t  getTriggeredAlarmId();  //returns the currently triggered  alarm id
// returns  dtINVALID_ALARM_ID if not invoked from within an alarm handler

This would enable a sketch along the following lines:

#include <Time.h>
#include <TimeAlarms.h>

AlarmID_t morningAlarmID, afternoonAlarmID, eveningAlarmID;

void setup()
{
  morningAlarmID   = Alarm.alarmRepeat(8,30,0, onAlarm); 
  afternoonAlarmID = Alarm.alarmRepeat(13,25,0,onAlarm); 
  eveningAlarmID   = Alarm.alarmRepeat(17,45,0,onAlarm);   
}

void onAlarm()
{
  // alarm callback function
  AlarmId id = Alarm. getTriggeredAlarmId();

  if(id == morningAlarmID) {
    Serial.println("Morning Alarm"); 
  } 
  else if (id == afternoonAlarmID) {  
    Serial.println("Afternoon Alarm"); 
  } 
  else if (id == eveningAlarmID) {  
    Serial.println("Evening Alarm"); 
  }  
  else {  
    Serial.println("Invalid Alarm ID"); 
  }
}

void loop()
{
  Alarm.delay(1000);
}

The implementation would required the following new method :

AlarmID_t getTriggeredAlarmId()();  //returns the currently triggered  alarm id
// returns  dtINVALID_ALARM_ID if not invoked from within an alarm handler
{
  if(isServicing)
       return  servicedAlarmId;  // new private data member used instead of local loop variable i in serviceAlarms();
  else
     return dtINVALID_ALARM_ID; // valid ids only available when servicing a callback
}

If something like this would be generally useful then I can add it into the next release

Michael Margolis