From ad97260055187bfacd4b4e6d634c012e1d297c81 Mon Sep 17 00:00:00 2001 From: peteGSX <97784652+peteGSX@users.noreply.github.com> Date: Tue, 7 Feb 2023 07:32:16 +1000 Subject: [PATCH] Add extra error checking --- IO_EXIOExpander.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index d7d73ae..43a6155 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -114,8 +114,13 @@ private: _digitalOutBuffer[0] = EXIODPUP; _digitalOutBuffer[1] = pin; _digitalOutBuffer[2] = pullup; - I2CManager.write(_i2cAddress, _digitalOutBuffer, 3); - return true; + I2CManager.read(_i2cAddress, _command1Buffer, 1, _digitalOutBuffer, 3); + if (_command1Buffer[0] == EXIORDY) { + return true; + } else { + DIAG(F("Vpin %d cannot be used as a digital input pin"), (int)vpin); + return false; + } } else { return false; } @@ -126,7 +131,13 @@ private: int pin = vpin - _firstVpin; _command2Buffer[0] = EXIOENAN; _command2Buffer[1] = pin; - I2CManager.write(_i2cAddress, _command2Buffer, 2); + I2CManager.read(_i2cAddress, _command1Buffer, 1, _command2Buffer, 2); + if (_command1Buffer[0] == EXIORDY) { + return true; + } else { + DIAG(F("Vpin %d cannot be used as an analogue input pin"), (int)vpin); + return false; + } return true; } @@ -165,7 +176,10 @@ private: _digitalOutBuffer[0] = EXIOWRD; _digitalOutBuffer[1] = pin; _digitalOutBuffer[2] = value; - I2CManager.write(_i2cAddress, _digitalOutBuffer, 3); + I2CManager.read(_i2cAddress, _command1Buffer, 1, _digitalOutBuffer, 3); + if (_command1Buffer[0] != EXIORDY) { + DIAG(F("Vpin %d cannot be used as a digital output pin"), (int)vpin); + } } void _writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t param2) override {