1313#include < Adafruit_BusIO_Register.h>
1414#include < Adafruit_I2CDevice.h>
1515#include < cstdint>
16+ #include < etl/format_spec.h>
17+ #include < etl/string.h>
18+ #include < etl/to_string.h>
1619
1720/* *
1821 * @brief Class to interface with the MCP23008T I2C 8-Bit I/O Expander
4043 */
4144class MCP23008T {
4245 public: // MARK: Public Constants
46+ static constexpr const char *TAG = " IOE" ;
47+
4348 static constexpr uint16_t REG_IODIR_ADDR = 0x00 ;
4449 static constexpr uint16_t REG_IPOL_ADDR = 0x01 ;
4550 static constexpr uint16_t REG_GPINTEN_ADDR = 0x02 ;
@@ -219,7 +224,10 @@ class MCP23008T {
219224 *
220225 * @returns Returns true on success, false otherwise
221226 */
222- inline bool setGPIO (uint32_t value) { return regGPIO.write (value); }
227+ inline bool setGPIO (uint32_t value) {
228+ ESP_LOGV (TAG , " Setpoint %u" , value);
229+ return regGPIO.write (value);
230+ }
223231
224232 /* *
225233 * @details The OLAT register provides access to the output latches. A read
@@ -243,6 +251,27 @@ class MCP23008T {
243251 return device.address ();
244252 }
245253
254+ static constexpr uint_fast8_t LOG_STRING_SIZE = 3 + 5 + 2 + (3 * 2 ) + 1 ;
255+ /* *
256+ * @brief Get at string that describes the current state of the actuator
257+ * @returns the current state of the actuator as a string
258+ */
259+ etl::string<LOG_STRING_SIZE > getLogString () {
260+ etl::string<LOG_STRING_SIZE > logString (TAG ); // 3 chars
261+ logString.append (" : @ox" ); // 5 chars
262+
263+ etl::format_spec format2;
264+ format2.hex ().width (2 ).fill (' 0' ); // [2 chars]
265+ etl::to_string (getAddress (), logString, format2, true ); // 2 chars
266+
267+ etl::format_spec format3;
268+ format3.hex ().width (3 ).fill (' 0' ); // [3 chars]
269+ etl::to_string (readIntCap (), logString, format3, true ); // 3 chars
270+ etl::to_string (readIntFlag (), logString, format3, true ); // 3 chars
271+
272+ return logString;
273+ }
274+
246275 private: // MARK: Private
247276 Adafruit_I2CDevice device;
248277
0 commit comments