Skip to content

Commit

Permalink
Merge pull request #6 from porrey/new-constructor
Browse files Browse the repository at this point in the history
New constructor
  • Loading branch information
porrey authored May 3, 2021
2 parents 99644a0 + f83c191 commit fdbc2e6
Show file tree
Hide file tree
Showing 13 changed files with 649 additions and 236 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
*.exe
*.out
*.app
.DS_Store
src/.vscode/arduino.json
88 changes: 0 additions & 88 deletions examples/Both/Both.ino

This file was deleted.

37 changes: 37 additions & 0 deletions examples/MAX17043/MAX17043.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* MAX1704X Arduino Library for MAX17043 and MAX17044 Fuel Gauge.
*
* Version 1.1.0
* Copyright © 2018-2021 Daniel Porrey. All Rights Reserved.
* https://github.com/porrey/max1704x
*
* This file is part of the MAX1704X Arduino Library.
*
* The MAX1704X Arduino Library 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.
*
* The MAX1704X Arduino Library is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the MAX1704X Arduino Library. If not,
* see http://www.gnu.org/licenses/.
*/
#ifndef MAX17043_H
#define MAX17043_H

#include "MAX1704X.h"

extern MAX1704X FuelGauge;

//
// The MAX17043 is a one-cell device with a
// a voltage measurement range of 0 to 5 V in 1.25 mV increments.
//
MAX1704X FuelGauge = MAX1704X(1.25);

#endif
57 changes: 36 additions & 21 deletions examples/MAX17043/MAX17043.ino
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* MAX1704X Arduino Library for MAX17043 and MAX17044 Fuel Gauge.
*
* Version 1.0.0
* Copyright © 2018 Daniel Porrey. All Rights Reserved.
* Version 1.1.0
* Copyright © 2018-2021 Daniel Porrey. All Rights Reserved.
* https://github.com/porrey/max1704x
*
* This file is part of the MAX1704X Arduino Library.
Expand Down Expand Up @@ -35,35 +35,46 @@

void setup()
{
// ***
// *** Initialize the serial interface.
// ***
//
// Initialize the serial interface.
//
Serial.begin(115200);

// ***
// *** Initialize the fuel gauge.
// ***
//
// Wait for serial port to connect.
//
while (!Serial) {}
Serial.println("Serial port initialized.\n");

//
// Initialize the fuel gauge.
//
FuelGauge.begin();

// ***
// *** Display an initial reading.
// ***
//
// Other ways to initialize:
//
// begin(bool initializeWire)
// begin(bool initializeWire, uint32_t address)
// begin(int sda, int scl) [esp only]
// begin(int sda, int scl, uint8_t) [esp only]

//
// Display an initial reading.
//
displayReading();
Serial.println();
displayMenu();
}

void loop()
{
Serial.println("Enter an option in the serial input (M for menu):");

while (Serial.available() == 0)
{
delay(25);
}

char c = Serial.read();
Serial.println();

switch (c)
{
Expand Down Expand Up @@ -95,12 +106,11 @@ void loop()
decrementThreshold();
break;
}

Serial.println();
}

void displayMenu()
{
Serial.println("Enter an option in the serial input (M for menu):");
Serial.println("D => Display a reading.");
Serial.println("S => Enter sleep mode.");
Serial.println("W => Wake.");
Expand All @@ -109,22 +119,27 @@ void displayMenu()
Serial.println("R => Reset.");
Serial.println("+ => Increment threshold.");
Serial.println("- => Decrement threshold.");
Serial.println();
}

void displayReading()
{
// ***
// *** Get the voltage, battery percent
// *** and other properties.
// ***
//
// Get the voltage, battery percent
// and other properties.
//

Serial.println("Device Reading:");
Serial.print("Address: 0x"); Serial.println(FuelGauge.address(), HEX);
Serial.print("Version: "); Serial.println(FuelGauge.version());
Serial.print("ADC: "); Serial.println(FuelGauge.adc());
Serial.print("Voltage: "); Serial.print(FuelGauge.voltage()); Serial.println(" v");
Serial.print("Voltage: "); Serial.print(FuelGauge.voltage()); Serial.println(" mV");
Serial.print("Percent: "); Serial.print(FuelGauge.percent()); Serial.println("%");
Serial.print("Is Sleeping: "); Serial.println(FuelGauge.isSleeping() ? "Yes" : "No");
Serial.print("Alert: "); Serial.println(FuelGauge.alertIsActive() ? "Yes" : "No");
Serial.print("Threshold: "); Serial.println(FuelGauge.getThreshold());
Serial.print("Compensation: 0x"); Serial.println(FuelGauge.compensation(), HEX);
Serial.println();
}

void sleepMode()
Expand Down
37 changes: 37 additions & 0 deletions examples/MAX17043/MAX17044.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* MAX1704X Arduino Library for MAX17043 and MAX17044 Fuel Gauge.
*
* Version 1.1.0
* Copyright © 2018-2021 Daniel Porrey. All Rights Reserved.
* https://github.com/porrey/max1704x
*
* This file is part of the MAX1704X Arduino Library.
*
* The MAX1704X Arduino Library 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.
*
* The MAX1704X Arduino Library is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the MAX1704X Arduino Library. If not,
* see http://www.gnu.org/licenses/.
*/
#ifndef MAX17044_H
#define MAX17044_H

#include "MAX1704X.h"

extern MAX1704X FuelGauge;

//
// The MAX17044 is a two-cell device with a
// a voltage measurement range of 0 to 10 V in 2.50 mV increments.
//
MAX1704X FuelGauge = MAX1704X(2.50);

#endif
Loading

0 comments on commit fdbc2e6

Please sign in to comment.