RTC Alarm Synchronized Scheduler
This library is a built in class that provides functions to assist in setting the alarm occurrence time for RTC objects.
Library usage requirements | |
---|---|
Type | Utils |
Name | ALMSYNC |
Version | 1_00_00 |
Code size used | 1.2KB |
Resources used | RTC x 1 |
Abstracts
Methods()/Properties | Summary | Note |
---|---|---|
new ALMSYNC() | Creates an ALMSYNC instance. |
{ALMSYNC} Instance
Methods()/Properties | Summary | Note |
---|---|---|
.start() | Starts the first alarm. | |
.setNext() | Starts the next alarm based on the first alarm time. | |
.getNext() | Gets the next alarm time currently set. | |
.check() | Checks the status of the alarm. | |
.stop() | Stops the set alarm. | |
.VERSION | Version information maj : {number} Main Version min : {number} Minor Version rev : {number} Revision |
Details
new ALMSYNC()
Creates an ALMSYNC instance.
Name | Type | M/O | Description | Note |
---|---|---|---|---|
return | {ALMSYNC} | - | {ALMSYNC}: Generated {ALMSYNC} | An exception will be raised if an error occurs. |
.start(stepUnit,interval)
Starts the first alarm.
The first alarm is set to the time closest to the current time within the specified step unit interval starting from the absolute time 00:00:00
.
After that, the .setNext() method is used to start the next alarm based on the first alarm time at the specified alarm interval.
Name | Type | M/O | Description | Note |
---|---|---|---|---|
stepUnit | number | mandatory | Step unit for first alarm [s] Range: 1-86400 | When the step unit is set to 30s: The first alarm is the closest hh:mm:00 or hh:mm:30 from the current time.When the step unit is set to 60s: The first alarm is at the closest hh:[mm+1]:00 from the current time.When the step unit is set to 300s: The first alarm is at the closest hh:05:00 , hh:10:00 , hh:15:00 , ... , hh:55:00 , or [hh+1]:00:00 from the current time. |
interval | number | mandatory | Alarm interval [s] Sets the alarm interval to be applied on subsequent alarm settings. Range: 1-86400 | |
return | boolean | - | Alarm setting result true: Success false: Failure |
.setNext()
Starts the next alarm based on the first alarm time.
The .start() method must be executed in advance.
Name | Type | M/O | Description | Note |
---|---|---|---|---|
return | boolean | - | Alarm setting result true: Success false: Failure |
.getNext()
Gets the next alarm time currently set.
Name | Type | M/O | Description | Note |
---|---|---|---|---|
return | {Date}, null | - | {Date} : Currently set next alarm time The alarm time will be a Date object.If no alarm has been set, null will be returned. |
.check()
Checks the status of the alarm.
Name | Type | M/O | Description | Note |
---|---|---|---|---|
return | number | - | Alarm occurrence status 0: No alarm occurred 1: Alarm occurred | If no alarm has been set, it will be 0. |
.stop()
Stops the set alarm.
Name | Type | M/O | Description | Note |
---|---|---|---|---|
return | undefined | - |
Usage Examples
Sample 1
The first alarm is raised at n minutes and 0 seconds, then every 10 seconds thereafter.
// IMPORTED LIBRARIES
// - ALMSYNC
//Logging setup
log.setLevel(0,2); //-1:NONE 0:ERROR 1:WARNING 2:DEBUG 3:TRACE, 0:DISABLE 1:LOG 2:CONSOLE 3:BOTH
log.printLevel(2); //0:DISABLE 1:LOG 2:CONSOLE 3:BOTH
//Alarm config
var alarm = new ALMSYNC();
var stepUnit = 60;
var interval = 10;
alarm.start(stepUnit, interval);
print(alarm.getNext() + ' first alarm event');
//Main loop
while(1) {
if(alarm.check()) {
print(Date() + ' alarm event');
alarm.setNext();
print(alarm.getNext() + ' next alarm event');
}
}
Updated: 2021-10-19