public HSPE16InputOnly CreateHSPE16InputOnly(Enum id, I2CSlaveAddress address) { var device = new HSPE16InputOnly(DeviceIdFactory.CreateIdFrom(id), address, _i2CBus) { AutomaticallyFetchState = true }; _controller.AddDevice(device); return(device); }
private void ParseDevices() { var devicesElement = _configuration.Root.Element("Devices"); foreach (XElement deviceElement in devicesElement.Elements()) { try { IDevice device = GetConfigurationExtender(deviceElement).ParseDevice(deviceElement); _controller.AddDevice(device); } catch (Exception exception) { _controller.Logger.Warning(exception, "Unable to parse device node '{0}'.", deviceElement.Name); } } }
/// <summary> /// Configures the Devices of a Controller. /// </summary> /// <param name="deviceConfigurations">A <see cref="List{T}"/> of <see cref="DeviceConfig"/> instances.</param> private void ConfigureDevices(List <DeviceConfig> deviceConfigurations) { deviceConfigurations.ForEach(device => { // TODO: configure device settings trough interface method of IDevice and pass SystemConfiguration child object that contains the needed information var deviceType = _deviceTypeNameMapping.FirstOrDefault(kvp => kvp.Key == device.Name).Value; var deviceObject = (IDevice)Activator.CreateInstance(deviceType); if (deviceObject != null) { deviceObject.DeviceName = device.Name; deviceObject.Configure(device.Configuration); _controller.AddDevice(deviceObject); } else { _logger.Log($"Could not create object of type {device.Name}."); } }); }