LCOV - code coverage report
Current view: top level - src/MIDI_Inputs/LEDs - NoteCCRangeLEDs.hpp (source / functions) Hit Total Coverage
Test: 90a1b9beff85a60dc6ebcea034a947a845e56960 Lines: 19 19 100.0 %
Date: 2019-11-30 15:53:32 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <AH/Settings/Warnings.hpp>
       4             : AH_DIAGNOSTIC_WERROR()
       5             : 
       6             : #include <AH/Hardware/ExtendedInputOutput/ExtendedInputOutput.hpp>
       7             : #include <MIDI_Inputs/NoteCCRange.hpp>
       8             : 
       9             : BEGIN_CS_NAMESPACE
      10             : 
      11             : template <uint8_t NumLEDs>
      12           1 : class NoteCCLED : public SimpleNoteCCValueCallback {
      13             :   public:
      14           1 :     NoteCCLED(const PinList<NumLEDs> &ledPins) : ledPins(ledPins) {}
      15             : 
      16             :     void setThreshold(uint8_t threshold) { this->threshold = threshold; }
      17             :     uint8_t getThreshold() const { return this->threshold; }
      18             : 
      19           1 :     void begin(const INoteCCValue &t) override {
      20           2 :         for (pin_t pin : ledPins)
      21           1 :             AH::ExtIO::pinMode(pin, OUTPUT);
      22           1 :         updateAll(t);
      23           1 :     }
      24             : 
      25           3 :     void update(const INoteCCValue &t, uint8_t index) override {
      26           3 :         uint8_t value = t.getValue(index);
      27           3 :         bool state = value > threshold;
      28           3 :         AH::ExtIO::digitalWrite(ledPins[index], state);
      29           3 :     }
      30             : 
      31             :   private:
      32             :     PinList<NumLEDs> ledPins;
      33           1 :     uint8_t threshold = 0x3F;
      34             : };
      35             : 
      36             : template <uint8_t RangeLen>
      37             : class NoteRangeLEDs : public GenericNoteCCRange<MIDIInputElementNote, RangeLen,
      38             :                                                 NoteCCLED<RangeLen>> {
      39             :   public:
      40             :     NoteRangeLEDs(const PinList<RangeLen> &ledPins,
      41             :                   MIDICNChannelAddress address)
      42             :         : GenericNoteCCRange<MIDIInputElementNote, RangeLen,
      43             :                              NoteCCLED<RangeLen>>{
      44             :               address,
      45             :               {ledPins},
      46             :           } {}
      47             : };
      48             : 
      49           1 : class NoteValueLED
      50             :     : public GenericNoteCCRange<MIDIInputElementNote, 1, NoteCCLED<1>> {
      51             :   public:
      52           1 :     NoteValueLED(pin_t ledPin, MIDICNChannelAddress address)
      53           1 :         : GenericNoteCCRange<MIDIInputElementNote, 1, NoteCCLED<1>>{
      54           1 :               address,
      55           1 :               {{ledPin}},
      56           2 :           } {}
      57             : };
      58             : 
      59             : using MIDINoteLED[[deprecated("Use NoteValueLED instead")]] = NoteValueLED;
      60             : 
      61             : template <uint8_t RangeLen>
      62             : class CCRangeLEDs : public GenericNoteCCRange<MIDIInputElementCC, RangeLen,
      63             :                                               NoteCCLED<RangeLen>> {
      64             :   public:
      65             :     CCRangeLEDs(const PinList<RangeLen> &ledPins, MIDICNChannelAddress address)
      66             :         : GenericNoteCCRange<MIDIInputElementCC, RangeLen, NoteCCLED<RangeLen>>{
      67             :               address,
      68             :               {ledPins},
      69             :           } {}
      70             : };
      71             : 
      72             : class CCValueLED
      73             :     : public GenericNoteCCRange<MIDIInputElementCC, 1, NoteCCLED<1>> {
      74             :   public:
      75             :     CCValueLED(pin_t ledPin, MIDICNChannelAddress address)
      76             :         : GenericNoteCCRange<MIDIInputElementCC, 1, NoteCCLED<1>>{
      77             :               address,
      78             :               {{ledPin}},
      79             :           } {}
      80             : };
      81             : 
      82             : namespace Bankable {
      83             : 
      84             : template <uint8_t RangeLen, uint8_t BankSize>
      85             : class NoteRangeLEDs : public GenericNoteCCRange<MIDIInputElementNote, RangeLen,
      86             :                                                 BankSize, NoteCCLED<RangeLen>> {
      87             :   public:
      88             :     NoteRangeLEDs(const BankConfig<BankSize> &config,
      89             :                   const PinList<RangeLen> &ledPins,
      90             :                   const MIDICNChannelAddress &address)
      91             :         : GenericNoteCCRange<MIDIInputElementNote, RangeLen, BankSize,
      92             :                              NoteCCLED<RangeLen>>{
      93             :               config,
      94             :               address,
      95             :               {ledPins},
      96             :           } {}
      97             : };
      98             : 
      99             : template <uint8_t BankSize>
     100             : class NoteValueLED : public GenericNoteCCRange<MIDIInputElementNote, 1,
     101             :                                                BankSize, NoteCCLED<1>> {
     102             :   public:
     103             :     NoteValueLED(const BankConfig<BankSize> &config, pin_t ledPin,
     104             :                  const MIDICNChannelAddress &address)
     105             :         : GenericNoteCCRange<MIDIInputElementNote, 1, BankSize, NoteCCLED<1>>{
     106             :               config,
     107             :               address,
     108             :               {{ledPin}},
     109             :           } {}
     110             : };
     111             : 
     112             : template <uint8_t BankSize>
     113             : using MIDINoteLED[[deprecated("Use NoteValueLED instead")]] =
     114             :     NoteValueLED<BankSize>;
     115             : 
     116             : template <uint8_t RangeLen, uint8_t BankSize>
     117             : class CCRangeLEDs : public GenericNoteCCRange<MIDIInputElementCC, RangeLen,
     118             :                                               BankSize, NoteCCLED<RangeLen>> {
     119             :   public:
     120             :     CCRangeLEDs(const BankConfig<BankSize> &config,
     121             :                 const PinList<RangeLen> &ledPins,
     122             :                 const MIDICNChannelAddress &address)
     123             :         : GenericNoteCCRange<MIDIInputElementCC, RangeLen, BankSize,
     124             :                              NoteCCLED<RangeLen>>{
     125             :               config,
     126             :               address,
     127             :               {ledPins},
     128             :           } {}
     129             : };
     130             : 
     131             : template <uint8_t BankSize>
     132             : class CCValueLED
     133             :     : public GenericNoteCCRange<MIDIInputElementCC, 1, BankSize, NoteCCLED<1>> {
     134             :   public:
     135             :     CCValueLED(const BankConfig<BankSize> &config, pin_t ledPin,
     136             :                const MIDICNChannelAddress &address)
     137             :         : GenericNoteCCRange<MIDIInputElementCC, 1, BankSize, NoteCCLED<1>>{
     138             :               config,
     139             :               address,
     140             :               {{ledPin}},
     141             :           } {}
     142             : };
     143             : 
     144             : } // namespace Bankable
     145             : 
     146             : END_CS_NAMESPACE
     147             : 
     148             : AH_DIAGNOSTIC_POP()

Generated by: LCOV version 1.14-5-g4ff2ed6