diff options
author | Daniel Friesel <derf@finalrewind.org> | 2023-01-01 19:55:26 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2023-01-01 19:55:26 +0100 |
commit | 3828a9b13774c0efaa90e61fd129bbf80bd12a5c (patch) | |
tree | 438cdcd8c39382a470c2c869f8f31415fbc25425 /src | |
parent | 7f0db02066a7554b959fa264fcc200b2a2e4c929 (diff) |
ads111x: add readRaw function
Diffstat (limited to 'src')
-rw-r--r-- | src/driver/ads111x.cc | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/driver/ads111x.cc b/src/driver/ads111x.cc index 53be2a4..5d9ed41 100644 --- a/src/driver/ads111x.cc +++ b/src/driver/ads111x.cc @@ -12,8 +12,6 @@ #include "driver/soft_i2c.h" #endif -#include <stdint.h> - void ADS111x::configure(unsigned short config) { txbuf[0] = P_CONFIG; @@ -43,14 +41,18 @@ void ADS111x::configure(unsigned short config) } } -float ADS111x::readVoltage() +int16_t ADS111x::readRaw() { txbuf[0] = P_CONVERSION; i2c.xmit(address, 1, txbuf, 2, rxbuf); int16_t intermediate = ((int8_t)rxbuf[0]) * 256 + (uint8_t) rxbuf[1]; + return intermediate; +} - return intermediate * 0.256 / 0x7fff * fsr_scale; +float ADS111x::readVoltage() +{ + return readRaw() * 0.256 / 0x7fff * fsr_scale; } ADS111x ads111x(0x48); |