#pragma once #include #include BEGIN_CS_NAMESPACE template class NoteCCKPLED : public MatchingMIDIInputElement { public: using Matcher = TwoByteMIDIMatcher; using Parent = MatchingMIDIInputElement; NoteCCKPLED(pin_t ledPin, MIDIAddress address) : Parent(address), ledPin(ledPin) {} private: void handleUpdate(typename Matcher::Result match) override { PinStatus_t state = match.value >= threshold ? HIGH : LOW; AH::ExtIO::digitalWrite(ledPin, state); } public: void begin() override { AH::ExtIO::pinMode(ledPin, OUTPUT); AH::ExtIO::digitalWrite(ledPin, LOW); } void reset() override { AH::ExtIO::digitalWrite(ledPin, LOW); } uint8_t getThreshold() const { return threshold; } void setThreshold(uint8_t threshold) { this->threshold = threshold; } private: pin_t ledPin; uint8_t threshold = 0x01; }; using NoteLED = NoteCCKPLED; using CCLED = NoteCCKPLED; using KPLED = NoteCCKPLED; namespace Bankable { template class NoteCCKPLED : public NoteCCKPValue { public: using Parent = NoteCCKPValue; using Matcher = typename Parent::Matcher; NoteCCKPLED(BankConfig config, pin_t ledPin, MIDIAddress address) : Parent(config, address), ledPin(ledPin) {} protected: void handleUpdate(typename Matcher::Result match) override { bool newdirty = Parent::handleUpdateImpl(match); if (newdirty) display(); this->dirty |= newdirty; } void display() { PinStatus_t state = getValue() >= threshold ? HIGH : LOW; AH::ExtIO::digitalWrite(ledPin, state); } public: void begin() override { AH::ExtIO::pinMode(ledPin, OUTPUT); AH::ExtIO::digitalWrite(ledPin, LOW); } void reset() override { Parent::reset(); AH::ExtIO::digitalWrite(ledPin, LOW); } using Parent::getValue; uint8_t getThreshold() const { return threshold; } void setThreshold(uint8_t threshold) { this->threshold = threshold; } protected: void onBankSettingChange() override { Parent::onBankSettingChange(); display(); } private: pin_t ledPin; uint8_t threshold = 0x01; }; template using NoteLED = NoteCCKPLED; template using CCLED = NoteCCKPLED; template using KPLED = NoteCCKPLED; } // namespace Bankable END_CS_NAMESPACE