This commit is contained in:
Daniel 2024-08-17 21:53:19 -04:00
parent ce3523fbd1
commit 38943343ea
3 changed files with 35 additions and 13 deletions

View file

@ -20,8 +20,8 @@ class Stillbox extends ChangeNotifier {
Filter? currentFilter; Filter? currentFilter;
SBCall? _currentCall; SBCall? _currentCall;
Uri? baseUri = Uri.base; Uri? baseUri = Uri.base;
final StreamController<SBCall> callStream = int queueLen = 0;
StreamController<SBCall>.broadcast(); final StreamController<SBCall> callStream = StreamController<SBCall>();
set state(LiveState newState) { set state(LiveState newState) {
channel.sink.add(Live(state: newState, filter: currentFilter)); channel.sink.add(Live(state: newState, filter: currentFilter));
@ -109,11 +109,16 @@ class Stillbox extends ChangeNotifier {
setUris(); setUris();
} }
void dispatchCall(SBCall call) {
queueLen++;
callStream.add(call);
}
void _handleData(dynamic event) { void _handleData(dynamic event) {
final msg = Message.fromBuffer(event); final msg = Message.fromBuffer(event);
switch (msg.whichToClientMessage()) { switch (msg.whichToClientMessage()) {
case Message_ToClientMessage.call: case Message_ToClientMessage.call:
callStream.add(SBCall( dispatchCall(SBCall(
msg.call, tgCache.getTg(msg.call.system, msg.call.talkgroup))); msg.call, tgCache.getTg(msg.call.system, msg.call.talkgroup)));
case Message_ToClientMessage.notification: case Message_ToClientMessage.notification:
case Message_ToClientMessage.popup: case Message_ToClientMessage.popup:

View file

@ -6,7 +6,8 @@ import '../pb/stillbox.pb.dart';
class LCD extends StatelessWidget { class LCD extends StatelessWidget {
final Color _lcdColor; final Color _lcdColor;
final SBCall? _call; 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -39,12 +40,18 @@ class LCD extends StatelessWidget {
} }
Widget lcdContents() { Widget lcdContents() {
return FutureBuilder( return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FutureBuilder(
future: _call?.tg, future: _call?.tg,
builder: (BuildContext context, AsyncSnapshot<TalkgroupInfo> tgi) { builder:
(BuildContext context, AsyncSnapshot<TalkgroupInfo> tgi) {
return Text( return Text(
'${tgi.data?.name ?? (_call?.call.talkgroup ?? '')}${tgi.data?.learned ?? false ? ' 📓' : ''}'); '${tgi.data?.name ?? (_call?.call.talkgroup ?? '')}${tgi.data?.learned ?? false ? ' 📓' : ''}');
}); }),
Text('Q: $queueLen'),
]);
} }
} }

View file

@ -26,6 +26,7 @@ class _MainRadioState extends State<MainRadio> {
Color _ledColor = Colors.black; Color _ledColor = Colors.black;
Timer? _lcdTimer; Timer? _lcdTimer;
SBCall? _call; SBCall? _call;
Future<bool> completion;
@override @override
void initState() { void initState() {
@ -39,14 +40,22 @@ class _MainRadioState extends State<MainRadio> {
}); });
} }
}); });
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(); lcdOn();
setState(() { setState(() {
_call = call; _call = call;
sb.queueLen--;
}); });
print("bef");
await player.play(call.call); await player.play(call.call);
print("aft");
lcdOff(); lcdOff();
}); } //);
} }
void lcdOn() { void lcdOn() {
@ -88,7 +97,8 @@ class _MainRadioState extends State<MainRadio> {
const ScannerLabel('Stillbox'), const ScannerLabel('Stillbox'),
LED(_ledColor), LED(_ledColor),
]), ]),
LCD(_call, _lcdColor), LCD(_call, _lcdColor,
Provider.of<Stillbox>(context, listen: false).queueLen),
const Keypad(), const Keypad(),
], ],
)), )),