Skip to content

RTC.setAlarmCallback does not allows matching on more than one field #154

Closed
@dquadros

Description

@dquadros

The setAlarmCallback method implementation uses "if / else if" so only the first field is used:

at.min_match = false;
at.sec_match = false;

...

if(m.isMatchingSecond()) {
at.sec_match = true;
}
else if(m.isMatchingMinute()) {
at.min_match = true;
}


If you try, for example, to set an alarm for 09:10:04 it will fire every time the second is 4:

#include "RTC.h"
void setup() {
  Serial.begin(115200);
  RTC.begin();
  RTCTime starttime(29, Month::SEPTEMBER, 2023, 14, 00, 00, 
      DayOfWeek::FRIDAY, SaveLight::SAVING_TIME_INACTIVE);
  RTC.setTime(starttime);  
  RTCTime alarme;
  alarme.setHour(9);
  alarme.setMinute(10);
  alarme.setSecond(4);
  AlarmMatch am;
  am.addMatchHour();
  am.addMatchMinute();
  am.addMatchSecond();
  if (!RTC.setAlarmCallback(alarm_cbk, alarme, am)) {
    Serial.println("ERROR: alarm callback not set");
  }
}

bool beep = false;

void alarm_cbk() {
  beep = true;
}

void loop() {
  if (beep) {
    Serial.println("BEEP");
    beep = false;
  }
  delay (100);
}

The setAlarmCallback method could be implemented as follows:

at.min_match = m.isMatchingSecond();               
at.sec_match = m.isMatchingMinute(); 
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions