-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSwitches.h
69 lines (56 loc) · 1.81 KB
/
Switches.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
#ifndef SWITCHES_H
#define SWITCHES_H
#include "LEDsAndButtonsHWWrapper.h"
/**
* This class handles maximum 8 independent switches
*/
class Switches
{
public:
/**
* Constructor
*/
Switches();
/**
* Initialize switches
* @param hwLayer HW layer to read button states from
* @param buttonIndexes indexes of the buttons in HW layer to be used in this
* button switches array (MAXIMUM IS 16)
* @param count number of buttons in this button array
* @param useLEDs set whether the LED shall reflect the state of the switch
* @param changeOnEvent event to change state on (Default is on button down)
*/
void init(unsigned char * buttonIndexes,
unsigned char count,
bool useLEDs = false,
IButtonHW::ButtonState changeOnEvent = IButtonHW::DOWN);
/**
* get the status of the button at the index in the switches array
* @param buttonIndex index of the button in the switches array to bet value for
* @return status of the button specified by argument
*/
bool getStatus(unsigned char buttonIndex);
/**
* sets the status of the button at the index in the switches array
* @param buttonIndex index of the button in the switches array to bet value for
* @param value status to be set to the button specified by argument
*/
void setStatus(unsigned char buttonIndex, bool value);
/**
* Updates status of all buttons reading values from the HW
*/
void update();
/**
* Detects already pressed buttons and ignore changes on them
*/
void computeIgnoreButton();
private:
unsigned char * buttonIndexes_;
unsigned char buttonCount_;
unsigned int lastStates_;
unsigned int statuses_;
unsigned char changeOnEvent_;
unsigned char ignoreButton_;
bool useLEDs_;
};
#endif // SWITCHES_H