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

Add PCF8523 alarm functionality #264

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Sloogs
Copy link

@Sloogs Sloogs commented Aug 2, 2022

Summary

This commit adds basic alarm functionality to the PCF8523.

This addresses Issue #241.

Details

The follow methods have been added:

void RTC_PCF8523::enableAlarm(const DateTime &dt,
                                   const Pcf8523AlarmMode alarmMode);
void RTC_PCF8523::disableAlarm();

An example sketch has been added as well: pcf8523Alarm.ino

I have not added functionality to retrieve the alarm, although would be open to adding it in a similar fashion to #257

This is my first open source contribution on GitHub, please be kind. :)

Copy link
Contributor

@edgar-bonet edgar-bonet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to me like a useful and well written contribution! I have a few comments below, which are only my personal opinions (I am not a maintainer of this repo).

You may have noticed that a continuous integration test failed. This is a script that runs clang-format in order to enforce some coding conventions. You may fix this by applying the patch that appears in the page of the failed test. Alternatively, you could run clang-format -i locally, as suggested in the README.


RTC_PCF8523 rtc;

bool alarm_triggered = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag should be qualified as volatile.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!


bool alarm_triggered = false;

void setAlarmExample();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no function with this name. You probably mean doAlarmExample.

Copy link
Author

@Sloogs Sloogs Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shoot! I had renamed it at some point. Thanks for pointing it out. :) As you mentioned in another comment, I'll probably just get rid of forward declarations entirely.

Comment on lines 10 to 12
void setAlarmExample();
void alarmISR();
void handleAlarmTriggered();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to declare these functions, as the Arduino IDE handles those declarations for you.

I personally do prefer adding the declarations explicitly, rather that relying on this feature of the IDE. However, for the sake of consistency with the other provided examples, it think it would be better to omit them.

Copy link
Author

@Sloogs Sloogs Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strangely I've had my Arduino IDE complain on and off about having forward declarations but I'm not exactly sure why. I usually have to restart the IDE or reboot to get it to stop complaining, so I think I just got in the habit of adding them, but the other examples in the library don't include them so I should probably remove them to be consistent.

rtc.enableAlarmTimer(alarm_time, PCF8523_AlarmDate);

// Print the current time for demonstration purposes.
char current_time_buf[] = "YYYY, MMM, DD, DDD, hh:mm:ss AP";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are too many commas here. The date format also seems unusual.

For reference, ISO 8601 defines the big-endian format 2022-08-02 whereas RFC 2822 / RFC 5322 (internet mail) uses the little-endian format Tue, 02 Aug 2022. In the USA, a middle-endian format is quite common.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I should probably stick to a common format like ISO 8601.

attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), alarmISR, LOW);
}

void handleAlarmTriggered()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function could be inlined in loop(), which is tiny.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

rtc.disableAlarmTimer();
Serial.println("Alarm triggered.\n");
doAlarmExample();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious empty line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

src/RTClib.h Outdated
Comment on lines 428 to 429
void enableAlarmTimer(const DateTime &dt, const Pcf8523AlarmMode alarmMode,
uint8_t alarmWeekday);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This three-parameter version of enableAlarmTimer() has not been defined. It is not needed either.

Copy link
Author

@Sloogs Sloogs Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing! I must have missed removing this. I was was originally going to make the weekday an explicit argument but pivoted and felt it might be easier to just grab it from the passed DateTime object like another alarm for the DS3231 RTCs in the library was already doing. I'll review and fix. Thanks!!! :)

@Sloogs
Copy link
Author

Sloogs commented Aug 2, 2022

This looks to me like a useful and well written contribution! I have a few comments below, which are only my personal opinions (I am not a maintainer of this repo).

You may have noticed that a continuous integration test failed. This is a script that runs clang-format in order to enforce some coding conventions. You may fix this by applying the patch that appears in the page of the failed test. Alternatively, you could run clang-format -i locally, as suggested in the README.

Great suggestions! I was wondering about the build failing so I'll implement those changes and give clang-format a try when I'm at my workstation next (which will probably be tomorrow). Thanks a bunch for taking a look!

@Sloogs
Copy link
Author

Sloogs commented Aug 4, 2022

I have implemented the suggestions from @edgar-bonet and ran clang-format, the build appears to have been successful this time.

@lcmcninch
Copy link

Any word on whether this PR will be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants