diff --git a/software/src/app.py b/software/src/app.py index 15f486c..cbe8503 100644 --- a/software/src/app.py +++ b/software/src/app.py @@ -58,6 +58,7 @@ class PlayerApp: self.mp3file = None self.volume_pos = 3 self.paused = False + self.playing = False self.player.set_volume(VOLUME_CURVE[self.volume_pos]) self._onIdle() @@ -115,6 +116,9 @@ class PlayerApp: # Check again in a minute 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): if self.playlist is not None: pos = self.player.stop() @@ -176,7 +180,9 @@ class PlayerApp: def _onIdle(self): self.timer_manager.schedule(time.ticks_ms() + self.idle_timeout_ms, self.onIdleTimeout) self.leds.set_state(self.leds.IDLE) + self.playing = False def _onActive(self): self.timer_manager.cancel(self.onIdleTimeout) self.leds.set_state(self.leds.PLAYING) + self.playing = True diff --git a/software/src/main.py b/software/src/main.py index 62282ad..768ead1 100644 --- a/software/src/main.py +++ b/software/src/main.py @@ -65,7 +65,6 @@ def run(): # Wifi with default config setup_wifi() - start_webserver(config) # Setup MP3 player 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) the_app = app.PlayerApp(deps) + start_webserver(config, the_app) # Start asyncio.create_task(aiorepl.task({'timer_manager': TimerManager(), 'app': the_app})) diff --git a/software/src/webserver.py b/software/src/webserver.py index 6f1aaf6..95cacc5 100644 --- a/software/src/webserver.py +++ b/software/src/webserver.py @@ -10,12 +10,14 @@ from microdot import Microdot webapp = Microdot() server = None config = None +app = None -def start_webserver(config_): - global server, config +def start_webserver(config_, app_): + global server, config, app server = asyncio.create_task(webapp.start_server(port=80)) config = config_ + app = app_ @webapp.route('/') @@ -50,6 +52,8 @@ async def config_get(request): @webapp.route('/api/v1/config', methods=['PUT']) async def config_put(request): + if app.is_playing(): + return 503 try: config.set_config(request.json) except ValueError as ex: