104 lines
2.3 KiB
C++
104 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <event_bus/event_bus.h>
|
|
#include <utils/math_utils.h>
|
|
#include <utils/timing.h>
|
|
#include <filesystem.h>
|
|
#include <features.h>
|
|
#include <settings/peripherals_settings.h>
|
|
#include <platform_shared/message.pb.h>
|
|
#include <esp_http_server.h>
|
|
|
|
#include <list>
|
|
|
|
#if FT_ENABLED(USE_USS)
|
|
#include <NewPing.h>
|
|
#endif
|
|
#include <peripherals/i2c_bus.h>
|
|
#include <peripherals/imu.h>
|
|
#include <peripherals/magnetometer.h>
|
|
#include <peripherals/barometer.h>
|
|
#include <peripherals/gesture.h>
|
|
|
|
/*
|
|
* Ultrasonic Sensor Settings
|
|
*/
|
|
#define MAX_DISTANCE 200
|
|
|
|
class Peripherals {
|
|
public:
|
|
Peripherals();
|
|
|
|
void begin();
|
|
|
|
void update();
|
|
|
|
void updatePins();
|
|
|
|
void scanI2C(uint8_t lower = 1, uint8_t higher = 127);
|
|
|
|
void getI2CScanProto(socket_message_I2CScanData &data);
|
|
void getIMUProto(socket_message_IMUData &data);
|
|
void getSettingsProto(socket_message_PeripheralSettingsData &data);
|
|
|
|
bool readImu();
|
|
|
|
bool readMag();
|
|
|
|
bool readBMP();
|
|
|
|
bool readGesture();
|
|
|
|
void readSonar();
|
|
|
|
float angleX();
|
|
|
|
float angleY();
|
|
|
|
float angleZ();
|
|
|
|
gesture_t takeGesture();
|
|
|
|
float leftDistance();
|
|
float rightDistance();
|
|
|
|
bool calibrateIMU();
|
|
|
|
esp_err_t getSettings(httpd_req_t *request);
|
|
esp_err_t updateSettings(httpd_req_t *request, api_Request *protoReq);
|
|
|
|
private:
|
|
static constexpr const char *TAG = "Peripherals";
|
|
|
|
void onSettingsChanged(const api_PeripheralSettings &newSettings);
|
|
|
|
PeripheralsConfiguration _settings = PeripheralsConfiguration_defaults();
|
|
EventBus::Handle<api_PeripheralSettings> _settingsHandle;
|
|
|
|
SemaphoreHandle_t _accessMutex;
|
|
inline void beginTransaction() { xSemaphoreTakeRecursive(_accessMutex, portMAX_DELAY); }
|
|
|
|
inline void endTransaction() { xSemaphoreGiveRecursive(_accessMutex); }
|
|
|
|
#if FT_ENABLED(USE_MPU6050 || USE_BNO055)
|
|
IMU _imu;
|
|
#endif
|
|
#if FT_ENABLED(USE_HMC5883)
|
|
Magnetometer _mag;
|
|
#endif
|
|
#if FT_ENABLED(USE_BMP180)
|
|
Barometer _bmp;
|
|
#endif
|
|
#if FT_ENABLED(USE_PAJ7620U2)
|
|
GestureSensor _gesture;
|
|
#endif
|
|
#if FT_ENABLED(USE_USS)
|
|
std::unique_ptr<NewPing> _left_sonar;
|
|
std::unique_ptr<NewPing> _right_sonar;
|
|
#endif
|
|
float _left_distance {MAX_DISTANCE};
|
|
float _right_distance {MAX_DISTANCE};
|
|
|
|
std::list<uint8_t> addressList;
|
|
bool i2c_active = false;
|
|
}; |