public async Task <bool> Initialize() { var cmd = new CommandStateMachine(deviceEntity, bridgeReportFactory, new CoolitBridgeResponseValidator()); await RunCmdSynchronized(cmd, (byte)CoolitBridgeCommandCode.MODEL); var model = (CoolitModel)(GetCommandStateMachineResult(cmd, GetParser(CoolitBridgeCommandCode.MODEL)) ?? CoolitModel.Unknown); deviceInfo = DeviceInfoTable.ContainsKey(model) ? DeviceInfoTable[model] : new CoolitDeviceInfo(CoolitModel.Unknown, "0000", ProtocolType.Unsupported, true, 0); if (deviceInfo.ProtocolType == ProtocolType.Unsupported) { return(IsInitialized = false); } fanController = new ModernFanController(deviceEntity, Channel); // Retrieving Unique Device ID. Need to identify device with Channel to work correctly with nested Coolit devices UDID = deviceEntity.DeviceInstancePath + Channel.ToString(); await RunCmdSynchronized(cmd, (byte)CoolitBridgeCommandCode.DEVICE_ADDRESS); if (cmd.IsFaulted) { return(IsInitialized = false); } return(IsInitialized = true); }
private async Task FillFanSensorsCollection() { fanSensors.Clear(); var cmd = new CommandStateMachine(deviceEntity, modernReportFactory, new CoolitBridgeResponseValidator()); await RunCmdSynchronized(cmd, (byte)CoolitModernCommandCode.NUMBER_OF_FANS); int count = (byte)(GetCommandStateMachineResult(cmd, GetParser(CoolitModernCommandCode.NUMBER_OF_FANS)) ?? 0); for (byte i = 0; i < count; i++) { byte mode = await fanController.GetFanMode((CoolitSensorAddress)i); if ((mode & 0x80) != 0) // highest bit specifies if fan is detected { fanSensors.Add(new CoolitSensor() { Channel = (CoolitSensorAddress)i, SensorType = CoolitSensorType.FanRpm }); } } if (fanSensors.Count > 0 && deviceInfo.Model != CoolitModel.Whiptail) // whiptail does not contain pump { var pump = fanSensors.Last(); pump.SensorType = CoolitSensorType.PumpRpm; } }
public ModernFanController(HidDevice hidDevice, byte channel) { reportFactory = new CoolitModernOutputReportFactory(hidDevice) { Channel = channel }; cmd = new CommandStateMachine(hidDevice, reportFactory, new CoolitBridgeResponseValidator()); }
private object GetCommandStateMachineResult(CommandStateMachine cmd, IResponseParser parser) { if (cmd.IsFaulted) { return(null); } return(parser.Parse(cmd.Result)); }
private async Task ReadFwVersion() { fwVersion = "<Empty>"; CommandStateMachine cmd; var parser = new BCDFWVersionParser(); byte commandCode; IReportFactory factory; switch (deviceInfo.ProtocolType) { case ProtocolType.Modern: default: commandCode = (byte)CoolitModernCommandCode.FW_VERSION; factory = modernReportFactory; break; } cmd = new CommandStateMachine(deviceEntity, factory, new CoolitBridgeResponseValidator()); await RunCmdSynchronized(cmd, commandCode); fwVersion = (GetCommandStateMachineResult(cmd, parser) ?? string.Empty).ToString(); }
private async Task RunCmdSynchronized(CommandStateMachine cmd, byte data) { await cmd.Run(data); }