因为散热不够,所以Quark N的系统总是不稳定,所以迫切需要监控一下温度。最终基于稚晖君的LCD时钟脚本,折腾了如下python脚本,同时修正了原本脚本占用CPU过高的问题(其实就是加了一个一秒的Sleep),不然CPU占用在20%左右,有点恐怖。
import threading import time import cv2 as cv import os import pygame import sys import psutil from pygame.locals import * start_play = False playing = False drivers = ['/dev/fb1'] index = 0 class pyscope: screen = None; def __init__(self): disp_no = os.getenv("DISPLAY") if disp_no: print("I'm running under X display = " + str(disp_no)) found = False for driver in drivers: # Make sure that SDL_VIDEODRIVER is set if not os.getenv('SDL_FBDEV'): os.putenv('SDL_FBDEV', driver) try: pygame.display.init() except pygame.error: print("Driver: " + str(driver) + "failed.") continue found = True break if not found: raise Exception('No suitable video driver found!') size = (pygame.display.Info().current_w, pygame.display.Info().current_h) print("Framebuffer size: %d x %d" % (size[0], size[1])) self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN) # Clear the screen to start self.screen.fill((0, 0, 0)) # Initialise font support pygame.font.init() self.font = pygame.font.Font("/home/pi/WorkSpace/LCD/data/DIGITAL.ttf", 80) #self.font_chinese1 = pygame.font.Font("/home/pi/WorkSpace/LCD/data/SIMYOU.TTF", 30) #self.font_chinese2 = pygame.font.Font("/home/pi/WorkSpace/LCD/data/SIMYOU.TTF", 23) #self.font_chinese3 = pygame.font.Font("/home/pi/WorkSpace/LCD/data/msyhbd.ttc", 30) self.font_chinese = pygame.font.Font("/home/pi/WorkSpace/LCD/data/msyhbd.ttc", 14) pygame.mouse.set_visible(False) # Render the screen pygame.display.update() def __del__(self): "Destructor to make sure pygame shuts down, etc." def test(self): # Fill the screen with red (255, 0, 0) self.screen.fill((0, 0, 0)) global start_play global playing global index t = None while True: if (t != time.strftime('%H:%M:%S', time.localtime(time.time()))): t = time.strftime('%H:%M:%S', time.localtime(time.time())) # CPU占用率 cpu_perc = str(psutil.cpu_percent())+"%" # CPU温度 cpu_temp = str(int(psutil.sensors_temperatures()['cpu_thermal'][0].current))+"℃" # 内存总数 mem_total = str(int((psutil.virtual_memory().total)/1024/1024))+"M" # 已使用内存 mem_use = str(int((psutil.virtual_memory().used)/1024/1024))+"M" # 内存占用率 mem_perc = str(int((psutil.virtual_memory().percent)))+"%" # 网络Wlan0发送 wlan_sent = str(int( psutil.net_io_counters(pernic=True)['wlan0'].bytes_sent/1024/1024))+"M" # 网络Wlan0接收 wlan_recv = str(int( psutil.net_io_counters(pernic=True)['wlan0'].bytes_recv/1024/1024))+"M" # 网络Wlan0 IP wlan_ip = str(psutil.net_if_addrs()['wlan0'][0].address) # 启动时间 # boot_time = str(datetime.datetime.fromtimestamp(psutil.boot_time ()).strftime("%Y-%m-%d %H: %M")) # 运行时间 uptime = str(os.popen("uptime -p").readline().strip()) self.screen.fill((0, 0, 0)) ts = t.split(":") if (int(ts[0]) >= 20 or int(ts[0]) <= 7): text_sys_1 = self.font_chinese.render("CPU:" + cpu_perc + "/" +cpu_temp + " "+ "MEM:" + mem_use + "/" + mem_perc, True, (206, 0, 0)) text_sys_2 = self.font_chinese.render("NET:" + wlan_sent + "/" + wlan_recv + " : " + wlan_ip, True, (206, 0, 0)) text_sys_3 = self.font_chinese.render("RUN:" + uptime, True, (206, 0, 0)) text_time = self.font.render(ts[0] + " : " + ts[1], True, (255, 0, 0)) else: text_sys_1 = self.font_chinese.render("CPU:" + cpu_perc + "/" +cpu_temp + " "+ "MEM:" + mem_use + "/" + mem_perc, True, (222, 222, 222)) text_sys_2 = self.font_chinese.render("NET:" + wlan_sent + "/" + wlan_recv + " : " + wlan_ip, True, (222, 222, 222)) text_sys_3 = self.font_chinese.render("RUN:" + uptime, True, (222, 222, 222)) text_time = self.font.render(ts[0] + " : " + ts[1], True, (00, 255, 184)) self.screen.blit(text_time, (11, -15)) self.screen.blit(text_sys_1, (10, 85)) self.screen.blit(text_sys_2, (10, 100)) self.screen.blit(text_sys_3, (10, 115)) pygame.display.update() #每秒执行一次,减少CPU占用 time.sleep(1) # Create an instance of the PyScope class scope = pyscope() scope.test()