BaseMachine UI Controllerに分離
Dependencies: AverageAnalogIn PinDetect RotaryEncoder Sequence SequencerDisplay mbed-rtos mbed st7567LCD BaseMachineComon
Fork of BaseMachine_Sequencer by
Diff: main.cpp
- Revision:
- 47:f4c16d1e4207
- Parent:
- 46:0fb579ecdd77
- Child:
- 48:9cde2da0a5d3
--- a/main.cpp Fri Oct 07 10:41:48 2016 +0000 +++ b/main.cpp Fri Oct 07 13:23:01 2016 +0000 @@ -24,8 +24,9 @@ #define SEQUENCE_N (16) #define SPI1_RATE (3000000) #define SPI2_RATE (1000000) -#define POT_RESOLUTION (7) // bit -#define AIN_AVERAGE (32) // AnalogInを移動平均する要素数 +#define POT_RESOLUTION (7) // bit +#define AIN_AVERAGE (32) // AnalogInを移動平均する要素数 +#define POLLING_POTS_WAIT (20) // POT読み取りThreadのWait値(ミリ秒) enum SequencerCmd { CMD_RCV_PLAYING_STEP = 0x01, @@ -214,65 +215,6 @@ return noteData; } -void pollingPots() -{ - uint8_t pulseWidth = AinPulseWidth.read_u16() >> (16 - POT_RESOLUTION); - if (pulseWidth != oscillatorParam.pulseWidth) { - oscillatorParam.pulseWidth = pulseWidth; - SpiSendParams(CMD_PULSE_WIDTH, pulseWidth); - isDirty = true; - } - - uint8_t cutoff = AinCutOff.read_u16() >> (16 - POT_RESOLUTION); - if (cutoff != filterParam.cutoff) { - filterParam.cutoff = cutoff; - SpiSendParams(CMD_CUTOFF, cutoff); - isDirty = true; - } - - uint8_t resonance = AinResonance.read_u16() >> (16 - POT_RESOLUTION); - if (resonance != filterParam.resonance) { - filterParam.resonance = resonance; - SpiSendParams(CMD_RESONANCE, resonance); - isDirty = true; - } - - uint8_t level = AinLevel.read_u16() >> (16 - POT_RESOLUTION); - if (level != envelopeParam.level) { - envelopeParam.level = level; - SpiSendParams(CMD_LEVEL, level); - isDirty = true; - } - - uint8_t duration = AinDuration.read_u16() >> (16 - POT_RESOLUTION); - if (duration != envelopeParam.duration) { - envelopeParam.duration = duration; - SpiSendParams(CMD_DURATION, duration); - isDirty = true; - } - - uint8_t decay = AinDecay.read_u16() >> (16 - POT_RESOLUTION); - if (decay != envelopeParam.decay) { - envelopeParam.decay = decay; - SpiSendParams(CMD_DECAY, decay); - isDirty = true; - } - - uint8_t sustain = AinSustain.read_u16() >> (16 - POT_RESOLUTION); - if (sustain != envelopeParam.sustain) { - envelopeParam.sustain = sustain; - SpiSendParams(CMD_SUSTAIN, sustain); - isDirty = true; - } - - uint8_t _accentLevel = AinAccentLevel.read_u16() >> (16 - POT_RESOLUTION); - if (_accentLevel != accentLevel) { - accentLevel = _accentLevel; - SpiSendParams(CMD_ACCENT_LEVEL, accentLevel); - isDirty = true; - } -} - void pollingRotEncs() { int _bpm = RotEncBpm.getVal(); @@ -512,6 +454,74 @@ } //------------------------------------------------------------------------ +// Threads +//------------------------------------------------------------------------ + +void pollingPots(void const *args) +{ + for (;;) + { + uint8_t pulseWidth = AinPulseWidth.read_u16() >> (16 - POT_RESOLUTION); + if (pulseWidth != oscillatorParam.pulseWidth) { + oscillatorParam.pulseWidth = pulseWidth; + SpiSendParams(CMD_PULSE_WIDTH, pulseWidth); + isDirty = true; + } + + uint8_t cutoff = AinCutOff.read_u16() >> (16 - POT_RESOLUTION); + if (cutoff != filterParam.cutoff) { + filterParam.cutoff = cutoff; + SpiSendParams(CMD_CUTOFF, cutoff); + isDirty = true; + } + + uint8_t resonance = AinResonance.read_u16() >> (16 - POT_RESOLUTION); + if (resonance != filterParam.resonance) { + filterParam.resonance = resonance; + SpiSendParams(CMD_RESONANCE, resonance); + isDirty = true; + } + + uint8_t level = AinLevel.read_u16() >> (16 - POT_RESOLUTION); + if (level != envelopeParam.level) { + envelopeParam.level = level; + SpiSendParams(CMD_LEVEL, level); + isDirty = true; + } + + uint8_t duration = AinDuration.read_u16() >> (16 - POT_RESOLUTION); + if (duration != envelopeParam.duration) { + envelopeParam.duration = duration; + SpiSendParams(CMD_DURATION, duration); + isDirty = true; + } + + uint8_t decay = AinDecay.read_u16() >> (16 - POT_RESOLUTION); + if (decay != envelopeParam.decay) { + envelopeParam.decay = decay; + SpiSendParams(CMD_DECAY, decay); + isDirty = true; + } + + uint8_t sustain = AinSustain.read_u16() >> (16 - POT_RESOLUTION); + if (sustain != envelopeParam.sustain) { + envelopeParam.sustain = sustain; + SpiSendParams(CMD_SUSTAIN, sustain); + isDirty = true; + } + + uint8_t _accentLevel = AinAccentLevel.read_u16() >> (16 - POT_RESOLUTION); + if (_accentLevel != accentLevel) { + accentLevel = _accentLevel; + SpiSendParams(CMD_ACCENT_LEVEL, accentLevel); + isDirty = true; + } + + Thread::wait(POLLING_POTS_WAIT); + } +} + +//------------------------------------------------------------------------ // Main routine //------------------------------------------------------------------------ int main() @@ -591,13 +601,20 @@ RotEncPitch.setVal(sequences[0].getPitch()); //-------------------------------------------------------------------- + // Initialize threads + // + Thread thPollingPots(pollingPots); + + //-------------------------------------------------------------------- // Main loop // for (;;) { // Polling Devices + /* if (UImode != 2) { pollingPots(); } + */ pollingRotEncs(); pollingPins();