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
using System;
namespace Shared.SimpleControl.Phone
{
    public class ACMethod
    {
 
        public byte SetACTemperatureText (byte [] setBytes, Button btnSetTemperature)
        {
            byte temperature = setBytes [11];
 
            btnSetTemperature.Text = temperature.ToString () + "°";
            if (setBytes [1] == 1) {
                btnSetTemperature.Text = btnSetTemperature.Text.Replace ('C', 'F');
            }
            return temperature;
        }
           
 
        public void UpdataACHostWindIcon (byte windByte, Button btn = null, Button btn2 = null)
        {
            switch (windByte) {
            case 0:
                if (btn != null)
                    btn.UnSelectedImagePath = "AC/ACAuto.png";
                if (btn2 != null)
                    btn2.TextID = R.MyInternationalizationString.Auto;
                break;
            case 3:
                if (btn != null)
                    btn.UnSelectedImagePath = "AC/ACLowWind.png";
                if (btn2 != null)
                    btn2.TextID = R.MyInternationalizationString.Low;
                break;
            case 2:
                if (btn != null)
                    btn.UnSelectedImagePath = "AC/ACStroke.png";
                if (btn2 != null)
                    btn2.TextID = R.MyInternationalizationString.Stroke;
                break;
            case 1:
                if (btn != null)
                    btn.UnSelectedImagePath = "AC/ACHighWind.png";
                if (btn2 != null)
                    btn2.TextID = R.MyInternationalizationString.High;
                break;
            }
        }
 
        public void UpdataACHostModeIcon (byte modeByte, Button btn = null, Button btn2 = null)
        {
            switch (modeByte) {
            case 0:
                if (btn != null)
                    btn.UnSelectedImagePath = "AC/ACRefrigeration.png";
                if (btn2 != null)
                    btn2.TextID = R.MyInternationalizationString.Cool;
                break;
            case 1:
                if (btn != null)
                    btn.UnSelectedImagePath = "AC/ACHeating.png";
                if (btn2 != null)
                    btn2.TextID = R.MyInternationalizationString.Heating;
                break;
            case 2:
                if (btn != null)
                    btn.UnSelectedImagePath = "AC/ACModeAuto.png";
                if (btn2 != null)
                    btn2.TextID = R.MyInternationalizationString.Ventila;
                break;
            case 3:
                if (btn != null)
                    btn.UnSelectedImagePath = "AC/ACAuto.png";
                if (btn2 != null)
                    btn2.TextID = R.MyInternationalizationString.Auto;
                break;
            case 4:
                if (btn != null)
                    btn.UnSelectedImagePath = "AC/ACDehumidification.png";
                if (btn2 != null)
                    btn2.TextID = R.MyInternationalizationString.Dehumidify;
                break;
            }
        }
 
        public void UpdataACModeTemperature (AC ac, byte modeByte, Button btn,bool showTempType = true)
        {
            switch (modeByte) {
            case 0:
                ac.SetTemperature = ac.CoolTemperature;
                break;
            case 1:
                ac.SetTemperature = ac.HeatTemperature;
                break;
            case 2:
                ac.SetTemperature = ac.CoolTemperature;
                break;
            case 3:
                ac.SetTemperature = ac.AutoTemperature;
                break;
            case 4:
                ac.SetTemperature = ac.ChuShiTemperature;
                break;
            }
            btn.Text = ac.SetTemperature.ToString () + "°";
            if (showTempType) {
                if (ac.TemperatureMode == 0) {
                    btn.Text = ac.SetTemperature.ToString () + "°C";
                } else {
                    btn.Text = ac.SetTemperature.ToString () + "°F";
                }
            }
        }
 
 
        /// <summary>
        /// 控制空调
        /// </summary>
        public void ControlAC (AC ac,bool onlyPower = false)
        {
            if (ac.Type == DeviceType.ACPanel) {
                byte modeKey = 4;
                switch (ac.SetMode) {
                //cooling
                case 0:
                    modeKey = 4;
                    break;
                //Heating
                case 1:
                    modeKey = 7;
                    break;
                //Fan
                case 2:
                    modeKey = 2;
                    break;
                //  Auto
                case 3:
                    modeKey = 8;
                    break;
                //Dry
                case 4:
                    modeKey = 19;
                    break;
                }
                if (!onlyPower) {
                    Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { modeKey, ac.SetTemperature, ac.LoopID });
                    Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 6, ac.SetMode, ac.LoopID });
                    Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 5, ac.SetFanSpeed, ac.LoopID });
                }
                Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 3, ac.Power, ac.LoopID });
            } else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.HVAC || ac.Type == DeviceType.ACInfrared) {
                Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new byte [] {ac.LoopID,ac.TemperatureMode,ac.IndoorTemperature,ac.CoolTemperature,ac.HeatTemperature,ac.AutoTemperature,
                ac.ChuShiTemperature,ac.RealModeAndFanSpeed,ac.Power,ac.SetMode,ac.SetFanSpeed,ac.SetTemperature,ac.ShaoFanMode});
            } else if (ac.Type == DeviceType.LongXiAC) {
                if ((ac as LongXiAC).LongXiDeviceType == 1 || (ac as LongXiAC).LongXiDeviceType == 2) {//新风
                    Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new byte [] {ac.LoopID,ac.TemperatureMode,ac.IndoorTemperature,ac.CoolTemperature,ac.HeatTemperature,ac.AutoTemperature,
                        ac.ChuShiTemperature,ac.RealModeAndFanSpeed,ac.Power,ac.SetMode,ac.SetFanSpeed,ac.SetTemperature,(ac as LongXiAC).Wave,0xAB,0xCD,
                        (ac as LongXiAC).ElectricHeating,(ac as LongXiAC).Antifreeze,0,0,0,0,0,0});
                    //var ac = common as LongXiAC;
                    //ac.TemperatureMode = usefullBytes [1];
                    //ac.IndoorTemperature = usefullBytes [2];
                    //ac.CoolTemperature = usefullBytes [3];
                    //ac.HeatTemperature = usefullBytes [4];
                    //ac.AutoTemperature = usefullBytes [5];
                    //ac.ChuShiTemperature = usefullBytes [6];
                    //ac.RealModeAndFanSpeed = usefullBytes [7];
                    //ac.Power = usefullBytes [8];
                    //ac.SetMode = usefullBytes [9];
                    //ac.SetFanSpeed = usefullBytes [10];
                    //ac.Wave = usefullBytes [12];
                    //if (usefullBytes.Length == 23) {//首城珑玺定制的新风空调固件是不一样的
                    //    ac.ElectricHeating = usefullBytes [15];
                    //    ac.Antifreeze = usefullBytes [16];
                    //    ac.OutTemp = usefullBytes [17];
                    //    ac.Humidity = usefullBytes [18];
                    //    ac.TVOC = usefullBytes [19 * 256] + usefullBytes [20];
                    //    ac.PM25 = usefullBytes [21 * 256] + usefullBytes [22];
                    //}
                } else  {//二次过滤if ((ac as LongXiAC).LongXiDeviceType == 3 || (ac as LongXiAC).LongXiDeviceType == 4)
                    Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new byte [] {ac.LoopID,ac.TemperatureMode,ac.IndoorTemperature,ac.CoolTemperature,ac.HeatTemperature,ac.AutoTemperature,
                        ac.ChuShiTemperature,ac.RealModeAndFanSpeed,ac.Power,ac.SetMode,ac.SetFanSpeed,ac.SetTemperature,0});
                }
            }
        }
 
    }
}