device.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "device.h"
  2. esp_err_t Device::hardware_init()
  3. {
  4. // HW Buses Init
  5. Serial.begin(SERIAL_BAUD);
  6. I2C0_BUS.setPins(I2C0_SDA, I2C0_SCL);
  7. SPI0_BUS.begin(SPI0_SCLK, SPI0_MISO, SPI0_MOSI);
  8. // IMU Init
  9. Imu.begin(SPI0_CS, SPI0_BUS);
  10. if (Imu.status != ICM_20948_Stat_Ok)
  11. {
  12. ESP_LOGE("IMU", "IMU failed to connect!");
  13. return ESP_ERR_NOT_FOUND;
  14. }
  15. // 1. Vytvorte si štruktúru pre delič frekvencie
  16. ICM_20948_smplrt_t mySmplrt;
  17. // 2. Vypočítajte a zadajte delič (Divider)
  18. // Vzorec: Sample Rate = 1125 / (1 + Divider)
  19. // Príklad pre ~100 Hz: 1125 / (1 + 10) = 102.2 Hz
  20. mySmplrt.a = 4; // Delič pre akcelerometer
  21. mySmplrt.g = 4; // Delič pre gyroskop
  22. // 3. (Aktivujte DLPF - bez toho delič nefunguje!)
  23. Imu.enableDLPF(ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr, true);
  24. // 4. Aplikujte nastavenie
  25. Imu.setSampleRate(ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr, mySmplrt);
  26. // ENV Init
  27. bool env_status = Env.begin(BME280_ADDR, &I2C0_BUS);
  28. if (env_status != 1)
  29. {
  30. ESP_LOGE("ENV", "ENV failed to connect!");
  31. return ESP_ERR_NOT_FOUND;
  32. }
  33. return ESP_OK;
  34. }
  35. Device Dev; // Global Instance