Integrated version

Revision:
5:c3ed523c0330
Parent:
4:0a55042fa86c
Child:
6:5ef23727ce6a
--- a/BaseMachineUIController.h	Wed Nov 09 08:06:37 2016 +0000
+++ b/BaseMachineUIController.h	Mon Nov 14 05:48:48 2016 +0000
@@ -17,6 +17,7 @@
 #include "PinDetect.h"
 #include "RotaryEncoder.h"
 #include "AverageAnalogIn.h"
+#include "ExioBufferedDebounceIn.h"
 
 #include "Sequence.h"
 #include "ST7565_SequencerDisplay.h"
@@ -30,7 +31,7 @@
 const int octaveMax = 2;
 const int octaveMin = -2;
 const int waveShapeMax = 1;
-const int UImodeMax = 2;
+const int UImodeMax = 3;
 
 struct OscillatorParam {
     uint8_t waveShape;
@@ -112,6 +113,16 @@
         PinTie        = new PinDetect(PC_6, PullUp);
         PinAccent     = new PinDetect(PC_8, PullUp);
         PinRunStop    = new PinDetect(PC_9, PullUp);
+        
+        Spi3 = new SPI(PC_12, PC_11, PC_10);    // SPI3 mosi, miso, sclk;
+        // ExioMcp23s17(int hardwareaddress, SPI& spi, PinName nCs, PinName nReset);
+        Exio = new ExioMcp23s17(0x00, *Spi3, PD_2, PA_13);
+        Exio->reset();
+
+        ExioInBufferB = new ExioInBuffer(Exio, ExioPortB);
+        for (int i = 0; i < 8; i++) {
+            ExioIn[i] = new ExioBufferedDebounceIn(ExioInBufferB, i);
+        }
 
         //--------------------------------------------------------------------
         // Setup Devices
@@ -159,6 +170,11 @@
         PinRunStop->attach_asserted(this, &BaseMachineUIController::swRunStopPressed);
         PinRunStop->setAssertValue(0);
         PinRunStop->setSampleFrequency();
+        
+        ExioInBufferB->run(10);
+        for (int i = 0; i < 8; i++) {
+            ExioIn[i]->set_debounce_us(10000);
+        }
 
         //--------------------------------------------------------------------
         // Initialize objects
@@ -202,6 +218,11 @@
         delete PinTie;
         delete PinAccent;
         delete PinRunStop;
+        
+        delete[] ExioIn;
+        delete ExioInBufferB;
+        delete Exio;
+        delete Spi3;
     }
     
     void getSequences(Sequence (*pSequences)[SEQUENCE_N]) {
@@ -231,6 +252,7 @@
     void update() {
         pollingRotEncs();
         pollingPots();
+        pollingExio();
 
         switch (UImode) {
             case 0:
@@ -249,11 +271,19 @@
             case 2:
                 dumpToLCD01();
                 break;
+            case 3:
+                dumpToLCD02();
+                break;
         }
     }
 
 private:
     ST7565* gLCD;
+    
+    SPI* Spi3;
+    ExioMcp23s17* Exio;
+    ExioInBuffer* ExioInBufferB;
+    ExioBufferedDebounceIn* ExioIn[8];
 
     AverageAnalogIn* AinPulseWidth;
     AverageAnalogIn* AinCutOff;
@@ -287,6 +317,7 @@
     
     uint8_t bpm;
     uint8_t accentLevel;
+    uint8_t stepPattern;
 
     int editingStep;
     int playingStep;
@@ -473,6 +504,16 @@
         }
     }
 
+    void pollingExio()
+    {
+        stepPattern = 0;
+        for (int i = 0; i < 8; i++) {
+            if (ExioIn[i]->read()) {
+                stepPattern |= (1 << i);
+            }
+        }
+    }
+    
     void dumpToLCD00() {
         char buff[64];
         int col = 0;
@@ -505,7 +546,8 @@
         gLCD->display();
     }
 
-    void dumpToLCD01() {
+    void dumpToLCD01()
+    {
         char buff[64];
 
         gLCD->clear();
@@ -529,6 +571,18 @@
 
         gLCD->display();
     }
+    
+    void dumpToLCD02()
+    {
+        char buff[64];
+
+        gLCD->clear();
+
+        sprintf(buff, "stepPattern %d", stepPattern);
+        gLCD->drawstring(0, 0, buff);
+        
+        gLCD->display();
+    }
 };
 
 #endif //_UICONTROLLER_H_