Skip to content

Commit

Permalink
fix sensor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj committed Jun 13, 2024
1 parent 22acb24 commit b1e745c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 2 additions & 3 deletions include/common/core/sensor_buffer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#ifndef SENSOR_BUFF_SIZE
#define SENSOR_BUFFER_SIZE 0
#else
#define SENSOR_BUFFER_SIZE 1
#endif
constexpr size_t SENSOR_BUFFER_SIZE = SENSOR_BUFF_SIZE;
#endif
17 changes: 15 additions & 2 deletions include/sensors/core/tasks/pressure_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

#include <cmath>

// Not my favorite way to check this, but if we don't have access
// to vTaskDelay during host compilation so just dummy the function
template <typename T>
requires std::is_integral_v<T>
static void _hardware_delay(T ticks) {
#ifndef INC_TASK_H
std::ignore = ticks;
#else
vTaskDelay(ticks);
#endif
}

#include "can/core/can_writer_task.hpp"
#include "can/core/ids.hpp"
#include "can/core/messages.hpp"
Expand Down Expand Up @@ -292,7 +304,8 @@ class MMR920 {
for (int i = 0; i < static_cast<int>(SENSOR_BUFFER_SIZE); i++) {
// send over buffer and then clear buffer values
// NOLINTNEXTLINE(div-by-zero)
int current_index = (i + sensor_buffer_index) % static_cast<int>(SENSOR_BUFFER_SIZE);
int current_index = (i + sensor_buffer_index) %
static_cast<int>(SENSOR_BUFFER_SIZE);

can_client.send_can_message(
can::ids::NodeId::host,
Expand All @@ -304,7 +317,7 @@ class MMR920 {
(*sensor_buffer).at(current_index))});
if (i % 10 == 0) {
// slow it down so the can buffer doesn't choke
vTaskDelay(50);
_hardware_delay(50);
}
(*sensor_buffer).at(current_index) = 0;
}
Expand Down

0 comments on commit b1e745c

Please sign in to comment.