-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathConfiger v02.cs
More file actions
196 lines (158 loc) · 6.25 KB
/
Configer v02.cs
File metadata and controls
196 lines (158 loc) · 6.25 KB
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
using System;
using System.Text;
using Crestron.SimplSharp; // For Basic SIMPL# Classes
using Newtonsoft.Json; //Thanks to Neil Colvin. Full Library @ http://www.nivloc.com/downloads/crestron/SSharp/
using Crestron.SimplSharp.CrestronIO;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using System.Linq;
namespace Config
{
public class MyConfig
{
public string RmName; //Name of the Room
public ushort RoomID; //Control ID or other ID
public ushort AudioEquipID;
public ushort VideoEquipID;
public ushort SubAudio; //Has Audio
public ushort SubVideo; //Has Video
public ushort SubLights; //Has Lights
public ushort SubShades; //Has Shades
public ushort SubHVAC; //Has HVAC
public ushort[] HazSource; //Which Sources are avaiable?
public string[] HazSourceName; //What are the Source's names?
public string[] HazHvacLightZone; //Hvac or Light Zone Name
public int Count; //Total number of sources found. I'm passing this back to SIMPL+ to make the loop dynamic
private string DaString;
private Configuration Obj;
private SourceList MysList;
private HVACandLIGHTList myHVACandLIGHTList;
/*Pass the FilePath from SIMPL+ then read in the file.
Create the JSON Object and use the library to deserialize it ushorto
our classes.
*/
public void Reader(string FilePath)
{
if (File.Exists(FilePath)) //Ok make sure the file is there
{
StreamReader daFile = new StreamReader(FilePath);
DaString = daFile.ReadToEnd();
daFile.Close();
}
else
{
CrestronConsole.PrintLine("File Not found\n\r"); //Generate error
DaString = "";
}
}
public void Builder(ushort ConnectTo)
{
HazSource = new ushort[25];
HazSourceName = new string[50];
Obj = JsonConvert.DeserializeObject<Configuration>(DaString); //All the heavy lifting
this.RmName = Obj.room[ConnectTo].RoomName;
this.RoomID = Obj.room[ConnectTo].ControlID;
this.AudioEquipID = Obj.room[ConnectTo].AudioEquipID;
this.VideoEquipID = Obj.room[ConnectTo].VideoEquipID;
this.SubAudio = Obj.room[ConnectTo].Audio;
this.SubVideo = Obj.room[ConnectTo].Video;
this.SubLights = Obj.room[ConnectTo].Lights;
this.SubShades = Obj.room[ConnectTo].Shades;
this.SubHVAC = Obj.room[ConnectTo].HVAC;
Count = Obj.room[ConnectTo].Sources.Count;
for (ushort i = 0; i < Count; i++) //fill in the arrays
{
HazSourceName[i] = Obj.room[ConnectTo].Sources[i].Name;
HazSource[i] = Obj.room[ConnectTo].Sources[i].isUsing;
}
}
#region BuildSource
//v2 Get info about Source X then send data
public void SourceInfo()
{
MysList = JsonConvert.DeserializeObject<SourceList>(DaString);
}
public string SourceName(ushort ConnectTo)
{
return MysList.ListOfSources[ConnectTo].Name;
}
public ushort SourceEquipID(ushort ConnectTo)
{
return MysList.ListOfSources[ConnectTo].EquipID;
}
public ushort SourceSubPageType(ushort ConnectTo)
{
return MysList.ListOfSources[ConnectTo].Type;
}
public ushort SourceAudioInput(ushort ConnectTo)
{
return MysList.ListOfSources[ConnectTo].Ainput;
}
public ushort SourceVideoInput(ushort ConnectTo)
{
return MysList.ListOfSources[ConnectTo].Vinput;
}
public class ListOfSource : myList
{
public ushort Type { get; set; }
public ushort EquipID { get; set; }
public ushort Ainput { get; set; }
public ushort Vinput { get; set; }
}
public class SourceList
{
public IList<ListOfSource> ListOfSources { get; set; }
}
#endregion
#region HVACandLIGHT
public void BuildHVACandLIGHT()
{
myHVACandLIGHTList = JsonConvert.DeserializeObject<HVACandLIGHTList>(DaString);
}
public string HVACandLIGHTZoneName(ushort Zone)
{
return myHVACandLIGHTList.HVACandLIGHTZones[Zone].Name;
}
public ushort HVACandLIGHTEquipID(ushort zone)
{
return myHVACandLIGHTList.HVACandLIGHTZones[zone].EquipID;
}
public class HVACandLIGHTList
{
public IList<myHVACLightList> HVACandLIGHTZones { get; set; }
}
public class myHVACLightList : myList
{
public ushort EquipID;
}
#endregion
#region Main
//Classes built from http://jsonutils.com/
public class myList
{
public string Name { get; set; }
public ushort isUsing { get; set; }
}
/* This is the main object
This tells the JsonConvert where to put everything
*/
public class Room
{
public string RoomName { get; set; }
public ushort ControlID { get; set; }
public ushort AudioEquipID { get; set; }
public ushort VideoEquipID { get; set; }
public ushort Audio { get; set; }
public ushort Video { get; set; }
public ushort Lights { get; set; }
public ushort Shades { set; get; }
public ushort HVAC { get; set; }
public IList<myList> Sources { get; set; }
}
public class Configuration
{
public IList<Room> room{ get; set; }
}
#endregion
}
}