diff --git a/lib/knob/knob b/lib/knob/knob index 7c2610c..ae5e182 100644 --- a/lib/knob/knob +++ b/lib/knob/knob @@ -19,6 +19,7 @@ class Knob { int getRotation(); void updateRotation(bool ANew, bool BNew); + void setRotation(int newRotation); void changeLimitsVolume(int newMinimum, int newMaximum); }; diff --git a/lib/knob/knob.cpp b/lib/knob/knob.cpp index db50f96..88da517 100644 --- a/lib/knob/knob.cpp +++ b/lib/knob/knob.cpp @@ -14,6 +14,11 @@ int Knob::getRotation() { return Knob::rotation; }; +void Knob::setRotation(int newRotation) { + rotation = newRotation; + rotationInternal = newRotation; +}; + void Knob::updateRotation(bool ANew, bool BNew) { if (A == ANew && B == BNew) return; // No change, do not update values @@ -75,11 +80,12 @@ void Knob::updateRotation(bool ANew, bool BNew) { } void Knob::changeLimitsVolume(int newMinimum, int newMaximum) { - if(newMaximum>maximum){ - rotation = rotation<<1; - }else if(newMaximum>1; - }else{} - minimum = newMinimum; - maximum = newMaximum; + if (newMaximum > maximum) { + rotation = rotation << 1; + } else if (newMaximum < maximum) { + rotation = rotation >> 1; + } else { + } + minimum = newMinimum; + maximum = newMaximum; }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 839906b..1838899 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -182,7 +182,8 @@ void CAN_RX_ISR() { uint8_t ISR_RX_Message[8]; uint32_t ISR_rxID; CAN_RX(ISR_rxID, ISR_RX_Message); - xQueueSendFromISR(msgInQ, ISR_RX_Message, nullptr); + if (isMainSynth) + xQueueSendFromISR(msgInQ, ISR_RX_Message, nullptr); } // Task to update activeNotes[] and currentStepSize based on received CAN message @@ -193,12 +194,15 @@ void decodeTask(void *pvParameters) { activeNotes[(RX_Message[1] - 1) * 12 + RX_Message[2]] = true; latestKey = (RX_Message[1] - 1) * 12 + RX_Message[2]; currentStepSize = stepSizes[latestKey]; - } else { // Released + } else if (RX_Message[0] == 0x52) { // Released activeNotes[(RX_Message[1] - 1) * 12 + RX_Message[2]] = false; if (latestKey == (RX_Message[1] - 1) * 12 + RX_Message[2]) { latestKey = 0; currentStepSize = stepSizes[latestKey]; // Atomic Store } + } else if (RX_Message[0] == 0x4D) { // Main Synth Announce + isMainSynth = false; + K2.setRotation(1); } } } @@ -213,6 +217,17 @@ void keyChangedSendTXMessage(uint8_t octave, uint8_t key, bool pressed) { } TX_Message[1] = octave; TX_Message[2] = key; + if (isMainSynth) { + xQueueSend(msgInQ, TX_Message, 0); + } else { + CAN_TX(canID, TX_Message); + } +} + +// +void announceMainSynth() { + uint8_t TX_Message[8] = {0}; + TX_Message[0] = 0x4D; // "M" CAN_TX(canID, TX_Message); } @@ -240,6 +255,9 @@ void scanKeysTask(void *pvParameters) { } } } + if (keyArray[5] & 0x1 && isMainSynth) { + announceMainSynth(); + } if (volumeFiner) { K3.changeLimitsVolume(0, 10); } else { @@ -294,12 +312,18 @@ void displayUpdateTask(void *pvParameters) { // Print volume indicator above knob 3 if (!volumeFiner) { - u8g2.drawXBM(116, 22, 13, 9, volumes[volume]); + u8g2.drawXBM(112, 22, 13, 9, volumes[volume]); } else { u8g2.setCursor(117, 30); u8g2.print(volume); } + if (!isMainSynth) { + u8g2.drawHLine(1, 6, 26); + u8g2.drawHLine(36, 26, 18); + u8g2.drawHLine(110, 26, 16); + } + u8g2.sendBuffer(); // transfer internal memory to the display digitalToggle(LED_BUILTIN); // Toggle LED to show display update rate } @@ -340,7 +364,7 @@ void setup() { #pragma endregion #pragma region CAN Setup msgInQ = xQueueCreate(36, 8); - CAN_Init(true); + CAN_Init(false); setCANFilter(0x123, 0x7ff); CAN_RegisterRX_ISR(CAN_RX_ISR); CAN_Start();