Skip to content

Commit b9390dd

Browse files
committed
Version 3.1.1 - Better prints at scanning.
1 parent a956508 commit b9390dd

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# [SMB](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino) - Smart Battery Module (Laptop Battery Pack) Info
2-
### Version 3.1
2+
### Version 3.1.1
33
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
44
[![Hit Counter](https://hitcounter.pythonanywhere.com/count/tag.svg?url=https%3A%2F%2Fgithub.com%2FArminJo%2FSmart-Battery-Module-Info_For_Arduino)](https://github.com/brentvollebregt/hit-counter)
55

@@ -132,4 +132,8 @@ Minutes remaining until empty: 2913 min
132132
Average minutes remaining until empty: 2913 min
133133
```
134134

135+
# Revision History
136+
### Version 3.1.1
137+
- Better prints at scanning.
138+
135139
#### If you find this library useful, please give it a star.

src/SBMInfo/SBMInfo.ino

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22
* SBMInfo.ino
33
* Shows Smart Battery Info
44
*
5-
* Copyright (C) 2016 Armin Joachimsmeyer
5+
* Copyright (C) 2016-2020 Armin Joachimsmeyer
66
77
*
8+
* https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino
9+
*
10+
* SBMInfo is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
815
* This program is distributed in the hope that it will be useful,
916
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1017
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -24,7 +31,12 @@
2431
#define LCD_COLUMNS 20
2532
#define LCD_ROWS 4
2633

27-
#define VERSION_EXAMPLE "3.1"
34+
#define VERSION_EXAMPLE "3.1.1"
35+
36+
/*
37+
* Version 3.1.1 - 3/2020
38+
* - Better prints at scanning.
39+
*/
2840

2941
//#define DEBUG
3042
/*
@@ -198,13 +210,15 @@ void setup() {
198210
/*
199211
* Check for I2C device and blink until device attached
200212
*/
201-
if (!checkForAttachedI2CDevice(SBM_DEVICE_ADDRESS)) {
202-
int tDeviceAttached;
213+
if (checkForAttachedI2CDevice(SBM_DEVICE_ADDRESS)) {
214+
sI2CDeviceAddress = SBM_DEVICE_ADDRESS;
215+
} else {
216+
Serial.println(F("Start scanning for device at I2C bus"));
203217
do {
204-
tDeviceAttached = scanForAttachedI2CDevice();
218+
sI2CDeviceAddress = scanForAttachedI2CDevice();
205219
delay(500);
206220
TogglePin(LED_BUILTIN);
207-
} while (tDeviceAttached < 0);
221+
} while (sI2CDeviceAddress < 0);
208222
}
209223

210224
uint16_t tVoltage;
@@ -256,22 +270,23 @@ void TogglePin(uint8_t aPinNr) {
256270

257271
bool checkForAttachedI2CDevice(uint8_t aStandardDeviceAddress) {
258272
Wire.beginTransmission(aStandardDeviceAddress);
259-
uint8_t tOK = Wire.endTransmission();
260-
if (tOK == 0) {
273+
uint8_t tRetCode = Wire.endTransmission();
274+
if (tRetCode == 0) {
261275
Serial.print(F("Found attached I2C device at 0x"));
262276
Serial.println(aStandardDeviceAddress, HEX);
263277
Serial.flush();
264-
sI2CDeviceAddress = SBM_DEVICE_ADDRESS;
265278
return true;
266279
} else {
267280
Serial.print(F("Transmission error code="));
268-
Serial.println(tOK);
281+
Serial.print(tRetCode);
282+
Serial.print(F(" while looking for device at default address 0x"));
283+
Serial.println(aStandardDeviceAddress, HEX);
269284
return false;
270285
}
271286
}
272287

273-
int sScanCount = 0;
274288
int scanForAttachedI2CDevice(void) {
289+
int sScanCount = 0;
275290
int tFoundAdress = -1;
276291
for (uint8_t i = 0; i < 127; i++) {
277292
Wire.beginTransmission(i);
@@ -286,15 +301,13 @@ int scanForAttachedI2CDevice(void) {
286301
Serial.print(F("Scan found no attached I2C device - "));
287302
Serial.println(sScanCount);
288303
myLCD.setCursor(0, 3);
289-
// print the number of seconds since reset:
290304
myLCD.print("Scan for device ");
291305
myLCD.print(sScanCount);
292306
sScanCount++;
293307
} else {
294308
// clear LCD line
295309
myLCD.setCursor(0, 3);
296310
myLCD.print(" ");
297-
sI2CDeviceAddress = tFoundAdress;
298311
}
299312
return tFoundAdress;
300313
}

0 commit comments

Comments
 (0)