diff --git a/IODevice.cpp b/IODevice.cpp index be26b92..32e6445 100644 --- a/IODevice.cpp +++ b/IODevice.cpp @@ -74,6 +74,13 @@ void IODevice::begin() { MCP23017::create(180, 16, 0x21); } +// reset() function to reinitialise all devices +void IODevice::reset() { + for (IODevice *dev = _firstDevice; dev != NULL; dev = dev->_nextDevice) { + dev->_begin(); + } +} + // Overarching static loop() method for the IODevice subsystem. Works through the // list of installed devices and calls their individual _loop() method. // Devices may or may not implement this, but if they do it is useful for things like animations @@ -302,9 +309,9 @@ IODevice *IODevice::findDeviceFollowing(VPIN vpin) { // Private helper function to check for vpin overlap. Run during setup only. // returns true if pins DONT overlap with existing device -bool IODevice::checkNoOverlap(VPIN firstPin, uint8_t nPins, uint8_t i2cAddress) { +bool IODevice::checkNoOverlap(VPIN firstPin, uint8_t nPins, I2CAddress i2cAddress) { #ifdef DIAG_IO - DIAG(F("Check no overlap %d %d 0x%x"), firstPin,nPins,i2cAddress); + DIAG(F("Check no overlap %d %d %s"), firstPin,nPins,i2cAddress.toString()); #endif VPIN lastPin=firstPin+nPins-1; for (IODevice *dev = _firstDevice; dev != 0; dev = dev->_nextDevice) { @@ -322,7 +329,7 @@ bool IODevice::checkNoOverlap(VPIN firstPin, uint8_t nPins, uint8_t i2cAddress) } // Check for overlapping I2C address if (i2cAddress && dev->_I2CAddress==i2cAddress) { - DIAG(F("WARNING HAL Overlap. i2c Addr 0x%x ignored."),(int)i2cAddress); + DIAG(F("WARNING HAL Overlap. i2c Addr %s ignored."),i2cAddress.toString()); return false; } } diff --git a/IODevice.h b/IODevice.h index f5c7c6f..8fd5efd 100644 --- a/IODevice.h +++ b/IODevice.h @@ -113,6 +113,10 @@ public: // Also, the _begin method of any existing instances is called from here. static void begin(); + // reset function to invoke all driver's _begin() methods again, to + // reset the state of the devices and reinitialise. + static void reset(); + // configure is used invoke an IODevice instance's _configure method static bool configure(VPIN vpin, ConfigTypeEnum configType, int paramCount, int params[]); @@ -165,7 +169,7 @@ public: void setGPIOInterruptPin(int16_t pinNumber); // Method to check if pins will overlap before creating new device. - static bool checkNoOverlap(VPIN firstPin, uint8_t nPins=1, uint8_t i2cAddress=0); + static bool checkNoOverlap(VPIN firstPin, uint8_t nPins=1, I2CAddress i2cAddress=0); // Method used by IODevice filters to locate slave pins that may be overlayed by their own // pin range. diff --git a/IO_AnalogueInputs.h b/IO_AnalogueInputs.h index a03d90f..8ff8683 100644 --- a/IO_AnalogueInputs.h +++ b/IO_AnalogueInputs.h @@ -85,7 +85,7 @@ private: _display(); #endif } else { - DIAG(F("ADS111x device not found, I2C:%x"), (int)_I2CAddress); + DIAG(F("ADS111x device not found, I2C:%s"), _I2CAddress.toString()); _deviceState = DEVSTATE_FAILED; } } @@ -131,7 +131,7 @@ private: break; } } else { // error status - DIAG(F("ADS111x I2C:x%x Error:%d %S"), (int)_I2CAddress, status, I2CManager.getErrorMessage(status)); + DIAG(F("ADS111x I2C:%s Error:%d %S"), _I2CAddress.toString(), status, I2CManager.getErrorMessage(status)); _deviceState = DEVSTATE_FAILED; } } @@ -142,7 +142,7 @@ private: } void _display() override { - DIAG(F("ADS111x I2C:x%x Configured on Vpins:%d-%d %S"), (int)_I2CAddress, _firstVpin, _firstVpin+_nPins-1, + DIAG(F("ADS111x I2C:%s Configured on Vpins:%d-%d %S"), _I2CAddress.toString(), _firstVpin, _firstVpin+_nPins-1, _deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F("")); } diff --git a/IO_EXFastclock.h b/IO_EXFastclock.h index 0e1bf76..442799b 100644 --- a/IO_EXFastclock.h +++ b/IO_EXFastclock.h @@ -56,7 +56,7 @@ static void create(uint8_t _I2CAddress) { // XXXX change thistosave2 bytes if (_checkforclock == 0) { FAST_CLOCK_EXISTS = true; - //DIAG(F("I2C Fast Clock found at x%x"), _I2CAddress); + //DIAG(F("I2C Fast Clock found at %s"), _I2CAddress.toString()); new EXFastClock(_I2CAddress); } else { @@ -68,7 +68,6 @@ static void create(uint8_t _I2CAddress) { } private: -uint8_t _I2CAddress; // Initialisation of Fastclock @@ -84,7 +83,7 @@ void _begin() override { } else { _deviceState = DEVSTATE_FAILED; //LCD(6,F("CLOCK NOT FOUND")); - DIAG(F("Fast Clock Not Found at address %d"), _I2CAddress); + DIAG(F("Fast Clock Not Found at address %s"), _I2CAddress.toString()); } } } @@ -120,7 +119,7 @@ void _loop(unsigned long currentMicros) override{ // Display EX-FastClock device driver info. void _display() { - DIAG(F("FastCLock on I2C:x%x - %S"), _I2CAddress, (_deviceState==DEVSTATE_FAILED) ? F("OFFLINE") : F("")); + DIAG(F("FastCLock on I2C:%s - %S"), _I2CAddress.toString(), (_deviceState==DEVSTATE_FAILED) ? F("OFFLINE") : F("")); } }; diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index d2269f6..06cbc24 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -63,7 +63,7 @@ private: EXIOExpander(VPIN firstVpin, int nPins, I2CAddress i2cAddress, int numDigitalPins, int numAnaloguePins) { _firstVpin = firstVpin; _nPins = nPins; - _i2cAddress = i2cAddress; + _I2CAddress = i2cAddress; _numDigitalPins = numDigitalPins; _numAnaloguePins = numAnaloguePins; _digitalPinBytes = (numDigitalPins+7)/8; @@ -76,31 +76,31 @@ private: void _begin() { // Initialise EX-IOExander device I2CManager.begin(); - if (I2CManager.exists(_i2cAddress)) { + if (I2CManager.exists(_I2CAddress)) { _digitalOutBuffer[0] = EXIOINIT; _digitalOutBuffer[1] = _numDigitalPins; _digitalOutBuffer[2] = _numAnaloguePins; // Send config, if EXIORDY returned, we're good, otherwise go offline - I2CManager.read(_i2cAddress, _commandBuffer, 1, _digitalOutBuffer, 3); + I2CManager.read(_I2CAddress, _commandBuffer, 1, _digitalOutBuffer, 3); if (_commandBuffer[0] != EXIORDY) { - DIAG(F("ERROR configuring EX-IOExpander device, I2C:x%x"), (int)_i2cAddress); + DIAG(F("ERROR configuring EX-IOExpander device, I2C:%s"), _I2CAddress.toString()); _deviceState = DEVSTATE_FAILED; return; } // Attempt to get version, if we don't get it, we don't care, don't go offline // Using digital in buffer in reverse to save RAM _commandBuffer[0] = EXIOVER; - I2CManager.read(_i2cAddress, _versionBuffer, 3, _commandBuffer, 1); + I2CManager.read(_I2CAddress, _versionBuffer, 3, _commandBuffer, 1); _majorVer = _versionBuffer[0]; _minorVer = _versionBuffer[1]; _patchVer = _versionBuffer[2]; - DIAG(F("EX-IOExpander device found, I2C:x%x, Version v%d.%d.%d"), - (int)_i2cAddress, _versionBuffer[0], _versionBuffer[1], _versionBuffer[2]); + DIAG(F("EX-IOExpander device found, I2C:%s, Version v%d.%d.%d"), + _I2CAddress.toString(), _versionBuffer[0], _versionBuffer[1], _versionBuffer[2]); #ifdef DIAG_IO _display(); #endif } else { - DIAG(F("EX-IOExpander device not found, I2C:x%x"), (int)_i2cAddress); + DIAG(F("EX-IOExpander device not found, I2C:%s"), _I2CAddress.toString()); _deviceState = DEVSTATE_FAILED; } } @@ -117,7 +117,7 @@ private: _digitalOutBuffer[0] = EXIODPUP; _digitalOutBuffer[1] = pin; _digitalOutBuffer[2] = pullup; - I2CManager.write(_i2cAddress, _digitalOutBuffer, 3); + I2CManager.write(_I2CAddress, _digitalOutBuffer, 3); return true; } @@ -130,16 +130,16 @@ private: int pin = vpin - _firstVpin; _analogueOutBuffer[0] = EXIOENAN; _analogueOutBuffer[1] = pin; - I2CManager.write(_i2cAddress, _analogueOutBuffer, 2); + I2CManager.write(_I2CAddress, _analogueOutBuffer, 2); return true; } void _loop(unsigned long currentMicros) override { (void)currentMicros; // remove warning _commandBuffer[0] = EXIORDD; - I2CManager.read(_i2cAddress, _digitalInputStates, _digitalPinBytes, _commandBuffer, 1); + I2CManager.read(_I2CAddress, _digitalInputStates, _digitalPinBytes, _commandBuffer, 1); _commandBuffer[0] = EXIORDAN; - I2CManager.read(_i2cAddress, _analogueInputStates, _analoguePinBytes, _commandBuffer, 1); + I2CManager.read(_I2CAddress, _analogueInputStates, _analoguePinBytes, _commandBuffer, 1); } int _readAnalogue(VPIN vpin) override { @@ -164,7 +164,7 @@ private: _digitalOutBuffer[0] = EXIOWRD; _digitalOutBuffer[1] = pin; _digitalOutBuffer[2] = value; - I2CManager.write(_i2cAddress, _digitalOutBuffer, 3); + I2CManager.write(_I2CAddress, _digitalOutBuffer, 3); } void _display() override { @@ -176,14 +176,13 @@ private: _firstAnalogue = _firstVpin + _numDigitalPins; _lastAnalogue = _firstVpin + _nPins - 1; } - DIAG(F("EX-IOExpander I2C:x%x v%d.%d.%d: %d Digital Vpins %d-%d, %d Analogue Vpins %d-%d %S"), - (int)_i2cAddress, _majorVer, _minorVer, _patchVer, + DIAG(F("EX-IOExpander I2C:%s v%d.%d.%d: %d Digital Vpins %d-%d, %d Analogue Vpins %d-%d %S"), + _I2CAddress.toString(), _majorVer, _minorVer, _patchVer, _numDigitalPins, _firstVpin, _firstVpin + _numDigitalPins - 1, _numAnaloguePins, _firstAnalogue, _lastAnalogue, _deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F("")); } - uint8_t _i2cAddress; uint8_t _numDigitalPins; uint8_t _numAnaloguePins; byte _analogueOutBuffer[2]; diff --git a/IO_EXTurntable.h b/IO_EXTurntable.h index 5b501b3..02a87e3 100644 --- a/IO_EXTurntable.h +++ b/IO_EXTurntable.h @@ -106,15 +106,15 @@ void EXTurntable::_writeAnalogue(VPIN vpin, int value, uint8_t activity, uint16_ DIAG(F("EX-Turntable WriteAnalogue Vpin:%d Value:%d Activity:%d Duration:%d"), vpin, value, activity, duration); DIAG(F("I2CManager write I2C Address:%d stepsMSB:%d stepsLSB:%d activity:%d"), - (int)_I2CAddress, stepsMSB, stepsLSB, activity); + _I2CAddress.toString(), stepsMSB, stepsLSB, activity); #endif _stepperStatus = 1; // Tell the device driver Turntable-EX is busy - I2CManager.write((int)_I2CAddress, 3, stepsMSB, stepsLSB, activity); + I2CManager.write(_I2CAddress, 3, stepsMSB, stepsLSB, activity); } // Display Turnetable-EX device driver info. void EXTurntable::_display() { - DIAG(F("EX-Turntable I2C:x%x Configured on Vpins:%d-%d %S"), (int)_I2CAddress, (int)_firstVpin, + DIAG(F("EX-Turntable I2C:%s Configured on Vpins:%d-%d %S"), _I2CAddress.toString(), (int)_firstVpin, (int)_firstVpin+_nPins-1, (_deviceState==DEVSTATE_FAILED) ? F("OFFLINE") : F("")); } diff --git a/IO_GPIOBase.h b/IO_GPIOBase.h index 17e72d6..0f7019c 100644 --- a/IO_GPIOBase.h +++ b/IO_GPIOBase.h @@ -107,7 +107,7 @@ void GPIOBase::_begin() { _setupDevice(); _deviceState = DEVSTATE_NORMAL; } else { - DIAG(F("%S I2C:x%x Device not detected"), _deviceName, (int)_I2CAddress); + DIAG(F("%S I2C:%s Device not detected"), _deviceName, _I2CAddress.toString()); _deviceState = DEVSTATE_FAILED; } } @@ -121,7 +121,7 @@ bool GPIOBase::_configure(VPIN vpin, ConfigTypeEnum configType, int paramCoun bool pullup = params[0]; int pin = vpin - _firstVpin; #ifdef DIAG_IO - DIAG(F("%S I2C:x%x Config Pin:%d Val:%d"), _deviceName, (int)_I2CAddress, pin, pullup); + DIAG(F("%S I2C:%s Config Pin:%d Val:%d"), _deviceName, _I2CAddress.toString(), pin, pullup); #endif uint16_t mask = 1 << pin; if (pullup) @@ -151,7 +151,7 @@ void GPIOBase::_loop(unsigned long currentMicros) { _deviceState = DEVSTATE_NORMAL; } else { _deviceState = DEVSTATE_FAILED; - DIAG(F("%S I2C:x%x Error:%d %S"), _deviceName, (int)_I2CAddress, status, + DIAG(F("%S I2C:%s Error:%d %S"), _deviceName, _I2CAddress.toString(), status, I2CManager.getErrorMessage(status)); } _processCompletion(status); @@ -174,7 +174,7 @@ void GPIOBase::_loop(unsigned long currentMicros) { #ifdef DIAG_IO if (differences) - DIAG(F("%S I2C:x%x PortStates:%x"), _deviceName, (int)_I2CAddress, _portInputState); + DIAG(F("%S I2C:%s PortStates:%x"), _deviceName, _I2CAddress.toString(), _portInputState); #endif } @@ -195,7 +195,7 @@ void GPIOBase::_loop(unsigned long currentMicros) { template void GPIOBase::_display() { - DIAG(F("%S I2C:x%x Configured on Vpins:%d-%d %S"), _deviceName, (int)_I2CAddress, + DIAG(F("%S I2C:%s Configured on Vpins:%d-%d %S"), _deviceName, _I2CAddress.toString(), _firstVpin, _firstVpin+_nPins-1, (_deviceState==DEVSTATE_FAILED) ? F("OFFLINE") : F("")); } @@ -204,7 +204,7 @@ void GPIOBase::_write(VPIN vpin, int value) { int pin = vpin - _firstVpin; T mask = 1 << pin; #ifdef DIAG_IO - DIAG(F("%S I2C:x%x Write Pin:%d Val:%d"), _deviceName, (int)_I2CAddress, pin, value); + DIAG(F("%S I2C:%s Write Pin:%d Val:%d"), _deviceName, _I2CAddress.toString(), pin, value); #endif // Set port mode output if currently not output mode @@ -240,7 +240,7 @@ int GPIOBase::_read(VPIN vpin) { // Set unused pin and write mode pin value to 1 _portInputState |= ~_portInUse | _portMode; #ifdef DIAG_IO - DIAG(F("%S I2C:x%x PortStates:%x"), _deviceName, (int)_I2CAddress, _portInputState); + DIAG(F("%S I2C:%s PortStates:%x"), _deviceName, _I2CAddress.toString(), _portInputState); #endif } return (_portInputState & mask) ? 0 : 1; // Invert state (5v=0, 0v=1) diff --git a/IO_OLEDDisplay.h b/IO_OLEDDisplay.h index 9aefbaa..1ef8ed1 100644 --- a/IO_OLEDDisplay.h +++ b/IO_OLEDDisplay.h @@ -86,32 +86,38 @@ protected: _buffer = (char *)calloc(_numRows*_numCols, sizeof(char)); _rowGeneration = (uint8_t *)calloc(_numRows, sizeof(uint8_t)); _lastRowGeneration = (uint8_t *)calloc(_numRows, sizeof(uint8_t)); + // Fill buffer with spaces + memset(_buffer, ' ', _numCols*_numRows); + + // Create OLED driver + oled = new SSD1306AsciiWire(); + + // Clear the entire screen + oled->clearNative(); addDevice(this); } - + // Device-specific initialisation void _begin() override { - // Create OLED driver - oled = new SSD1306AsciiWire(); // Initialise device if (oled->begin(_I2CAddress, _width, _height)) { // Store pointer to this object into CS display hook, so that we // will intercept any subsequent calls to lcdDisplay methods. DisplayInterface::lcdDisplay = this; - DIAG(F("OLEDDisplay installed on address x%x"), (int)_I2CAddress); - - // First clear the entire screen - oled->clearNative(); + DIAG(F("OLEDDisplay installed on address %s"), _I2CAddress.toString()); // Set first two lines on screen LCD(0,F("DCC++ EX v%S"),F(VERSION)); LCD(1,F("Lic GPLv3")); + + // Force all rows to be redrawn + for (uint8_t row=0; row<_numRows; row++) + _rowGeneration[row]++; } } - void _loop(unsigned long) override { // Loop through the buffer and if a row has changed @@ -196,7 +202,7 @@ protected: // Display information about the device. void _display() { - DIAG(F("OLEDDisplay Configured addr x%x"), (int)_I2CAddress); + DIAG(F("OLEDDisplay Configured addr %s"), _I2CAddress.toString()); } }; diff --git a/IO_PCA9685.cpp b/IO_PCA9685.cpp index f7a6882..68e44a1 100644 --- a/IO_PCA9685.cpp +++ b/IO_PCA9685.cpp @@ -239,13 +239,13 @@ void PCA9685::updatePosition(uint8_t pin) { // between 0 and 4095 for the PWM mark-to-period ratio, with 4095 being 100%. void PCA9685::writeDevice(uint8_t pin, int value) { #ifdef DIAG_IO - DIAG(F("PCA9685 I2C:x%x WriteDevice Pin:%d Value:%d"), (int)_I2CAddress, pin, value); + DIAG(F("PCA9685 I2C:%s WriteDevice Pin:%d Value:%d"), _I2CAddress.toString(), pin, value); #endif // Wait for previous request to complete uint8_t status = requestBlock.wait(); if (status != I2C_STATUS_OK) { _deviceState = DEVSTATE_FAILED; - DIAG(F("PCA9685 I2C:x%x failed %S"), (int)_I2CAddress, I2CManager.getErrorMessage(status)); + DIAG(F("PCA9685 I2C:%s failed %S"), _I2CAddress.toString(), I2CManager.getErrorMessage(status)); } else { // Set up new request. outputBuffer[0] = PCA9685_FIRST_SERVO + 4 * pin; @@ -259,7 +259,7 @@ void PCA9685::writeDevice(uint8_t pin, int value) { // Display details of this device. void PCA9685::_display() { - DIAG(F("PCA9685 I2C:x%x Configured on Vpins:%d-%d %S"), (int)_I2CAddress, (int)_firstVpin, + DIAG(F("PCA9685 I2C:%s Configured on Vpins:%d-%d %S"), _I2CAddress.toString(), (int)_firstVpin, (int)_firstVpin+_nPins-1, (_deviceState==DEVSTATE_FAILED) ? F("OFFLINE") : F("")); } diff --git a/IO_PCA9685pwm.h b/IO_PCA9685pwm.h index 72884a9..ef92118 100644 --- a/IO_PCA9685pwm.h +++ b/IO_PCA9685pwm.h @@ -101,8 +101,8 @@ private: void _writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t param2) override { (void)param1; (void)param2; // suppress compiler warning #ifdef DIAG_IO - DIAG(F("PCA9685pwm WriteAnalogue Vpin:%d Value:%d Profile:%d Duration:%d %S"), - vpin, value, profile, duration, _deviceState == DEVSTATE_FAILED?F("DEVSTATE_FAILED"):F("")); + DIAG(F("PCA9685pwm WriteAnalogue Vpin:%d Value:%d %S"), + vpin, value, _deviceState == DEVSTATE_FAILED?F("DEVSTATE_FAILED"):F("")); #endif if (_deviceState == DEVSTATE_FAILED) return; int pin = vpin - _firstVpin; @@ -114,7 +114,7 @@ private: // Display details of this device. void _display() override { - DIAG(F("PCA9685pwm I2C:x%x Configured on Vpins:%d-%d %S"), (int)_I2CAddress, (int)_firstVpin, + DIAG(F("PCA9685pwm I2C:%s Configured on Vpins:%d-%d %S"), _I2CAddress.toString(), (int)_firstVpin, (int)_firstVpin+_nPins-1, (_deviceState==DEVSTATE_FAILED) ? F("OFFLINE") : F("")); } @@ -122,13 +122,13 @@ private: // between 0 and 4095 for the PWM mark-to-period ratio, with 4095 being 100%. void writeDevice(uint8_t pin, int value) { #ifdef DIAG_IO - DIAG(F("PCA9685pwm I2C:x%x WriteDevice Pin:%d Value:%d"), (int)_I2CAddress, pin, value); + DIAG(F("PCA9685pwm I2C:%s WriteDevice Pin:%d Value:%d"), _I2CAddress.toString(), pin, value); #endif // Wait for previous request to complete uint8_t status = requestBlock.wait(); if (status != I2C_STATUS_OK) { _deviceState = DEVSTATE_FAILED; - DIAG(F("PCA9685pwm I2C:x%x failed %S"), (int)_I2CAddress, I2CManager.getErrorMessage(status)); + DIAG(F("PCA9685pwm I2C:%s failed %S"), _I2CAddress.toString(), I2CManager.getErrorMessage(status)); } else { // Set up new request. outputBuffer[0] = PCA9685_FIRST_SERVO + 4 * pin; diff --git a/IO_RotaryEncoder.h b/IO_RotaryEncoder.h index 6de97af..9cf4e65 100644 --- a/IO_RotaryEncoder.h +++ b/IO_RotaryEncoder.h @@ -104,7 +104,7 @@ private: } void _display() override { - DIAG(F("Rotary Encoder I2C:x%x v%d.%d.%d Configured on Vpin:%d-%d %S"), (int)_I2CAddress, _majorVer, _minorVer, _patchVer, + DIAG(F("Rotary Encoder I2C:%s v%d.%d.%d Configured on Vpin:%d-%d %S"), _I2CAddress.toString(), _majorVer, _minorVer, _patchVer, (int)_firstVpin, _firstVpin+_nPins-1, (_deviceState==DEVSTATE_FAILED) ? F("OFFLINE") : F("")); } diff --git a/IO_VL53L0X.h b/IO_VL53L0X.h index 86d9624..a1e1dcc 100644 --- a/IO_VL53L0X.h +++ b/IO_VL53L0X.h @@ -159,7 +159,9 @@ protected: if (_xshutPin == VPIN_NONE && I2CManager.exists(_I2CAddress)) { // Device already present on this address, so skip the address initialisation. _nextState = STATE_CONFIGUREDEVICE; - } + } else + _nextState = STATE_INIT; + } void _loop(unsigned long currentMicros) override { @@ -171,7 +173,7 @@ protected: // If no XSHUT pin is configured, then only one device is supported. if (_xshutPin != VPIN_NONE) IODevice::write(_xshutPin, 0); _nextState = STATE_RESTARTMODULE; - delayUntil(currentMicros+1000); + delayUntil(currentMicros+10000); break; case STATE_RESTARTMODULE: // On second entry, set XSHUT pin high to allow this module to restart. @@ -183,9 +185,8 @@ protected: // shared flag accessible to all device instances. if (_addressConfigInProgress) return; _addressConfigInProgress = true; - // Set XSHUT pin (if connected). Because of supply voltage differences, - // drive the signal through the digital output's pull-up resistor. - if (_xshutPin != VPIN_NONE) IODevice::configureInput(_xshutPin, 1); + // Set XSHUT pin (if connected) to bring the module out of sleep mode. + if (_xshutPin != VPIN_NONE) IODevice::write(_xshutPin, 1); // Allow the module time to restart delayUntil(currentMicros+10000); _nextState = STATE_CONFIGUREADDRESS; @@ -202,15 +203,12 @@ protected: I2CManager.write(VL53L0X_I2C_DEFAULT_ADDRESS, 2, VL53L0X_REG_I2C_SLAVE_DEVICE_ADDRESS, _I2CAddress); #endif } - _addressConfigInProgress = false; - _nextState = STATE_SKIP; - break; - case STATE_SKIP: - // Do nothing on the third entry. - _nextState = STATE_CONFIGUREDEVICE; + delayUntil(currentMicros+10000); break; case STATE_CONFIGUREDEVICE: - // On next entry, check if device address has been set. + // Allow next VL53L0X device to be configured + _addressConfigInProgress = false; + // Now check if device address has been set. if (I2CManager.exists(_I2CAddress)) { #ifdef DIAG_IO _display(); @@ -220,7 +218,7 @@ protected: read_reg(VL53L0X_CONFIG_PAD_SCL_SDA__EXTSUP_HV) | 0x01); _nextState = STATE_INITIATESCAN; } else { - DIAG(F("VL53L0X I2C:x%x device not responding"), (int)_I2CAddress); + DIAG(F("VL53L0X I2C:%s device not responding"), _I2CAddress.toString()); _deviceState = DEVSTATE_FAILED; _nextState = STATE_FAILED; } @@ -285,7 +283,7 @@ protected: // Function to report a failed I2C operation. Put the device off-line. void reportError(uint8_t status) { - DIAG(F("VL53L0X I2C:x%x Error:%d %S"), (int)_I2CAddress, status, I2CManager.getErrorMessage(status)); + DIAG(F("VL53L0X I2C:%s Error:%d %S"), _I2CAddress.toString(), status, I2CManager.getErrorMessage(status)); _deviceState = DEVSTATE_FAILED; _value = false; } @@ -314,8 +312,8 @@ protected: } void _display() override { - DIAG(F("VL53L0X I2C:x%x Configured on Vpins:%d-%d On:%dmm Off:%dmm %S"), - (int)_I2CAddress, _firstVpin, _firstVpin+_nPins-1, _onThreshold, _offThreshold, + DIAG(F("VL53L0X I2C:%s Configured on Vpins:%d-%d On:%dmm Off:%dmm %S"), + _I2CAddress.toString(), _firstVpin, _firstVpin+_nPins-1, _onThreshold, _offThreshold, (_deviceState==DEVSTATE_FAILED) ? F("OFFLINE") : F("")); } diff --git a/LiquidCrystal_I2C.cpp b/LiquidCrystal_I2C.cpp index b18614f..a5c2e16 100644 --- a/LiquidCrystal_I2C.cpp +++ b/LiquidCrystal_I2C.cpp @@ -53,7 +53,7 @@ LiquidCrystal_I2C::LiquidCrystal_I2C(I2CAddress lcd_Addr, uint8_t lcd_cols, I2CManager.setClock(100000L); // PCF8574 is spec'd to 100kHz. if (I2CManager.exists(lcd_Addr)) { - DIAG(F("%dx%d LCD configured on I2C:x%x"), (int)lcd_cols, (int)lcd_rows, (int)lcd_Addr); + DIAG(F("%dx%d LCD configured on I2C:%s"), (int)lcd_cols, (int)lcd_rows, (int)lcd_Addr); _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; begin(); backlight(); diff --git a/SSD1306Ascii.cpp b/SSD1306Ascii.cpp index 12d8702..deae5ac 100644 --- a/SSD1306Ascii.cpp +++ b/SSD1306Ascii.cpp @@ -197,7 +197,7 @@ bool SSD1306AsciiWire::begin(I2CAddress address, int width, int height) { return false; } // Device found - DIAG(F("%dx%d OLED display configured on I2C:x%x"), m_displayWidth, m_displayHeight, (int)m_i2cAddr); + DIAG(F("%dx%d OLED display configured on I2C:%s"), m_displayWidth, m_displayHeight, m_i2cAddr.toString()); clear(); return true; }