Random fixes

philcrump-phil-add-ntp
Marek Ventur 2018-08-24 23:00:09 +01:00
parent ba94e340f8
commit 14007f3d9e
8 changed files with 95 additions and 21 deletions

13
README
View File

@ -7,3 +7,16 @@ TiLDA Mk4 App Library
* How to make your own changes
* How to run tests
* How to send a PR
Please use one of these categories:
* System
* Homescreens
* Games
* Sound
* EMF
* Villages
* Phone
* LEDs
* Sensors
* Demo
* Other

View File

@ -1,4 +1,4 @@
import os, micropython, sys
import os, tilda
# micropython.alloc_emergency_exception_buf(100) # doesn't exist in TiLDA Mk4 yet
@ -10,7 +10,6 @@ def app(a):
return a + "/main.py"
def file(file, remove):
print(file)
try:
a = None
with open(file, 'r') as f:
@ -19,7 +18,7 @@ def file(file, remove):
os.remove(file)
return app(a)
except Exception as e:
print(e)
print(str(e))
def any_home():
return app(next(a for a in root if a.startswith("home")))
@ -31,5 +30,5 @@ else:
if "main.py" in root:
start = "main.py"
start = file("once.txt", True) or file("default_app.txt", False) or any_home() or "bootstrap.py"
#todo: something like tilda.main(start)
print(start)
#tilda.main(start)

View File

@ -17,28 +17,29 @@ from homescreen import *
import time
init()
ugfx.clear()
# title
ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
ugfx.Label(0, 20, ugfx.width(), 40, "TiLDA Mk4", justification=ugfx.Label.CENTERTOP)
#ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
ugfx.Label(0, 20, ugfx.width(), 40, "TiLDA Mk4") # , justification=ugfx.Label.CENTERTOP
# name
if name():
ugfx.set_default_font(ugfx.FONT_NAME)
ugfx.Label(0, 60, ugfx.width(), 40, name(), justification=ugfx.Label.CENTERTOP)
#ugfx.set_default_font(ugfx.FONT_NAME)
ugfx.Label(0, 60, ugfx.width(), 40, name()) # , justification=ugfx.Label.CENTERTOP
else:
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.set_default_font(ugfx.FONT_MEDIUM)
ugfx.Label(0, 60, ugfx.width(), 40, "Set your name in the settings app") # , justification=ugfx.Label.CENTERTOP
# 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)
status = ugfx.Label(0, 130, ugfx.width(), 40, "", justification=ugfx.Label.CENTERTOP)
#ugfx.set_default_font(ugfx.FONT_MEDIUM)
status = ugfx.Label(0, 130, ugfx.width(), 40, "") # , justification=ugfx.Label.CENTERTOP
# update loop
while True:
status.text("wifi: %s%%\nbattery: %s%%" % (int(wifi_strength() * 100), int(battery() * 100)))
sleep(500)
sleep_or_exit(0.5)

View File

@ -19,7 +19,7 @@ They also *may*:
___license___ = "MIT"
___dependencies___ = ["database", "buttons", "random", "app", "sleep"]
import database, ugfx, random, select, buttons
import database, ugfx, random, buttons, tilda, sleep
from app import App
_state = None
@ -29,7 +29,7 @@ def init(enable_menu_button = True):
ugfx.init()
if enable_menu_button:
buttons.init()
pass
#buttons.enable_interrupt("BTN_MENU", lambda t: set_state("menu"), on_release = True)
def set_state(key, value = True):
@ -41,10 +41,12 @@ def set_state(key, value = True):
def clean_up():
pass
def sleep(interval = 500):
if button.is_triggered("BTN_MENU", interval=interval):
def sleep_or_exit(interval = 0.5):
# 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()
App("launcher").boot()
sleep.sleep(interval)
def name(default = None):

View File

@ -6,6 +6,10 @@ def sleep_ms(duration):
# todo: deepsleep?
time.sleep_ms(duration)
def sleep(duration):
# todo: deepsleep?
time.sleep(duration)
def wfi():
# todo: this is fake
sleep_ms(1)

View File

@ -36,12 +36,13 @@ def frequency(value = None):
return _frequency
_frequency = value
_set_amp()
speaker_pwm().init(duty=50, freq=_frequency)
speaker_pwm().init(duty=1, freq=_frequency)
def stop():
global _frequency
# todo: maybe we should deinit the PWM?
_frequency = None
_set_amp()
speaker_pwm().duty(0)
# Music

View File

@ -3,9 +3,11 @@
___license___ = "MIT"
___dependencies___ = ["upip:unittest", "speaker", "sleep"]
import unittest, speaker
import unittest, speaker, ugfx_helper
from sleep import *
ugfx_helper.init()
class TestSpeaker(unittest.TestCase):
def tearDown(self):

52
synth/main.py Normal file
View File

@ -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()