add logo, do more aggressive batching

This commit is contained in:
Joe Ardent 2023-08-30 10:11:35 -07:00
parent d8ed7acddd
commit be1e6e3f1e
6 changed files with 35 additions and 41 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 544 B

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 442 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 721 B

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -45,6 +45,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
final _barcodeScanner = BarcodeScanner(formats: [BarcodeFormat.qrCode]); final _barcodeScanner = BarcodeScanner(formats: [BarcodeFormat.qrCode]);
// late final AnalysisController _scannerController;
final _rxTextController = BehaviorSubject<String>(); final _rxTextController = BehaviorSubject<String>();
late final Stream<String> _rxTextStream = _rxTextController.stream; late final Stream<String> _rxTextStream = _rxTextController.stream;
@ -53,6 +54,7 @@ class _MyHomePageState extends State<MyHomePage> {
final HashSet<RaptorPacket> _rxData = HashSet(); final HashSet<RaptorPacket> _rxData = HashSet();
String _rxText = ''; String _rxText = '';
int _rxCount = 1; int _rxCount = 1;
int _bSize = 0;
final _formatter = NumberFormat('###,###,###'); final _formatter = NumberFormat('###,###,###');
@ -66,18 +68,19 @@ class _MyHomePageState extends State<MyHomePage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: CameraAwesomeBuilder.previewOnly( body: CameraAwesomeBuilder.previewOnly(
zoom: 1.5,
onImageForAnalysis: (img) => _processImageBarcode(img), onImageForAnalysis: (img) => _processImageBarcode(img),
imageAnalysisConfig: AnalysisConfig( imageAnalysisConfig: AnalysisConfig(
androidOptions: const AndroidAnalysisOptions.nv21( androidOptions: const AndroidAnalysisOptions.nv21(
width: 600, width: 600,
), ),
maxFramesPerSecond: 20, maxFramesPerSecond: 20,
autoStart: false, autoStart: true,
), ),
builder: (cameraModeState, previewSize, previewRect) { builder: (cameraModeState, previewSize, previewRect) {
//_scannerController = cameraModeState.analysisController!;
return _RxTextDisplayWidget( return _RxTextDisplayWidget(
rxTextStream: _rxTextStream, rxTextStream: _rxTextStream,
analysisController: cameraModeState.analysisController!,
); );
}, },
), ),
@ -124,16 +127,28 @@ class _MyHomePageState extends State<MyHomePage> {
case CuttleState.receiving: case CuttleState.receiving:
{ {
if (_bSize > 0 && dbytes.length < _bSize) {
continue;
}
if (_bSize == 0) {
var txconf = await api.getTxConfig(bytes: dbytes); var txconf = await api.getTxConfig(bytes: dbytes);
if (txconf != null) { if (txconf != null) {
await api.dropTxConfig(txc: txconf); await api.dropTxConfig(txc: txconf);
continue; continue;
} }
}
_bSize = dbytes.length;
final packet = RaptorPacket(field0: dbytes); final packet = RaptorPacket(field0: dbytes);
_rxData.add(packet); _rxData.add(packet);
_rxCount += 1; _rxCount += 1;
final bytesTotal = _rxData.length * dbytes.length;
if (_rxCount % 40 == 0) { if (_rxCount % 40 == 0) {
_rxCount = 1; _rxCount = 1;
// if we've not received at least as many bytes as txconf.len,
// we cannot have enough bytes to reconstruct, so only try to
// decode if we've gotten at least that many
if (bytesTotal > _txConfig!.len) {
final content = await api.decodePackets( final content = await api.decodePackets(
packets: _rxData.toList(), txconf: _txConfig!); packets: _rxData.toList(), txconf: _txConfig!);
if (content != null) { if (content != null) {
@ -147,7 +162,7 @@ class _MyHomePageState extends State<MyHomePage> {
continue; continue;
} }
} }
final bytesTotal = _rxData.length * dbytes.length; }
final pct = (100.0 * bytesTotal / _txConfig!.len).floor(); final pct = (100.0 * bytesTotal / _txConfig!.len).floor();
_rxTextController.add( _rxTextController.add(
"$_rxText -- $pct% received (${_formatter.format(bytesTotal)} bytes)"); "$_rxText -- $pct% received (${_formatter.format(bytesTotal)} bytes)");
@ -176,13 +191,10 @@ class _MyHomePageState extends State<MyHomePage> {
class _RxTextDisplayWidget extends StatefulWidget { class _RxTextDisplayWidget extends StatefulWidget {
final Stream<String> rxTextStream; final Stream<String> rxTextStream;
final AnalysisController analysisController;
const _RxTextDisplayWidget({ const _RxTextDisplayWidget({
// ignore: unused_element // ignore: unused_element
super.key, super.key,
required this.rxTextStream, required this.rxTextStream,
required this.analysisController,
}); });
@override @override
@ -199,24 +211,6 @@ class _RxTextDisplayWidgetState extends State<_RxTextDisplayWidget> {
color: Colors.white, color: Colors.white,
), ),
child: Column(mainAxisSize: MainAxisSize.min, children: [ child: Column(mainAxisSize: MainAxisSize.min, children: [
Material(
color: Colors.transparent,
child: CheckboxListTile(
value: widget.analysisController.enabled,
onChanged: (newValue) async {
if (widget.analysisController.enabled == true) {
await widget.analysisController.stop();
} else {
await widget.analysisController.start();
}
setState(() {});
},
title: const Text(
"Enable barcode scan",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
),
Container( Container(
height: 120, height: 120,
padding: const EdgeInsets.symmetric(horizontal: 16), padding: const EdgeInsets.symmetric(horizontal: 16),