Skip to content

Commit 4b4a6e6

Browse files
authored
Merge pull request RobTillaart#169 from RobTillaart/develop
update libs
2 parents cc7e03d + 534c960 commit 4b4a6e6

File tree

148 files changed

+3024
-136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+3024
-136
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+

libraries/ADS1x15/ADS1X15.cpp

Lines changed: 66 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
//
22
// FILE: ADS1X15.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.2.7
4+
// VERSION: 0.3.0
55
// DATE: 2013-03-24
66
// PUPROSE: Arduino library for ADS1015 and ADS1115
77
// URL: https://github.com/RobTillaart/ADS1X15
88
//
9-
// HISTORY:
10-
// 0.0.0 2013-03-24 initial version
11-
// 0.0.1 2013-03-24 first working version
12-
// 0.1.0 2017-07-31 removed pre 1.0 support; added getVoltage
13-
// 0.2.0 2020-04-08 initial release; refactor ad fundum;
14-
// 0.2.1 2020-08-15 fix issue 2 gain; refactor
15-
// 0.2.2 2020-08-18 add begin(sda, scl) for ESP32
16-
// 0.2.3 2020-08-20 add comparator code + async mode
17-
// 0.2.4 2020-08-26 check readme.md and minor fixes
18-
// 0.2.5 2020-08-26 add missing readADC_Differential_X_X()
19-
// 0.2.6 2020-09-01 fix #12 - fix getMaxVoltage + minor refactor
20-
// 0.2.7 2020-09-27 redo readRegister() + getValue() + getError()
9+
// HISTORY:
10+
// 0.0.0 2013-03-24 initial version
11+
// 0.0.1 2013-03-24 first working version
12+
// 0.1.0 2017-07-31 removed pre 1.0 support; added getVoltage
13+
// 0.2.0 2020-04-08 initial release; refactor ad fundum;
14+
// 0.2.1 2020-08-15 fix issue 2 gain; refactor
15+
// 0.2.2 2020-08-18 add begin(sda, scl) for ESP32
16+
// 0.2.3 2020-08-20 add comparator code + async mode
17+
// 0.2.4 2020-08-26 check readme.md and minor fixes
18+
// 0.2.5 2020-08-26 add missing readADC_Differential_X_X()
19+
// 0.2.6 2020-09-01 fix #12 - fix getMaxVoltage + minor refactor
20+
// 0.2.7 2020-09-27 redo readRegister() + getValue() + getError()
21+
// 0.3.0 2021-03-29 add Wire parameter to constructors.
2122

2223

2324
#include "ADS1X15.h"
@@ -121,35 +122,6 @@ differs for different devices, check datasheet or readme.md
121122
#define ADS_CONF_COMP 0x20
122123

123124

124-
/////////////////////////////////////////////////////////////////////////
125-
//
126-
// STATIC MEMBERS
127-
//
128-
static bool writeRegister(uint8_t address, uint8_t reg, uint16_t value)
129-
{
130-
Wire.beginTransmission(address);
131-
Wire.write((uint8_t)reg);
132-
Wire.write((uint8_t)(value >> 8));
133-
Wire.write((uint8_t)(value & 0xFF));
134-
return (Wire.endTransmission() == 0);
135-
}
136-
137-
static uint16_t readRegister(uint8_t address, uint8_t reg)
138-
{
139-
Wire.beginTransmission(address);
140-
Wire.write(reg);
141-
Wire.endTransmission();
142-
143-
int rv = Wire.requestFrom(address, (uint8_t) 2);
144-
if (rv == 2)
145-
{
146-
uint16_t value = Wire.read() << 8;
147-
value += Wire.read();
148-
return value;
149-
}
150-
return 0x0000;
151-
}
152-
153125
//////////////////////////////////////////////////////
154126
//
155127
// BASE CONSTRUCTOR
@@ -168,30 +140,33 @@ ADS1X15::ADS1X15()
168140
#if defined (ESP8266) || defined(ESP32)
169141
bool ADS1X15::begin(uint8_t sda, uint8_t scl)
170142
{
171-
Wire.begin(sda, scl);
143+
_wire = &Wire;
144+
_wire->begin(sda, scl);
172145
if ((_address < 0x48) || (_address > 0x4B)) return false;
146+
if (! isConnected()) return false;
173147
return true;
174148
}
175149
#endif
176150

177151
bool ADS1X15::begin()
178152
{
179-
Wire.begin();
153+
_wire->begin();
180154
if ((_address < 0x48) || (_address > 0x4B)) return false;
155+
if (! isConnected()) return false;
181156
return true;
182157
}
183158

184159
bool ADS1X15::isBusy()
185160
{
186-
uint16_t val = readRegister(_address, ADS1X15_REG_CONFIG);
161+
uint16_t val = _readRegister(_address, ADS1X15_REG_CONFIG);
187162
if ((val & ADS1X15_OS_NOT_BUSY) != 0) return false;
188163
return true;
189164
}
190165

191166
bool ADS1X15::isConnected()
192167
{
193-
Wire.beginTransmission(_address);
194-
return (Wire.endTransmission() == 0);
168+
_wire->beginTransmission(_address);
169+
return (_wire->endTransmission() == 0);
195170
}
196171

197172
void ADS1X15::setGain(uint8_t gain)
@@ -318,29 +293,29 @@ void ADS1X15::requestADC(uint8_t pin)
318293

319294
int16_t ADS1X15::getValue()
320295
{
321-
int16_t raw = readRegister(_address, ADS1X15_REG_CONVERT);
296+
int16_t raw = _readRegister(_address, ADS1X15_REG_CONVERT);
322297
if (_bitShift) raw >>= _bitShift; // Shift 12-bit results
323298
return raw;
324299
}
325300

326301
void ADS1X15::setComparatorThresholdLow(int16_t lo)
327302
{
328-
writeRegister(_address, ADS1X15_REG_LOW_THRESHOLD, lo);
303+
_writeRegister(_address, ADS1X15_REG_LOW_THRESHOLD, lo);
329304
};
330305

331306
int16_t ADS1X15::getComparatorThresholdLow()
332307
{
333-
return readRegister(_address, ADS1X15_REG_LOW_THRESHOLD);
308+
return _readRegister(_address, ADS1X15_REG_LOW_THRESHOLD);
334309
};
335310

336311
void ADS1X15::setComparatorThresholdHigh(int16_t hi)
337312
{
338-
writeRegister(_address, ADS1X15_REG_HIGH_THRESHOLD, hi);
313+
_writeRegister(_address, ADS1X15_REG_HIGH_THRESHOLD, hi);
339314
};
340315

341316
int16_t ADS1X15::getComparatorThresholdHigh()
342317
{
343-
return readRegister(_address, ADS1X15_REG_HIGH_THRESHOLD);
318+
return _readRegister(_address, ADS1X15_REG_HIGH_THRESHOLD);
344319
};
345320

346321
int8_t ADS1X15::getError()
@@ -352,7 +327,7 @@ int8_t ADS1X15::getError()
352327

353328
//////////////////////////////////////////////////////
354329
//
355-
// PRIVATE
330+
// PROTECTED
356331
//
357332
int16_t ADS1X15::_readADC(uint16_t readmode)
358333
{
@@ -383,17 +358,43 @@ void ADS1X15::_requestADC(uint16_t readmode)
383358
if (_compLatch) config |= ADS1X15_COMP_LATCH;
384359
else config |= ADS1X15_COMP_NON_LATCH; // bit 2 ALERT latching
385360
config |= _compQueConvert; // bit 0..1 ALERT mode
386-
writeRegister(_address, ADS1X15_REG_CONFIG, config);
361+
_writeRegister(_address, ADS1X15_REG_CONFIG, config);
362+
}
363+
364+
bool ADS1X15::_writeRegister(uint8_t address, uint8_t reg, uint16_t value)
365+
{
366+
_wire->beginTransmission(address);
367+
_wire->write((uint8_t)reg);
368+
_wire->write((uint8_t)(value >> 8));
369+
_wire->write((uint8_t)(value & 0xFF));
370+
return (_wire->endTransmission() == 0);
371+
}
372+
373+
uint16_t ADS1X15::_readRegister(uint8_t address, uint8_t reg)
374+
{
375+
_wire->beginTransmission(address);
376+
_wire->write(reg);
377+
_wire->endTransmission();
378+
379+
int rv = _wire->requestFrom(address, (uint8_t) 2);
380+
if (rv == 2)
381+
{
382+
uint16_t value = _wire->read() << 8;
383+
value += _wire->read();
384+
return value;
385+
}
386+
return 0x0000;
387387
}
388388

389389

390390
///////////////////////////////////////////////////////////////////////////
391391
//
392392
// ADS1013
393393
//
394-
ADS1013::ADS1013(uint8_t address)
394+
ADS1013::ADS1013(uint8_t address, TwoWire *wire)
395395
{
396396
_address = address;
397+
_wire = wire;
397398
_config = ADS_CONF_NOCOMP | ADS_CONF_NOGAIN | ADS_CONF_RES_12 | ADS_CONF_CHAN_1;
398399
_conversionDelay = ADS1015_CONVERSION_DELAY;
399400
_bitShift = 4;
@@ -405,9 +406,10 @@ ADS1013::ADS1013(uint8_t address)
405406
//
406407
// ADS1014
407408
//
408-
ADS1014::ADS1014(uint8_t address)
409+
ADS1014::ADS1014(uint8_t address, TwoWire *wire)
409410
{
410411
_address = address;
412+
_wire = wire;
411413
_config = ADS_CONF_COMP | ADS_CONF_GAIN | ADS_CONF_RES_12 | ADS_CONF_CHAN_1;
412414
_conversionDelay = ADS1015_CONVERSION_DELAY;
413415
_bitShift = 4;
@@ -419,9 +421,10 @@ ADS1014::ADS1014(uint8_t address)
419421
//
420422
// ADS1015
421423
//
422-
ADS1015::ADS1015(uint8_t address)
424+
ADS1015::ADS1015(uint8_t address, TwoWire *wire)
423425
{
424426
_address = address;
427+
_wire = wire;
425428
_config = ADS_CONF_COMP | ADS_CONF_GAIN | ADS_CONF_RES_12 | ADS_CONF_CHAN_4;
426429
_conversionDelay = ADS1015_CONVERSION_DELAY;
427430
_bitShift = 4;
@@ -475,9 +478,10 @@ void ADS1015::requestADC_Differential_2_3()
475478
//
476479
// ADS1113
477480
//
478-
ADS1113::ADS1113(uint8_t address)
481+
ADS1113::ADS1113(uint8_t address, TwoWire *wire)
479482
{
480483
_address = address;
484+
_wire = wire;
481485
_config = ADS_CONF_NOCOMP | ADS_CONF_NOGAIN | ADS_CONF_RES_16 | ADS_CONF_CHAN_1;
482486
_conversionDelay = ADS1115_CONVERSION_DELAY;
483487
_bitShift = 0;
@@ -489,9 +493,10 @@ ADS1113::ADS1113(uint8_t address)
489493
//
490494
// ADS1114
491495
//
492-
ADS1114::ADS1114(uint8_t address)
496+
ADS1114::ADS1114(uint8_t address, TwoWire *wire)
493497
{
494498
_address = address;
499+
_wire = wire;
495500
_config = ADS_CONF_COMP | ADS_CONF_GAIN | ADS_CONF_RES_16 | ADS_CONF_CHAN_1;
496501
_conversionDelay = ADS1115_CONVERSION_DELAY;
497502
_bitShift = 0;
@@ -503,9 +508,10 @@ ADS1114::ADS1114(uint8_t address)
503508
//
504509
// ADS1115
505510
//
506-
ADS1115::ADS1115(uint8_t address)
511+
ADS1115::ADS1115(uint8_t address, TwoWire *wire)
507512
{
508513
_address = address;
514+
_wire = wire;
509515
_config = ADS_CONF_COMP | ADS_CONF_GAIN | ADS_CONF_RES_16 | ADS_CONF_CHAN_4;
510516
_conversionDelay = ADS1115_CONVERSION_DELAY;
511517
_bitShift = 0;

0 commit comments

Comments
 (0)