lss
2020-05-20 a6c8525a85eae4c64b90b651d42b6c1f6d0df90f
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
using System;
using System.Collections.Generic;
using Shared.Common;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.SmartSound
{
    public class SmartSoundControlForm : EditorCommonForm
    {
        private SmartSound mSmartSound;
 
        public SmartSoundControlForm()
        {
        }
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            // iniData();//先加载模拟数据
 
            this.ScrollEnabled = false;
           
            //设置标题信息
            base.SetTitleText("语音控制");
 
            //右上添加按钮
            var btnAddDeviceIcon = new MostRightIconControl(69, 69);
            btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png";
            topFrameLayout.AddChidren(btnAddDeviceIcon);
            btnAddDeviceIcon.InitControl();
            btnAddDeviceIcon.ButtonClickEvent += (sender, e) =>
            {
                iniView();
            };
 
            //初始化中部控件
            //this.InitMiddleFrame();
 
        }
 
        /// <summary>
        /// 将数据转换为智能音箱使用的数据
        /// </summary>
        private void iniData(bool isAdd)
        {
            //1.从服务器获取的数据,json反序列化得来
            //2.点击"+"将网关的数据转换为 智能音箱使用的数据
            /*{
 
                Dictionary<string, string> ss = Config.Instance.Home.FloorDics;//楼层列表
                string currentFloor = Config.Instance.Home.CurrentFloorId;//当前楼层的键
 
                var listRoom = HdlRoomLogic.Current.GetFloorSortRoom("楼层的主键");//获取当前楼层的所有房间
                var room = listRoom[0];
                for (int i=0;i<room.ListDevice.Count;i++)
                {//设备数据
                    var device = LocalDevice.Current.GetDevice(room.ListDevice[i]);
                    var myType = LocalDevice.Current.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device });                                      
 
                    if (myType.BeloneType == DeviceBeloneType.A灯光)
                    {
                        //这里面的就是灯光了
                        var light = device;
                        // light.DeviceAddr;  设备的地址
                        // light.DeviceEpoint;//设备的端口
                    }
                }
 
                for (int i = 0; i < room.ListSceneId.Count; i++)
                {   //场景数据
                    var device = HdlSceneLogic.Current.GetSceneUIBySceneId(room.ListSceneId[i]);
                    // device.Id;场景 id
                }
            }*/
 
            if (isAdd)
            {
                mSmartSound = new SmartSound();
                mSmartSound.HomeID = Config.Instance.Home.Id;
                mSmartSound.UserID = Config.Instance.Guid;
 
                Dictionary<string, string> floorDictionary = Config.Instance.Home.FloorDics;//楼层列表
 
                if (floorDictionary.Count < 1)
                {
                    //没有楼层,模拟一个
                    SmartSound.Layer layer = new SmartSound.Layer();
                    layer.LayerID = "0000";
                    layer.LayerName = "一楼";
                    layer.RoomList.Clear();
 
                    //添加房间
                    SmartSound.Room smartRoom = null;
                    var roomList = HdlRoomLogic.Current.GetAllListRooms();
                    for (int i = 0; i < roomList.Count; i++)
                    {
                        Room room = roomList[i];
                        smartRoom = new SmartSound.Room();
                        layer.RoomList.Add(smartRoom);
 
                        smartRoom.RoomID = room.Id;
                        smartRoom.RoomName = room.Name;
                        smartRoom.DeviceList.Clear();
                        smartRoom.SceneList.Clear();
 
                        //添加设备  // 灯光、窗帘、场景、空调
                        for (int j = 0; j < room.ListDevice.Count; j++)
                        {
                            string key = room.ListDevice[j].ToString();
                            var device = LocalDevice.Current.GetDevice(key);
 
                            SmartSound.Device smartDevice = new SmartSound.Device();
                            smartDevice.Id = device.DeviceID.ToString();//设备 Id
                            smartDevice.DeviceAddress = device.DeviceAddr;//设备 MAC
                            smartDevice.Epoint = device.DeviceEpoint;//设备端口
                            smartDevice.ClusterID = 0;
                            smartDevice.DeviceName = device.DeviceName;//设备名称
                            smartDevice.NicksName = "";
                            smartDevice.DeviceType = getDeviceType(device);//设备类型
                            smartDevice.GatewayID = device.CurrentGateWayId;//网关 Id
                            smartDevice.RoomID = room.Id;//房间 Id
 
                            smartRoom.DeviceList.Add(smartDevice);
                                                       
                        }
 
                        var sceneList = HdlSceneLogic.Current.GetRoomSceneList(room);
                        //添加场景
                        for (int j = 0; j < sceneList.Count; j++)
                        {
                            SceneUI scene = sceneList[j];
                            SmartSound.Scene smartScene = new SmartSound.Scene();
                            smartScene.Id = scene.DeviceID.ToString();
                            smartScene.SceneName = scene.Name;
                            smartScene.SceneID = scene.Id;
                            smartScene.DelayTime = scene.DelayTime;
                            smartScene.ClusterID = 0;
                            smartScene.NicksName = "";
                            smartScene.RoomID = room.Id;
 
                            smartRoom.SceneList.Add(smartScene);
                        }
                    }
                }
            }
        }
 
        /// <summary>
        /// Zigbee设备类型转换为智能音箱使用的类型
        /// </summary>
        /// <returns></returns>
        private int getDeviceType(ZigBee.Device.CommonDevice device)
        {
            int type = 0;//1=开关灯,2=调光灯,3=RGB 灯,4=窗帘模块,5=开合帘,6=卷帘,7=空调,8=面板,9=新风
 
            if (device.Type == DeviceType.OnOffOutput && device.DfunctionType == DeviceFunctionType.A灯光)
            {
                type = 1;//这里面的就是继电器灯光了
            }
            else if (device.Type == DeviceType.DimmableLight)
            {
                type = 2;//调光
            }
            else if (device.Type == DeviceType.ColorDimmableLight)
            {
                type = 3;
            }
            else if (device.Type == DeviceType.WindowCoveringDevice)
            {
                //窗帘
                if (((Rollershade)device).WcdType == 4)//开合帘
                {
                    type = 5;
                }
                else if (((Rollershade)device).WcdType == 0)//卷帘
                    type = 6;//卷帘
            }
            else if (device.Type == DeviceType.Thermostat)
            {
                type = 7;
            }
            else if (device.Type == DeviceType.FreshAir)
            {
                type = 9;
            }
 
            return type;
        }
 
        private void iniView()
        {
            //房间列表行{房间列表 textView,楼层下拉窗}
            //显示房间{带选择框的;当选中了房间后需要在底部弹出确认按钮,点击确认跳转到新的界面}
            var frame = new TopRightMenuControl(2, 2);
            //创建楼层
            frame.AddRowMenu(Language.StringByID(R.MyInternationalizationString.uCreatFloor), "Item/CreatFloor.png", "Item/CreatFloorSelected.png", () =>
            {
                //创建楼层
                //this.CreatOrEditorFloor(null, null, string.Empty, string.Empty);
            });
            //创建房间
            frame.AddRowMenu(Language.StringByID(R.MyInternationalizationString.uCreatRoom), "Item/RoomIcon.png", "Item/RoomIconSelected.png", () =>
            {
                /*var form = new AddNewRoomForm();
                form.AddForm(string.Empty);
                form.FinishEditorEvent += () =>
                {
                    //根据指定模式,初始化桌布控件
                    this.InitFrameTableByMode();
                };*/
            });
        }
    }
}