Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensor interface PR proof of concept #335

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

soypat
Copy link
Contributor

@soypat soypat commented Oct 26, 2021

Proof of concept for #321. WIP


func (d *Device) Update(which drivers.Measurement) (err error) {
// Temperature is needed for presssure calculation.
if which|drivers.Temperature|drivers.Pressure == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall it not return some sort of error when measurement requested is not temperature or pressure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason behind it not being an error is to allow for grouping of Sensors.

allSensors := []Sensor{imu, bmp, tempSens}
updateAll := func (w Measurement) {
   for _, sens := range allSensors {
     sens.Update(w) // illustrative, please handle your errors
   }
}

This way you can have precise requests of what sensor measurements you want to update. This is especially useful if the characteristic time of a sensor is very slow compared to other sensors in the group, i.e Temperature sensor vs. voltage sensor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be worth thinking about this a bit more. Maybe it's worth having a io.EOF sentinel like error for the case you mention Yurii, for example: drivers.ErrNoMeasurement.

}

// Channel returns an ADC measurement for a specific channel. Must call Update Beforehand
func (d *BufferedDev) Channel(ch int) uint16 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this name? Shall be "Voltage"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So maybe this name should be Get, the reason it is not Voltage is because it does not represent the voltage, merely the bits read by the ADC. I have added the Voltage method separate as a conversion of Channel.


// UNTESTED
func (d *BufferedDev) Update(which drivers.Measurement) error {
if which|drivers.Voltage == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now it only reads voltage, can read more things?
If only voltage ever, why have which drivers.Measurement at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comment above

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.

3 participants