🔥 Cleans up peripherals service

This commit is contained in:
Rune Harlyk
2025-07-16 20:32:19 +02:00
parent 922a4e3665
commit 6e10eabd9f
+7 -15
View File
@@ -28,13 +28,6 @@
#define MAX_ESP_IMU_SIZE 500 #define MAX_ESP_IMU_SIZE 500
#define EVENT_IMU "imu" #define EVENT_IMU "imu"
/*
* OLED Settings
*/
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define SCREEN_RESET -1
/* /*
* Ultrasonic Sensor Settings * Ultrasonic Sensor Settings
*/ */
@@ -77,8 +70,8 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
if (!_bmp.initialize()) ESP_LOGE("IMUService", "BMP initialize failed"); if (!_bmp.initialize()) ESP_LOGE("IMUService", "BMP initialize failed");
#endif #endif
#if FT_ENABLED(USE_USS) #if FT_ENABLED(USE_USS)
_left_sonar = new NewPing(USS_LEFT_PIN, USS_LEFT_PIN, MAX_DISTANCE); _left_sonar = std::make_unique<NewPing>(USS_LEFT_PIN, USS_LEFT_PIN, MAX_DISTANCE);
_right_sonar = new NewPing(USS_RIGHT_PIN, USS_RIGHT_PIN, MAX_DISTANCE); _right_sonar = std::make_unique<NewPing>(USS_RIGHT_PIN, USS_RIGHT_PIN, MAX_DISTANCE);
#endif #endif
}; };
@@ -128,10 +121,7 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
} }
} }
uint8_t nDevices = addressList.size(); uint8_t nDevices = addressList.size();
if (nDevices == 0) ESP_LOGI("Peripherals", "Scan complete - Found %d device(s)", nDevices);
ESP_LOGI("Peripherals", "No I2C devices found");
else
ESP_LOGI("Peripherals", "Scan complete - Found %d devices", nDevices);
} }
/* IMU FUNCTIONS */ /* IMU FUNCTIONS */
@@ -190,8 +180,10 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
#if FT_ENABLED(USE_BMP180) #if FT_ENABLED(USE_BMP180)
_bmp.readBarometer(root); _bmp.readBarometer(root);
#endif #endif
#if FT_ENABLED(USE_MPU6050 || USE_BNO055) || FT_ENABLED(USE_HMC5883)
JsonVariant data = doc.as<JsonVariant>(); JsonVariant data = doc.as<JsonVariant>();
socket.emit(EVENT_IMU, data); socket.emit(EVENT_IMU, data);
#endif
} }
void emitSonar() { void emitSonar() {
@@ -225,8 +217,8 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
Barometer _bmp; Barometer _bmp;
#endif #endif
#if FT_ENABLED(USE_USS) #if FT_ENABLED(USE_USS)
NewPing *_left_sonar; std::unique_ptr<NewPing> _left_sonar;
NewPing *_right_sonar; std::unique_ptr<NewPing> _right_sonar;
#endif #endif
float _left_distance {MAX_DISTANCE}; float _left_distance {MAX_DISTANCE};
float _right_distance {MAX_DISTANCE}; float _right_distance {MAX_DISTANCE};