Add distance sensor, rewrite OLED to use new i2c library

This commit is contained in:
2026-02-19 14:48:31 -05:00
parent 29b79fbbb5
commit 20b047bbfe
31 changed files with 3040 additions and 122 deletions

View File

@@ -8,6 +8,7 @@
#include "SensorMessageBuilder.h"
#include "TopologyMessageBuilder.h"
#include "esp_wifi.h"
#include "freertos/projdefs.h"
#define ACTUATOR_CMD_TAG 5
#define TOPOLOGY_CMD_TAG 6
@@ -16,16 +17,22 @@
#define METADATA_PERIOD_MS 1000
#define SENSOR_DATA_PERIOD_MS 1000
#define SLEEP_WITH_NO_ACTUATOR_MS 2000
[[noreturn]] void LoopManager::control_loop() const {
uint8_t buffer[512];
while (true) {
if (m_actuator == nullptr) {
vTaskDelay(pdMS_TO_TICKS(SLEEP_WITH_NO_ACTUATOR_MS));
continue;
}
if (m_messaging_interface->recv(buffer, 512,
ACTUATOR_CMD_TAG)) {
m_actuator->actuate(buffer);
send_sensor_reading(false);
}
}
}
}
[[noreturn]] void LoopManager::sensor_loop(char *args) {
@@ -72,10 +79,20 @@
void LoopManager::send_sensor_reading(bool durable) const {
Flatbuffers::SensorMessageBuilder smb{};
// todo: get data from sensor
std::vector<Flatbuffers::sensor_value> sensor_values;
if (m_actuator) {
auto data = m_actuator->get_sensor_data();
const auto [ptr, size] = smb.build_sensor_message(data);
sensor_values.insert(sensor_values.end(), data.begin(), data.end());
}
if (m_sensor) {
auto data = m_sensor->get_sensor_data();
sensor_values.insert(sensor_values.end(), data.begin(), data.end());
}
if (sensor_values.size() > 0) {
const auto [ptr, size] = smb.build_sensor_message(sensor_values);
m_messaging_interface->send((uint8_t *)ptr, size, PC_ADDR, SENSOR_TAG, durable);
}
}