Exemplo n.º 1
0
        private InputDevice MatchDevice(TabletConfiguration config, IList <DeviceIdentifier> identifiers)
        {
            foreach (var identifier in identifiers)
            {
                var matches = GetMatchingDevices(config, identifier);

                if (matches.Count() > 1)
                {
                    Log.Write("Detect", "More than 1 matching device has been found.", LogLevel.Warning);
                }

                foreach (IDeviceEndpoint dev in matches)
                {
                    try
                    {
                        return(new InputDevice(this, dev, config, identifier));
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        continue;
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public InputDevice(IDriver driver, IDeviceEndpoint device, TabletConfiguration configuration, DeviceIdentifier identifier)
            : base(device, driver.GetReportParser(identifier))
        {
            if (driver == null || device == null || configuration == null || identifier == null)
            {
                string argumentName = driver == null?nameof(driver) :
                                          device == null?nameof(device) :
                                              configuration == null?nameof(configuration) :
                                                  nameof(identifier);

                throw new ArgumentNullException(argumentName);
            }

            Endpoint      = device;
            Configuration = configuration;
            Identifier    = identifier;

            if (Configuration.Attributes.TryGetValue(DELAY_ATTRIBUTE_KEY_NAME, out var delayStr))
            {
                if (!uint.TryParse(delayStr, out _featureInitDelayMs))
                {
                    Log.Write("Device", $"Could not parse '{delayStr}' from attribute {DELAY_ATTRIBUTE_KEY_NAME}", LogLevel.Warning);
                }
            }

            Start();
        }
Exemplo n.º 3
0
 public ConfigurationSettings(TabletConfiguration config)
 {
     base.Content = new StackLayout
     {
         HorizontalContentAlignment = HorizontalAlignment.Stretch,
         Items =
         {
             new InputBox(
                 "Name",
                 () => config.Name,
                 (s) => config.Name = s
                 ),
             new DigitizerIdentifierEditor(
                 "Digitizer Identifiers",
                 () => config.DigitizerIdentifiers,
                 (o) => config.DigitizerIdentifiers = o
                 ),
             new AuxiliaryIdentifierEditor(
                 "Auxiliary Device Identifiers",
                 () => config.AuxilaryDeviceIdentifiers,
                 (o) => config.AuxilaryDeviceIdentifiers = o
                 ),
             new DictionaryEditor(
                 "Attributes",
                 () => config.Attributes,
                 (o) => config.Attributes = o
                 )
         }
     };
 }
Exemplo n.º 4
0
        public async Task <bool> SetTablet(TabletConfiguration tablet)
        {
            var match = Driver.TryMatch(tablet);

            TabletChanged?.Invoke(this, match ? await GetTablet() : null);
            return(match);
        }
Exemplo n.º 5
0
        static IEnumerable <TabletConfiguration> GetAllConfigurations(DirectoryInfo directory)
        {
            var files = Directory.GetFiles(directory.FullName, "*.json", SearchOption.AllDirectories);

            foreach (var path in files)
            {
                var file = new FileInfo(path);
                yield return(TabletConfiguration.Read(file));
            }
        }
Exemplo n.º 6
0
 public TabletState(
     TabletConfiguration tabletProperties,
     DigitizerIdentifier digitizer,
     DeviceIdentifier auxiliary
     )
 {
     TabletProperties = tabletProperties;
     Digitizer        = digitizer;
     Auxiliary        = auxiliary;
 }
Exemplo n.º 7
0
 public TabletStatus(
     TabletConfiguration tabletProperties,
     DigitizerIdentifier tabletIdentifier,
     DeviceIdentifier auxiliaryIdentifier
     )
 {
     TabletProperties    = tabletProperties;
     TabletIdentifier    = tabletIdentifier;
     AuxiliaryIdentifier = auxiliaryIdentifier;
 }
Exemplo n.º 8
0
 private IEnumerable <IDeviceEndpoint> GetMatchingDevices(TabletConfiguration configuration, DeviceIdentifier identifier)
 {
     return(from device in HidSharpDeviceRootHub.Current.GetDevices()
            where identifier.VendorID == device.VendorID
            where identifier.ProductID == device.ProductID
            where device.CanOpen
            where identifier.InputReportLength == null || identifier.InputReportLength == device.InputReportLength
            where identifier.OutputReportLength == null || identifier.OutputReportLength == device.OutputReportLength
            where DeviceMatchesStrings(device, identifier.DeviceStrings)
            where DeviceMatchesAttribute(device, configuration.Attributes)
            select device);
 }
 public static IEnumerable <Rule> CreateOverrideRules(TabletConfiguration tablet)
 {
     foreach (var id in GetDistinctIdentifiers(tablet))
     {
         yield return(new Rule(
                          new Token("SUBSYSTEM", Operator.Equal, "input"),
                          new ATTRS("idVendor", Operator.Equal, id.VendorID.ToHexFormat()),
                          new ATTRS("idProduct", Operator.Equal, id.ProductID.ToHexFormat()),
                          new ENV("LIBINPUT_IGNORE_DEVICE", Operator.Assign, "1")
                          ));
     }
 }
 public static IEnumerable <Rule> CreateAccessRules(TabletConfiguration tablet, string subsystem, string mode)
 {
     foreach (var id in GetDistinctIdentifiers(tablet))
     {
         yield return(new Rule(
                          new Token("SUBSYSTEM", Operator.Equal, subsystem),
                          new ATTRS("idVendor", Operator.Equal, id.VendorID.ToHexFormat()),
                          new ATTRS("idProduct", Operator.Equal, id.ProductID.ToHexFormat()),
                          new Token("MODE", Operator.Assign, mode)
                          ));
     }
 }
Exemplo n.º 11
0
        protected virtual InputDeviceTree Match(TabletConfiguration config)
        {
            Log.Write("Detect", $"Searching for tablet '{config.Name}'");
            try
            {
                var devices = new List <InputDevice>();
                if (MatchDevice(config, config.DigitizerIdentifiers) is InputDevice digitizer)
                {
                    Log.Write("Detect", $"Found tablet '{config.Name}'");
                    devices.Add(digitizer);

                    if (config.AuxilaryDeviceIdentifiers.Any())
                    {
                        if (MatchDevice(config, config.AuxilaryDeviceIdentifiers) is InputDevice aux)
                        {
                            devices.Add(aux);
                        }
                        else
                        {
                            Log.Write("Detect", "Failed to find auxiliary device, express keys may be unavailable.", LogLevel.Warning);
                        }
                    }

                    return(new InputDeviceTree(config, devices));
                }
            }
            catch (IOException iex) when(iex.Message.Contains("Unable to open HID class device") &&
                                         SystemInterop.CurrentPlatform == PluginPlatform.Linux)
            {
                Log.Write(
                    "Driver",
                    "The current user does not have the permissions to open the device stream. " +
                    "Follow the instructions from https://github.com/OpenTabletDriver/OpenTabletDriver/wiki/Linux-FAQ#the-driver-fails-to-open-the-tablet-deviceioexception to resolve this issue.",
                    LogLevel.Error
                    );
            }
            catch (ArgumentOutOfRangeException aex) when(aex.Message.Contains("Value range is [0, 15]") &&
                                                         SystemInterop.CurrentPlatform == PluginPlatform.Linux)
            {
                Log.Write(
                    "Driver",
                    "Device is currently in use by another kernel module. " +
                    "Follow the instructions from https://github.com/OpenTabletDriver/OpenTabletDriver/wiki/Linux-FAQ#argumentoutofrangeexception-value-0-15 to resolve this issue.",
                    LogLevel.Error
                    );
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
            return(null);
        }
Exemplo n.º 12
0
        public InputDeviceTree(TabletConfiguration configuration, IList <InputDevice> inputDevices)
        {
            Properties   = configuration;
            InputDevices = inputDevices;

            foreach (var dev in InputDevices)
            {
                // Hook endpoint states
                dev.ConnectionStateChanged += (sender, reading) =>
                {
                    if (this.connected && !reading)
                    {
                        this.connected = false;
                        Disconnected?.Invoke(this, new EventArgs());
                    }
                };
            }
        }
Exemplo n.º 13
0
        public InputDevice(IDriver driver, IDeviceEndpoint device, TabletConfiguration configuration, DeviceIdentifier identifier)
            : base(device, driver.GetReportParser(identifier))
        {
            if (driver == null || device == null || configuration == null || identifier == null)
            {
                string argumentName = driver == null?nameof(driver) :
                                          device == null?nameof(device) :
                                              configuration == null?nameof(configuration) :
                                                  nameof(identifier);

                throw new ArgumentNullException(argumentName);
            }

            Endpoint      = device;
            Configuration = configuration;
            Identifier    = identifier;

            Start();
        }
Exemplo n.º 14
0
        public async Task <TabletStatus> DetectTablets()
        {
            var configDir = new DirectoryInfo(AppInfo.Current.ConfigurationDirectory);

            if (configDir.Exists)
            {
                foreach (var file in configDir.EnumerateFiles("*.json", SearchOption.AllDirectories))
                {
                    var tablet = TabletConfiguration.Read(file);
                    if (await SetTablet(tablet))
                    {
                        return(await GetTablet());
                    }
                }
            }
            else
            {
                Log.Write("Detect", $"The configuration directory '{configDir.FullName}' does not exist.", LogLevel.Error);
            }
            return(null);
        }
Exemplo n.º 15
0
 public record IdentificationContext(TabletConfiguration TabletConfiguration,
                                     DeviceIdentifier Identifier,
                                     IdentifierType IdentifierType,
                                     int IdentifierIndex);
        private static IEnumerable <DeviceIdentifier> GetDistinctIdentifiers(TabletConfiguration config)
        {
            var allIdentifiers = config.DigitizerIdentifiers.Concat(config.AuxilaryDeviceIdentifiers);

            return(allIdentifiers.Distinct(new IdentifierComparer()));
        }