-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputPin.h
43 lines (38 loc) · 1.32 KB
/
InputPin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include <Arduino.h>
/*
InputPin.h - class to encapusulate an input pin with interrupt handling
*/
class InputPin
{
public:
InputPin ( pin_size_t pin, uint32_t debouncems, uint32_t maxMatchedTimems, PinStatus matchStatus, PinMode mode = PinMode::INPUT, PinStatus status = PinStatus::CHANGE );
void ProcessISR ();
bool IsMatched ();
uint32_t GetMatchedCount ();
uint32_t GetUnmatchedCount ();
uint32_t GetInvokedCount ();
uint32_t GetSpuriousCount ();
uint32_t GetDiscardUnchangedCount ();
uint32_t GetLastMatchedDuration();
void DebugStats ( String &result );
bool GetCurrentMatchedState();
private:
virtual void MatchAction () = 0;
virtual void UnmatchAction () = 0;
static void InputPinISR ( void *pParam );
const pin_size_t m_Pin;
const uint32_t m_Debouncems;
const uint32_t m_maxMatchedTimems;
const PinStatus m_MatchStatus;
volatile PinStatus m_LastPinRead;
volatile uint32_t m_LastChangedTime;
volatile bool m_CurrentMatchedState = false;
// stat counters
volatile uint32_t m_ISRCalledCount = 0UL;
volatile uint32_t m_DiscardedUnchangedCount = 0UL;
volatile uint32_t m_MatchedCount = 0UL;
volatile uint32_t m_UnmatchedCount = 0UL;
volatile uint32_t m_SpuriousCount = 0UL;
volatile uint32_t m_MatchedDuration = 0UL;
};