-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControllerPort.h
49 lines (40 loc) · 1.54 KB
/
ControllerPort.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
/*
* A service that represents a controller port that
* a player (aka a set of keys) may play on (be connected to).
*
* The service builds the controller port as a stateful switch (outlet) which
* can be linked to the player. Each player needs its own set of
* four controller ports. The state of these four pseudo-ports is mapped from the
* actual ports, defined as MeasuringControllerPort.
*
* The MeasuringControllerPort represents the physical port and is not exposed directly
* to HomeKit. Its subscribers will be Players, which in turn have ControllerPorts
* that are exposed. This means that there will be a 1:4 relationship between
* MeasuringControllerPorts and ControllerPorts. This is to make things look nice in HomeKit.
*/
#ifndef CONTROLLER_PORT_H
#define CONTROLLER_PORT_H
#include <HomeSpan.h>
#include "StatefulSwitch.h"
#include "MeasuringQueuer.h"
struct ControllerPort : StatefulSwitch {
ControllerPort(const char* portName) : StatefulSwitch(portName) {};
};
struct MeasuringControllerPort : MeasuringQueuer {
const int gpioReadings[6] = GPIO_READINGS;
const int nbrOfPlayers = NUMBER_OF_PLAYERS;
MeasuringControllerPort(int gpioPin, int controllerPortNbr) :
MeasuringQueuer(
gpioPin,
controllerPortNbr
)
{}
int preprocessValueBeforePublish(int reading) override {
if (reading <= interferenceReading) {
return -1;
}
int pluggedInPlayer = measurementHelpers::getPositionInArrayWithVariance(reading, readingVariance, gpioReadings, nbrOfPlayers);
return pluggedInPlayer;
}
};
#endif