Permalink
Browse files

wip

  • Loading branch information...
1 parent 3d71638 commit e1bc4f25c2edac4994c5a91b9694f4c7875f73b6 Matthew Newberry committed Dec 22, 2011
Showing with 44 additions and 9 deletions.
  1. +35 −8 MAX1704.cpp
  2. +5 −1 MAX1704.h
  3. +4 −0 MAX1704.ino
View
@@ -23,19 +23,16 @@ float MAX1704::stateOfCharge(){
void MAX1704::showConfig(){
- int data[] = {};
- readFrom(MAX1704_CONFIG,2,data);
-
- byte sleep = (data[1] >>7) & 0x01;
- byte alert = (data[1] >>5) & 0x01;
- byte alertThreshold = data[1] & 0x1f;
+ int threshold = alertThreshold();
+ boolean sleep = isSleeping();
+ boolean alert = isAlerting();
Serial.print("Sleep = ");
Serial.println(sleep, HEX);
Serial.print("Alert = ");
Serial.println(alert, HEX);
Serial.print("Alert Threshold = ");
- Serial.print(32-alertThreshold, DEC);
+ Serial.print(threshold, DEC);
Serial.println("%");
}
@@ -53,7 +50,7 @@ void MAX1704::version(){
}
-void MAX1704::setAlertLevel(uint8_t level){
+void MAX1704::setAlertThreshold(uint8_t level){
Wire.beginTransmission(MAX1704_ADDR);
Wire.write(MAX1704_CONFIG);
@@ -62,6 +59,36 @@ void MAX1704::setAlertLevel(uint8_t level){
Wire.endTransmission();
}
+int MAX1704::alertThreshold(){
+
+ int data[] = {};
+ readFrom(MAX1704_CONFIG,2,data);
+
+ byte alertThreshold = data[1] & 0x1f;
+
+ return int(32 - alertThreshold);
+}
+
+boolean MAX1704::isAlerting(){
+
+ int data[] = {};
+ readFrom(MAX1704_CONFIG,2,data);
+
+ byte alert = (data[1] >>5) & 0x01;
+
+ return int(alert) == 1;
+}
+
+boolean MAX1704::isSleeping(){
+
+ int data[] = {};
+ readFrom(MAX1704_CONFIG,2,data);
+
+ byte sleep = (data[1] >>7) & 0x01;
+
+ return int(sleep) == 1;
+}
+
void MAX1704::performCommand(byte address, int value){
Wire.beginTransmission(MAX1704_ADDR);
View
@@ -28,7 +28,11 @@ class MAX1704{
void powerOnReset();
void quickStart();
void version();
- void setAlertLevel(uint8_t level);
+ void setAlertThreshold(uint8_t level);
+ int alertThreshold();
+ boolean isSleeping();
+ boolean isAlerting();
+
private:
void performCommand(byte address, int value);
View
@@ -13,6 +13,7 @@
* *
***************************************************************************/
+#include "Arduino.h"
#include "Wire.h"
#include "MAX1704.h"
@@ -23,8 +24,11 @@ void setup(){
Wire.begin();
Serial.begin(9600);
+ Serial.println("Starting up...");
+ delay(1000);
fuelGauge.quickStart();
fuelGauge.powerOnReset();
+ fuelGauge.showConfig();
}
void loop(){

0 comments on commit e1bc4f2

Please sign in to comment.