BaseMachine UI Controllerに分離

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

Fork of BaseMachine_Sequencer by Ryo Od

Revision:
16:b0419e3c9079
Parent:
15:9813d8eaf57e
Child:
17:557658db3e81
--- a/main.cpp	Tue Aug 23 09:45:37 2016 +0000
+++ b/main.cpp	Tue Aug 23 10:02:18 2016 +0000
@@ -8,6 +8,7 @@
 
 #include "mbed.h"
 #include "rtos.h"
+#include "st7565LCD.h"
 
 #define UART_TRACE  (0)
 #include "SpiSequenceSender.h"
@@ -15,6 +16,9 @@
 #include "SpiAmpController.h"
 #include "SpiFilterController.h"
 
+#define TITLE_STR1  ("BaseMachine Sequencer")
+#define TITLE_STR2  ("20160823")
+
 #define SEQUENCE_N  (16)
 #define SPI_RATE    (8000000)
 
@@ -30,6 +34,15 @@
 const int pitch[SEQUENCE_N]  = { 9, 7, 3, 0, 0, 3, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 };
 const int tie[SEQUENCE_N]    = { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 };
 
+// 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);
+
+//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);
@@ -37,10 +50,10 @@
 AnalogIn cutoffIn(A3);
 AnalogIn resonanceIn(A4);
 
-SPI spiMaster(SPI_MOSI, SPI_MISO, SPI_SCK);
-
-Sequence sequence[SEQUENCE_N];
-SpiSequenceSender sequenceSender(&spiMaster, D9, sequence, SEQUENCE_N, samplingPeriod, bpm);
+// Grobal Variables
+//
+Sequence sequences[SEQUENCE_N];
+SpiSequenceSender sequenceSender(&spiMaster, D9, sequences, SEQUENCE_N, samplingPeriod, bpm);
 
 Envelope envelope(4095, envelopeLength, envelopeLength*3/4, envelopeLength/2, 2047);
 EnvelopeGenerator envelopeGenerator;
@@ -48,7 +61,37 @@
 
 SpiFilterController filterController(&spiMaster, D10);
 
-void callbackFunction(int ticks)
+volatile int currentStep = 0;
+volatile bool isRunning = false;
+volatile bool isDirty = false;
+volatile uint8_t pinFlag = 0x00;
+
+enum PinBit {
+    bWaveShape  = 0x01,
+    bModNumber  = 0x02,
+    bOctaveUp   = 0x04,
+    bOctaveDown = 0x08,
+    bNoteOnOff  = 0x10,
+    bTie        = 0x20,
+    bAccent     = 0x40,
+    bRunStop    = 0x80
+};
+
+// とりあえずの変数(後で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
+//------------------------------------------------------------------------
+void updateFunction(int ticks)
 {
     if (ticks == 0) {
         envelopeGenerator.init(envelope);
@@ -65,11 +108,71 @@
     filterController.outDcf();
 }
 
+
+//------------------------------------------------------------------------
+// Functions
+//------------------------------------------------------------------------
+void dumpToLCD()
+{
+    char buff[64];
+    int col = 0;
+    
+    gLCD.clear();
+
+    sprintf(buff, "Run: %d", isRunning);
+    gLCD.drawstring(0, col++, buff);
+    sprintf(buff, "BPM: %d", sequenceSender.getBpm());
+    gLCD.drawstring(0, col++, buff);
+
+    sprintf(buff, "Step: %d", currentStep);
+    gLCD.drawstring(0, col++, buff);
+    sprintf(buff, "NoteOn: %d", sequences[currentStep].isNoteOn());
+    gLCD.drawstring(0, col++, buff);
+    sprintf(buff, "Pitch: %d", sequences[currentStep].getPitch());
+    gLCD.drawstring(0, col++, buff);
+    sprintf(buff, "Octave: %d", sequences[currentStep].getOctave());
+    gLCD.drawstring(0, col++, buff);
+    sprintf(buff, "Tie: %d", sequences[currentStep].isTie());
+    gLCD.drawstring(0, col++, buff);
+    sprintf(buff, "Accent: %d", sequences[currentStep].isAccent());
+    gLCD.drawstring(0, col++, buff);
+    
+    col = 0;
+    sprintf(buff, "WavS: %d", sequenceSender.getWaveShape());
+    gLCD.drawstring(64, col++, buff);
+    sprintf(buff, "ModN: %d", modNumber);
+    gLCD.drawstring(64, col++, buff);
+    
+    col = 2;
+    sprintf(buff, "PW%3d CO%3d", sequenceSender.getPulseWidth(), cutOff);
+    gLCD.drawstring(60, col++, buff);
+    sprintf(buff, "RS%3d EV%3d", resonance, envMod);
+    gLCD.drawstring(60, col++, buff);
+    sprintf(buff, "LV%3d DR%3d", level, duration);
+    gLCD.drawstring(60, col++, buff);
+    sprintf(buff, "DC%3d ST%3d", decay, sustain);
+    gLCD.drawstring(60, col++, buff);
+
+    gLCD.display();
+}
+
+//------------------------------------------------------------------------
+// Main routine
+//------------------------------------------------------------------------
 int main()
 {
+    // Setup Devices
+    //
     spiMaster.format(8, 0);
     spiMaster.frequency(SPI_RATE);
     
+    gLCD.begin(0x12);
+    gLCD.clear();
+    gLCD.drawstring(0, 0, TITLE_STR1);
+    gLCD.drawstring(0, 1, TITLE_STR2);
+    gLCD.display();
+    Thread::wait(1000);
+    
     // Test SequencerSender Run
     //
     Sequence::setBaseNoteNumber(baseNoteNumber);
@@ -85,7 +188,7 @@
     
     envelopeGenerator.init(envelope);
 
-    sequenceSender.attachUpdate(&callbackFunction);
+    sequenceSender.attachUpdate(&updateFunction);
     sequenceSender.setWaveShape(waveShape);
     sequenceSender.run(0);
     
@@ -116,5 +219,7 @@
             envelope.getSustain()
         );
         #endif
+        
+        //dumpToLCD();
     }
 }