public Switch(IGalRenderer Renderer, IAalOutput AudioOut) { if (Renderer == null) { throw new ArgumentNullException(nameof(Renderer)); } if (AudioOut == null) { throw new ArgumentNullException(nameof(AudioOut)); } this.AudioOut = AudioOut; Log = new Logger(); Memory = new DeviceMemory(); Gpu = new NvGpu(Renderer); FileSystem = new VirtualFileSystem(); System = new Horizon(this); Statistics = new PerformanceStatistics(); Hid = new Hid(this, System.HidSharedMem.PA); }
private void button_OpenAnalog_Click(object sender, EventArgs e) { if (myHid_An.Opened == false) { myHid_An = new Hid(); //初始化该USB端口,在重新打开USB时一定要这步 myHidPtr_An = new IntPtr(); myHid_An.DataReceived += myhid_DataReceived_An; //订阅DataRec事件 myHid_An.DataProcessed += myhid_DataProcessed_An; myHid_An.DeviceRemoved += myhid_DeviceRemoved; UInt16 myVendorID = Convert.ToUInt16("0483", 16); UInt16 myProductID = Convert.ToUInt16("5750", 16); string productname = "ANALOG MODULE VER1"; if ((int)(myHidPtr_An = myHid_An.OpenDevice(myVendorID, myProductID, productname)) != -1) { button_OpenAnalog.BackColor = Color.Red; Analog_Read_All(); myhid_UIDeal_An(); } else { button_OpenAnalog.BackColor = Color.LightBlue; MessageBoxERRwarning(9); } } else { myHid_An.CloseDevice(myHidPtr_An); button_OpenAnalog.BackColor = Color.LightBlue; } Tooling_Enable(); }
public void Initialize() { System.State.SetLanguage((SystemLanguage)ConfigurationState.Instance.System.Language.Value); System.State.SetRegion((RegionCode)ConfigurationState.Instance.System.Region.Value); EnableDeviceVsync = ConfigurationState.Instance.Graphics.EnableVsync; System.State.DockedMode = ConfigurationState.Instance.System.EnableDockedMode; System.PerformanceState.PerformanceMode = System.State.DockedMode ? PerformanceMode.Boost : PerformanceMode.Default; System.EnablePtc = ConfigurationState.Instance.System.EnablePtc; System.FsIntegrityCheckLevel = GetIntegrityCheckLevel(); System.GlobalAccessLogMode = ConfigurationState.Instance.System.FsGlobalAccessLogMode; ServiceConfiguration.IgnoreMissingServices = ConfigurationState.Instance.System.IgnoreMissingServices; ConfigurationState.Instance.System.IgnoreMissingServices.Event += (object _, ReactiveEventArgs <bool> args) => { ServiceConfiguration.IgnoreMissingServices = args.NewValue; }; // Configure controllers Hid.RefreshInputConfig(ConfigurationState.Instance.Hid.InputConfig.Value); ConfigurationState.Instance.Hid.InputConfig.Event += Hid.RefreshInputConfigEvent; Logger.Info?.Print(LogClass.Application, $"AudioBackend: {ConfigurationState.Instance.System.AudioBackend.Value}"); Logger.Info?.Print(LogClass.Application, $"IsDocked: {ConfigurationState.Instance.System.EnableDockedMode.Value}"); Logger.Info?.Print(LogClass.Application, $"Vsync: {ConfigurationState.Instance.Graphics.EnableVsync.Value}"); }
public bool GetFeature <T>(byte reportId, T data) where T : struct { lock (lockObject) { if (reference == null) { throw new InvalidOperationException("The HID reference is null."); } else if (reference.IsInvalid) { throw new InvalidOperationException("The HID reference is invalid"); } featureBuffer[0] = reportId; GCHandle gch = GCHandle.Alloc(featureBuffer, GCHandleType.Pinned); bool ret = Hid.HidD_GetFeature(reference, gch.AddrOfPinnedObject(), (uint)Marshal.SizeOf <T>()); if (ret) { data = Marshal.PtrToStructure <T>(gch.AddrOfPinnedObject()); } gch.Free(); return(ret); } }
public Switch(IGalRenderer Renderer, IAalOutput AudioOut) { if (Renderer == null) { throw new ArgumentNullException(nameof(Renderer)); } if (AudioOut == null) { throw new ArgumentNullException(nameof(AudioOut)); } this.AudioOut = AudioOut; Memory = new DeviceMemory(); Gpu = new NvGpu(Renderer); FileSystem = new VirtualFileSystem(); System = new Horizon(this); Statistics = new PerformanceStatistics(); Hid = new Hid(this, System.HidBaseAddress); VsyncEvent = new AutoResetEvent(true); }
/// <summary> /// Lights the keyboard with the specified keys and colors, using the specified default color for unlisted keys. /// </summary> /// <param name="keyColors">The key colors.</param> /// <param name="defaultColor">The default color for unspecified keys.</param> public override void DrawKeys(IDictionary <uint, Color> keyColors, Color defaultColor) { var redPayload = new byte[72]; var greenPayload = new byte[72]; var bluePayload = new byte[72]; var redDefault = (byte)(defaultColor.R ^ byte.MaxValue); var greenDefault = (byte)(defaultColor.G ^ byte.MaxValue); var blueDefault = (byte)(defaultColor.B ^ byte.MaxValue); for (uint i = 0; i < 72; i++) { var keyIndex = i * 2; byte red; byte green; byte blue; Color color; if (keyColors.TryGetValue(keyIndex, out color)) { red = (byte)(((color.R ^ byte.MaxValue) >> 1) & 0x70); green = (byte)(((color.G ^ byte.MaxValue) >> 1) & 0x70); blue = (byte)(((color.B ^ byte.MaxValue) >> 1) & 0x70); } else { red = (byte)(redDefault >> 1); green = (byte)(greenDefault >> 1); blue = (byte)(blueDefault >> 1); } keyIndex = (i * 2) + 1; if (keyColors.TryGetValue(keyIndex, out color)) { red |= (byte)((color.R ^ byte.MaxValue) >> 5); green |= (byte)((color.G ^ byte.MaxValue) >> 5); blue |= (byte)((color.B ^ byte.MaxValue) >> 5); } else { red |= (byte)(redDefault >> 5); green |= (byte)(greenDefault >> 5); blue |= (byte)(blueDefault >> 5); } redPayload[i] = red; greenPayload[i] = green; bluePayload[i] = blue; } var payloads = CorsairRgbKeyboardPacket.GetPackets(redPayload, greenPayload, bluePayload); Hid.OpenDevice(); foreach (var payload in payloads) { Hid.WriteReport(new HidReport(Hid.Capabilities.OutputReportByteLength, new HidDeviceData(new byte[] { 0x00 }.Concat(payload.GetBytes()).ToArray <byte>(), HidDeviceData.ReadStatus.Success))); } Hid.CloseDevice(); }
/// <summary> /// Finds and displays the number of Input buffers /// (the number of Input reports the host will store). /// </summary> public static void GetInputReportBufferSize( ref Boolean exclusiveAccess , ref SafeFileHandle hidHandle , ref Hid MyHid , ref string txtInputReportBufferSize ) { Int32 numberOfInputBuffers = 0; Boolean success; try { // Get the number of input buffers. success = MyHid.GetNumberOfInputBuffers(hidHandle, ref numberOfInputBuffers); // Display the result in the text box. txtInputReportBufferSize = Convert.ToString(numberOfInputBuffers); } catch (Exception ex) { DisplayException("GetInputReportBufferSize", ex); //throw; } }
public bool SetFeature(byte reportId, byte[] data, int offset, int count) { lock (lockObject) { if (reference == null) { throw new InvalidOperationException("The HID reference is null."); } else if (reference.IsInvalid) { throw new InvalidOperationException("The HID reference is invalid"); } featureBuffer[0] = reportId; Buffer.BlockCopy(featureBuffer, 1, data, offset, count); GCHandle gch = GCHandle.Alloc(featureBuffer, GCHandleType.Pinned); bool ret = Hid.HidD_SetFeature(reference, gch.AddrOfPinnedObject(), (uint)(count + 1)); gch.Free(); return(ret); } }
public bool SetFeature <T>(byte reportId, T buffer) where T : struct { lock (lockObject) { if (reference == null) { throw new InvalidOperationException("The HID reference is null."); } else if (reference.IsInvalid) { throw new InvalidOperationException("The HID reference is invalid"); } featureBuffer[0] = reportId; int size; GCHandle gch = CopyStructToBuffer(featureBuffer, buffer, out size); bool ret = Hid.HidD_SetFeature(reference, gch.AddrOfPinnedObject(), (uint)(size + 1)); gch.Free(); return(ret); } }
public Switch(IGalRenderer Renderer, IAalOutput AudioOut) { if (Renderer == null) { throw new ArgumentNullException(nameof(Renderer)); } if (AudioOut == null) { throw new ArgumentNullException(nameof(AudioOut)); } this.AudioOut = AudioOut; Log = new Logger(); Gpu = new NvGpu(Renderer); VFs = new VirtualFileSystem(); Os = new Horizon(this); Settings = new SystemSettings(); Statistics = new PerformanceStatistics(); Hid = new Hid(Log); Os.HidSharedMem.MemoryMapped += Hid.ShMemMap; Os.HidSharedMem.MemoryUnmapped += Hid.ShMemUnmap; }
public void Initialize() { System.State.SetLanguage((SystemLanguage)ConfigurationState.Instance.System.Language.Value); System.State.SetRegion((RegionCode)ConfigurationState.Instance.System.Region.Value); EnableDeviceVsync = ConfigurationState.Instance.Graphics.EnableVsync; System.State.DockedMode = ConfigurationState.Instance.System.EnableDockedMode; System.PerformanceState.PerformanceMode = System.State.DockedMode ? PerformanceMode.Boost : PerformanceMode.Default; if (ConfigurationState.Instance.System.EnableMulticoreScheduling) { System.EnableMultiCoreScheduling(); } System.EnablePtc = ConfigurationState.Instance.System.EnablePtc; System.FsIntegrityCheckLevel = GetIntegrityCheckLevel(); System.GlobalAccessLogMode = ConfigurationState.Instance.System.FsGlobalAccessLogMode; ServiceConfiguration.IgnoreMissingServices = ConfigurationState.Instance.System.IgnoreMissingServices; // Configure controllers Hid.RefreshInputConfig(ConfigurationState.Instance.Hid.InputConfig.Value); ConfigurationState.Instance.Hid.InputConfig.Event += Hid.RefreshInputConfigEvent; }
internal async Task Setup(uint pktVersion) { _currentTask = new TaskCompletionSource <bool>(); // construct a HID output report to send to the device HidOutputReport outReport = Hid.CreateOutputReport(); YUSBPkt.imm_FormatConfReset(outReport, pktVersion); // Send the output report asynchronously _devState = DevState.ResetSend; var u = await Hid.SendOutputReportAsync(outReport); if (u != 65) { _devState = DevState.IOError; throw new YAPI_Exception(YAPI.IO_ERROR, "Unable to send Reset PKT"); } Task <bool> task = _currentTask.Task; Task taskDone = await Task.WhenAny(task, Task.Delay(1000)); if (taskDone != task) { throw new YAPI_Exception(YAPI.IO_ERROR, "Device does not respond to reset"); } }
public Switch(VirtualFileSystem fileSystem, ContentManager contentManager, IRenderer renderer, IAalOutput audioOut) { if (renderer == null) { throw new ArgumentNullException(nameof(renderer)); } if (audioOut == null) { throw new ArgumentNullException(nameof(audioOut)); } AudioOut = audioOut; Memory = new DeviceMemory(); Gpu = new GpuContext(renderer); FileSystem = fileSystem; System = new Horizon(this, contentManager); Statistics = new PerformanceStatistics(); Hid = new Hid(this, System.HidBaseAddress); Hid.InitDevices(); }
public string GetProductString() { var buffer = new byte[260]; Hid.HidD_GetProductString(this._handle, ref buffer[0], Convert.ToUInt32(buffer.Length)); return(buffer.GetString()); }
public Switch(VirtualFileSystem fileSystem, ContentManager contentManager, UserChannelPersistence userChannelPersistence, IRenderer renderer, IAalOutput audioOut) { if (renderer == null) { throw new ArgumentNullException(nameof(renderer)); } if (audioOut == null) { throw new ArgumentNullException(nameof(audioOut)); } if (userChannelPersistence == null) { throw new ArgumentNullException(nameof(userChannelPersistence)); } UserChannelPersistence = userChannelPersistence; AudioOut = audioOut; Memory = new MemoryBlock(1UL << 32); Gpu = new GpuContext(renderer); Host1x = new Host1xDevice(Gpu.Synchronization); var nvdec = new NvdecDevice(Gpu.MemoryManager); var vic = new VicDevice(Gpu.MemoryManager); Host1x.RegisterDevice(ClassId.Nvdec, nvdec); Host1x.RegisterDevice(ClassId.Vic, vic); nvdec.FrameDecoded += (FrameDecodedEventArgs e) => { // FIXME: // Figure out what is causing frame ordering issues on H264. // For now this is needed as workaround. if (e.CodecId == CodecId.H264) { vic.SetSurfaceOverride(e.LumaOffset, e.ChromaOffset, 0); } else { vic.DisableSurfaceOverride(); } }; FileSystem = fileSystem; System = new Horizon(this, contentManager); System.InitializeServices(); Statistics = new PerformanceStatistics(); Hid = new Hid(this, System.HidBaseAddress); Hid.InitDevices(); Application = new ApplicationLoader(this, fileSystem, contentManager); }
public void Update(Hid hleHid, TamperMachine tamperMachine) { lock (_lock) { List <GamepadInput> hleInputStates = new List <GamepadInput>(); List <SixAxisInput> hleMotionStates = new List <SixAxisInput>(NpadDevices.MaxControllers); KeyboardInput?hleKeyboardInput = null; foreach (InputConfig inputConfig in _inputConfig) { GamepadInput inputState = default; SixAxisInput motionState = default; NpadController controller = _controllers[(int)inputConfig.PlayerIndex]; // Do we allow input updates and is a controller connected? if (!_blockInputUpdates && controller != null) { DriverConfigurationUpdate(ref controller, inputConfig); controller.UpdateUserConfiguration(inputConfig); controller.Update(); inputState = controller.GetHLEInputState(); inputState.Buttons |= hleHid.UpdateStickButtons(inputState.LStick, inputState.RStick); motionState = controller.GetHLEMotionState(); if (ConfigurationState.Instance.Hid.EnableKeyboard) { hleKeyboardInput = controller.GetHLEKeyboardInput(); } } else { // Ensure that orientation isn't null motionState.Orientation = new float[9]; } inputState.PlayerId = (Ryujinx.HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex; motionState.PlayerId = (Ryujinx.HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex; hleInputStates.Add(inputState); hleMotionStates.Add(motionState); } hleHid.Npads.Update(hleInputStates); hleHid.Npads.UpdateSixAxis(hleMotionStates); if (hleKeyboardInput.HasValue) { hleHid.Keyboard.Update(hleKeyboardInput.Value); } tamperMachine.UpdateInput(hleInputStates); } }
public Hid.HidD_Attributes GetAttributes() { var attributes = new Hid.HidD_Attributes(); attributes.Size = Marshal.SizeOf(attributes); Hid.HidD_GetAttributes(this._handle, ref attributes); return(attributes); }
public void Hide() { foreach (Graphic g in graphics) { g.enabled = false; } Hid?.Invoke(); }
public Form1() { hid = new Hid(); hid.vID = 0x0483; hid.pID = 0x0409; hid.DataReceived += Hid_DataReceived; hid.OnSpecifiedDeviceArrived += Hid_OnSpecifiedDeviceArrived; hid.OnSpecifiedDeviceRemoved += Hid_OnSpecifiedDeviceRemoved; InitializeComponent(); }
public bool SetFeature(int reportNumber, byte[] data) { if (data.Length > 64) { throw new ArgumentException("Array too large!", "data"); } data[0] = Convert.ToByte(reportNumber); return(Hid.HidD_SetFeature(this._handle, ref data[0], data.Length)); }
public MainForm() { InitializeComponent(); devList.SelectedIndex = 0; hid = new Hid(); hid.DataReceived += Hid_DataReceived; hid.DeviceRemoved += Hid_DeviceRemoved; ptr = new IntPtr(-1); Util.Output = (obj) => outputBox.Text += obj.ToString(); }
public IEnumerable <HidDeviceInfo> CollectInfo() { var result = new List <HidDeviceInfo>(); Guid hidGuid; Hid.HidD_GetHidGuid(out hidGuid); var deviceInfoList = SetupApi.SetupDiGetClassDevs(ref hidGuid, null, IntPtr.Zero, Constants.DIGCF_DEVICEINTERFACE | Constants.DIGCF_PRESENT); if (deviceInfoList != IntPtr.Zero && deviceInfoList != Constants.INVALID_HANDLE_VALUE) { var deviceInfo = new SetupApi.SP_DEVICE_INTERFACE_DATA(); deviceInfo.cbSize = Marshal.SizeOf(deviceInfo); for (var i = 0; ; i++) { if (!SetupApi.SetupDiEnumDeviceInterfaces(deviceInfoList, 0, ref hidGuid, Convert.ToUInt32(i), ref deviceInfo)) { break; } var path = this.GetPath(deviceInfoList, deviceInfo); var device = new HidDevice(); if (device.Open(path)) { var attributes = device.GetAttributes(); var vendor = device.GetVendorString(); var product = device.GetProductString(); result.Add(new HidDeviceInfo( path, attributes.VendorID, attributes.ProductID, attributes.VersionString, vendor, product)); device.Close(); } } SetupApi.SetupDiDestroyDeviceInfoList(deviceInfoList); } return(result); }
static void Main(string[] args) { Hid hid = new Hid(); IntPtr ptr = new IntPtr(); hid.DataReceived += Hid_DataReceived; if ((int)(ptr = hid.OpenDevice(0x3232, 0x0001, 0x02)) != -1) { Console.WriteLine("sending..."); Report report = new Report(0x55, new byte[] { 0x00, 0x55, 0xAA, 0xFF }); hid.Write(report); } Console.ReadKey(true); }
/// <summary> /// Plays back the specified StrokeCollection on the specified element /// </summary> public void PlayStrokeCollection(StrokeCollection strokes, InkCanvas inkCanvas) { //inkCanvas.Ink.AddStrokesAtRectangle(strokes, strokes.GetBoundingBox()); //there is a // // determine the transform between the UIElement and the root // GeneralTransform transform = GetTransformToRootElement(inkCanvas); foreach (Stroke stroke in strokes) { StylusPointCollection stylusPoints = stroke.StylusPoints; if (stroke.DrawingAttributes.FitToCurve) { stylusPoints = stroke.GetBezierStylusPoints(); } if (stylusPoints.Count > 0) { Point pt = new Point(); for (int i = 0; i < stylusPoints.Count; i++) { StylusPoint stylusPoint = stylusPoints[i]; pt.X = stylusPoint.X; pt.Y = stylusPoint.Y; transform.TryTransform(pt, out pt); stylusPoint.X = pt.X; stylusPoint.Y = pt.Y; stylusPoints[i] = stylusPoint; } // // simulate a stylus in air // Hid.SimulateDrtPacket(this.MainWindow, (int)stylusPoints[0].X, (int)stylusPoints[0].Y, false); foreach (StylusPoint point in stylusPoints) { Hid.SimulateDrtPacket(this.MainWindow, (int)point.X, (int)point.Y, true); } // // simulate an up // Hid.SimulateDrtPacket(this.MainWindow, (int)stylusPoints[stylusPoints.Count - 1].X, (int)stylusPoints[stylusPoints.Count - 1].Y, false); } } }
public bool SetNumberInputBuffers(int buffers) { lock (lockObject) { if (reference == null) { throw new InvalidOperationException("The HID reference is null."); } else if (reference.IsInvalid) { throw new InvalidOperationException("The HID reference is invalid"); } return(Hid.HidD_SetNumInputBuffers(reference, buffers)); } }
public bool FlushQueue() { lock (lockObject) { if (reference == null) { throw new InvalidOperationException("The HID reference is null."); } else if (reference.IsInvalid) { throw new InvalidOperationException("The HID reference is invalid"); } return(Hid.HidD_FlushQueue(reference)); } }
private async Task checkMetaUTC() { if (_lastMetaUTC + META_UTC_DELAY < YAPI.GetTickCount()) { HidOutputReport outReport = Hid.CreateOutputReport(); YUSBPkt.imm_FormatMetaUTC(outReport, true); var u = await Hid.SendOutputReportAsync(outReport); if (u != 65) { _devState = DevState.IOError; throw new YAPI_Exception(YAPI.IO_ERROR, "Unable to send Start PKT"); } _lastMetaUTC = YAPI.GetTickCount(); } }
internal async Task Start(byte pktAckDelay) { // construct a HID output report to send to the device HidOutputReport outReport = Hid.CreateOutputReport(); //("Activate USB pkt ack (%dms)\n", dev->pktAckDelay); YUSBPkt.imm_FormatConfStart(outReport, 1, pktAckDelay); // Send the output report asynchronously _devState = DevState.StartSend; var u = await Hid.SendOutputReportAsync(outReport); if (u != 65) { _devState = DevState.IOError; throw new YAPI_Exception(YAPI.IO_ERROR, "Unable to send Start PKT"); } }
/// <summary> /// Perform actions that must execute when the program starts. /// </summary> private void Startup() { try { MyHid = new Hid(); // Default USB Vendor ID and Product ID: //txtVendorID.Text = "0925"; //txtProductID.Text = "7001"; } catch (Exception ex) { Tracer.Error(ex); throw; } }
private static bool GetAttributes(ref DeviceInformationStructure deviceInformation) { try { deviceInformation.Attributes.Size = Marshal.SizeOf(deviceInformation.Attributes); if (Hid.HidD_GetAttributes(deviceInformation.HidHandle, ref deviceInformation.Attributes)) { return(true); } } catch { Debug.WriteLine("GetAttributes failed"); return(false); } return(false); }
public skyetek_hid(String path) { MyDebugging = new Debugging(); // For viewing results of API calls via Debug.Write. MyDeviceManagement = new DeviceManagement(); MyHid = new Hid(); readBuffer = new Queue<byte>(65); ReadFinished = false; ReadStart = 0; myDevicePathName = path; }