From 459904e5ddc16361d43cd033d7e2e1725f8f7211 Mon Sep 17 00:00:00 2001 From: peteGSX Date: Mon, 23 Jan 2023 20:12:28 +1000 Subject: [PATCH] More analogue inputs --- IO_EXIOExpander.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index 77554b5..9fc6876 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -67,9 +67,9 @@ private: _numDigitalPins = numDigitalPins; _numAnaloguePins = numAnaloguePins; _digitalPinBytes = (numDigitalPins+7)/8; - _analoguePinBytes = (numAnaloguePins+7)/8; + _analoguePinBytes = numAnaloguePins * 2; _digitalInputStates=(byte*) calloc(_digitalPinBytes,1); - _analogueInputStates=(byte*) calloc(_analoguePinBytes,2); + _analogueInputStates=(byte*) calloc(_analoguePinBytes,1); addDevice(this); } @@ -130,7 +130,6 @@ private: int pin = vpin - _firstVpin; _analogueOutBuffer[0] = EXIOENAN; _analogueOutBuffer[1] = pin; - DIAG(F("Enable Vpin %d/pin %d"), vpin, pin); I2CManager.write(_i2cAddress, _analogueOutBuffer, 2); return true; } @@ -140,7 +139,6 @@ private: I2CManager.read(_i2cAddress, _digitalInputStates, _digitalPinBytes, _commandBuffer, 1); _commandBuffer[0] = EXIORDAN; I2CManager.read(_i2cAddress, _analogueInputStates, _analoguePinBytes, _commandBuffer, 1); - delayUntil(currentMicros + 500000); } int _readAnalogue(VPIN vpin) override { @@ -150,9 +148,10 @@ private: // _analogueOutBuffer[1] = pin; // I2CManager.read(_i2cAddress, _analogueInBuffer, 2, _analogueOutBuffer, 2); // return (_analogueInBuffer[1] << 8) + _analogueInBuffer[0]; - uint8_t _pinLSBByte = (pin / 4) * 2; + uint8_t _pinLSBByte = pin * 2; uint8_t _pinMSBByte = _pinLSBByte + 1; - return (_pinMSBByte << 8) + _pinLSBByte; + // DIAG(F("Vpin %d LSB %d MSB %d"), vpin, _analogueInputStates[_pinLSBByte], _analogueInputStates[_pinMSBByte]); + return (_analogueInputStates[_pinMSBByte] << 8) + _analogueInputStates[_pinLSBByte]; } int _read(VPIN vpin) override {