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