This is an application library for PlatformIO projects. It encapsulates the functionality of postponed action
. The encapsulation provides following advantages:
- Functionality is hidden from the main sketch.
- The library follows the principle
separation of concerns
. - The library is reusable for various projects without need to code timers.
- Update in library is valid for all involved projects.
- It specifies (inherits from) the parent application library
gbj_appcore
. - It utilizes funcionality and error handling from the parent class.
- The library creates internal one-shot timer, which executes input procedure (handler) after provided time interval.
- The defering is useful mainly for postponed reconnecting to wifi or restarting microcontroller from the built-in webserver to give it a chance to redirect to the main webpage and suppress the web browser to repeate that action at its refresh mode.
- gbj_appcore: Parent library for all application libraries loaded from the file
gbj_appcore.h
. - gbj_serial_debug: Auxilliary library for debug serial output loaded from the file
gbj_serial_debug.h
. It enables to exclude serial outputs from final compilation. - gbj_timer: Library for executing internal timer within an instance object loaded from the file
gbj_timer.h
.
- Arduino.h: Main include file for the Arduino SDK.
- inttypes.h: Integer type conversions. This header file includes the exact-width integer definitions and extends them with additional facilities provided by the implementation.
- Arduino.h: Main include file for the Arduino platform.
- Particle.h: Includes alternative (C++) data type definitions.
The template or the signature of a callback function, which is called at the end of the timer interval in order to execute some useful action.
- A handler is just a bare function without any input parameters and returning nothing.
- A handler can be declared just as
void
type.
typedef void Handler()
None
None
Constructor creates the class instance object and initiates internal resources.
- It inputs operational parameters.
- It creates an internal one-shot timer.
gbj_appdefer(unsigned long timerPeriod, Handler *timerHandler)
-
timerPeriod: The duration of postpone interval in milliseconds.
- Valid values: non-negative integer 0 ~ 2^32 - 1
- Default value: none
-
timerHandler: Pointer to a procedure that is called at the end of the timer period. If no handler is provided, the timer just runs without any useful action.
- Valid values: valid address space
- Default value: 0
Object managing deferred actions.
The execution method as a wrapper of the internal timer's execution method.
- It should be called frequently, usually in the loop function of a main sketch.
The overloaded method starts the one-shot timer with the current time interval.
- The method without input argument or zero-valued one uses current time interval either from the constructor or previous calling this method.
- The method with numerical input argument sets new timer interval in milliseconds and starts timer.
- The method with textual input argument sets new timer interval in seconds. It is useful with conjunction with a project data hub, which data has always string data type.
void setPeriod(unsigned long period)
void setPeriod(String periodSec)
-
period: The duration of new postpone interval in milliseconds.
- Valid values: 0 ~ 2^32 - 1
- Default value: none
-
periodSec: The duration of new postpone interval in seconds declared as string.
- Valid values: String
- Default value: none
None
The method returns current time interval of the internal timer.
unsigned long getPeriod()
None
Current timer period in milliseconds.