Skip to content

refactor/sensor-pointers#18

Open
jacek-kow wants to merge 2 commits into
mainfrom
refactor/sensor-pointers
Open

refactor/sensor-pointers#18
jacek-kow wants to merge 2 commits into
mainfrom
refactor/sensor-pointers

Conversation

@jacek-kow
Copy link
Copy Markdown
Contributor

@jacek-kow jacek-kow commented Apr 20, 2026

  1. Sensor objects are now created as unique_ptrs that are passed into the Application constructor right from the start - instead of first creating static objects and then moving them inside the unique_ptrs. Code in main is thus simpler and easier to understand.
  2. Zephyr device struct pointers obtained from DEVICE_DT_GET_ANY are now no longer parameters of the sensors' constructor. Instead, DEVICE_DT_GET_ANY is called inside the sensor class' constructor. This, again, makes main's code less cluttered.
    Note that this wasn't refactored in the Analog sensor, as the Analog sensor requires different specifications structs (obtained from ADC_DT_SPEC_GET) for different ADC sensors - that's why the soil sensor's specification wasn't hard-coded in the Analog constructor.
  3. Internal device pointers in each Sensor class were kept as raw pointers, because DEVICE_DT_GET_ANY returns a device address from the device tree - no memory allocation is performed, so these pointers don't need to be deleted. Device pointers are not deleted in Zephyr samples, e. g. the BME280 sample.

…_DT_GET_ANY) inside the sensor class to avoid passing this pointer through the sensor class constructor
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.

1 participant