Linting
This commit is contained in:
		
							parent
							
								
									9e0a8ec584
								
							
						
					
					
						commit
						f06503b6fb
					
				
					 2 changed files with 24 additions and 29 deletions
				
			
		
							
								
								
									
										4
									
								
								dance.py
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								dance.py
									
										
									
									
									
								
							|  | @ -11,12 +11,12 @@ from enum import Enum | ||||||
| import aiohttp | import aiohttp | ||||||
| import hid | import hid | ||||||
| from aiohttp import WSMsgType, web | from aiohttp import WSMsgType, web | ||||||
| from pycon import ButtonEventJoyCon, JoyCon |  | ||||||
| from pycon.constants import JOYCON_PRODUCT_IDS, JOYCON_VENDOR_ID |  | ||||||
| 
 | 
 | ||||||
| from joydance import JoyDance, PairingState | from joydance import JoyDance, PairingState | ||||||
| from joydance.constants import (DEFAULT_CONFIG, JOYDANCE_VERSION, | from joydance.constants import (DEFAULT_CONFIG, JOYDANCE_VERSION, | ||||||
|                                 WsSubprotocolVersion) |                                 WsSubprotocolVersion) | ||||||
|  | from pycon import ButtonEventJoyCon, JoyCon | ||||||
|  | from pycon.constants import JOYCON_PRODUCT_IDS, JOYCON_VENDOR_ID | ||||||
| 
 | 
 | ||||||
| logging.getLogger('asyncio').setLevel(logging.WARNING) | logging.getLogger('asyncio').setLevel(logging.WARNING) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import asyncio | import asyncio | ||||||
| import time | import time | ||||||
| from typing import Optional | from typing import Optional, Tuple | ||||||
| 
 | 
 | ||||||
| import hid | import hid | ||||||
| 
 | 
 | ||||||
|  | @ -19,9 +19,9 @@ class JoyCon: | ||||||
|     product_id: int |     product_id: int | ||||||
|     serial: Optional[str] |     serial: Optional[str] | ||||||
|     simple_mode: bool |     simple_mode: bool | ||||||
|     color_body : (int, int, int) |     color_body: Tuple[int, int, int] | ||||||
|     color_btn  : (int, int, int) |     color_btn: Tuple[int, int, int] | ||||||
|     stick_cal  : [int, int, int, int, int, int, int, int] |     stick_cal: Tuple[int, int, int, int, int, int, int, int] | ||||||
| 
 | 
 | ||||||
|     def __init__(self, vendor_id: int, product_id: int, serial: str = None, simple_mode=False): |     def __init__(self, vendor_id: int, product_id: int, serial: str = None, simple_mode=False): | ||||||
|         if vendor_id != JOYCON_VENDOR_ID: |         if vendor_id != JOYCON_VENDOR_ID: | ||||||
|  | @ -85,7 +85,7 @@ class JoyCon: | ||||||
|         ])) |         ])) | ||||||
|         self._packet_number = (self._packet_number + 1) & 0xF |         self._packet_number = (self._packet_number + 1) & 0xF | ||||||
| 
 | 
 | ||||||
|     def _send_subcmd_get_response(self, subcommand, argument) -> (bool, bytes): |     def _send_subcmd_get_response(self, subcommand, argument) -> Tuple[bool, bytes]: | ||||||
|         # TODO: handle subcmd when daemon is running |         # TODO: handle subcmd when daemon is running | ||||||
|         self._write_output_report(b'\x01', subcommand, argument) |         self._write_output_report(b'\x01', subcommand, argument) | ||||||
| 
 | 
 | ||||||
|  | @ -131,6 +131,8 @@ class JoyCon: | ||||||
| 
 | 
 | ||||||
|     def _read_joycon_data(self): |     def _read_joycon_data(self): | ||||||
|         color_data = self._spi_flash_read(0x6050, 6) |         color_data = self._spi_flash_read(0x6050, 6) | ||||||
|  |         self.color_body = tuple(color_data[:3]) | ||||||
|  |         self.color_btn = tuple(color_data[3:]) | ||||||
| 
 | 
 | ||||||
|         self._read_stick_calibration_data() |         self._read_stick_calibration_data() | ||||||
| 
 | 
 | ||||||
|  | @ -147,9 +149,6 @@ class JoyCon: | ||||||
|             # print(f"Calibrate {self.serial} IME with factory data") |             # print(f"Calibrate {self.serial} IME with factory data") | ||||||
|             imu_cal = self._spi_flash_read(0x6020, 24) |             imu_cal = self._spi_flash_read(0x6020, 24) | ||||||
| 
 | 
 | ||||||
|         self.color_body = tuple(color_data[:3]) |  | ||||||
|         self.color_btn  = tuple(color_data[3:]) |  | ||||||
| 
 |  | ||||||
|         self.set_accel_calibration(( |         self.set_accel_calibration(( | ||||||
|             self._to_int16le_from_2bytes(imu_cal[0], imu_cal[1]), |             self._to_int16le_from_2bytes(imu_cal[0], imu_cal[1]), | ||||||
|             self._to_int16le_from_2bytes(imu_cal[2], imu_cal[3]), |             self._to_int16le_from_2bytes(imu_cal[2], imu_cal[3]), | ||||||
|  | @ -158,8 +157,7 @@ class JoyCon: | ||||||
|             self._to_int16le_from_2bytes(imu_cal[6], imu_cal[7]), |             self._to_int16le_from_2bytes(imu_cal[6], imu_cal[7]), | ||||||
|             self._to_int16le_from_2bytes(imu_cal[8], imu_cal[9]), |             self._to_int16le_from_2bytes(imu_cal[8], imu_cal[9]), | ||||||
|             self._to_int16le_from_2bytes(imu_cal[10], imu_cal[11]), |             self._to_int16le_from_2bytes(imu_cal[10], imu_cal[11]), | ||||||
|             ) |         )) | ||||||
|         ) |  | ||||||
| 
 | 
 | ||||||
|     def _read_stick_calibration_data(self): |     def _read_stick_calibration_data(self): | ||||||
|         user_stick_cal_addr = 0x8012 if self.is_left() else 0x801D |         user_stick_cal_addr = 0x8012 if self.is_left() else 0x801D | ||||||
|  | @ -213,16 +211,13 @@ class JoyCon: | ||||||
| 
 | 
 | ||||||
|     def set_accel_calibration(self, offset_xyz=None, coeff_xyz=None): |     def set_accel_calibration(self, offset_xyz=None, coeff_xyz=None): | ||||||
|         if offset_xyz and coeff_xyz: |         if offset_xyz and coeff_xyz: | ||||||
|             self._ACCEL_OFFSET_X, \ |             self._ACCEL_OFFSET_X, self._ACCEL_OFFSET_Y, self._ACCEL_OFFSET_Z = offset_xyz | ||||||
|             self._ACCEL_OFFSET_Y, \ |  | ||||||
|             self._ACCEL_OFFSET_Z = offset_xyz |  | ||||||
| 
 | 
 | ||||||
|             cx, cy, cz = coeff_xyz |             cx, cy, cz = coeff_xyz | ||||||
|             self._ACCEL_COEFF_X = (1.0 / (cx - self._ACCEL_OFFSET_X)) * 4.0 |             self._ACCEL_COEFF_X = (1.0 / (cx - self._ACCEL_OFFSET_X)) * 4.0 | ||||||
|             self._ACCEL_COEFF_Y = (1.0 / (cy - self._ACCEL_OFFSET_Y)) * 4.0 |             self._ACCEL_COEFF_Y = (1.0 / (cy - self._ACCEL_OFFSET_Y)) * 4.0 | ||||||
|             self._ACCEL_COEFF_Z = (1.0 / (cz - self._ACCEL_OFFSET_Z)) * 4.0 |             self._ACCEL_COEFF_Z = (1.0 / (cz - self._ACCEL_OFFSET_Z)) * 4.0 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     def get_actual_stick_value(self, pre_cal, orientation):  # X/Horizontal = 0, Y/Vertical = 1 |     def get_actual_stick_value(self, pre_cal, orientation):  # X/Horizontal = 0, Y/Vertical = 1 | ||||||
|         diff = pre_cal - self.stick_cal[2 + orientation] |         diff = pre_cal - self.stick_cal[2 + orientation] | ||||||
|         if (abs(diff) < self.deadzone): |         if (abs(diff) < self.deadzone): | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue