From af468e6b4b99f1ff5640df869643183653ac0659 Mon Sep 17 00:00:00 2001 From: unlogisch04 <98281608+unlogisch04@users.noreply.github.com> Date: Sat, 31 May 2025 18:14:14 +0200 Subject: [PATCH] Esp32 fix defines (#452) * fix debugbuild * make all esp32 define the same only check if ESP32 is defined. The value changed from "1" to "ESP32" in pioarduino and tasmota in newer versions. --- lib/i2cscan/i2cscan.cpp | 6 +++--- src/batterymonitor.cpp | 2 +- src/main.cpp | 2 +- src/sensorinterface/I2CPCAInterface.cpp | 2 +- src/sensorinterface/I2CWireSensorInterface.cpp | 6 +++--- src/sensorinterface/SensorInterface.h | 2 +- src/sensors/ADCResistanceSensor.cpp | 4 ++-- src/sensors/SensorBuilder.h | 2 +- src/sensors/SensorFusion.h | 2 +- src/sensors/SensorFusionDMP.h | 2 +- src/serial/serialcommands.cpp | 6 +++--- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/i2cscan/i2cscan.cpp b/lib/i2cscan/i2cscan.cpp index 00c2816..2eda286 100644 --- a/lib/i2cscan/i2cscan.cpp +++ b/lib/i2cscan/i2cscan.cpp @@ -70,7 +70,7 @@ namespace I2CSCAN if (!found) { Serial.println("[ERR] I2C: No I2C devices found"); } -#if ESP32 +#ifdef ESP32 Wire.end(); #endif Wire.begin(static_cast(PIN_IMU_SDA), static_cast(PIN_IMU_SCL)); @@ -89,7 +89,7 @@ namespace I2CSCAN } if (currentAddress == 1) { -#if ESP32 +#ifdef ESP32 Wire.end(); #endif } @@ -214,4 +214,4 @@ namespace I2CSCAN pinMode(SCL, INPUT); return 0; } -} \ No newline at end of file +} diff --git a/src/batterymonitor.cpp b/src/batterymonitor.cpp index f6dcddd..7c0db20 100644 --- a/src/batterymonitor.cpp +++ b/src/batterymonitor.cpp @@ -74,7 +74,7 @@ void BatteryMonitor::Loop() { voltage = ((float)analogRead(PIN_BATTERY_LEVEL)) * ADCVoltageMax / ADCResolution * ADCMultiplier; #endif -#if ESP32 && BATTERY_MONITOR == BAT_EXTERNAL +#if defined(ESP32) && BATTERY_MONITOR == BAT_EXTERNAL voltage = ((float)analogReadMilliVolts(PIN_BATTERY_LEVEL)) / 1000 * ADCMultiplier; #endif diff --git a/src/main.cpp b/src/main.cpp index 547ebba..9f8ce15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -83,7 +83,7 @@ void setup() { // join I2C bus -#if ESP32 +#ifdef ESP32 // For some unknown reason the I2C seem to be open on ESP32-C3 by default. Let's // just close it before opening it again. (The ESP32-C3 only has 1 I2C.) Wire.end(); diff --git a/src/sensorinterface/I2CPCAInterface.cpp b/src/sensorinterface/I2CPCAInterface.cpp index acbc374..826583b 100644 --- a/src/sensorinterface/I2CPCAInterface.cpp +++ b/src/sensorinterface/I2CPCAInterface.cpp @@ -32,7 +32,7 @@ void SlimeVR::I2CPCASensorInterface::swapIn() { Wire.beginTransmission(m_Address); Wire.write(1 << m_Channel); Wire.endTransmission(); -#if ESP32 +#ifdef ESP32 // On ESP32 we need to reconnect to I2C bus for some reason m_Wire.disconnect(); m_Wire.swapIn(); diff --git a/src/sensorinterface/I2CWireSensorInterface.cpp b/src/sensorinterface/I2CWireSensorInterface.cpp index bddc897..42bacc6 100644 --- a/src/sensorinterface/I2CWireSensorInterface.cpp +++ b/src/sensorinterface/I2CWireSensorInterface.cpp @@ -25,7 +25,7 @@ #include -#if ESP32 +#ifdef ESP32 #include "driver/i2c.h" #endif @@ -37,7 +37,7 @@ namespace SlimeVR { void swapI2C(uint8_t sclPin, uint8_t sdaPin) { if (sclPin != activeSCLPin || sdaPin != activeSDAPin || !isI2CActive) { Wire.flush(); -#if ESP32 +#ifdef ESP32 if (!isI2CActive) { // Reset HWI2C to avoid being affected by I2CBUS reset Wire.end(); @@ -68,7 +68,7 @@ void swapI2C(uint8_t sclPin, uint8_t sdaPin) { void disconnectI2C() { Wire.flush(); isI2CActive = false; -#if ESP32 +#ifdef ESP32 Wire.end(); #endif } diff --git a/src/sensorinterface/SensorInterface.h b/src/sensorinterface/SensorInterface.h index 4b999f9..983e375 100644 --- a/src/sensorinterface/SensorInterface.h +++ b/src/sensorinterface/SensorInterface.h @@ -31,7 +31,7 @@ class SensorInterface { public: virtual bool init() = 0; virtual void swapIn() = 0; - [[nodiscard]] virtual std::string toString() const; + [[nodiscard]] virtual std::string toString() const = 0; }; class EmptySensorInterface : public SensorInterface { diff --git a/src/sensors/ADCResistanceSensor.cpp b/src/sensors/ADCResistanceSensor.cpp index 7415e83..c40708e 100644 --- a/src/sensors/ADCResistanceSensor.cpp +++ b/src/sensors/ADCResistanceSensor.cpp @@ -30,7 +30,7 @@ void ADCResistanceSensor::motionLoop() { float voltage = ((float)analogRead(m_Pin)) * ADCVoltageMax / ADCResolution; m_Data = m_ResistanceDivider * (ADCVoltageMax / voltage - 1.0f); // Convert voltage to resistance -#elif ESP32 +#elif defined(ESP32) float voltage = ((float)analogReadMilliVolts(m_Pin)) / 1000; m_Data = m_ResistanceDivider * (m_VCC / voltage - 1.0f); // Convert voltage to resistance @@ -41,4 +41,4 @@ void ADCResistanceSensor::sendData() { networkConnection.sendFlexData(sensorId, m_Data); } -} // namespace SlimeVR::Sensors \ No newline at end of file +} // namespace SlimeVR::Sensors diff --git a/src/sensors/SensorBuilder.h b/src/sensors/SensorBuilder.h index 5bed41d..88c4af6 100644 --- a/src/sensors/SensorBuilder.h +++ b/src/sensors/SensorBuilder.h @@ -78,7 +78,7 @@ #define SFCALIBRATOR SlimeVR::Sensor::SoftfusionCalibrator #endif -#if ESP32 +#ifdef ESP32 #include "driver/i2c.h" #endif diff --git a/src/sensors/SensorFusion.h b/src/sensors/SensorFusion.h index 726767e..ceccb18 100644 --- a/src/sensors/SensorFusion.h +++ b/src/sensors/SensorFusion.h @@ -98,7 +98,7 @@ protected: sensor_real_t vecGravity[3]{0.0f, 0.0f, 0.0f}; bool linaccelReady = false; sensor_real_t linAccel[3]{0.0f, 0.0f, 0.0f}; -#if ESP32 +#ifdef ESP32 sensor_real_t linAccel_guard; // Temporary patch for some weird ESP32 bug #endif }; diff --git a/src/sensors/SensorFusionDMP.h b/src/sensors/SensorFusionDMP.h index cb17d03..5f32df1 100644 --- a/src/sensors/SensorFusionDMP.h +++ b/src/sensors/SensorFusionDMP.h @@ -38,7 +38,7 @@ protected: sensor_real_t vecGravity[3]{0.0f, 0.0f, 0.0f}; bool linaccelReady = false; sensor_real_t linAccel[3]{0.0f, 0.0f, 0.0f}; -#if ESP32 +#ifdef ESP32 sensor_real_t linAccel_guard; // Temporary patch for some weird ESP32 bug #endif }; diff --git a/src/serial/serialcommands.cpp b/src/serial/serialcommands.cpp index 25caf6d..57dbdd6 100644 --- a/src/serial/serialcommands.cpp +++ b/src/serial/serialcommands.cpp @@ -31,7 +31,7 @@ #include "logging/Logger.h" #include "utils.h" -#if ESP32 +#ifdef ESP32 #include "nvs_flash.h" #endif @@ -172,7 +172,7 @@ void printState() { ); } -#if ESP32 +#ifdef ESP32 String getEncryptionTypeName(wifi_auth_mode_t type) { switch (type) { case WIFI_AUTH_OPEN: @@ -346,7 +346,7 @@ void cmdFactoryReset(CmdParser* parser) { WiFi.disconnect(true); // Clear WiFi credentials #if ESP8266 ESP.eraseConfig(); // Clear ESP config -#elif ESP32 +#elif defined(ESP32) nvs_flash_erase(); #else #warning SERIAL COMMAND FACTORY RESET NOT SUPPORTED