Skip to content

Instantly share code, notes, and snippets.

@BearBeardgh
Forked from mishushakov/README.md
Created March 6, 2022 14:12
Show Gist options
  • Save BearBeardgh/3063e029264bdb05817ac3c8cd163708 to your computer and use it in GitHub Desktop.
Save BearBeardgh/3063e029264bdb05817ac3c8cd163708 to your computer and use it in GitHub Desktop.
PineTime PulseTime (Metronome)

PulseTime for wasp-os

Problem

  • Soundbrenner Smartwatch is expensive (197 eur)
  • Existing Apple Watch apps either don’t fulfil the requirement of having haptic vibration or offer unreasonable subscription-based business model
  • Publishing new Apple Watch app would cost me 100/year + take effort learning their programming language and frameworks

Pine64 PineTime comes to rescue

  • very affordable, 20 eur
  • open-source platform
  • has vibration sensor
  • python sdk
import wasp
from time import sleep #, perf_counter
import _thread
class PulseApp():
"""A metronome application for wasp-os."""
NAME = "Pulse"
def __init__(self):
self._metronome_spinner = wasp.widgets.Spinner(90, 60, 1, 200)
self._metronome_toggle = wasp.widgets.Button(0, 200, 240, 40, "START / STOP")
self._metronome_spinner.value = 120
self._metronome_activated = False
# Metronome
def _metronome(self):
delay = d = (60 / self._metronome_spinner.value) - 0.01
#prev = perf_counter()
while True:
if not self._metronome_activated:
break
sleep(d)
#t = perf_counter()
#delta = t - prev - delay
wasp.watch.vibrator.pulse(50, 100)
#print("Pulse")
#d -= delta
#prev = t
# Start metronome by creating a new thread with _metronome as target
def _start_metronome(self):
self._metronome_activated = True
_thread.start_new_thread(self._metronome, ())
print("Started", self._metronome_spinner.value)
# Stop running metronome by overriding _metronome_activated value and joining the threads
def _stop_metronome(self):
self._metronome_activated = False
try:
_thread.exit()
except SystemExit:
print("Stopped")
# Start or stop metronome depending if it's deactivated or activated, respectivly
def _toggle_metronome(self):
if self._metronome_activated:
self._stop_metronome()
else:
self._start_metronome()
def foreground(self):
self._draw()
wasp.system.request_event(wasp.EventMask.TOUCH |
wasp.EventMask.BUTTON)
wasp.system.request_tick(1000)
def press(self, button, state):
if state == True:
self._toggle_metronome()
def touch(self, event):
if self._metronome_spinner.touch(event):
if self._metronome_activated:
self._stop_metronome()
if self._metronome_toggle.touch(event):
self._toggle_metronome()
# Keep the screen awake to avoid messing with latency
def tick(self, _ticks):
wasp.system.keep_awake()
def _draw(self):
draw = wasp.watch.drawable
draw.fill()
draw.string("PulseTime", 0, 6, width=240)
draw.string("BPM", 165, 115, width=40)
self._metronome_spinner.draw()
self._metronome_toggle.draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment