avaibility, compass big box

This commit is contained in:
jusax23 2023-09-21 16:05:34 +02:00
parent 0ce9f9c1a1
commit 1a714bcdeb
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
3 changed files with 284 additions and 192 deletions

View file

@ -27,35 +27,50 @@ base class GnssLocData extends Struct {
// end c-structs // end c-structs
class Compass extends JuBox { class Compass extends JuBox {
const Compass({super.key}); final bool small;
const Compass(this.small, {super.key});
@override @override
State<StatefulWidget> createState() => _CompassState(); // ignore: no_logic_in_create_state
State<StatefulWidget> createState() => _CompassState(small);
} }
class _CompassState extends State<Compass> { class _CompassState extends State<Compass> {
final bool small;
_CompassState(this.small) : super();
USerial serial = getSerial(); USerial serial = getSerial();
late Timer timer; Timer? timer;
int _magX = 0, _magY = 0, _magZ = 0, _magAngle = 0; int _magX = 0, _magY = 0, _magZ = 0, _magAngle = 0;
bool available = true;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
SensorReader.listen(serialListen); SensorReader.listen(serialListen);
if (small) {
timer = Timer.periodic(const Duration(milliseconds: 500), (_) async { timer = Timer.periodic(const Duration(milliseconds: 500), (_) async {
serial.sprintln("<rfSystemSensor>2200", system: true); if (available) serial.sprintln("<rfSystemSensor>2200", system: true);
}); });
} }
}
@override @override
void dispose() { void dispose() {
SensorReader.removeListen(serialListen); SensorReader.removeListen(serialListen);
timer.cancel(); timer?.cancel();
super.dispose(); super.dispose();
} }
void serialListen(int type, int command, Pointer<ArrayCStruct> ptr) { void serialListen(int type, int command, Pointer<ArrayCStruct> ptr) {
if (type == 0x22 && command == 0xff) {
setState(() {
available = false;
});
return;
}
if (type != 0x22 || command != 0x00) return; if (type != 0x22 || command != 0x00) return;
var loc = ptr as Pointer<GnssLocData>; var loc = ptr as Pointer<GnssLocData>;
setState(() { setState(() {
@ -70,14 +85,50 @@ class _CompassState extends State<Compass> {
} }
@override @override
Widget build(BuildContext context) => Stack( Widget build(BuildContext context) => small
? GestureDetector(
onTap: () {
if (available) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const Compass(false)),
);
} else {
available = true;
}
},
child: buildLoc(context))
: Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text(
"Compass",
style: TextStyle(
fontSize: 16,
),
),
toolbarHeight: 40,
),
body: Container(
padding: const EdgeInsets.all(0.3 * 2 * 20),
child: buildLoc(context)),
);
Widget buildLoc(BuildContext context) => !available
? const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [Text("Compass is not available!"), Icon(Icons.block)]))
: Stack(
children: [ children: [
SvgPicture.asset('assets/compass.svg'), Center(child: SvgPicture.asset('assets/compass.svg')),
AnimatedRotation( Center(
child: AnimatedRotation(
turns: _magAngle / 360.0, turns: _magAngle / 360.0,
duration: const Duration(milliseconds: 500), duration: const Duration(milliseconds: 500),
alignment: Alignment.center, // Rotate around the center alignment: Alignment.center, // Rotate around the center
child: SvgPicture.asset('assets/needle.svg')), child: SvgPicture.asset('assets/needle.svg'))),
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@ -87,6 +138,7 @@ class _CompassState extends State<Compass> {
"y: ${(_magY * 8.0 / 32768.0 * 100.0).toStringAsFixed(2)}µT"), "y: ${(_magY * 8.0 / 32768.0 * 100.0).toStringAsFixed(2)}µT"),
Text( Text(
"z: ${(_magZ * 8.0 / 32768.0 * 100.0).toStringAsFixed(2)}µT"), "z: ${(_magZ * 8.0 / 32768.0 * 100.0).toStringAsFixed(2)}µT"),
if (!small)
Expanded( Expanded(
child: Align( child: Align(
alignment: Alignment.bottomLeft, alignment: Alignment.bottomLeft,
@ -101,7 +153,8 @@ class _CompassState extends State<Compass> {
'When clicking okay the compass will be calibrated, \ncompletely blocking all radio communication for 10 sec. \nWhile calibrating rotate the sensor in ever direction.'), 'When clicking okay the compass will be calibrated, \ncompletely blocking all radio communication for 10 sec. \nWhile calibrating rotate the sensor in ever direction.'),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
onPressed: () => Navigator.pop(context, 'Cancel'), onPressed: () =>
Navigator.pop(context, 'Cancel'),
child: const Text('Cancel'), child: const Text('Cancel'),
), ),
TextButton( TextButton(
@ -122,12 +175,11 @@ class _CompassState extends State<Compass> {
), ),
], ],
), ),
Expanded( Align(
child: Align(
alignment: Alignment.topRight, alignment: Alignment.topRight,
child: Text( child: Text(
"t: ${(sqrt(_magX * _magX + _magY * _magY + _magZ * _magZ) * 8.0 / 32768.0 * 100.0).toStringAsFixed(2)}µT"), "t: ${(sqrt(_magX * _magX + _magY * _magY + _magZ * _magZ) * 8.0 / 32768.0 * 100.0).toStringAsFixed(2)}µT"),
)) )
], ],
); );
} }

View file

@ -108,13 +108,14 @@ class _MapsState extends State<Maps> with TickerProviderStateMixin {
int _state = 0; int _state = 0;
bool _wasVaild = false; bool _wasVaild = false;
final _mapController = MapController(); final _mapController = MapController();
bool available = true;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
SensorReader.listen(serialListen); SensorReader.listen(serialListen);
timer = Timer.periodic(const Duration(seconds: 1), (_) async { timer = Timer.periodic(const Duration(seconds: 1), (_) async {
serial.sprintln("<rfSystemSensor>2300", system: true); if (available) serial.sprintln("<rfSystemSensor>2300", system: true);
}); });
} }
@ -126,6 +127,12 @@ class _MapsState extends State<Maps> with TickerProviderStateMixin {
} }
void serialListen(int type, int command, Pointer<ArrayCStruct> ptr) { void serialListen(int type, int command, Pointer<ArrayCStruct> ptr) {
if (type == 0x23 && command == 0xff) {
setState(() {
available = false;
});
return;
}
if (type != 0x23 || command != 0x00) return; if (type != 0x23 || command != 0x00) return;
var loc = ptr as Pointer<GnssLocData>; var loc = ptr as Pointer<GnssLocData>;
setState(() { setState(() {
@ -140,7 +147,22 @@ class _MapsState extends State<Maps> with TickerProviderStateMixin {
} }
@override @override
Widget build(BuildContext context) => FlutterMap( Widget build(BuildContext context) => !available
? GestureDetector(
onTap: () {
if (!available) {
available = true;
}
},
child: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text("GNSS is not available!"),
Icon(Icons.block)
])))
: FlutterMap(
options: MapOptions( options: MapOptions(
center: LatLng(_lat, _long), center: LatLng(_lat, _long),
zoom: _wasVaild ? 17 : 6, zoom: _wasVaild ? 17 : 6,
@ -206,11 +228,13 @@ class _SerialDetailPageState extends State<SerialDetailPage>
_hdopState = false; _hdopState = false;
int _satN = -1; int _satN = -1;
bool _follow = true; bool _follow = true;
bool available = true;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
timer = Timer.periodic(const Duration(seconds: 2), (_) async { timer = Timer.periodic(const Duration(seconds: 2), (_) async {
if(!available) return;
serial.sprintln("<rfSystemSensor>2303", system: true); serial.sprintln("<rfSystemSensor>2303", system: true);
sleep(const Duration(milliseconds: 200)); sleep(const Duration(milliseconds: 200));
serial.sprintln("<rfSystemSensor>2304", system: true); serial.sprintln("<rfSystemSensor>2304", system: true);
@ -233,6 +257,7 @@ class _SerialDetailPageState extends State<SerialDetailPage>
void serialListen(int type, int command, Pointer<ArrayCStruct> ptr) { void serialListen(int type, int command, Pointer<ArrayCStruct> ptr) {
if (type != 0x23) return; if (type != 0x23) return;
command = 0xff;
switch (command) { switch (command) {
case 0: case 0:
{ {
@ -295,7 +320,11 @@ class _SerialDetailPageState extends State<SerialDetailPage>
} }
break; break;
case 0xff: case 0xff:
{} {
setState(() {
available = false;
});
}
break; break;
} }
} }
@ -327,15 +356,25 @@ class _SerialDetailPageState extends State<SerialDetailPage>
}, },
child: Icon(_follow ? Icons.near_me : Icons.near_me_outlined), child: Icon(_follow ? Icons.near_me : Icons.near_me_outlined),
), ),
body: Column(children: [ body: !available
? const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text("GNSS is not available!"),
Icon(Icons.block)
]))
: Column(children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text( Text(
"Speed: ${_mps.toStringAsPrecision(3)}m/s", "Speed: ${_mps.toStringAsPrecision(3)}m/s",
style: TextStyle( style: TextStyle(
backgroundColor: backgroundColor: _mpsState
_mpsState ? Colors.green[shade()] : Colors.red[shade()]), ? Colors.green[shade()]
: Colors.red[shade()]),
), ),
const VerticalDivider(width: 5), const VerticalDivider(width: 5),
Text("Course: ${_course.toStringAsFixed(0)}°", Text("Course: ${_course.toStringAsFixed(0)}°",
@ -384,7 +423,8 @@ class _SerialDetailPageState extends State<SerialDetailPage>
}), }),
children: [ children: [
TileLayer( TileLayer(
urlTemplate: 'https://tile.openstreetmap.de/{z}/{x}/{y}.png', urlTemplate:
'https://tile.openstreetmap.de/{z}/{x}/{y}.png',
//urlTemplate: 'https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/GLOBAL_WEBMERCATOR/{z}/{y}/{x}.png', //urlTemplate: 'https://sgx.geodatenzentrum.de/wmts_basemapde/tile/1.0.0/de_basemapde_web_raster_farbe/default/GLOBAL_WEBMERCATOR/{z}/{y}/{x}.png',
userAgentPackageName: 'de.jusax.ju_rc_app', userAgentPackageName: 'de.jusax.ju_rc_app',
), ),

View file

@ -49,8 +49,8 @@ class _MyHomePageState extends State<MyHomePage> {
static List<JuBox> boxes = [ static List<JuBox> boxes = [
const ControllerState(), const ControllerState(),
const Compass(true),
const Maps(), const Maps(),
const Compass(),
const SerialBox(), const SerialBox(),
]; ];