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

Add ADC Voltmeter and Ammeter traits. #569

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

reitermarkus
Copy link
Member

This adds an AdcChannel trait as mentioned in #377.

Still needs to be tested by implementing an actual driver. I feel there is something still missing with regard to how the return value can actually be used further. Is it even practical to have this trait without having a corresponding unit and a lower/upper bound for converting the raw value?

@onkoe
Copy link

onkoe commented Jan 17, 2024

That's a good point! Also, it may be challenging to take something implementing AdcChannel in a library if there's no way to tell what the voltage 'could' be.

However, how do you ask every implementation to know the voltage range of an arbitrary device? Would having an Option<Voltage> suffice? (i.e., we 'ask' the implementation to tell us if it knows)

My apologies if I've missed your point, though! 😄

@reitermarkus
Copy link
Member Author

I have changed the API here now to measure voltage instead of the raw value.

the voltage range of an arbitrary device

I think you may have indeed missed my point. 😄 I am talking about the voltage range of the ADC itself. So it's not an arbitrary device's voltage, but the voltage the ADC is actually measuring. For example, with a 16-bit ADC with a range of ±5V, this means i16::MIN corresponds to -5V and i16::MAX to +5V.

Then you can swap out ADCs, as long as they support the range you need. And the rest of the code only depends on the measured voltage. As a simple example, I have a water depth sensor with a range of 0-5V corresponding to 0-5m, which would be a 1:1 mapping from mV to mm. So as long as I have any ADC that can measure between 0 and 5V, I can implement e.g. a WaterDepthSensor using the trait.

@onkoe
Copy link

onkoe commented Jan 18, 2024

Got it - I thought I was missing something! Thanks for the clarification ☺️

@reitermarkus reitermarkus force-pushed the adc branch 7 times, most recently from 29d5d76 to 0bd50b5 Compare January 18, 2024 18:42
@reitermarkus reitermarkus force-pushed the adc branch 2 times, most recently from 34382a5 to cb86eb0 Compare January 19, 2024 12:49
@reitermarkus reitermarkus changed the title WIP: Add AdcChannel trait. ~~Add AdcChannel trait.~~ Add ADC Voltmeter and Ammeter traits. Jan 20, 2024
@reitermarkus reitermarkus changed the title ~~Add AdcChannel trait.~~ Add ADC Voltmeter and Ammeter traits. Add ADC Voltmeter and Ammeter traits. Jan 20, 2024
@reitermarkus
Copy link
Member Author

reitermarkus commented Jan 20, 2024

Given ADCs measure either voltage or current, I have now split the AdcChannel trait into Voltmeter and Ammeter traits.

@reitermarkus reitermarkus marked this pull request as ready for review January 20, 2024 12:56
@reitermarkus reitermarkus requested a review from a team as a code owner January 20, 2024 12:56
@kurtjd
Copy link

kurtjd commented Jul 10, 2024

I would be interested in seeing this gain more traction. My particular use case is for developing generic drivers for analog temperature sensors. Would be nice for the drivers to not have to depend on any particular ADC implementation.

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