Skip to content

Commit

Permalink
- radians instead of degrees
Browse files Browse the repository at this point in the history
- static member instead of instance
  • Loading branch information
diegoveloper committed Oct 4, 2018
1 parent c59fd40 commit 84e57d5
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .packages
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by pub on 2018-10-02 16:00:36.347987.
# Generated by pub on 2018-10-04 10:28:35.784701.
analyzer:file:///Users/diegoveloper/Development/SDKS/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.32.4/lib/
args:file:///Users/diegoveloper/Development/SDKS/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.5.0/lib/
async:file:///Users/diegoveloper/Development/SDKS/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.0.8/lib/
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.0.4] - 10/02/2018

* Values are expressed in radians instead of degrees
* Use AeyriumSensor.sensorEvents instead of AeyriumSensor().sensorEvents

## [1.0.3] - 10/02/2018

* Pitch value was fixed when rotate the device on iOS
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ To use this plugin, add `aeyrium_sensor` as a [dependency in your pubspec.yaml f

```yaml
dependencies:
aeyrium_sensor: ^1.0.3
aeyrium_sensor: ^1.0.4
```
## Usage
``` dart
import 'package:aeyrium_sensor/aeyrium_sensor.dart';

AeyriumSensor().sensorEvents.listen((SensorEvent event) {
//do something with the event
AeyriumSensor.sensorEvents.listen((SensorEvent event) {
//do something with the event , values expressed in radians
print("Pitch ${event.pitch} and Roll ${event.roll}")

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ private void updateOrientation(float[] rotationVector, EventChannel.EventSink ev
float[] orientation = new float[3];
SensorManager.getOrientation(adjustedRotationMatrix, orientation);

// Convert radians to degrees
double pitch = orientation[1]* -57;
double roll = orientation[2] * -57;
double pitch = - orientation[1];
double roll = - orientation[2];
double[] sensorValues = new double[2];
sensorValues[0] = pitch;
sensorValues[1] = roll;
Expand Down
Binary file modified build/testfile.dill
Binary file not shown.
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class _MyAppState extends State<MyApp> {

@override
void initState() {
_streamSubscriptions = AeyriumSensor().sensorEvents.listen((event) {
_streamSubscriptions = AeyriumSensor.sensorEvents.listen((event) {
setState(() {
_data = "Pitch ${event.pitch} , Roll ${event.roll}";
});
Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/AeyriumSensorPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ - (FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink
0.0f, 0.0f, 0.0f, 1.0f);

deviceMotionAttitudeMatrix = GLKMatrix4Multiply(baseRotation, deviceMotionAttitudeMatrix);
double pitch = degrees (asin(-deviceMotionAttitudeMatrix.m22));
double roll = -degrees(atan2(2*(quat.y*quat.w - quat.x*quat.z), 1 - 2*quat.y*quat.y - 2*quat.z*quat.z)) ;
double pitch = (asin(-deviceMotionAttitudeMatrix.m22));
double roll = -(atan2(2*(quat.y*quat.w - quat.x*quat.z), 1 - 2*quat.y*quat.y - 2*quat.z*quat.z)) ;
sendData(pitch, roll , eventSink);
}];
return nil;
Expand Down
20 changes: 6 additions & 14 deletions lib/aeyrium_sensor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const EventChannel _sensorEventChannel =
EventChannel('plugins.aeyrium.com/sensor');

class SensorEvent {
/// Pitch event from the device
/// Pitch from the device in radians
/// A pitch is a rotation around a lateral (X) axis that passes through the device from side to side
final double pitch;

///Roll event from the device
///Roll value from the device in radians
///A roll is a rotation around a longitudinal (Y) axis that passes through the device from its top to bottom
final double roll;

Expand All @@ -21,20 +21,12 @@ class SensorEvent {
}

class AeyriumSensor {
static AeyriumSensor _instance;
Stream<SensorEvent> _sensorEvents;
static Stream<SensorEvent> _sensorEvents;

factory AeyriumSensor() {
if (_instance == null) {
_instance = AeyriumSensor._internal();
}
return _instance;
}

AeyriumSensor._internal();
AeyriumSensor._();

/// A broadcast stream of events from the device rotation sensor.
Stream<SensorEvent> get sensorEvents {
static Stream<SensorEvent> get sensorEvents {
if (_sensorEvents == null) {
_sensorEvents = _sensorEventChannel
.receiveBroadcastStream()
Expand All @@ -43,7 +35,7 @@ class AeyriumSensor {
return _sensorEvents;
}

SensorEvent _listToSensorEvent(List<double> list) {
static SensorEvent _listToSensorEvent(List<double> list) {
return SensorEvent(list[0], list[1]);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: aeyrium_sensor
description: A Flutter sensor plugin which provide easy access to the Pitch and Roll on Android and iOS devices.
version: 1.0.3
version: 1.0.4
author: Diego Velásquez - Aeyrium Inc. <diego@aeyrium.com>
homepage: https://github.com/aeyrium/aeyrium-sensor/

Expand Down
4 changes: 2 additions & 2 deletions test/aeyrium_sensor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/services.dart';
import 'package:test/test.dart';

void main() {
test('${AeyriumSensor().sensorEvents} are streamed', () async {
test('${AeyriumSensor.sensorEvents} are streamed', () async {
const String channelName = 'plugins.aeyrium.com/sensor';
const List<double> sensorData = <double>[1.0, 2.0];

Expand Down Expand Up @@ -34,7 +34,7 @@ void main() {
}
});

final SensorEvent event = await AeyriumSensor().sensorEvents.first;
final SensorEvent event = await AeyriumSensor.sensorEvents.first;
expect(event.pitch, 1.0);
expect(event.roll, 2.0);

Expand Down

0 comments on commit 84e57d5

Please sign in to comment.