avaibility, compass big box
This commit is contained in:
parent
0ce9f9c1a1
commit
1a714bcdeb
3 changed files with 284 additions and 192 deletions
|
@ -27,35 +27,50 @@ base class GnssLocData extends Struct {
|
|||
// end c-structs
|
||||
|
||||
class Compass extends JuBox {
|
||||
const Compass({super.key});
|
||||
final bool small;
|
||||
const Compass(this.small, {super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CompassState();
|
||||
// ignore: no_logic_in_create_state
|
||||
State<StatefulWidget> createState() => _CompassState(small);
|
||||
}
|
||||
|
||||
class _CompassState extends State<Compass> {
|
||||
final bool small;
|
||||
|
||||
_CompassState(this.small) : super();
|
||||
|
||||
USerial serial = getSerial();
|
||||
late Timer timer;
|
||||
Timer? timer;
|
||||
|
||||
int _magX = 0, _magY = 0, _magZ = 0, _magAngle = 0;
|
||||
bool available = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
SensorReader.listen(serialListen);
|
||||
if (small) {
|
||||
timer = Timer.periodic(const Duration(milliseconds: 500), (_) async {
|
||||
serial.sprintln("<rfSystemSensor>2200", system: true);
|
||||
if (available) serial.sprintln("<rfSystemSensor>2200", system: true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
SensorReader.removeListen(serialListen);
|
||||
timer.cancel();
|
||||
timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void serialListen(int type, int command, Pointer<ArrayCStruct> ptr) {
|
||||
if (type == 0x22 && command == 0xff) {
|
||||
setState(() {
|
||||
available = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (type != 0x22 || command != 0x00) return;
|
||||
var loc = ptr as Pointer<GnssLocData>;
|
||||
setState(() {
|
||||
|
@ -70,14 +85,50 @@ class _CompassState extends State<Compass> {
|
|||
}
|
||||
|
||||
@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: [
|
||||
SvgPicture.asset('assets/compass.svg'),
|
||||
AnimatedRotation(
|
||||
Center(child: SvgPicture.asset('assets/compass.svg')),
|
||||
Center(
|
||||
child: AnimatedRotation(
|
||||
turns: _magAngle / 360.0,
|
||||
duration: const Duration(milliseconds: 500),
|
||||
alignment: Alignment.center, // Rotate around the center
|
||||
child: SvgPicture.asset('assets/needle.svg')),
|
||||
child: SvgPicture.asset('assets/needle.svg'))),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
@ -87,6 +138,7 @@ class _CompassState extends State<Compass> {
|
|||
"y: ${(_magY * 8.0 / 32768.0 * 100.0).toStringAsFixed(2)}µT"),
|
||||
Text(
|
||||
"z: ${(_magZ * 8.0 / 32768.0 * 100.0).toStringAsFixed(2)}µT"),
|
||||
if (!small)
|
||||
Expanded(
|
||||
child: Align(
|
||||
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.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, 'Cancel'),
|
||||
onPressed: () =>
|
||||
Navigator.pop(context, 'Cancel'),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
|
@ -122,12 +175,11 @@ class _CompassState extends State<Compass> {
|
|||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: Align(
|
||||
Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: Text(
|
||||
"t: ${(sqrt(_magX * _magX + _magY * _magY + _magZ * _magZ) * 8.0 / 32768.0 * 100.0).toStringAsFixed(2)}µT"),
|
||||
))
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -108,13 +108,14 @@ class _MapsState extends State<Maps> with TickerProviderStateMixin {
|
|||
int _state = 0;
|
||||
bool _wasVaild = false;
|
||||
final _mapController = MapController();
|
||||
bool available = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
SensorReader.listen(serialListen);
|
||||
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) {
|
||||
if (type == 0x23 && command == 0xff) {
|
||||
setState(() {
|
||||
available = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (type != 0x23 || command != 0x00) return;
|
||||
var loc = ptr as Pointer<GnssLocData>;
|
||||
setState(() {
|
||||
|
@ -140,7 +147,22 @@ class _MapsState extends State<Maps> with TickerProviderStateMixin {
|
|||
}
|
||||
|
||||
@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(
|
||||
center: LatLng(_lat, _long),
|
||||
zoom: _wasVaild ? 17 : 6,
|
||||
|
@ -206,11 +228,13 @@ class _SerialDetailPageState extends State<SerialDetailPage>
|
|||
_hdopState = false;
|
||||
int _satN = -1;
|
||||
bool _follow = true;
|
||||
bool available = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
timer = Timer.periodic(const Duration(seconds: 2), (_) async {
|
||||
if(!available) return;
|
||||
serial.sprintln("<rfSystemSensor>2303", system: true);
|
||||
sleep(const Duration(milliseconds: 200));
|
||||
serial.sprintln("<rfSystemSensor>2304", system: true);
|
||||
|
@ -233,6 +257,7 @@ class _SerialDetailPageState extends State<SerialDetailPage>
|
|||
|
||||
void serialListen(int type, int command, Pointer<ArrayCStruct> ptr) {
|
||||
if (type != 0x23) return;
|
||||
command = 0xff;
|
||||
switch (command) {
|
||||
case 0:
|
||||
{
|
||||
|
@ -295,7 +320,11 @@ class _SerialDetailPageState extends State<SerialDetailPage>
|
|||
}
|
||||
break;
|
||||
case 0xff:
|
||||
{}
|
||||
{
|
||||
setState(() {
|
||||
available = false;
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -327,15 +356,25 @@ class _SerialDetailPageState extends State<SerialDetailPage>
|
|||
},
|
||||
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(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"Speed: ${_mps.toStringAsPrecision(3)}m/s",
|
||||
style: TextStyle(
|
||||
backgroundColor:
|
||||
_mpsState ? Colors.green[shade()] : Colors.red[shade()]),
|
||||
backgroundColor: _mpsState
|
||||
? Colors.green[shade()]
|
||||
: Colors.red[shade()]),
|
||||
),
|
||||
const VerticalDivider(width: 5),
|
||||
Text("Course: ${_course.toStringAsFixed(0)}°",
|
||||
|
@ -384,7 +423,8 @@ class _SerialDetailPageState extends State<SerialDetailPage>
|
|||
}),
|
||||
children: [
|
||||
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',
|
||||
userAgentPackageName: 'de.jusax.ju_rc_app',
|
||||
),
|
||||
|
|
|
@ -49,8 +49,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
|
||||
static List<JuBox> boxes = [
|
||||
const ControllerState(),
|
||||
const Compass(true),
|
||||
const Maps(),
|
||||
const Compass(),
|
||||
const SerialBox(),
|
||||
];
|
||||
|
||||
|
|
Loading…
Reference in a new issue