DigitalIO driver with dynamic channel count

This commit is contained in:
Emanuele Trabattoni
2025-07-12 13:45:00 +02:00
parent 1955b8cb39
commit ef7b9506b6
8 changed files with 335 additions and 38 deletions

View File

@@ -39,7 +39,7 @@ namespace drivers
uint8_t currState(0);
uint8_t newState(0);
if (ch < OUT_PIN1 || ch > OUT_PIN8)
if (ch < DO1 || ch > DO8)
{
LOG_ERROR("Invalid write to output channel: [%d]", ch);
return false;
@@ -64,7 +64,7 @@ namespace drivers
const bool TCA9554PWR::readOut(const uint8_t ch)
{
uint8_t currState(0);
if (ch < OUT_PIN1 || ch > OUT_PIN8)
if (ch < DO1 || ch > DO8)
{
LOG_ERROR("Invalid read to output channel: [%d]", ch);
return false;

View File

@@ -21,18 +21,18 @@ namespace drivers
{
public:
enum
typedef enum
{
OUT_PIN1,
OUT_PIN2,
OUT_PIN3,
OUT_PIN4,
OUT_PIN5,
OUT_PIN6,
OUT_PIN7,
OUT_PIN8,
OUT_PIN_MAX
};
DO1,
DO2,
DO3,
DO4,
DO5,
DO6,
DO7,
DO8,
DO_MAX
} channel_t;
TCA9554PWR(I2C &i2c, const uint8_t address);
~TCA9554PWR();

View File

@@ -6,17 +6,6 @@
#include <CRC16.h>
#include <memory>
#define Extension_CH1 1 // Expansion Channel 1
#define Extension_CH2 2 // Expansion Channel 2
#define Extension_CH3 3 // Expansion Channel 3
#define Extension_CH4 4 // Expansion Channel 4
#define Extension_CH5 5 // Expansion Channel 5
#define Extension_CH6 6 // Expansion Channel 6
#define Extension_CH7 7 // Expansion Channel 7
#define Extension_CH8 8 // Expansion Channel 8
#define Extension_ALL_ON 9 // Expansion ALL ON
#define Extension_ALL_OFF 10 // Expansion ALL OFF
namespace drivers
{
class RS485
@@ -34,7 +23,7 @@ namespace drivers
HardwareSerial &m_serial;
};
class MODBUS : public RS485
class MODBUS : private RS485
{
static const uint8_t RESP_HEADER_SIZE = 3;