LCOV - code coverage report
Current view: top level - src/MIDI_Inputs/LEDs/MCU - VPotRingLEDs.hpp (source / functions) Hit Total Coverage
Test: ffed98f648fe78e7aa7bdd228474317d40dadbec Lines: 24 28 85.7 %
Date: 2022-05-28 15:22:59 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() {
      56             :         this->displayVPot(this->getState());
      57             :     }
      58             : 
      59             :   public:
      60             :     void begin() override {
      61             :         Parent::begin();
      62             :         VPotRingLEDsDriver::begin();
      63             :         updateDisplay();
      64             :     }
      65             : 
      66             :     void reset() override {
      67             :         Parent::reset();
      68             :         updateDisplay();
      69             :     }
      70             : };
      71             : 
      72             : namespace Bankable {
      73             : 
      74             : /**
      75             :  * @brief   A MIDI input element that represents a Mackie Control Universal VPot
      76             :  *          ring and displays its value using LEDs. This version can be banked.
      77             :  * 
      78             :  * @tparam  BankSize
      79             :  *          The number of banks.
      80             :  * 
      81             :  * @ingroup BankableMIDIInputElementsLEDs
      82             :  */
      83             : template <uint8_t BankSize>
      84             : class VPotRingLEDs : public VPotRing<BankSize>, public VPotRingLEDsDriver {
      85             :   public:
      86             :     using Parent = VPotRing<BankSize>;
      87             :     using Matcher = typename Parent::Matcher;
      88             : 
      89             :     /** 
      90             :      * Constructor.
      91             :      * 
      92             :      * @param   config
      93             :      *          The bank configuration to use: the bank to add this element to,
      94             :      *          and whether to change the address, channel or cable number.
      95             :      * @param   leds
      96             :      *          The pins with LEDs connected.
      97             :      * @param   track
      98             :      *          The track of the VPot. [1, 8]
      99             :      * @param   channelCN
     100             :      *          The MIDI channel [CHANNEL_1, CHANNEL_16] and Cable
     101             :      *          Number [CABLE_1, CABLE_16].
     102             :      */
     103           1 :     VPotRingLEDs(BankConfig<BankSize> config, const PinList<11> &leds,
     104             :                  uint8_t track, MIDIChannelCable channelCN = CHANNEL_1)
     105             :         : Parent(config, track, channelCN),
     106           1 :           VPotRingLEDsDriver(leds) {}
     107             : 
     108             :   protected:
     109           2 :     void handleUpdate(typename Matcher::Result match) override {
     110           2 :         bool newdirty = Parent::handleUpdateImpl(match);
     111           2 :         if (newdirty)
     112           1 :             updateDisplay();
     113           2 :         this->dirty |= newdirty;
     114           2 :     }
     115             : 
     116           3 :     void updateDisplay() {
     117           3 :         this->displayVPot(this->getState());
     118           3 :     }
     119             : 
     120             :   public:
     121           1 :     void begin() override {
     122           1 :         Parent::begin();
     123           1 :         VPotRingLEDsDriver::begin();
     124           1 :         updateDisplay();
     125           1 :     }
     126             : 
     127           0 :     void reset() override {
     128           0 :         Parent::reset();
     129           0 :         updateDisplay();
     130           0 :     }
     131             : 
     132             :   protected:
     133           1 :     void onBankSettingChange() override {
     134           1 :         Parent::onBankSettingChange();
     135           1 :         updateDisplay();
     136           1 :     }
     137             : };
     138             : 
     139             : } // namespace Bankable
     140             : 
     141             : } // namespace MCU
     142             : 
     143             : END_CS_NAMESPACE

Generated by: LCOV version 1.15