Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dquadros opened this issue Sep 29, 2023 · 2 comments · Fixed by #156
Closed

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

dquadros opened this issue Sep 29, 2023 · 2 comments · Fixed by #156
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@dquadros
Copy link

dquadros commented Sep 29, 2023

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(); 
...
@dquadros dquadros changed the title setAlarmCallback does not allows matching on more than one field RTC.setAlarmCallback does not allows matching on more than one field Sep 29, 2023
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Sep 29, 2023
@Fashion-Corp
Copy link

Fashion-Corp commented Sep 30, 2023 via email

@facchinm
Copy link
Member

facchinm commented Oct 2, 2023

@maidnl can you take a look?

maidnl added a commit to maidnl/ArduinoCore-renesas that referenced this issue Oct 2, 2023
@per1234 per1234 linked a pull request Oct 2, 2023 that will close this issue
@per1234 per1234 closed this as completed Oct 2, 2023
@per1234 per1234 added the conclusion: resolved Issue was resolved label Oct 2, 2023
andreagilardoni pushed a commit to andreagilardoni/ArduinoCore-renesas that referenced this issue Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants