HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-12-30 3dcbd186c42c598c0c08d1cd37034cf2baa09e54
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
using System.Threading.Tasks;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// PIR传感器的逻辑
    /// </summary>
    public class HdlDevicePirSensorLogic
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// PIR传感器的逻辑
        /// </summary>
        private static HdlDevicePirSensorLogic m_Current = null;
        /// <summary>
        /// PIR传感器的逻辑
        /// </summary>
        public static HdlDevicePirSensorLogic Current
        {
            get
            {
                if (m_Current == null)
                {
                    m_Current = new HdlDevicePirSensorLogic();
                }
                return m_Current;
            }
        }
        #endregion
 
        #region ■ 光感等级总刻度_____________________
 
        /// <summary>
        /// 获取PIR传感器的【光感等级总刻度】,错误时返回-1
        /// </summary>
        /// <param name="iASZone"></param>
        /// <returns></returns>
        public async Task<int> GetPirLightAbilitySize(IASZone iASZone)
        {
            var data = await iASZone.GetPIRLightAbilitySizeAsync();
            //共通错误检测
            string error = HdlCheckLogic.Current.CheckCommonErrorCode(data);
            if (error != null)
            {
                this.ShowErrorMsg(error);
                return -1;
            }
 
            if (data == null || data.errorMessageBase != null || data.LightLevelCount == -1)
            {
                //获取传感器光感等级失败
                string msg = Language.StringByID(R.MyInternationalizationString.uGetPirSensorLightPerceptionRegulationFail);
                //拼接上【网关回复超时】的Msg
                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, data);
 
                this.ShowErrorMsg(msg);
                return -1;
            }
 
            return data.LightLevelCount;
        }
 
        #endregion
 
        #region ■ 获取配置信息_______________________
 
        /// <summary>
        /// 获取PIR传感器的【配置信息】,错误时返回null
        /// </summary>
        /// <param name="iASZone"></param>
        /// <returns></returns>
        public async Task<IASZone.ConfigureParamates> GetPirSensorLightSettion(IASZone iASZone)
        {
            var data = await iASZone.GetPIRSensorParamateAsync();
            if (data == null || data.configureParamates == null)
            {
                //获取传感器设置信息失败
                string msg = Language.StringByID(R.MyInternationalizationString.uGetPirSensorSettionFail);
                //拼接上【网关回复超时】的Msg
                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, data);
 
                this.ShowErrorMsg(msg);
                return null;
            }
            return data.configureParamates;
        }
 
        #endregion
 
        #region ■ 设置配置信息_______________________
 
        /// <summary>
        /// 设置PIR传感器的【配置信息】
        /// </summary>
        /// <param name="iASZone">传感器对象</param>
        /// <param name="configure">灯光配置</param>
        /// <returns></returns>
        public async Task<bool> SetPirSensorSettion(IASZone iASZone, IASZone.ConfigureParamates configure)
        {
            var result = await iASZone.SetPIRSensorParamateAsync(configure);
            if (result == null || result.responseData == null)
            {
                //设置传感器配置信息失败
                string msg = Language.StringByID(R.MyInternationalizationString.uSetPirSensorSettionFail);
                //拼接上【网关回复超时】的Msg
                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result);
 
                this.ShowErrorMsg(msg);
                return false;
            }
            if (result.responseData.status != 0)
            {
                //设置传感器配置信息失败
                string msg = Language.StringByID(R.MyInternationalizationString.uSetPirSensorSettionFail);
                this.ShowErrorMsg(msg);
                return false;
            }
            //备份设置
            await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(iASZone, GatewayBackupEnum.APir灯光配置, configure);
 
            return true;
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 显示错误信息窗口
        /// </summary>
        /// <param name="msg"></param>
        private void ShowErrorMsg(string msg)
        {
            Application.RunOnMainThread(() =>
            {
                var contr = new ShowMsgControl(ShowMsgType.Error, msg);
                contr.Show();
            });
        }
 
        /// <summary>
        /// 显示Tip信息窗口
        /// </summary>
        /// <param name="msg"></param>
        private void ShowTipMsg(string msg)
        {
            Application.RunOnMainThread(() =>
            {
                var contr = new UserCenter.ShowMsgControl(ShowMsgType.Tip, msg);
                contr.Show();
            });
        }
 
        #endregion
    }
}