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_BUTTON_h
11#define _MITOV_BUTTON_h
12
13#include <Mitov.h>
14
15namespace Mitov
16{
17 class Button : public Mitov::CommonFilter
18 {
19 typedef Mitov::CommonFilter inherited;
20
21 protected:
22 unsigned long FLastTime = 0;
23 bool FLastValue = false;
24 bool FValue = false;
25
26 public:
27 uint32_t DebounceInterval = 50;
28
29 protected:
30 virtual void DoReceive( void *_Data )
31 {
32 bool AValue = *( bool *)_Data;
33 if( AValue != FLastValue )
34 FLastTime = millis();
35
36 FLastValue = AValue;
37 }
38
39 virtual void SystemLoopBegin( unsigned long currentMicros )
40 {
41 if( FValue != FLastValue )
42 if( millis() - FLastTime > DebounceInterval )
43 {
44 FValue = FLastValue;
45 OutputPin.Notify( &FValue );
46 }
47
48 inherited::SystemLoopBegin( currentMicros );
49 }
50
51 };
52}
53
54#endif