diff --git a/pwnagotchi/plugins/default/bluetoothsniffer.py b/pwnagotchi/plugins/default/bluetoothsniffer.py index e7d0aa6b..5f5b0306 100644 --- a/pwnagotchi/plugins/default/bluetoothsniffer.py +++ b/pwnagotchi/plugins/default/bluetoothsniffer.py @@ -46,26 +46,28 @@ class BluetoothSniffer(plugins.Plugin): self.data = json.load(f) def on_ui_setup(self, ui): - ui.add_element('BtS', LabeledValue(color=BLACK, - label='BT SNFD', - value=" ", - position=(int(self.options["bt_x_coord"]), - int(self.options["bt_y_coord"])), - label_font=fonts.Small, - text_font=fonts.Small)) + with ui._lock: + ui.add_element('BtS', LabeledValue(color=BLACK, + label='BT SNFD', + value=" ", + position=(int(self.options["bt_x_coord"]), + int(self.options["bt_y_coord"])), + label_font=fonts.Small, + text_font=fonts.Small)) def on_unload(self, ui): with ui._lock: ui.remove_element('BtS') def on_ui_update(self, ui): - current_time = time.time() - # Checking the time elapsed since last scan - if current_time - self.last_scan_time >= self.options['timer']: - self.last_scan_time = current_time - #logging.info("[BtS] Bluetooth sniffed: %s", str(self.bt_sniff_info())) - ui.set('BtS', str(self.bt_sniff_info())) - self.scan(ui) + with ui._lock: + current_time = time.time() + # Checking the time elapsed since last scan + if current_time - self.last_scan_time >= self.options['timer']: + self.last_scan_time = current_time + #logging.info("[BtS] Bluetooth sniffed: %s", str(self.bt_sniff_info())) + ui.set('BtS', str(self.bt_sniff_info())) + self.scan(ui) # Method for scanning the nearby bluetooth devices def scan(self, display): diff --git a/pwnagotchi/plugins/default/bt-tether.py b/pwnagotchi/plugins/default/bt-tether.py index a65c603b..dd0008a0 100644 --- a/pwnagotchi/plugins/default/bt-tether.py +++ b/pwnagotchi/plugins/default/bt-tether.py @@ -583,4 +583,5 @@ class BTTether(plugins.Plugin): label_font=fonts.Bold, text_font=fonts.Medium)) def on_ui_update(self, ui): - ui.set('bluetooth', self.status) + with ui._lock: + ui.set('bluetooth', self.status) diff --git a/pwnagotchi/plugins/default/fix_services.py b/pwnagotchi/plugins/default/fix_services.py index c26af9cb..3ddc0878 100644 --- a/pwnagotchi/plugins/default/fix_services.py +++ b/pwnagotchi/plugins/default/fix_services.py @@ -378,32 +378,34 @@ class FixServices(plugins.Plugin): # called to setup the ui elements def on_ui_setup(self, ui): - # add custom UI elements - if "position" in self.options: - pos = self.options['position'].split(',') - pos = [int(x.strip()) for x in pos] - else: - pos = (ui.width() / 2 + 35, ui.height() - 11) + with ui._lock: + # add custom UI elements + if "position" in self.options: + pos = self.options['position'].split(',') + pos = [int(x.strip()) for x in pos] + else: + pos = (ui.width() / 2 + 35, ui.height() - 11) - logging.info("Got here") - ui.add_element('brcmfmac_status', Text(color=BLACK, value='--', position=pos, font=fonts.Small)) - - # called when the ui is updated + logging.info("Got here") + ui.add_element('brcmfmac_status', Text(color=BLACK, value='--', position=pos, font=fonts.Small)) + # called when the ui is updated def on_ui_update(self, ui): - # update those elements - if self._status: - ui.set('brcmfmac_status', "wlan0mon %s" % self._status) - else: - ui.set('brcmfmac_status', "rst#%s" % self._count) + with ui._lock: + # update those elements + if self._status: + ui.set('brcmfmac_status', "wlan0mon %s" % self._status) + else: + ui.set('brcmfmac_status', "rst#%s" % self._count) def on_unload(self, ui): - try: - ui.remove_element('brcmfmac_status') - logging.info("[Fix_Services] unloaded") - except Exception as err: - logging.info("[Fix_Services] unload err %s " % repr(err)) - pass + with ui._lock: + try: + ui.remove_element('brcmfmac_status') + logging.info("[Fix_Services] unloaded") + except Exception as err: + logging.info("[Fix_Services] unload err %s " % repr(err)) + pass # run from command line to brute force a reload diff --git a/pwnagotchi/plugins/default/gps.py b/pwnagotchi/plugins/default/gps.py index 888282d4..74f74c85 100644 --- a/pwnagotchi/plugins/default/gps.py +++ b/pwnagotchi/plugins/default/gps.py @@ -151,12 +151,13 @@ class GPS(plugins.Plugin): ui.remove_element('altitude') def on_ui_update(self, ui): - if self.coordinates and all([ - # avoid 0.000... measurements - self.coordinates["Latitude"], self.coordinates["Longitude"] - ]): - # last char is sometimes not completely drawn ¯\_(ツ)_/¯ - # using an ending-whitespace as workaround on each line - ui.set("latitude", f"{self.coordinates['Latitude']:.4f} ") - ui.set("longitude", f"{self.coordinates['Longitude']:.4f} ") - ui.set("altitude", f"{self.coordinates['Altitude']:.1f}m ") + with ui._lock: + if self.coordinates and all([ + # avoid 0.000... measurements + self.coordinates["Latitude"], self.coordinates["Longitude"] + ]): + # last char is sometimes not completely drawn ¯\_(ツ)_/¯ + # using an ending-whitespace as workaround on each line + ui.set("latitude", f"{self.coordinates['Latitude']:.4f} ") + ui.set("longitude", f"{self.coordinates['Longitude']:.4f} ") + ui.set("altitude", f"{self.coordinates['Altitude']:.1f}m ") diff --git a/pwnagotchi/plugins/default/memtemp.py b/pwnagotchi/plugins/default/memtemp.py index d9ac75ce..e3cf3ac8 100644 --- a/pwnagotchi/plugins/default/memtemp.py +++ b/pwnagotchi/plugins/default/memtemp.py @@ -103,90 +103,91 @@ class MemTemp(plugins.Plugin): return " " * (self.FIELD_WIDTH - len(data)) + data def on_ui_setup(self, ui): - try: - # Configure field list - self.fields = self.options['fields'].split(',') - self.fields = [x.strip() for x in self.fields if x.strip() in self.ALLOWED_FIELDS.keys()] - self.fields = self.fields[:3] # limit to the first 3 fields - except Exception: - # Set default value - self.fields = self.DEFAULT_FIELDS + with ui._lock: + try: + # Configure field list + self.fields = self.options['fields'].split(',') + self.fields = [x.strip() for x in self.fields if x.strip() in self.ALLOWED_FIELDS.keys()] + self.fields = self.fields[:3] # limit to the first 3 fields + except Exception: + # Set default value + self.fields = self.DEFAULT_FIELDS - try: - # Configure line_spacing - line_spacing = int(self.options['linespacing']) - except Exception: - # Set default value - line_spacing = self.LINE_SPACING + try: + # Configure line_spacing + line_spacing = int(self.options['linespacing']) + except Exception: + # Set default value + line_spacing = self.LINE_SPACING + + try: + # Configure position + pos = self.options['position'].split(',') + pos = [int(x.strip()) for x in pos] + if self.options['orientation'] == "vertical": + v_pos = (pos[0], pos[1]) + else: + h_pos = (pos[0], pos[1]) + except Exception: + # Set default position based on screen type + if ui.is_waveshare_v2(): + h_pos = (178, 84) + v_pos = (197, 74) + elif ui.is_waveshare_v1(): + h_pos = (170, 80) + v_pos = (165, 61) + elif ui.is_waveshare144lcd(): + h_pos = (53, 77) + v_pos = (73, 67) + elif ui.is_inky(): + h_pos = (140, 68) + v_pos = (160, 54) + elif ui.is_waveshare27inch(): + h_pos = (192, 138) + v_pos = (211, 122) + else: + h_pos = (155, 76) + v_pos = (175, 61) - try: - # Configure position - pos = self.options['position'].split(',') - pos = [int(x.strip()) for x in pos] if self.options['orientation'] == "vertical": - v_pos = (pos[0], pos[1]) + # Dynamically create the required LabeledValue objects + for idx, field in enumerate(self.fields): + v_pos_x = v_pos[0] + v_pos_y = v_pos[1] + ((len(self.fields) - 3) * -1 * line_spacing) + ui.add_element( + f"memtemp_{field}", + LabeledValue( + color=BLACK, + label=f"{self.pad_text(field)}:", + value="-", + position=(v_pos_x, v_pos_y + (idx * line_spacing)), + label_font=fonts.Small, + text_font=fonts.Small, + label_spacing=self.LABEL_SPACING, + ) + ) else: - h_pos = (pos[0], pos[1]) - except Exception: - # Set default position based on screen type - if ui.is_waveshare_v2(): - h_pos = (178, 84) - v_pos = (197, 74) - elif ui.is_waveshare_v1(): - h_pos = (170, 80) - v_pos = (165, 61) - elif ui.is_waveshare144lcd(): - h_pos = (53, 77) - v_pos = (73, 67) - elif ui.is_inky(): - h_pos = (140, 68) - v_pos = (160, 54) - elif ui.is_waveshare27inch(): - h_pos = (192, 138) - v_pos = (211, 122) - else: - h_pos = (155, 76) - v_pos = (175, 61) - - if self.options['orientation'] == "vertical": - # Dynamically create the required LabeledValue objects - for idx, field in enumerate(self.fields): - v_pos_x = v_pos[0] - v_pos_y = v_pos[1] + ((len(self.fields) - 3) * -1 * line_spacing) + # default to horizontal + h_pos_x = h_pos[0] + ((len(self.fields) - 3) * -1 * 25) + h_pos_y = h_pos[1] ui.add_element( - f"memtemp_{field}", - LabeledValue( + 'memtemp_header', + Text( color=BLACK, - label=f"{self.pad_text(field)}:", - value="-", - position=(v_pos_x, v_pos_y + (idx * line_spacing)), - label_font=fonts.Small, - text_font=fonts.Small, - label_spacing=self.LABEL_SPACING, + value=" ".join([self.pad_text(x) for x in self.fields]), + position=(h_pos_x, h_pos_y), + font=fonts.Small, ) ) - else: - # default to horizontal - h_pos_x = h_pos[0] + ((len(self.fields) - 3) * -1 * 25) - h_pos_y = h_pos[1] - ui.add_element( - 'memtemp_header', - Text( - color=BLACK, - value=" ".join([self.pad_text(x) for x in self.fields]), - position=(h_pos_x, h_pos_y), - font=fonts.Small, + ui.add_element( + 'memtemp_data', + Text( + color=BLACK, + value=" ".join([self.pad_text("-") for x in self.fields]), + position=(h_pos_x, h_pos_y + line_spacing), + font=fonts.Small, + ) ) - ) - ui.add_element( - 'memtemp_data', - Text( - color=BLACK, - value=" ".join([self.pad_text("-") for x in self.fields]), - position=(h_pos_x, h_pos_y + line_spacing), - font=fonts.Small, - ) - ) def on_unload(self, ui): with ui._lock: @@ -199,10 +200,11 @@ class MemTemp(plugins.Plugin): ui.remove_element('memtemp_data') def on_ui_update(self, ui): - if self.options['orientation'] == "vertical": - for idx, field in enumerate(self.fields): - ui.set(f"memtemp_{field}", getattr(self, self.ALLOWED_FIELDS[field])()) - else: - # default to horizontal - data = " ".join([self.pad_text(getattr(self, self.ALLOWED_FIELDS[x])()) for x in self.fields]) - ui.set('memtemp_data', data) + with ui._lock: + if self.options['orientation'] == "vertical": + for idx, field in enumerate(self.fields): + ui.set(f"memtemp_{field}", getattr(self, self.ALLOWED_FIELDS[field])()) + else: + # default to horizontal + data = " ".join([self.pad_text(getattr(self, self.ALLOWED_FIELDS[x])()) for x in self.fields]) + ui.set('memtemp_data', data)