| 16 | from logic.arduino import arduino |
| 17 | |
| 18 | class MouseThread: |
| 19 | def __init__(self): |
| 20 | self.initialize_parameters() |
| 21 | self.setup_hardware() |
| 22 | |
| 23 | def initialize_parameters(self): |
| 24 | self.dpi = cfg.mouse_dpi |
| 25 | self.mouse_sensitivity = cfg.mouse_sensitivity |
| 26 | self.fov_x = cfg.mouse_fov_width |
| 27 | self.fov_y = cfg.mouse_fov_height |
| 28 | self.disable_prediction = cfg.disable_prediction |
| 29 | self.prediction_interval = cfg.prediction_interval |
| 30 | self.bScope_multiplier = cfg.bScope_multiplier |
| 31 | self.screen_width = cfg.detection_window_width |
| 32 | self.screen_height = cfg.detection_window_height |
| 33 | self.center_x = self.screen_width / 2 |
| 34 | self.center_y = self.screen_height / 2 |
| 35 | self.prev_x = 0 |
| 36 | self.prev_y = 0 |
| 37 | self.prev_time = None |
| 38 | self.max_distance = math.sqrt(self.screen_width**2 + self.screen_height**2) / 2 |
| 39 | self.min_speed_multiplier = cfg.mouse_min_speed_multiplier |
| 40 | self.max_speed_multiplier = cfg.mouse_max_speed_multiplier |
| 41 | self.prev_distance = None |
| 42 | self.speed_correction_factor = 0.1 |
| 43 | self.bScope = False |
| 44 | self.arch = self.get_arch() |
| 45 | self.section_size_x = self.screen_width / 100 |
| 46 | self.section_size_y = self.screen_height / 100 |
| 47 | self._warned_input_unavailable = False |
| 48 | |
| 49 | def get_arch(self): |
| 50 | if cfg.AI_enable_AMD: |
| 51 | return f'hip:{cfg.AI_device}' |
| 52 | ai_device = str(cfg.AI_device).lower() |
| 53 | if 'cpu' in ai_device: |
| 54 | return 'cpu' |
| 55 | if ai_device == 'cuda': |
| 56 | return 'cuda' |
| 57 | if ai_device.startswith('cuda:'): |
| 58 | return cfg.AI_device |
| 59 | return f'cuda:{cfg.AI_device}' |
| 60 | |
| 61 | def setup_hardware(self): |
| 62 | if cfg.mouse_ghub and not hasattr(self, 'ghub'): |
| 63 | from logic.ghub import gHub |
| 64 | self.ghub = gHub |
| 65 | |
| 66 | if cfg.mouse_rzr and not hasattr(self, 'rzr'): |
| 67 | from logic.rzctl import RZCONTROL |
| 68 | dll_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "rzctl.dll") |
| 69 | self.rzr = RZCONTROL(dll_path) |
| 70 | if not self.rzr.init(): |
| 71 | logger.error("Failed to initialize rzctl") |
| 72 | |
| 73 | def process_data(self, data): |
| 74 | if isinstance(data, sv.Detections): |
| 75 | xyxy = data.xyxy[0] |