Skip to content

Commit

Permalink
Battery stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rouing committed Dec 22, 2024
1 parent 03f713e commit 4373917
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
21 changes: 18 additions & 3 deletions lib/utility/bq27220.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,34 @@

BQ27220::BQ27220() : addr{BQ27220_I2C_ADDRESS}, wire(&Wire), scl(BQ27220_I2C_SCL), sda(BQ27220_I2C_SDA) {}

void BQ27220::unseal()
bool BQ27220::unseal()
{
OP_STATUS status;

writeCtrlWord(BQ27220_UNSEAL_KEY1);
delayMicroseconds(5000);
readCtrlWord(BQ27220_UNSEAL_KEY2);
writeCtrlWord(BQ27220_UNSEAL_KEY2);
delayMicroseconds(5000);
status = OP_STATUS(readWord(BQ27220_CONTROL_CONTROL_STATUS));
if(status = OP_STATUS::UNSEALED)
{
Serial.println("UNSEALED");
return true;
}
return false;
}

bool BQ27220::seal()
{
OP_STATUS status;

writeCtrlWord(BQ27220_CONTROL_SEALED);
delayMicroseconds(5000);
status = OP_STATUS(readWord(BQ27220_CONTROL_CONTROL_STATUS));
if(status = OP_STATUS::SEALED)
{
return true;
}
return false;
}

uint16_t BQ27220::getTemp()
Expand Down
3 changes: 2 additions & 1 deletion lib/utility/bq27220.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ class BQ27220
{
public:
BQ27220();
void unseal();
bool unseal();
bool seal();
uint16_t getTemp();
uint16_t getBatterySt(void);
bool getIsCharging(void);
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void showDeviceInfo() {
area.addLine("Charge: " + String(getBattery()) + "%");
#ifdef USE_BQ27220_VIA_I2C
area.addLine("BQ27220 ADDR: " + String(BQ27220_I2C_ADDRESS));
area.addLine("Charging: " + String(bq.getIsCharging()));
area.addLine("Charging: " + bq.getIsCharging());
area.addLine("Charging Voltage: " + String(((double)bq.getVolt(VOLT_MODE::VOLT_CHARGING)/1000.0)) + "V");
area.addLine("Charging Current: " + String(bq.getCurr(CURR_MODE::CURR_CHARGING) + "mA"));
area.addLine("Time to Empty: " + String((bq.getTimeToEmpty()/1440)) + " days, " + String(((bq.getTimeToEmpty()%1440)/60)) + " hrs," + String(((bq.getTimeToEmpty()%1440)%60)) + " mins");
Expand Down

0 comments on commit 4373917

Please sign in to comment.