Small gps fixes + memtemp rework

This commit is contained in:
Thomas Bouve 2020-09-18 02:11:37 +02:00
parent 713a14c504
commit 1aea0b95b1
2 changed files with 117 additions and 34 deletions
pwnagotchi/plugins/default

@ -57,7 +57,7 @@ class GPS(plugins.Plugin):
def on_ui_setup(self, ui): def on_ui_setup(self, ui):
# add coordinates for other displays # add coordinates for other displays
if ui.is_waveshare_v2(): if ui.is_waveshare_v2():
lat_pos = (127, 75) lat_pos = (127, 74)
lon_pos = (122, 84) lon_pos = (122, 84)
alt_pos = (127, 94) alt_pos = (127, 94)
elif ui.is_waveshare_v1(): elif ui.is_waveshare_v1():
@ -66,15 +66,15 @@ class GPS(plugins.Plugin):
alt_pos = (130, 90) alt_pos = (130, 90)
elif ui.is_inky(): elif ui.is_inky():
lat_pos = (127, 60) lat_pos = (127, 60)
lon_pos = (127, 70) lon_pos = (122, 70)
alt_pos = (127, 80) alt_pos = (127, 80)
elif ui.is_waveshare144lcd(): elif ui.is_waveshare144lcd():
# guessed values, add tested ones if you can # guessed values, add tested ones if you can
lat_pos = (67, 73) lat_pos = (67, 73)
lon_pos = (62, 83) lon_pos = (62, 83)
alt_pos = (67, 93) alt_pos = (67, 93)
elif ui.is_dfrobot_v2: elif ui.is_dfrobot_v2():
lat_pos = (127, 75) lat_pos = (127, 74)
lon_pos = (122, 84) lon_pos = (122, 84)
alt_pos = (127, 94) alt_pos = (127, 94)
elif ui.is_waveshare27inch(): elif ui.is_waveshare27inch():
@ -126,7 +126,6 @@ class GPS(plugins.Plugin):
), ),
) )
def on_unload(self, ui): def on_unload(self, ui):
with ui._lock: with ui._lock:
ui.remove_element('latitude') ui.remove_element('latitude')

@ -17,7 +17,7 @@
# - Added horizontal and vertical orientation # - Added horizontal and vertical orientation
# #
############################################################### ###############################################################
from pwnagotchi.ui.components import LabeledValue from pwnagotchi.ui.components import LabeledValue, Text
from pwnagotchi.ui.view import BLACK from pwnagotchi.ui.view import BLACK
import pwnagotchi.ui.fonts as fonts import pwnagotchi.ui.fonts as fonts
import pwnagotchi.plugins as plugins import pwnagotchi.plugins as plugins
@ -40,39 +40,118 @@ class MemTemp(plugins.Plugin):
def cpu_load(self): def cpu_load(self):
return int(pwnagotchi.cpu_load() * 100) return int(pwnagotchi.cpu_load() * 100)
@staticmethod
def pad_text(width, data, symbol):
data = str(data) + symbol
return " " * (width - len(data)) + data
def on_ui_setup(self, ui): def on_ui_setup(self, ui):
if ui.is_waveshare_v2(): if ui.is_waveshare_v2():
h_pos = (180, 80) h_pos_line1 = (178, 84)
v_pos = (180, 61) h_pos_line2 = (178, 94)
v_pos_line1 = (202, 74) # (127, 75)
v_pos_line2 = (202, 84) # (122, 84)
v_pos_line3 = (197, 94) # (127, 94)
elif ui.is_waveshare_v1(): elif ui.is_waveshare_v1():
h_pos = (170, 80) h_pos_line1 = (170, 80)
v_pos = (170, 61) h_pos_line2 = (170, 90)
v_pos_line1 = (170, 61) # (130, 70)
v_pos_line2 = (170, 71) # (125, 80)
v_pos_line3 = (165, 81) # (130, 90)
elif ui.is_waveshare144lcd(): elif ui.is_waveshare144lcd():
h_pos = (53, 77) h_pos_line1 = (53, 77)
v_pos = (78, 67) h_pos_line2 = (53, 87)
v_pos_line1 = (78, 67) # (67, 73)
v_pos_line2 = (78, 77) # (62, 83)
v_pos_line3 = (73, 87) # (67, 93)
elif ui.is_inky(): elif ui.is_inky():
h_pos = (140, 68) h_pos_line1 = (140, 68)
v_pos = (165, 54) h_pos_line2 = (140, 78)
v_pos_line1 = (165, 54) # (127, 60)
v_pos_line2 = (165, 64) # (122, 70)
v_pos_line3 = (160, 74) # (127, 80)
elif ui.is_waveshare27inch(): elif ui.is_waveshare27inch():
h_pos = (192, 138) h_pos_line1 = (192, 138)
v_pos = (216, 122) h_pos_line2 = (192, 148)
v_pos_line1 = (216, 122) # (6,120)
v_pos_line2 = (216, 132) # (1,135)
v_pos_line3 = (211, 142) # (6,150)
else: else:
h_pos = (155, 76) h_pos_line1 = (155, 76)
v_pos = (180, 61) h_pos_line2 = (155, 86)
v_pos_line1 = (180, 61) # (127, 51)
v_pos_line2 = (180, 71) # (127, 56)
v_pos_line3 = (175, 81) # (102, 71)
label_spacing = 0
if self.options['orientation'] == "vertical": if self.options['orientation'] == "vertical":
ui.add_element('memtemp', LabeledValue(color=BLACK, label='', value=' mem:-\n cpu:-\ntemp:-', ui.add_element(
position=v_pos, 'memtemp_line1',
label_font=fonts.Small, text_font=fonts.Small)) LabeledValue(
color=BLACK,
label='mem:',
value='-',
position=v_pos_line1,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=label_spacing,
)
)
ui.add_element(
'memtemp_line2',
LabeledValue(
color=BLACK,
label='cpu:',
value='-',
position=v_pos_line2,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=label_spacing,
)
)
ui.add_element(
'memtemp_line3',
LabeledValue(
color=BLACK,
label='temp:',
value='-',
position=v_pos_line3,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=label_spacing,
)
)
else: else:
# default to horizontal # default to horizontal
ui.add_element('memtemp', LabeledValue(color=BLACK, label='', value='mem cpu temp\n - - -', ui.add_element(
position=h_pos, 'memtemp_line1',
label_font=fonts.Small, text_font=fonts.Small)) Text(
color=BLACK,
value=' mem cpu temp',
position=h_pos_line1,
font=fonts.Small,
)
)
ui.add_element(
'memtemp_line2',
Text(
color=BLACK,
value=' - - -',
position=h_pos_line2,
font=fonts.Small,
)
)
def on_unload(self, ui): def on_unload(self, ui):
with ui._lock: with ui._lock:
ui.remove_element('memtemp') if self.options['orientation'] == "vertical":
ui.remove_element('memtemp_line1')
ui.remove_element('memtemp_line2')
ui.remove_element('memtemp_line3')
else:
ui.remove_element('memtemp_line1')
ui.remove_element('memtemp_line2')
def on_ui_update(self, ui): def on_ui_update(self, ui):
if self.options['scale'] == "fahrenheit": if self.options['scale'] == "fahrenheit":
@ -87,9 +166,14 @@ class MemTemp(plugins.Plugin):
symbol = "c" symbol = "c"
if self.options['orientation'] == "vertical": if self.options['orientation'] == "vertical":
ui.set('memtemp', ui.set('memtemp_line1', f"{self.mem_usage()}%")
" mem:%s%%\n cpu:%s%%\ntemp:%s%s" % (self.mem_usage(), self.cpu_load(), temp, symbol)) ui.set('memtemp_line2', f"{self.cpu_load()}%")
ui.set('memtemp_line3', f"{temp}{symbol}")
else: else:
# default to horizontal # default to horizontal
ui.set('memtemp', ui.set(
" mem cpu temp\n %s%% %s%% %s%s" % (self.mem_usage(), self.cpu_load(), temp, symbol)) 'memtemp_line2',
self.pad_text(4, self.mem_usage(), "%") +
self.pad_text(5, self.cpu_load(), "%") +
self.pad_text(5, temp, symbol)
)