DigitalIO driver with dynamic channel count
This commit is contained in:
28
src/main.cpp
28
src/main.cpp
@@ -1,15 +1,15 @@
|
||||
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
|
||||
#define DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG
|
||||
|
||||
#include <DebugLog.h>
|
||||
#include <DebugLogEnable.h>
|
||||
#include <Arduino.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
#include <RS485_Driver.h>
|
||||
#include <TCA9554PWR_Driver.h>
|
||||
#include <PCF85063_Driver.h>
|
||||
#include <ETH_Driver.h>
|
||||
|
||||
#include <digitalIO.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
void callback(char *topic, uint8_t *payload, unsigned int length)
|
||||
@@ -42,29 +42,28 @@ void loop()
|
||||
const uint8_t relayBoardAddr(0x01);
|
||||
const uint8_t baseRegister(0x00);
|
||||
uint16_t k(0);
|
||||
uint8_t ethRetries(0);
|
||||
|
||||
//////////////// DEVICES ////////////////
|
||||
// Declared here to keep devices local to the main loop otherwise the kernel crashes //
|
||||
auto i2c = drivers::I2C();
|
||||
auto relays = drivers::TCA9554PWR(i2c, TCA9554_ADDRESS);
|
||||
auto bus = drivers::MODBUS(9600, SERIAL_8N1);
|
||||
auto rtc = drivers::PCF85063(i2c, PCF85063_ADDRESS);
|
||||
auto eth = drivers::Ethernet("waveshare-test");
|
||||
auto io = digitalIO(i2c, bus, {relayBoardAddr});
|
||||
|
||||
Network.onEvent([ð](arduino_event_id_t event, arduino_event_info_t info)
|
||||
{ eth.onEvent(event, info); });
|
||||
|
||||
while (!eth.isConnected())
|
||||
while (!eth.isConnected() && ethRetries++ < 5)
|
||||
{
|
||||
LOG_WARN("Waiting for Ethernet");
|
||||
LOG_WARN("Waiting for Ethernet retry", ethRetries);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// Set RTC time at startup
|
||||
// Get RTC time at startup
|
||||
time_t ntpTime;
|
||||
drivers::PCF85063::datetime_t dt;
|
||||
eth.getNtpTime(ntpTime);
|
||||
rtc.setDatetime(drivers::PCF85063::fromEpoch(ntpTime));
|
||||
|
||||
// MQTT Test
|
||||
NetworkClient tcp;
|
||||
@@ -101,10 +100,13 @@ void loop()
|
||||
results.clear();
|
||||
}
|
||||
|
||||
delay(500);
|
||||
LOG_INFO("====>Read Inputs");
|
||||
bus.readInputs(relayBoardAddr, 0x00, 8, values);
|
||||
printBool("====>Inputs", values);
|
||||
for (auto j(0); j < io.getOutNum(); j++)
|
||||
{
|
||||
//io.digitalIOWrite(j, true);
|
||||
LOG_INFO("Input", j, io.digitalIORead(j) ? "True" : "False");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user