Skip to content

Commit

Permalink
Merge pull request #13 from Crequency/dev=dynesshely
Browse files Browse the repository at this point in the history
[Pull Request] 关于添加陀螺仪等传感器数据测试页
  • Loading branch information
Cranyozen authored Jan 8, 2023
2 parents 82e876e + 8af5971 commit 4bb836b
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 44 deletions.
1 change: 1 addition & 0 deletions kitx_mobile/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@
<!-- <uses-permission android:name="android.permission.BLUETOOTH" />-->
<!-- <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />-->
<!-- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>-->
<uses-permission android:name="android.permission.VIBRATE"/>
</manifest>
2 changes: 1 addition & 1 deletion kitx_mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import 'dart:ui' as ui;

import 'package:flutter/material.dart' hide Intent;

import 'package:flutter_logs/flutter_logs.dart';

// import 'package:receive_intent/receive_intent.dart';
import 'package:get/get.dart';

Expand Down
1 change: 0 additions & 1 deletion kitx_mobile/lib/pages/about_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';

import 'package:get/get.dart';


class AboutPage extends StatefulWidget {
const AboutPage({Key? key}) : super(key: key);

Expand Down
1 change: 0 additions & 1 deletion kitx_mobile/lib/pages/account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import 'package:get/get.dart';


class AccountPage extends StatefulWidget {
const AccountPage({Key? key}) : super(key: key);

Expand Down
1 change: 0 additions & 1 deletion kitx_mobile/lib/pages/setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import 'package:get/get.dart';


class SettingPage extends StatefulWidget {
const SettingPage({Key? key}) : super(key: key);

Expand Down
19 changes: 7 additions & 12 deletions kitx_mobile/lib/pages/test_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'test_pages/device_test.dart';
import 'test_pages/device_sensors.dart';
import 'test_pages/network_info_test.dart';

class TestPage extends StatefulWidget {
Expand All @@ -12,13 +13,6 @@ class TestPage extends StatefulWidget {
}

class _TestPageState extends State<TestPage> {
// int _counter = 0;
//
// void _incrementCounter() {
// setState(() {
// _counter++;
// });
// }

@override
Widget build(BuildContext context) {
Expand All @@ -35,11 +29,12 @@ class _TestPageState extends State<TestPage> {
icon: Icon(Icons.devices),
),
Tab(
text: "NetworkInfo",
icon: Icon(Icons.wifi),
text: "Device Sensors",
icon: Icon(Icons.sensors),
),
Tab(
icon: Icon(Icons.brightness_5_sharp),
text: "Network Info",
icon: Icon(Icons.wifi),
),
],
),
Expand All @@ -50,10 +45,10 @@ class _TestPageState extends State<TestPage> {
child: DeviceTestPage(),
),
Center(
child: networkInfoTestPage(),
child: DeviceSensorsPage(),
),
Center(
child: Text("It's sunny here"),
child: NetworkInfoTestPage(),
),
],
),
Expand Down
120 changes: 120 additions & 0 deletions kitx_mobile/lib/pages/test_pages/device_sensors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:sensors_plus/sensors_plus.dart';
import 'package:vibration/vibration.dart';

// import 'package:model_viewer/model_viewer.dart';
// import 'package:flutter_cube/flutter_cube.dart';

class DeviceSensorsPage extends StatefulWidget {
@override
_DeviceSensorsPage createState() => _DeviceSensorsPage();
}

class _DeviceSensorsPage extends State<DeviceSensorsPage> {
double dir_x = 0, dir_y = 0, dir_z = 0;
double acc_x = 0, acc_y = 0, acc_z = 0;
String direction_x = "none";
String direction_y = "none";
String direction_z = "none";

@override
void initState() {
gyroscopeEvents.listen((event) {
print(event);

dir_x = event.x;
dir_y = event.y;
dir_z = event.z;

//rough calculation, you can use
//advance formula to calculate the orentation
if (dir_x >= 0)
direction_x = "back";
else
direction_x = "forward";
if (dir_y >= 0)
direction_y = "right";
else
direction_y = "left";
if (dir_z >= 0)
direction_z = "👈";
else
direction_z = "👉";

setState(() {});
});

userAccelerometerEvents.listen((event) {
print(event);

acc_x = event.x;
acc_y = event.y;
acc_z = event.z;
});

super.initState();
}

int vibrate_duration = 200;

Future<void> vibrate() async {
if (await Vibration.hasCustomVibrationsSupport() ?? false) {
Vibration.vibrate(duration: vibrate_duration);
} else if (await Vibration.hasVibrator() ?? false) {
Vibration.vibrate();
}
}

void vibrate_cancel() {
Vibration.cancel();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text("Device Sensors Info"),
),
body: Container(
alignment: Alignment.center,
padding: EdgeInsets.all(30),
child: ListView(children: [
Text("Gyroscope Data", style: TextStyle(fontSize: 32)),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(direction_x, style: TextStyle(fontSize: 26),),
Text(direction_y, style: TextStyle(fontSize: 26),),
Text(direction_z, style: TextStyle(fontSize: 26),),
]),
Text("x: $dir_x", style: TextStyle(fontSize: 14)),
Text("y: $dir_y", style: TextStyle(fontSize: 14)),
Text("z: $dir_z", style: TextStyle(fontSize: 14)),
Text("Acceleration Data", style: TextStyle(fontSize: 32)),
Text("x: $acc_x", style: TextStyle(fontSize: 14)),
Text("y: $acc_y", style: TextStyle(fontSize: 14)),
Text("z: $acc_z", style: TextStyle(fontSize: 14)),
Text("Vibration Test", style: TextStyle(fontSize: 32)),
TextField(
decoration:
new InputDecoration(labelText: "Vibration Duration (ms)"),
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp(r'[0-9]')),
FilteringTextInputFormatter.digitsOnly,
], // Only numbers can be entered
onChanged: (val) {
vibrate_duration = int.parse(val);
},
),
OutlinedButton(onPressed: vibrate, child: Text("Vibrate")),
OutlinedButton(onPressed: vibrate_cancel, child: Text("Cancel")),
])),
);
}
}
9 changes: 2 additions & 7 deletions kitx_mobile/lib/pages/test_pages/device_test.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

import 'dart:async';

// import 'dart:developer' as developer;
import 'dart:io';

Expand Down Expand Up @@ -245,4 +240,4 @@ class _DeviceTestPage extends State<DeviceTestPage> {
),
);
}
}
}
20 changes: 7 additions & 13 deletions kitx_mobile/lib/pages/test_pages/network_info_test.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

import 'dart:async';
import 'dart:io';

Expand All @@ -24,7 +18,7 @@ import 'package:flutter/services.dart';
// _enablePlatformOverrideForDesktop();
// }

class networkInfoTestPage extends StatelessWidget {
class NetworkInfoTestPage extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
Expand All @@ -33,21 +27,21 @@ class networkInfoTestPage extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: _networkInfoTestPage(title: 'Flutter Demo Home Page'),
home: _NetworkInfoTestPage(title: 'Flutter Demo Home Page'),
);
}
}

class _networkInfoTestPage extends StatefulWidget {
_networkInfoTestPage({Key? key, this.title}) : super(key: key);
class _NetworkInfoTestPage extends StatefulWidget {
_NetworkInfoTestPage({Key? key, this.title}) : super(key: key);

final String? title;

@override
_networkInfoTestPageState createState() => _networkInfoTestPageState();
_NetworkInfoTestPageState createState() => _NetworkInfoTestPageState();
}

class _networkInfoTestPageState extends State<_networkInfoTestPage> {
class _NetworkInfoTestPageState extends State<_NetworkInfoTestPage> {
String _connectionStatus = 'Unknown';
final NetworkInfo _networkInfo = NetworkInfo();

Expand Down Expand Up @@ -168,4 +162,4 @@ class _networkInfoTestPageState extends State<_networkInfoTestPage> {
'Wifi Submask: $wifiSubmask\n';
});
}
}
}
21 changes: 13 additions & 8 deletions kitx_mobile/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@ environment:
dependencies:
flutter:
sdk: flutter
# flutter_localizations:
# sdk: flutter
# flutter_localizations:
# sdk: flutter

# intl: ^0.17.0
# flutter_i18n: ^0.32.4 # 国际化
# intl: ^0.17.0
# flutter_i18n: ^0.32.4 # 国际化
get: ^4.6.5 # 路由管理
network_info_plus: ^1.3.0 # 网络信息
device_info_plus: ^5.0.1 # 设备信息
date_format: ^2.0.7 # 时间格式
flutter_logs: ^2.1.7 # 日志
# sms_receiver: ^0.4.1 # 短信接收
permission_handler: ^8.1.4+2 # 权限管理
# sms_receiver: ^0.4.1 # 短信接收
permission_handler: ^8.1.4+2 #权限管理
mac_address: ^1.0.0 # 获取 MAC
community_material_icon: ^5.9.55 # Material Design Icons 社区贡献
flutter_blue_plus: ^1.3.1 # 蓝牙
flutter_blue_plus: ^1.3.1
# flutter_blue: ^0.8.0
sensors_plus: ^1.2.2 # 传感器
# flutter_cube: ^0.1.0 # 加载简单 3D 模型
model_viewer: ^0.8.1 # 3D 模型查看器
vibration: ^1.7.6 # 手机震动
# battery_plus: ^3.0.2 # 电池数据
built_value: ^8.4.2 # JSON 序列化
built_collection: ^5.1.1
# flutter_blue: ^0.8.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 4bb836b

Please sign in to comment.