Library to interface to the TI BQ27441, a fuel gauge monitor

Dependents:   rcCar

Fork of battery-gauge-bq27441 by u-blox

Revision:
5:63b325f2c21a
Parent:
3:ebd56471d57c
--- a/TESTS/unit_tests/default/main.cpp	Wed Jun 07 10:32:54 2017 +0000
+++ b/TESTS/unit_tests/default/main.cpp	Wed Jun 14 17:11:40 2017 +0100
@@ -80,6 +80,11 @@
     TEST_ASSERT_FALSE(pBatteryGauge->enableGauge());
     
     TEST_ASSERT(pBatteryGauge->init(gpI2C));
+#ifdef TARGET_UBLOX_C030
+    // Battery detection is not supported on C030
+    TEST_ASSERT(pBatteryGauge->disableBatteryDetect());
+#endif
+
     // Normal case
     TEST_ASSERT(pBatteryGauge->enableGauge());
     TEST_ASSERT(pBatteryGauge->isGaugeEnabled());
@@ -106,6 +111,10 @@
     
     // Normal case
     TEST_ASSERT(pBatteryGauge->init(gpI2C));
+#ifdef TARGET_UBLOX_C030
+    // Battery detection is not supported on C030
+    TEST_ASSERT(pBatteryGauge->disableBatteryDetect());
+#endif
     TEST_ASSERT(pBatteryGauge->isBatteryDetected());
 }
 
@@ -120,7 +129,7 @@
     // Normal case
     TEST_ASSERT(pBatteryGauge->init(gpI2C));
     TEST_ASSERT(pBatteryGauge->getTemperature(&temperatureC));
-    printf ("Temperature %d C.\n", temperatureC);
+    printf ("Temperature %d C.\n", (int) temperatureC);
     // Range check
     TEST_ASSERT((temperatureC >= MIN_TEMPERATURE_READING_C) && (temperatureC <= MAX_TEMPERATURE_READING_C));
     
@@ -195,8 +204,13 @@
     
     // Normal case
     TEST_ASSERT(pBatteryGauge->init(gpI2C));
+#ifdef TARGET_UBLOX_C030
+    // Battery detection is not supported on C030
+    // and battery detect is required for the "gauging" type APIs
+    TEST_ASSERT(pBatteryGauge->disableBatteryDetect());
+#endif
     TEST_ASSERT(pBatteryGauge->getRemainingPercentage(&batteryPercent));
-    printf ("Remaining percentage %d%%.\n", batteryPercent);
+    printf ("Remaining percentage %d%%.\n", (int) batteryPercent);
     // Range check
     TEST_ASSERT((batteryPercent >= 0) && (batteryPercent <= 100));
 
@@ -222,7 +236,7 @@
     subClassId = 80;
     memset(&(data1[0]), 0, sizeof (data1));
     TEST_ASSERT(pBatteryGauge->advancedGetConfig(subClassId, offset, length, &(data1[0])));
-    printf("%d bytes received from subClassID %d, offset %d:\n", length, subClassId, offset);
+    printf("%d bytes received from subClassID %d, offset %d:\n", (int) length, subClassId, (int) offset);
     printBytesAsHex(&(data1[0]), length);
     TEST_ASSERT_EQUAL_UINT32 (0xdeadbeef, deadArea1);
     
@@ -231,7 +245,7 @@
     length = MAX_CONFIG_BLOCK_SIZE - 16;
     memset(&(data2[0]), 0, sizeof (data2));
     TEST_ASSERT(pBatteryGauge->advancedGetConfig(subClassId, offset, length, &(data2[0])));
-    printf("%d bytes received from subClassID %d, offset %d:\n", length, subClassId, offset);
+    printf("%d bytes received from subClassID %d, offset %d:\n", (int) length, subClassId, (int) offset);
     printBytesAsHex(&(data2[0]), length);
     // The second 16 bytes of data1 and the first 16 bytes of data2 should match
     TEST_ASSERT_EQUAL_UINT8_ARRAY(&(data1[16]), &(data2[0]), 16);
@@ -242,7 +256,7 @@
     length = MAX_CONFIG_BLOCK_SIZE;
     memset(&(data1[0]), 0, sizeof (data1));
     TEST_ASSERT(pBatteryGauge->advancedGetConfig(subClassId, offset, length, &(data1[0])));
-    printf("%d bytes received from subClassID %d, offset %d:\n", length, subClassId, offset);
+    printf("%d bytes received from subClassID %d, offset %d:\n", (int) length, subClassId, (int) offset);
     printBytesAsHex(&(data1[0]), length);
     TEST_ASSERT_EQUAL_UINT32 (0xdeadbeef, deadArea1);
 
@@ -250,7 +264,7 @@
     length = 16;
     memset(&(data2[0]), 0, sizeof (data2));
     TEST_ASSERT(pBatteryGauge->advancedGetConfig(subClassId, offset, length, &(data2[0])));
-    printf("%d bytes received from subClassID %d, offset %d:\n", length, subClassId, offset);
+    printf("%d bytes received from subClassID %d, offset %d:\n", (int) length, subClassId, (int) offset);
     printBytesAsHex(&(data2[0]), length);
     // The first 16 bytes of data1 and data2 should match
     TEST_ASSERT_EQUAL_UINT8_ARRAY(&(data1[0]), &(data2[0]), length);
@@ -278,7 +292,7 @@
     length = 2;
     memset(&(data1[0]), 0, sizeof (data1));
     TEST_ASSERT(pBatteryGauge->advancedGetConfig(subClassId, offset, length, &(data1[0])));
-    printf("%d bytes received from subClassID %d, offset %d:\n", length, subClassId, offset);
+    printf("%d bytes received from subClassID %d, offset %d:\n", (int) length, subClassId, (int) offset);
     printBytesAsHex(&(data1[0]), length);
     TEST_ASSERT_EQUAL_UINT32 (0xdeadbeef, deadArea1);
     
@@ -287,7 +301,7 @@
     printf ("Modified data block:\n");
     printBytesAsHex(&(data1[0]), length);
     TEST_ASSERT(pBatteryGauge->advancedSetConfig(subClassId, offset, length, &(data1[0])));
-    printf("%d bytes written to subClassID %d, offset %d:\n", length, subClassId, offset);
+    printf("%d bytes written to subClassID %d, offset %d:\n", (int) length, subClassId, (int) offset);
 
     // Read it back and check that the Delta Voltage really is the new value
     subClassId = 82;
@@ -295,7 +309,7 @@
     length = 9;
     memset(&(data2[0]), 0, sizeof (data2));
     TEST_ASSERT(pBatteryGauge->advancedGetConfig(subClassId, offset, length, &(data2[0])));
-    printf("%d bytes received from subClassID %d, offset %d:\n", length, subClassId, offset);
+    printf("%d bytes received from subClassID %d, offset %d:\n", (int) length, subClassId, (int) offset);
     printBytesAsHex(&(data2[0]), length);
     TEST_ASSERT_EQUAL_UINT32 (0xdeadbeef, deadArea1);
     TEST_ASSERT_EQUAL_UINT32 (data1[0], data2[7]);
@@ -304,7 +318,7 @@
     // Now put Delta Voltage back as it was
     (data2[8])--;
     TEST_ASSERT(pBatteryGauge->advancedSetConfig(subClassId, offset, length, &(data2[0])));
-    printf("%d bytes written to subClassID %d, offset %d:\n", length, subClassId, offset);
+    printf("%d bytes written to subClassID %d, offset %d:\n", (int) length, subClassId, (int) offset);
 }
 
 // Test fail cases of the advanced configuration functions
@@ -405,6 +419,10 @@
 
     // Make sure that the device is not sealed from a previous field test run
     TEST_ASSERT(pBatteryGauge->init(gpI2C));
+#ifdef TARGET_UBLOX_C030
+    // Battery detection is not supported on C030
+    TEST_ASSERT(pBatteryGauge->disableBatteryDetect());
+#endif
     TEST_ASSERT(pBatteryGauge->advancedUnseal());
 
     delete pBatteryGauge;