-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSwitchScanner.h
70 lines (49 loc) · 1.14 KB
/
SwitchScanner.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* SwitchScanner.h
*
* Created on: 04.09.2015
* Author: sr
*/
#ifndef PINBALL_LW3_SWITCHSCANNER_H_
#define PINBALL_LW3_SWITCHSCANNER_H_
#include <Arduino.h>
#include "SwitchAction.h"
enum Trigger { EDGE, PERIODIC };
class ActionEntry {
public:
SwitchAction* action;
int col;
int row;
byte rowMask;
Trigger trigger;
};
#define LAST_COL_TO_READ 7
#define MAX_HANDLERS 20
class SwitchScanner {
public:
SwitchScanner(uint32_t delay);
virtual ~SwitchScanner();
void readSwitches();
void registerSwitchAction(int col, int row, SwitchAction* action, Trigger trigger = EDGE);
void update(uint32_t now);
void printbin(byte bin);
void dump();
volatile boolean getSwitchChanged() const {
return switchChanged;
}
int handlerIndex;
ActionEntry handlers[MAX_HANDLERS];
boolean led;
uint32_t nextPeriodic;
uint32_t delay;
volatile int col;
// two times 8 byte for row returns
// two arrays are used to detect changes
volatile byte rows[2][8];
// switches from 0 to 1 and back
volatile int rowIndex;
volatile int pin;
volatile boolean switchChanged;
volatile boolean colChanged;
};
#endif /* PINBALL_LW3_SWITCHSCANNER_H_ */