summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-05-17 08:45:16 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-05-17 08:45:16 (GMT)
commit4906d46ff42ec9ecec49de375677dd6654455845 (patch)
tree433bbeb01a0f2aa30b8e471e37d6465552e82191
parentc3bc8717277db06ab829387bab5ad280d886375c (diff)
apps: demo: Move the demo code into a fully fledged application
-rw-r--r--README.rst12
-rw-r--r--wasp/apps/demo.py72
-rw-r--r--wasp/demo.py65
3 files changed, 72 insertions, 77 deletions
diff --git a/README.rst b/README.rst
index fe62bbe..8341569 100644
--- a/README.rst
+++ b/README.rst
@@ -109,18 +109,6 @@ At this point you will also be able to use the Nordic UART Service to
access the MicroPython REPL, although currently you must send ^C to
interrupt the program that updates the watch display.
-Just for fun try:
-
-.. code-block:: python
-
- ^C
- import demo
- demo.run()
- # After watching the demo for a bit...
- ^C
- wasp.app.draw(watch)
- wasp.system.run()
-
To set the time and restart the main application:
.. code-block:: python
diff --git a/wasp/apps/demo.py b/wasp/apps/demo.py
new file mode 100644
index 0000000..e71cfbe
--- /dev/null
+++ b/wasp/apps/demo.py
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: LGPL-3.0-or-later
+# Copyright (C) 2020 Daniel Thompson
+
+"""Logo demo for PineTime
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This demo is simply an alternating sweep of the Pine64 and
+MicroPython logos. It cycles through a variety of colours
+and swaps between the logos every 5 images (so if you change
+anything make sure len(colors) is not a multiple of 5).
+"""
+
+import wasp
+import logo
+import icons
+
+colors = (
+ 0xffff,
+ 0xf800, # red
+ 0xffff,
+ 0xffe0, # yellow
+ 0xffff,
+ 0x07e0, # green
+ 0xffff,
+ 0x07ff, # cyan
+ 0xffff,
+ 0x001f, # blue
+ 0xffff,
+ 0xf81f, # magenta
+ )
+
+class DemoApp():
+ """Application for live demos.
+
+ Start this to give the watch something "interesting" to do when talking
+ over demos!
+ """
+ NAME = 'Demo'
+ ICON = icons.app
+
+ def __init__(self):
+ self._logo = logo.pine64
+ self._color = 0
+ self._i = 0
+
+ def foreground(self):
+ """Draw the first frame and establish the tick."""
+ self._draw()
+ wasp.system.request_tick(2000)
+
+ def tick(self, ticks):
+ """Handle the tick."""
+ self._draw()
+ wasp.system.keep_awake()
+
+ def _draw(self):
+ """Draw the next frame."""
+ draw = wasp.watch.drawable
+
+ if self._i < 5:
+ self._i += 1
+ else:
+ self._i = 0
+ if self._logo == logo.pine64:
+ self._logo = logo.micropython
+ else:
+ self._logo = logo.pine64
+ draw.fill()
+ draw.rleblit(self._logo, fg=colors[self._color])
+ self._color += 1
+ if self._color >= len(colors):
+ self._color = 0
diff --git a/wasp/demo.py b/wasp/demo.py
deleted file mode 100644
index a16c306..0000000
--- a/wasp/demo.py
+++ /dev/null
@@ -1,65 +0,0 @@
-# SPDX-License-Identifier: LGPL-3.0-or-later
-# Copyright (C) 2020 Daniel Thompson
-
-#
-# Logo demo for PineTime
-#
-# This demo is simply an alternating sweep of the Pine64 and
-# MicroPython logos. It cycles through a variety of colours
-# and swaps between the logos every 5 images (so make sure
-# len(colors) is not a multiple of 5 ;-) ).
-#
-
-import watch, logo, time, gc
-
-colors = (
- 0xffff,
- 0xf800, # red
- 0xffff,
- 0xffe0, # yellow
- 0xffff,
- 0x07e0, # green
- 0xffff,
- 0x07ff, # cyan
- 0xffff,
- 0x001f, # blue
- 0xffff,
- 0xf81f, # magenta
- )
-
-def textdemo():
- watch.display.fill(0)
- draw = watch.drawable
- draw.string("The quick brown", 12, 24)
- draw.string("fox jumped over", 12, 48)
- draw.string("the lazy dog.", 12, 72)
- time.sleep(2)
- draw.string("0123456789", 12, 120)
- draw.string('!"£$%^&*()', 12, 144)
- time.sleep(3)
-
-def run():
- l = logo.pine64
- i = 0
-
- watch.display.poweron()
- watch.backlight.set(2)
-
- while True:
- for c in colors:
- if i == 2:
- textdemo()
- if i < 5:
- i += 1
- else:
- i = 0
- if l == logo.pine64:
- l = logo.micropython
- else:
- l = logo.pine64
- watch.display.fill(0)
-
- watch.drawable.rleblit(l, fg=c)
- time.sleep(2)
- gc.collect()
-