HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-10-28 8b4d79ca03495e522a1953e04ca17527f33c853a
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DeviceAirConditioner
{
    /// <summary>
    /// 空调的室内机列表界面
    /// </summary>
    public class IndoorUnitListForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 设备列表
        /// </summary>
        private List<CommonDevice> listDevice = null;
        /// <summary>
        /// 控件信息
        /// </summary>
        private Dictionary<string, RowControlInfo> dicControl = new Dictionary<string, RowControlInfo>();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_diviceMac">设备Mac地址</param>
        public void ShowForm(string i_diviceMac)
        {
            this.listDevice = Common.LocalDevice.Current.GetDevicesByMac(i_diviceMac);
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uIndoorUnitSettion));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var listView = new VerticalFrameControl(14);
            listView.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listView);
 
            var frameTemp = new FrameLayout();
            frameTemp.Height = Application.GetRealHeight(69);
            listView.AddChidrenFrame(frameTemp);
 
            HdlThreadLogic.Current.RunMainInThread(() =>
            {
                for (int i = 0; i < listDevice.Count; i++)
                {
                    //添加空调行
                    this.AddAcControlRow(listView, (AC)listDevice[i]);
                }
                var frameTemp2 = new FrameLayout();
                frameTemp2.Height = Application.GetRealHeight(29);
                listView.AddChidrenFrame(frameTemp2);
 
                //数据接收
                this.StartReceiveDataEvent();
                //发送读取属性的命令
                this.SetReadAttributeComand();
            });
        }
 
        /// <summary>
        /// 添加空调行
        /// </summary>
        /// <param name="listView"></param>
        /// <param name="device"></param>
        private void AddAcControlRow(VerticalFrameControl listView, AC device)
        {
            var rowInfo = new RowControlInfo();
 
            var frameTable = new FrameLayoutControl();
            frameTable.UseClickStatu = false;
            frameTable.Width = Application.GetRealWidth(994);
            frameTable.Height = Application.GetRealHeight(337);
            frameTable.BackgroundImagePath = "Item/IndoorUnitGround.png";
            frameTable.Gravity = Gravity.CenterHorizontal;
            listView.AddChidrenFrame(frameTable);
 
            //设备图标
            var btnIconBack = new FrameLayout();
            btnIconBack.X = Application.GetRealWidth(46);
            btnIconBack.Y = Application.GetRealHeight(43);
            btnIconBack.Height = Application.GetMinRealAverage(112);
            btnIconBack.Width = Application.GetMinRealAverage(112);
            btnIconBack.Radius = (uint)Application.GetMinRealAverage(112) / 2;
            btnIconBack.BackgroundColor = 0xfff5f6fa;
            frameTable.AddChidren(btnIconBack, ChidrenBindMode.NotBind);
            rowInfo.btnIconBack = btnIconBack;
 
            var btnIcon = new IconViewControl(78);
            btnIcon.Gravity = Gravity.Center;
            Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
            btnIconBack.AddChidren(btnIcon);
            frameTable.ChangedChidrenBindMode(btnIconBack, ChidrenBindMode.BindEventOnly);
            rowInfo.btnIcon = btnIcon;
 
            //设备名称
            var btnDeviceName = new NormalViewControl(400, 60, true);
            btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device);
            btnDeviceName.X = Application.GetRealWidth(193);
            btnDeviceName.Y = Application.GetRealHeight(45);
            frameTable.AddChidren(btnDeviceName, ChidrenBindMode.BindEventOnly);
            //房间
            var btnRoom = new NormalViewControl(400, 50, true);
            btnRoom.X = btnDeviceName.X;
            btnRoom.Y = btnDeviceName.Bottom + Application.GetRealHeight(12);
            btnRoom.TextSize = 12;
            btnRoom.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnRoom.Text = Common.Room.CurrentRoom.GetRoomNameByDevice(device);
            frameTable.AddChidren(btnRoom, ChidrenBindMode.BindEventOnly);
            //摄氏度
            var btnValue = new NormalViewControl(150, 60, true);
            btnValue.Y = Application.GetRealHeight(58);
            btnValue.X = frameTable.Width - Application.GetRealWidth(150 + 58);
            btnValue.TextAlignment = TextAlignment.CenterRight;
            frameTable.AddChidren(btnValue, ChidrenBindMode.BindEventOnly);
            rowInfo.btnValue = btnValue;
            //警告图标
            var btnWarningIcon = new IconViewControl(69);
            btnWarningIcon.X = btnIconBack.X;
            btnWarningIcon.Y = btnRoom.Bottom + Application.GetRealHeight(43);
            btnWarningIcon.UnSelectedImagePath = "Item/WarningIcon1.png";
            frameTable.AddChidren(btnWarningIcon, ChidrenBindMode.NotBind);
            btnWarningIcon.Visible = false;
            rowInfo.btnWarningIcon = btnWarningIcon;
            //警告信息
            var btnWarningMsg = new NormalViewControl(500, 50, true);
            btnWarningMsg.X = btnWarningIcon.Right + Application.GetRealWidth(12);
            btnWarningMsg.Y = btnRoom.Bottom + Application.GetRealHeight(55);
            btnWarningMsg.TextSize = 12;
            btnWarningMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
            frameTable.AddChidren(btnWarningMsg, ChidrenBindMode.NotBind);
            rowInfo.btnWarningMsg = btnWarningMsg;
            //开关
            var btnSwitch = new IconViewControl(69);
            btnSwitch.X = frameTable.Width - Application.GetRealWidth(69 + 46);
            btnSwitch.Y = btnRoom.Bottom + Application.GetRealHeight(43);
            btnSwitch.UnSelectedImagePath = "Item/Switch.png";
            btnSwitch.SelectedImagePath = "Item/SwitchSelected.png";
            frameTable.AddChidren(btnSwitch, ChidrenBindMode.NotBind);
            rowInfo.btnSwitch = btnSwitch;
            btnSwitch.ButtonClickEvent += async (sender, e) =>
            {
                if (btnSwitch.IsSelected == false)
                {
                    //打开空调
                    var result = await HdlDeviceAirConditionerLogic.Current.OpenAirConditioner(device);
                    if (result == false)
                    {
                        return;
                    }
                    btnIcon.IsSelected = true;
                    btnIconBack.BackgroundColor = 0xfffef1ed;
                }
                else
                {
                    //关闭空调
                    var result = await HdlDeviceAirConditionerLogic.Current.CloseAirConditioner(device);
                    if (result == false)
                    {
                        return;
                    }
                    btnIcon.IsSelected = false;
                    btnIconBack.BackgroundColor = 0xfff5f6fa;
                }
                btnSwitch.IsSelected = !btnSwitch.IsSelected;
            };
 
            frameTable.ButtonClickEvent += (sender, e) =>
            {
                var form = new IndoorUnitSettionForm();
                form.AddForm(device);
            };
 
            dicControl[Common.LocalDevice.Current.GetDeviceMainKeys(device)] = rowInfo;
        }
 
        #endregion
 
        #region ■ 发送命令___________________________
 
        /// <summary>
        /// 发送读取属性的命令
        /// </summary>
        private void SetReadAttributeComand()
        {
            HdlThreadLogic.Current.RunThread(() =>
            {
                for (int i = 0; i < listDevice.Count; i++)
                {
                    if (i != 0 && i % 5 == 0)
                    {
                        //读取5个后,间隔一段时间
                        System.Threading.Thread.Sleep(500);
                        if (this.Parent == null)
                        {
                            return;
                        }
                    }
                    //获取当前室温
                    ((AC)listDevice[i]).ReadLocalTemperature();
                    //获取开关状态(处于某种工作状态,即为打开状态)
                    ((AC)listDevice[i]).ReadSystemMode();
                }
            });
        }
 
        #endregion
 
        #region ■ 数据接收___________________________
 
        /// <summary>
        /// 数据接收
        /// </summary>
        private void StartReceiveDataEvent()
        {
            HdlDeviceAttributeLogic.Current.AddAttributeEvent("IndoorUnitListFormEvent", "DeviceStatusReport", (device) =>
            {
                string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
                if (dicControl.ContainsKey(mainkeys) == false || device.DeviceStatusReport.CluterID != 513)
                {
                    return;
                }
 
                var rowInfo = dicControl[mainkeys];
                for (int i = 0; i < device.DeviceStatusReport.AttriBute.Count; i++)
                {
                    var data = device.DeviceStatusReport.AttriBute[i];
                    if (data.AttributeId == 0)
                    {
                        //室内温度
                        if (data.AttriButeData == 0)
                        {
                            //0℃
                            rowInfo.btnValue.Text = "0.0℃";
                        }
                        else if (data.AttriButeData > 32767)
                        {
                            //负数(特殊处理)
                            string strValue = (data.AttriButeData - 65536).ToString();
                            //小数点需要一位
                            strValue = strValue.Substring(0, strValue.Length - 1);
                            rowInfo.btnValue.Text = strValue.Insert(strValue.Length - 1, ".") + "℃";
                        }
                        else
                        {
                            //小数点需要一位
                            string strValue = data.AttriButeData.ToString();
                            strValue = strValue.Substring(0, strValue.Length - 1);
                            rowInfo.btnValue.Text = strValue.Insert(strValue.Length - 1, ".") + "℃";
                        }
                    }
                    else if (data.AttributeId == 28)
                    {
                        //此属性描述恒温设备正处于哪种模式
                        //Off = 0  Auto = 1 Cool = 3 Heat = 4 FanOnly = 7  Dry = 8
                        if (data.AttriButeData != 0)
                        {
                            rowInfo.btnSwitch.IsSelected = true;
                            rowInfo.btnIcon.IsSelected = true;
                            rowInfo.btnIconBack.BackgroundColor = 0xfffef1ed;
                        }
                    }
                }
            });
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseForm()
        {
            HdlDeviceAttributeLogic.Current.RemoveEvent("IndoorUnitListFormEvent");
 
            base.CloseForm();
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 行数据
        /// </summary>
        private class RowControlInfo
        {
            /// <summary>
            /// 设备图标背景
            /// </summary>
            public FrameLayout btnIconBack = null;
            /// <summary>
            /// 设备图标
            /// </summary>
            public IconViewControl btnIcon = null;
            /// <summary>
            /// 摄氏度
            /// </summary>
            public NormalViewControl btnValue = null;
            /// <summary>
            /// 警告图标
            /// </summary>
            public IconViewControl btnWarningIcon = null;
            /// <summary>
            /// 警告信息
            /// </summary>
            public NormalViewControl btnWarningMsg = null;
            /// <summary>
            /// 开关
            /// </summary>
            public IconViewControl btnSwitch = null;
        }
 
        #endregion
    }
}