1
wxr
2023-03-31 7e42cc13a14b7de31c9f5d5c61cdf24f3246335d
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
using Shared.SimpleControl.Phone;
using System;
namespace Shared.SimpleControl.Pad
{
    public class UserFan : FrameLayout
    {
        public static UserFan curView;
        FrameLayout speedView;
        Button btnBottomSwitch;
        Button btnSwitch;
        FanModule fanModule;
        public UserFan (FanModule fan)
        {
            curView = this;
            fanModule = fan;
            showLightsRoom ();
             BackgroundColor = 0xFF2f2f2f;
        }
 
        public void showLightsRoom ()
        {
            var roomBackgroundImage = new FrameLayout () {
                Height = Application.GetRealHeight (Application.DesignHeight),
                BackgroundImagePath = "Fan/FanSpeedBackground.png"
            };
            AddChidren (roomBackgroundImage);
 
            int padX = 570;
 
            speedView = new FrameLayout () {
                X = Application.GetRealWidth (padX - 70),
                Y = Application.GetRealHeight (100),
                Width = Application.GetRealWidth (500),
                Height = Application.GetRealHeight (500),
                BackgroundImagePath = "Fan/Speed0.png",
            };
            roomBackgroundImage.AddChidren (speedView);
 
            Button btnSpeed8 = new Button () {
                X = Application.GetRealWidth (100),
                Y = Application.GetRealHeight (20),
                Width = Application.GetRealWidth (140),
                Height = Application.GetRealHeight (90),
                Radius = 5,
            };
            speedView.AddChidren (btnSpeed8);
            btnSpeed8.MouseDownEventHandler += (sender, e) => {
                fanModule.WindSpeed = 8;
                Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                          new byte [] { fanModule.LoopID, 8 });
                speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
            };
 
            Button btnSpeed1 = new Button () {
                X = btnSpeed8.Right + Application.GetRealWidth (20),
                Y = btnSpeed8.Y,
                Width = Application.GetRealWidth (140),
                Height = Application.GetRealHeight (90),
                Radius = 5,
            };
            speedView.AddChidren (btnSpeed1);
            btnSpeed1.MouseDownEventHandler += (sender, e) => {
                fanModule.WindSpeed = 1;
                Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                          new byte [] { fanModule.LoopID, 1 });
                speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
            };
 
            Button btnSpeed2 = new Button () {
                X = Application.GetRealWidth (380),
                Y = Application.GetRealHeight (130),
                Width = Application.GetRealWidth (105),
                Height = Application.GetRealHeight (105),
                Radius = 5,
            };
            speedView.AddChidren (btnSpeed2);
            btnSpeed2.MouseDownEventHandler += (sender, e) => {
                fanModule.WindSpeed = 2;
                Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                          new byte [] { fanModule.LoopID, 2 });
                speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
            };
 
            Button btnSpeed3 = new Button () {
                X = Application.GetRealWidth (380),
                Y = btnSpeed2.Bottom + Application.GetRealHeight (20),
                Width = Application.GetRealWidth (105),
                Height = Application.GetRealHeight (105),
                Radius = 5,
            };
            speedView.AddChidren (btnSpeed3);
            btnSpeed3.MouseDownEventHandler += (sender, e) => {
                fanModule.WindSpeed = 3;
                Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                          new byte [] { fanModule.LoopID, 3 });
                speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
            };
            Button btnSpeed4 = new Button () {
                X = btnSpeed1.X,
                Y = btnSpeed3.Bottom + Application.GetRealHeight (20),
                Width = Application.GetRealWidth (140),
                Height = Application.GetRealHeight (90),
                Radius = 5,
            };
            speedView.AddChidren (btnSpeed4);
            btnSpeed4.MouseDownEventHandler += (sender, e) => {
                fanModule.WindSpeed = 4;
                Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                          new byte [] { fanModule.LoopID, 4 });
                speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
            };
            Button btnSpeed5 = new Button () {
                X = btnSpeed8.X,
                Y = btnSpeed4.Y,
                Width = Application.GetRealWidth (140),
                Height = Application.GetRealHeight (90),
                Radius = 5,
            };
            speedView.AddChidren (btnSpeed5);
            btnSpeed5.MouseDownEventHandler += (sender, e) => {
                fanModule.WindSpeed = 5;
                Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                          new byte [] { fanModule.LoopID, 5 });
                speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
            };
            Button btnSpeed6 = new Button () {
                X = Application.GetRealWidth (20),
                Y = btnSpeed3.Y,
                Width = Application.GetRealWidth (105),
                Height = Application.GetRealHeight (105),
                Radius = 5,
            };
            speedView.AddChidren (btnSpeed6);
            btnSpeed6.MouseDownEventHandler += (sender, e) => {
                fanModule.WindSpeed = 6;
                Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                          new byte [] { fanModule.LoopID, 6 });
                speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
            };
            Button btnSpeed7 = new Button () {
                X = Application.GetRealWidth (20),
                Y = btnSpeed2.Y,
                Width = Application.GetRealWidth (105),
                Height = Application.GetRealHeight (105),
                Radius = 5,
            };
            speedView.AddChidren (btnSpeed7);
            btnSpeed7.MouseDownEventHandler += (sender, e) => {
                fanModule.WindSpeed = 7;
                Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                          new byte [] { fanModule.LoopID, 7 });
                speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
            };
 
            btnSwitch = new Button () {
                Gravity = Gravity.Center,
                Width = Application.GetMinRealAverage (260),
                Height = Application.GetMinRealAverage (260),
                SelectedImagePath = "Fan/FanIconSwitchOn.png",
                UnSelectedImagePath = "Fan/FanIconSwitch.png",
                Radius = (uint)Application.GetMinRealAverage(100),
                IsSelected = false
            };
            speedView.AddChidren (btnSwitch);
 
            btnBottomSwitch = new Button () {
                X = Application.GetRealWidth (620),
                Y = speedView.Bottom + Application.GetRealHeight (250),
                Width = Application.GetRealWidth (215),
                Height = Application.GetRealHeight (95),
                SelectedImagePath = "Fan/FanSwitchOn.png",
                UnSelectedImagePath = "Fan/FanSwitch.png",
                IsSelected = false
            };
            AddChidren (btnBottomSwitch);
 
            btnSwitch.MouseDownEventHandler += (sender, e) => {
                if (btnSwitch.IsSelected) {
                    btnBottomSwitch.IsSelected = false;
                    btnSwitch.IsSelected = false;
                    Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                               new byte [] { fanModule.LoopID, 0 });
                    fanModule.Switch = fanModule.WindSpeed;
                    speedView.BackgroundImagePath = "Fan/Speed0.png";
                } else {
                    btnSwitch.IsSelected = true;
                    btnBottomSwitch.IsSelected = true;
                    Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                              new byte [] { fanModule.LoopID, fanModule.Switch });
                    speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
                }
                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
            };
 
            btnBottomSwitch.MouseDownEventHandler += (sender, e) => {
                if (btnBottomSwitch.IsSelected) {
                    btnBottomSwitch.IsSelected = false;
                    btnSwitch.IsSelected = false;
                    Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                               new byte [] { fanModule.LoopID, 0 });
                    fanModule.Switch = fanModule.WindSpeed;
                    speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
                } else {
                    btnBottomSwitch.IsSelected = true;
                    btnSwitch.IsSelected = true;
                    Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                              new byte [] { fanModule.LoopID, fanModule.Switch });
                    speedView.BackgroundImagePath = "Fan/Speed" + fanModule.WindSpeed.ToString () + ".png";
                }
                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
            };
            Control.ControlBytesSend (Command.ReadLightEquipmentAllLoopBrightness, fanModule.SubnetID, fanModule.DeviceID,
                                     new byte [] { });
        }
 
        public static void UpdataFanView (string updataFlag, byte windSpeed)
        {
            Application.RunOnMainThread (() => {
                if (curView == null)
                    return;
                if (curView.fanModule.CommonLoopID != updataFlag)
                    return;
                if (windSpeed == 0) {
                    curView.btnBottomSwitch.IsSelected = false;
                    curView.btnSwitch.IsSelected = false;
                    curView.speedView.BackgroundImagePath = "Fan/Speed" + windSpeed.ToString () + ".png";
                } else {
                    curView.btnBottomSwitch.IsSelected = true;
                    curView.btnSwitch.IsSelected = true;
                    curView.speedView.BackgroundImagePath = "Fan/Speed" + windSpeed.ToString () + ".png";
                }
            });
        }
    }
}