some changes
This commit is contained in:
@@ -42,6 +42,7 @@ class State:
|
||||
scan_stop: int = 10800
|
||||
scan_step: int = 10
|
||||
scan_bw: int = 0
|
||||
last_bw_extend: bool = False
|
||||
|
||||
def init_tef():
|
||||
tef = TEF6686(I2CPCClient(DEVICE, int(os.getenv("BAUD") or 0) or 115200))
|
||||
@@ -91,8 +92,8 @@ def process_command(tef: TEF6686, data: bytes, state: State, conn: socket.socket
|
||||
if cmd.startswith(b"T"):
|
||||
freq = int(cmd.decode().removeprefix("T").strip()) // 10
|
||||
if freq < 6500 or freq > 10800: continue
|
||||
tef.FM_Tune_To(TEF6686.TuneTo_Mode.Preset, freq)
|
||||
time.sleep(0.05)
|
||||
tef.FM_Tune_To(TEF6686.TuneTo_Mode.FM_Jump, freq)
|
||||
time.sleep(0.01)
|
||||
state.last_tune = freq
|
||||
out += f"T{freq*10}\n".encode()
|
||||
elif cmd.startswith(b"G"):
|
||||
@@ -180,7 +181,11 @@ def send_signal_status(tef: TEF6686, conn: socket.socket, state: State):
|
||||
|
||||
res = tef.FM_Get_Quality_Data()
|
||||
if res is None: return
|
||||
_, level, usn, wam, _, bandwidth, *_ = res
|
||||
|
||||
status, level, usn, wam, _, bandwidth, *_ = res
|
||||
|
||||
ms_since_tune = (status & 0x1ff) / 10
|
||||
if ms_since_tune < 33: return # Give only "quality data"
|
||||
|
||||
level = level / 10
|
||||
|
||||
@@ -190,6 +195,13 @@ def send_signal_status(tef: TEF6686, conn: socket.socket, state: State):
|
||||
elif stereo_pilot: data += b"s"
|
||||
else: data += b"m"
|
||||
|
||||
if not state.last_bw_extend and level > 38 and usn < 7:
|
||||
tef.FM_Set_Bandwidth_Options(400)
|
||||
state.last_bw_extend = True
|
||||
if state.last_bw_extend and (level < 33 or usn > 10):
|
||||
tef.FM_Set_Bandwidth_Options()
|
||||
state.last_bw_extend = False
|
||||
|
||||
conn.sendall(data + f"{level + 11.25},{wam//10},{usn//10},{bandwidth}\n\n".encode())
|
||||
|
||||
@periodic(RDS_UPDATE_INTERVAL)
|
||||
@@ -224,6 +236,8 @@ def send_rds_data(tef: TEF6686, conn: socket.socket, state: State):
|
||||
|
||||
def run_server():
|
||||
with init_tef() as tef:
|
||||
state = State()
|
||||
|
||||
device, hw_version, sw_version = d if (d := tef.APPL_Get_Identification()) else (None, None, None)
|
||||
if device and hw_version and sw_version:
|
||||
variant = device & 127
|
||||
@@ -239,8 +253,6 @@ def run_server():
|
||||
|
||||
print(f"{variant_str} (V{hw_major}{hw_minor}{sw_major}.{sw_minor})")
|
||||
else: print("Could not fetch variant")
|
||||
|
||||
state = State()
|
||||
|
||||
with socket.socket() as s:
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
|
||||
Reference in New Issue
Block a user