BaseMachine UI Controllerに分離

Dependencies:   AverageAnalogIn PinDetect RotaryEncoder Sequence SequencerDisplay mbed-rtos mbed st7567LCD BaseMachineComon

Fork of BaseMachine_Sequencer by Ryo Od

Revision:
49:22e651444533
Parent:
48:9cde2da0a5d3
Child:
50:0a06df15c784
--- a/main.cpp	Mon Oct 10 13:48:29 2016 +0000
+++ b/main.cpp	Mon Oct 10 17:38:37 2016 +0000
@@ -19,7 +19,7 @@
 #include "ST7565_SequencerDisplay.h"
 
 #define TITLE_STR1  ("BaseMachine UI Controller")
-#define TITLE_STR2  ("20161007")
+#define TITLE_STR2  ("20161011")
 
 #define SEQUENCE_N  (16)
 #define SPI1_RATE   (3000000)
@@ -191,6 +191,18 @@
 //------------------------------------------------------------------------
 // Functions
 //------------------------------------------------------------------------
+uint8_t getNoteData(uint8_t step)
+{
+    uint8_t noteData = 0;
+    
+    noteData |= (step << 4);
+    noteData |= (sequences[step].isAccent() ? 4 : 0);
+    noteData |= (sequences[step].isTie()    ? 2 : 0);
+    noteData |= (sequences[step].isNoteOn() ? 1 : 0);
+    
+    return noteData;
+}
+
 uint16_t SpiSendParams(uint8_t cmd, uint8_t data)
 {
     uint16_t sendVal = ((uint16_t)cmd << 8) | data;
@@ -203,18 +215,31 @@
     return recievedVal;
 }
 
-uint8_t getNoteData(uint8_t step)
+uint16_t SpiSendAllParams()
 {
-    uint8_t noteData = 0;
+    SpiSendParams(CMD_BPM, bpm);
+    SpiSendParams(CMD_ACCENT_LEVEL, accentLevel);
+    SpiSendParams(CMD_WAVE_SHAPE , oscillatorParam.waveShape);
+    SpiSendParams(CMD_PULSE_WIDTH, oscillatorParam.pulseWidth);
+    SpiSendParams(CMD_CUTOFF, filterParam.cutoff);
+    SpiSendParams(CMD_RESONANCE, filterParam.resonance);
+    SpiSendParams(CMD_LEVEL, envelopeParam.level);
+    SpiSendParams(CMD_DURATION, envelopeParam.duration);
+    SpiSendParams(CMD_DECAY, envelopeParam.decay);
+    SpiSendParams(CMD_SUSTAIN, envelopeParam.sustain);
+
+    for (int i = 0; i < SEQUENCE_N; i++) {
+        SpiSendParams(CMD_NOTE, getNoteData(i));
+        SpiSendParams(CMD_PITCH, sequences[i].getPitch());
+    }
+
+    uint16_t retVal = SpiSendParams(CMD_RCV_PLAYING_STEP, 0xaa);   // Send dummy data
     
-    noteData |= (step << 4);
-    noteData |= (sequences[step].isAccent() ? 4 : 0);
-    noteData |= (sequences[step].isTie()    ? 2 : 0);
-    noteData |= (sequences[step].isNoteOn() ? 1 : 0);
-    
-    return noteData;
+    return retVal;
 }
 
+
+
 void pollingRotEncs()
 {
     int _bpm = RotEncBpm.getVal();
@@ -604,6 +629,12 @@
     // Initialize threads
     //
     Thread thPollingPots(pollingPots);
+
+    //--------------------------------------------------------------------
+    // Synchronize with Slave
+    //
+    Thread::wait(100);
+    SpiSendAllParams();
     
     //--------------------------------------------------------------------
     // Main loop