51 52 with same code

Dependencies:   MtSense07

Fork of MtConnect04S_MtSense07 by MtM+

Revision:
2:87f1b98c0d09
Parent:
1:40c18f027e6c
Child:
4:4ca64a863fbf
--- a/main.cpp	Fri Feb 03 06:51:09 2017 +0000
+++ b/main.cpp	Thu Mar 23 08:43:52 2017 +0000
@@ -25,10 +25,18 @@
 
 DigitalOut reset_sensor(p4, 1);   // Reset pin for AK09970 (Low active)
 I2C i2c(p3, p2);
-AK9750 ak9750(i2c);
+AK9750 ak9750(i2c, p0);
 AK09912 ak09912(i2c);
 AK09970 ak09970(i2c);
 
+volatile bool isIntEvent = false;
+
+//==============================================================================
+static void IntEventCallback() {
+    isIntEvent = true;
+}
+
+//==============================================================================
 int main() {
     /* Disable the hardware flow control of Serial, then show the mbed version */
     pc.set_flow_control(SerialBase::Disabled);
@@ -72,6 +80,7 @@
         while(1);
     }
 
+
     /* Main loop */
 #if (CONFIG_RUN_MODE == RUN_ALL_SENSOR_COM)
     AK9750::Data ak9750_data;
@@ -122,6 +131,29 @@
         count++;
         wait(1);
     }
+#elif (CONFIG_RUN_MODE == RUN_IR_AK9750_INT_COM)
+    // Enable interrupt sources and set callback function
+    ak9750.SetIntEvent(AK9750::INT_DR, &IntEventCallback);
+    
+    while (1) {
+        /* If any interrupt occurred */
+        if (isIntEvent) {
+            /* Read interrupt status */
+            uint8_t status = ak9750.GetIntStatus();
+            if (status & AK9750::INT_DR) {
+                pc.printf("INT_DR\n");
+                /* Read data */
+                AK9750::Data data;
+                ak9750.GetData(&data);
+                pc.printf("AK9750(%5.1fpA, %5.1fpA, %5.1fpA, %5.1fpA)\n", data.ir1, data.ir2, data.ir3, data.ir4);
+            }
+            if (status & AK9750::INT_IR24L) pc.printf("INT_IR24L\n");
+            if (status & AK9750::INT_IR24H) pc.printf("INT_IR24H\n");
+            if (status & AK9750::INT_IR13L) pc.printf("INT_IR13L\n");
+            if (status & AK9750::INT_IR13H) pc.printf("INT_IR13H\n");
+            isIntEvent = false;
+        }
+    }
 #else
     #errror "Config run mode ...FAIL"
 #endif