Skip to content

Commit

Permalink
create circular buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj committed Jun 12, 2024
1 parent 7e89b0f commit fb23053
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions include/sensors/core/tasks/pressure_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ class MMR920 {
return true;
}

auto sensor_buffer_log(float data) -> void {
if (sensor_buffer_index == SENSOR_BUFFER_SIZE) {
sensor_buffer_index = 0;
}

(*sensor_buffer).at(sensor_buffer_index) = response_pressure;
sensor_buffer_index++;
}

auto save_temperature(int32_t data) -> bool {
_registers.temperature_result.reading = data;
LOG("Updated temperature reading is %u",
Expand Down Expand Up @@ -281,21 +290,23 @@ class MMR920 {

void send_accumulated_sensor_data(uint32_t message_index) {
#ifdef USE_SENSOR_MOVE
for (int i = 0; i < sensor_buffer_index; i++) {
for (int i = 0; i < SENSOR_BUFFER_SIZE; i++) {
// send over buffer adn then clear buffer values
current_index = (i + sensor_buffer_index) % SENSOR_BUFFER_SIZE;

can_client.send_can_message(
can::ids::NodeId::host,
can::messages::ReadFromSensorResponse{
.message_index = message_index,
.sensor = can::ids::SensorType::pressure,
.sensor_id = sensor_id,
.sensor_data =
mmr920::reading_to_fixed_point((*sensor_buffer).at(i))});
mmr920::reading_to_fixed_point((*sensor_buffer).at(current_index))});
if (i % 10 == 0) {
// slow it down so the can buffer doesn't choke
vTaskDelay(50);
}
(*sensor_buffer).at(i) = 0;
(*sensor_buffer).at(current_index) = 0;
}
#else
std::ignore = message_index;
Expand Down Expand Up @@ -323,6 +334,7 @@ class MMR920 {
_registers.pressure_result.reading, sensor_version);

if (max_pressure_sync) {
sensor_buffer_log(pressure);
bool this_tick_over_threshold =
std::fabs(pressure - current_pressure_baseline_pa) >=
mmr920::get_max_pressure_reading(sensor_version);
Expand Down

0 comments on commit fb23053

Please sign in to comment.