From e570bf4f262180f09d8b6bdef393d529c567b238 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Mon, 28 Dec 2020 14:37:15 +0000 Subject: [PATCH] apps: calc: Optimize the fields lookup structure Currently the fields is a list of lists of strings. This will needlessly consume RAM so lets switch it over to a simple string (which is immutable and can be stored in flash). We also replace indices with simple x and y variables. In addition to avoiding a (temporary) memory allocation this is also easier to use when looking up in fields. Signed-off-by: Daniel Thompson --- wasp/apps/calc.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/wasp/apps/calc.py b/wasp/apps/calc.py index 35a2309..5860b31 100644 --- a/wasp/apps/calc.py +++ b/wasp/apps/calc.py @@ -39,6 +39,10 @@ calc = ( b'n3l5j7h9f3): - indices[0] = 3 - if (indices[1]>4): - indices[1] = 4 - button_pressed = self.fields[indices[0]][indices[1]] + if x > 4: + x = 4 + if y > 3: + y = 3 + button_pressed = fields[x + 5*y] if (button_pressed == "C"): self.output = "" elif (button_pressed == "="): @@ -96,7 +98,7 @@ class CalculatorApp(): if x == 3: draw.set_color(wasp.system.theme('accent-mid')) for y in range(4): - label = self.fields[y][x] + label = fields[x + 5*y] if (x == 0): draw.string(label, x*47+14, y*47+60) else: