forked from FrenchiDotNet/FrameWork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HVAC.cs
253 lines (211 loc) · 7.46 KB
/
HVAC.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace FrameWork {
/**
* Class: HVAC
* @author: Ryan French
* @version: 1.3a
* Description: Class for storing details and control functions for an individual HVAC zone.
*/
public class HVAC {
//===================// Members //===================//
public ushort id;
public string name;
public HVACControlType controlType;
public HVACControlType fanOrPower;
//public bool hasFanModeControl;
public bool hasFanSpeedControl;
public bool powerIsOn;
public ushort currentSetpointTemp;
public ushort currentAmbientTemp;
public string currentSystemMode;
public string currentFanMode;
public string currentFanSpeed;
public bool coolCallActive;
public bool heatCallActive;
public bool fanCallActive;
// Delegates for sending commands to hardware via S+
public DelegateUshort2 TriggerSendCommand { get; set; }
// Delegates for sending feedback to subscribed Interfaces
public delegate void DelegateHVACFbUpdate(ushort id, HVACCommand action, ushort state);
public event DelegateHVACFbUpdate UpdateEvent;
//===================// Constructor //===================//
public HVAC() {
// Set empty values to be populated by S+
id = 0;
name = "";
controlType = 0;
}
//===================// Methods //===================//
/**
* Method: CreateHVAC
* Access: public
* Description: Populate object with values passed from S+
*/
public void CreateHVAC(ushort _id, string _name, ushort _controlType, ushort _fanOrPower, ushort _hasFanSpeedControl) {
this.id = _id;
this.name = _name;
this.controlType = (HVACControlType)_controlType;
this.fanOrPower = (HVACControlType)_fanOrPower;
//this.hasFanModeControl = _hasFanModeControl == 1 ? true : false;
this.hasFanSpeedControl = _hasFanSpeedControl == 1 ? true : false;
}
/**
* Method: FeedbackEvent
* Access: public
* Description: Receive hardware feedback from S+, store in variable, and push value to subscribed Interfaces via event
*/
public void FeedbackEvent(ushort _action, ushort _state) {
HVACCommand act = (HVACCommand)_action;
switch (act) {
case HVACCommand.SystemMode_Off_Fb:
if (_state == 1)
currentSystemMode = "Off";
break;
case HVACCommand.SystemMode_Cool_Fb:
if (_state == 1)
currentSystemMode = "Cool";
break;
case HVACCommand.SystemMode_Heat_Fb:
if (_state == 1)
currentSystemMode = "Heat";
break;
case HVACCommand.SystemMode_Auto_Fb:
if (_state == 1)
currentSystemMode = "Auto";
break;
case HVACCommand.FanMode_On_Fb:
if (_state == 1)
currentFanMode = "On";
break;
case HVACCommand.FanMode_Auto_Fb:
if (_state == 1)
currentFanMode = "Auto";
break;
case HVACCommand.FanSpeed_Low_Fb:
if (_state == 1)
currentFanSpeed = "Low";
break;
case HVACCommand.FanSpeed_Medium_Fb:
if (_state == 1)
currentFanSpeed = "Medium";
break;
case HVACCommand.FanSpeed_High_Fb:
if (_state == 1)
currentFanSpeed = "High";
break;
case HVACCommand.FanSpeed_Max_Fb:
if (_state == 1)
currentFanSpeed = "Max";
break;
case HVACCommand.CoolCall_Fb:
coolCallActive = _state == 1 ? true : false;
break;
case HVACCommand.HeatCall_Fb:
heatCallActive = _state == 1 ? true : false;
break;
case HVACCommand.FanCall_Fb:
fanCallActive = _state == 1 ? true : false;
break;
case HVACCommand.TempSetpoint:
currentSetpointTemp = _state;
break;
case HVACCommand.TempAmbient:
currentAmbientTemp = _state;
break;
case HVACCommand.Power_On_Fb:
powerIsOn = true;
break;
case HVACCommand.Power_Off_Fb:
powerIsOn = false;
break;
}
// Broadcast to UpdateEvent subscribers
if (this.UpdateEvent != null)
UpdateEvent(this.id, act, _state);
}
/**
* Method: SendHVACCommand
* Access: public
* Description: Receive Commands from Interfaces and pass to S+ via TriggerSendCommand delegate
*/
public void SendHVACCommand(HVACCommand _cmd, ushort _state) {
if (TriggerSendCommand != null)
TriggerSendCommand((ushort)_cmd, _state);
}
/**
* Method: subscribeToEvents
* Access: public
* @return: void
* Description: ...
*/
public void subscribeToEvents(Interface _int) {
this.UpdateEvent += _int.HVACFbHandler;
SendHVACCommand(HVACCommand.InUseState, (ushort)(UpdateEvent != null ? 1 : 0));
}
/**
* Method: unsubscribeFromEvents
* Access: public
* @return: void
* Description: ...
*/
public void unsubscribeFromEvents(Interface _int) {
this.UpdateEvent -= _int.HVACFbHandler;
SendHVACCommand(HVACCommand.InUseState, (ushort)(UpdateEvent != null ? 1 : 0));
}
//===================// Event Handlers //===================//
} // End HVAC Class
public enum HVACControlType {
Unknown,
Auto,
HeatCool,
HeatCoolAuto,
HeatCoolOff,
FanPwr_None,
FanPwr_Fan,
FanPwr_Pwr
}
public enum HVACCommand {
Unknown,
Setpoint_Up,
Setpoint_Down,
SystemMode_Off,
SystemMode_Cool,
SystemMode_Heat,
SystemMode_Auto,
FanMode_On,
FanMode_Auto,
FanSpeed_Low,
FanSpeed_Medium,
FanSpeed_High,
FanSpeed_Max,
SystemMode_Off_Fb,
SystemMode_Cool_Fb,
SystemMode_Heat_Fb,
SystemMode_Auto_Fb,
FanMode_On_Fb,
FanMode_Auto_Fb,
FanSpeed_Low_Fb,
FanSpeed_Medium_Fb,
FanSpeed_High_Fb,
FanSpeed_Max_Fb,
CoolCall_Fb,
HeatCall_Fb,
FanCall_Fb,
TempSetpoint,
TempAmbient,
InUseState,
Power_On_Fb,
Power_Off_Fb,
Power_On,
Power_Off,
Button_1,
Button_2,
Button_3,
Button_4,
Button_5
}
}