Skip to content

Conversation

@caila-marashaj
Copy link
Contributor

@caila-marashaj caila-marashaj commented Nov 6, 2025

Overview

With this code, once a FreeRTOSTask is connected to the sensor policies, you should be able to read from all sensors, as well as interact with the eoc and reset pins on the MPR pressure sensor.

Another note: the atmosphere pressure sensor (lps22df)'s pins aren't actually connected to the MCU as of this hardware revision. There's just a TODO noting that we should add that when it's connected.

Changelog

  • added read functionality to both pressure sensor policies
  • moved sensor hardware initialization from system_hardware to its own file
  • defined pin values in main.h and reference those, rather than the HAL_GPIO defs directly

@caila-marashaj caila-marashaj marked this pull request as ready for review November 6, 2025 20:56
Copy link
Contributor

@vegano1 vegano1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confused by those min and max reading numbers - those need 24 or so bits, so either the data type is wrong or the numbers are wrong

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.84%. Comparing base (d834200) to head (1dea21e).
⚠️ Report is 5 commits behind head on edge.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             edge     #543      +/-   ##
==========================================
+ Coverage   77.52%   77.84%   +0.31%     
==========================================
  Files          83       86       +3     
  Lines        7743     7773      +30     
==========================================
+ Hits         6003     6051      +48     
+ Misses       1740     1722      -18     

see 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vegano1 vegano1 requested review from sfoster1 and vegano1 November 10, 2025 23:02
Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bunch of little things, but also it kind of seems like the end of conversion and reset pins are flipped?

constexpr uint8_t ONE_SHOT_PRESSURE_READ = 0x01;
// pressure in hectoPascals is the 3 byte output value divided by the
// sensitivity
constexpr uint16_t SENSOR_SENSITIVITY = 4096.0f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float constant but integral datatype

constexpr uint8_t PRESSURE_FRAME_LEN = 10;

// Frame retry defaults
constexpr uint8_t DEFAULT_RETRIES = 3;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this to be a uint8_t since it's used on line 51 for comparing with a regular int; the loop variable and this should be the same type, whatever that type happens to be

}
}
if (!pressure_reading_ready) {
// raise an error here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even if we're not raising an error yet we should probably not parse whatever's randomly in the data buffer (last read?) even in dev since it might make the control loop run away. really recommend making this function return std::optional<double> or something

// Add the header
WR_BUFF[0] = cmd;
// Copy data to the buffer starting from the header len.
for (uint8_t i = 1; i < len; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memcpy(&WR_BUFF[1], data, len)?

auto I2C::i2c_master_write(uint16_t dev_addr, uint8_t *data, uint16_t size)
-> RxTxReturn {
auto ret = hal_i2c_master_write(bus, dev_addr, data, size);
auto ret = hal_i2c_master_write(this->bus, dev_addr, data, size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤨

return len + 1;
}

static auto parse_pressure(const uint8_t* raw) -> double {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a const function right

return len + 1;
}

static auto parse_pressure(const uint8_t* raw) -> double {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a const function right

// Equation 2: Pressure Output Function
auto press_counts =
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
(double)((int32_t)raw[3] + (int32_t)raw[2] * (int32_t)256 +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is doing the same 24 bit bitshifting as the other one and it's way more readable if it's (int32_t)raw[3] + ((int32_t)raw[2]) << 8) + ((int32_t)raw[1]) << 16) or the same thing with | or whatever.

// Add the header
WR_BUFF[0] = cmd;
// Copy data to the buffer starting from the header len.
for (uint8_t i = 1; i < len; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memcpy(&WR_BUFF[1], data, len)?

constexpr uint8_t PRESSURE_FRAME_LEN = 10;

// Frame retry defaults
constexpr uint8_t DEFAULT_RETRIES = 3;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be the same data type as the loop var on line 60 (don't care which)

@caila-marashaj caila-marashaj force-pushed the vm-pressure-sensor-policies branch from 1c29a55 to f198002 Compare November 14, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants