Experiment with edit screen

This commit is contained in:
Phil Howard
2020-08-28 13:12:40 +01:00
parent 5928f99e29
commit 732034952c

View File

@@ -107,8 +107,6 @@ class DetailView(View):
) )
class EditView(View): class EditView(View):
def __init__(self, channel=None): def __init__(self, channel=None):
self.channel = channel self.channel = channel
@@ -119,10 +117,39 @@ class EditView(View):
width, height = canvas.size width, height = canvas.size
draw.rectangle((0, 0, width, height), (255, 255, 255)) draw.rectangle((0, 0, width, height), (255, 255, 255))
draw.rectangle(( self.channel.render_edit(canvas, font)
0, 0,
40, DISPLAY_HEIGHT # Icon backdrops
), (60, 60, 60)) draw.rectangle((0, 0, 19, 19), (138, 138, 138))
draw.rectangle((DISPLAY_WIDTH - 38, 0, DISPLAY_WIDTH, 19), (75, 166, 252))
draw.rectangle((0, DISPLAY_HEIGHT - 19, 60, DISPLAY_WIDTH), (32, 137, 251))
draw.rectangle((DISPLAY_WIDTH - 60, DISPLAY_HEIGHT - 19, DISPLAY_WIDTH, DISPLAY_HEIGHT), (254, 219, 82))
# Icons
icon(image, icon_rightarrow, (0, 0), (255, 255, 255))
# Edit
draw.text(
(DISPLAY_WIDTH - 36, 3),
"Done",
font=font,
fill=(255, 255, 255)
)
draw.text(
(0, HEIGHT - 19),
"Set Wet",
font=font,
fill=(255, 255, 255)
)
draw.text(
(DISPLAY_WIDTH - 60, HEIGHT - 19),
"Set Dry",
font=font,
fill=(255, 255, 255)
)
class Channel: class Channel:
@@ -237,6 +264,21 @@ Dry point: {dry_point}
return True return True
return False return False
def render_edit(self, image, font):
draw = ImageDraw.Draw(image)
draw.text(
(23, 3),
"{}".format(self.title),
font=font,
fill=(0, 0, 0)
)
draw.text(
(5, 30),
"Sat: {:.2f}%".format(self.sensor.saturation * 100),
font=font,
fill=(0, 0, 0)
)
def render_detail(self, image, font): def render_detail(self, image, font):
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
draw.text( draw.text(
@@ -317,7 +359,7 @@ Dry point: {dry_point}
if sat < self.alarm_level and not self.alarm: if sat < self.alarm_level and not self.alarm:
logging.warning( logging.warning(
"Alarm on Channel: {} - saturation is {:.2f}% (warn level {:.2f}%)".format( "Alarm on Channel: {} - saturation is {:.2f}% (warn level {:.2f}%)".format(
self.channel, sat * 10, self.alarm_level * 10 self.channel, sat * 100, self.alarm_level * 100
) )
) )
self.alarm = True self.alarm = True
@@ -359,6 +401,7 @@ def handle_button(pin):
label = LABELS[index] label = LABELS[index]
if label == "A": # Select View if label == "A": # Select View
if current_subview == 0:
current_view += 1 current_view += 1
current_view %= len(views) current_view %= len(views)
current_subview = 0 current_subview = 0
@@ -370,7 +413,11 @@ def handle_button(pin):
channel.alarm = False channel.alarm = False
if label == "X": if label == "X":
pass view = views[current_view]
if isinstance(view, tuple):
current_subview += 1
current_subview %= len(view)
print("Switched to subview {}".format(current_subview))
if label == "Y": if label == "Y":
pass pass
@@ -382,7 +429,7 @@ def main():
GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_UP)
for pin in BUTTONS: for pin in BUTTONS:
GPIO.add_event_detect(pin, GPIO.FALLING, handle_button, bouncetime=150) GPIO.add_event_detect(pin, GPIO.FALLING, handle_button, bouncetime=200)
alarm_enable = True alarm_enable = True
alarm_interval = 10.0 alarm_interval = 10.0