diff --git a/README.rst b/README.rst index 8578c3c..8985e40 100644 --- a/README.rst +++ b/README.rst @@ -185,6 +185,10 @@ using one of the techniques is the Application Writer's guide. :alt: Music Player running in the wasp-os simulator :width: 179 +.. image:: res/CalcApp.png + :alt: Calculator running in the wasp-os simulator + :width: 179 + .. image:: res/SnakeApp.png :alt: Snake Game running in the wasp-os simulator :width: 179 diff --git a/res/CalcApp.png b/res/CalcApp.png new file mode 100644 index 0000000..8af84a6 Binary files /dev/null and b/res/CalcApp.png differ diff --git a/res/calc.png b/res/calc.png new file mode 100644 index 0000000..14a3199 Binary files /dev/null and b/res/calc.png differ diff --git a/wasp/apps/calc.py b/wasp/apps/calc.py new file mode 100644 index 0000000..8dddf57 --- /dev/null +++ b/wasp/apps/calc.py @@ -0,0 +1,121 @@ +# 2-bit RLE, generated from res/calc.png, 413 bytes +calc = ( + b'\x02' + b'`@' + b'(@\x03P?\x0eV?\x08[?\x04_?\x01b' + b' 200): # undo button pressed + if (self.output != ""): + self.output = self.output[:-1] + else: + indices = [(event[2]// 48)-1,event[1]//47] + # Error handling for touching at the border + if (indices[0]>3): + indices[0] = 3 + if (indices[1]>4): + indices[1] = 4 + button_pressed = self.fields[indices[0]][indices[1]] + if (button_pressed == "C"): + self.output = "" + elif (button_pressed == "="): + self.output = self.calculate(self.output) + else: + self.output += button_pressed + self.display_output() + + def _draw(self): + draw = wasp.watch.drawable + draw.fill() + # Make grid: + for i in range(4): + # horizontal lines + draw.line(x0=0,y0=(i+1)*47,x1=240,y1=(i+1)*47) + # vertical lines + draw.line(x0=(i+1)*47,y0=47,x1=(i+1)*47,y1=240) + # Draw button label: + for y in range(4): + for x in range(5): + label = self.fields[y][x] + if (x == 0): + draw.string(label, x*47+14, y*47+60) + else: + draw.string(label, x*47+16, y*47+60) + draw.string("<", 215, 10) + + + + def display_output(self): + wasp.watch.drawable.fill(x=2,y=2,w=170,h=40) + if (self.output != ""): + if len(self.output) >= 10: + wasp.watch.drawable.string(self.output[len(self.output)-9:], 6, 14, width=170) + else: + wasp.watch.drawable.string(self.output, 6, 14, width=170) + + def calculate(self,s): + equation = s + + # Normal calculator stuff + for i in range(len(s)): + if (s[i] =="^"): + equation = s[:i] + "**"+s[i+1:] + elif (s[i] == ":"): + equation = s[:i] + "/"+s[i+1:] + try: + result = eval(equation) + except: # Error + result = "" + return str(result) \ No newline at end of file diff --git a/wasp/boards/manifest_240x240.py b/wasp/boards/manifest_240x240.py index 4341fc9..6021df5 100644 --- a/wasp/boards/manifest_240x240.py +++ b/wasp/boards/manifest_240x240.py @@ -10,6 +10,7 @@ manifest = ( 'apps/haiku.py', 'apps/heart.py', 'apps/musicplayer.py', + 'apps/calc.py', 'apps/launcher.py', 'apps/pager.py', 'apps/settings.py', diff --git a/wasp/boards/simulator/main.py b/wasp/boards/simulator/main.py index d170247..ea943f3 100644 --- a/wasp/boards/simulator/main.py +++ b/wasp/boards/simulator/main.py @@ -15,6 +15,9 @@ wasp.system.register(GameOfLifeApp()) from apps.snake import SnakeGameApp wasp.system.register(SnakeGameApp()) +from apps.calc import CalculatorApp +wasp.system.register(CalculatorApp()) + from apps.musicplayer import MusicPlayerApp wasp.system.register(MusicPlayerApp()) wasp.system.set_music_info({