sfuphantom / DAQ

0 stars 0 forks source link

Iadc sensor #28

Closed Andromas14 closed 1 year ago

Andromas14 commented 1 year ago

Purpose

Implementation of the Adafruit Ads library, allowing for the class to interface with the ADC and receive data from it.

Implementation

Functions the same as the theoretical implementation, Read() returns the binary data from the ADC, and Process() uses that value and converts it into Voltage. An Initialize() function was also added, that begins the ads on setup()

The adafruitADS11X5 library also allows for gain mode initialization and voltage conversion functions, thus the ones implemented previously became obsolete and were removed.

Read() and Process() also can not be const anymore, as the mADS library object will be modified with calls to the library functions.

Testing

Tested with an ESP32 as well as the ADS1115 - will require further testing with sensors, once they are available.

View on github

References

https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#referencing-issues-and-pull-requests

PR Review Rules

  1. Reviewer is responsible for resolving any threads they started
  2. One commit per thread and if it's a widespread change, link the commit in the reply pls :)
  3. ...
rafguevara14 commented 1 year ago

I think you should create a test child class in this PR that inherits from IADC just so you can see how a child class would actually be implemented. I think it'll clear up some confusions with the design

Andromas14 commented 1 year ago

I pushed an implementation using the enum class, let me know if I need to make any changes.

For the child implementation, can I create another virtual function inside the Process()? I don't really see why Read() would get overridden in the current use, as it just returns 16 bits of data from the stored adc member, which should stay consistent across all child classes.

My understanding is that the overwrite should happen in the middle of the Process() function, so I should either make Process() virtual, or a new function "ProcessedDataCalculation()" or something along those lines, which goes after final_data is declared and modifies it. image

rafguevara14 commented 1 year ago

Yea, I think what you're saying makes more sense now. In terms of naming though, the function that the user ultimately calls (currently named Process()) should be called something like GetData() since the function both samples and processes the data. The virtual function (ProcessedDataCalculation()) can then just be called Process().

Just so we're on the same page, you're thinking smt like this?

// in main 
sensor.GetData() // returns the final computation
// in class

GetData(){
data = readADC()
return Process(data) // this one is virtual and implemented by the children 
}
Andromas14 commented 1 year ago

Yeah, exactly, I will push an implementation of this asap.