expand and fix digitalIO class
This commit is contained in:
55
src/main.cpp
55
src/main.cpp
@@ -50,6 +50,7 @@ void loop()
|
||||
auto seneca = drivers::S50140(bus, conf.m_modbusSenecaAddr);
|
||||
auto buzzer = drivers::Buzzer();
|
||||
auto led = drivers::Led();
|
||||
delay(500);
|
||||
auto io = digitalIO(i2c, bus, {conf.m_modbusRelayAddr});
|
||||
// Initialize temperature sensors
|
||||
sensors = tmp.getNum();
|
||||
@@ -63,8 +64,24 @@ void loop()
|
||||
std::function<void(const ArduinoJson::JsonDocument &)> mycallback =
|
||||
[&io](const ArduinoJson::JsonDocument &doc)
|
||||
{
|
||||
io.digitalIOWrite(0, doc["stat"].as<bool>());
|
||||
io.digitalIOWrite(15, doc["stat"].as<bool>());
|
||||
std::vector<bool> v1 = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
|
||||
std::vector<bool> v2 = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
|
||||
std::vector<bool> v0(io.getOutNum(), 0);
|
||||
|
||||
LOG_INFO("SET Digital Outputs V1: ", printBoolVec(v1).c_str());
|
||||
io.digitalOutWritePort(v1);
|
||||
delay(100);
|
||||
LOG_INFO("GET Digital Outputs V1: ", printBoolVec(io.digitalOutReadPort()).c_str());
|
||||
delay(2000);
|
||||
|
||||
LOG_INFO("SET Digital Outputs V2: ", printBoolVec(v2).c_str());
|
||||
io.digitalOutWritePort(v2);
|
||||
delay(100);
|
||||
LOG_INFO("GET Digital Outputs V2: ", printBoolVec(io.digitalOutReadPort()).c_str());
|
||||
delay(2000);
|
||||
|
||||
LOG_INFO("GET Digital Inputs: ", printBoolVec(io.digitalInReadPort()).c_str());
|
||||
io.digitalOutWritePort(v0);
|
||||
};
|
||||
|
||||
//////////////// NETWORK ////////////////
|
||||
@@ -134,16 +151,32 @@ void loop()
|
||||
drivers::S50140::powerinfo_t pinfo = seneca.getAll();
|
||||
LOG_INFO("Power Info ==> V:", pinfo.v, "- A:", pinfo.a, "- W:", pinfo.pAct, "- F:", pinfo.f, "- Wh_t:", pinfo.whTot, "- Wh_p:", pinfo.whPar);
|
||||
|
||||
if (io.digitalIORead(0)) // rosso
|
||||
if (io.digitalInRead(0)) // rosso
|
||||
{
|
||||
uint8_t regset(seneca.getRegset());
|
||||
uint16_t countStat(seneca.getCounterStatus());
|
||||
LOG_INFO("Register Set: ", regset);
|
||||
LOG_INFO("Counter Status: ", countStat);
|
||||
seneca.resetPartialCounters();
|
||||
std::vector<bool> v1 = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
|
||||
std::vector<bool> v2 = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
|
||||
std::vector<bool> v0(16, 0);
|
||||
|
||||
LOG_INFO("SET Digital Outputs V1: ", printBoolVec(v1).c_str());
|
||||
io.digitalOutWritePort(v1);
|
||||
delay(100);
|
||||
LOG_INFO("GET Digital Outputs V1: ", printBoolVec(io.digitalOutReadPort()).c_str());
|
||||
delay(2000);
|
||||
|
||||
LOG_INFO("SET Digital Outputs V2: ", printBoolVec(v2).c_str());
|
||||
io.digitalOutWritePort(v2);
|
||||
delay(100);
|
||||
LOG_INFO("GET Digital Outputs V2: ", printBoolVec(io.digitalOutReadPort()).c_str());
|
||||
delay(2000);
|
||||
|
||||
LOG_INFO("GET Digital Inputs: ", printBoolVec(io.digitalInReadPort()).c_str());
|
||||
delay(2000);
|
||||
|
||||
io.digitalOutWritePort(v0);
|
||||
}
|
||||
|
||||
delay(100);
|
||||
if (io.digitalIORead(8)) // blu
|
||||
if (io.digitalInRead(8)) // blu
|
||||
{
|
||||
if (!buzzing)
|
||||
{
|
||||
@@ -160,12 +193,12 @@ void loop()
|
||||
LOG_INFO("Buzzing -> ", buzzing ? "True" : "False");
|
||||
}
|
||||
|
||||
if (io.digitalIORead(9))
|
||||
if (io.digitalInRead(9))
|
||||
{ // verde
|
||||
conf.resetConfig();
|
||||
}
|
||||
|
||||
if (io.digitalIORead(10))
|
||||
if (io.digitalInRead(10))
|
||||
{ // giallo
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user