adafruit / adafruit/CircuitPython_NAU7802
Read function
- Dominant language
- Python
- Stars
- 14
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
There is a mistake in the read function. The following line is wrong:
self._adc_out = value / 128 # Restore to 24-bit signed integer value
It should be divided by 256 because it needs to be shifted with 8 bits not 7.
Also this method is not the ideal method to convert the raw data. It would be more efficient like this:
raw = (self._adc_out_2 << 16) | (self._adc_out_1 << 8) | self._adc_out_0
# Sign-extend 24-bit to Python int
if raw & 0x800000: # if sign bit set
raw -= 1 << 24
return raw
The original creater also told me that it is a mistake see screenshot
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the driver's read function and inspect how the raw 24-bit ADC bytes are converted into a signed Python integer. Compare the current shift with the issue's proposed conversion and verify that positive and sign-bit-set values return the expected signed results; done means the incorrect shift is corrected and the conversion behavior is covered by the project's available checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100