public bool Connect(HidDeviceInfo hidDevice) { ReusltString result = new ReusltString(); HidDeviceData.HID_RETURN hdrtn = device.OpenDevice(hidDevice.vID, hidDevice.pID, hidDevice.serial); if (hdrtn == HidDeviceData.HID_RETURN.SUCCESS) { bConnected = true; #region 消息通知 result.Result = true; result.message = "设备连接成功!"; RaiseEventConnectedState(result.Result); #endregion return(true); } bConnected = false; #region 消息通知 result.Result = false; result.message = "设备连接错误"; RaiseEventConnectedState(result.Result); #endregion return(false); }
public void AutoConnect(HidDeviceInfo hidDevice) { lowHidDevice = hidDevice; ContinueConnectFlag = true; ReadWriteThread.DoWork += ReadWriteThread_DoWork; ReadWriteThread.WorkerSupportsCancellation = true; ReadWriteThread.RunWorkerAsync(); }
public BatteryPropertyMap(HidDeviceInfo deviceInfo) { var mapper = new FieldMapper(deviceInfo); if (mapper.Initialized) { } props = typeof(BatteryPropertyMap).GetProperties(BindingFlags.Public | BindingFlags.Instance); BatteryPropertyCode c; mapper.MapField(out c, 0x43); VARATING = c; mapper.MapField(out c, 0x40, 0x12); NominalBatteryVoltage = c; mapper.MapField(out c, 0x53); LowVoltageTransfer = c; mapper.MapField(out c, 0x54); HighVoltageTransfer = c; mapper.MapField(out c, 0x32, 0x1a); InputFrequency = c; mapper.MapField(out c, 0x32, 0x1c); OutputFrequency = c; mapper.MapField(out c, 0x30, 0x1a); InputVoltage = c; mapper.MapField(out c, 0x30, 0x1c); OutputVoltage = c; mapper.MapField(out c, 0x31); OutputCurrent = c; mapper.MapField(out c, 0x34); OutputPower = c; mapper.MapField(out c, 0x35); OutputLoad = c; mapper.MapField(out c, 0x68, 1); TimeRemaining = c; mapper.MapField(out c, 0x30, 0x12); BatteryVoltage = c; mapper.MapField(out c, 0x66, 1); ChargeRemaining = c; }
private RelayInfo GetInfo(HidDeviceInfo hidInfo) { var relay = new Relay(hidInfo); RelayInfo relayInfo = null; if (relay.Open()) { relayInfo = new RelayInfo(relay.ReadId(), relay.ChannelsCount, hidInfo); relay.Close(); } return(relayInfo); }
public FieldMapper(HidDeviceInfo hidDevice) { this.initialized = false; if (hidDevice is HidPowerDeviceInfo hpd) { this.deviceInfo = hpd; } else { this.deviceInfo = HidPowerDeviceInfo.CreateFromHidDevice(hidDevice); } Initialize(); }
private void DeviceConnected(bool isConnected) { if (isConnected) { System.Diagnostics.Trace.WriteLine("Connected " + DateTime.Now); try { m_dataflash = HidConnector.Instance.ReadDataflash(); } catch { return; } m_connectedDeviceProductId = m_dataflash.ProductId; m_deviceInfo = HidDeviceInfo.Get(m_connectedDeviceProductId); m_hardwareVersion = (m_dataflash.HardwareVersion / 100f).ToString("0.00", CultureInfo.InvariantCulture); m_firmwareVersion = (m_dataflash.FirmwareVersion / 100f).ToString("0.00", CultureInfo.InvariantCulture); UpdateUI(() => { DeviceNameTextBox.Text = m_deviceInfo.Name; HardwareVersionTextBox.Text = m_hardwareVersion; FirmwareVersionTextBox.Text = m_firmwareVersion; BootModeTextBox.Text = m_dataflash.LoadFromLdrom ? "LDROM" : "APROM"; UpdateStatusLabel.Text = LocalizableStrings.FirmwareUpdaterDeviceIsReady; SetUpdaterButtonsState(true); }); } else { System.Diagnostics.Trace.WriteLine("Disconnected " + DateTime.Now); m_connectedDeviceProductId = null; m_dataflash = null; UpdateUI(() => { DeviceNameTextBox.Clear(); HardwareVersionTextBox.Clear(); FirmwareVersionTextBox.Clear(); BootModeTextBox.Clear(); UpdateStatusLabel.Text = LocalizableStrings.FirmwareUpdaterWaitingForDevice; SetUpdaterButtonsState(false); }); } }
public BatteryPickerViewModel() { deviceIds = new ObservableCollection <PowerDeviceIdEntry>(); var hids = HidDeviceInfo.EnumerateHidDevices(false, new[] { HidUsagePage.PowerDevice1, HidUsagePage.PowerDevice2 }); foreach (var hid in hids) { var newDev = new PowerDeviceIdEntry(hid.ProductString, hid.DevicePath, hids.Length == 1) { Source = hid, Parent = this }; deviceIds.Add(newDev); } CheckState(); }
private void InitializeWorkspace() { var deviceInfo = m_deviceConfiguration.Info; { DeviceNameLabel.Text = HidDeviceInfo.Get(deviceInfo.ProductId).Name; FirmwareVersionTextBox.Text = (deviceInfo.FirmwareVersion / 100f).ToString("0.00", CultureInfo.InvariantCulture); BuildTextBox.Text = deviceInfo.FirmwareBuild.ToString(); HardwareVersionTextBox.Text = (deviceInfo.HardwareVersion / 100f).ToString("0.00", CultureInfo.InvariantCulture); if (deviceInfo.DisplaySize == ArcticFoxConfiguration.DisplaySize.W96H16) { MainScreenSkinLabel.Visible = MainScreenSkinComboBox.Visible = false; ClockTypeLabel.Visible = ClockTypeComboBox.Visible = false; UseClassicMenuLabel.Visible = UseClassicMenuCheckBox.Visible = false; } Battery2OffsetLabel.Visible = Battery2OffsetUpDown.Visible = Battery2OffsetVoltsLabel.Visible = deviceInfo.NumberOfBatteries > 1; Battery3OffsetLabel.Visible = Battery3OffsetUpDown.Visible = Battery3OffsetVoltsLabel.Visible = deviceInfo.NumberOfBatteries > 2; Battery4OffsetLabel.Visible = Battery4OffsetUpDown.Visible = Battery4OffsetVoltsLabel.Visible = deviceInfo.NumberOfBatteries > 3; } var general = m_deviceConfiguration.General; { for (var i = 0; i < general.Profiles.Length; i++) { var tabName = "P" + (i + 1); ProfileTabContent tabContent; if (ProfilesTabControl.TabPages.Count <= i) { var tabPage = new TabPage(tabName); tabContent = new ProfileTabContent(this) { Dock = DockStyle.Fill }; tabPage.Controls.Add(tabContent); ProfilesTabControl.TabPages.Add(tabPage); SelectedProfleComboBox.Items.Add(new NamedItemContainer <byte>(tabName, (byte)i)); } else { tabContent = (ProfileTabContent)ProfilesTabControl.TabPages[i].Controls[0]; } tabContent.Initialize(m_deviceConfiguration, i); tabContent.UpdatePowerCurveNames(m_deviceConfiguration.Advanced.PowerCurves); tabContent.UpdateTFRNames(m_deviceConfiguration.Advanced.TFRTables); } ProfilesTabControl.SelectedIndex = Math.Max(0, Math.Min(general.SelectedProfile, ProfilesTabControl.TabCount)); SelectedProfleComboBox.SelectItem(general.SelectedProfile); SmartCheckBox.Checked = general.IsSmartEnabled; } var ui = m_deviceConfiguration.Interface; { BrightnessTrackBar.Value = ui.Brightness; IdleTimeUpDow.SetValue(ui.DimTimeout); PuffScreenDelayUpDown.SetValue(ui.PuffScreenDelay / 10m); StealthModeCheckBox.Checked = ui.IsStealthMode; FlippedModeCheckBox.Checked = ui.IsFlipped; MainScreenSkinComboBox.SelectItem(ui.MainScreenSkin); UseClassicMenuCheckBox.Checked = ui.IsClassicMenu; ShowLogoCheckBox.Checked = ui.IsLogoEnabled; ShowClockCheckBox.Checked = ui.IsClockOnMainScreen; ClockTypeComboBox.SelectItem(ui.ClockType); ScreensaverTimeComboBox.SelectItem(ui.ScreensaveDuration); ChargeScreenComboBox.SelectItem(ui.ChargeScreenType); // Classic Screen InitializeLineContentEditor(ui.ClassicSkinVWLines.Line1, ClassicVWLine1ComboBox, ClassicVWLine1FireCheckBox); InitializeLineContentEditor(ui.ClassicSkinVWLines.Line2, ClassicVWLine2ComboBox, ClassicVWLine2FireCheckBox); InitializeLineContentEditor(ui.ClassicSkinVWLines.Line3, ClassicVWLine3ComboBox, ClassicVWLine3FireCheckBox); InitializeLineContentEditor(ui.ClassicSkinVWLines.Line4, ClassicVWLine4ComboBox, ClassicVWLine4FireCheckBox); InitializeLineContentEditor(ui.ClassicSkinTCLines.Line1, ClassicTCLine1ComboBox, ClassicTCLine1FireCheckBox); InitializeLineContentEditor(ui.ClassicSkinTCLines.Line2, ClassicTCLine2ComboBox, ClassicTCLine2FireCheckBox); InitializeLineContentEditor(ui.ClassicSkinTCLines.Line3, ClassicTCLine3ComboBox, ClassicTCLine3FireCheckBox); InitializeLineContentEditor(ui.ClassicSkinTCLines.Line4, ClassicTCLine4ComboBox, ClassicTCLine4FireCheckBox); // Circle Screen InitializeLineContentEditor(ui.CircleSkinVWLines.Line1, CircleVWLine1ComboBox); InitializeLineContentEditor(ui.CircleSkinVWLines.Line2, CircleVWLine2ComboBox); InitializeLineContentEditor(ui.CircleSkinVWLines.Line3, CircleVWLine3ComboBox, CircleVWLine3FireCheckBox); InitializeLineContentEditor(ui.CircleSkinTCLines.Line1, CircleTCLine1ComboBox); InitializeLineContentEditor(ui.CircleSkinTCLines.Line2, CircleTCLine2ComboBox); InitializeLineContentEditor(ui.CircleSkinTCLines.Line3, CircleTCLine3ComboBox, CircleTCLine3FireCheckBox); // Small Screen InitializeLineContentEditor(ui.SmallSkinVWLines.Line1, SmallVWLine1ComboBox, SmallVWLine1FireCheckBox); InitializeLineContentEditor(ui.SmallSkinVWLines.Line2, SmallVWLine2ComboBox, SmallVWLine2FireCheckBox); InitializeLineContentEditor(ui.SmallSkinTCLines.Line1, SmallTCLine1ComboBox, SmallTCLine1FireCheckBox); InitializeLineContentEditor(ui.SmallSkinTCLines.Line2, SmallTCLine2ComboBox, SmallTCLine2FireCheckBox); ClicksVW2ComboBox.SelectItem(ui.ClicksVW[0]); ClicksVW3ComboBox.SelectItem(ui.ClicksVW[1]); ClicksVW4ComboBox.SelectItem(ui.ClicksVW[2]); ClicksTC2ComboBox.SelectItem(ui.ClicksTC[0]); ClicksTC3ComboBox.SelectItem(ui.ClicksTC[1]); ClicksTC4ComboBox.SelectItem(ui.ClicksTC[2]); UpDownButtonsComboBox.SelectItem(ui.IsUpDownSwapped); WakeUpByPlusMinusCheckBox.Checked = ui.WakeUpByPlusMinus; Step1WCheckBox.Checked = ui.IsPowerStep1W; LayoutTabControl.SelectedTab = deviceInfo.DisplaySize == ArcticFoxConfiguration.DisplaySize.W64H128 ? ui.MainScreenSkin == ArcticFoxConfiguration.Skin.Classic ? ClassicScreenTabPage : CircleScreenTabPage : SmallScreenTabPage; } var stats = m_deviceConfiguration.Counters; { PuffsUpDown.SetValue(stats.PuffsCount); PuffsTimeUpDown.SetValue(stats.PuffsTime / 10m); PuffsTimeFormatComboBox.SelectItem(ui.PuffsTimeFormat); } var advanced = m_deviceConfiguration.Advanced; { PuffCutOffUpDown.SetValue(advanced.PuffCutOff / 10m); ShuntCorrectionUpDown.SetValue(advanced.ShuntCorrection); BatteryModelComboBox.SelectItem(advanced.BatteryModel); X32CheckBox.Checked = advanced.IsX32; LightSleepCheckBox.Checked = advanced.IsLightSleepMode; ResetCountersCheckBox.Checked = advanced.ResetCountersOnStartup; CheckTCRCheckBox.Checked = advanced.CheckTCR; UsbChargeCheckBox.Checked = advanced.IsUsbCharge; UsbNoSleepCheckBox.Checked = advanced.UsbNoSleep; Battery1OffsetUpDown.SetValue(advanced.BatteryVoltageOffsets[0] / 100m); Battery2OffsetUpDown.SetValue(advanced.BatteryVoltageOffsets[1] / 100m); Battery3OffsetUpDown.SetValue(advanced.BatteryVoltageOffsets[2] / 100m); Battery4OffsetUpDown.SetValue(advanced.BatteryVoltageOffsets[3] / 100m); PowerCurvesListView.Items.Clear(); PowerCurvesListView.LargeImageList.Images.Clear(); for (var i = 0; i < m_deviceConfiguration.Advanced.PowerCurves.Length; i++) { var powerCurve = m_deviceConfiguration.Advanced.PowerCurves[i]; var bitmap = ChartPreviewService.CreatePowerCurvePreview(powerCurve, PowerCurvesListView.LargeImageList.ImageSize); PowerCurvesListView.LargeImageList.Images.Add(bitmap); PowerCurvesListView.Items.Add(new ListViewItem(powerCurve.Name, i) { Tag = i }); } MaterialsListView.Items.Clear(); MaterialsListView.LargeImageList.Images.Clear(); for (var i = 0; i < m_deviceConfiguration.Advanced.TFRTables.Length; i++) { var tfrTable = m_deviceConfiguration.Advanced.TFRTables[i]; var bitmap = ChartPreviewService.CreateTFRCurvePreview(tfrTable, PowerCurvesListView.LargeImageList.ImageSize); MaterialsListView.LargeImageList.Images.Add(bitmap); MaterialsListView.Items.Add(new ListViewItem("[TFR] " + tfrTable.Name, i) { Tag = i }); } } }
private void DeviceSelect_SelectionChanged(object sender, SelectionChangedEventArgs e) { HidDeviceInfo d = (HidDeviceInfo)this.DeviceSelect.SelectedItem; StartWatching(d); }
private void StartWatching(HidDeviceInfo d) { IntPtr h; int i = 0; if (_devThread is object) { StopWatching(); } var s = new ObservableCollection <string>(); _lastDevice = d; this.ViewingArea.ItemsSource = s; for (i = 0; i <= 255; i++) { s.Add(""); } var th = new Thread(() => { cts = new CancellationTokenSource(); h = HidFeatures.OpenHid(d); if ((long)h <= 0L) { return; } var mm = new MemPtr(65L); try { do { this.Dispatcher.Invoke(() => { for (i = 0; i <= 255; i++) { mm.LongAtAbsolute(1L) = 0L; mm.ByteAt(0L) = (byte)i; if (HidD_GetFeature(h, mm, 65)) { s[i] = "HID CODE " + i.ToString("X2") + " = " + mm.IntAtAbsolute(1L); } } }); Thread.Sleep(1000); if (cts is null || cts.IsCancellationRequested) { break; } }while (true); mm.Free(); HidFeatures.CloseHid(h); cts = null; return; } catch (ThreadAbortException) { mm.Free(); HidFeatures.CloseHid(h); cts = null; return; } catch (Exception) { mm.Free(); HidFeatures.CloseHid(h); cts = null; return; } }); th.IsBackground = true; th.SetApartmentState(ApartmentState.STA); _devThread = th; th.Start(); }
internal RelayInfo(string id, int channelsCount, HidDeviceInfo hidInfo) { this.Id = id; this.ChannelsCount = channelsCount; this.HidInfo = hidInfo; }
internal Relay(HidDeviceInfo deviceInfo) { this.Info = deviceInfo; this._device = new HidDevice(); }
private void InitializeWorkspaceFromDataflash([NotNull] Dataflash dataflash) { if (dataflash == null) { throw new ArgumentNullException("dataflash"); } DeviceNameLabel.Text = HidDeviceInfo.Get(dataflash.InfoBlock.ProductID).Name; FirmwareVersionTextBox.Text = (dataflash.InfoBlock.FWVersion / 100f).ToString("0.00", CultureInfo.InvariantCulture); //BuildTextBox.Text = m_simple.Build.ToString(); HardwareVersionTextBox.Text = (dataflash.ParamsBlock.HardwareVersion / 100f).ToString("0.00", CultureInfo.InvariantCulture); BootModeTextBox.Text = dataflash.ParamsBlock.BootMode.ToString(); // General -> Power & Temp Tab PowerUpDown.Value = Math.Max(PowerUpDown.Minimum, Math.Min(dataflash.ParamsBlock.Power / 10m, PowerUpDown.Maximum)); TCPowerUpDown.Value = Math.Max(TCPowerUpDown.Minimum, Math.Min(dataflash.ParamsBlock.TCPower / 10m, TCPowerUpDown.Maximum)); Step1WCheckBox.Checked = dataflash.ParamsBlock.Status.Step1W; TemperatureTypeComboBox.SelectItem(dataflash.ParamsBlock.IsCelsius); TemperatureUpDown.Value = dataflash.ParamsBlock.Temperature; TemperatureDominantCheckBox.Checked = dataflash.ParamsBlock.Status.TemperatureDominant; PreheatTypeComboBox.SelectItem(dataflash.ParamsBlock.Status.PreheatPercent); PreheatPowerUpDown.Value = dataflash.ParamsBlock.Status.PreheatPercent ? dataflash.ParamsBlock.PreheatPwr : Math.Max(PreheatPowerUpDown.Minimum, Math.Min(dataflash.ParamsBlock.PreheatPwr / 10m, PreheatPowerUpDown.Maximum)); PreheatTimeUpDown.Value = dataflash.ParamsBlock.PreheatTime / 100m; // General -> Coils Manager Tab ResistanceNiUpDown.Value = dataflash.ParamsBlock.ResistanceNi / 100m; ResistanceNiCheckBox.Checked = dataflash.ParamsBlock.ResistanceNiLocked; ResistanceTiUpDown.Value = dataflash.ParamsBlock.ResistanceTi / 100m; ResistanceTiCheckBox.Checked = dataflash.ParamsBlock.ResistanceTiLocked; ResistanceSSUpDown.Value = dataflash.ParamsBlock.ResistanceSS / 100m; ResistanceSSCheckBox.Checked = dataflash.ParamsBlock.ResistanceSSLocked; ResistanceTCRUpDown.Value = dataflash.ParamsBlock.ResistanceTCR / 100m; ResistanceTCRCheckBox.Checked = dataflash.ParamsBlock.ResistanceTCRLocked; TCRM1UpDown.Value = dataflash.ParamsBlock.TCR[0]; TCRM2UpDown.Value = dataflash.ParamsBlock.TCR[1]; TCRM3UpDown.Value = dataflash.ParamsBlock.TCR[2]; // General -> Modes Tab SelectedModeComboBox.SelectItem(dataflash.ParamsBlock.SelectedMode); TempNiModeCheckBox.Checked = !dataflash.ParamsBlock.DisabledModes.HasFlag(VapeModes.TempNi); TempTiModeCheckBox.Checked = !dataflash.ParamsBlock.DisabledModes.HasFlag(VapeModes.TempTi); TempSSModeCheckBox.Checked = !dataflash.ParamsBlock.DisabledModes.HasFlag(VapeModes.TempSS); TCRModeCheckBox.Checked = !dataflash.ParamsBlock.DisabledModes.HasFlag(VapeModes.TCR); PowerModeCheckBox.Checked = !dataflash.ParamsBlock.DisabledModes.HasFlag(VapeModes.Power); BypassModeCheckBox.Checked = !dataflash.ParamsBlock.DisabledModes.HasFlag(VapeModes.Bypass); SmartModeCheckBox.Checked = !dataflash.ParamsBlock.DisabledModes.HasFlag(VapeModes.Start); // General -> Controls Tab Clicks2ComboBox.SelectItem(dataflash.ParamsBlock.MClicks[0]); Clicks3ComboBox.SelectItem(dataflash.ParamsBlock.MClicks[1]); Clicks4ComboBox.SelectItem(dataflash.ParamsBlock.MClicks[2]); WakeUpByPlusMinusCheckBox.Checked = dataflash.ParamsBlock.Status.WakeUpByPlusMinus; // General -> Stats Tab PuffsUpDown.Value = Math.Max(0, Math.Min(dataflash.InfoBlock.PuffCount, 99999)); PuffsTimeUpDown.Value = Math.Max(0, Math.Min(dataflash.InfoBlock.TimeCount / 10m, 99999)); // Screen -> Display Tab BrightnessTrackBar.Value = dataflash.ParamsBlock.Contrast; IdleTimeUpDow.Value = dataflash.ParamsBlock.ScreenDimTimeout; StealthModeCheckBox.Checked = dataflash.ParamsBlock.StealthOn; FlippedModeCheckBox.Checked = dataflash.ParamsBlock.Status.Flipped; // Screen -> Layout Tab ThirdLineContentComboBox.SelectItem(dataflash.ParamsBlock.ThirdLineContent); BatteryPercentsCheckBox.Checked = dataflash.ParamsBlock.Status.BatteryPercent; ShowLogoCheckBox.Checked = !dataflash.ParamsBlock.Status.NoLogo; if (!dataflash.ParamsBlock.Status.AnalogClock) { ClockTypeComboBox.SelectItem(ClockType.Disabled); } else if (dataflash.ParamsBlock.Status.AnalogClock && dataflash.ParamsBlock.Status.DigitalClock) { ClockTypeComboBox.SelectItem(ClockType.Digital); } else if (dataflash.ParamsBlock.Status.AnalogClock) { ClockTypeComboBox.SelectItem(ClockType.Analog); } UseClassicMenuCheckBox.Checked = dataflash.ParamsBlock.Status.UseClassicMenu; // Screen -> Screensaver Tab ScreensaverTypeComboBox.SelectItem(dataflash.ParamsBlock.ScreensaverType); ScreenProtectionTimeComboBox.SelectItem(dataflash.ParamsBlock.ScreenProtectionTime); // Developer -> Expert ShuntCorrectionUpDown.Value = Math.Max((byte)85, Math.Min(dataflash.ParamsBlock.ShuntCorrection, (byte)115)); BatteryModelComboBox.SelectItem(dataflash.ParamsBlock.SelectedBatteryModel); }