diff --git a/.pylintrc b/.pylintrc index d7edeb117..73035360c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -54,7 +54,7 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=C,R,W0613,W0511,W0212,W0201,W0311,W0106,W0603,W0621,W0703,W1201,W1203,E1136,W1514 +disable=C,R,W0613,W0511,W0212,W0201,W0106,W0603,W0621,W0703,W1201,W1203,E1136,W1514 # Enable the message, report, category or checker with the given id(s). You can diff --git a/common/kalman/tests/test_simple_kalman.py b/common/kalman/tests/test_simple_kalman.py index 7b327918a..96b252765 100644 --- a/common/kalman/tests/test_simple_kalman.py +++ b/common/kalman/tests/test_simple_kalman.py @@ -36,8 +36,8 @@ class TestSimpleKalman(unittest.TestCase): self.assertEqual(self.kf.x, [[1.0], [1.0]]) def update_returns_state(self): - x = self.kf.update(100) - self.assertEqual(x, self.kf.x) + x = self.kf.update(100) + self.assertEqual(x, self.kf.x) def test_old_equal_new(self): for _ in range(1000): diff --git a/common/logging_extra.py b/common/logging_extra.py index d3a75d0f4..53f4c0a53 100644 --- a/common/logging_extra.py +++ b/common/logging_extra.py @@ -172,33 +172,33 @@ class SwagLogger(logging.Logger): #On some versions of IronPython, currentframe() returns None if #IronPython isn't run with -X:Frames. if f is not None: - f = f.f_back + f = f.f_back orig_f = f while f and stacklevel > 1: - f = f.f_back - stacklevel -= 1 + f = f.f_back + stacklevel -= 1 if not f: - f = orig_f + f = orig_f rv = "(unknown file)", 0, "(unknown function)", None while hasattr(f, "f_code"): - co = f.f_code - filename = os.path.normcase(co.co_filename) + co = f.f_code + filename = os.path.normcase(co.co_filename) - # TODO: is this pylint exception correct? - if filename == _srcfile: # pylint: disable=comparison-with-callable - f = f.f_back - continue - sinfo = None - if stack_info: - sio = io.StringIO() - sio.write('Stack (most recent call last):\n') - traceback.print_stack(f, file=sio) - sinfo = sio.getvalue() - if sinfo[-1] == '\n': - sinfo = sinfo[:-1] - sio.close() - rv = (co.co_filename, f.f_lineno, co.co_name, sinfo) - break + # TODO: is this pylint exception correct? + if filename == _srcfile: # pylint: disable=comparison-with-callable + f = f.f_back + continue + sinfo = None + if stack_info: + sio = io.StringIO() + sio.write('Stack (most recent call last):\n') + traceback.print_stack(f, file=sio) + sinfo = sio.getvalue() + if sinfo[-1] == '\n': + sinfo = sinfo[:-1] + sio.close() + rv = (co.co_filename, f.f_lineno, co.co_name, sinfo) + break return rv if __name__ == "__main__": diff --git a/selfdrive/boardd/tests/test_boardd_api.py b/selfdrive/boardd/tests/test_boardd_api.py index 9386c7845..f2bcd57a6 100644 --- a/selfdrive/boardd/tests/test_boardd_api.py +++ b/selfdrive/boardd/tests/test_boardd_api.py @@ -74,4 +74,4 @@ class TestBoarddApiMethods(unittest.TestCase): if __name__ == '__main__': - unittest.main() + unittest.main() diff --git a/selfdrive/camerad/test/get_thumbnails_for_segment.py b/selfdrive/camerad/test/get_thumbnails_for_segment.py index ab9a7b308..898377b11 100755 --- a/selfdrive/camerad/test/get_thumbnails_for_segment.py +++ b/selfdrive/camerad/test/get_thumbnails_for_segment.py @@ -24,9 +24,9 @@ if __name__ == "__main__": lr = list(LogReader(path)) for msg in tqdm(lr): - if msg.which() == 'thumbnail': - with open(os.path.join(out_path, f"{msg.thumbnail.frameId}.jpg"), 'wb') as f: - f.write(msg.thumbnail.thumbnail) - elif msg.which() == 'navThumbnail': - with open(os.path.join(out_path, f"nav_{msg.navThumbnail.frameId}.jpg"), 'wb') as f: - f.write(msg.navThumbnail.thumbnail) + if msg.which() == 'thumbnail': + with open(os.path.join(out_path, f"{msg.thumbnail.frameId}.jpg"), 'wb') as f: + f.write(msg.thumbnail.thumbnail) + elif msg.which() == 'navThumbnail': + with open(os.path.join(out_path, f"nav_{msg.navThumbnail.frameId}.jpg"), 'wb') as f: + f.write(msg.navThumbnail.thumbnail) diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 5e0c428c3..8a23154bc 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -404,7 +404,7 @@ class CarInterface(CarInterfaceBase): # do enable on both accel and decel buttons if not self.CP.pcmCruise: if b.type in (ButtonType.accelCruise, ButtonType.decelCruise) and not b.pressed: - events.add(EventName.buttonEnable) + events.add(EventName.buttonEnable) # do disable on button down if b.type == ButtonType.cancel and b.pressed: diff --git a/selfdrive/car/nissan/carcontroller.py b/selfdrive/car/nissan/carcontroller.py index 15cd44be9..4ceb142d4 100644 --- a/selfdrive/car/nissan/carcontroller.py +++ b/selfdrive/car/nissan/carcontroller.py @@ -58,14 +58,14 @@ class CarController(): self.last_angle = apply_angle if self.CP.carFingerprint in (CAR.ROGUE, CAR.XTRAIL, CAR.ALTIMA) and cruise_cancel: - can_sends.append(nissancan.create_acc_cancel_cmd(self.packer, self.car_fingerprint, CS.cruise_throttle_msg, frame)) + can_sends.append(nissancan.create_acc_cancel_cmd(self.packer, self.car_fingerprint, CS.cruise_throttle_msg, frame)) # TODO: Find better way to cancel! # For some reason spamming the cancel button is unreliable on the Leaf # We now cancel by making propilot think the seatbelt is unlatched, # this generates a beep and a warning message every time you disengage if self.CP.carFingerprint in (CAR.LEAF, CAR.LEAF_IC) and frame % 2 == 0: - can_sends.append(nissancan.create_cancel_msg(self.packer, CS.cancel_msg, cruise_cancel)) + can_sends.append(nissancan.create_cancel_msg(self.packer, CS.cancel_msg, cruise_cancel)) can_sends.append(nissancan.create_steering_control( self.packer, apply_angle, frame, c.enabled, self.lkas_max_torque)) diff --git a/selfdrive/car/subaru/subarucan.py b/selfdrive/car/subaru/subarucan.py index 86ec5e8bd..63511d183 100644 --- a/selfdrive/car/subaru/subarucan.py +++ b/selfdrive/car/subaru/subarucan.py @@ -54,7 +54,7 @@ def create_es_lkas(packer, es_lkas_msg, enabled, visual_alert, left_line, right_ values["LKAS_ACTIVE"] = 1 # Show LKAS lane lines values["LKAS_Dash_State"] = 2 # Green enabled indicator else: - values["LKAS_Dash_State"] = 0 # LKAS Not enabled + values["LKAS_Dash_State"] = 0 # LKAS Not enabled values["LKAS_Left_Line_Visible"] = int(left_line) values["LKAS_Right_Line_Visible"] = int(right_line) diff --git a/selfdrive/car/tests/test_fingerprints.py b/selfdrive/car/tests/test_fingerprints.py index 01c7d753c..9dd28b2d5 100755 --- a/selfdrive/car/tests/test_fingerprints.py +++ b/selfdrive/car/tests/test_fingerprints.py @@ -37,12 +37,12 @@ def check_fingerprint_consistency(f1, f2): is_f1_in_f2 = True for k in f1: if (k not in f2 or f1[k] != f2[k]) and k < max_msg: - is_f1_in_f2 = False + is_f1_in_f2 = False is_f2_in_f1 = True for k in f2: if (k not in f1 or f2[k] != f1[k]) and k < max_msg: - is_f2_in_f1 = False + is_f2_in_f1 = False return not is_f1_in_f2 and not is_f2_in_f1 diff --git a/selfdrive/debug/show_matching_cars.py b/selfdrive/debug/show_matching_cars.py index 79a23c1f8..d5199b2a9 100755 --- a/selfdrive/debug/show_matching_cars.py +++ b/selfdrive/debug/show_matching_cars.py @@ -10,11 +10,11 @@ candidate_cars = all_legacy_fingerprint_cars() for addr, l in fingerprint.items(): - dat = messaging.new_message('can', 1) + dat = messaging.new_message('can', 1) - msg = dat.can[0] - msg.address = addr - msg.dat = " " * l + msg = dat.can[0] + msg.address = addr + msg.dat = " " * l - candidate_cars = eliminate_incompatible_cars(msg, candidate_cars) - print(candidate_cars) + candidate_cars = eliminate_incompatible_cars(msg, candidate_cars) + print(candidate_cars) diff --git a/selfdrive/hardware/tici/hardware.py b/selfdrive/hardware/tici/hardware.py index 38f914680..22c9abd8a 100644 --- a/selfdrive/hardware/tici/hardware.py +++ b/selfdrive/hardware/tici/hardware.py @@ -24,19 +24,19 @@ MM_MODEM_SIMPLE = MM + ".Modem.Simple" MM_SIM = MM + ".Sim" class MM_MODEM_STATE(IntEnum): - FAILED = -1 - UNKNOWN = 0 - INITIALIZING = 1 - LOCKED = 2 - DISABLED = 3 - DISABLING = 4 - ENABLING = 5 - ENABLED = 6 - SEARCHING = 7 - REGISTERED = 8 - DISCONNECTING = 9 - CONNECTING = 10 - CONNECTED = 11 + FAILED = -1 + UNKNOWN = 0 + INITIALIZING = 1 + LOCKED = 2 + DISABLED = 3 + DISABLING = 4 + ENABLING = 5 + ENABLED = 6 + SEARCHING = 7 + REGISTERED = 8 + DISCONNECTING = 9 + CONNECTING = 10 + CONNECTED = 11 class NMMetered(IntEnum): NM_METERED_UNKNOWN = 0 @@ -194,14 +194,14 @@ class Tici(HardwareBase): return None def parse_strength(self, percentage): - if percentage < 25: - return NetworkStrength.poor - elif percentage < 50: - return NetworkStrength.moderate - elif percentage < 75: - return NetworkStrength.good - else: - return NetworkStrength.great + if percentage < 25: + return NetworkStrength.poor + elif percentage < 50: + return NetworkStrength.moderate + elif percentage < 75: + return NetworkStrength.good + else: + return NetworkStrength.great def get_network_strength(self, network_type): network_strength = NetworkStrength.unknown diff --git a/selfdrive/locationd/models/loc_kf.py b/selfdrive/locationd/models/loc_kf.py index 199cc7e20..b6293d60d 100755 --- a/selfdrive/locationd/models/loc_kf.py +++ b/selfdrive/locationd/models/loc_kf.py @@ -474,14 +474,14 @@ class LocKalman(): z = trans[:, :3] R = np.zeros((len(trans), 3, 3)) for i, _ in enumerate(z): - R[i, :, :] = np.diag(trans[i, 3:]**2) + R[i, :, :] = np.diag(trans[i, 3:]**2) return self.filter.predict_and_update_batch(t, kind, z, R) def predict_and_update_odo_rot(self, rot, t, kind): z = rot[:, :3] R = np.zeros((len(rot), 3, 3)) for i, _ in enumerate(z): - R[i, :, :] = np.diag(rot[i, 3:]**2) + R[i, :, :] = np.diag(rot[i, 3:]**2) return self.filter.predict_and_update_batch(t, kind, z, R) def predict_and_update_orb_features(self, tracks, t, kind): @@ -518,7 +518,7 @@ class LocKalman(): y_full = np.zeros((z.shape[0], z.shape[1] - 3)) if sum(good_idxs) > 0: - y_full[good_idxs] = np.array(ret[6]) + y_full[good_idxs] = np.array(ret[6]) ret = ret[:6] + (y_full, z, ecef_pos) return ret diff --git a/selfdrive/loggerd/tests/fill_eon.py b/selfdrive/loggerd/tests/fill_eon.py index f273ea89e..b40982fa9 100755 --- a/selfdrive/loggerd/tests/fill_eon.py +++ b/selfdrive/loggerd/tests/fill_eon.py @@ -23,4 +23,4 @@ if __name__ == "__main__": # Fill up to 99 percent available_percent = get_available_percent() if available_percent < 1.0: - break + break diff --git a/selfdrive/loggerd/tests/loggerd_tests_common.py b/selfdrive/loggerd/tests/loggerd_tests_common.py index 59952fd2c..80cfb162f 100644 --- a/selfdrive/loggerd/tests/loggerd_tests_common.py +++ b/selfdrive/loggerd/tests/loggerd_tests_common.py @@ -8,22 +8,22 @@ import unittest import selfdrive.loggerd.uploader as uploader def create_random_file(file_path, size_mb, lock=False): - try: - os.mkdir(os.path.dirname(file_path)) - except OSError: - pass + try: + os.mkdir(os.path.dirname(file_path)) + except OSError: + pass - lock_path = file_path + ".lock" - if lock: - os.close(os.open(lock_path, os.O_CREAT | os.O_EXCL)) + lock_path = file_path + ".lock" + if lock: + os.close(os.open(lock_path, os.O_CREAT | os.O_EXCL)) - chunks = 128 - chunk_bytes = int(size_mb * 1024 * 1024 / chunks) - data = os.urandom(chunk_bytes) + chunks = 128 + chunk_bytes = int(size_mb * 1024 * 1024 / chunks) + data = os.urandom(chunk_bytes) - with open(file_path, 'wb') as f: - for _ in range(chunks): - f.write(data) + with open(file_path, 'wb') as f: + for _ in range(chunks): + f.write(data) class MockResponse(): def __init__(self, text, status_code): diff --git a/selfdrive/manager/process.py b/selfdrive/manager/process.py index ebdd2a90b..4cd9783b2 100644 --- a/selfdrive/manager/process.py +++ b/selfdrive/manager/process.py @@ -199,7 +199,7 @@ class NativeProcess(ManagerProcess): def start(self) -> None: # In case we only tried a non blocking stop we need to stop it before restarting if self.shutting_down: - self.stop() + self.stop() if self.proc is not None: return @@ -231,7 +231,7 @@ class PythonProcess(ManagerProcess): def start(self) -> None: # In case we only tried a non blocking stop we need to stop it before restarting if self.shutting_down: - self.stop() + self.stop() if self.proc is not None: return diff --git a/selfdrive/monitoring/test_monitoring.py b/selfdrive/monitoring/test_monitoring.py index 66b345194..a84ed242b 100755 --- a/selfdrive/monitoring/test_monitoring.py +++ b/selfdrive/monitoring/test_monitoring.py @@ -136,21 +136,21 @@ class TestMonitoring(unittest.TestCase): # engaged, invisible driver, down to orange, driver touches wheel; then down to orange again, driver appears # - both actions should clear the alert, but momentary appearance should not def test_sometimes_transparent_commuter(self): - _visible_time = np.random.choice([0.5, 10]) - ds_vector = always_no_face[:]*2 - interaction_vector = always_false[:]*2 - ds_vector[int((2*INVISIBLE_SECONDS_TO_ORANGE+1)/DT_DMON):int((2*INVISIBLE_SECONDS_TO_ORANGE+1+_visible_time)/DT_DMON)] = [msg_ATTENTIVE] * int(_visible_time/DT_DMON) - interaction_vector[int((INVISIBLE_SECONDS_TO_ORANGE)/DT_DMON):int((INVISIBLE_SECONDS_TO_ORANGE+1)/DT_DMON)] = [True] * int(1/DT_DMON) - events, _ = self._run_seq(ds_vector, interaction_vector, 2*always_true, 2*always_false) - self.assertTrue(len(events[int(INVISIBLE_SECONDS_TO_ORANGE*0.5/DT_DMON)]) == 0) - self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive) - self.assertTrue(len(events[int((INVISIBLE_SECONDS_TO_ORANGE+0.1)/DT_DMON)]) == 0) - if _visible_time == 0.5: - self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive) - self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1+0.1+_visible_time)/DT_DMON)].names[0], EventName.preDriverUnresponsive) - elif _visible_time == 10: - self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive) - self.assertTrue(len(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1+0.1+_visible_time)/DT_DMON)]) == 0) + _visible_time = np.random.choice([0.5, 10]) + ds_vector = always_no_face[:]*2 + interaction_vector = always_false[:]*2 + ds_vector[int((2*INVISIBLE_SECONDS_TO_ORANGE+1)/DT_DMON):int((2*INVISIBLE_SECONDS_TO_ORANGE+1+_visible_time)/DT_DMON)] = [msg_ATTENTIVE] * int(_visible_time/DT_DMON) + interaction_vector[int((INVISIBLE_SECONDS_TO_ORANGE)/DT_DMON):int((INVISIBLE_SECONDS_TO_ORANGE+1)/DT_DMON)] = [True] * int(1/DT_DMON) + events, _ = self._run_seq(ds_vector, interaction_vector, 2*always_true, 2*always_false) + self.assertTrue(len(events[int(INVISIBLE_SECONDS_TO_ORANGE*0.5/DT_DMON)]) == 0) + self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive) + self.assertTrue(len(events[int((INVISIBLE_SECONDS_TO_ORANGE+0.1)/DT_DMON)]) == 0) + if _visible_time == 0.5: + self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive) + self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1+0.1+_visible_time)/DT_DMON)].names[0], EventName.preDriverUnresponsive) + elif _visible_time == 10: + self.assertEqual(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1-0.1)/DT_DMON)].names[0], EventName.promptDriverUnresponsive) + self.assertTrue(len(events[int((INVISIBLE_SECONDS_TO_ORANGE*2+1+0.1+_visible_time)/DT_DMON)]) == 0) # engaged, invisible driver, down to red, driver appears and then touches wheel, then disengages/reengages # - only disengage will clear the alert diff --git a/selfdrive/test/process_replay/compare_logs.py b/selfdrive/test/process_replay/compare_logs.py index de734e52f..f1ca69987 100755 --- a/selfdrive/test/process_replay/compare_logs.py +++ b/selfdrive/test/process_replay/compare_logs.py @@ -25,7 +25,7 @@ def save_log(dest, log_msgs, compress=True): dat = bz2.compress(dat) with open(dest, "wb") as f: - f.write(dat) + f.write(dat) def remove_ignored_fields(msg, ignore): diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index bfe68d93e..6e3398f9c 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -231,7 +231,7 @@ def ublox_rcv_callback(msg): elif (msg_class, msg_id) in {(2, 1 * 16 + 5), (10, 9)}: return ["ubloxGnss"] else: - return [] + return [] CONFIGS = [ diff --git a/selfdrive/test/process_replay/regen.py b/selfdrive/test/process_replay/regen.py index e2493d048..1a6b11094 100755 --- a/selfdrive/test/process_replay/regen.py +++ b/selfdrive/test/process_replay/regen.py @@ -61,10 +61,10 @@ def replay_manager_state(s, msgs): rk = Ratekeeper(service_list[s].frequency, print_delay_threshold=None) while True: - new_m = messaging.new_message('managerState') - new_m.managerState.processes = [{'name': name, 'running': True} for name in managed_processes] - pm.send(s, new_m) - rk.keep_time() + new_m = messaging.new_message('managerState') + new_m.managerState.processes = [{'name': name, 'running': True} for name in managed_processes] + pm.send(s, new_m) + rk.keep_time() def replay_device_state(s, msgs): diff --git a/selfdrive/tombstoned.py b/selfdrive/tombstoned.py index 459ab2f0f..dcf3ee0f6 100755 --- a/selfdrive/tombstoned.py +++ b/selfdrive/tombstoned.py @@ -153,9 +153,9 @@ def report_tombstone_apport(fn): # Try to find first entry in openpilot, fall back to first line for line in stacktrace_s: if "at selfdrive/" in line: - crash_function = line - found = True - break + crash_function = line + found = True + break if not found: crash_function = stacktrace_s[1] diff --git a/tools/lib/auth.py b/tools/lib/auth.py index 0e9e7705b..54fb81cc2 100755 --- a/tools/lib/auth.py +++ b/tools/lib/auth.py @@ -86,13 +86,13 @@ def auth_redirect_link(method): }) return 'https://github.com/login/oauth/authorize?' + urlencode(params) elif method == 'apple': - params.update({ - 'client_id': 'ai.comma.login', - 'response_type': 'code', - 'response_mode': 'form_post', - 'scope': 'name email', - }) - return 'https://appleid.apple.com/auth/authorize?' + urlencode(params) + params.update({ + 'client_id': 'ai.comma.login', + 'response_type': 'code', + 'response_mode': 'form_post', + 'scope': 'name email', + }) + return 'https://appleid.apple.com/auth/authorize?' + urlencode(params) else: raise NotImplementedError(f"no redirect implemented for method {method}") diff --git a/tools/lib/tests/test_caching.py b/tools/lib/tests/test_caching.py index 953b47e95..d2a2a6872 100644 --- a/tools/lib/tests/test_caching.py +++ b/tools/lib/tests/test_caching.py @@ -66,4 +66,4 @@ class TestFileDownload(unittest.TestCase): if __name__ == "__main__": - unittest.main() + unittest.main() diff --git a/tools/sim/lib/manual_ctrl.py b/tools/sim/lib/manual_ctrl.py index 7c47e2ba4..8f1bcc2b5 100755 --- a/tools/sim/lib/manual_ctrl.py +++ b/tools/sim/lib/manual_ctrl.py @@ -9,8 +9,8 @@ from typing import NoReturn # Iterate over the joystick devices. print('Available devices:') for fn in os.listdir('/dev/input'): - if fn.startswith('js'): - print(f' /dev/input/{fn}') + if fn.startswith('js'): + print(f' /dev/input/{fn}') # We'll store the states here. axis_states = {} @@ -18,74 +18,74 @@ button_states = {} # These constants were borrowed from linux/input.h axis_names = { - 0x00 : 'x', - 0x01 : 'y', - 0x02 : 'z', - 0x03 : 'rx', - 0x04 : 'ry', - 0x05 : 'rz', - 0x06 : 'trottle', - 0x07 : 'rudder', - 0x08 : 'wheel', - 0x09 : 'gas', - 0x0a : 'brake', - 0x10 : 'hat0x', - 0x11 : 'hat0y', - 0x12 : 'hat1x', - 0x13 : 'hat1y', - 0x14 : 'hat2x', - 0x15 : 'hat2y', - 0x16 : 'hat3x', - 0x17 : 'hat3y', - 0x18 : 'pressure', - 0x19 : 'distance', - 0x1a : 'tilt_x', - 0x1b : 'tilt_y', - 0x1c : 'tool_width', - 0x20 : 'volume', - 0x28 : 'misc', + 0x00 : 'x', + 0x01 : 'y', + 0x02 : 'z', + 0x03 : 'rx', + 0x04 : 'ry', + 0x05 : 'rz', + 0x06 : 'trottle', + 0x07 : 'rudder', + 0x08 : 'wheel', + 0x09 : 'gas', + 0x0a : 'brake', + 0x10 : 'hat0x', + 0x11 : 'hat0y', + 0x12 : 'hat1x', + 0x13 : 'hat1y', + 0x14 : 'hat2x', + 0x15 : 'hat2y', + 0x16 : 'hat3x', + 0x17 : 'hat3y', + 0x18 : 'pressure', + 0x19 : 'distance', + 0x1a : 'tilt_x', + 0x1b : 'tilt_y', + 0x1c : 'tool_width', + 0x20 : 'volume', + 0x28 : 'misc', } button_names = { - 0x120 : 'trigger', - 0x121 : 'thumb', - 0x122 : 'thumb2', - 0x123 : 'top', - 0x124 : 'top2', - 0x125 : 'pinkie', - 0x126 : 'base', - 0x127 : 'base2', - 0x128 : 'base3', - 0x129 : 'base4', - 0x12a : 'base5', - 0x12b : 'base6', - 0x12f : 'dead', - 0x130 : 'a', - 0x131 : 'b', - 0x132 : 'c', - 0x133 : 'x', - 0x134 : 'y', - 0x135 : 'z', - 0x136 : 'tl', - 0x137 : 'tr', - 0x138 : 'tl2', - 0x139 : 'tr2', - 0x13a : 'select', - 0x13b : 'start', - 0x13c : 'mode', - 0x13d : 'thumbl', - 0x13e : 'thumbr', + 0x120 : 'trigger', + 0x121 : 'thumb', + 0x122 : 'thumb2', + 0x123 : 'top', + 0x124 : 'top2', + 0x125 : 'pinkie', + 0x126 : 'base', + 0x127 : 'base2', + 0x128 : 'base3', + 0x129 : 'base4', + 0x12a : 'base5', + 0x12b : 'base6', + 0x12f : 'dead', + 0x130 : 'a', + 0x131 : 'b', + 0x132 : 'c', + 0x133 : 'x', + 0x134 : 'y', + 0x135 : 'z', + 0x136 : 'tl', + 0x137 : 'tr', + 0x138 : 'tl2', + 0x139 : 'tr2', + 0x13a : 'select', + 0x13b : 'start', + 0x13c : 'mode', + 0x13d : 'thumbl', + 0x13e : 'thumbr', - 0x220 : 'dpad_up', - 0x221 : 'dpad_down', - 0x222 : 'dpad_left', - 0x223 : 'dpad_right', + 0x220 : 'dpad_up', + 0x221 : 'dpad_down', + 0x222 : 'dpad_left', + 0x223 : 'dpad_right', - # XBox 360 controller uses these codes. - 0x2c0 : 'dpad_left', - 0x2c1 : 'dpad_right', - 0x2c2 : 'dpad_up', - 0x2c3 : 'dpad_down', + # XBox 360 controller uses these codes. + 0x2c0 : 'dpad_left', + 0x2c1 : 'dpad_right', + 0x2c2 : 'dpad_up', + 0x2c3 : 'dpad_down', } axis_map = [] @@ -118,18 +118,18 @@ def wheel_poll_thread(q: 'Queue[str]') -> NoReturn: ioctl(jsdev, 0x80406a32, buf) # JSIOCGAXMAP for _axis in buf[:num_axes]: - axis_name = axis_names.get(_axis, f'unknown(0x{_axis:02x})') - axis_map.append(axis_name) - axis_states[axis_name] = 0.0 + axis_name = axis_names.get(_axis, f'unknown(0x{_axis:02x})') + axis_map.append(axis_name) + axis_states[axis_name] = 0.0 # Get the button map. buf = array.array('H', [0] * 200) ioctl(jsdev, 0x80406a34, buf) # JSIOCGBTNMAP for btn in buf[:num_buttons]: - btn_name = button_names.get(btn, f'unknown(0x{btn:03x})') - button_map.append(btn_name) - button_states[btn_name] = 0 + btn_name = button_names.get(btn, f'unknown(0x{btn:03x})') + button_map.append(btn_name) + button_states[btn_name] = 0 print('%d axes found: %s' % (num_axes, ', '.join(axis_map))) print('%d buttons found: %s' % (num_buttons, ', '.join(button_map))) diff --git a/tools/zookeeper/enable_and_wait.py b/tools/zookeeper/enable_and_wait.py index 16b662f59..6907e6017 100755 --- a/tools/zookeeper/enable_and_wait.py +++ b/tools/zookeeper/enable_and_wait.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 - import os import sys import time @@ -7,11 +6,11 @@ from socket import gethostbyname, gaierror from tools.zookeeper import Zookeeper def is_online(ip): - try: - addr = gethostbyname(ip) - return (os.system(f"ping -c 1 {addr} > /dev/null") == 0) - except gaierror: - return False + try: + addr = gethostbyname(ip) + return (os.system(f"ping -c 1 {addr} > /dev/null") == 0) + except gaierror: + return False if __name__ == "__main__": z = Zookeeper()