diff --git a/lib/main_screen.dart b/lib/main_screen.dart index 446a2e5..114a810 100644 --- a/lib/main_screen.dart +++ b/lib/main_screen.dart @@ -66,20 +66,40 @@ class _MainScreenState extends State { @override Widget build(BuildContext context) { + print("connected: ${serialHandler.isConnected}"); return Scaffold( backgroundColor: Colors.black, - floatingActionButton: MaterialButton( - child: const Text( - "choose serial port", - style: TextStyle(color: Colors.amberAccent), - ), - onPressed: () { - serialHandler.chooseSerialDevice(); - }, - ), - body: PicoScreen( - _grid, - _grid.background, + body: Stack( + children: [ + PicoScreen( + _grid, + _grid.background, + ), + Visibility( + visible: !serialHandler.isConnected(), + child: Positioned( + left: MediaQuery.of(context).size.width / 4, + top: MediaQuery.of(context).size.height / 4, + child: MaterialButton( + color: const Color.fromARGB(255, 35, 13, 73), + child: const Padding( + padding: EdgeInsets.all(38.0), + child: Text( + "Connect", + style: TextStyle( + color: Colors.amberAccent, + fontSize: 50, + ), + ), + ), + onPressed: () { + serialHandler.chooseSerialDevice(); + setState(() {}); + }, + ), + ), + ), + ], )); } } diff --git a/lib/serialport_none.dart b/lib/serialport_none.dart index cd2d8a5..60619dd 100644 --- a/lib/serialport_none.dart +++ b/lib/serialport_none.dart @@ -4,4 +4,6 @@ class SerialPortHandler { SerialPortHandler(CmdBuilder cmdBuilder); void chooseSerialDevice() async {} + + bool isConnected() => false; } diff --git a/lib/serialport_web.dart b/lib/serialport_web.dart index f6100e0..f773816 100644 --- a/lib/serialport_web.dart +++ b/lib/serialport_web.dart @@ -6,13 +6,20 @@ import 'command_builder.dart'; class SerialPortHandler { final CmdBuilder cmdBuilder; + JSSerialPort? port; SerialPortHandler(this.cmdBuilder); + bool isConnected() => port?.connected.toDart ?? false; + void chooseSerialDevice() async { - late final JSSerialPort? port; try { - port = await requestWebSerialPort(); + // Create filter options for specific vendor ID + final filters = [ + JSFilterObject(usbVendorId: 0xcafe, usbProductId: 0x4009) + ]; + + port = await requestWebSerialPort(filters.toJS); debugPrint("got serial port: $port"); } catch (e) { debugPrint(e.toString()); @@ -42,11 +49,11 @@ class SerialPortHandler { final reader = port?.readable?.getReader() as ReadableStreamDefaultReader; if (port != null) { - debugPrint("port opened: ${port.readable}"); + debugPrint("port opened: ${port?.readable}"); // request full screen refresh after opening final request = Uint8List.fromList([REMOTE_COMMAND_MARKER, 0x02]); final JSUint8Array jsReq = request.toJS; - final writer = port.writable?.getWriter(); + final writer = port?.writable?.getWriter(); writer?.write(jsReq); // Allow the serial port to be closed later. writer?.releaseLock(); diff --git a/lib/widgets/pico_screen.dart b/lib/widgets/pico_screen.dart index 98140c7..056b45d 100644 --- a/lib/widgets/pico_screen.dart +++ b/lib/widgets/pico_screen.dart @@ -18,35 +18,37 @@ class PicoScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return Container( - height: 754, - width: 904, - decoration: const BoxDecoration( - image: DecorationImage( - image: AssetImage( - 'assets/images/bezel-brd-2.png', - ), + return Column( + children: [ + Padding( + padding: const EdgeInsets.all(4.0), + child: Text("picoTracker", + style: Theme.of(context).textTheme.headlineLarge), ), - ), - child: Padding( - padding: - const EdgeInsets.only(top: 100, bottom: 98, left: 60, right: 75), - child: Container( - height: 320 * 2, - width: 240 * 2, - color: Colors.black, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: grid - .getRows() - .map((row) => ScreenCharRow( - row, - grid, - )) - .toList(), + SizedBox( + height: 754, + width: 904, + child: Padding( + padding: const EdgeInsets.only( + top: 100, bottom: 98, left: 60, right: 75), + child: Container( + height: 320 * 2, + width: 240 * 2, + color: Colors.black, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: grid + .getRows() + .map((row) => ScreenCharRow( + row, + grid, + )) + .toList(), + ), + ), ), ), - ), + ], ); } } diff --git a/pubspec.lock b/pubspec.lock index 168a35f..2708196 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -268,10 +268,10 @@ packages: dependency: "direct main" description: name: webserial - sha256: "45f464246ea90f6f6edf07c30ca69f719ad83d9b4e48ee27120fda7824d5cb83" + sha256: "5845d455033153939b12307bb1e33b676bd2f01faf57e436f70a5df7a091081c" url: "https://pub.dev" source: hosted - version: "1.0.0+1" + version: "1.1.0" sdks: dart: ">=3.5.1 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index e00eda6..5556f1d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: flutter: sdk: flutter flutter_libserialport: ^0.4.0 - webserial: ^1.0.0 + webserial: ^1.1.0 udev: ^0.0.3 dev_dependencies: diff --git a/web/favicon.png b/web/favicon.png index 8aaa46a..fde4199 100644 Binary files a/web/favicon.png and b/web/favicon.png differ diff --git a/web/icons/Icon-192.png b/web/icons/Icon-192.png index b749bfe..99ec835 100644 Binary files a/web/icons/Icon-192.png and b/web/icons/Icon-192.png differ diff --git a/web/icons/Icon-512.png b/web/icons/Icon-512.png index 88cfd48..fa35304 100644 Binary files a/web/icons/Icon-512.png and b/web/icons/Icon-512.png differ diff --git a/web/icons/Icon-maskable-192.png b/web/icons/Icon-maskable-192.png deleted file mode 100644 index eb9b4d7..0000000 Binary files a/web/icons/Icon-maskable-192.png and /dev/null differ diff --git a/web/icons/Icon-maskable-512.png b/web/icons/Icon-maskable-512.png deleted file mode 100644 index d69c566..0000000 Binary files a/web/icons/Icon-maskable-512.png and /dev/null differ