-
Notifications
You must be signed in to change notification settings - Fork 0
/
FirmwareModule.cpp
70 lines (62 loc) · 1.77 KB
/
FirmwareModule.cpp
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
#include <Arduino.h>
#include <FirmwareModule.h>
#include <string>
// #include <FirmwareBase.h>
// class FirmwareModule
// {
int FirmwareModule::cycleCounter = 0;
std::vector<FirmwareModule *> *FirmwareModule::instances = new std::vector<FirmwareModule *>();
// int internalCycleCount = 0;
// int resetCycleCount = pow(2, 10); // the numbers of cycles after which internal counter is increased and cycleCounter is reset
FirmwareModule::FirmwareModule(std::string name) : moduleName(name)
{
// FirmwareModule::cycleCounter = 0;
FirmwareModule::instances->push_back(this);
}
void FirmwareModule::onCycle()
{
internalCycleCount++; // increase internal counter
}
void FirmwareModule::setup()
{
}
void FirmwareModule::loop()
{
if (cycleCounter++ >= resetCycleCount)
{
cycleCounter = 0; // reset counter
onCycle();
}
}
void FirmwareModule::setupAll()
{
std::string logStr("");
Serial.println("");
Serial.println("[Firmware] Loading ...");
std::size_t total = FirmwareModule::instances->size();
logStr = "[Firmware] found " + std::to_string(total) + " modules ";
Serial.println(logStr.c_str());
Serial.println("");
int i = 0;
for (auto module : *FirmwareModule::instances)
{
logStr = "[Module " + std::to_string(i + 1) + "/" + std::to_string(total) + "] ";
logStr += "*** " + module->moduleName + " ***";
Serial.println(logStr.c_str());
module->setup();
Serial.println("");
i++;
}
Serial.println("");
logStr = "[Firmware] Loaded " + std::to_string(i) + " modules";
Serial.println(logStr.c_str());
Serial.println("[Firmware] Running ...");
}
void FirmwareModule::loopAll()
{
for (auto elem : *FirmwareModule::instances)
{
elem->loop();
}
}
// };