Loom_Interrupt_Manager class

Submanager for managing interrupts, timers, and stopwatches.

Base classes

class LoomModule
Abstract root of Loom component modules inheritance hierarchy.

Protected static variables

static bool interrupt_triggered
Flags set by interrupts, indicating ISR bottom half should be called if not Null.

Protected variables

LoomRTC* RTC_Inst
Pointer to an RTC object for managing timers / timed interrupts.
Loom_Sleep_Manager* Sleep_Manager
Pointer to a Sleep Manager object.
IntDetails int_settings
List of interrupts configurations.
bool interrupts_enabled
Enable or disable all interrupts – currently only disables bottom halves.
DateTime last_alarm_time
Last time an alarm went off.

CONSTRUCTORS / DESTRUCTOR

Loom_Interrupt_Manager(LoomManager* manager, LoomRTC* RTC_Inst = nullptr)
Interrupt Manager module constructor.
Loom_Interrupt_Manager(LoomManager* manager, JsonArrayConst p)
Constructor that takes Json Array, extracts args and delegates to regular constructor.
~Loom_Interrupt_Manager() defaulted
Destructor.

OPERATION

void package(JsonObject json) override
No package necessary.
void run_pending_ISRs()
Run any waiting ISRs.

EXTERNAL INTERRUPT METHODS

void register_ISR(const uint32_t pin, ISRFuncPtr ISR, const uint32_t signal_type, ISR_Type run_type)
Register an ISR to an interrupt pin and its configuration.
auto reconnect_interrupt(const uint32_t pin) -> bool
If an ISR dettaches interrupt, use this to reattach according to previous settings.
void unregister_ISR(const uint32_t pin, const uint32_t signal_type = LOW)
Restores pin to default ISR, disables interrupt.
void interrupt_reset(const uint32_t pin)
Detaches then reattacheds interrupt according to settings.

RTC ALARM METHODS

auto RTC_alarm_duration(const TimeSpan duration) -> bool
Set RTC alarm an amount of time from now.
auto RTC_alarm_duration(const uint8_t days, const uint8_t hours, const uint8_t minutes, const uint8_t seconds) -> bool
Set RTC alarm an amount of time from now.
auto RTC_alarm_at(DateTime future_time) -> bool
Set RTC alarm for a specific time.
auto RTC_alarm_at(const uint8_t hour, const uint8_t minute, const uint8_t second) -> bool
Set RTC alarm for a specific time.
auto RTC_alarm_duration_from_last(const TimeSpan duration) -> bool
Set RTC alarm an amount of time from last alarm time.
auto RTC_alarm_duration_from_last(const uint8_t days, const uint8_t hours, const uint8_t minutes, const uint8_t seconds) -> bool
Set RTC alarm an amount of time from last alarm time.

ASYNCDELAY TIMER METHODS

void check_timers()
Check if timers have elapsed, if so run associated 'ISR'.
void register_timer(const uint8_t timer_num, const unsigned long duration, const ISRFuncPtr ISR, const bool repeat)
Configure specified timer.
void clear_timer(const uint8_t timer_num)
Clear specified timer.

INTERNAL TIMER METHODS

void register_internal_timer(const uint duration, const ISRFuncPtr ISR, const bool repeat, const ISR_Type run_type)
Configure internal timer.
auto run_pending_internal_timer_ISR() -> bool
Run a delayed (flag based) ISR if the interal timer elapsed.
auto get_internal_timer_flag() const -> bool
Get whether the internal timer has elapsed.
void clear_internal_timer_flag() const
Clear internal timer flag.
void internal_timer_enable(const bool enable)
Enable or disable internal timer.
void unregister_internal_timer()
Clear and disable internal timer, remove ISR.

GETTERS

auto get_interrupts_enabled() const -> bool
Get global interrupt enable state.
auto get_enable_interrupt(const uint32_t pin) const -> bool
Get pin interrupt enable state.
auto get_RTC_module() const -> LoomRTC*
Return pointer to the currently linked RTC object.

SETTERS

void link_device_manager(LoomManager* LM) override
Link a device manager.
void link_sleep_manager(Loom_Sleep_Manager* SM)
Set pointer to sleep Manager.
void set_interrupts_enabled(const bool state)
All interrupts enable/disable.
void set_enable_interrupt(const uint32_t pin, const bool state)
Per interrupt enable.
void set_RTC_module(LoomRTC* RTC_Inst)
Set the RTC module to use for timers.

MISCELLANEOUS

static const ISRFuncPtr default_ISRs
Array of the default ISRs that set flags.
static auto interrupt_type_to_string(const uint8_t type) -> const char*
Get c-string of name associated with interrupt type enum.

Function documentation

Loom_Interrupt_Manager::Loom_Interrupt_Manager(LoomManager* manager, LoomRTC* RTC_Inst = nullptr)

Interrupt Manager module constructor.

Parameters
manager
RTC_Inst in Set(Int) | <0> | {0("Null")} | OLED module name

Loom_Interrupt_Manager::Loom_Interrupt_Manager(LoomManager* manager, JsonArrayConst p)

Constructor that takes Json Array, extracts args and delegates to regular constructor.

Parameters
manager
in The array of constuctor args to expand

void Loom_Interrupt_Manager::package(JsonObject json) override

No package necessary.

Implement with empty body.

void Loom_Interrupt_Manager::run_pending_ISRs()

Run any waiting ISRs.

Flag was set by a top half ISR

void Loom_Interrupt_Manager::register_ISR(const uint32_t pin, ISRFuncPtr ISR, const uint32_t signal_type, ISR_Type run_type)

Register an ISR to an interrupt pin and its configuration.

Parameters
pin in Which pin to connect the interrupt on
ISR in ISR function (Null if no interrupt linked)
signal_type in Low, High, Change, Falling, Rising
run_type in Whether the interrupt runs immediately, else sets flag to check and runs ISR when flag checked

bool Loom_Interrupt_Manager::reconnect_interrupt(const uint32_t pin)

If an ISR dettaches interrupt, use this to reattach according to previous settings.

Parameters
pin in Which pin to reconnect the interrupt on

Effectively to running register_ISR with previous settings

void Loom_Interrupt_Manager::unregister_ISR(const uint32_t pin, const uint32_t signal_type = LOW)

Restores pin to default ISR, disables interrupt.

Parameters
pin in The pin to unregister ISRs for
signal_type in What signal to configure default ISR to (default LOW)

void Loom_Interrupt_Manager::interrupt_reset(const uint32_t pin)

Detaches then reattacheds interrupt according to settings.

Parameters
pin in Pin to reset interrupts for ...

used to clear pending interrupts

bool Loom_Interrupt_Manager::RTC_alarm_duration(const TimeSpan duration)

Set RTC alarm an amount of time from now.

Parameters
duration in How long before the alarm should go off

bool Loom_Interrupt_Manager::RTC_alarm_duration(const uint8_t days, const uint8_t hours, const uint8_t minutes, const uint8_t seconds)

Set RTC alarm an amount of time from now.

Parameters
days in Days into the future the alarm should be set
hours in Hours into the future the alarm should be set
minutes in Minutes into the future the alarm should be set
seconds in Seconds into the future the alarm should be set

bool Loom_Interrupt_Manager::RTC_alarm_at(DateTime future_time)

Set RTC alarm for a specific time.

Parameters
future_time in Time to set alarm for

Increments to next day at given hour, min, sec if specified time is in past

bool Loom_Interrupt_Manager::RTC_alarm_at(const uint8_t hour, const uint8_t minute, const uint8_t second)

Set RTC alarm for a specific time.

Parameters
hour in Hour to set alarm for
minute in Minute to set alarm for
second in Second to set alarm for

Forwards to RTC_alarm_at that takes DateTime object

bool Loom_Interrupt_Manager::RTC_alarm_duration_from_last(const TimeSpan duration)

Set RTC alarm an amount of time from last alarm time.

Parameters
duration in How long before the alarm should go off

bool Loom_Interrupt_Manager::RTC_alarm_duration_from_last(const uint8_t days, const uint8_t hours, const uint8_t minutes, const uint8_t seconds)

Set RTC alarm an amount of time from last alarm time.

Parameters
days in Days into the future the alarm should be set
hours in Hours into the future the alarm should be set
minutes in Minutes into the future the alarm should be set
seconds in Seconds into the future the alarm should be set

void Loom_Interrupt_Manager::register_timer(const uint8_t timer_num, const unsigned long duration, const ISRFuncPtr ISR, const bool repeat)

Configure specified timer.

Parameters
timer_num in Timer to set
duration in How long timer should take (seconds)
ISR in ISR to run after timer goes off
repeat in Whether or not to be a repeating alarm

void Loom_Interrupt_Manager::clear_timer(const uint8_t timer_num)

Clear specified timer.

Parameters
timer_num in Timer to clear

void Loom_Interrupt_Manager::register_internal_timer(const uint duration, const ISRFuncPtr ISR, const bool repeat, const ISR_Type run_type)

Configure internal timer.

Parameters
duration in How long timer should take (seconds)
ISR in ISR to run after timer goes off
repeat in Whether or not to be a repeating alarm
run_type in Whether the interrupt runs immediately, else sets flag to check and runs ISR when flag checked

bool Loom_Interrupt_Manager::run_pending_internal_timer_ISR()

Run a delayed (flag based) ISR if the interal timer elapsed.

Returns True if flag was set and ISR run

Is not needed if using ISR_Type::IMMEDIATE ISR

bool Loom_Interrupt_Manager::get_internal_timer_flag() const

Get whether the internal timer has elapsed.

Returns True if timer elapsed, false otherwise

void Loom_Interrupt_Manager::internal_timer_enable(const bool enable)

Enable or disable internal timer.

Parameters
enable in True to enable timer, false to disable

Disabling does not remove settings, use unregister_interal_timer for that behavior

bool Loom_Interrupt_Manager::get_interrupts_enabled() const

Get global interrupt enable state.

Returns Global interrupt enable state

bool Loom_Interrupt_Manager::get_enable_interrupt(const uint32_t pin) const

Get pin interrupt enable state.

Parameters
pin in Pin to the the enable state of
Returns The enable state

LoomRTC* Loom_Interrupt_Manager::get_RTC_module() const

Return pointer to the currently linked RTC object.

Returns Current RTC object

void Loom_Interrupt_Manager::link_device_manager(LoomManager* LM) override

Link a device manager.

Parameters
LM in Manager to link

Overrides default by getting RTC pointer from device manager if possible

void Loom_Interrupt_Manager::link_sleep_manager(Loom_Sleep_Manager* SM)

Set pointer to sleep Manager.

Parameters
SM in Pointer to sleep manager

void Loom_Interrupt_Manager::set_interrupts_enabled(const bool state)

All interrupts enable/disable.

Parameters
state in Enable state to apply to all interrupts

void Loom_Interrupt_Manager::set_enable_interrupt(const uint32_t pin, const bool state)

Per interrupt enable.

Parameters
pin in Interrupt pin to change enable state of
state in The enable state to set pin to

void Loom_Interrupt_Manager::set_RTC_module(LoomRTC* RTC_Inst)

Set the RTC module to use for timers.

Parameters
RTC_Inst in Pointer to the RTC object

static const char* Loom_Interrupt_Manager::interrupt_type_to_string(const uint8_t type)

Get c-string of name associated with interrupt type enum.

Parameters
type in Interrupt type
Returns C-string of interrupt type