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_RC_SERVO_METER_h
11#define _MITOV_RC_SERVO_METER_h
12
13#include <Mitov.h>
14
15namespace Mitov
16{
17 class RCServoMeter : 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 ) override
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 float APeriod = ANow - FStartTime;
44 float AFloatValue = MitovMin( ( APeriod - 1000 ) / 1000, 1 );
45
46 OutputPin.Notify( &AFloatValue );
47 }
48
49 };
50}
51
52#endif