Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions memtemp-plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class MemTempPlus(plugins.Plugin):
__author__ = 'https://github.com/xenDE'
__version__ = '1.0.3'
__version__ = '1.0.5'
__license__ = 'GPL3'
__description__ = 'A plugin that will display memory/cpu usage and temperature'

Expand All @@ -34,9 +34,10 @@ class MemTempPlus(plugins.Plugin):

def __init__(self):
self.options = dict()
self.fields = list(self.DEFAULT_FIELDS)

def on_loaded(self):
logging.info('memtemp plugin loaded.')
logging.info('[MemTemp-Plus] loaded')

def mem_usage(self):
return f'{int(pwnagotchi.mem_usage() * 100)}%'
Expand All @@ -45,10 +46,11 @@ def cpu_load(self):
return f'{int(pwnagotchi.cpu_load() * 100)}%'

def cpu_temp(self):
if self.options['scale'].lower() == 'fahrenheit':
scale = self.options.get('scale', 'celsius').lower()
if scale == 'fahrenheit':
temp = (pwnagotchi.temperature() * 9 / 5) + 32
symbol = 'F'
elif self.options['scale'].lower() == 'kelvin':
elif scale == 'kelvin':
temp = pwnagotchi.temperature() + 273.15
symbol = 'K'
else:
Expand All @@ -58,8 +60,11 @@ def cpu_temp(self):
return f'{temp}{symbol}'

def cpu_freq(self):
with open('/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq', 'rt') as fp:
return f'{round(float(fp.readline()) / 1000000, 1)}G'
try:
with open('/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq', 'rt') as fp:
return f'{round(float(fp.readline()) / 1000000, 1)}G'
except Exception:
return '?G'

def pad_text(self, data):
return ' ' * (self.FIELD_WIDTH - len(data)) + data
Expand Down Expand Up @@ -96,7 +101,7 @@ def on_ui_setup(self, ui):
v_pos = (175, 50)
h_pos = (155, 60)

if self.options['orientation'] == 'vertical':
if self.options.get('orientation', 'horizontal') == 'vertical':
# Dynamically create the required LabeledValue objects
for idx, field in enumerate(self.fields):
v_pos_x = v_pos[0]
Expand Down Expand Up @@ -138,7 +143,7 @@ def on_ui_setup(self, ui):

def on_unload(self, ui):
with ui._lock:
if self.options['orientation'] == 'vertical':
if self.options.get('orientation', 'horizontal') == 'vertical':
for idx, field in enumerate(self.fields):
ui.remove_element(f'memtemp_{field}')
else:
Expand All @@ -147,7 +152,7 @@ def on_unload(self, ui):
ui.remove_element('memtemp_data')

def on_ui_update(self, ui):
if self.options['orientation'] == 'vertical':
if self.options.get('orientation', 'horizontal') == 'vertical':
for idx, field in enumerate(self.fields):
ui.set(f'memtemp_{field}', getattr(self, self.ALLOWED_FIELDS[field])())
else:
Expand Down