Skip to content

Commit f3b08b8

Browse files
authored
Merge pull request #1 from sparkfun/Avoid_Ambiguity
Avoid ambiguity
2 parents d92f72c + f84b4a6 commit f3b08b8

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

.github/workflows/compile-sketch.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
# - push
55
- pull_request
66

7-
87
jobs:
98
compile-sketch:
109
runs-on: ubuntu-latest
@@ -94,12 +93,16 @@ jobs:
9493
- name: Compile Sketch
9594
uses: arduino/compile-sketches@v1.1.0
9695
with:
96+
github-token: ${{ secrets.GITHUB_TOKEN }}
9797
platforms: ${{ matrix.board.platforms }}
9898
fqbn: ${{ matrix.board.fqbn }}
9999
libraries: |
100100
- source-path: ./
101+
# Add library dependencies here:
102+
- source-url: https://github.com/sparkfun/SparkFun_Toolkit.git
103+
# - name: name-of-library-registered-with-arduino-library-manager
101104
sketch-paths: |
102-
- examples/Example01_Basic_SingleShot
105+
- examples/Example05_AlternateAddress
103106
enable-warnings-report: true
104107
enable-deltas-report: true
105108
verbose: true

src/SparkFun_ADS1219.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,17 @@ bool SfeADS1219Driver::readConversion()
126126
if (result)
127127
{
128128
// Data is 3-bytes (24-bits), big-endian (MSB first).
129-
_adcResult = rawBytes[0];
130-
_adcResult = (_adcResult << 8) | rawBytes[1];
131-
_adcResult = (_adcResult << 8) | rawBytes[2];
129+
union {
130+
int32_t i32;
131+
uint32_t u32;
132+
} iu32; // Use a union to avoid signed / unsigned ambiguity
133+
iu32.u32 = rawBytes[0];
134+
iu32.u32 = (iu32.u32 << 8) | rawBytes[1];
135+
iu32.u32 = (iu32.u32 << 8) | rawBytes[2];
132136
// Preserve the 2's complement.
133-
if (_adcResult & (1 << 23))
134-
_adcResult |= 0xFF000000;
137+
if (0x00100000 == (iu32.u32 & 0x00100000))
138+
iu32.u32 = iu32.u32 | 0xFF000000;
139+
_adcResult = iu32.i32; // Store the signed result
135140
}
136141
return result;
137142
}

src/SparkFun_ADS1219.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class SfeADS1219Driver
230230

231231
ads1219_gain_config_t _adcGain; // Local configuration value. ADC gain - needed for conversion to mV.
232232

233-
int32_t _adcResult; // Local store for the ADC conversion result. 24-Bit, shifted left for correct 2's complement
233+
int32_t _adcResult; // Local store for the ADC conversion result. 24-Bit, 2's complement
234234
};
235235

236236
class SfeADS1219ArdI2C : public SfeADS1219Driver

0 commit comments

Comments
 (0)