Skip to content

Instantly share code, notes, and snippets.

@piersstorey
Created November 28, 2023 20:51
Show Gist options
  • Save piersstorey/8d5dce556cd3205592b813bdaa222151 to your computer and use it in GitHub Desktop.
Save piersstorey/8d5dce556cd3205592b813bdaa222151 to your computer and use it in GitHub Desktop.
⌚ Wasp-os Examples and Commands
import wasp
import icons
import fonts
from micropython import const
class CounterApp():
"""Class and methods to set and run a simple counter."""
NAME = "Counter"
ICON = icons.app # Get built in 2-bit RLE icon
def __init__(self):
"""Initialize the application."""
self.running, self.stopped = const(0), const(1)
# Set default minutes and seconds values
self.seconds, self.state = 10, self.running
def foreground(self):
"""Activate the application."""
self._draw()
wasp.system.request_tick(1000)
def tick(self, ticks):
"""Periodic callback to update the display."""
if self.state == self.running : self._draw()
def _draw(self):
draw = wasp.watch.drawable
draw.fill()
draw.set_color(0x0000ff)
draw.set_font(fonts.sans36)
draw.string(str(self.seconds), 0, 108, width=240)
if self.seconds == 0:
wasp.watch.vibrator.pulse(duty=50, ms=500)
self.state = self.stopped
self.seconds -= 1
import wasp
import icons
class HelloOxPython():
"""A hello world application for wasp-os."""
NAME = "Hello" # Application displayed name
ICON = icons.app # Get built in 2-bit RLE icon
def __init__(self, msg="Hello OxPython"):
"""Init method"""
self.msg = msg # Set the message string
def foreground(self):
"""Entrypoint for drawing the screen"""
self._draw() # Call the draw method
def _draw(self):
"""Draw method for displaying the content"""
draw = wasp.watch.drawable # Use watch.drawable driver
draw.fill() # fill a rectangle (Default black screen size)
draw.string(self.msg, 0, 108, width=240) # draw the string and set position
import wasp
class SwipeTest():
"""Sample swipe test app."""
NAME = "Swipe Me"
def __init__(self):
self.action = "Swipe Test"
def foreground(self):
"""Activate foreground activities."""
self._draw()
wasp.system.request_event(wasp.EventMask.SWIPE_UPDOWN)
wasp.system.request_event(wasp.EventMask.SWIPE_LEFTRIGHT)
def swipe(self, event):
"""Notify the application of a touchscreen swipe event."""
if event[0] == wasp.EventType.DOWN: self.action = "Down"
if event[0] == wasp.EventType.UP: self.action = "Up"
if event[0] == wasp.EventType.RIGHT: self.action = "Right"
if event[0] == wasp.EventType.LEFT: self.action = "Left"
self._draw()
def _draw(self):
draw = wasp.watch.drawable
draw.fill()
draw.string(self.action, 0, 108, width=240)

⌚ Wasp-os Examples and Commands

Run simulator

make sim
CTRL + C

Register and run an app

 >>> from apps.hello_app import HelloOxPython
 >>> wasp.system.register(HelloOxPython())
 >>> wasp.system.run()

Temporarily load app on watch

./tools/wasptool --exec /wasp-os/apps/hello_app.py --eval "wasp.system.register(HelloOxPython())"

Upload a file to the wasp-os filesystem

./tools/wasptool --upload ~/repos/personal/micropython/wasp-os/wasp-os/apps/swipe_test.py

Temp register app

./tools/wasptool --console
import wasp
from swipe_test import SwipeTest
wasp.system.register(SwipeTest())

Remove py file

./tools/wasptool --console
import os
os.remove("swipe_test.py")
del os

Compile and compress app binary

./tools/wasptool --upload ~/repos/personal/micropython/wasp-os/wasp-os/apps/swipe_test.py  

Create 2-bit RLE icon

./tools/rle_encode.py --2bit myicon.png > myicon.py

2-bit RLE, 96x64, generated icon string

climb_on_icon = (
b'\x02'
b'`@'
b'\xff\xaa\xc1\xc1\xc1@\xfbAAA\xc1\xc1\xc1'
b'\xc1\xc1\xfb\xc1A\x80\xd0\x81\xc0\xf7\xc'
b'AE\x80\xfb\x81\xc0\xf7\xc1\xc1\x81zA\x81'
)

Toolbelt

⌚ wasptools (--console, --exec )
⌚ dfu.py (Bluetooth - OTA Firmware Updates)
⌚ rle_encode.py (Create 2-bit RLE icon from png)
⌚ mpy-cross (Compiles .py scripts into .mpy files)
⌚ make sim (Simulator and console)

Drivers

⌚ watch.backlight
⌚ watch.drawable
⌚ watch.battery
⌚ watch.rtc
⌚ watch.button
⌚ watch.touch
⌚ watch.display
⌚ watch.vibrator

Widgets

⌚ widgets.BatteryMeter
⌚ widgets.NotificationBar
⌚ widgets.Checkbox
⌚ widgets.ScrollIndicator
⌚ widgets.Clock
⌚ widgets.Slider
⌚ widgets.ConfirmationView
⌚ widgets.Spinner
⌚ widgets.StatusBar
⌚ widgets.ToggleButton

Wasp-OS Issues

https://github.com/wasp-os/wasp-os/issues

MicroPython Discord Community - Wearables Channel

https://discord.gg/8Prvjkjns9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment