LCOV - code coverage report
Current view: top level - src/MIDI_Inputs/LEDs/MCU - VPotRingLEDs.hpp (source / functions) Hit Total Coverage
Test: 3a807a259ebe0769dd942f7f612dca5273937539 Lines: 22 26 84.6 %
Date: 2024-03-24 17:16:54 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <AH/Hardware/LEDs/LEDs.hpp>
       4             : #include <MIDI_Inputs/MCU/VPotRing.hpp>
       5             : 
       6             : BEGIN_CS_NAMESPACE
       7             : 
       8             : namespace MCU {
       9             : 
      10             : class VPotRingLEDsDriver : public AH::LEDs<11> {
      11             :   public:
      12           1 :     VPotRingLEDsDriver(const AH::LEDs<11> &leds) : AH::LEDs<11>(leds) {}
      13             : 
      14           3 :     void displayVPot(VPotState v) {
      15           3 :         this->displayRange(v.getStartOn(), v.getStartOff());
      16           3 :     }
      17             : };
      18             : 
      19             : // -------------------------------------------------------------------------- //
      20             : 
      21             : /**
      22             :  * @brief   A MIDI input element that represents a Mackie Control Universal VPot
      23             :  *          ring and displays it using LEDs.
      24             :  * 
      25             :  * @ingroup midi-input-elements-leds
      26             :  */
      27             : class VPotRingLEDs : public VPotRing, public VPotRingLEDsDriver {
      28             :   public:
      29             :     using Parent = VPotRing;
      30             :     using Matcher = Parent::Matcher;
      31             : 
      32             :     /** 
      33             :      * Constructor.
      34             :      * 
      35             :      * @param   leds
      36             :      *          The pins with LEDs connected.
      37             :      * @param   track
      38             :      *          The track of the VPot. [1, 8]
      39             :      * @param   channelCN
      40             :      *          The MIDI channel [Channel_1, Channel_16] and Cable
      41             :      *          Number [Cable_1, Cable_16].
      42             :      */
      43             :     VPotRingLEDs(const PinList<11> &leds, uint8_t track,
      44             :                  MIDIChannelCable channelCN = Channel_1)
      45             :         : Parent(track, channelCN), VPotRingLEDsDriver(leds) {}
      46             : 
      47             :   protected:
      48             :     void handleUpdate(typename Matcher::Result match) override {
      49             :         bool newdirty = Parent::handleUpdateImpl(match);
      50             :         if (newdirty)
      51             :             updateDisplay();
      52             :         this->dirty |= newdirty;
      53             :     }
      54             : 
      55             :     void updateDisplay() { this->displayVPot(this->getState()); }
      56             : 
      57             :   public:
      58             :     void begin() override {
      59             :         Parent::begin();
      60             :         VPotRingLEDsDriver::begin();
      61             :         updateDisplay();
      62             :     }
      63             : 
      64             :     void reset() override {
      65             :         Parent::reset();
      66             :         updateDisplay();
      67             :     }
      68             : };
      69             : 
      70             : namespace Bankable {
      71             : 
      72             : /**
      73             :  * @brief   A MIDI input element that represents a Mackie Control Universal VPot
      74             :  *          ring and displays its value using LEDs. This version can be banked.
      75             :  * 
      76             :  * @tparam  BankSize
      77             :  *          The number of banks.
      78             :  * 
      79             :  * @ingroup BankableMIDIInputElementsLEDs
      80             :  */
      81             : template <uint8_t BankSize>
      82             : class VPotRingLEDs : public VPotRing<BankSize>, public VPotRingLEDsDriver {
      83             :   public:
      84             :     using Parent = VPotRing<BankSize>;
      85             :     using Matcher = typename Parent::Matcher;
      86             : 
      87             :     /** 
      88             :      * Constructor.
      89             :      * 
      90             :      * @param   config
      91             :      *          The bank configuration to use: the bank to add this element to,
      92             :      *          and whether to change the address, channel or cable number.
      93             :      * @param   leds
      94             :      *          The pins with LEDs connected.
      95             :      * @param   track
      96             :      *          The track of the VPot. [1, 8]
      97             :      * @param   channelCN
      98             :      *          The MIDI channel [Channel_1, Channel_16] and Cable
      99             :      *          Number [Cable_1, Cable_16].
     100             :      */
     101           1 :     VPotRingLEDs(BankConfig<BankSize> config, const PinList<11> &leds,
     102             :                  uint8_t track, MIDIChannelCable channelCN = Channel_1)
     103           1 :         : Parent(config, track, channelCN), VPotRingLEDsDriver(leds) {}
     104             : 
     105             :   protected:
     106           2 :     void handleUpdate(typename Matcher::Result match) override {
     107           2 :         bool newdirty = Parent::handleUpdateImpl(match);
     108           2 :         if (newdirty)
     109           1 :             updateDisplay();
     110           2 :         this->dirty |= newdirty;
     111           2 :     }
     112             : 
     113           3 :     void updateDisplay() { this->displayVPot(this->getState()); }
     114             : 
     115             :   public:
     116           1 :     void begin() override {
     117           1 :         Parent::begin();
     118           1 :         VPotRingLEDsDriver::begin();
     119           1 :         updateDisplay();
     120           1 :     }
     121             : 
     122           0 :     void reset() override {
     123           0 :         Parent::reset();
     124           0 :         updateDisplay();
     125           0 :     }
     126             : 
     127             :   protected:
     128           1 :     void onBankSettingChange() override {
     129           1 :         Parent::onBankSettingChange();
     130           1 :         updateDisplay();
     131           1 :     }
     132             : };
     133             : 
     134             : } // namespace Bankable
     135             : 
     136             : } // namespace MCU
     137             : 
     138             : END_CS_NAMESPACE

Generated by: LCOV version 1.15