forked from MobiFlight/MobiFlight-FirmwareSource
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDigInMux.cpp
More file actions
74 lines (64 loc) · 1.85 KB
/
DigInMux.cpp
File metadata and controls
74 lines (64 loc) · 1.85 KB
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
71
72
73
74
//
// DigInMux.cpp
//
// (C) MobiFlight Project 2022
//
#include "mobiflight.h"
#include "MFDigInMux.h"
#include "MFMuxDriver.h"
extern MFMuxDriver MUX;
namespace DigInMux
{
MFDigInMux *digInMux[MAX_DIGIN_MUX];
uint8_t digInMuxRegistered = 0;
void handlerOnDigInMux(uint8_t eventId, uint8_t channel, const char *name)
{
cmdMessenger.sendCmdStart(kDigInMuxChange);
cmdMessenger.sendCmdArg(name);
cmdMessenger.sendCmdArg(channel);
cmdMessenger.sendCmdArg(eventId);
cmdMessenger.sendCmdEnd();
};
void Add(uint8_t dataPin, uint8_t nRegs, char const *name)
{
if (digInMuxRegistered == MAX_DIGIN_MUX)
return;
MFDigInMux *dip;
if (!FitInMemory(sizeof(MFDigInMux))) {
// Error Message to Connector
cmdMessenger.sendCmd(kStatus, F("DigInMux does not fit in Memory"));
return;
}
dip = new (allocateMemory(sizeof(MFDigInMux))) MFDigInMux(&MUX, name);
digInMux[digInMuxRegistered] = dip;
dip->attach(dataPin, (nRegs == 1), name);
MFDigInMux::attachHandler(handlerOnDigInMux);
digInMuxRegistered++;
#ifdef DEBUG2MSG
cmdMessenger.sendCmd(kDebug, F("Added digital input MUX"));
#endif
}
void Clear()
{
for (uint8_t i = 0; i < digInMuxRegistered; i++) {
digInMux[digInMuxRegistered]->detach();
}
digInMuxRegistered = 0;
#ifdef DEBUG2CMDMESSENGER
cmdMessenger.sendCmd(kDebug, F("Cleared dig. input Muxes"));
#endif
}
void read()
{
for (uint8_t i = 0; i < digInMuxRegistered; i++) {
digInMux[i]->update();
}
}
void OnTrigger()
{
for (uint8_t i = 0; i < digInMuxRegistered; i++) {
digInMux[i]->retrigger();
}
}
} // namespace
// DigInMux.cpp