Skip to content

Commit

Permalink
format lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthecoder committed Jul 1, 2024
1 parent f05b409 commit 730db71
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion include/can/core/ids.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ enum class SensorOutputBinding {
sync = 0x1,
report = 0x2,
max_threshold_sync = 0x4,
auto_baseline_report = 0x8,
auto_baseline_report = 0x08,
multi_sensor_sync = 0x10,
};

Expand Down
2 changes: 2 additions & 0 deletions include/motor-control/core/motor_messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct SensorSyncMove { // NOLINT(cppcoreguidelines-pro-type-member-init)
uint16_t usage_key;
can::ids::SensorId sensor_id;
can::ids::SensorType sensor_type;
uint8_t binding_flags;

auto build_ack(uint32_t position, int32_t pulses, uint8_t flags,
AckMessageId _id) -> Ack {
Expand Down Expand Up @@ -121,6 +122,7 @@ struct GearMotorMove // NOLINT(cppcoreguidelines-pro-type-member-init)
can::ids::GearMotorId gear_motor_id;
can::ids::SensorId sensor_id;
can::ids::SensorType sensor_type;
uint8_t binding_flags;
auto build_ack(uint32_t position, int32_t pulses, uint8_t flags,
AckMessageId _id) -> GearMotorAck {
return GearMotorAck{message_index, group_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,20 +408,17 @@ class MotorInterruptHandler {
hardware.get_encoder_pulses();
#ifdef USE_SENSOR_MOVE
if (buffered_move.sensor_id != can::ids::SensorId::UNUSED) {
auto binding =
static_cast<uint8_t>(can::ids::SensorOutputBinding::sync) |
static_cast<uint8_t>(
can::ids::SensorOutputBinding::report) |
static_cast<uint8_t>(
can::ids::SensorOutputBinding::auto_baseline_report);
if (buffered_move.sensor_id == can::ids::SensorId::BOTH) {
send_bind_message(buffered_move.sensor_type,
can::ids::SensorId::S0, binding);
can::ids::SensorId::S0,
buffered_move.binding_flags);
send_bind_message(buffered_move.sensor_type,
can::ids::SensorId::S1, binding);
can::ids::SensorId::S1,
buffered_move.binding_flags);
} else {
send_bind_message(buffered_move.sensor_type,
buffered_move.sensor_id, binding);
buffered_move.sensor_id,
buffered_move.binding_flags);
}
}
#endif
Expand Down
12 changes: 5 additions & 7 deletions include/sensors/core/sensor_hardware_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,32 @@ class SensorHardwareBase {
virtual auto check_tip_presence() -> bool = 0;

auto mask_satisfied() -> bool {
if (set_sync_required_mask != static_cast<uint8_t>(SensorIdBitMask::UNUSED)) {
if (set_sync_required_mask !=
static_cast<uint8_t>(SensorIdBitMask::UNUSED)) {
// if anything is "required" only sync when they are all triggered
return (sync_state_mask & set_sync_required_mask) == set_sync_required_mask;
return (sync_state_mask & set_sync_required_mask) ==
set_sync_required_mask;
}
return sync_state_mask & set_sync_enabled_mask;
}

auto set_sync(can::ids::SensorId sensor) -> void {
printf("Set sync sensor called\n");
// force the bit for this sensor to 1
sync_state_mask |= get_mask_from_id(sensor);
if (mask_satisfied()) {
printf("satisfied calling sync\n");
set_sync();
}
}

auto reset_sync(can::ids::SensorId sensor) -> void {
// force the bit for this sensor to 0
printf("reset sync sensor called\n");
sync_state_mask &= 0xFF ^ get_mask_from_id(sensor);
if (!mask_satisfied()) {
printf("No longer satisfied calling reset\n");
reset_sync();
}
}

auto set_sync_enabled(can::ids::SensorId sensor, bool enabled) -> void {
printf("Set sync required called %d\n", enabled);
uint8_t applied_mask = get_mask_from_id(sensor);
if (!enabled) {
// force enabled bit to 0
Expand Down Expand Up @@ -117,6 +114,7 @@ class SensorHardwareBase {
reset_sync();
}
}

private:
uint8_t set_sync_required_mask = 0x00;
uint8_t set_sync_enabled_mask = 0x00;
Expand Down
4 changes: 2 additions & 2 deletions include/sensors/core/tasks/pressure_sensor_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class PressureMessageHandler {
m.binding &
static_cast<uint8_t>(can::ids::SensorOutputBinding::report));
driver.set_multi_sensor_sync(
m.binding &
static_cast<uint8_t>(can::ids::SensorOutputBinding::multi_sensor_sync));
m.binding & static_cast<uint8_t>(
can::ids::SensorOutputBinding::multi_sensor_sync));
driver.set_bind_sync(
m.binding &
static_cast<uint8_t>(can::ids::SensorOutputBinding::sync));
Expand Down
1 change: 0 additions & 1 deletion include/sensors/firmware/sensor_hardware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace sensors {
namespace hardware {


class SensorHardware : public SensorHardwareBase {
public:
SensorHardware(sensors::hardware::SensorHardwareConfiguration hardware)
Expand Down
7 changes: 5 additions & 2 deletions include/sensors/tests/mock_hardware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ class MockSensorHardware : public sensors::hardware::SensorHardwareBase {
sensors::hardware::SensorHardwareBase::reset_sync(sensor);
}
auto set_sync_enabled(can::ids::SensorId sensor, bool enabled) -> void {
sensors::hardware::SensorHardwareBase::set_sync_enabled(sensor, enabled);
sensors::hardware::SensorHardwareBase::set_sync_enabled(sensor,
enabled);
}
auto set_sync_required(can::ids::SensorId sensor, bool required) -> void {
sensors::hardware::SensorHardwareBase::set_sync_required(sensor, required);
sensors::hardware::SensorHardwareBase::set_sync_required(sensor,
required);
}

private:
bool sync_state = false;
uint32_t sync_set_calls = 0;
Expand Down
5 changes: 2 additions & 3 deletions sensors/tests/test_sensor_hardware.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <concepts>

#include "catch2/catch.hpp"
#include "can/core/messages.hpp"
#include "sensors/tests/mock_hardware.hpp"
#include "catch2/catch.hpp"
#include "sensors/core/sensor_hardware_interface.hpp"
#include "sensors/tests/mock_hardware.hpp"

constexpr auto sensor_id_primary = can::ids::SensorId::S0;
constexpr auto sensor_id_secondary = can::ids::SensorId::S1;
Expand Down Expand Up @@ -79,7 +79,6 @@ SCENARIO("Multiple Sensors connected") {
mock_hw.set_sync_enabled(sensor_id_secondary, false);
REQUIRE(mock_hw.get_sync_state_mock() == false);
}

}
GIVEN("Two sensors required") {
mock_hw.set_sync_required(sensor_id_primary, true);
Expand Down

0 comments on commit 730db71

Please sign in to comment.