software:firmware
MakAir Firmware
alarm.cpp
Go to the documentation of this file.
1 
8 #pragma once
9 
10 // INCLUDES ===================================================================
11 
12 // Externals
13 #include "Arduino.h"
14 
15 // Internals
16 #include "../includes/alarm.h"
17 
18 // FUNCTIONS ==================================================================
19 
20 Alarm::Alarm(AlarmPriority p_priority, uint8_t p_code, uint8_t p_detectionThreshold) {
21  m_priority = p_priority;
22  m_code = p_code;
23  m_detectionThreshold = p_detectionThreshold;
25  UINT32_MAX; // We need this not to be 0 so that alarms can be triggered just after booting
26  m_detectionNumber = 0u;
28  m_enabled = true;
29 }
30 
32 
33 uint8_t Alarm::getCode() const { return m_code; }
34 
35 // cppcheck-suppress unusedFunction
37 
39 
40 void Alarm::detected(uint32_t p_cycleNumber) {
41  if (m_cycleNumber != p_cycleNumber) {
42  m_cycleNumber = p_cycleNumber;
47  }
48  }
49 }
50 
52  m_cycleNumber = UINT32_MAX;
53  m_detectionNumber = 0u;
55 }
56 
57 void Alarm::enable() { m_enabled = true; }
58 
59 void Alarm::disable() { m_enabled = false; }
60 
61 bool Alarm::isEnabled() { return m_enabled; }
AlarmPriority
Priority levels of an alarm.
Definition: alarm.h:18
bool isTriggered() const
True if the number of detections is equal or above the detection threshold, false otherwise.
Definition: alarm.cpp:38
bool m_enabled
Whether or not this alarm is enabled.
Definition: alarm.h:87
uint8_t m_detectionThreshold
Alarm detection threshold.
Definition: alarm.h:75
void disable()
Disable this alarm.
Definition: alarm.cpp:59
AlarmPriority m_priority
Alarm priority.
Definition: alarm.h:69
uint32_t m_cyclesSinceTrigger
Number of cycles since the alarm was triggered.
Definition: alarm.h:84
void detected(uint32_t p_cycleNumber)
If the alarm is detected, it increments the number of detection until the detection threshold.
Definition: alarm.cpp:40
uint8_t m_detectionNumber
Number of detections.
Definition: alarm.h:78
Alarm(AlarmPriority p_priority, uint8_t p_code, uint8_t p_detectionThreshold)
Parameterized constructor.
Definition: alarm.cpp:20
void notDetected()
Reset to zero the number of detection.
Definition: alarm.cpp:51
AlarmPriority getPriority() const
Get the alarm priority.
Definition: alarm.cpp:31
void enable()
Enable this alarm.
Definition: alarm.cpp:57
uint8_t getCode() const
Get the alarm code.
Definition: alarm.cpp:33
uint8_t m_code
Alarm code.
Definition: alarm.h:72
uint32_t getCyclesSinceTrigger() const
Get the number of cycles since the alarm was triggered.
Definition: alarm.cpp:36
bool isEnabled()
True if this alarm is enabled.
Definition: alarm.cpp:61
uint32_t m_cycleNumber
Cycle number.
Definition: alarm.h:81