Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
Jeroen Oudshoorn
2023-09-15 13:35:29 +02:00
parent f1feedad72
commit 078b8b6374
5 changed files with 135 additions and 127 deletions

View File

@ -46,26 +46,28 @@ class BluetoothSniffer(plugins.Plugin):
self.data = json.load(f) self.data = json.load(f)
def on_ui_setup(self, ui): def on_ui_setup(self, ui):
ui.add_element('BtS', LabeledValue(color=BLACK, with ui._lock:
label='BT SNFD', ui.add_element('BtS', LabeledValue(color=BLACK,
value=" ", label='BT SNFD',
position=(int(self.options["bt_x_coord"]), value=" ",
int(self.options["bt_y_coord"])), position=(int(self.options["bt_x_coord"]),
label_font=fonts.Small, int(self.options["bt_y_coord"])),
text_font=fonts.Small)) label_font=fonts.Small,
text_font=fonts.Small))
def on_unload(self, ui): def on_unload(self, ui):
with ui._lock: with ui._lock:
ui.remove_element('BtS') ui.remove_element('BtS')
def on_ui_update(self, ui): def on_ui_update(self, ui):
current_time = time.time() with ui._lock:
# Checking the time elapsed since last scan current_time = time.time()
if current_time - self.last_scan_time >= self.options['timer']: # Checking the time elapsed since last scan
self.last_scan_time = current_time if current_time - self.last_scan_time >= self.options['timer']:
#logging.info("[BtS] Bluetooth sniffed: %s", str(self.bt_sniff_info())) self.last_scan_time = current_time
ui.set('BtS', str(self.bt_sniff_info())) #logging.info("[BtS] Bluetooth sniffed: %s", str(self.bt_sniff_info()))
self.scan(ui) ui.set('BtS', str(self.bt_sniff_info()))
self.scan(ui)
# Method for scanning the nearby bluetooth devices # Method for scanning the nearby bluetooth devices
def scan(self, display): def scan(self, display):

View File

@ -583,4 +583,5 @@ class BTTether(plugins.Plugin):
label_font=fonts.Bold, text_font=fonts.Medium)) label_font=fonts.Bold, text_font=fonts.Medium))
def on_ui_update(self, ui): def on_ui_update(self, ui):
ui.set('bluetooth', self.status) with ui._lock:
ui.set('bluetooth', self.status)

View File

@ -378,32 +378,34 @@ class FixServices(plugins.Plugin):
# called to setup the ui elements # called to setup the ui elements
def on_ui_setup(self, ui): def on_ui_setup(self, ui):
# add custom UI elements with ui._lock:
if "position" in self.options: # add custom UI elements
pos = self.options['position'].split(',') if "position" in self.options:
pos = [int(x.strip()) for x in pos] pos = self.options['position'].split(',')
else: pos = [int(x.strip()) for x in pos]
pos = (ui.width() / 2 + 35, ui.height() - 11) else:
pos = (ui.width() / 2 + 35, ui.height() - 11)
logging.info("Got here") logging.info("Got here")
ui.add_element('brcmfmac_status', Text(color=BLACK, value='--', position=pos, font=fonts.Small)) ui.add_element('brcmfmac_status', Text(color=BLACK, value='--', position=pos, font=fonts.Small))
# called when the ui is updated
# called when the ui is updated
def on_ui_update(self, ui): def on_ui_update(self, ui):
# update those elements with ui._lock:
if self._status: # update those elements
ui.set('brcmfmac_status', "wlan0mon %s" % self._status) if self._status:
else: ui.set('brcmfmac_status', "wlan0mon %s" % self._status)
ui.set('brcmfmac_status', "rst#%s" % self._count) else:
ui.set('brcmfmac_status', "rst#%s" % self._count)
def on_unload(self, ui): def on_unload(self, ui):
try: with ui._lock:
ui.remove_element('brcmfmac_status') try:
logging.info("[Fix_Services] unloaded") ui.remove_element('brcmfmac_status')
except Exception as err: logging.info("[Fix_Services] unloaded")
logging.info("[Fix_Services] unload err %s " % repr(err)) except Exception as err:
pass logging.info("[Fix_Services] unload err %s " % repr(err))
pass
# run from command line to brute force a reload # run from command line to brute force a reload

View File

@ -151,12 +151,13 @@ class GPS(plugins.Plugin):
ui.remove_element('altitude') ui.remove_element('altitude')
def on_ui_update(self, ui): def on_ui_update(self, ui):
if self.coordinates and all([ with ui._lock:
# avoid 0.000... measurements if self.coordinates and all([
self.coordinates["Latitude"], self.coordinates["Longitude"] # 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 # last char is sometimes not completely drawn ¯\_(ツ)_/¯
ui.set("latitude", f"{self.coordinates['Latitude']:.4f} ") # using an ending-whitespace as workaround on each line
ui.set("longitude", f"{self.coordinates['Longitude']:.4f} ") ui.set("latitude", f"{self.coordinates['Latitude']:.4f} ")
ui.set("altitude", f"{self.coordinates['Altitude']:.1f}m ") ui.set("longitude", f"{self.coordinates['Longitude']:.4f} ")
ui.set("altitude", f"{self.coordinates['Altitude']:.1f}m ")

View File

@ -103,90 +103,91 @@ class MemTemp(plugins.Plugin):
return " " * (self.FIELD_WIDTH - len(data)) + data return " " * (self.FIELD_WIDTH - len(data)) + data
def on_ui_setup(self, ui): def on_ui_setup(self, ui):
try: with ui._lock:
# Configure field list try:
self.fields = self.options['fields'].split(',') # Configure field list
self.fields = [x.strip() for x in self.fields if x.strip() in self.ALLOWED_FIELDS.keys()] self.fields = self.options['fields'].split(',')
self.fields = self.fields[:3] # limit to the first 3 fields self.fields = [x.strip() for x in self.fields if x.strip() in self.ALLOWED_FIELDS.keys()]
except Exception: self.fields = self.fields[:3] # limit to the first 3 fields
# Set default value except Exception:
self.fields = self.DEFAULT_FIELDS # Set default value
self.fields = self.DEFAULT_FIELDS
try: try:
# Configure line_spacing # Configure line_spacing
line_spacing = int(self.options['linespacing']) line_spacing = int(self.options['linespacing'])
except Exception: except Exception:
# Set default value # Set default value
line_spacing = self.LINE_SPACING 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": 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: else:
h_pos = (pos[0], pos[1]) # default to horizontal
except Exception: h_pos_x = h_pos[0] + ((len(self.fields) - 3) * -1 * 25)
# Set default position based on screen type h_pos_y = h_pos[1]
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)
ui.add_element( ui.add_element(
f"memtemp_{field}", 'memtemp_header',
LabeledValue( Text(
color=BLACK, color=BLACK,
label=f"{self.pad_text(field)}:", value=" ".join([self.pad_text(x) for x in self.fields]),
value="-", position=(h_pos_x, h_pos_y),
position=(v_pos_x, v_pos_y + (idx * line_spacing)), font=fonts.Small,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
) )
) )
else: ui.add_element(
# default to horizontal 'memtemp_data',
h_pos_x = h_pos[0] + ((len(self.fields) - 3) * -1 * 25) Text(
h_pos_y = h_pos[1] color=BLACK,
ui.add_element( value=" ".join([self.pad_text("-") for x in self.fields]),
'memtemp_header', position=(h_pos_x, h_pos_y + line_spacing),
Text( font=fonts.Small,
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,
)
)
def on_unload(self, ui): def on_unload(self, ui):
with ui._lock: with ui._lock:
@ -199,10 +200,11 @@ class MemTemp(plugins.Plugin):
ui.remove_element('memtemp_data') ui.remove_element('memtemp_data')
def on_ui_update(self, ui): def on_ui_update(self, ui):
if self.options['orientation'] == "vertical": with ui._lock:
for idx, field in enumerate(self.fields): if self.options['orientation'] == "vertical":
ui.set(f"memtemp_{field}", getattr(self, self.ALLOWED_FIELDS[field])()) for idx, field in enumerate(self.fields):
else: ui.set(f"memtemp_{field}", getattr(self, self.ALLOWED_FIELDS[field])())
# default to horizontal else:
data = " ".join([self.pad_text(getattr(self, self.ALLOWED_FIELDS[x])()) for x in self.fields]) # default to horizontal
ui.set('memtemp_data', data) data = " ".join([self.pad_text(getattr(self, self.ALLOWED_FIELDS[x])()) for x in self.fields])
ui.set('memtemp_data', data)