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
|
using namespace std;
#include <bits/stdc++.h>
// declare structure
struct configLines
{
String section;
String key;
std::function<void(int)> command;
std::function<void(int)> remedial_command;
};
void loadConfigLines(void)
{
vector<configLines> v_configLines = {
{"heartbeat", "COLOR",
setHeartBeatColor,
setHeartBeatColorDefault},
{"s_4_20_MA_1", "ACTIVE",
S_4_20_MA_1.SetActiveState(bool()),
S_4_20_MA_1.SetActiveState(bool(INACTIVE))}
};
}
void processConfigIni(void)
{
extern vector<configLines> v_configLines;
const char *filename = "/config.ini";
const size_t bufferLen = 80;
char buffer[bufferLen];
// bunch of stuff happens here to check SD card and attach to .ini file on SD
loadConfigLines(); // populate the vector of structures
// now step through the configLines
for (int i = 0; i < v_configLines.size(); i++)
{
extern IniFile ini;
if (ini.getValue(v_configLines[i, 0], v_configLines[i, 1], buffer, bufferLen));
// bool IniFile::getValue(const char* section, const char* key, char* buffer, size_t len, float & val) const
{
PrintSectionHas(v_configLines[i, 0], v_configLines[i, 1], buffer);
v_configLines[i, 2]; // void PrintCouldNotRead(String section, String key);
}
else
{
PrintCouldNotRead(v_configLines[i, 0], v_configLines[i, 1]); // void PrintSectionHas(String section, String key, char *value);
v_configLines[i, 3] // Take remedial action here.
}
}
| |