private static void internalCallback(DeviceEventType eventType, IntPtr deviceInfo)
        {
            Console.WriteLine("Internal callback");
            var dev = (DeviceInfo)Marshal.PtrToStructure(
                deviceInfo,
                typeof(DeviceInfo));

            DeviceEvent?.Invoke(eventType, dev);
        }
Esempio n. 2
0
        static void device_event_cb(DeviceEventType eventType, DeviceInfo deviceInfo)
        {
            Console.WriteLine($"Device event cb called with: {eventType} {deviceInfo}");

            if (eventType == DeviceEventType.Connected)
            {
                Console.WriteLine($"Attempted read analog in callback, got value: {WootingAnalogSDK.ReadAnalog(30)}");
            }

            Console.WriteLine("Attempting to read connected devices in callback");
            var(devices, infoErr) = WootingAnalogSDK.GetConnectedDevicesInfo();
            foreach (DeviceInfo device in devices)
            {
                Console.WriteLine($"Device info has: {device}, {infoErr}");
            }
            Console.WriteLine("Finished attempting to read connected devices in callback");
        }
Esempio n. 3
0
        private async void IInitDevice(DeviceID id, DeviceEventType e, HidDevice hid = null)
        {
            ResponseDevice device = DeviceFactory.Create(id);

            if (device != null)
            {
                m_log.Trace("ResponseDevice detected...");
                if (hid == null)
                {
                    HidDeviceLoader loader = new HidDeviceLoader();
                    for (int i = 0; i < 10; i++)
                    {
                        hid = loader.GetDeviceOrDefault(vendorID: id.Vendor, productID: id.Product);
                        if (hid == null)
                        {
                            m_log.Trace("... HID device matching USB insert not found, retrying in 50ms");
                            Thread.Sleep(50); // :(
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (hid == null)
                    {
                        m_log.Warn("Could not find HID device [V:{0:X}] [P:{1:X}] [S:{2}] after USB insert", id.Vendor, id.Product, id.Serial);
                        return;
                    }
                }
                m_log.Info("Discovered `{0}` [V:{1:X}] [P:{2:X}] [S:{3}]", hid.ProductName, id.Vendor, id.Product, id.Serial);
                if (await device.Initialize(hid))
                {
                    m_devices.Add(id, device);
                    DeviceDiscovered?.Invoke(this, new DeviceEventArgs(device, e));
                }
                else
                {
                    m_log.Warn("Failed to init `{0}` [V:{1:X}] [P:{2:X}] [S:{3}]", hid.ProductName, id.Vendor, id.Product, id.Serial);
                }
            }
        }
Esempio n. 4
0
        public static DeviceEvent InsertDeviceEvent(
            this IDbConnection connection,
            IDbTransaction transaction,
            Guid deviceId,
            DeviceEventType eventType,
            string message)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            var deviceEvent = new DeviceEvent
            {
                DeviceId  = deviceId,
                EventType = eventType,
                Message   = message
            }.SetNew();

            connection.Insert(deviceEvent, transaction);

            return(deviceEvent);
        }
Esempio n. 5
0
        public bool Matches(DeviceEventType eventType)
        {
            var result = EventTypes.Contains(eventType);

            return(result);
        }
Esempio n. 6
0
 public DeviceEventAction(DeviceEventType eventType, ScriptCommandList commands)
     : this(new[] { eventType }, commands)
 {
 }
Esempio n. 7
0
 public bool HasType(DeviceEventType type)
 {
     return((Actions & type) == type);
 }
Esempio n. 8
0
        public async Task <DeviceConfig> SaveDeviceAsync(DeviceConfig model)
        {
            Device dbDevice = null;

            var transaction = await context.Database.BeginTransactionAsync();

            if (string.IsNullOrEmpty(model.DeviceId))
            {
                dbDevice = new Device
                {
                    Name      = model.Name,
                    IsEnabled = model.IsEnabled
                };

                await context.Device.AddAsync(dbDevice);
            }
            else
            {
                dbDevice = await context.Device.FirstOrDefaultAsync(d => d.DeviceId == Guid.Parse(model.DeviceId));

                if (dbDevice == null)
                {
                    throw new ApplicationException($"Device with id {model.DeviceId.ToString()} was not found.");
                }

                dbDevice.Name      = model.Name;
                dbDevice.IsEnabled = model.IsEnabled;

                context.Device.Update(dbDevice);
            }

            try
            {
                await context.SaveChangesAsync();
            }
            catch (System.Exception)
            {
                transaction.Rollback();
                throw;
            }

            context.DeviceSensor.RemoveRange(context.DeviceSensor.Where(ds => !model.Sensors.Any(s => s.DeviceSensorId == ds.DeviceSensorId)));
            await context.SaveChangesAsync();

            foreach (var sensor in model.Sensors)
            {
                DeviceSensor dbDeviceSensor = null;
                if (sensor.DeviceSensorId.HasValue)
                {
                    dbDeviceSensor = await context.DeviceSensor.FirstOrDefaultAsync(ds => ds.DeviceSensorId == sensor.DeviceSensorId);

                    dbDeviceSensor.IsEnabled = sensor.IsEnabled;
                    context.DeviceSensor.Update(dbDeviceSensor);
                }
                else
                {
                    dbDeviceSensor           = new DeviceSensor();
                    dbDeviceSensor.DeviceId  = dbDevice.DeviceId;
                    dbDeviceSensor.SensorId  = sensor.SensorId;
                    dbDeviceSensor.IsEnabled = sensor.IsEnabled;
                    await context.DeviceSensor.AddAsync(dbDeviceSensor);
                }
            }

            context.DeviceEventType.RemoveRange(context.DeviceEventType.Where(de => !model.Events.Any(e => e.DeviceEventTypeId == de.DeviceEventTypeId)));
            await context.SaveChangesAsync();

            foreach (var eventType in model.Events)
            {
                DeviceEventType dbDeviceEventType = null;
                if (eventType.DeviceEventTypeId.HasValue)
                {
                    dbDeviceEventType = await context.DeviceEventType.FirstOrDefaultAsync(de => de.DeviceEventTypeId == eventType.DeviceEventTypeId);

                    dbDeviceEventType.IsEnabled = eventType.IsEnabled;
                    context.DeviceEventType.Update(dbDeviceEventType);
                }
                else
                {
                    dbDeviceEventType             = new DeviceEventType();
                    dbDeviceEventType.DeviceId    = dbDevice.DeviceId;
                    dbDeviceEventType.EventTypeId = eventType.EventTypeId;
                    dbDeviceEventType.IsEnabled   = eventType.IsEnabled;
                    await context.DeviceEventType.AddAsync(dbDeviceEventType);
                }
            }

            context.DeviceState.RemoveRange(context.DeviceState.Where(ds => !model.States.Any(e => e.DeviceStateId == ds.DeviceStateId)));
            await context.SaveChangesAsync();

            foreach (var state in model.States)
            {
                DeviceState dbDeviceState = null;
                if (state.DeviceStateId.HasValue)
                {
                    dbDeviceState = await context.DeviceState.FirstOrDefaultAsync(ds => ds.DeviceStateId == state.DeviceStateId);

                    dbDeviceState.IsEnabled = state.IsEnabled;
                    context.DeviceState.Update(dbDeviceState);
                }
                else
                {
                    dbDeviceState           = new DeviceState();
                    dbDeviceState.DeviceId  = dbDevice.DeviceId;
                    dbDeviceState.StateId   = state.StateId;
                    dbDeviceState.IsEnabled = state.IsEnabled;
                    await context.DeviceState.AddAsync(dbDeviceState);
                }
            }

            try
            {
                await context.SaveChangesAsync();
            }
            catch (Exception)
            {
                transaction.Rollback();
                throw;
            }

            transaction.Commit();

            return(await GetDeviceByIdAsync(dbDevice.DeviceId.ToString()));
        }
Esempio n. 9
0
 // Our callback function which will print out whenever a Device has been connected or disconnected
 static void callback(DeviceEventType eventType, DeviceInfo deviceInfo)
 {
     Console.WriteLine($"Device event cb called with: {eventType} {deviceInfo}");
 }
Esempio n. 10
0
 public DeviceEventArgs(ResponseDevice d, DeviceEventType e)
 {
     Device = d;
     Event  = e;
     Deny   = false;
 }
Esempio n. 11
0
        public bool Matches(DeviceEventType eventType)
        {
            var result = EventTypes.Contains(eventType);

            return result;
        }
Esempio n. 12
0
 public DeviceEventAction(DeviceEventType eventType, ScriptCommandList commands)
     : this(new[] {eventType}, commands)
 {
 }
 private void FrmEventActionBase_FormClosing(object sender, FormClosingEventArgs e)
 {
     this.DeviceActions = ctrlActionBar1.Actions;
 }