Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 1 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | # |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 5 | """ This module manages the platform properties in mttools/platforms. """ |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 6 | |
Harry Cutts | 69fc2be | 2020-01-22 18:03:21 -0800 | [diff] [blame] | 7 | from __future__ import absolute_import |
| 8 | from __future__ import division |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 9 | from __future__ import print_function |
| 10 | |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 11 | from collections import namedtuple |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 12 | import json |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 13 | import os |
| 14 | import re |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 15 | import sys |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 16 | |
Harry Cutts | 69fc2be | 2020-01-22 18:03:21 -0800 | [diff] [blame] | 17 | from .cros_remote import CrOSRemote |
| 18 | from .util import AskUser, ExecuteException |
| 19 | from .xorg_conf import XorgInputClassParser |
| 20 | from functools import reduce |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 21 | |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 22 | # path to current script directory |
| 23 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 24 | platforms_dir = os.path.realpath(os.path.join(script_dir, '..', 'platforms')) |
Chung-yih Wang | 35613f1 | 2014-04-25 13:57:23 +0800 | [diff] [blame] | 25 | xorg_conf_project_path = 'src/platform/xorg-conf' |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 26 | |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 27 | props_template = """\ |
| 28 | { |
| 29 | "gestures": { |
| 30 | }, |
| 31 | "xorg": { |
| 32 | "file": "%s", |
| 33 | "identifiers": %s |
| 34 | }, |
| 35 | "ignore": [ |
| 36 | ] |
| 37 | }""" |
| 38 | |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 39 | AbsInfo = namedtuple("AbsInfo", ("min", "max", "res")) |
| 40 | |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 41 | class PlatformProperties(object): |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 42 | """ A class containing hardware and xorg properties for a platform. |
| 43 | |
| 44 | The class can be created from an activity log or by providing |
| 45 | the name of the platform. Information will then be read from the |
| 46 | 'platforms_dir' directory. |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 47 | """ |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 48 | def __init__(self, platform=None, log=None): |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 49 | self.absinfos = {} |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 50 | self.device_class = "touchpad" |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 51 | self.properties = {} |
| 52 | self.ignore_properties = [] |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 53 | if platform: |
| 54 | basename = os.path.join(platforms_dir, platform) |
| 55 | self.name = platform |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 56 | self.hwprops_file = basename + '.hwprops' |
| 57 | self.props_file = basename + '.props' |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 58 | self.xorg_parser = XorgInputClassParser() |
| 59 | self._ParseHWProperties(open(self.hwprops_file).read()) |
| 60 | self._ParseProperties(open(self.props_file).read()) |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 61 | elif log: |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 62 | self.name = '' |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 63 | if log.evdev: |
| 64 | self._ParseEvdevLog(log.evdev) |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 65 | |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 66 | def _ParseEvdevLog(self, evdev_data): |
Dennis Kempin | 143ef16 | 2014-04-09 13:46:50 -0700 | [diff] [blame] | 67 | # Look for embedded hwproperties in header. Format: |
| 68 | # absinfo: axis min max 0 0 res |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 69 | values_regex = 6 * ' ([-0-9]+)' |
| 70 | abs_regex = re.compile('# absinfo:' + values_regex) |
| 71 | for match in abs_regex.finditer(evdev_data): |
| 72 | axis = int(match.group(1)) |
| 73 | info = AbsInfo(min=int(match.group(2)), max=int(match.group(3)), |
| 74 | res=int(match.group(6))) |
| 75 | self.absinfos[axis] = info |
Dennis Kempin | 143ef16 | 2014-04-09 13:46:50 -0700 | [diff] [blame] | 76 | |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 77 | def _ParseHWProperties(self, data): |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 78 | """Parse x and y dimensions and resolution from hwprops file.""" |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 79 | values_regex = 6 * ' ([0-9\\-a-fA-F]+)' |
| 80 | abs_regex = re.compile('A:' + values_regex) |
| 81 | for match in abs_regex.finditer(data): |
| 82 | axis = int(match.group(1), 16) |
| 83 | info = AbsInfo(min=int(match.group(2)), max=int(match.group(3)), |
| 84 | res=int(match.group(6))) |
| 85 | self.absinfos[axis] = info |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 86 | |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 87 | def _ParseProperties(self, data): |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 88 | """ Parse properties from file and inject xorg properties. """ |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 89 | self.properties = {} |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 90 | self.ignore_properties = [] |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 91 | data = json.loads(data) |
| 92 | |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 93 | if 'gestures' in data: |
| 94 | self.properties.update(data['gestures']) |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 95 | |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 96 | if 'device_class' in data: |
| 97 | self.device_class = data['device_class'] |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 98 | |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 99 | if 'ignore' in data: |
| 100 | self.ignore_properties.extend(data['ignore']) |
| 101 | |
Chung-yih Wang | 35613f1 | 2014-04-25 13:57:23 +0800 | [diff] [blame] | 102 | # Sanity check: Make sure it is not used inside ebuild. |
| 103 | if os.environ.get('PN') and os.environ.get('S'): |
| 104 | raise Exception("Should not be executed inside ebuild") |
| 105 | |
| 106 | # If run on a Chromebook device, access xorg-conf files from their normal |
| 107 | # installed location. If run from inside chroot, access xorg-conf files |
| 108 | # from the xorg-conf project repository. |
| 109 | src_root = os.environ.get('CROS_WORKON_SRCROOT') |
| 110 | if src_root: |
| 111 | xorg_conf_path = os.path.join(src_root, xorg_conf_project_path) |
| 112 | else: |
Andrew de los Reyes | c012597 | 2015-01-28 10:04:44 -0800 | [diff] [blame] | 113 | xorg_conf_path = '/etc/gesture' |
| 114 | if not os.path.exists(xorg_conf_path): |
| 115 | xorg_conf_path = '/etc/X11/xorg.conf.d' |
Chung-yih Wang | 35613f1 | 2014-04-25 13:57:23 +0800 | [diff] [blame] | 116 | |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 117 | if xorg_conf_path and 'xorg' in data and 'file' in data['xorg']: |
| 118 | filename = os.path.join(xorg_conf_path, data['xorg']['file']) |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 119 | input_classes = self.xorg_parser.Parse(file=filename) |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 120 | if 'identifier' in data['xorg']: |
| 121 | properties = input_classes[data['xorg']['identifier']] |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 122 | self.properties.update(properties) |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 123 | if 'identifiers' in data['xorg']: |
| 124 | for identifier in data['xorg']['identifiers']: |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 125 | properties = input_classes[identifier] |
| 126 | self.properties.update(properties) |
| 127 | |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 128 | for prop in self.ignore_properties: |
| 129 | if prop in self.properties: |
| 130 | del self.properties[prop] |
| 131 | |
Dennis Kempin | 55af9cc | 2013-06-20 15:07:21 -0700 | [diff] [blame] | 132 | def Match(self, other, loose, debug=False): |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 133 | """ Compare properties and return similarity. |
| 134 | |
| 135 | Compare these properties to another PlatformProperties instance. |
| 136 | The return value is a score between 1. 0 meaning there is a big mismatch |
| 137 | and 1 meaning the properties match completely. |
| 138 | Only a selected range of properties are compared in order to |
| 139 | prevent property adjustments to cause platforms to be mismatched. |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 140 | """ |
| 141 | scores = [] |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 142 | def compare_absinfo_prop(a, b, field): |
| 143 | a_value = float(getattr(a, field)) if a else None |
| 144 | b_value = float(getattr(b, field)) if b else None |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 145 | |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 146 | score = 0.0 |
| 147 | if a_value is not None and b_value is not None: |
| 148 | delta = abs(float(a_value) - float(b_value)) |
| 149 | if delta > 0: |
| 150 | score = 1.0 - min(1.0, delta / max(abs(a_value), abs(b_value))) |
| 151 | else: |
| 152 | score = 1.0 |
| 153 | scores.append(score) |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 154 | |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 155 | a_str = str(a_value) if a_value is not None else "N/A" |
| 156 | b_str = str(b_value) if b_value is not None else "N/A" |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 157 | if debug: |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 158 | print(" %s: %.2f (%s == %s)" % (field, score, a_str, b_str)) |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 159 | |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 160 | for axis in set(self.absinfos.keys() + other.absinfos.keys()): |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 161 | if debug: |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 162 | print("axis %d:" % axis) |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 163 | self_absinfo = self.absinfos.get(axis, None) |
| 164 | other_absinfo = other.absinfos.get(axis, None) |
| 165 | compare_absinfo_prop(self_absinfo, other_absinfo, "min") |
| 166 | compare_absinfo_prop(self_absinfo, other_absinfo, "max") |
| 167 | compare_absinfo_prop(self_absinfo, other_absinfo, "res") |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 168 | |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 169 | return reduce(lambda x, y: (x * y), scores) |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 170 | |
| 171 | class PlatformDatabase(object): |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 172 | """ Class for managing platforms. |
| 173 | |
| 174 | This class reads all available platforms from the platforms_dir and allows |
| 175 | to search for matching platforms to an activity log file. |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 176 | """ |
| 177 | def __init__(self): |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 178 | platform_files = [f for f in os.listdir(platforms_dir) |
| 179 | if f.endswith('.hwprops')] |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 180 | self.platforms = {} |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 181 | for filename in platform_files: |
| 182 | name = filename.replace('.hwprops', '') |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 183 | self.platforms[name] = PlatformProperties(platform=name) |
| 184 | |
Dennis Kempin | 55af9cc | 2013-06-20 15:07:21 -0700 | [diff] [blame] | 185 | def FindMatching(self, log, loose=True, debug=False): |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 186 | """ Find platform matching activity_data. |
| 187 | |
| 188 | Returns the PlatformProperties instance of the platform matching |
| 189 | the activity log data. This method might terminate the program in |
| 190 | case no match can be made, or the match is ambiguous. |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 191 | """ |
| 192 | result = None |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 193 | properties = PlatformProperties(log=log) |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 194 | for name, platform in self.platforms.items(): |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 195 | if debug: |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 196 | print("-" * 30, name) |
Dennis Kempin | 55af9cc | 2013-06-20 15:07:21 -0700 | [diff] [blame] | 197 | score = platform.Match(properties, loose, debug) |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 198 | if debug: |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 199 | print(name, "score =", score) |
Andrew de los Reyes | f56af27 | 2014-07-21 14:32:21 -0700 | [diff] [blame] | 200 | if score > 0.96: |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 201 | if result: |
Dennis Kempin | 55af9cc | 2013-06-20 15:07:21 -0700 | [diff] [blame] | 202 | if loose: |
| 203 | if debug: |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 204 | print("-" * 10, "Multiple matches. Try strict") |
Dennis Kempin | 55af9cc | 2013-06-20 15:07:21 -0700 | [diff] [blame] | 205 | return self.FindMatching(log, False, debug) |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 206 | print(("multiple matching platforms:", result.name, |
| 207 | "and", platform.name)) |
Dennis Kempin | 19e972b | 2013-06-20 13:21:38 -0700 | [diff] [blame] | 208 | return None |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 209 | result = platform |
| 210 | if not result: |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 211 | print("cannot find matching platform") |
Dennis Kempin | 19e972b | 2013-06-20 13:21:38 -0700 | [diff] [blame] | 212 | return None |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 213 | return result |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 214 | |
| 215 | @staticmethod |
| 216 | def RegisterPlatformFromDevice(ip): |
| 217 | # get list of multitouch devices |
| 218 | remote = CrOSRemote(ip) |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 219 | inputcontrolexist = True |
| 220 | try: |
| 221 | devices = remote.SafeExecute( |
| 222 | "/opt/google/input/inputcontrol -t multitouch --names", |
| 223 | verbose=True) |
| 224 | except ExecuteException: |
| 225 | inputcontrolexist = False |
| 226 | if inputcontrolexist: |
| 227 | # Each line has the format: |
| 228 | # id: Device Name |
| 229 | # devices[*][0] will have the id |
| 230 | # devices[*][1] will have the name |
| 231 | devices = devices.splitlines() |
| 232 | devices = [l.split(":", 1) for l in devices] |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 233 | |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 234 | # select one device from list |
| 235 | idx = AskUser.Select([d[1] for d in devices], |
| 236 | "Which device would you like to register?") |
| 237 | device_id = devices[idx][0] |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 238 | |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 239 | # read hardware properties |
| 240 | hwprops = remote.SafeExecute( |
| 241 | "/opt/google/input/inputcontrol --id %s --hwprops" % device_id, |
| 242 | verbose=True) |
| 243 | else: |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame] | 244 | event_devices = remote.SafeExecute( |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 245 | "ls /dev/input/ | grep event", |
| 246 | verbose=True) |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame] | 247 | event_devices = event_devices.splitlines() |
| 248 | devices = [] |
| 249 | for d in event_devices: |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 250 | device_desc_evemu = remote.SafeExecute( |
| 251 | "evemu-describe /dev/input/%s |grep N:" % d, |
| 252 | verbose=False) |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame] | 253 | event_number = int((d.split("event", 1))[1]) |
Amirhossein Simjour | bcc3701 | 2015-07-07 14:59:56 -0400 | [diff] [blame] | 254 | device_desc_evemu = device_desc_evemu.split("N:",1)[1] |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame] | 255 | |
| 256 | devices.append([event_number, device_desc_evemu]) |
| 257 | |
| 258 | idx = AskUser.Select([t[1] for t in devices], |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 259 | "Which device would you like to register?") |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame] | 260 | device_id = devices[idx][0] |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 261 | hwprops = remote.SafeExecute( |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame] | 262 | "evemu-describe /dev/input/event%s" % devices[idx][0], |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 263 | verbose=True) |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 264 | if not hwprops: |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 265 | print("Please update your device to latest canary or:") |
| 266 | print(" emerge-${BOARD} inputcontrol") |
| 267 | print(" cros deploy $DEVICE_IP inputcontrol") |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 268 | return None |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame] | 269 | |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 270 | |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 271 | xorg_files = [ |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 272 | "/etc/X11/xorg.conf.d/60-touchpad-cmt-*.conf", |
| 273 | "/etc/X11/xorg.conf.d/50-touchpad-cmt-*.conf", |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 274 | "/etc/X11/xorg.conf.d/40-touchpad-cmt.conf", |
| 275 | "/etc/gesture/60-touchpad-cmt-*.conf", |
| 276 | "/etc/gesture/50-touchpad-cmt-*.conf", |
| 277 | "/etc/gesture/40-touchpad-cmt.conf" |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 278 | ] |
| 279 | |
| 280 | for pattern in xorg_files: |
| 281 | # find filename of xorg configuration file |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 282 | xorg_file = remote.Execute("ls " + pattern, verbose=False) |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 283 | if not xorg_file: |
| 284 | continue |
| 285 | xorg_file = xorg_file.strip() |
| 286 | |
| 287 | # extract identifiers |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 288 | print("Selecting Xorg identifiers from", xorg_file) |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 289 | conf = remote.Read(xorg_file) |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 290 | all_ids = [] |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 291 | for match in re.finditer("Identifier\\s+\"([a-zA-Z0-9-_ ]+)\"", conf): |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 292 | all_ids.append(match.group(1)) |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 293 | |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 294 | # ask user to select |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 295 | idxs = AskUser.SelectMulti( |
| 296 | all_ids, "Which xorg identifiers apply to this device?", |
| 297 | allow_none=True) |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 298 | ids = [all_ids[i] for i in idxs] |
| 299 | if ids: |
| 300 | break |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 301 | |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 302 | if not ids: |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 303 | print("Please configure the platform properties manually") |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 304 | xorg_file = "todo: add correct xorg conf file" |
| 305 | ids = ["todo: add correct xorg identifier"] |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 306 | |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 307 | ids_string = "[" + ", ".join(["\"%s\"" % i for i in ids]) + "]" |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 308 | xorg_file = os.path.basename(xorg_file) |
| 309 | |
| 310 | sys.stdout.write("Please name this platform: ") |
| 311 | sys.stdout.flush() |
| 312 | platform_name = sys.stdin.readline().strip() |
| 313 | |
| 314 | # write platform info to files |
| 315 | hwprops_file = os.path.join(platforms_dir, platform_name + ".hwprops") |
| 316 | props_file = os.path.join(platforms_dir, platform_name + ".props") |
| 317 | |
| 318 | open(hwprops_file, "w").write(hwprops) |
| 319 | open(props_file, "w").write(props_template % (xorg_file, ids_string)) |
| 320 | |
Harry Cutts | 0edf157 | 2020-01-21 15:42:10 -0800 | [diff] [blame] | 321 | print("Created files: ") |
| 322 | print(" ", hwprops_file) |
| 323 | print(" ", props_file) |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 324 | |
| 325 | return platform_name |