Skip to content

Commit 0b26a6c

Browse files
committed
Use volts and amps as unit
1 parent f9f8360 commit 0b26a6c

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

Diff for: examples/Powershell/Powershell.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ void setup() {
217217

218218

219219
#if !defined(ARDUINO_NICLA_VISION)
220-
charger.setChargeCurrent(ChargeCurrent::I_200_mA);
221-
charger.setChargeVoltage(ChargeVoltage::V_4_20);
222-
charger.setEndOfChargeCurrent(EndOfChargeCurrent::I_5_mA);
220+
charger.setChargeCurrent(0.2);
221+
charger.setChargeVoltage(4.2);
222+
charger.setEndOfChargeCurrent(0.005);
223223
#endif
224224
}
225225

Diff for: src/Battery.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@ bool Battery::isConnected(){
3434
return bitRead(statusRegister, BATTERY_STATUS_BIT) == 0;
3535
}
3636

37-
int Battery::voltage(){
37+
float Battery::voltage(){
3838
if(!isConnected()){
3939
return -1;
4040
}
4141

42-
return readRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, VCELL_REG) * VOLTAGE_MULTIPLIER;
42+
auto voltageInMV = readRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, VCELL_REG) * VOLTAGE_MULTIPLIER;
43+
return voltageInMV / 1000.0f;
4344
}
4445

45-
unsigned int Battery::averageVoltage(){
46+
float Battery::averageVoltage(){
4647
if(!isConnected()){
4748
return -1;
4849
}
4950

50-
return readRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, AVG_VCELL_REG) * VOLTAGE_MULTIPLIER;
51+
auto voltageInVolts = readRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, AVG_VCELL_REG) * VOLTAGE_MULTIPLIER;
52+
return voltageInVolts / 1000.0f;
5153
}
5254

5355
int Battery::temperature(){
@@ -66,20 +68,22 @@ int Battery::averageTemperature(){
6668
return readRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, AVG_TA_REG) >> 8;
6769
}
6870

69-
int Battery::current(){
71+
float Battery::current(){
7072
if(!isConnected()){
7173
return -1;
7274
}
7375

74-
return (int16_t)readRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, CURRENT_REG) * CURRENT_MULTIPLIER;
76+
auto currentInAmperes = (int16_t)readRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, CURRENT_REG) * CURRENT_MULTIPLIER;
77+
return currentInAmperes / 1000.0f;
7578
}
7679

77-
int Battery::averageCurrent(){
80+
float Battery::averageCurrent(){
7881
if(!isConnected()){
7982
return -1;
8083
}
8184

82-
return (int16_t)readRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, AVG_CURRENT_REG) * CURRENT_MULTIPLIER;
85+
auto currentInAmperes = (int16_t)readRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, AVG_CURRENT_REG) * CURRENT_MULTIPLIER;
86+
return currentInAmperes / 1000.0f;
8387
}
8488

8589
int Battery::percentage(){

Diff for: src/Battery.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ class Battery {
4545
// TODO Shall this be in volts to be consistent?
4646
/**
4747
* @brief Reads the current voltage of the battery.
48-
* Voltage is usually between 3000mV and 4200mV.
49-
* @return The current voltage in millivolts (mV).
48+
* Voltage is usually between 3.0V and 4.2V.
49+
* @return The current voltage in volts (V).
5050
*/
51-
int voltage();
51+
float voltage();
5252

5353
// TODO Shall this be in ampere to be consistent?
5454
/**
5555
* @brief Reads the current flowing from the battery at the moment.
5656
* Negative values indicate that the battery is charging,
5757
* positive values indicate that the battery is discharging.
5858
* When no battery is connected, the value is 0.
59-
* @return The current flowing from the battery in milliamperes (mA).
59+
* @return The current flowing from the battery in amperes (A).
6060
*/
61-
int current();
61+
float current();
6262

6363
/**
6464
* @brief Reads the current temperature of the battery.
@@ -92,16 +92,16 @@ class Battery {
9292
// TODO Shall this be in ampere to be consistent?
9393
/**
9494
* @brief Reads the average current of the battery.
95-
* @return The average current in millivolts (mV).
95+
* @return The average current in amperes (A).
9696
*/
97-
int averageCurrent();
97+
float averageCurrent();
9898

9999
// TODO Shall this be in volts to be consistent?
100100
/**
101101
* @brief Reads the average voltage of the battery.
102-
* @return The average voltage in millivolts (mV).
102+
* @return The average voltage in volts (V).
103103
*/
104-
unsigned int averageVoltage();
104+
float averageVoltage();
105105

106106
int batteryCapacityInMiliampereHours = DEFAULT_BATTERY_CAPACITY;
107107
int batteryEmptyVoltage = DEFAULT_BATTERY_EMPTY_VOLTAGE;

0 commit comments

Comments
 (0)