From f007fe83ef96630debb845891ab8f8b18529ac67 Mon Sep 17 00:00:00 2001 From: tyeth Date: Wed, 20 Aug 2025 14:20:24 +0100 Subject: [PATCH] refactor(mlx90632d): support extended range at init --- src/components/i2c/WipperSnapper_I2C.cpp | 23 ++++++++++++++----- src/components/i2c/WipperSnapper_I2C.h | 5 ++-- ...h => WipperSnapper_I2C_Driver_MLX90632D.h} | 0 3 files changed, 20 insertions(+), 8 deletions(-) rename src/components/i2c/drivers/{WipperSnapper_I2C_Driver_MLX90632.h => WipperSnapper_I2C_Driver_MLX90632D.h} (100%) diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index c301eaeb..3116af30 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -537,18 +537,29 @@ bool WipperSnapper_Component_I2C::initI2CDevice( _mcp9808->configureDriver(msgDeviceInitReq); drivers.push_back(_mcp9808); WS_DEBUG_PRINTLN("MCP9808 Initialized Successfully!"); - } else if (strcmp("mlx90632d_med", msgDeviceInitReq->i2c_device_name) == 0 || - strcmp("mlx90632d_ext", msgDeviceInitReq->i2c_device_name) == 0) { - _mlx90632 = new WipperSnapper_I2C_Driver_MLX90632D(this->_i2c, i2cAddress); - if (!_mlx90632->begin()) { + } else if (strcmp("mlx90632d_med", msgDeviceInitReq->i2c_device_name) == 0) { + _mlx90632d = new WipperSnapper_I2C_Driver_MLX90632D(this->_i2c, i2cAddress); + if (!_mlx90632d->begin()) { WS_DEBUG_PRINTLN("ERROR: Failed to initialize MLX90632!"); _busStatusResponse = wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; return false; } - _mlx90632->configureDriver(msgDeviceInitReq); - drivers.push_back(_mlx90632); + _mlx90632d->configureDriver(msgDeviceInitReq); + drivers.push_back(_mlx90632d); WS_DEBUG_PRINTLN("MLX90632 Initialized Successfully!"); + } else if (strcmp("mlx90632d_ext", msgDeviceInitReq->i2c_device_name) == 0) { + _mlx90632d_ext = new WipperSnapper_I2C_Driver_MLX90632D(this->_i2c, i2cAddress); + // set extended range + if (!_mlx90632d_ext->begin() || !_mlx90632d_ext->ConfigureAndPrintSensorInfo(true)) { + WS_DEBUG_PRINTLN("ERROR: Failed to initialize MLX90632D with extended range!"); + _busStatusResponse = + wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; + return false; + } + _mlx90632d_ext->configureDriver(msgDeviceInitReq); + drivers.push_back(_mlx90632d_ext); + WS_DEBUG_PRINTLN("MLX90632D_EXT Initialized Successfully!"); } else if (strcmp("mpl115a2", msgDeviceInitReq->i2c_device_name) == 0) { _mpl115a2 = new WipperSnapper_I2C_Driver_MPL115A2(this->_i2c, i2cAddress); if (!_mpl115a2->begin()) { diff --git a/src/components/i2c/WipperSnapper_I2C.h b/src/components/i2c/WipperSnapper_I2C.h index 33f9fdc7..9dc4c5cb 100644 --- a/src/components/i2c/WipperSnapper_I2C.h +++ b/src/components/i2c/WipperSnapper_I2C.h @@ -50,7 +50,7 @@ #include "drivers/WipperSnapper_I2C_Driver_MAX17048.h" #include "drivers/WipperSnapper_I2C_Driver_MCP3421.h" #include "drivers/WipperSnapper_I2C_Driver_MCP9808.h" -#include "drivers/WipperSnapper_I2C_Driver_MLX90632.h" +#include "drivers/WipperSnapper_I2C_Driver_MLX90632D.h" #include "drivers/WipperSnapper_I2C_Driver_MPL115A2.h" #include "drivers/WipperSnapper_I2C_Driver_MPRLS.h" #include "drivers/WipperSnapper_I2C_Driver_MS8607.h" @@ -181,7 +181,8 @@ private: WipperSnapper_I2C_Driver_LTR390 *_ltr390 = nullptr; WipperSnapper_I2C_Driver_MCP3421 *_mcp3421 = nullptr; WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr; - WipperSnapper_I2C_Driver_MLX90632D *_mlx90632 = nullptr; + WipperSnapper_I2C_Driver_MLX90632D *_mlx90632d = nullptr; + WipperSnapper_I2C_Driver_MLX90632D *_mlx90632d_ext = nullptr; WipperSnapper_I2C_Driver_MPL115A2 *_mpl115a2 = nullptr; WipperSnapper_I2C_Driver_MPRLS *_mprls = nullptr; WipperSnapper_I2C_Driver_MS8607 *_ms8607 = nullptr; diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MLX90632.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MLX90632D.h similarity index 100% rename from src/components/i2c/drivers/WipperSnapper_I2C_Driver_MLX90632.h rename to src/components/i2c/drivers/WipperSnapper_I2C_Driver_MLX90632D.h