libraries / Mitov / Mitov_LEDBarDisplay.hon commit Added link to project report (97a3ba0)
   1////////////////////////////////////////////////////////////////////////////////
   2//                                                                            //
   3//     This software is supplied under the terms of a license agreement or    //
   4//     nondisclosure agreement with Mitov Software and may not be copied      //
   5//     or disclosed except in accordance with the terms of that agreement.    //
   6//         Copyright(c) 2002-2016 Mitov Software. All Rights Reserved.        //
   7//                                                                            //
   8////////////////////////////////////////////////////////////////////////////////
   9
  10#ifndef _MITOV_LED_BAR_DISPLAY_h
  11#define _MITOV_LED_BAR_DISPLAY_h
  12
  13#include <Mitov.h>
  14#include <Mitov_BasicDisplay.h>
  15
  16namespace Mitov
  17{
  18        template<typename T> class LEDBarBasicDisplay : public Mitov::BasicDisplay<T>
  19        {
  20                typedef Mitov::BasicDisplay<T>  inherited;
  21
  22        public:
  23                Mitov::SimpleList<OpenWire::SourcePin>  BarsOutputPins;
  24
  25        public:
  26                bool InvertedBars = false;
  27                bool SingleBar = false;
  28
  29        public:
  30                virtual void DoReceive( void *_Data ) override
  31                {
  32                        inherited::DoReceive( _Data );
  33                        UpdateDisplay();
  34                }
  35
  36        protected:
  37                virtual void UpdateDisplay() = 0;
  38
  39        protected:
  40                void DisplayValue( long AValue )
  41                {
  42                        for( int i = 0; i < BarsOutputPins.size(); ++i )
  43                        {
  44                                bool ABitValue;
  45                                if( SingleBar )
  46                                        ABitValue = ( AValue == 0 ) ^ InvertedBars;
  47
  48                                else
  49                                        ABitValue = ( AValue > 0 ) ^ InvertedBars;
  50
  51                                BarsOutputPins[ i ].Notify( &ABitValue );
  52                                --AValue;
  53                        }
  54                }
  55
  56        };
  57//---------------------------------------------------------------------------
  58        class LEDBarDisplay : public Mitov::LEDBarBasicDisplay<long>
  59        {
  60                typedef Mitov::LEDBarBasicDisplay<long> inherited;
  61
  62        protected:
  63                virtual void UpdateDisplay() override
  64                {
  65                        int AValue = (Enabled) ? FValue : 0;
  66                        DisplayValue( AValue );
  67                }
  68
  69        };
  70//---------------------------------------------------------------------------
  71        class LEDBarAnalogDisplay : public Mitov::LEDBarBasicDisplay<float>
  72        {
  73                typedef Mitov::LEDBarBasicDisplay<float>        inherited;
  74
  75        protected:
  76                virtual void UpdateDisplay() override
  77                {
  78                        int AValue;
  79                        if( Enabled )
  80                        {
  81                                if( SingleBar )
  82                                        AValue = FValue * BarsOutputPins.size();
  83
  84                                else
  85                                        AValue = FValue * BarsOutputPins.size() + 0.5;
  86                        }
  87
  88                        else
  89                                AValue = 0;
  90
  91                        DisplayValue( AValue );
  92                }
  93
  94        };
  95//---------------------------------------------------------------------------
  96}
  97
  98#endif