Random fixes
parent
ba94e340f8
commit
14007f3d9e
13
README
13
README
|
@ -7,3 +7,16 @@ TiLDA Mk4 App Library
|
||||||
* How to make your own changes
|
* How to make your own changes
|
||||||
* How to run tests
|
* How to run tests
|
||||||
* How to send a PR
|
* How to send a PR
|
||||||
|
|
||||||
|
Please use one of these categories:
|
||||||
|
* System
|
||||||
|
* Homescreens
|
||||||
|
* Games
|
||||||
|
* Sound
|
||||||
|
* EMF
|
||||||
|
* Villages
|
||||||
|
* Phone
|
||||||
|
* LEDs
|
||||||
|
* Sensors
|
||||||
|
* Demo
|
||||||
|
* Other
|
||||||
|
|
9
boot.py
9
boot.py
|
@ -1,4 +1,4 @@
|
||||||
import os, micropython, sys
|
import os, tilda
|
||||||
|
|
||||||
# micropython.alloc_emergency_exception_buf(100) # doesn't exist in TiLDA Mk4 yet
|
# micropython.alloc_emergency_exception_buf(100) # doesn't exist in TiLDA Mk4 yet
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ def app(a):
|
||||||
return a + "/main.py"
|
return a + "/main.py"
|
||||||
|
|
||||||
def file(file, remove):
|
def file(file, remove):
|
||||||
print(file)
|
|
||||||
try:
|
try:
|
||||||
a = None
|
a = None
|
||||||
with open(file, 'r') as f:
|
with open(file, 'r') as f:
|
||||||
|
@ -19,7 +18,7 @@ def file(file, remove):
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
return app(a)
|
return app(a)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(str(e))
|
||||||
|
|
||||||
def any_home():
|
def any_home():
|
||||||
return app(next(a for a in root if a.startswith("home")))
|
return app(next(a for a in root if a.startswith("home")))
|
||||||
|
@ -31,5 +30,5 @@ else:
|
||||||
if "main.py" in root:
|
if "main.py" in root:
|
||||||
start = "main.py"
|
start = "main.py"
|
||||||
start = file("once.txt", True) or file("default_app.txt", False) or any_home() or "bootstrap.py"
|
start = file("once.txt", True) or file("default_app.txt", False) or any_home() or "bootstrap.py"
|
||||||
|
print(start)
|
||||||
#todo: something like tilda.main(start)
|
#tilda.main(start)
|
||||||
|
|
|
@ -17,28 +17,29 @@ from homescreen import *
|
||||||
import time
|
import time
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
ugfx.clear()
|
||||||
|
|
||||||
# title
|
# title
|
||||||
ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
|
#ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
|
||||||
ugfx.Label(0, 20, ugfx.width(), 40, "TiLDA Mk4", justification=ugfx.Label.CENTERTOP)
|
ugfx.Label(0, 20, ugfx.width(), 40, "TiLDA Mk4") # , justification=ugfx.Label.CENTERTOP
|
||||||
|
|
||||||
# name
|
# name
|
||||||
if name():
|
if name():
|
||||||
ugfx.set_default_font(ugfx.FONT_NAME)
|
#ugfx.set_default_font(ugfx.FONT_NAME)
|
||||||
ugfx.Label(0, 60, ugfx.width(), 40, name(), justification=ugfx.Label.CENTERTOP)
|
ugfx.Label(0, 60, ugfx.width(), 40, name()) # , justification=ugfx.Label.CENTERTOP
|
||||||
else:
|
else:
|
||||||
ugfx.set_default_font(ugfx.FONT_MEDIUM)
|
#ugfx.set_default_font(ugfx.FONT_MEDIUM)
|
||||||
ugfx.Label(0, 60, ugfx.width(), 40, "Set your name in the settings app", justification=ugfx.Label.CENTERTOP)
|
ugfx.Label(0, 60, ugfx.width(), 40, "Set your name in the settings app") # , justification=ugfx.Label.CENTERTOP
|
||||||
|
|
||||||
# info
|
# info
|
||||||
ugfx.Label(0, 200, ugfx.width(), 40, "Press MENU", justification=ugfx.Label.CENTERTOP)
|
ugfx.Label(0, 200, ugfx.width(), 40, "Press MENU") # , justification=ugfx.Label.CENTERTOP
|
||||||
|
|
||||||
ugfx.set_default_font(ugfx.FONT_MEDIUM)
|
#ugfx.set_default_font(ugfx.FONT_MEDIUM)
|
||||||
status = ugfx.Label(0, 130, ugfx.width(), 40, "", justification=ugfx.Label.CENTERTOP)
|
status = ugfx.Label(0, 130, ugfx.width(), 40, "") # , justification=ugfx.Label.CENTERTOP
|
||||||
|
|
||||||
# update loop
|
# update loop
|
||||||
while True:
|
while True:
|
||||||
status.text("wifi: %s%%\nbattery: %s%%" % (int(wifi_strength() * 100), int(battery() * 100)))
|
status.text("wifi: %s%%\nbattery: %s%%" % (int(wifi_strength() * 100), int(battery() * 100)))
|
||||||
sleep(500)
|
sleep_or_exit(0.5)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ They also *may*:
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["database", "buttons", "random", "app", "sleep"]
|
___dependencies___ = ["database", "buttons", "random", "app", "sleep"]
|
||||||
|
|
||||||
import database, ugfx, random, select, buttons
|
import database, ugfx, random, buttons, tilda, sleep
|
||||||
from app import App
|
from app import App
|
||||||
|
|
||||||
_state = None
|
_state = None
|
||||||
|
@ -29,7 +29,7 @@ def init(enable_menu_button = True):
|
||||||
ugfx.init()
|
ugfx.init()
|
||||||
|
|
||||||
if enable_menu_button:
|
if enable_menu_button:
|
||||||
buttons.init()
|
pass
|
||||||
#buttons.enable_interrupt("BTN_MENU", lambda t: set_state("menu"), on_release = True)
|
#buttons.enable_interrupt("BTN_MENU", lambda t: set_state("menu"), on_release = True)
|
||||||
|
|
||||||
def set_state(key, value = True):
|
def set_state(key, value = True):
|
||||||
|
@ -41,10 +41,12 @@ def set_state(key, value = True):
|
||||||
def clean_up():
|
def clean_up():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def sleep(interval = 500):
|
def sleep_or_exit(interval = 0.5):
|
||||||
if button.is_triggered("BTN_MENU", interval=interval):
|
# todo: do this better - check button multiple times and sleep for only a short while
|
||||||
|
if buttons.is_triggered(tilda.Buttons.BTN_Menu):
|
||||||
clean_up()
|
clean_up()
|
||||||
App("launcher").boot()
|
App("launcher").boot()
|
||||||
|
sleep.sleep(interval)
|
||||||
|
|
||||||
|
|
||||||
def name(default = None):
|
def name(default = None):
|
||||||
|
|
|
@ -6,6 +6,10 @@ def sleep_ms(duration):
|
||||||
# todo: deepsleep?
|
# todo: deepsleep?
|
||||||
time.sleep_ms(duration)
|
time.sleep_ms(duration)
|
||||||
|
|
||||||
|
def sleep(duration):
|
||||||
|
# todo: deepsleep?
|
||||||
|
time.sleep(duration)
|
||||||
|
|
||||||
def wfi():
|
def wfi():
|
||||||
# todo: this is fake
|
# todo: this is fake
|
||||||
sleep_ms(1)
|
sleep_ms(1)
|
||||||
|
|
|
@ -36,12 +36,13 @@ def frequency(value = None):
|
||||||
return _frequency
|
return _frequency
|
||||||
_frequency = value
|
_frequency = value
|
||||||
_set_amp()
|
_set_amp()
|
||||||
speaker_pwm().init(duty=50, freq=_frequency)
|
speaker_pwm().init(duty=1, freq=_frequency)
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
global _frequency
|
global _frequency
|
||||||
# todo: maybe we should deinit the PWM?
|
# todo: maybe we should deinit the PWM?
|
||||||
_frequency = None
|
_frequency = None
|
||||||
|
_set_amp()
|
||||||
speaker_pwm().duty(0)
|
speaker_pwm().duty(0)
|
||||||
|
|
||||||
# Music
|
# Music
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["upip:unittest", "speaker", "sleep"]
|
___dependencies___ = ["upip:unittest", "speaker", "sleep"]
|
||||||
|
|
||||||
import unittest, speaker
|
import unittest, speaker, ugfx_helper
|
||||||
from sleep import *
|
from sleep import *
|
||||||
|
|
||||||
|
ugfx_helper.init()
|
||||||
|
|
||||||
class TestSpeaker(unittest.TestCase):
|
class TestSpeaker(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
"""BEEP BEEP!
|
||||||
|
|
||||||
|
Todo: fix this, it doesn't work at at the moment
|
||||||
|
"""
|
||||||
|
|
||||||
|
___name___ = "Synthesizers"
|
||||||
|
___license___ = "MIT"
|
||||||
|
___categories___ = ["Sound"]
|
||||||
|
___dependencies___ = ["speaker", "buttons", "ugfx_helper"]
|
||||||
|
|
||||||
|
import ugfx, speaker, ugfx_helper
|
||||||
|
from app import *
|
||||||
|
from tilda import Buttons
|
||||||
|
from buttons import *
|
||||||
|
|
||||||
|
ugfx_helper.init()
|
||||||
|
speaker.enabled(True)
|
||||||
|
|
||||||
|
def mode_buttons():
|
||||||
|
print("mode: buttons")
|
||||||
|
notes = {
|
||||||
|
Buttons.BTN_1: "C",
|
||||||
|
Buttons.BTN_2: "C#",
|
||||||
|
Buttons.BTN_3: "D",
|
||||||
|
Buttons.BTN_4: "D#",
|
||||||
|
Buttons.BTN_5: "E",
|
||||||
|
Buttons.BTN_6: "F",
|
||||||
|
Buttons.BTN_7: "F#",
|
||||||
|
Buttons.BTN_8: "G",
|
||||||
|
Buttons.BTN_9: "G#",
|
||||||
|
Buttons.BTN_Star: "A",
|
||||||
|
Buttons.BTN_0: "A#",
|
||||||
|
Buttons.BTN_Hash: "B"
|
||||||
|
}
|
||||||
|
ugfx.clear()
|
||||||
|
ugfx.text(5, 5, "Synth", ugfx.BLACK)
|
||||||
|
ugfx.text(5, 30, "Use the buttons >", ugfx.BLACK)
|
||||||
|
ugfx.text(5, 80, "Octave: 4", ugfx.BLUE) # Make this adjustable
|
||||||
|
|
||||||
|
alive = True
|
||||||
|
while alive:
|
||||||
|
note_to_play = None
|
||||||
|
for btn, note in notes.items():
|
||||||
|
if is_pressed(btn):
|
||||||
|
note_to_play = note
|
||||||
|
break
|
||||||
|
if note_to_play:
|
||||||
|
speaker.note(note_to_play)
|
||||||
|
else:
|
||||||
|
speaker.stop()
|
||||||
|
|
||||||
|
mode_buttons()
|
Loading…
Reference in New Issue