diff --git a/ADS1X15.cpp b/ADS1X15.cpp index cd22834..20216c2 100644 --- a/ADS1X15.cpp +++ b/ADS1X15.cpp @@ -1,7 +1,7 @@ // // FILE: ADS1X15.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.3.11 +// VERSION: 0.3.12 // DATE: 2013-03-24 // PUPROSE: Arduino library for ADS1015 and ADS1115 // URL: https://github.com/RobTillaart/ADS1X15 @@ -136,6 +136,7 @@ void ADS1X15::reset() _compPol = 1; _compLatch = 0; _compQueConvert = 3; + _lastRequest = 0xFFFF; // no request yet } @@ -335,6 +336,24 @@ bool ADS1X15::isReady() } +uint8_t ADS1X15::lastRequest() +{ + switch (_lastRequest) + { + case ADS1X15_READ_0: return 0x00; + case ADS1X15_READ_1: return 0x01; + case ADS1X15_READ_2: return 0x02; + case ADS1X15_READ_3: return 0x03; + // technically 0x01 -- but would collide with READ_1 + case ADS1X15_MUX_DIFF_0_1: return 0x10; + case ADS1X15_MUX_DIFF_0_3: return 0x30; + case ADS1X15_MUX_DIFF_1_3: return 0x31; + case ADS1X15_MUX_DIFF_2_3: return 0x32; + } + return 0xFF; +} + + void ADS1X15::setComparatorMode(uint8_t mode) { _compMode = mode == 0 ? 0 : 1; @@ -462,7 +481,8 @@ int16_t ADS1X15::_readADC(uint16_t readmode) } else { - delay(_conversionDelay); // TODO needed in continuous mode? + // needed in continuous mode too, otherwise one get old value. + delay(_conversionDelay); } return getValue(); } @@ -484,6 +504,9 @@ void ADS1X15::_requestADC(uint16_t readmode) else config |= ADS1X15_COMP_NON_LATCH; // bit 2 ALERT latching config |= _compQueConvert; // bit 0..1 ALERT mode _writeRegister(_address, ADS1X15_REG_CONFIG, config); + + // remember last request type. + _lastRequest = readmode; } diff --git a/ADS1X15.h b/ADS1X15.h index eb7ff03..e4b6f5e 100644 --- a/ADS1X15.h +++ b/ADS1X15.h @@ -1,8 +1,8 @@ #pragma once // -// FILE: ADS1X15.H +// FILE: ADS1X15.h // AUTHOR: Rob Tillaart -// VERSION: 0.3.11 +// VERSION: 0.3.12 // DATE: 2013-03-24 // PUPROSE: Arduino library for ADS1015 and ADS1115 // URL: https://github.com/RobTillaart/ADS1X15 @@ -12,7 +12,7 @@ #include "Arduino.h" #include "Wire.h" -#define ADS1X15_LIB_VERSION (F("0.3.11")) +#define ADS1X15_LIB_VERSION (F("0.3.12")) // allow compile time default address // address in { 0x48, 0x49, 0x4A, 0x4B }, no test... @@ -78,6 +78,7 @@ class ADS1X15 int16_t readADC_Differential_0_1(); // used by continuous mode and async mode. + [[deprecated("Use getValue() instead")]] int16_t getLastValue() { return getValue(); }; // will be obsolete in the future 0.4.0 int16_t getValue(); @@ -91,6 +92,12 @@ class ADS1X15 bool isReady(); + // returns a pin 0x0[0..3] or + // a differential "mode" 0x[pin second][pin first] or + // 0xFF (no request / invalid request) + uint8_t lastRequest(); + + // COMPARATOR // 0 = TRADITIONAL > high => on < low => off // else = WINDOW > high or < low => on between => off @@ -162,6 +169,11 @@ class ADS1X15 uint8_t _compLatch; uint8_t _compQueConvert; + // variable to track the last pin requested, + // to allow for round robin query of + // pins based on this state == if no last request then == 0xFFFF. + uint16_t _lastRequest; + int16_t _readADC(uint16_t readmode); void _requestADC(uint16_t readmode); bool _writeRegister(uint8_t address, uint8_t reg, uint16_t value); diff --git a/CHANGELOG.md b/CHANGELOG.md index be446dc..2961a09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.3.12] - 2023-09-11 - update and add examples +- add **getLastRequest()** to track last type of measurement. +- update readme.md +- minor edits. ## [0.3.11] - 2023-08-31 @@ -14,7 +18,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - reordered code in .cpp to follow .h - minor edits - ## [0.3.10] - 2023-06-07 - fix NANO RP2040 - update and add examples diff --git a/README.md b/README.md index fb78d29..7a3f1a5 100644 --- a/README.md +++ b/README.md @@ -266,6 +266,38 @@ After one of these calls you need to call See [examples](https://github.com/RobTillaart/ADS1X15/blob/master/examples/ADS_differential/ADS_differential.ino). +#### lastRequestMode + +Since 0.3.12 the library tracks the last request mode, single pin or differential. +This variable is set at the moment of request, and keeps its value until a new +request is made. This implies that the value / request can be quite old. + +Values >= 0x10 are differential, values < 0x10 are single pin. + +- **uint8_t lastRequest()** returns one of the values below. + +| Value | Description | Notes | +|:-------:|:-----------------------------|:--------| +| 0xFF | no (invalid) request made | after call constructor. +| 0x00 | single pin 0 | +| 0x01 | single pin 1 | +| 0x02 | single pin 2 | +| 0x03 | single pin 3 | +| 0x10 | differential pin 1 0 | +| 0x30 | differential pin 3 0 | +| 0x31 | differential pin 3 1 | +| 0x32 | differential pin 3 2 | + + +Please note that (for now) the function does not support a descriptive return value +for the following two requests: +- **readADC_Differential_0_2()** ADS1x15 only - in software (no async equivalent) +- **readADC_Differential_1_2()** ADS1x15 only - in software (no async equivalent) + +As these are emulated in software by two single pin calls, the state would be +one of the two single pin values. + + #### ReadADC continuous mode To use the continuous mode you need call three functions: @@ -430,7 +462,7 @@ If, "Wire1" is used, you need to add "&Wire1" in the constructor. #### Could -- More examples ? +- More examples - SMB alert command (00011001) on I2C bus? - sync order .h / .cpp @@ -438,7 +470,7 @@ If, "Wire1" is used, you need to add "&Wire1" in the constructor. #### Wont (unless requested) - type flag? -- constructor for ADS1X15? +- constructor for ADS1X15? No as all types are supported. ## Support diff --git a/keywords.txt b/keywords.txt index 414a842..3613e70 100644 --- a/keywords.txt +++ b/keywords.txt @@ -33,6 +33,8 @@ readADC_Differential_1_3 KEYWORD2 readADC_Differential_2_3 KEYWORD2 getValue KEYWORD2 +getLastRequest KEYWORD2 + setComparatorMode KEYWORD2 getComparatorMode KEYWORD2 setComparatorPolarity KEYWORD2 diff --git a/library.json b/library.json index 346a1a5..5f3ffba 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/ADS1X15" }, - "version": "0.3.11", + "version": "0.3.12", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index 74e87df..5eacd7b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ADS1X15 -version=0.3.11 +version=0.3.12 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for ADS1015 - I2C 12 bit ADC and ADS1115 I2C 16 bit ADC