libraries / Mitov / Mitov_PulseMeter.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_PULSE_METER_h
  11#define _MITOV_PULSE_METER_h
  12
  13#include <Mitov.h>
  14
  15namespace Mitov
  16{
  17        class PulseMeter : public Mitov::CommonEnableFilter
  18        {
  19                typedef Mitov::CommonEnableFilter inherited;
  20
  21        protected:
  22                unsigned long   FStartTime = 0;
  23                bool                    FOldValue = false;
  24
  25        protected:
  26                virtual void DoReceive( void *_Data )
  27                {
  28            if( ! Enabled )
  29                                return;
  30
  31                        bool AValue = *(bool *)_Data;
  32                        if( FOldValue == AValue )
  33                                return;
  34
  35                        unsigned long ANow = micros();
  36                        FOldValue = AValue;
  37                        if( AValue )
  38                        {
  39                                FStartTime = ANow;
  40                                return;
  41                        }
  42
  43                        int APeriod = ANow - FStartTime;
  44
  45                        OutputPin.Notify( &APeriod );
  46                }
  47
  48        };
  49}
  50
  51#endif