Refactor code

This commit is contained in:
Mike Cifelli 2021-06-17 09:39:49 -04:00
parent b79b60976a
commit d0a83fbe49
1 changed files with 36 additions and 14 deletions

View File

@ -8,31 +8,53 @@ from time import sleep
from unicornhatmini import UnicornHATMini, BUTTON_A
POWER_BUTTON_HOLD_TIME_IN_SECONDS = 1
TEMP_COLOR = [64, 0, 0]
CPU_COLOR = [0, 16, 32]
class SystemStatus:
def __init__(self, hat):
self.hat = hat
self.hat.set_brightness(0.1)
self.hat.set_rotation(90)
self.hat.set_rotation(270)
self.width, self.height = self.hat.get_shape()
self.cpuStartColumn = 0
self.cpuEndColumn = int(self.width / 2) - 1
self.tempStartColumn = int(self.width / 2) + 1
self.tempEndColumn = self.width - 1
self.tempStartColumn = 0
self.tempEndColumn = int(self.width / 2)
self.cpuStartColumn = int(self.width / 2)
self.cpuEndColumn = self.width - 1
def display(self):
for x in range(self.cpuStartColumn, self.cpuEndColumn):
for y in range(self.height):
self.hat.set_pixel(x, y, 255, 0, 127)
for x in range(self.tempStartColumn, self.tempEndColumn):
for y in range(self.height):
self.hat.set_pixel(x, y, 0, 127, 255)
self.displayTemp()
self.displayCpu()
self.hat.show()
def displayTemp(self):
self.displayField(
start=self.tempStartColumn,
end=self.tempEndColumn,
value=self.getTempValue(),
color=TEMP_COLOR
)
def displayCpu(self):
self.displayField(
start=self.cpuStartColumn,
end=self.cpuEndColumn,
value=self.getCpuValue(),
color=CPU_COLOR
)
def displayField(self, start, end, value, color):
for x in range(start, end):
for y in range(value):
self.hat.set_pixel(x, y, *color)
def getTempValue(self):
return self.height
def getCpuValue(self):
return self.height
def exit(self):
self.hat.set_all(0, 0, 0)
self.hat.show()