forked from MobiFlight/MobiFlight-FirmwareSource
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAnalog.cpp
More file actions
84 lines (72 loc) · 1.86 KB
/
Analog.cpp
File metadata and controls
84 lines (72 loc) · 1.86 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
75
76
77
78
79
80
81
82
83
84
//
// Analog.cpp
//
// (C) MobiFlight Project 2022
//
#include "mobiflight.h"
#include "MFAnalog.h"
#include "Analog.h"
#if MF_ANALOG_SUPPORT == 1
namespace Analog
{
MFAnalog *analog;
uint8_t analogRegistered = 0;
uint8_t maxAnalogIn = 0;
void handlerOnAnalogChange(int value, const char *name)
{
if (!getBoardReady())
return;
cmdMessenger.sendCmdStart(kAnalogChange);
cmdMessenger.sendCmdArg(name);
cmdMessenger.sendCmdArg(value);
cmdMessenger.sendCmdEnd();
};
bool setupArray(uint16_t count)
{
if (!FitInMemory(sizeof(MFAnalog) * count))
return false;
analog = new (allocateMemory(sizeof(MFAnalog) * count)) MFAnalog;
maxAnalogIn = count;
return true;
}
void Add(uint8_t pin, char const *name, uint8_t sensitivity)
{
if (analogRegistered == maxAnalogIn)
return;
analog[analogRegistered] = MFAnalog();
analog[analogRegistered].attach(pin, name, sensitivity);
MFAnalog::attachHandler(handlerOnAnalogChange);
analogRegistered++;
#ifdef DEBUG2CMDMESSENGER
cmdMessenger.sendCmd(kDebug, F("Added analog device "));
#endif
}
void Clear(void)
{
analogRegistered = 0;
#ifdef DEBUG2CMDMESSENGER
cmdMessenger.sendCmd(kDebug, F("Cleared analog devices"));
#endif
}
void read(void)
{
for (uint8_t i = 0; i < analogRegistered; i++) {
analog[i].update();
}
}
void readAverage(void)
{
for (uint8_t i = 0; i < analogRegistered; i++) {
analog[i].readBuffer();
}
}
void OnTrigger()
{
// Scan and transit current values
for (uint8_t i = 0; i < analogRegistered; i++) {
analog[i].retrigger();
}
}
} // namespace Analog
#endif
// Analog.cpp