public ActionResult On(Device device)
 {
     SlapsteonFacade facade = new SlapsteonFacade();
     facade.On(device.Name);
     device.Status = 100;
     return RedirectToAction("Index", "Home");
 }
        public LightOffTimer(Device device, TimeSpan duration, DeviceTimerCallBack timerCallback)
        {
            _device = device;
            _duration = duration;
            _timerCallback = timerCallback;

            _lightTimer = new Timer(_duration.TotalMilliseconds);
        }
        public void ProcessSendingRelatedEvents(byte command1, Device sourceDevice)
        {
            log.InfoFormat("Processing related device events for 0x{0} for device {1}", command1.ToString("X"), sourceDevice.Name);

            // if we're turning a light on via API, arm any timers, update KPL buttons, etc
            foreach (string i in _allDevices.Keys)
            {
                // only really care about updating KPL buttons
                if (!(_allDevices[i] is IMultiButtonDevice)) continue;

                IMultiButtonDevice kplDevice = _allDevices[i] as IMultiButtonDevice;

                // ignore this change if it will be triggered by a slave device command
                if (sourceDevice.SlaveDevices.Contains(_allDevices[i])) continue;

                DeviceALDB devALDB = _aldbLibrary.Devices.FirstOrDefault(d => d.DeviceAddress == _allDevices[i].Address.ToString());

                if (null == devALDB)
                    continue;

                // go thru each device looking for responders
                foreach (ALDBRecord record in devALDB.ALDBRecords)
                {
                    // record not active
                    if ((record.Flags & 0x80) == 0)
                        continue;

                    if ((record.Flags & 0x40) == 0 && // responder
                            record.AddressToString() == sourceDevice.Address.ToString())
                    {
                        // only need to worry about group 1 since this is sent from single group devices...
                        if (record.Group != 0x01) continue;

                        // set timers
                        if (_allDevices[i].DefaultOffMinutes.HasValue && (command1 == Constants.STD_COMMAND_FAST_ON || command1 == Constants.STD_COMMAND_ON))
                        {
                            log.InfoFormat("Setting off timer for responder {0} for {1} minutes", _allDevices[i].Name, _allDevices[i].DefaultOffMinutes.Value);
                            _allDevices[i].SetTimer(new DeviceTimerCallBack(DeviceTimerCallBack));
                        }

                        // local data says what button to turn off
                        byte flipMask = 0xFF;
                        switch (record.LocalData3)
                        {
                            case 0x03:
                                flipMask = 0x04;
                                break;
                            case 0x04:
                                flipMask = 0x08;
                                break;
                            case 0x05:
                                flipMask = 0x10;
                                break;
                            case 0x06:
                                flipMask = 0x20;
                                break;
                            default:
                                break;
                        }

                        if (command1 == Constants.STD_COMMAND_ON || command1 == Constants.STD_COMMAND_FAST_ON)
                        {
                            kplDevice.KPLButtonMask |= flipMask;
                        }
                        else if (command1 == Constants.STD_COMMAND_OFF || command1 == Constants.STD_COMMAND_FAST_OFF)
                        {
                            kplDevice.KPLButtonMask &= (byte)(0xFF ^ flipMask);
                        }
                        log.InfoFormat("Updated Button Mask to {0} for device {1}", kplDevice.KPLButtonMask.ToString("X"), _allDevices[i].Name);

                        Thread.Sleep(500);
                        SendExtendedCommand(_allDevices[i].Address, Constants.EXT_COMMAND_EXTENDED_GET_SET, 0x00, 0x1F, false, record.LocalData2, 0x09, kplDevice.KPLButtonMask, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                    }
                }
            }
        }
        private void DeviceTimerCallBack(Device device)
        {
            SlapsteonEventLog.AddLogEntry(new SlapsteonEventLogEntry(device.Name,
                string.Format("Turned off by timer.")));

            device.Status = 0;
            device.LastOff = DateTime.Now;
            this.SendStandardCommand(device.Address, Constants.STD_COMMAND_FAST_OFF, 0x00, 0x0F);
            this.ProcessSendingRelatedEvents(Constants.STD_COMMAND_FAST_OFF, device);
        }
 public ActionResult SetPointUp(Device device)
 {
     SlapsteonFacade facade = new SlapsteonFacade();
     facade.SetPointUp(device.Name);
     return RedirectToAction("Index", "Home");
 }
 public ActionResult Refresh(Device device)
 {
     return PartialView(device);
 }
Beispiel #7
0
        private void dgvDevices_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                // index didn't change
                if (e.RowIndex == _deviceSelectedIndex)
                    return;

                _deviceSelectedIndex = e.RowIndex;

                _selectedDevice = _allDevices.First(d => d.AddressString == dgvDevices.Rows[e.RowIndex].Cells["AddressString"].Value.ToString());

                lblName.Text = _selectedDevice.Name;
                lblAddress.Text = _selectedDevice.AddressString;
            }
            catch (Exception ex)
            {

            }
        }