コード例 #1
0
        public BigRedButtonState?QueryState()
        {
            var statusQuery = new HidReport(1)
            {
                Data = StatusReport
            };

            var isQueryWritten = device.WriteReport(statusQuery);

            if (!isQueryWritten)
            {
                return(null);
            }

            var readReport = device.ReadReport(100);

            var readData = readReport.Data;

            if (readReport.ReadStatus != HidDeviceData.ReadStatus.Success)
            {
                return(null);
            }

            var statusByte = readData[0];

            Debug.WriteLine(Convert.ToString(readData[0], 2));

            var buttonIsPressed = (statusByte & (1 << 0)) == 0;
            var lidIsOpen       = (statusByte & (1 << 1)) != 0;

            return(new BigRedButtonState(buttonIsPressed, lidIsOpen));
        }
コード例 #2
0
ファイル: TemperReader.cs プロジェクト: Codeuctivity/Tempify
        private static HidReport WriteAndReadReport(IHidDevice device, byte reportId, byte[] data)
        {
            var outData = device.CreateReport();

            outData.ReportId = reportId;
            outData.Data     = data;
            device.WriteReport(outData);
            while (outData.ReadStatus != HidDeviceData.ReadStatus.Success)
            {
                Thread.Sleep(1);
            }
            var report = device.ReadReport();

            return(report);
        }