BaseMachine UI Controllerに分離

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

Fork of BaseMachine_Sequencer by Ryo Od

Revision:
19:241a4b355413
Parent:
18:309f794eba74
Child:
20:00d3b6ace8c7
--- a/main.cpp	Tue Aug 23 10:49:31 2016 +0000
+++ b/main.cpp	Tue Aug 23 11:20:39 2016 +0000
@@ -10,6 +10,7 @@
 #include "rtos.h"
 #include "st7565LCD.h"
 #include "PinDetect.h"
+#include "AverageAnalogIn.h"
 
 #define UART_TRACE  (0)
 #include "SpiSequenceSender.h"
@@ -39,18 +40,19 @@
 // Devices
 //
 //SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
-//SPI spiMaster(PA_7, PA_6, PA_5);
-SPI spiMaster(SPI_MOSI, SPI_MISO, SPI_SCK);
+SPI spiMaster(PA_7, PA_6, PA_5);
 
 //ST7565(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName a0);
 ST7565 gLCD(PB_15, PB_13, PB_12, PB_2, PB_1);
 
-//AnalogIn levelIn(A0);
-AnalogIn durationIn(A2);
-AnalogIn decayIn(A1);
-AnalogIn sustainIn(A0);
-AnalogIn cutoffIn(A3);
-AnalogIn resonanceIn(A4);
+AverageAnalogIn AinPulseWidth(PC_2);
+AverageAnalogIn AinCutOff(PB_0);
+AverageAnalogIn AinResonance(PC_1);
+AverageAnalogIn AinEnvMod(PC_3);
+AverageAnalogIn AinLevel(PC_0);
+AverageAnalogIn AinDuration(PA_4);
+AverageAnalogIn AinDecay(PA_1);
+AverageAnalogIn AinSustain(PA_0);
 
 PinDetect PinWaveShape(PD_2, PullUp);
 PinDetect PinModNumber(PC_11, PullUp);
@@ -93,13 +95,17 @@
 // とりあえずの変数(後でClassのメンバ変数に格納)
 #define MOD_NUMBER_MAX 1
 volatile int modNumber = 0;
+/*
 volatile uint8_t cutOff;
 volatile uint8_t resonance;
+*/
 volatile uint8_t envMod;
+/*
 volatile uint8_t level;
 volatile uint8_t duration;
 volatile uint8_t decay;
 volatile uint8_t sustain;
+*/
 
 //------------------------------------------------------------------------
 // Callback functions
@@ -170,6 +176,28 @@
 //------------------------------------------------------------------------
 // Functions
 //------------------------------------------------------------------------
+void pollingPots()
+{
+    filterController.setCutoff(AinCutOff.read_u16() >> 8);
+    filterController.setResonance(AinResonance.read_u16() >> 8);
+    
+    //envelope.setLevel(AinLevel.read_u16() >> 4);
+    envelope.setLevel(4095);
+    envelope.setDuration(AinDuration.read() * envelopeLength);
+    envelope.setDecay(AinDecay.read() * envelopeLength);
+    envelope.setSustain(AinSustain.read() * 4095);
+/*    
+    //pulseWidth = AinPulseWidth.read_u16() >> 8;
+    cutOff     = AinCutOff.read_u16()     >> 8;
+    resonance  = AinResonance.read_u16()  >> 8;
+    //envMod     = AinEnvMod.read_u16()     >> 8;
+    //level      = AinLevel.read_u16()      >> 8;
+    duration   = AinDuration.read_u16()   >> 8;
+    decay      = AinDecay.read_u16()      >> 8;
+    sustain    = AinSustain.read_u16()    >> 8;
+*/
+}
+
 void pollingPins()
 {
     if (pinFlag & bWaveShape) {
@@ -284,13 +312,13 @@
     gLCD.drawstring(64, col++, buff);
     
     col = 2;
-    sprintf(buff, "PW%3d CO%3d", sequenceSender.getPulseWidth(), cutOff);
+    sprintf(buff, "PW%3d CO%3d", sequenceSender.getPulseWidth(), filterController.getCutoff());
     gLCD.drawstring(60, col++, buff);
-    sprintf(buff, "RS%3d EV%3d", resonance, envMod);
+    sprintf(buff, "RS%3d EV%3d", filterController.getResonance(), envMod);
     gLCD.drawstring(60, col++, buff);
-    sprintf(buff, "LV%3d DR%3d", level, duration);
+    sprintf(buff, "LV%3d DR%3d", envelope.getLevel(), envelope.getDuration());
     gLCD.drawstring(60, col++, buff);
-    sprintf(buff, "DC%3d ST%3d", decay, sustain);
+    sprintf(buff, "DC%3d ST%3d", envelope.getDecay(), envelope.getSustain());
     gLCD.drawstring(60, col++, buff);
 
     gLCD.display();
@@ -359,6 +387,7 @@
     Sequence::setBaseNoteNumber(baseNoteNumber);
     sequenceSender.setBpm(bpm);
     
+    // Initialize sequences
     for (int i = 0; i < SEQUENCE_N; i++) {
         Sequence& seq = sequenceSender.getSequences()[i];
         seq.setPitch(pitch[i]);
@@ -375,6 +404,7 @@
     
     for (;;) {
         pollingPins();
+        pollingPots();
 #if 0        
         /*
         sequenceSender.setPulseWidth(sequenceSender.getPulseWidth() + 4);