mirror of
https://github.com/Death916/deathclock.git
synced 2026-04-10 03:04:40 -07:00
implementing radio
This commit is contained in:
parent
b2320fd073
commit
756f8dfd07
4 changed files with 61 additions and 54 deletions
|
|
@ -1,6 +1,3 @@
|
|||
#!/usr/bin/python3
|
||||
# connect to rda5807 chip and control it and display the current station
|
||||
# TODO: reference rd library in readme
|
||||
import logging
|
||||
|
||||
import reflex as rx
|
||||
|
|
@ -8,40 +5,47 @@ import reflex as rx
|
|||
# from utils.python_rd5807m.radio import Rda5807m as Radio_lib
|
||||
|
||||
DEBUG = True
|
||||
CURRENT_STATION = "90.9 FM"
|
||||
CURRENT_STATION = 90.9
|
||||
PLAYING = False
|
||||
HARDWARE = True
|
||||
|
||||
|
||||
class Radio(rx.Base):
|
||||
class Radio_UI:
|
||||
def __init__(self):
|
||||
if DEBUG:
|
||||
self.device = None
|
||||
else:
|
||||
self.device = Radio_Control()
|
||||
|
||||
def open_radio_button(self):
|
||||
return rx.button("Radio", on_click=self.open_radio_button)
|
||||
|
||||
def radio_card(self):
|
||||
radio_card = rx.popover.root(
|
||||
"""
|
||||
Radio Card
|
||||
Main pop open button for radio control
|
||||
"""
|
||||
|
||||
return rx.popover.root(
|
||||
rx.popover.trigger(rx.button("Radio")),
|
||||
rx.popover.content(
|
||||
rx.vstack(
|
||||
rx.heading("Current Station"),
|
||||
rx.text(CURRENT_STATION),
|
||||
# rx.text("Volume"),
|
||||
# rx.button("Play"
|
||||
# on_click=Radio_Control.play_radio),
|
||||
# ),
|
||||
# rx.button("Pause"),
|
||||
# rx.button("Stop"),
|
||||
# rx.button("Play", on_click=self.device.play_radio),
|
||||
),
|
||||
# rx.button("Pause"),
|
||||
# rx.button("Stop"),
|
||||
),
|
||||
)
|
||||
return radio_card
|
||||
|
||||
|
||||
"""
|
||||
class Radio_Control:
|
||||
|
||||
# Radio Control Class
|
||||
#uses rda5807m library, if debugging populates false values for display
|
||||
|
||||
"""
|
||||
Radio Control Class
|
||||
uses rda5807m library, if debugging populates false values for display
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.debug = DEBUG
|
||||
|
|
@ -51,29 +55,32 @@ class Radio_Control:
|
|||
self.volume = 7
|
||||
self.playing = False
|
||||
self.signal = 0.0
|
||||
self._device = None
|
||||
self._display = None
|
||||
self._device = None
|
||||
|
||||
def init_radio(self):
|
||||
# self._device = Radio_lib(self.bus)
|
||||
self._device.init_chip()
|
||||
# self._device.init_chip()
|
||||
pass
|
||||
|
||||
def play_radio(self):
|
||||
if self.debug:
|
||||
logging.debug("Playing fake radio")
|
||||
self._display = rx.text("Playing") # may not work
|
||||
self._display = rx.text("Playing")
|
||||
self.playing = True
|
||||
else:
|
||||
self._device.on()
|
||||
if self._device:
|
||||
self._device.on()
|
||||
self.playing = True
|
||||
|
||||
def stop_radio(self):
|
||||
if self.debug:
|
||||
logging.debug("Stopping radio")
|
||||
self._display = rx.text("Stopped") # may not work
|
||||
self._display = rx.text("Stopped")
|
||||
self.playing = False
|
||||
else:
|
||||
self._device.off()
|
||||
if self._device:
|
||||
self._device.off()
|
||||
self.playing = False
|
||||
|
||||
def set_volume(self, volume):
|
||||
|
|
@ -81,7 +88,8 @@ class Radio_Control:
|
|||
logging.debug(f"Setting volume to {volume}")
|
||||
self.volume = volume
|
||||
else:
|
||||
self._device.set_volume(volume)
|
||||
if self._device:
|
||||
self._device.set_volume(volume)
|
||||
self.volume = volume
|
||||
|
||||
def set_station(self, station):
|
||||
|
|
@ -89,12 +97,17 @@ class Radio_Control:
|
|||
logging.debug(f"Setting station to {station}")
|
||||
self.current_station = station
|
||||
else:
|
||||
self._device.set_station(station)
|
||||
self.current_station = station
|
||||
logging.info(f"Station set to {station}")
|
||||
"""
|
||||
|
||||
## for testing chip
|
||||
# if __name__ == "__main__":
|
||||
# radio = Radio_Control()
|
||||
# radio.play_radio()
|
||||
def station_change_up(self):
|
||||
if self.debug:
|
||||
pass
|
||||
else:
|
||||
self.current_station += 0.1
|
||||
|
||||
def station_change_down(self):
|
||||
if self.debug:
|
||||
pass
|
||||
else:
|
||||
self.current_station -= 0.1
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# /home/death916/code/python/deathclock/utils/scores.py
|
||||
import logging # Use logging for consistency
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
import reflex as rx
|
||||
import statsapi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue