Commit b9390ddf authored by Armin's avatar Armin
Browse files

Version 3.1.1 - Better prints at scanning.

parent a9565084
# [SMB](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino) - Smart Battery Module (Laptop Battery Pack) Info # [SMB](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino) - Smart Battery Module (Laptop Battery Pack) Info
### Version 3.1 ### Version 3.1.1
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![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) [![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)
...@@ -132,4 +132,8 @@ Minutes remaining until empty: 2913 min ...@@ -132,4 +132,8 @@ Minutes remaining until empty: 2913 min
Average minutes remaining until empty: 2913 min Average minutes remaining until empty: 2913 min
``` ```
# Revision History
### Version 3.1.1
- Better prints at scanning.
#### If you find this library useful, please give it a star. #### If you find this library useful, please give it a star.
...@@ -2,9 +2,16 @@ ...@@ -2,9 +2,16 @@
* SBMInfo.ino * SBMInfo.ino
* Shows Smart Battery Info * Shows Smart Battery Info
* *
* Copyright (C) 2016 Armin Joachimsmeyer * Copyright (C) 2016-2020 Armin Joachimsmeyer
* armin.joachimsmeyer@gmail.com * armin.joachimsmeyer@gmail.com
* *
* https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino
*
* SBMInfo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...@@ -24,7 +31,12 @@ ...@@ -24,7 +31,12 @@
#define LCD_COLUMNS 20 #define LCD_COLUMNS 20
#define LCD_ROWS 4 #define LCD_ROWS 4
#define VERSION_EXAMPLE "3.1" #define VERSION_EXAMPLE "3.1.1"
/*
* Version 3.1.1 - 3/2020
* - Better prints at scanning.
*/
//#define DEBUG //#define DEBUG
/* /*
...@@ -198,13 +210,15 @@ void setup() { ...@@ -198,13 +210,15 @@ void setup() {
/* /*
* Check for I2C device and blink until device attached * Check for I2C device and blink until device attached
*/ */
if (!checkForAttachedI2CDevice(SBM_DEVICE_ADDRESS)) { if (checkForAttachedI2CDevice(SBM_DEVICE_ADDRESS)) {
int tDeviceAttached; sI2CDeviceAddress = SBM_DEVICE_ADDRESS;
} else {
Serial.println(F("Start scanning for device at I2C bus"));
do { do {
tDeviceAttached = scanForAttachedI2CDevice(); sI2CDeviceAddress = scanForAttachedI2CDevice();
delay(500); delay(500);
TogglePin(LED_BUILTIN); TogglePin(LED_BUILTIN);
} while (tDeviceAttached < 0); } while (sI2CDeviceAddress < 0);
} }
uint16_t tVoltage; uint16_t tVoltage;
...@@ -256,22 +270,23 @@ void TogglePin(uint8_t aPinNr) { ...@@ -256,22 +270,23 @@ void TogglePin(uint8_t aPinNr) {
bool checkForAttachedI2CDevice(uint8_t aStandardDeviceAddress) { bool checkForAttachedI2CDevice(uint8_t aStandardDeviceAddress) {
Wire.beginTransmission(aStandardDeviceAddress); Wire.beginTransmission(aStandardDeviceAddress);
uint8_t tOK = Wire.endTransmission(); uint8_t tRetCode = Wire.endTransmission();
if (tOK == 0) { if (tRetCode == 0) {
Serial.print(F("Found attached I2C device at 0x")); Serial.print(F("Found attached I2C device at 0x"));
Serial.println(aStandardDeviceAddress, HEX); Serial.println(aStandardDeviceAddress, HEX);
Serial.flush(); Serial.flush();
sI2CDeviceAddress = SBM_DEVICE_ADDRESS;
return true; return true;
} else { } else {
Serial.print(F("Transmission error code=")); Serial.print(F("Transmission error code="));
Serial.println(tOK); Serial.print(tRetCode);
Serial.print(F(" while looking for device at default address 0x"));
Serial.println(aStandardDeviceAddress, HEX);
return false; return false;
} }
} }
int sScanCount = 0;
int scanForAttachedI2CDevice(void) { int scanForAttachedI2CDevice(void) {
int sScanCount = 0;
int tFoundAdress = -1; int tFoundAdress = -1;
for (uint8_t i = 0; i < 127; i++) { for (uint8_t i = 0; i < 127; i++) {
Wire.beginTransmission(i); Wire.beginTransmission(i);
...@@ -286,7 +301,6 @@ int scanForAttachedI2CDevice(void) { ...@@ -286,7 +301,6 @@ int scanForAttachedI2CDevice(void) {
Serial.print(F("Scan found no attached I2C device - ")); Serial.print(F("Scan found no attached I2C device - "));
Serial.println(sScanCount); Serial.println(sScanCount);
myLCD.setCursor(0, 3); myLCD.setCursor(0, 3);
// print the number of seconds since reset:
myLCD.print("Scan for device "); myLCD.print("Scan for device ");
myLCD.print(sScanCount); myLCD.print(sScanCount);
sScanCount++; sScanCount++;
...@@ -294,7 +308,6 @@ int scanForAttachedI2CDevice(void) { ...@@ -294,7 +308,6 @@ int scanForAttachedI2CDevice(void) {
// clear LCD line // clear LCD line
myLCD.setCursor(0, 3); myLCD.setCursor(0, 3);
myLCD.print(" "); myLCD.print(" ");
sI2CDeviceAddress = tFoundAdress;
} }
return tFoundAdress; return tFoundAdress;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment