Compare commits
3 Commits
b69f4bd87d
...
aa1a02ce54
| Author | SHA1 | Date | |
|---|---|---|---|
| aa1a02ce54 | |||
| 3e888790e4 | |||
| 96759c999c |
@@ -17,6 +17,7 @@ set -eu
|
|||||||
)
|
)
|
||||||
|
|
||||||
BUILDDIR=lib/micropython/ports/rp2/build-TONBERRY_RPI_PICO_W/
|
BUILDDIR=lib/micropython/ports/rp2/build-TONBERRY_RPI_PICO_W/
|
||||||
|
BUILDDIR_UNIX=lib/micropython/ports/unix/build-tonberry_unix/
|
||||||
OUTDIR=$(pwd)/build
|
OUTDIR=$(pwd)/build
|
||||||
mkdir -p "$OUTDIR"
|
mkdir -p "$OUTDIR"
|
||||||
FS_STAGE_DIR=$(mktemp -d)
|
FS_STAGE_DIR=$(mktemp -d)
|
||||||
@@ -51,5 +52,9 @@ for hwconfig in boards/RPI_PICO_W/manifest-*.py; do
|
|||||||
$PICOTOOL uf2 convert $BUILDDIR/firmware-filesystem.bin "$OUTDIR"/firmware-filesystem-"$hwname".uf2
|
$PICOTOOL uf2 convert $BUILDDIR/firmware-filesystem.bin "$OUTDIR"/firmware-filesystem-"$hwname".uf2
|
||||||
done
|
done
|
||||||
|
|
||||||
|
cp "$BUILDDIR_UNIX"/micropython "$OUTDIR"/micropython-tonberry_unix
|
||||||
|
chmod u+x "$OUTDIR"/micropython-tonberry_unix
|
||||||
|
|
||||||
echo "Output in" "${OUTDIR}"/firmware-*.uf2
|
echo "Output in" "${OUTDIR}"/firmware-*.uf2
|
||||||
echo "Images with filesystem in" "${OUTDIR}"/firmware-filesystem-*.uf2
|
echo "Images with filesystem in" "${OUTDIR}"/firmware-filesystem-*.uf2
|
||||||
|
echo "Unix build in" "${OUTDIR}"/micropython-tonberry_unix
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class PlayerApp:
|
|||||||
self.mp3file = None
|
self.mp3file = None
|
||||||
self.volume_pos = 3
|
self.volume_pos = 3
|
||||||
self.paused = False
|
self.paused = False
|
||||||
|
self.playing = False
|
||||||
self.player.set_volume(VOLUME_CURVE[self.volume_pos])
|
self.player.set_volume(VOLUME_CURVE[self.volume_pos])
|
||||||
self._onIdle()
|
self._onIdle()
|
||||||
|
|
||||||
@@ -115,6 +116,9 @@ class PlayerApp:
|
|||||||
# Check again in a minute
|
# Check again in a minute
|
||||||
self.timer_manager.schedule(time.ticks_ms() + self.idle_timeout_ms, self.onIdleTimeout)
|
self.timer_manager.schedule(time.ticks_ms() + self.idle_timeout_ms, self.onIdleTimeout)
|
||||||
|
|
||||||
|
def is_playing(self) -> bool:
|
||||||
|
return self.playing
|
||||||
|
|
||||||
def _set_playlist(self, tag: bytes):
|
def _set_playlist(self, tag: bytes):
|
||||||
if self.playlist is not None:
|
if self.playlist is not None:
|
||||||
pos = self.player.stop()
|
pos = self.player.stop()
|
||||||
@@ -176,7 +180,9 @@ class PlayerApp:
|
|||||||
def _onIdle(self):
|
def _onIdle(self):
|
||||||
self.timer_manager.schedule(time.ticks_ms() + self.idle_timeout_ms, self.onIdleTimeout)
|
self.timer_manager.schedule(time.ticks_ms() + self.idle_timeout_ms, self.onIdleTimeout)
|
||||||
self.leds.set_state(self.leds.IDLE)
|
self.leds.set_state(self.leds.IDLE)
|
||||||
|
self.playing = False
|
||||||
|
|
||||||
def _onActive(self):
|
def _onActive(self):
|
||||||
self.timer_manager.cancel(self.onIdleTimeout)
|
self.timer_manager.cancel(self.onIdleTimeout)
|
||||||
self.leds.set_state(self.leds.PLAYING)
|
self.leds.set_state(self.leds.PLAYING)
|
||||||
|
self.playing = True
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ def run():
|
|||||||
|
|
||||||
# Wifi with default config
|
# Wifi with default config
|
||||||
setup_wifi()
|
setup_wifi()
|
||||||
start_webserver(config)
|
|
||||||
|
|
||||||
# Setup MP3 player
|
# Setup MP3 player
|
||||||
with SDContext(mosi=hwconfig.SD_DI, miso=hwconfig.SD_DO, sck=hwconfig.SD_SCK, ss=hwconfig.SD_CS,
|
with SDContext(mosi=hwconfig.SD_DI, miso=hwconfig.SD_DO, sck=hwconfig.SD_SCK, ss=hwconfig.SD_CS,
|
||||||
@@ -96,6 +95,7 @@ def run():
|
|||||||
config=lambda _: config)
|
config=lambda _: config)
|
||||||
the_app = app.PlayerApp(deps)
|
the_app = app.PlayerApp(deps)
|
||||||
|
|
||||||
|
start_webserver(config, the_app)
|
||||||
# Start
|
# Start
|
||||||
asyncio.create_task(aiorepl.task({'timer_manager': TimerManager(),
|
asyncio.create_task(aiorepl.task({'timer_manager': TimerManager(),
|
||||||
'app': the_app}))
|
'app': the_app}))
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ from microdot import Microdot
|
|||||||
webapp = Microdot()
|
webapp = Microdot()
|
||||||
server = None
|
server = None
|
||||||
config = None
|
config = None
|
||||||
|
app = None
|
||||||
|
|
||||||
|
|
||||||
def start_webserver(config_):
|
def start_webserver(config_, app_):
|
||||||
global server, config
|
global server, config, app
|
||||||
server = asyncio.create_task(webapp.start_server(port=80))
|
server = asyncio.create_task(webapp.start_server(port=80))
|
||||||
config = config_
|
config = config_
|
||||||
|
app = app_
|
||||||
|
|
||||||
|
|
||||||
@webapp.route('/')
|
@webapp.route('/')
|
||||||
@@ -50,6 +52,8 @@ async def config_get(request):
|
|||||||
|
|
||||||
@webapp.route('/api/v1/config', methods=['PUT'])
|
@webapp.route('/api/v1/config', methods=['PUT'])
|
||||||
async def config_put(request):
|
async def config_put(request):
|
||||||
|
if app.is_playing():
|
||||||
|
return 503
|
||||||
try:
|
try:
|
||||||
config.set_config(request.json)
|
config.set_config(request.json)
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
|
|||||||
Reference in New Issue
Block a user