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_BASIC_RTC_h
11#define _MITOV_BASIC_RTC_h
12
13#include <Mitov.h>
14
15namespace Mitov
16{
17//---------------------------------------------------------------------------
18 class BasicRTC : public Mitov::CommonSource, public Mitov::ClockingSupport
19 {
20 typedef Mitov::CommonSource inherited;
21
22 public:
23 OpenWire::SinkPin SetInputPin;
24
25 protected:
26 virtual void DoSetReceive( void *_Data ) = 0;
27 virtual void ReadTime() = 0;
28
29 virtual void DoClockReceive( void *_Data ) override
30 {
31 ReadTime();
32 }
33
34 protected:
35 virtual void SystemLoopBegin( unsigned long currentMicros ) override
36 {
37 if( ! ClockInputPin.IsConnected() )
38 ReadTime();
39
40 inherited::SystemLoopBegin( currentMicros );
41 }
42
43 public:
44 BasicRTC()
45 {
46 SetInputPin.SetCallback( MAKE_CALLBACK( BasicRTC::DoSetReceive ));
47 }
48
49 };
50//---------------------------------------------------------------------------
51 class BasicHaltRTC : public BasicRTC
52 {
53 typedef BasicRTC inherited;
54
55 public:
56 bool Halt = false;
57
58 public:
59 void SetHalt( bool AValue )
60 {
61 if( Halt == AValue )
62 return;
63
64 Halt = AValue;
65 UpdateHalt();
66 }
67
68 protected:
69 virtual void UpdateHalt() = 0;
70
71 };
72//---------------------------------------------------------------------------
73}
74
75#endif