From 38943343ea30753177d6e6ceb92b1f60420f0f60 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sat, 17 Aug 2024 21:53:19 -0400 Subject: [PATCH] wip --- lib/controller/stillbox.dart | 11 ++++++++--- lib/views/lcd.dart | 21 ++++++++++++++------- lib/views/radio.dart | 16 +++++++++++++--- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/controller/stillbox.dart b/lib/controller/stillbox.dart index 612e5b2..df34b80 100644 --- a/lib/controller/stillbox.dart +++ b/lib/controller/stillbox.dart @@ -20,8 +20,8 @@ class Stillbox extends ChangeNotifier { Filter? currentFilter; SBCall? _currentCall; Uri? baseUri = Uri.base; - final StreamController callStream = - StreamController.broadcast(); + int queueLen = 0; + final StreamController callStream = StreamController(); set state(LiveState newState) { channel.sink.add(Live(state: newState, filter: currentFilter)); @@ -109,11 +109,16 @@ class Stillbox extends ChangeNotifier { setUris(); } + void dispatchCall(SBCall call) { + queueLen++; + callStream.add(call); + } + void _handleData(dynamic event) { final msg = Message.fromBuffer(event); switch (msg.whichToClientMessage()) { case Message_ToClientMessage.call: - callStream.add(SBCall( + dispatchCall(SBCall( msg.call, tgCache.getTg(msg.call.system, msg.call.talkgroup))); case Message_ToClientMessage.notification: case Message_ToClientMessage.popup: diff --git a/lib/views/lcd.dart b/lib/views/lcd.dart index 0767536..3d631f4 100644 --- a/lib/views/lcd.dart +++ b/lib/views/lcd.dart @@ -6,7 +6,8 @@ import '../pb/stillbox.pb.dart'; class LCD extends StatelessWidget { final Color _lcdColor; final SBCall? _call; - const LCD(this._call, this._lcdColor, {super.key}); + final int queueLen; + const LCD(this._call, this._lcdColor, this.queueLen, {super.key}); @override Widget build(BuildContext context) { @@ -39,12 +40,18 @@ class LCD extends StatelessWidget { } Widget lcdContents() { - return FutureBuilder( - future: _call?.tg, - builder: (BuildContext context, AsyncSnapshot tgi) { - return Text( - '${tgi.data?.name ?? (_call?.call.talkgroup ?? '')}${tgi.data?.learned ?? false ? ' 📓' : ''}'); - }); + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + FutureBuilder( + future: _call?.tg, + builder: + (BuildContext context, AsyncSnapshot tgi) { + return Text( + '${tgi.data?.name ?? (_call?.call.talkgroup ?? '')}${tgi.data?.learned ?? false ? ' 📓' : ''}'); + }), + Text('Q: $queueLen'), + ]); } } diff --git a/lib/views/radio.dart b/lib/views/radio.dart index be9cabc..07951d2 100644 --- a/lib/views/radio.dart +++ b/lib/views/radio.dart @@ -26,6 +26,7 @@ class _MainRadioState extends State { Color _ledColor = Colors.black; Timer? _lcdTimer; SBCall? _call; + Future completion; @override void initState() { @@ -39,14 +40,22 @@ class _MainRadioState extends State { }); } }); - sb.callStream.stream.listen((call) async { + _callLoop(sb); + // sb.callStream.stream.listen((call) async { + } + + void _callLoop(Stillbox sb) async { + await for (final call in sb.callStream.stream) { lcdOn(); setState(() { _call = call; + sb.queueLen--; }); + print("bef"); await player.play(call.call); + print("aft"); lcdOff(); - }); + } //); } void lcdOn() { @@ -88,7 +97,8 @@ class _MainRadioState extends State { const ScannerLabel('Stillbox'), LED(_ledColor), ]), - LCD(_call, _lcdColor), + LCD(_call, _lcdColor, + Provider.of(context, listen: false).queueLen), const Keypad(), ], )),