黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DeviceAirConditioner
{
    /// <summary>
    /// 空调室内机设置界面
    /// </summary>
    public class IndoorUnitSettionForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private FrameListControl listview = null;
        /// <summary>
        /// 当前选择的网关
        /// </summary>
        private AC deviceAc = null;
        /// <summary>
        /// 摆风模式(用二进制来玩自定义模式 0:不使用 1:使用)
        /// </summary>
        private int swingMode = 0;
        /// <summary>
        /// 固定预留的数据
        /// </summary>
        private string fixValue = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_deviceAc">选择的空调回路</param>
        public void ShowForm(AC i_deviceAc)
        {
            this.deviceAc = i_deviceAc;
 
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uIndoorUnitSettion));
 
            //初始化右上角菜单
            this.InitTopRightMenu();
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //开启进度条
                this.ShowProgressBar();
                //读取空调摆风模式
                var result = this.ReadAirConditionerSwingModeSupport();
                if (result == false)
                {
                    //关闭进度条
                    this.CloseProgressBar(ShowReLoadMode.YES);
                    return;
                }
                //关闭进度条
                this.CloseProgressBar();
 
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //初始化中部控件
                    this.InitMiddleFrame();
                });
            });
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var listBackControl = new VerticalFrameControl();
            listBackControl.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listBackControl);
 
            //初始化桌布
            var tableContr = new InformationEditorControl();
            this.listview = tableContr.InitControl(listBackControl.frameTable, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 1368);
 
            //图片
            var btnPic = new DeviceInfoIconControl();
            btnPic.Y = Application.GetRealHeight(92);
            btnPic.Gravity = Gravity.CenterHorizontal;
            listBackControl.frameTable.AddChidren(btnPic);
            btnPic.InitControl(this.deviceAc);
 
            //设备备注
            string caption = Language.StringByID(R.MyInternationalizationString.uDeviceNote);
            string nameValue = Common.LocalDevice.Current.GetDeviceEpointName(deviceAc);
            var btnNote = new FrameCaptionInputControl(caption, nameValue, listview.rowSpace / 2);
            listview.AddChidren(btnNote);
            btnNote.InitControl();
            //划线
            btnNote.AddBottomLine();
            btnNote.txtInput.FinishInputEvent += () =>
             {
                 string oldName = Common.LocalDevice.Current.GetDeviceEpointName(deviceAc);
                 if (btnNote.Text.Trim() == string.Empty)
                 {
                     //将名字还原
                     btnNote.Text = oldName;
                 }
                 if (oldName != btnNote.Text)
                 {
                     //设备名称修改
                     var result = Common.LocalDevice.Current.ReName(deviceAc, btnNote.Text);
                     if (result == false)
                     {
                         return;
                     }
                     //设备备注修改成功!
                     string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNoteSuccess);
                     this.ShowMassage(ShowMsgType.Tip, msg);
                 }
             };
 
            //设备类型
            caption = Language.StringByID(R.MyInternationalizationString.uDeviceType);
            nameValue = Common.LocalDevice.Current.GetDeviceObjectText(new List<CommonDevice>() { deviceAc });
            var btnType = new FrameCaptionViewControl(caption, nameValue, listview.rowSpace / 2);
            btnType.UseClickStatu = false;
            listview.AddChidren(btnType);
            btnType.InitControl();
            //划线
            btnType.AddBottomLine();
 
            //所属区域
            var rowBeloneArea = new BelongAreaControl(listview.rowSpace / 2);
            listview.AddChidren(rowBeloneArea);
            rowBeloneArea.InitControl(Language.StringByID(R.MyInternationalizationString.uBelongArea), deviceAc);
            //底线
            rowBeloneArea.AddBottomLine();
            rowBeloneArea.SelectRoomEvent += (roomKeys) =>
            {
                HdlRoomLogic.Current.ChangedRoom(deviceAc, roomKeys);
            };
 
            //空调模式
            var rowMode = new FrameRowControl(listview.rowSpace / 2);
            listview.AddChidren(rowMode);
            rowMode.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAirConditionerMode), 600);
            rowMode.AddRightArrow();
            rowMode.AddBottomLine();
            rowMode.ButtonClickEvent += (sender, e) =>
            {
                var form = new AirConditionerModeForm();
                form.AddForm(deviceAc);
            };
 
            //摆风
            var rowSwing = new FrameRowControl(listview.rowSpace / 2);
            rowSwing.UseClickStatu = false;
            listview.AddChidren(rowSwing);
            rowSwing.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAirConditionerSwing), 400);
            rowSwing.AddBottomLine();
            var btnSwingSwitch = rowSwing.AddMostRightSwitchIcon();
            if (this.swingMode == 1)
            {
                btnSwingSwitch.IsSelected = true;
            }
            btnSwingSwitch.ButtonClickEvent += (sender, e) =>
            {
                //不能再点击
                btnSwingSwitch.CanClick = false;
                string statu = btnSwingSwitch.IsSelected == true ? "0" : "1";
                //将二进制转换为十进制
                int sendData = Convert.ToInt32(this.fixValue + statu, 2);
                HdlThreadLogic.Current.RunThread(() =>
                {
                    var result = HdlDeviceAirConditionerLogic.Current.SetUseAcSwingFunctionStatu(deviceAc, sendData);
                    if (result == true)
                    {
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            btnSwingSwitch.IsSelected = !btnSwingSwitch.IsSelected;
                            this.swingMode = this.swingMode == 1 ? 0 : 1;
 
                            deviceAc.UseSwingFunction = btnSwingSwitch.IsSelected;
                            deviceAc.ReSave();
                        });
                    }
                    //能够继续点击
                    btnSwingSwitch.CanClick = true;
                });
            };
 
            //初始化桌布完成
            tableContr.FinishInitControl();
            tableContr = null;
 
            //保存
            var btnFinish = new BottomClickButton();
            btnFinish.TextID = R.MyInternationalizationString.uSave;
            bodyFrameLayout.AddChidren(btnFinish);
            btnFinish.ButtonClickEvent += (sender, e) =>
            {
                string oldName = Common.LocalDevice.Current.GetDeviceEpointName(deviceAc);
                if (oldName != btnNote.Text)
                {
                    //设备名称修改
                    var result = Common.LocalDevice.Current.ReName(deviceAc, btnNote.Text);
                    if (result == false)
                    {
                        return;
                    }
                }
                this.CloseForm();
            };
        }
 
        #endregion
 
        #region ■ 右上角菜单_________________________
 
        /// <summary>
        /// 初始化右上角菜单
        /// </summary>
        private void InitTopRightMenu()
        {
            //检测此回路是否拥有定位功能(拿端点最小的那个回路去定位)
            bool canTest = Common.LocalDevice.Current.DeviceIsCanFixedPosition(deviceAc);
            if (canTest == false)
            {
                return;
            }
            var btnIcon = new MostRightIconControl(69, 69);
            btnIcon.UnSelectedImagePath = "Item/More.png";
            topFrameLayout.AddChidren(btnIcon);
            btnIcon.InitControl();
            btnIcon.ButtonClickEvent += ((sender, e) =>
            {
                //显示右上角菜单界面
                this.ShowTopRightMenu();
            });
        }
 
        /// <summary>
        /// 显示右上角菜单界面
        /// </summary>
        private void ShowTopRightMenu()
        {
            var frame = new TopRightMenuControl(1, 1);
            //定位
            var deviceMenu = Language.StringByID(R.MyInternationalizationString.uFixedPosition);
            frame.AddRowMenu(deviceMenu, "Item/FixedPosition.png", "Item/FixedPositionSelected.png", () =>
            {
                //发送定位功能
                Common.LocalDevice.Current.SetFixedPositionCommand(deviceAc);
            });
        }
 
        #endregion
 
        #region ■ 读取空调摆风模式___________________
 
        /// <summary>
        /// 读取空调摆风模式
        /// </summary>
        private bool ReadAirConditionerSwingModeSupport()
        {
            //如果是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                var data = ModelData.DeviceModelDataLogic.Current.GetAcSwingModeSupport(deviceAc);
                //转换为二进制
                var value = Convert.ToString(data, 2).PadLeft(16, '0');
                //这个设置是放在后面的
                this.fixValue = value.Substring(0, value.Length - 1);
                this.swingMode = Convert.ToInt32(value.Substring(this.fixValue.Length));
                return true;
            }
 
            string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(deviceAc);
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("ReadAirConditionerModeSupport", ReceiveComandDiv.A设备属性上报, (report) =>
            {
                string checkKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report);
                if (checkKeys != mainkeys || report.DeviceStatusReport.CluterID != 514)
                {
                    return;
                }
                for (int i = 0; i < report.DeviceStatusReport.AttriBute.Count; i++)
                {
                    var data = report.DeviceStatusReport.AttriBute[i];
                    if (data.AttributeId == 4097)
                    {
                        HdlGatewayReceiveLogic.Current.RemoveEvent("ReadAirConditionerModeSupport");
                        //转换为二进制
                        var value = Convert.ToString(data.AttriButeData, 2).PadLeft(16, '0');
                        //这个设置是放在后面的
                        this.fixValue = value.Substring(0, value.Length - 1);
                        this.swingMode = Convert.ToInt32(value.Substring(this.fixValue.Length));
                    }
                }
            });
            //获取是否启用空调摆风模式的状态(打开 或者 关闭)
            deviceAc.ReadUseSwingFunctionStatu();
 
            int timeOut = 0;
            while (this.fixValue == null && timeOut <= 30)
            {
                System.Threading.Thread.Sleep(100);
                timeOut++;
            }
            if (this.fixValue == null)
            {
                //获取空调摆风状态失败
                string msg = Language.StringByID(R.MyInternationalizationString.uGetAirConditionerSwingFunctionFail);
                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
                this.ShowMassage(ShowMsgType.Tip, msg);
                return false;
            }
            return true;
        }
 
        #endregion
    }
}