diff --git a/.github/workflows/compile-sketch.yml b/.github/workflows/compile-sketch.yml index e093abb..73051f0 100644 --- a/.github/workflows/compile-sketch.yml +++ b/.github/workflows/compile-sketch.yml @@ -4,7 +4,6 @@ on: # - push - pull_request - jobs: compile-sketch: runs-on: ubuntu-latest @@ -94,12 +93,16 @@ jobs: - name: Compile Sketch uses: arduino/compile-sketches@v1.1.0 with: + github-token: ${{ secrets.GITHUB_TOKEN }} platforms: ${{ matrix.board.platforms }} fqbn: ${{ matrix.board.fqbn }} libraries: | - source-path: ./ + # Add library dependencies here: + - source-url: https://github.com/sparkfun/SparkFun_Toolkit.git + # - name: name-of-library-registered-with-arduino-library-manager sketch-paths: | - - examples/Example01_Basic_SingleShot + - examples/Example05_AlternateAddress enable-warnings-report: true enable-deltas-report: true verbose: true diff --git a/src/SparkFun_ADS1219.cpp b/src/SparkFun_ADS1219.cpp index 62a19d0..f0566e7 100644 --- a/src/SparkFun_ADS1219.cpp +++ b/src/SparkFun_ADS1219.cpp @@ -126,12 +126,17 @@ bool SfeADS1219Driver::readConversion() if (result) { // Data is 3-bytes (24-bits), big-endian (MSB first). - _adcResult = rawBytes[0]; - _adcResult = (_adcResult << 8) | rawBytes[1]; - _adcResult = (_adcResult << 8) | rawBytes[2]; + union { + int32_t i32; + uint32_t u32; + } iu32; // Use a union to avoid signed / unsigned ambiguity + iu32.u32 = rawBytes[0]; + iu32.u32 = (iu32.u32 << 8) | rawBytes[1]; + iu32.u32 = (iu32.u32 << 8) | rawBytes[2]; // Preserve the 2's complement. - if (_adcResult & (1 << 23)) - _adcResult |= 0xFF000000; + if (0x00100000 == (iu32.u32 & 0x00100000)) + iu32.u32 = iu32.u32 | 0xFF000000; + _adcResult = iu32.i32; // Store the signed result } return result; } diff --git a/src/SparkFun_ADS1219.h b/src/SparkFun_ADS1219.h index 7564be9..07f9a5f 100644 --- a/src/SparkFun_ADS1219.h +++ b/src/SparkFun_ADS1219.h @@ -230,7 +230,7 @@ class SfeADS1219Driver ads1219_gain_config_t _adcGain; // Local configuration value. ADC gain - needed for conversion to mV. - int32_t _adcResult; // Local store for the ADC conversion result. 24-Bit, shifted left for correct 2's complement + int32_t _adcResult; // Local store for the ADC conversion result. 24-Bit, 2's complement }; class SfeADS1219ArdI2C : public SfeADS1219Driver