JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
using Shared.SimpleControl.Phone;
using System;
using System.Collections.Generic;
using Shared.SimpleControl;
 
namespace Shared.SimpleControl.Pad
{
    public class UserCurtainPage : FrameLayout
    {
        /// <summary>
        /// 当前打开的窗帘界面
        /// </summary>
        public static UserCurtainPage curView;
        FrameLayout ProgressControlView;
        FrameLayout roomBackgroundImageView;
        Common curtain;
        Button btnCloseCurtain;
        Button btnOpenCurtain;
        Button btnStopCurtain;
        Button btnCurrentStatus;
        HorizontalSeekBar horizontalSeekBar;
 
        /// <summary>
        /// 显示当前房间窗帘设备
        /// </summary>
        /// <param name="room">Room.</param>
        public UserCurtainPage (Common curtain, Room room)
        {
            this.curtain = curtain;
            curView = this;
            BackgroundColor = 0xFF2f2f2f;
            statrtReadProgress ();
            showCurtainsRoom (curtain, room);
        }
 
        //窗帘停止回复的命令没有必要调用UpdateStatus
        /// <summary>
        /// 接受到窗帘发出的数据之后更新UI
        /// </summary>
        /// <returns>The user lights.</returns>
        public static void UpdateStatus (Common curtain)
        {
            Application.RunOnMainThread (() => {
                if (curView == null || curView.curtain != curtain) {
                    return;
                }
                if (curView.curtain.Type == DeviceType.CurtainTrietex) {
                    var curtainTrietex = curView.curtain as CurtainTrietex;
                    //不在模拟进度时
                    if (curView.th == null) {
                        curView.btnCurrentStatus.Text =  Language.StringByID(R.MyInternationalizationString.CurrentStatus)  +" : "+ curtainTrietex.CurtainProress.ToString () + "%";
                        curView.horizontalSeekBar.Progress = curtainTrietex.CurtainProress;
                    }
                } else if (curView.curtain.Type == DeviceType.CurtainRoller) {
                    var curtainRoller = curView.curtain as CurtainRoller;
                    //不在模拟进度时
                    if (curView.th == null) {
                        curView.btnCurrentStatus.Text = Language.StringByID(R.MyInternationalizationString.CurrentStatus) +" : "+ curtainRoller.CurtainProress.ToString () + "%";
                        curView.horizontalSeekBar.Progress = curtainRoller.CurtainProress;
                    }
                }
            });
        }
 
        /// <summary>
        /// 房间模式进入的窗帘界面
        /// </summary>
        /// <returns>The lights room.</returns>
        public void showCurtainsRoom (Common curtain, Room room)
        {
 
            roomBackgroundImageView = new FrameLayout () {
                X = Application.GetRealWidth (10),
                Y = Application.GetRealHeight (10),
                Width = Application.GetRealWidth (920),
                Height = Application.GetRealHeight (520),
            };
            AddChidren (roomBackgroundImageView);
            roomBackgroundImageView.BackgroundImagePath = room.BackGroundImage;
            roomBackgroundImageView.MouseLongEventHandler += (sender, e) => {
                Camera.SelectPicture ((obj) => {
                    if (obj != null) {
                        room.BackGroundImage = obj;
                        roomBackgroundImageView.BackgroundImagePath = obj;
                        room.Save (typeof (Room).Name + "_" + room.Name);
                    }
                }, room.Name);
            };
 
 
            #region 开关停
            FrameLayout ControlView = new FrameLayout () {
                X = roomBackgroundImageView.Right + Application.GetRealWidth (10),
                Y = roomBackgroundImageView.Y,
                Width = Application.GetRealWidth (600),
                Height = Application.GetRealHeight (680),
            };
 
            AddChidren (ControlView);
 
            btnOpenCurtain = new Button () {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight (10),
                Width = Application.GetRealWidth (270),
                Height = Application.GetRealHeight (150),
                UnSelectedImagePath = "PadAdding/Black.png",
                SelectedImagePath = "PadAdding/ModeBlackOn.png",
                SelectedTextColor = SkinStyle.Current.SelectedColor,
                TextColor = SkinStyle.Current.TextColor1,
                TextID = R.MyInternationalizationString.Open,
            };
            ControlView.AddChidren (btnOpenCurtain);
            btnStopCurtain = new Button () {
                X = btnOpenCurtain.X,
                Y = btnOpenCurtain.Bottom + Application.GetRealHeight (20),
                Width = Application.GetRealWidth (270),
                Height = Application.GetRealHeight (150),
                UnSelectedImagePath = "PadAdding/Black.png",
                SelectedImagePath = "PadAdding/ModeBlackOn.png",
                SelectedTextColor = SkinStyle.Current.SelectedColor,
                TextColor = SkinStyle.Current.TextColor1,
                TextID = R.MyInternationalizationString.Stop,
            };
            ControlView.AddChidren (btnStopCurtain);
            btnCloseCurtain = new Button () {
                X = btnOpenCurtain.X,
                Y = btnStopCurtain.Bottom + Application.GetRealHeight (20),
                Width = Application.GetRealWidth (270),
                Height = Application.GetRealHeight (150),
                UnSelectedImagePath = "PadAdding/Black.png",
                SelectedImagePath = "PadAdding/ModeBlackOn.png",
                SelectedTextColor = SkinStyle.Current.SelectedColor,
                TextColor = SkinStyle.Current.TextColor1,
                TextID = R.MyInternationalizationString.Close2,
            };
            ControlView.AddChidren (btnCloseCurtain);
            #endregion
 
 
            ProgressControlView = new FrameLayout () {
                Y = roomBackgroundImageView.Bottom + Application.GetRealHeight(100),
                Width = LayoutParams.MatchParent,
                Height = Application.GetRealHeight (230),
            };
            AddChidren (ProgressControlView);
 
 
            if (curtain.Type == DeviceType.CurtainModel) {
                AddCurtainModeul (curtain);
            } else if (curtain.Type == DeviceType.CurtainTrietex) {
                AddCurtainsTrietex (curtain as CurtainTrietex);
            } else if (curtain.Type == DeviceType.CurtainRoller) {
                AddCurtainsRoller (curtain as CurtainRoller);
            }
            UpdateStatus (curtain);
        }
 
        /// <summary>
        /// 加载窗帘模块
        /// </summary>
        void AddCurtainModeul (Common device)
        {
            btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => {
                Control.ControlBytesSend (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, 2 });
                (sender3 as Button).IsSelected = true;
            };
            btnCloseCurtain.MouseUpEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = false;
            };
            btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => {
                Control.ControlBytesSend (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, 1 });
                (sender3 as Button).IsSelected = true;
            };
            btnOpenCurtain.MouseUpEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = false;
            };
            btnStopCurtain.MouseDownEventHandler += (sender3, e3) => {
                Control.ControlBytesSend (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, 0 });
                (sender3 as Button).IsSelected = true;
            };
            btnStopCurtain.MouseUpEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = false;
            };
        }
 
        /// <summary>
        /// 加载开合帘
        /// </summary>
        void AddCurtainsTrietex (CurtainTrietex device)
        {
            #region 进度条
            btnCurrentStatus = new Button () {
                Width = Application.GetRealWidth (400),
                Height = Application.GetRealHeight (50),
                X = Application.GetRealWidth (40),
                Y = Application.GetRealHeight (20),
                TextAlignment = TextAlignment.CenterLeft,
                TextID = R.MyInternationalizationString.CurrentStatus
            };
            ProgressControlView.AddChidren (btnCurrentStatus);
 
            var btnMinBrightness = new Button () {
                Width = Application.GetRealWidth (90),
                Height = Application.GetRealHeight (80),
                X = Application.GetRealWidth (40),
                Y = btnCurrentStatus.Bottom + Application.GetRealHeight (30),
                Text = "0%",
                TextColor = 0xFF333333,
                TextAlignment = TextAlignment.Center,
            };
            ProgressControlView.AddChidren (btnMinBrightness);
 
            var f = new FrameLayout () {
                Width = Application.GetRealWidth (1200),
                Height = Application.GetRealHeight (80),
                X = btnMinBrightness.Right,
                Y = btnMinBrightness.Y,
            };
            ProgressControlView.AddChidren (f);
 
            horizontalSeekBar = new HorizontalSeekBar () {
                Height = LayoutParams.MatchParent,
                Gravity = Gravity.CenterVertical,
                Progress = device.CurtainProress,
                ProgressColor =SkinStyle.Current.SelectedColor,
                                    ThumbColor = 0xFFFFFFFF,
            };
            f.AddChidren (horizontalSeekBar);
 
            var btnMaxBrightness = new Button () {
                X = f.Right + Application.GetRealHeight (10),
                Y = btnMinBrightness.Y,
                Width = Application.GetRealWidth (120),
                Height = Application.GetRealHeight (80),
                TextAlignment = TextAlignment.CenterLeft,
                Text = "100%",
                TextColor = 0xFF333333,
            };
            ProgressControlView.AddChidren (btnMaxBrightness);
 
            horizontalSeekBar.ProgressChanged += (sender, e) => {
                btnCurrentStatus.Text = e.ToString () + "%";
                device.CurtainProress = (byte)e;
            };
            horizontalSeekBar.MouseDownEventHandler += (sender, e) => {
                stop ();
            };
 
            horizontalSeekBar.MouseUpEventHandler += (sender, e) => {
                Control.ControlBytesSend (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 17, Convert.ToByte (horizontalSeekBar.Progress) });
                btnCurrentStatus.Text = Language.StringByID(R.MyInternationalizationString.CurrentStatus) +" : "+ device.CurtainProress.ToString () + "%";
                th = new System.Threading.Thread ((obj) => {
                    //如果后面没有什么操作,到时自动还原接收更新状态
                    System.Threading.Thread.Sleep (20 * 1000);
                    th = null;
                });
                th.Start ();
 
            };
            #endregion
 
            btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = true;
                Control.ControlBytesSend (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, 2 });
                stop ();
                int startProgress = horizontalSeekBar.Progress;
                if (0 < device.Speed) {
                    th = new System.Threading.Thread ((obj) => {
                        var startDateTime = DateTime.Now;
                        while (curView != null) {
                            System.Threading.Thread.Sleep (200);
                            var v = startProgress - (int)((DateTime.Now - startDateTime).TotalMilliseconds * device.Speed);
                            v = v < 0 ? 0 : v;
                            Application.RunOnMainThread (() => {
                                horizontalSeekBar.Progress = v;
                                btnCurrentStatus.Text = Language.StringByID(R.MyInternationalizationString.CurrentStatus) +" : "+ v + "%";
                            });
                            if (v <= 0) {
                                break;
                            }
                        }
                        //防止跳动
                        System.Threading.Thread.Sleep (2000);
                        th = null;
                    });
                    th.Start ();
                } else {
                    readProgressDateTime = DateTime.Now;
                    //接近全开状态,这样初始化的值会是比较准确的
                    if (90 <= startProgress) {
                        intSpped (0);
                    }
                }
            };
            btnCloseCurtain.MouseUpEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = false;
            };
            btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = true;
                Control.ControlBytesSend (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, 1 });
                stop ();
                int startProgress = horizontalSeekBar.Progress;
                if (0 < device.Speed) {
                    th = new System.Threading.Thread ((obj) => {
                        var startDateTime = DateTime.Now;
                        while (curView != null) {
                            System.Threading.Thread.Sleep (200);
                            var v = startProgress + (int)((DateTime.Now - startDateTime).TotalMilliseconds * device.Speed);
                            v = 100 < v ? 100 : v;
                            Application.RunOnMainThread (() => {
                                horizontalSeekBar.Progress = v;
                                btnCurrentStatus.Text = Language.StringByID(R.MyInternationalizationString.CurrentStatus) +" : "+ v + "%";
                            });
                            if (100 <= v) {
                                break;
                            }
                        }
                        //防止跳动
                        System.Threading.Thread.Sleep (2000);
                        th = null;
                    });
                    th.Start ();
                } else {
                    readProgressDateTime = DateTime.Now;
                    //接近全关状态,这样初始化的值会是比较准确的
                    if (startProgress <= 10) {
                        intSpped (100);
                    }
                }
            };
            btnOpenCurtain.MouseUpEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = false;
            };
            btnStopCurtain.MouseDownEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = true;
                Control.ControlBytesSend (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, 0 });
                stop ();
            };
            btnStopCurtain.MouseUpEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = false;
            };
        }
 
 
        /// <summary>
        /// 加载开合帘
        /// </summary>
        void AddCurtainsRoller (CurtainRoller device)
        {
            #region 进度条
            btnCurrentStatus = new Button () {
                Width = Application.GetRealWidth (400),
                Height = Application.GetRealHeight (50),
                X = Application.GetRealWidth (40),
                Y = Application.GetRealHeight (20),
                TextAlignment = TextAlignment.CenterLeft,
                TextID = R.MyInternationalizationString.CurrentStatus
            };
            ProgressControlView.AddChidren (btnCurrentStatus);
 
            var btnMinBrightness = new Button () {
                Width = Application.GetRealWidth (90),
                Height = Application.GetRealHeight (80),
                X = Application.GetRealWidth (40),
                Y = btnCurrentStatus.Bottom + Application.GetRealHeight (30),
                Text = "0%",
                TextColor = 0xFF333333,
                TextAlignment = TextAlignment.Center,
            };
            ProgressControlView.AddChidren (btnMinBrightness);
 
            var f = new FrameLayout () {
                Width = Application.GetRealWidth (1200),
                Height = Application.GetRealHeight (80),
                X = btnMinBrightness.Right,
                Y = btnMinBrightness.Y,
            };
            ProgressControlView.AddChidren (f);
 
            horizontalSeekBar = new HorizontalSeekBar () {
                Height = LayoutParams.MatchParent,
                Gravity = Gravity.CenterVertical,
                Progress = device.CurtainProress,
                ProgressColor = SkinStyle.Current.SelectedColor,
                ThumbColor = 0xFFFFFFFF,
            };
            f.AddChidren (horizontalSeekBar);
 
            var btnMaxBrightness = new Button () {
                X = f.Right + Application.GetRealHeight (10),
                Y = btnMinBrightness.Y,
                Width = Application.GetRealWidth (120),
                Height = Application.GetRealHeight (80),
                TextAlignment = TextAlignment.CenterLeft,
                Text = "100%",
                TextColor = 0xFF333333,
            };
            ProgressControlView.AddChidren (btnMaxBrightness);
 
            horizontalSeekBar.ProgressChanged += (sender, e) => {
                btnCurrentStatus.Text = Language.StringByID(R.MyInternationalizationString.CurrentStatus) +" : "+ e.ToString () + "%";
                device.CurtainProress = (byte)e;
            };
            horizontalSeekBar.MouseDownEventHandler += (sender, e) => {
                stop ();
            };
 
            horizontalSeekBar.MouseUpEventHandler += (sender, e) => {
                Control.ControlBytesSend (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 17, Convert.ToByte (horizontalSeekBar.Progress) });
                btnCurrentStatus.Text = Language.StringByID(R.MyInternationalizationString.CurrentStatus) +" : "+ device.CurtainProress.ToString () + "%";
                th = new System.Threading.Thread ((obj) => {
                    //如果后面没有什么操作,到时自动还原接收更新状态
                    System.Threading.Thread.Sleep (20 * 1000);
                    th = null;
                });
                th.Start ();
            };
            #endregion
 
            btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = true;
                Control.ControlBytesSend (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, 2 });
                stop ();
                int startProgress = horizontalSeekBar.Progress;
                if (0 < device.Speed) {
                    th = new System.Threading.Thread ((obj) => {
                        var startDateTime = DateTime.Now;
                        while (curView != null) {
                            System.Threading.Thread.Sleep (200);
                            var v = startProgress - (int)((DateTime.Now - startDateTime).TotalMilliseconds * device.Speed);
                            v = v < 0 ? 0 : v;
                            Application.RunOnMainThread (() => {
                                horizontalSeekBar.Progress = v;
                                btnCurrentStatus.Text = Language.StringByID(R.MyInternationalizationString.CurrentStatus) +" : "+ v + "%";
                            });
                            if (v <= 0) {
                                break;
                            }
                        }
                        //防止跳动
                        System.Threading.Thread.Sleep (2000);
                        th = null;
                    });
                    th.Start ();
                } else {
                    readProgressDateTime = DateTime.Now;
                    //接近全开状态,这样初始化的值会是比较准确的
                    if (90 <= startProgress) {
                        intSpped (0);
                    }
                }
            };
            btnCloseCurtain.MouseUpEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = false;
            };
            btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = true;
                Control.ControlBytesSend (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, 1 });
                stop ();
                int startProgress = horizontalSeekBar.Progress;
                if (0 < device.Speed) {
                    th = new System.Threading.Thread ((obj) => {
                        var startDateTime = DateTime.Now;
                        while (curView != null) {
                            System.Threading.Thread.Sleep (200);
                            var v = startProgress + (int)((DateTime.Now - startDateTime).TotalMilliseconds * device.Speed);
                            v = 100 < v ? 100 : v;
                            Application.RunOnMainThread (() => {
                                horizontalSeekBar.Progress = v;
                                btnCurrentStatus.Text = Language.StringByID(R.MyInternationalizationString.CurrentStatus) +" : "+ v + "%";
                            });
                            if (100 <= v) {
                                break;
                            }
                        }
                        //防止跳动
                        System.Threading.Thread.Sleep (2000);
                        th = null;
                    });
                    th.Start ();
                } else {
                    readProgressDateTime = DateTime.Now;
                    //接近全关状态,这样初始化的值会是比较准确的
                    if (startProgress <= 10) {
                        intSpped (100);
                    }
                }
            };
            btnOpenCurtain.MouseUpEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = false;
            };
            btnStopCurtain.MouseDownEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = true;
                Control.ControlBytesSend (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, 0 });
                stop ();
            };
            btnStopCurtain.MouseUpEventHandler += (sender3, e3) => {
                (sender3 as Button).IsSelected = false;
            };
        }
 
        DateTime readProgressDateTime = System.DateTime.MaxValue;
        System.Threading.Thread th;
        void statrtReadProgress ()
        {
            int endProgress = 0;
            System.Threading.Tasks.Task.Run (() => {
                if (curtain.Type == DeviceType.CurtainRoller) {
                    var curtainroller = curtain as CurtainRoller;
                    Control.ControlBytesSend (Command.ReadCurtainStatus, curtainroller.SubnetID, curtainroller.DeviceID, new byte [] { 17 });
                } else if (curtain.Type == DeviceType.CurtainTrietex) {
                    var curtaintrietex = curtain as CurtainTrietex;
                    Control.ControlBytesSend (Command.ReadCurtainStatus, curtaintrietex.SubnetID, curtaintrietex.DeviceID, new byte [] { 17 });
                }
 
                while (curView != null) {
                    System.Threading.Thread.Sleep (300);
                    if (readProgressDateTime == DateTime.MaxValue) {
                        continue;
                    }
                    if (curtain.Type == DeviceType.CurtainRoller) {
                        var curtainroller = curtain as CurtainRoller;
                        if (curtainroller.CurtainProress != endProgress) {
                            endProgress = curtainroller.CurtainProress;
                            readProgressDateTime = DateTime.Now;
                        }
                        if ((DateTime.Now - readProgressDateTime).TotalMilliseconds < 1000) {
                            Control.ControlBytesSend (Command.ReadCurtainStatus, curtainroller.SubnetID, curtainroller.DeviceID, new byte [] { 17 }, SendCount.Zero);
                        } else {
                            readProgressDateTime = DateTime.MaxValue;
                        }
                    } else if (curtain.Type == DeviceType.CurtainTrietex) {
                        var curtaintrietex = curtain as CurtainTrietex;
                        if (curtaintrietex.CurtainProress != endProgress) {
                            endProgress = curtaintrietex.CurtainProress;
                            readProgressDateTime = DateTime.Now;
                        }
                        if ((DateTime.Now - readProgressDateTime).TotalMilliseconds < 1000) {
                            Control.ControlBytesSend (Command.ReadCurtainStatus, curtaintrietex.SubnetID, curtaintrietex.DeviceID, new byte [] { 17 }, SendCount.Zero);
                        } else {
                            readProgressDateTime = DateTime.MaxValue;
                        }
                    }
                }
            });
        }
 
        /// <summary>
        /// 结束值
        /// </summary>
        void intSpped (int v)
        {
            MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.Initiating));
            DateTime dateTime = DateTime.Now;
            System.Threading.Tasks.Task.Run (() => {
                while (curView != null) {
                    System.Threading.Thread.Sleep (500);
                    var bytes = Control.ControlBytesSendHasReturn (Command.ReadCurtainStatus, curtain.SubnetID, curtain.DeviceID, new byte [] { 17 });
                    if (bytes == null) {
                        break;
                    } else {
                        if (2 <= bytes.Length && v == bytes [1]) {
                            if (curtain.Type == DeviceType.CurtainRoller) {
                                (curtain as CurtainRoller).Speed = 100 / ((DateTime.Now - dateTime).TotalMilliseconds - 300);
                            } else if (curtain.Type == DeviceType.CurtainTrietex) {
                                (curtain as CurtainTrietex).Speed = 100 / ((DateTime.Now - dateTime).TotalMilliseconds - 300);
                            }
                            break;
                        }
                    }
                }
                Application.RunOnMainThread (() => {
                    MainPage.Loading.Hide ();
                });
            });
        }
 
        void stop ()
        {
            try {
                if (th != null) {
                    th.Abort ();
                    th = null;
                    //Control.ControlBytesSend (Command.ReadCurtainStatus, curtain.SubnetID, curtain.DeviceID, new byte [] { 17 });
                }
            } catch { }
        }
    }
}