-
Notifications
You must be signed in to change notification settings - Fork 0
/
Input.hpp
49 lines (40 loc) · 1.29 KB
/
Input.hpp
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
#ifndef __INPUT_HPP
#define __INPUT_HPP
#include <stdint.h>
/* Interface class Input for polymorphic handling of inputs. */
class Input {
public:
virtual void initialize() = 0;
virtual void process() = 0;
};
/* Class for analog inputs, whose input is mapped to MIDI values 0-127 and output as command on change. */
class AnalogInput : public Input {
private:
uint8_t mPin;
uint8_t mMidiCommandId;
int mSensorValue;
bool processSensorValue(int reading);
void sendSensorValue();
public:
AnalogInput(int pin, uint8_t midiCommandId); /* Constructor */
virtual void initialize() { /* No initialization necessary. */ }
virtual void process();
};
/* Class for digital inputs, whose input is mapped to MIDI values 0 or 127 and output as command on change after debouncing. */
class DigitalInput : public Input {
private:
uint8_t mPin;
uint8_t mPinMode;
int mDebounceDelay;
uint8_t mMidiCommandId;
int mButtonState;
int mLastButtonState;
unsigned long mLastDebounceTime;
bool debounce(int reading);
void sendButtonState();
public:
DigitalInput(uint8_t pin, uint8_t pMode, int debounceDelayMs, uint8_t midiCommandId); /* Constructor */
virtual void initialize();
virtual void process();
};
#endif /* __INPUT_HPP */