<commit_before>﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Win32;
using Win32.HumanInterfaceDevices;
using Win32.RawInput;

namespace HID.MultiAxisController
{
	/// <summary>
	/// Class for handling <see cref="WM.INPUT">WM_INPUT</see> messages for SpaceMouse/SpaceNavigator/SpaceExplorer/... devices.
	/// </summary>
	public class SpaceMouse
	{
		/// <summary>
		/// Returns whether a device is a compatible devices, or not.
		/// </summary>
		/// <param name="info">The <see cref="RID_DEVICE_INFO"/> describing the device.</param>
		/// <returns><b>true</b> if the device is compatible with the class; otherwise, <b>false</b>.</returns>
		public static bool IsSpaceMouse(RID_DEVICE_INFO info)
		{
			return info.dwType==RIM_TYPE.HID&&info.hid.usUsage==HID_USAGE_GENERIC_DESKTOP.MULTIAXIS_CONTROLLER&&
				info.hid.usUsagePage==HID_USAGE_PAGE.GENERIC_DESKTOP&&
				(info.hid.dwVendorId==VendorID.Logitech||info.hid.dwVendorId==VendorID.D3connexion);
		}

		/// <summary>
		/// Set the state of the LED of a SpaceMouse/SpaceNavigator/SpaceExplorer/... devices.
		/// </summary>
		/// <param name="hDevice">The handle of the device.</param>
		/// <param name="enable">Defines the new state of the LED.</param>
		public static void SetLED(IntPtr hDevice, bool enable=true)
		{
			string name=RawInput.GetRawInputDeviceName(hDevice);

			IntPtr hFile=FileOperations.CreateFile(name, GENERIC.READ|GENERIC.WRITE, FILE_SHARE.READ|FILE_SHARE.WRITE, IntPtr.Zero,
				Win32.FileMode.OPEN_EXISTING, FILE_ATTRIBUTE.NORMAL, IntPtr.Zero);

			if(hFile!=FileOperations.INVALID_HANDLE_VALUE)
			{
				uint written;
				FileOperations.WriteFile(hFile, new byte[] { 4, (byte)(enable?1:0) }, 2, out written, IntPtr.Zero);
				FileOperations.CloseHandle(hFile);
			}

			WinKernel.SetLastError(0);
		}

		/// <summary>
		/// Enables the LED of a SpaceMouse/SpaceNavigator/SpaceExplorer/... devices.
		/// </summary><commit_msg>Fixed namespace issues<commit_after>﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Win32;
using Win32.HumanInterfaceDevices;
using Win32.IO;
using Win32.RawInput;

namespace HID.MultiAxisController
{
	/// <summary>
	/// Class for handling <see cref="WM.INPUT">WM_INPUT</see> messages for SpaceMouse/SpaceNavigator/SpaceExplorer/... devices.
	/// </summary>
	public class SpaceMouse
	{
		/// <summary>
		/// Returns whether a device is a compatible devices, or not.
		/// </summary>
		/// <param name="info">The <see cref="RID_DEVICE_INFO"/> describing the device.</param>
		/// <returns><b>true</b> if the device is compatible with the class; otherwise, <b>false</b>.</returns>
		public static bool IsSpaceMouse(RID_DEVICE_INFO info)
		{
			return info.dwType==RIM_TYPE.HID&&info.hid.usUsage==HID_USAGE_GENERIC_DESKTOP.MULTIAXIS_CONTROLLER&&
				info.hid.usUsagePage==HID_USAGE_PAGE.GENERIC_DESKTOP&&
				(info.hid.dwVendorId==VendorID.Logitech||info.hid.dwVendorId==VendorID.D3connexion);
		}

		/// <summary>
		/// Set the state of the LED of a SpaceMouse/SpaceNavigator/SpaceExplorer/... devices.
		/// </summary>
		/// <param name="hDevice">The handle of the device.</param>
		/// <param name="enable">Defines the new state of the LED.</param>
		public static void SetLED(IntPtr hDevice, bool enable=true)
		{
			string name=RawInput.GetRawInputDeviceName(hDevice);

			IntPtr hFile=FileOperations.CreateFile(name, GENERIC.READ|GENERIC.WRITE, FILE_SHARE.READ|FILE_SHARE.WRITE, IntPtr.Zero,
				FileMode.OPEN_EXISTING, FILE_ATTRIBUTE.NORMAL, IntPtr.Zero);

			if(hFile!=FileOperations.INVALID_HANDLE_VALUE)
			{
				uint written;
				FileOperations.WriteFile(hFile, new byte[] { 4, (byte)(enable?1:0) }, 2, out written, IntPtr.Zero);
				FileOperations.CloseHandle(hFile);
			}

			WinKernel.SetLastError(0);
		}

		/// <summary>
		/// Enables the LED of a SpaceMouse/SpaceNavigator/SpaceExplorer/... devices.
		/// </summary>
{'fraction_non_alphanumeric': 0.141694225387942, 'fraction_numerical': 0.0071228694988552535, 'mean_word_length': 4.194187582562748, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2428571', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1321, 'n_words': 269}