private void ShowSceneZone(SceneZone z) { _initializing = true; for (int i = 0; i < 12; i++) { ShowDoor(z.DoorOf(i), i); } _initializing = false; }
// 显示当前场景. private void ShowScene(Scene s) { _initializing = true; ResetSceneZone(); _selected_scene = s; _pre_selected_zone = -1; _selected_zone = null; cl_zone.SelectedIndex = -1; for (int i = 0; i < cl_zone.Items.Count; i++) { cl_zone.SetItemChecked(i, false); } if (s != null && s.Zones != null) foreach (SceneZone sz in s.Zones) { cl_zone.SetItemChecked(sz.Index, sz.Enabled); } _initializing = false; }
// Selected Index. private void cl_zone_SelectedIndexChanged(object sender, EventArgs e) { if (_initializing) return; int zid = cl_zone.SelectedIndex; // if (zid < 0) return; bool isChecked = cl_zone.GetItemChecked(zid); if (_pre_selected_zone == zid) { return; } _pre_selected_zone = zid; // log.DebugFormat("Selected Item {0} - {1}", zid, isChecked); _selected_zone = _selected_scene.ZoneAt(zid); ShowSceneZone(_selected_zone); }
private void SendSceneZone(SceneZone z) { int zcnt = 6; foreach (ZoneDoor d in z.Doors) { if (!d.Enabled) continue; // Switch int reg = z.Index + zcnt * OFFSET_SWITCH + REG_START; //开门. MBMessage req = NewWriteCoil((ushort)(reg << 4 | d.Index), d.SwitchOn); MBMessage resp = SendRequest(req); // Green reg = z.Index + zcnt * OFFSET_GREEN + REG_START; //绿灯 req = NewWriteCoil((ushort)(reg << 4 | d.Index), d.GreenOn); resp = SendRequest(req); // Red reg = z.Index + zcnt * OFFSET_GREEN + REG_START; //红灯. req = NewWriteCoil((ushort)(reg << 4 | d.Index), d.RedOn); resp = SendRequest(req); } }
/// Get Zone at [index] public SceneZone ZoneAt(int zid) { if (Zones == null) { Zones = new List<SceneZone>(); } foreach (SceneZone sz in Zones) { if (sz.Index == zid) { return sz; } } SceneZone zi = new SceneZone() { Index = zid }; Zones.Add(zi); return zi; }