I2C sensor test program, derived from testI2C program. Simple test for FXOS8700CQ, HIH6130, MAG3110, MMA8451Q, MMA8452Q, MPL3115A2, MAX44000, MAX44005, MAX44008, MAX30101 included beside simple I2C read/write from testI2C.

Dependencies:   FXOS8700CQ HIH6130 IS31SE5000 MAG3110 MAX44000 MAX44005 MAX44008 MMA8451Q MMA8452Q MPL3115A2 VEML6040 VEML6075 mbed vt100 LM75B FXAS21002 MAX30101 VCNL4020 VCNL4100

Revision:
9:d4f76e6fa35f
Parent:
4:c10b1aa9925c
Child:
12:b3dff3bbb1eb
--- a/testSensor.cpp	Fri Aug 05 07:57:22 2016 +0000
+++ b/testSensor.cpp	Wed Feb 08 05:48:17 2017 +0000
@@ -30,6 +30,7 @@
 DUMB_I2C *i2c = 0 ;
 vt100 *tty = 0 ;
 int test_loop = TEST_LOOP ;
+int interval = 100 ; /* ms wait interval */
 
 void doClose(void)
 {
@@ -110,6 +111,8 @@
         printf("i2c device at 0x%02X is opened at %d Hz\n", 
             i2c->address(), i2c->frequency()) ;
     }
+    printf("test loop number = %d\n", test_loop) ;
+    printf("loop interval = %d ms\n", interval) ;
 }
 
 void doHelp(void)
@@ -124,6 +127,7 @@
     printf("bus                 : bus scan for existing I2C addresses\n") ;
     printf("test <sensor>       : test a sensor\n") ;
     printf("loop <number>       : specify loop count for test\n") ;
+    printf("interval <numver>   : ms interval for each loop\n") ;
     printf("status              : print current status\n") ;
     printf("help                : print this help\n") ;
     printf("\nPlease set local-echo to see what you are typing.\n") ;
@@ -153,7 +157,8 @@
 void doBusScan(void)
 {
     int address ;
-    uint8_t data ;
+    uint8_t data[10] ;
+    int num_data = 1 ;
     int result ;
     if (i2c != 0) {
         printf("Closing I2C at 0x%02X ... ", i2c->address()) ;
@@ -164,7 +169,13 @@
 
     for (address = 1; address < 127 ; address++) {
         i2c = new DUMB_I2C(PIN_SDA, PIN_SCL, address) ;
-        result = i2c->read(address, &data, 1) ;
+//        result = i2c->read(address, &data, 1) ;
+        if (address == 0x10) {
+            num_data = 2 ;
+        } else {
+            num_data = 1 ;
+        }
+        result = i2c->read(0, data, num_data) ;
         if (result == 0) {
             printf("%02X : ", address) ;
             print_sensor_name(address) ;
@@ -185,6 +196,15 @@
     printf("test loop count set to %d\n", test_loop) ;
 }
 
+void setTestInterval(void)
+{
+    int num ;
+    scanf("%d", &num) ;
+    if (num < 0) num = 100 ;
+    interval = num ;
+    printf("wait %d ms for each loop\n", interval) ;
+}
+
 void str2upper(char *str)
 {
     while(str && *str) {
@@ -228,6 +248,8 @@
         doTestSensor() ; break ;
     case 'l': case 'L': /* set test_loop */
         setTestLoop() ; break ;
+    case 'i': case 'I': /* set interval */
+        setTestInterval() ; break ;
     case 'b': case 'B': /* Bus Scan */
         doBusScan() ; break ;
     default: