Buffered Test

Dependencies:   ExioBufferdController MCP23S17 mbed-rtos mbed

Revision:
10:5d1a09afe152
Parent:
9:76d17c5cac87
Child:
11:325c5e9d28e2
--- a/main.cpp	Fri Nov 04 23:20:32 2016 +0000
+++ b/main.cpp	Fri Nov 04 23:37:24 2016 +0000
@@ -24,6 +24,24 @@
 // MExioMcp23s17(int hardwareaddress, SPI& spi, PinName nCs, PinName nReset);
 ExioMcp23s17 Exio(0x00, Spi, PD_2, PA_13);
  
+bool state = false;
+uint8_t count = 0;
+
+//------------------------------------------------------------------------------
+// Callback functions
+//
+void pa6Falled() {
+    state = !state;
+}
+
+void pa7Falled() {
+    count++;
+}
+
+
+//------------------------------------------------------------------------------
+// Test functions
+//
 void testExioInBuffer()
 {
     printf("*** Test ExioInBuffer ***\r\n");
@@ -149,17 +167,6 @@
     }
 }
 
-bool state = false;
-uint8_t count = 0;
-
-void pa7Falled() {
-    count++;
-}
-
-void pa6Falled() {
-    state = !state;
-}
-
 void testExioBufferedPinDetect()
 {
     printf("*** Test ExioBufferedPinDetect ***\r\n");
@@ -213,33 +220,56 @@
     //testExioBufferedIn();
     //testExioBufferedDebounceIn();
     //testExioBufferedRotaryEncoder();
-    testExioBufferedPinDetect();
-    
-    /*
+    //testExioBufferedPinDetect();
     
     printf("*** Test ExioBufferedContoroller ***\r\n");
     
     // Reset MCP23S17 (初期化時にreset()が必要)
     Exio.reset();
     
+    // PinDetect
     ExioInBuffer inBufferA(&Exio, ExioPortA);
+    ExioBufferedPinDetect pinA6(&inBufferA, 6);
+    ExioBufferedPinDetect pinA7(&inBufferA, 7);
     
-    ExioBufferedDebounceIn pinA6(&inBufferA, 6);
-    ExioBufferedDebounceIn pinA7(&inBufferA, 7);
+    // assign callback functions
+    pinA6.attach_asserted(&pa6Falled);
+    pinA6.setAssertValue(0);
+    pinA7.attach_asserted(&pa7Falled);
+    pinA7.setAssertValue(0);
     
-    // Start Timers
+    // DebounceIn
+    ExioInBuffer inBufferB(&Exio, ExioPortB);
+    ExioBufferedDebounceIn inB[] = {
+        ExioBufferedDebounceIn(&inBufferB, 0),
+        ExioBufferedDebounceIn(&inBufferB, 1),
+        ExioBufferedDebounceIn(&inBufferB, 2),
+        ExioBufferedDebounceIn(&inBufferB, 3),
+        ExioBufferedDebounceIn(&inBufferB, 4),
+        ExioBufferedDebounceIn(&inBufferB, 5),
+        ExioBufferedDebounceIn(&inBufferB, 6),
+        ExioBufferedDebounceIn(&inBufferB, 7)
+    };
+    
+    // Start Timers for polling MCP23S17
     inBufferA.run(5);
-    pinA6.set_debounce_us(10000);
-    pinA7.set_debounce_us(10000);
+    inBufferB.run(10);
+    
+    // Start Timers for PinDetect
+    pinA6.setSampleFrequency(10000);
+    pinA7.setSampleFrequency(10000);
+    
+    // Start Timers for DebounceIn
+    for (int i = 0; i < 8; i++) {
+        inB[i].set_debounce_us(10000);
+        inB[i].set_debounce_us(10000);
+    }
 
     while(true) {
-        if (pinA6.read()) {
-            state = !state;
+        for (int i = 0; i < 8; i++) {
+            int va = inB[i].read();
+            printf("%d ", va);
         }
-        if (pinA7.read()) {
-            count++;
-        }
-        printf("%d %d\r\n", state, count);
+        printf(" %d %d  \r\n", state, count);
     }
-    */
 }
\ No newline at end of file