Zanduino / MCP7940

Arduino Library to access the MCP7940M, MCP7940N and MCP7940x Real-Time chips
GNU General Public License v3.0
37 stars 22 forks source link

Cancel a setAlarm #46

Closed logicaprogrammabile closed 4 years ago

logicaprogrammabile commented 4 years ago

Hi for particular project i need to cancel a setAlarm setting. For example i set a alarm, but in a specific condition is possible to cancel the alarm settings so that this is not generated?

Thanks

logicaprogrammabile commented 4 years ago

i try this

bool MCP7940_Class::resetAlarm(const uint8_t alarmNumber) { clearRegisterBit(MCP7940_CONTROL, alarmNumber ? MCP7940_ALM1EN : MCP7940_ALM0EN); // Turn off the alarm return true; }

and work fine

SV-Zanshin commented 4 years ago

Currently this is done using the SetAlarm() with an "AlarmType" of "0" and some value for the "AlarmDate" parameter which isn't used.

SV-Zanshin commented 4 years ago

I don't want to add a new function to clear the alarm because the functionality already exists in the SetAlarm() function. Is that acceptable to you? If so, I'll close this bug report.

logicaprogrammabile commented 4 years ago

ok, i read the code and the function to reset alarm is setAlarmState(), not setAlarm. it's correct?

SV-Zanshin commented 4 years ago

The https://github.com/SV-Zanshin/MCP7940/wiki/setAlarmState() just sets the state of the alarm, but doesn't enable/disable it, the https://github.com/SV-Zanshin/MCP7940/wiki/setAlarm() call with the "AlarmType" parameter set to 0 will disable it.

logicaprogrammabile commented 4 years ago

i tested setAlarmState() and the function work fine. for example: MCP7940.setAlarmState(0, false); disable the alarm 0 correctly

SV-Zanshin commented 4 years ago

Whether it works as you expect it to depends upon what type of alarm was triggered. If you set a "minutes match" type of alarm and turn it off using setAlarmState() but the minute is still the same then the alarm would immediately re-assert. If you set an alarm for a specific date/time then this method would work.