地区选择和罗盘十字
This commit is contained in:
@ -1,13 +1,17 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:fengshui_compass/components/cross_paint.dart';
|
||||
import 'package:fengshui_compass/components/my_icon.dart';
|
||||
import 'package:fengshui_compass/pages/login_page.dart';
|
||||
import 'package:fengshui_compass/states/region.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_serial_port_api/flutter_serial_port_api.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:stream_transform/stream_transform.dart';
|
||||
|
||||
import '../components/region_selector.dart';
|
||||
import '../utils/recv_parse.dart';
|
||||
|
||||
class CompassPage extends StatefulWidget {
|
||||
@ -30,6 +34,7 @@ class _CompassState extends State<CompassPage> {
|
||||
|
||||
double w_x = 0.5;
|
||||
double w_y = 0.5;
|
||||
|
||||
// 与磁北极夹角
|
||||
double myaw = 0.0;
|
||||
|
||||
@ -39,9 +44,11 @@ class _CompassState extends State<CompassPage> {
|
||||
var listb = [];
|
||||
var listc = [];
|
||||
|
||||
void initDevice() {
|
||||
// 省市名称,用于获取磁偏角
|
||||
String proviceName = '';
|
||||
String cityName = '';
|
||||
|
||||
}
|
||||
void initDevice() {}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -152,9 +159,7 @@ class _CompassState extends State<CompassPage> {
|
||||
|
||||
loginAction() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => LoginPage()));
|
||||
context, MaterialPageRoute(builder: (context) => LoginPage()));
|
||||
}
|
||||
|
||||
parsingRecvCom(str) {
|
||||
@ -172,41 +177,39 @@ class _CompassState extends State<CompassPage> {
|
||||
// var mx_l = hexToInt(str.substring(pos+10, pos+12));
|
||||
// var my_h = hexToInt(str.substring(pos+12, pos+14));
|
||||
|
||||
var myaw_flag = hexToInt(str.substring(pos+14, pos+16));
|
||||
var myaw_h = hexToInt(str.substring(pos+16, pos+18));
|
||||
var myaw_l = hexToInt(str.substring(pos+18, pos+20));
|
||||
var myaw_flag = hexToInt(str.substring(pos + 14, pos + 16));
|
||||
var myaw_h = hexToInt(str.substring(pos + 16, pos + 18));
|
||||
var myaw_l = hexToInt(str.substring(pos + 18, pos + 20));
|
||||
|
||||
var roll_tmp = (roll_h * 256 + roll_l) * 180 /32768;
|
||||
var pitch_tmp = (pitch_h * 256 + pitch_l) * 180 /32768;
|
||||
var roll_tmp = (roll_h * 256 + roll_l) * 180 / 32768;
|
||||
var pitch_tmp = (pitch_h * 256 + pitch_l) * 180 / 32768;
|
||||
// var yaw = (yaw_h * 256 + yaw_l) * 180 /32768;
|
||||
|
||||
// -180~180
|
||||
var ff = myaw_flag == 1 ? -1 : 1;
|
||||
var temp_myaw = (myaw_h *256 + myaw_l) * 0.01 * ff + 180;
|
||||
|
||||
if (roll_tmp>180) roll_tmp = roll_tmp -360;
|
||||
if (pitch_tmp>180) pitch_tmp = pitch_tmp -360;
|
||||
|
||||
var temp_myaw = (myaw_h * 256 + myaw_l) * 0.01 * ff + 180;
|
||||
|
||||
if (roll_tmp > 180) roll_tmp = roll_tmp - 360;
|
||||
if (pitch_tmp > 180) pitch_tmp = pitch_tmp - 360;
|
||||
|
||||
var w_x_tmp = 0.0;
|
||||
var w_y_tmp = 0.0;
|
||||
|
||||
// 倾角<30度
|
||||
var w_total = sqrt(roll_tmp.abs()*roll_tmp.abs() + pitch_tmp.abs()*pitch_tmp.abs());
|
||||
var w_total = sqrt(
|
||||
roll_tmp.abs() * roll_tmp.abs() + pitch_tmp.abs() * pitch_tmp.abs());
|
||||
|
||||
if (w_total <= 30) {
|
||||
w_y_tmp = 0.5 - 0.07 * roll_tmp / 30.0;
|
||||
w_x_tmp = 0.5 - 0.07 * pitch_tmp / 30.0;
|
||||
} else if (w_total > 30) {
|
||||
//todo
|
||||
w_y_tmp = 0.5 - 0.07 * w_total /30.0;
|
||||
w_y_tmp = 0.5 - 0.07 * w_total / 30.0;
|
||||
w_x_tmp = 0.5 - 0.07 * w_total / 30.0;
|
||||
}
|
||||
|
||||
// todo 其他情况
|
||||
|
||||
|
||||
var meanValue;
|
||||
|
||||
if (lista.length < 20) {
|
||||
@ -215,10 +218,8 @@ class _CompassState extends State<CompassPage> {
|
||||
} else {
|
||||
lista.removeAt(0);
|
||||
lista.add(temp_myaw);
|
||||
meanValue = lista.map((e) => e).reduce((a, b) => a+b) / lista.length;
|
||||
meanValue = lista.map((e) => e).reduce((a, b) => a + b) / lista.length;
|
||||
}
|
||||
|
||||
|
||||
|
||||
setState(() {
|
||||
// print("roll: $roll_tmp pitch: $pitch_tmp");
|
||||
@ -235,7 +236,6 @@ class _CompassState extends State<CompassPage> {
|
||||
|
||||
// 水平仪 0.5+-0.07范围
|
||||
// x旋转y在动 y旋转x在动 roll改变y坐标,pitch改变x坐标
|
||||
|
||||
});
|
||||
} else if (str.contains("9E010401") &&
|
||||
(str.length >= ((str.indexOf("9E010401") + 26)))) {
|
||||
@ -251,180 +251,230 @@ class _CompassState extends State<CompassPage> {
|
||||
} else {}
|
||||
}
|
||||
|
||||
// 拼接城市
|
||||
String spliceCityName(String pname, String cname) {
|
||||
if (pname == '') return '未选择城市';
|
||||
StringBuffer sb = StringBuffer();
|
||||
sb.write(pname);
|
||||
if (cname == '') return sb.toString();
|
||||
sb.write(' - ');
|
||||
sb.write(cname);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// bool strEmpty(String? value) {
|
||||
// if (value == null) return true;
|
||||
// return value.trim().isEmpty;
|
||||
// }
|
||||
|
||||
selectRegion() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('选择城市校准磁偏角'),
|
||||
content: RegionSelector(),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Provider.of<RegionProvider>(context, listen: false)
|
||||
.saveRegion();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('保存'))
|
||||
],
|
||||
);
|
||||
}).then((value) {
|
||||
Provider.of<RegionProvider>(context, listen: false).resetTemp();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage("assets/images/bg.png"), fit: BoxFit.cover)),
|
||||
child: Scaffold(
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage("assets/images/bg.png"), fit: BoxFit.cover)),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
title: const Text(
|
||||
'定盘星',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
leading: IconButton(
|
||||
color: Colors.amber,
|
||||
icon: Icon(isLock ? MyIcons.icon_mima : MyIcons.icon_jiesuo),
|
||||
onPressed: switchCompass,
|
||||
),
|
||||
actions: [
|
||||
//todo
|
||||
// 更改背景图
|
||||
IconButton(
|
||||
color: Colors.amber,
|
||||
icon: Icon(Icons.person, size: 22,),
|
||||
onPressed: loginAction,
|
||||
),
|
||||
],
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
title: const Text(
|
||||
'定盘星',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
body: SafeArea(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 600),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
// 罗盘
|
||||
Column(
|
||||
children: [
|
||||
const Padding(padding: EdgeInsets.only(top: 145)),
|
||||
Row(
|
||||
children: [
|
||||
Spacer(flex: 1),
|
||||
Container(
|
||||
width: 700,
|
||||
height: 700,
|
||||
child: Stack(
|
||||
children: [
|
||||
Transform.rotate(
|
||||
angle: myaw * pi /360,
|
||||
child: const Image(
|
||||
image:
|
||||
AssetImage("assets/images/compass.png"),
|
||||
fit: BoxFit.fill),
|
||||
leading: IconButton(
|
||||
color: Colors.amber,
|
||||
icon: Icon(isLock ? MyIcons.icon_mima : MyIcons.icon_jiesuo),
|
||||
onPressed: switchCompass,
|
||||
),
|
||||
actions: [
|
||||
//todo
|
||||
// 更改背景图
|
||||
IconButton(
|
||||
color: Colors.amber,
|
||||
icon: const Icon(
|
||||
Icons.person,
|
||||
size: 22,
|
||||
),
|
||||
onPressed: loginAction,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 600),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
// 罗盘
|
||||
Column(
|
||||
children: [
|
||||
const Padding(padding: EdgeInsets.only(top: 145)),
|
||||
Row(
|
||||
children: [
|
||||
Spacer(flex: 1),
|
||||
Container(
|
||||
width: 700,
|
||||
height: 700,
|
||||
child: Stack(
|
||||
children: [
|
||||
Transform.rotate(
|
||||
angle: myaw * pi / 360,
|
||||
child: const Image(
|
||||
image:
|
||||
AssetImage("assets/images/compass.png"),
|
||||
fit: BoxFit.fill),
|
||||
),
|
||||
Align(
|
||||
alignment: FractionalOffset(w_x, w_y),
|
||||
child: const Image(
|
||||
image: AssetImage("assets/images/water.png"),
|
||||
),
|
||||
Align(
|
||||
alignment: FractionalOffset(w_x, w_y),
|
||||
child: const Image(
|
||||
image: AssetImage("assets/images/water.png"),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(flex: 1),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
// 最上面一行, lock azimuth login
|
||||
Positioned(
|
||||
top: 5,
|
||||
child: Column(
|
||||
children: [
|
||||
const Image(
|
||||
width: 15,
|
||||
height: 15,
|
||||
image: AssetImage("assets/images/arrow.png"),
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
Text(
|
||||
// "${azimuth.toStringAsFixed(2)}",
|
||||
myaw.toStringAsFixed(2),
|
||||
style: const TextStyle(
|
||||
color: Colors.amber, fontSize: 36),
|
||||
),
|
||||
],
|
||||
)),
|
||||
// 最下面一行,ranging value openlaser
|
||||
Positioned(
|
||||
bottom: 80,
|
||||
left: 50,
|
||||
child: IconButton(
|
||||
onPressed: raging,
|
||||
icon: const Icon(
|
||||
MyIcons.icon_celiang,
|
||||
size: 34,
|
||||
),
|
||||
color: Colors.amber)),
|
||||
const Positioned(
|
||||
width: 180,
|
||||
height: 90,
|
||||
bottom: 60,
|
||||
child: Image(
|
||||
image: AssetImage("assets/images/range_input.png"),
|
||||
fit: BoxFit.contain,
|
||||
)),
|
||||
Positioned(
|
||||
width: 180,
|
||||
height: 90,
|
||||
bottom: 60,
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 15),
|
||||
child: Text(
|
||||
"${distance} m",
|
||||
style: const TextStyle(
|
||||
color: Colors.amber, fontSize: 28),
|
||||
),
|
||||
CrossPaint(),
|
||||
],
|
||||
),
|
||||
),
|
||||
)),
|
||||
|
||||
Positioned(
|
||||
bottom: 60,
|
||||
right: 40,
|
||||
height: 120,
|
||||
width: 100,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
IconButton(
|
||||
color: Colors.amber,
|
||||
onPressed: () {
|
||||
if (isUpClose) {
|
||||
openUpLaser();
|
||||
} else {
|
||||
closeUpLaser();
|
||||
}
|
||||
setState(() {
|
||||
isUpClose = !isUpClose;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
isUpClose
|
||||
? MyIcons.icon_shangdeng
|
||||
: MyIcons.icon_shangdnegguanbi,
|
||||
size: 36)),
|
||||
IconButton(
|
||||
color: Colors.amber,
|
||||
onPressed: () {
|
||||
if (isSideClose) {
|
||||
openSideLaser();
|
||||
} else {
|
||||
closeSideLaser();
|
||||
}
|
||||
setState(() {
|
||||
isSideClose = !isSideClose;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
isSideClose
|
||||
? MyIcons.icon_zuoyoudneg
|
||||
: MyIcons.icon_zuoyoudengguanbi,
|
||||
size: 32,
|
||||
))
|
||||
const Spacer(flex: 1),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
)),
|
||||
));
|
||||
)
|
||||
],
|
||||
),
|
||||
// 最上面一行, lock azimuth login
|
||||
Positioned(
|
||||
top: 5,
|
||||
child: Column(
|
||||
children: [
|
||||
const Image(
|
||||
width: 15,
|
||||
height: 15,
|
||||
image: AssetImage("assets/images/arrow.png"),
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
Text(
|
||||
// "${azimuth.toStringAsFixed(2)}",
|
||||
myaw.toStringAsFixed(2),
|
||||
style:
|
||||
const TextStyle(color: Colors.amber, fontSize: 36),
|
||||
),
|
||||
],
|
||||
)),
|
||||
Positioned(
|
||||
top: 5,
|
||||
right: 8,
|
||||
child: IconButton(
|
||||
onPressed: () => selectRegion(),
|
||||
icon: const Icon(Icons.settings, color: Colors.amber),
|
||||
)),
|
||||
// 最下面一行,ranging value openlaser
|
||||
Positioned(
|
||||
bottom: 80,
|
||||
left: 50,
|
||||
child: IconButton(
|
||||
onPressed: raging,
|
||||
icon: const Icon(
|
||||
MyIcons.icon_celiang,
|
||||
size: 34,
|
||||
),
|
||||
color: Colors.amber)),
|
||||
const Positioned(
|
||||
width: 180,
|
||||
height: 90,
|
||||
bottom: 60,
|
||||
child: Image(
|
||||
image: AssetImage("assets/images/range_input.png"),
|
||||
fit: BoxFit.contain,
|
||||
)),
|
||||
Positioned(
|
||||
width: 180,
|
||||
height: 90,
|
||||
bottom: 60,
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 15),
|
||||
child: Text(
|
||||
"${distance} m",
|
||||
style:
|
||||
const TextStyle(color: Colors.amber, fontSize: 28),
|
||||
),
|
||||
),
|
||||
)),
|
||||
|
||||
Positioned(
|
||||
bottom: 60,
|
||||
right: 40,
|
||||
height: 120,
|
||||
width: 100,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
IconButton(
|
||||
color: Colors.amber,
|
||||
onPressed: () {
|
||||
if (isUpClose) {
|
||||
openUpLaser();
|
||||
} else {
|
||||
closeUpLaser();
|
||||
}
|
||||
setState(() {
|
||||
isUpClose = !isUpClose;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
isUpClose
|
||||
? MyIcons.icon_shangdeng
|
||||
: MyIcons.icon_shangdnegguanbi,
|
||||
size: 36)),
|
||||
IconButton(
|
||||
color: Colors.amber,
|
||||
onPressed: () {
|
||||
if (isSideClose) {
|
||||
openSideLaser();
|
||||
} else {
|
||||
closeSideLaser();
|
||||
}
|
||||
setState(() {
|
||||
isSideClose = !isSideClose;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
isSideClose
|
||||
? MyIcons.icon_zuoyoudneg
|
||||
: MyIcons.icon_zuoyoudengguanbi,
|
||||
size: 32,
|
||||
))
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user