Example #1
0
        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);
        }
Example #2
0
        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;
            }
        }
Example #3
0
 public ModernFanController(HidDevice hidDevice, byte channel)
 {
     reportFactory = new CoolitModernOutputReportFactory(hidDevice)
     {
         Channel = channel
     };
     cmd = new CommandStateMachine(hidDevice, reportFactory, new CoolitBridgeResponseValidator());
 }
Example #4
0
        private object GetCommandStateMachineResult(CommandStateMachine cmd, IResponseParser parser)
        {
            if (cmd.IsFaulted)
            {
                return(null);
            }

            return(parser.Parse(cmd.Result));
        }
Example #5
0
        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();
        }
Example #6
0
 private async Task RunCmdSynchronized(CommandStateMachine cmd, byte data)
 {
     await cmd.Run(data);
 }