plugin for add memory infos and cpu temperature to screen

think this should be in default, but disabled
This commit is contained in:
xenDE 2019-10-03 18:11:42 +02:00 committed by GitHub
parent dd9b722ca2
commit 77b6009349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,55 @@
# tempmem shows memory infos and cpu temperature
#
# totalmem usedmem freemem cputemp
#
__author__ = 'https://github.com/xenDE'
__version__ = '1.0.0'
__name__ = 'memtemp'
__license__ = 'GPL3'
__description__ = 'A plugin that will add a memory and temperature indicator'
__enabled__ = False
import struct
from pwnagotchi.ui.components import LabeledValue
from pwnagotchi.ui.view import BLACK
import pwnagotchi.ui.fonts as fonts
class MEMTEMP:
def __init__(self):
# only import when the module is loaded and enabled
import os
def get_temp(self):
try:
temp = os.popen('/opt/vc/bin/vcgencmd measure_temp').readlines()[0].split('=')[1].replace("\n", '').replace("'","")
return 'cpu:' + temp
except:
return 'cpu:0.0C'
# cpu:37.4C
def get_mem_info(self):
try:
total, used, free = map(int, os.popen('free -t -m').readlines()[-1].split()[1:])
return "tm:"+str(total)+" um:"+str(used)+" fm:"+str(free)
except:
return "tm:0 um:0 fm:0"
# tm:532 um:82 fm:353
memtemp = None
def on_loaded():
global memtemp
memtemp = MEMTEMP()
def on_ui_setup(ui):
ui.add_element('memtemp', LabeledValue(color=BLACK, label='SYS', value='tm:0 um:0 fm:0 0.0C', position=(0, ui.height()-28),
label_font=fonts.Bold, text_font=fonts.Medium))
def on_ui_update(ui):
ui.set('memtemp', "%s %s" % (memtemp.get_mem_info(), memtemp.get_temp()))