wei
2021-06-23 d4973876384be55df64de45db8a511d1e0330872
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
using Shared;
using HDL_ON.Stan;
using System;
using System.Collections.Generic;
using System.Text;
using HDL_ON.UI.CSS;
using HDL_ON.Entity;
using HDL_ON.DriverLayer;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 涂鸦扫地机器人的控制界面
    /// </summary>
    public class TuyaWeepRobotPage : DeviceFunctionCardCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 电池控件
        /// </summary>
        private BatteryPersentControl btnBattery = null;
        /// <summary>
        /// 吸力调节图标
        /// </summary>
        private IconViewControl btnSuctionIcon = null;
        /// <summary>
        /// 吸力调节文本控件
        /// </summary>
        private NormalViewControl btnSuctionView = null;
        /// <summary>
        /// 充电图标
        /// </summary>
        private IconViewControl btnChargeIcon = null;
        /// <summary>
        /// 声音图标
        /// </summary>
        private IconViewControl btnVoiceIcon = null;
        /// <summary>
        /// 声音文本控件
        /// </summary>
        private NormalViewControl btnVoiceView = null;
        /// <summary>
        /// 清扫模式图标
        /// </summary>
        private IconViewControl btnModeIcon = null;
        /// <summary>
        /// 清扫模式文本控件
        /// </summary>
        private NormalViewControl btnModeView = null;
        /// <summary>
        /// 图像控制控件
        /// </summary>
        private DirectionImageControl ImageControl = null;
        /// <summary>
        /// 扫地机器人数据
        /// </summary>
        private WeepRobotData weepRobotData = new WeepRobotData();
        /// <summary>
        /// 是否在控制方向中
        /// </summary>
        private bool directionControling = false;
        /// <summary>
        /// 方向控制结束时间
        /// </summary>
        private DateTime directionFinishTime = DateTime.Now.AddDays(-1);
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化白色区域的内容
        /// </summary>
        public override void InitFrameWhiteContent()
        {
            base.SetTitleText(Language.StringByID(StringId.WeepRobot));
 
            //添加第二索引页
            this.AddSecondPage();
            //初始化第一个索引页的内容
            this.InitFrameWhiteContent1();
            //初始化第二个索引页的内容
            this.InitFrameWhiteContent2();
 
            //刷新当前设备的状态缓存
            this.RefreshNowDeviceStatuMemory(this.device);
            //刷新界面状态
            this.RefreshFormStatu();
        }
 
        /// <summary>
        /// 初始化第一个索引页的内容
        /// </summary>
        private void InitFrameWhiteContent1()
        {
            //电池控件
            this.btnBattery = new BatteryPersentControl();
            btnBattery.X = base.btnRoomName.Right + Application.GetRealWidth(24);
            FrameWhiteCentet1.AddChidren(btnBattery);
            btnBattery.Y = base.btnRoomName.Y - (btnBattery.Height - base.btnRoomName.Height) / 2;
            btnBattery.InitControl();
            //配置变更事件
            base.SettionFinishEvent += () =>
            {
                btnBattery.X = base.btnRoomName.Right + Application.GetRealWidth(24);
            };
 
            //初始化中间的那个图像控制控件
            this.ImageControl = new DirectionImageControl();
            ImageControl.Y = Application.GetRealHeight(108);
            ImageControl.Width = Application.GetRealWidth(198);
            ImageControl.Height = Application.GetRealWidth(198);
            ImageControl.Gravity = Gravity.CenterHorizontal;
            FrameWhiteCentet1.AddChidren(ImageControl);
            //初始化控件
            ImageControl.InitControl("FunctionIcon/Electrical/WeepRobot/ControlEnable.png", "FunctionIcon/Electrical/WeepRobot/ControlDisable.png",
                "FunctionIcon/Electrical/WeepRobot/ControlUp.png", "FunctionIcon/Electrical/WeepRobot/ControlDown.png",
                "FunctionIcon/Electrical/WeepRobot/ControlLeft.png", "FunctionIcon/Electrical/WeepRobot/ControlRight.png");
            //控制事件(只有enable,Mid,left,right,up,down。 enable:手指松开方向键后触发)
            ImageControl.NotRecoverControlEvent += (select) =>
            {
                //发送控制方向命令
                this.SendDirectionControlComand(select);
            };
 
            //吸力调节
            this.btnSuctionIcon = new IconViewControl(28);
            btnSuctionIcon.Y = ImageControl.Bottom + Application.GetRealHeight(64);
            //btnSuctionIcon.X = Application.GetRealWidth(33);
            btnSuctionIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/Suction.png";
            btnSuctionIcon.SelectedImagePath = "FunctionIcon/Electrical/WeepRobot/SuctionSelect.png";
            FrameWhiteCentet1.AddChidren(btnSuctionIcon);
            btnSuctionIcon.ButtonClickEvent += (sender, e) =>
            {
                //显示吸力调节选择界面
                this.ShowSuctionSelectView();
            };
            this.btnSuctionView = new NormalViewControl(80, 54, true);
            btnSuctionView.Y = btnSuctionIcon.Bottom + Application.GetRealHeight(10);
            //btnSuctionView.X = btnSuctionIcon.X - (Application.GetRealWidth(80) - btnSuctionIcon.Width) / 2;
            btnSuctionView.TextAlignment = TextAlignment.TopCenter;
            btnSuctionView.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnSuctionView.Text = Language.StringByID(StringId.SuctionAdjustment);
            btnSuctionView.IsMoreLines = true;
            FrameWhiteCentet1.AddChidren(btnSuctionView);
 
            //充电图标
            this.btnChargeIcon = new IconViewControl(28);
            btnChargeIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/ChargeSelect.png";
            btnChargeIcon.Y = btnSuctionIcon.Y;
            //btnChargeIcon.X = btnSuctionIcon.Right + Application.GetRealWidth(50);
            btnChargeIcon.Gravity = Gravity.CenterHorizontal;
            FrameWhiteCentet1.AddChidren(btnChargeIcon);
            btnChargeIcon.ButtonClickEvent += (sender, e) =>
            {
                //发送充电命令
                this.SendComand("mode", "chargego");
            };
            var btnChargeView = new NormalViewControl(80, 18, true);
            btnChargeView.Y = btnSuctionView.Y;
            btnChargeView.X = btnChargeIcon.X - (Application.GetRealWidth(80) - btnChargeIcon.Width) / 2;
            btnChargeView.TextAlignment = TextAlignment.TopCenter;
            btnChargeView.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnChargeView.TextID = StringId.Charge;
            FrameWhiteCentet1.AddChidren(btnChargeView);
 
            //2021.03.09 舍弃掉静音功能
            btnSuctionIcon.X = btnChargeIcon.X - btnSuctionIcon.IconSize - Application.GetRealWidth(50);
            btnSuctionView.X = btnSuctionIcon.X - (Application.GetRealWidth(80) - btnSuctionIcon.Width) / 2;
 
            //声音图标
            this.btnVoiceIcon = new IconViewControl(28);
            btnVoiceIcon.Y = btnSuctionIcon.Y;
            btnVoiceIcon.X = btnChargeIcon.Right + Application.GetRealWidth(50);
            btnVoiceIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/Voice.png";
            btnVoiceIcon.SelectedImagePath = "FunctionIcon/Electrical/WeepRobot/VoiceSelect.png";
            btnVoiceIcon.IsSelected = true;
            //FrameWhiteCentet1.AddChidren(btnVoiceIcon);
            btnVoiceIcon.ButtonClickEvent += (sender, e) =>
            {
                //发送静音命令
                this.SendComand("voice_switch", this.weepRobotData.VoiceSwitch == true ? "false" : "true");
            };
            this.btnVoiceView = new NormalViewControl(80, 18, true);
            btnVoiceView.Y = btnSuctionView.Y;
            btnVoiceView.X = btnVoiceIcon.X - (Application.GetRealWidth(80) - btnVoiceIcon.Width) / 2;
            btnVoiceView.TextAlignment = TextAlignment.TopCenter;
            btnVoiceView.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnVoiceView.TextID = StringId.Mute;
            //FrameWhiteCentet1.AddChidren(btnVoiceView);
 
            //清扫模式图标
            this.btnModeIcon = new IconViewControl(28);
            btnModeIcon.Y = btnSuctionIcon.Y;
            //btnModeIcon.X = btnVoiceIcon.Right + Application.GetRealWidth(50);
            btnModeIcon.X = btnChargeIcon.Right + Application.GetRealWidth(50);
            btnModeIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/Clean.png";
            FrameWhiteCentet1.AddChidren(btnModeIcon);
            btnModeIcon.ButtonClickEvent += (sender, e) =>
            {
                //显示清扫模式选择
                this.ShowCleanModeSelectView();
            };
            this.btnModeView = new NormalViewControl(80, 54, true);
            btnModeView.Y = btnSuctionView.Y;
            btnModeView.X = btnModeIcon.X - (Application.GetRealWidth(80) - btnModeIcon.Width) / 2;
            btnModeView.TextAlignment = TextAlignment.TopCenter;
            btnModeView.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnModeView.TextID = StringId.CleanMode;
            btnModeView.IsMoreLines = true;
            FrameWhiteCentet1.AddChidren(btnModeView);
        }
 
        /// <summary>
        /// 初始化第二个索引页的内容
        /// </summary>
        private void InitFrameWhiteContent2()
        {
            //扫地机器人
            var btnTitleName = new NormalViewControl(270, 37, true);
            btnTitleName.X = Application.GetRealWidth(16);
            btnTitleName.Y = Application.GetRealHeight(18);
            btnTitleName.TextColor = CSS_Color.FirstLevelTitleColor;
            btnTitleName.TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel;
            btnTitleName.TextID = StringId.WeepRobot;
            FrameWhiteCentet2.AddChidren(btnTitleName);
 
            //2021.03.09 舍弃耗材管理
            //耗材管理
            //var rowManment = new FrameRowControl();
            //rowManment.Height = Application.GetRealHeight(50);
            //rowManment.Width = FrameWhiteCentet2.Width;
            //rowManment.Y = Application.GetRealHeight(75);
            //FrameWhiteCentet2.AddChidren(rowManment);
            //rowManment.AddLeftCaption(Language.StringByID(StringId.ConsumablesManagement), 200);
            //rowManment.AddBottomLine();
            //rowManment.AddRightArrow();
            //rowManment.ButtonClickEvent += (sender, e) =>
            //{
            //    var form = new TuyaWeepRobotConsumablesMagPage();
            //    form.AddForm(this.device, this.weepRobotData);
            //};
 
            //历史记录
            var rowHistory = new FrameRowControl();
            rowHistory.Height = Application.GetRealHeight(50);
            rowHistory.Width = FrameWhiteCentet2.Width;
            //rowHistory.Y = rowManment.Bottom;
            rowHistory.Y = Application.GetRealHeight(75);
            FrameWhiteCentet2.AddChidren(rowHistory);
            rowHistory.AddLeftCaption(Language.StringByID(StringId.HistoryLog), 200);
            rowHistory.AddBottomLine();
            rowHistory.AddRightArrow();
            rowHistory.ButtonClickEvent += (sender, e) =>
            {
                var form = new TuyaWeepRobotHistoryPage();
                form.AddForm(this.weepRobotData);
            };
        }
 
        #endregion
 
        #region ■ 吸力调节选择_______________________
 
        /// <summary>
        /// 显示吸力调节选择界面
        /// </summary>
        private void ShowSuctionSelectView()
        {
            //整个灰色界面
            var frameBack = new Dialog();
 
            var dialogBody = new NormalFrameLayout();
            frameBack.AddChidren(dialogBody);
            dialogBody.ButtonClickEvent = (sender, e) =>
            {
                frameBack.Close();
            };
            frameBack.Show();
 
            //菜单控件(吸力调节)
            var menuContr = new DialogTitleMenuControl(3, Language.StringByID(StringId.SuctionAdjustment));
            menuContr.X = Application.GetRealWidth(5);
            menuContr.Y = Application.GetRealHeight(241);
            menuContr.Width = Application.GetRealWidth(160);
            menuContr.Height = Application.GetRealHeight(200);
            dialogBody.AddChidren(menuContr);
 
            //吸力1档
            var iconPath = this.weepRobotData.Suction == "quiet" ? "FunctionIcon/Electrical/WeepRobot/SuctionSelect.png" : "FunctionIcon/Electrical/WeepRobot/Suction.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.SuctionOneGear), iconPath, this.weepRobotData.Suction == "quiet", () =>
            {
                frameBack.Close();
                //发送吸力命令
                this.SendComand("suction", "quiet");
            });
 
            //吸力2档
            iconPath = this.weepRobotData.Suction == "normal" ? "FunctionIcon/Electrical/WeepRobot/SuctionSelect.png" : "FunctionIcon/Electrical/WeepRobot/Suction.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.SuctionTwoGear), iconPath, this.weepRobotData.Suction == "normal", () =>
            {
                frameBack.Close();
                //发送吸力命令
                this.SendComand("suction", "normal");
            });
 
            //吸力3档
            iconPath = this.weepRobotData.Suction == "strong" ? "FunctionIcon/Electrical/WeepRobot/SuctionSelect.png" : "FunctionIcon/Electrical/WeepRobot/Suction.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.SuctionThreeGear), iconPath, this.weepRobotData.Suction == "strong", () =>
            {
                frameBack.Close();
                //发送吸力命令
                this.SendComand("suction", "strong");
            });
        }
 
        #endregion
 
        #region ■ 清扫模式选择_______________________
 
        /// <summary>
        /// 显示清扫模式选择界面
        /// </summary>
        private void ShowCleanModeSelectView()
        {
            //整个灰色界面
            var frameBack = new Dialog();
 
            var dialogBody = new NormalFrameLayout();
            frameBack.AddChidren(dialogBody);
            dialogBody.ButtonClickEvent = (sender, e) =>
            {
                frameBack.Close();
            };
            frameBack.Show();
 
            //2021.03.09 舍弃随机清扫
            //菜单控件(清扫模式)
            //var menuContr = new DialogTitleMenuControl(4, Language.StringByID(StringId.CleanMode));
            var menuContr = new DialogTitleMenuControl(3, Language.StringByID(StringId.CleanMode));
            menuContr.X = Application.GetRealWidth(210);
            menuContr.Y = Application.GetRealHeight(197);
            menuContr.Width = Application.GetRealWidth(160);
            //menuContr.Height = Application.GetRealHeight(243);
            menuContr.Height = Application.GetRealHeight(203);
            dialogBody.AddChidren(menuContr);
 
            //自动清扫
            var iconPath = this.weepRobotData.Mode == "smart" ? "FunctionIcon/Electrical/WeepRobot/AutoModeSelect.png" : "FunctionIcon/Electrical/WeepRobot/AutoMode.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.AutoClean), iconPath, this.weepRobotData.Mode == "smart", () =>
            {
                frameBack.Close();
                //发送模式命令
                this.SendComand("mode", "smart");
            });
 
            //随机清扫
            //iconPath = this.weepRobotData.Mode == "random" ? "FunctionIcon/Electrical/WeepRobot/FixedPointModeSelect.png" : "FunctionIcon/Electrical/WeepRobot/FixedPointMode.png";
            //menuContr.AddRowMenu(Language.StringByID(StringId.RandomClean), iconPath, this.weepRobotData.Mode == "random", () =>
            //{
            //    frameBack.Close();
            //    //发送模式命令
            //    this.SendComand("mode", "random");
            //});
 
            //螺旋清扫
            iconPath = this.weepRobotData.Mode == "spiral" ? "FunctionIcon/Electrical/WeepRobot/AreaModeSelect.png" : "FunctionIcon/Electrical/WeepRobot/AreaMode.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.SpiralClean), iconPath, this.weepRobotData.Mode == "spiral", () =>
            {
                frameBack.Close();
                //发送模式命令
                this.SendComand("mode", "spiral");
            });
 
            //沿墙清扫
            iconPath = this.weepRobotData.Mode == "wall_follow" ? "FunctionIcon/Electrical/WeepRobot/WallModeSelect.png" : "FunctionIcon/Electrical/WeepRobot/WallMode.png";
            menuContr.AddRowMenu(Language.StringByID(StringId.WallClean), iconPath, this.weepRobotData.Mode == "wall_follow", () =>
            {
                frameBack.Close();
                //发送模式命令
                this.SendComand("mode", "wall_follow");
            });
        }
 
        #endregion
 
        #region ■ 设备状态反馈_______________________
 
        /// <summary>
        /// 设备状态反馈
        /// </summary>
        /// <param name="i_LocalDevice"></param>
        public override void DeviceStatuPush(Function i_LocalDevice)
        {
            //不是同一个东西
            if (this.device.sid != i_LocalDevice.sid) { return; }
 
            //刷新当前设备的状态缓存
            this.RefreshNowDeviceStatuMemory(i_LocalDevice);
            //刷新界面状态
            this.RefreshFormStatu();
        }
 
        #endregion
 
        #region ■ 发送各种命令_______________________
 
        /// <summary>
        /// 发送控制方向命令
        /// </summary>
        /// <param name="direction">只有enable,Mid,left,right,up,down。 enable:手指松开方向键后触发</param>
        private void SendDirectionControlComand(DirectionEnum direction)
        {
            if (direction == DirectionEnum.Mid)
            {
                //发送开关命令
                this.SendComand(FunctionAttributeKey.OnOff, this.weepRobotData.Cleaning == true ? "off" : "on");
            }
            else if (direction == DirectionEnum.Enable)
            {
                //停
                this.directionControling = false;
                this.directionFinishTime = DateTime.Now;
                this.SendComand("direction_control", "stop");
            }
            else if (direction == DirectionEnum.Left)
            {
                //左
                this.directionControling = true;
                this.SendComand("direction_control", "turn_left");
            }
            else if (direction == DirectionEnum.Right)
            {
                //右
                this.directionControling = true;
                this.SendComand("direction_control", "turn_right");
            }
            else if (direction == DirectionEnum.Up)
            {
                //上
                this.directionControling = true;
                this.SendComand("direction_control", "forward");
            }
            else if (direction == DirectionEnum.Down)
            {
                //下
                this.directionControling = true;
                this.SendComand("direction_control", "backward");
            }
        }
 
        /// <summary>
        /// 发送命令
        /// </summary>
        private void SendComand(string key, string i_value)
        {
            HdlThreadLogic.Current.RunThread(() =>
            {
                var dic = new Dictionary<string, string>();
                dic.Add(key, i_value);
                Control.Ins.SendWriteCommand(this.device, dic, true);
            }, ShowErrorMode.NO);
        }
 
        #endregion
 
        #region ■ 刷新界面状态_______________________
 
        /// <summary>
        /// 刷新界面状态
        /// </summary>
        private void RefreshFormStatu()
        {
            //静音(它有四个图标)
            if (this.weepRobotData.VoiceSwitch == true)
            {
                //需要切换图标
                this.btnVoiceIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/Mute.png";
                this.btnVoiceIcon.SelectedImagePath = "FunctionIcon/Electrical/WeepRobot/MuteSelect.png";
            }
            else
            {
                //需要切换图标
                this.btnVoiceIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/Voice.png";
                this.btnVoiceIcon.SelectedImagePath = "FunctionIcon/Electrical/WeepRobot/VoiceSelect.png";
            }
            //如果是清扫状态
            if (this.weepRobotData.Cleaning == true)
            {
                //吸力调节可用
                this.btnSuctionIcon.IsSelected = true;
                this.btnSuctionIcon.CanClick = true;
                //声音不可用
                //this.btnVoiceIcon.IsSelected = false;
                //this.btnVoiceIcon.CanClick = false;
                //清扫模式不可用
                this.btnModeIcon.IsSelected = false;
                this.btnModeIcon.CanClick = false;
                //方向按键不可用
                if (this.directionControling == false && (DateTime.Now - this.directionFinishTime).TotalSeconds >= 2)
                {
                    //在手动控制方向的过程中,不允许变更图片,并且结束之后,2秒内不接受任何反馈
                    this.ImageControl.SetDirectionImage(DirectionEnum.Disable);
                }
            }
            else
            {
                //吸力调节不可用
                this.btnSuctionIcon.IsSelected = false;
                this.btnSuctionIcon.CanClick = false;
                //声音可用
                //this.btnVoiceIcon.IsSelected = true;
                //this.btnVoiceIcon.CanClick = true;
                //清扫模式可用
                this.btnModeIcon.IsSelected = true;
                this.btnModeIcon.CanClick = true;
                //变更控制控件的图片
                if (this.directionControling == false && (DateTime.Now - this.directionFinishTime).TotalSeconds >= 2)
                {
                    //在手动控制方向的过程中,不允许变更图片,并且结束之后,2秒内不接受任何反馈
                    this.ImageControl.SetDirectionImage(DirectionEnum.Enable);
                }
            }
 
            //清扫模式
            if (this.weepRobotData.Mode == "random")
            {
                //自动清扫
                this.btnModeIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/AutoMode.png";
                this.btnModeIcon.SelectedImagePath = "FunctionIcon/Electrical/WeepRobot/AutoModeSelect.png";
                this.btnModeView.TextID = StringId.AutoClean;
            }
            //2021.03.09 舍弃随机清扫
            //else if (this.weepRobotData.Mode == "smart")
            //{
            //    //随机清扫
            //    this.btnModeIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/FixedPointMode.png";
            //    this.btnModeIcon.SelectedImagePath = "FunctionIcon/Electrical/WeepRobot/FixedPointModeSelect.png";
            //    this.btnModeView.TextID = StringId.RandomClean;
            //}
            else if (this.weepRobotData.Mode == "wall_follow")
            {
                //沿墙清扫
                this.btnModeIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/WallMode.png";
                this.btnModeIcon.SelectedImagePath = "FunctionIcon/Electrical/WeepRobot/WallModeSelect.png";
                this.btnModeView.TextID = StringId.WallClean;
            }
            else if (this.weepRobotData.Mode == "spiral")
            {
                //螺旋清扫
                this.btnModeIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/AreaMode.png";
                this.btnModeIcon.SelectedImagePath = "FunctionIcon/Electrical/WeepRobot/AreaModeSelect.png";
                this.btnModeView.TextID = StringId.SpiralClean;
            }
            else
            {
                //清扫模式
                this.btnModeIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/Clean.png";
                this.btnModeIcon.SelectedImagePath = "FunctionIcon/Electrical/WeepRobot/CleanSelect.png";
                this.btnModeView.TextID = StringId.CleanMode;
            }
            //电池电量
            this.btnBattery.SetValue(this.weepRobotData.ElectricityLeft);
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 刷新当前设备的状态缓存
        /// </summary>
        private void RefreshNowDeviceStatuMemory(Function i_LocalDevice)
        {
            for (int i = 0; i < i_LocalDevice.attributes.Count; i++)
            {
                var data = i_LocalDevice.attributes[i];
                //开关
                if (data.key == "on_off") { this.weepRobotData.Cleaning = data.state.ToLower() == "on"; }
                //寻找机器
                else if (data.key == "seek") { this.weepRobotData.SearchRobot = data.state.ToLower() == "true"; }
                //边刷重置
                else if (data.key == "reset_edge_brush") { this.weepRobotData.ResetEdgeBrush = data.state.ToLower() == "true"; }
                //滚刷重置
                else if (data.key == "reset_roll_brush") { this.weepRobotData.ResetRollBrush = data.state.ToLower() == "true"; }
                //滤网重置
                else if (data.key == "reset_filter") { this.weepRobotData.ResetFilter = data.state.ToLower() == "true"; }
                //吸力选择
                else if (data.key == "suction") { this.weepRobotData.Suction = data.state; }
                //工作模式
                else if (data.key == "mode") { this.weepRobotData.Mode = data.state; }
                //清扫方向    
                else if (data.key == "direction_control") { this.weepRobotData.DirectionControl = data.state; }
                //声音开关
                else if (data.key == "voice_switch") { this.weepRobotData.VoiceSwitch = data.state.ToLower() == "true"; }
                //清扫面积
                else if (data.key == "clean_area")
                {
                    var value = data.state;
                    if (value != string.Empty)
                    {
                        this.weepRobotData.CleanArea = Convert.ToInt32(value);
                    }
                }
                //清扫记录    
                else if (data.key == "clean_record") { this.weepRobotData.CleanRecord = data.state; }
                //边刷寿命
                else if (data.key == "edge_brush")
                {
                    var value = data.state;
                    if (value != string.Empty)
                    {
                        this.weepRobotData.EdgeBrush = Convert.ToInt32(value);
                    }
                }
                //滚刷寿命
                else if (data.key == "roll_brush")
                {
                    var value = data.state;
                    if (value != string.Empty)
                    {
                        this.weepRobotData.RollBrush = Convert.ToInt32(value);
                    }
                }
                //滤网寿命
                else if (data.key == "filter")
                {
                    var value = data.state;
                    if (value != string.Empty)
                    {
                        this.weepRobotData.Filter = Convert.ToInt32(value);
                    }
                }
                //清扫时间
                else if (data.key == "clean_time")
                {
                    var value = data.state;
                    if (value != string.Empty)
                    {
                        this.weepRobotData.CleanTime = Convert.ToInt32(value);
                    }
                }
                //剩余电量    
                else if (data.key == "electricity_left")
                {
                    var value = data.state;
                    if (value != string.Empty)
                    {
                        this.weepRobotData.ElectricityLeft = Convert.ToInt32(value);
                    }
                }
            }
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 扫地机器人的数据
        /// </summary>
        public class WeepRobotData
        {
            /// <summary>
            /// 是否处于清扫中
            /// </summary>
            public bool Cleaning = false;
            /// <summary>
            /// 寻找机器
            /// </summary>
            public bool SearchRobot = false;
            /// <summary>
            /// 边刷重置
            /// </summary>
            public bool ResetEdgeBrush = false;
            /// <summary>
            /// 滚刷重置
            /// </summary>
            public bool ResetRollBrush = false;
            /// <summary>
            /// 滤网重置
            /// </summary>
            public bool ResetFilter = false;
            /// <summary>
            /// 吸力选择(strong:一档 normal:二挡 quiet:三挡)
            /// </summary>
            public string Suction = string.Empty;
            /// <summary>
            /// 工作模式(smart:自动清扫 random:随机清扫 wall_follow:沿墙清扫 spiral:螺旋清扫 chargego:充电)
            /// </summary>
            public string Mode = string.Empty;
            /// <summary>
            /// 清扫方向(forward:向前 backward:向后 turn_left:向左 turn_right:向右 stop:停止)
            /// </summary>
            public string DirectionControl = string.Empty;
            /// <summary>
            /// 静音
            /// </summary>
            public bool VoiceSwitch = false;
            /// <summary>
            /// 清扫面积
            /// </summary>
            public int CleanArea = 0;
            /// <summary>
            /// 清扫记录(目前都是空的)
            /// </summary>
            public string CleanRecord = string.Empty;
            /// <summary>
            /// 边刷寿命(百分比)
            /// </summary>
            public int EdgeBrush = 0;
            /// <summary>
            /// 滚刷寿命(百分比)
            /// </summary>
            public int RollBrush = 0;
            /// <summary>
            /// 滤网寿命(百分比)
            /// </summary>
            public int Filter = 0;
            /// <summary>
            /// 清扫时间(0-432000) 单位为分钟
            /// </summary>
            public int CleanTime = 0;
            /// <summary>
            /// 剩余电量(百分比)
            /// </summary>
            public int ElectricityLeft = 0;
        }
 
        #endregion
    }
}