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_CONTROLLINO_RS485_h
11#define _MITOV_CONTROLLINO_RS485_h
12
13#include <Mitov.h>
14#include <Controllino.h>
15
16namespace Mitov
17{
18//---------------------------------------------------------------------------
19 class ControllinoRS485Module : public OpenWire::Component
20 {
21 typedef OpenWire::Component inherited;
22
23 public:
24 OpenWire::SinkPin TransmitInputPin;
25 OpenWire::SinkPin ReceiveInputPin;
26
27 public:
28 bool FTransmit = false;
29 bool FReceive = false;
30
31 public:
32 bool Enabled = true;
33
34 public:
35 void SetEnabled( bool AValue )
36 {
37 if( Enabled == AValue )
38 return;
39
40 Enabled = AValue;
41 if( Enabled )
42 StartModule();
43
44 else
45 StopModule();
46
47 }
48
49 protected:
50 virtual void SystemInit()
51 {
52 if( Enabled )
53 StartModule();
54
55 inherited::SystemInit();
56 }
57
58 void StopModule()
59 {
60 }
61
62 void StartModule()
63 {
64 Controllino_RS485Init();
65 Controllino_SwitchRS485DE( FTransmit );
66 Controllino_SwitchRS485RE( FReceive );
67 }
68
69 protected:
70 void DoTransmitInputPinReceive( void *_Data )
71 {
72 FTransmit = *(bool *)_Data;
73 if( ! Enabled )
74 return;
75
76 Controllino_SwitchRS485DE( FTransmit );
77 }
78
79 void DoReceiveInputPinReceive( void *_Data )
80 {
81 FReceive = *(bool *)_Data;
82 if( ! Enabled )
83 return;
84
85 Controllino_SwitchRS485RE( FReceive );
86 }
87
88 public:
89 ControllinoRS485Module()
90 {
91 TransmitInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&ControllinoRS485Module::DoTransmitInputPinReceive );
92 ReceiveInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&ControllinoRS485Module::DoReceiveInputPinReceive );
93 }
94
95 };
96}
97
98#endif