Browse Source

[sensors-plus] Add all sensors. OMP#OS-17084

merge-requests/27/head
Vitaliy Zarubin 2 years ago
parent
commit
46c8e52bd9
  1. 20
      example/lib/l10n/app_en.arb
  2. 20
      example/lib/l10n/app_ru.arb
  3. 2
      example/lib/packages/flutter_keyboard_visibility/page.dart
  4. 185
      example/lib/packages/sensors_plus/page.dart
  5. 2
      example/lib/packages/translator/page.dart
  6. 10
      example/lib/widgets/blocks/block_item.dart
  7. 112
      packages/sensors_plus/sensors_plus_aurora/README.md
  8. 67
      packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h
  9. 559
      packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp
  10. 11
      packages/sensors_plus/sensors_plus_aurora/lib/events/als_event.dart
  11. 13
      packages/sensors_plus/sensors_plus_aurora/lib/events/compass_event.dart
  12. 6
      packages/sensors_plus/sensors_plus_aurora/lib/events/orientation_event.dart
  13. 11
      packages/sensors_plus/sensors_plus_aurora/lib/events/proximity_event.dart
  14. 53
      packages/sensors_plus/sensors_plus_aurora/lib/events/tap_event.dart
  15. 66
      packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart
  16. 111
      packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart
  17. 30
      packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart

20
example/lib/l10n/app_en.arb

@ -1,4 +1,24 @@
{ {
"@_SENSORS_PLUS": {},
"sensorsPlusTitleOrientation": "Orientation",
"sensorsPlusTitleAccelerometer": "Accelerometer",
"sensorsPlusTitleCompass": "Compass",
"sensorsPlusTitleTap": "Tap",
"sensorsPlusTitleALS": "ALS",
"sensorsPlusTitleProximity": "Proximity",
"sensorsPlusTitleGyroscope": "Gyroscope",
"sensorsPlusTitleMagnetometer": "Magnetometer",
"sensorsPlusNotFound": "Sensor not found",
"sensorsPlusSubtitle": "Sensor key: {name}",
"@sensorsPlusSubtitle": {
"placeholders": {
"name": {
"type": "String",
"example": "orientationsensor"
}
}
},
"@_PROVIDER": {}, "@_PROVIDER": {},
"providerTitle": "Provider", "providerTitle": "Provider",
"providerSubtitle": "Simple example use provider package", "providerSubtitle": "Simple example use provider package",

20
example/lib/l10n/app_ru.arb

@ -1,4 +1,24 @@
{ {
"@_SENSORS_PLUS": {},
"sensorsPlusTitleOrientation": "Ориентация",
"sensorsPlusTitleAccelerometer": "Акселерометр",
"sensorsPlusTitleCompass": "Компас",
"sensorsPlusTitleTap": "Нажмите",
"sensorsPlusTitleALS": "ALS",
"sensorsPlusTitleProximity": "Датчик приближения",
"sensorsPlusTitleGyroscope": "Гироскоп",
"sensorsPlusTitleMagnetometer": "Магнитометр",
"sensorsPlusNotFound": "Датчик не найден",
"sensorsPlusSubtitle": "Ключ датчика: {name}",
"@sensorsPlusSubtitle": {
"placeholders": {
"name": {
"type": "String",
"example": "orientationsensor"
}
}
},
"@_PROVIDER": {}, "@_PROVIDER": {},
"providerTitle": "Provider", "providerTitle": "Provider",
"providerSubtitle": "Простой пример использования пакета provider", "providerSubtitle": "Простой пример использования пакета provider",

2
example/lib/packages/flutter_keyboard_visibility/page.dart

@ -99,7 +99,7 @@ class _FlutterKeyboardVisibilityPageState
title: l10n.flutterKeyboardVisibilityTitleHeight, title: l10n.flutterKeyboardVisibilityTitleHeight,
desc: l10n.flutterKeyboardVisibilityDescHeight, desc: l10n.flutterKeyboardVisibilityDescHeight,
value: _keyboardHeight, value: _keyboardHeight,
builder: (value) => value.toInt().toString(), builder: (value) => value?.toInt().toString(),
), ),
), ),
const SizedBox(height: 20), const SizedBox(height: 20),

185
example/lib/packages/sensors_plus/page.dart

@ -5,10 +5,15 @@ import 'package:flutter_example_packages/base/di/app_di.dart';
import 'package:flutter_example_packages/base/package/package.dart'; import 'package:flutter_example_packages/base/package/package.dart';
import 'package:flutter_example_packages/widgets/base/export.dart'; import 'package:flutter_example_packages/widgets/base/export.dart';
import 'package:flutter_example_packages/widgets/blocks/block_info_package.dart'; import 'package:flutter_example_packages/widgets/blocks/block_info_package.dart';
import 'package:flutter_example_packages/widgets/blocks/block_item.dart';
import 'package:flutter_example_packages/widgets/layouts/block_layout.dart'; import 'package:flutter_example_packages/widgets/layouts/block_layout.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:sensors_plus/sensors_plus.dart'; import 'package:sensors_plus/sensors_plus.dart';
import 'package:sensors_plus_aurora/orientation_event.dart'; import 'package:sensors_plus_aurora/events/als_event.dart';
import 'package:sensors_plus_aurora/events/compass_event.dart';
import 'package:sensors_plus_aurora/events/orientation_event.dart';
import 'package:sensors_plus_aurora/events/proximity_event.dart';
import 'package:sensors_plus_aurora/events/tap_event.dart';
import 'package:sensors_plus_aurora/sensors_plus_aurora.dart'; import 'package:sensors_plus_aurora/sensors_plus_aurora.dart';
import 'model.dart'; import 'model.dart';
@ -26,42 +31,59 @@ class SensorsPlusPage extends AppStatefulWidget {
} }
class _SensorsPlusPageState extends AppState<SensorsPlusPage> { class _SensorsPlusPageState extends AppState<SensorsPlusPage> {
OrientationEvent orientation = OrientationEvent.undefined; Stream<OrientationEvent>? _orientationEvents;
AccelerometerEvent accelerometer = AccelerometerEvent(0, 0, 0); Stream<AccelerometerEvent>? _accelerometerEvents;
Stream<CompassEvent>? _compassEvents;
Stream<TapEvent>? _tapEvents;
Stream<ALSEvent>? _alsEvents;
Stream<ProximityEvent>? _proximityEvents;
Stream<GyroscopeEvent>? _gyroscopeEvents;
Stream<MagnetometerEvent>? _magnetometerEvents;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
/// Accelerometer change try {
accelerometerEvents.listen( _orientationEvents = orientationEvents;
(AccelerometerEvent event) { } catch (e) {
if (mounted) { debugPrint(e.toString());
setState(() { }
accelerometer = event; try {
}); _accelerometerEvents = accelerometerEvents;
} } catch (e) {
}, debugPrint(e.toString());
onError: (error) { }
debugPrint(error.toString()); try {
}, _compassEvents = compassEvents;
cancelOnError: true, } catch (e) {
); debugPrint(e.toString());
}
/// Only Aurora OS orientation change try {
orientationEvents?.listen( _tapEvents = tapEvents;
(OrientationEvent event) { } catch (e) {
if (mounted) { debugPrint(e.toString());
setState(() { }
orientation = event; try {
}); _alsEvents = alsEvents;
} } catch (e) {
}, debugPrint(e.toString());
onError: (error) { }
debugPrint(error.toString()); try {
}, _proximityEvents = proximityEvents;
cancelOnError: true, } catch (e) {
); debugPrint(e.toString());
}
try {
_gyroscopeEvents = gyroscopeEvents;
} catch (e) {
debugPrint(e.toString());
}
try {
_magnetometerEvents = magnetometerEvents;
} catch (e) {
debugPrint(e.toString());
}
} }
@override @override
@ -81,12 +103,101 @@ class _SensorsPlusPageState extends AppState<SensorsPlusPage> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
BlockInfoPackage(widget.package), BlockInfoPackage(widget.package),
Center( Visibility(
child: Text('Orientation: $orientation'), visible: _orientationEvents != null,
child: BlockItem(
isShowProgress: false,
title: l10n.sensorsPlusTitleOrientation,
desc: l10n.sensorsPlusSubtitle('orientationsensor'),
stream: _orientationEvents,
builder: (value) => value == null
? l10n.sensorsPlusNotFound
: value.toString(),
),
),
Visibility(
visible: _accelerometerEvents != null,
child: BlockItem(
isShowProgress: false,
title: l10n.sensorsPlusTitleAccelerometer,
desc: l10n.sensorsPlusSubtitle('accelerometersensor'),
stream: _accelerometerEvents,
builder: (value) => value == null
? l10n.sensorsPlusNotFound
: value.toString(),
),
),
Visibility(
visible: _compassEvents != null,
child: BlockItem(
isShowProgress: false,
title: l10n.sensorsPlusTitleCompass,
desc: l10n.sensorsPlusSubtitle('compasssensor'),
stream: _compassEvents,
builder: (value) => value == null
? l10n.sensorsPlusNotFound
: value.toString(),
),
),
Visibility(
visible: _tapEvents != null,
child: BlockItem(
isShowProgress: false,
title: l10n.sensorsPlusTitleTap,
desc: l10n.sensorsPlusSubtitle('tapsensor'),
stream: _tapEvents,
builder: (value) => value == null
? l10n.sensorsPlusNotFound
: value.toString(),
),
),
Visibility(
visible: _alsEvents != null,
child: BlockItem(
isShowProgress: false,
title: l10n.sensorsPlusTitleALS,
desc: l10n.sensorsPlusSubtitle('alssensor'),
stream: _alsEvents,
builder: (value) => value == null
? l10n.sensorsPlusNotFound
: value.toString(),
),
),
Visibility(
visible: _proximityEvents != null,
child: BlockItem(
isShowProgress: false,
title: l10n.sensorsPlusTitleProximity,
desc: l10n.sensorsPlusSubtitle('proximitysensor'),
stream: _proximityEvents,
builder: (value) => value == null
? l10n.sensorsPlusNotFound
: value.toString(),
),
),
Visibility(
visible: _gyroscopeEvents != null,
child: BlockItem(
isShowProgress: false,
title: l10n.sensorsPlusTitleGyroscope,
desc: l10n.sensorsPlusSubtitle('rotationsensor'),
stream: _gyroscopeEvents,
builder: (value) => value == null
? l10n.sensorsPlusNotFound
: value.toString(),
),
), ),
const SizedBox(height: 20,), Visibility(
Center( visible: _magnetometerEvents != null,
child: Text('Accelerometer: $accelerometer'), child: BlockItem(
isShowProgress: false,
title: l10n.sensorsPlusTitleMagnetometer,
desc: l10n.sensorsPlusSubtitle('magnetometersensor'),
stream: _magnetometerEvents,
builder: (value) => value == null
? l10n.sensorsPlusNotFound
: value.toString(),
),
), ),
], ],
), ),

2
example/lib/packages/translator/page.dart

@ -45,7 +45,7 @@ class _TranslatorPageState extends AppState<TranslatorPage> {
title: l10n.translatorTitle, title: l10n.translatorTitle,
desc: l10n.translatorSubtitle, desc: l10n.translatorSubtitle,
future: model.translate(l10n.translatorText), future: model.translate(l10n.translatorText),
builder: (value) => value.text, builder: (value) => value?.text,
), ),
], ],
), ),

10
example/lib/widgets/blocks/block_item.dart

@ -15,6 +15,7 @@ class BlockItem<T> extends AppStatelessWidget {
this.future, this.future,
this.stream, this.stream,
this.builder, this.builder,
this.isShowProgress = true,
}); });
final String? title; final String? title;
@ -22,7 +23,8 @@ class BlockItem<T> extends AppStatelessWidget {
final T? value; final T? value;
final Stream<T>? stream; final Stream<T>? stream;
final Future<T>? future; final Future<T>? future;
final Function(T)? builder; final Function(T?)? builder;
final bool isShowProgress;
AsyncWidgetBuilder<T?> get widgetBuilder => AsyncWidgetBuilder<T?> get widgetBuilder =>
(BuildContext context, AsyncSnapshot<T?> snapshot) { (BuildContext context, AsyncSnapshot<T?> snapshot) {
@ -47,14 +49,14 @@ class BlockItem<T> extends AppStatelessWidget {
], ],
), ),
), ),
if (snapshot.hasData) if (!isShowProgress)
TextBodyMedium( TextBodyMedium(
builder == null builder == null
? snapshot.data.toString() ? snapshot.data.toString()
: builder?.call(snapshot.data as T), : builder?.call(snapshot.data),
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
if (!snapshot.hasData) if (isShowProgress)
const SizedBox( const SizedBox(
width: 16, width: 16,
height: 16, height: 16,

112
packages/sensors_plus/sensors_plus_aurora/README.md

@ -12,11 +12,119 @@ Therefore, you have to include `sensors_plus_aurora` alongside `sensors_plus` as
```yaml ```yaml
dependencies: dependencies:
sensors_plus: ^3.0.2 sensors_plus: ^3.0.2
sensors_plus_aurora: ^0.0.0 # @todo Not published sensors_plus_aurora:
path: # path to folder with plugin
```
## Features
- accelerometerEvents - A broadcast stream of events from the device accelerometer.
- gyroscopeEvents - A broadcast stream of events from the device gyroscope.
- magnetometerEvents - A broadcast stream of events from the device magnetometer.
- orientationEvents - A broadcast stream of events from the Aurora OS device orientation.
- compassEvents - A broadcast stream of events from the Aurora OS device compass.
- tapEvents - A broadcast stream of events from the Aurora OS device tap.
- alsEvents - A broadcast stream of events from the Aurora OS device ALS.
- proximityEvents - A broadcast stream of events from the Aurora OS device proximity.
***.dart**
```spec
BuildRequires: pkgconfig(sensord-qt5)
``` ```
***.dart** ***.dart**
```dart ```dart
// @todo import 'package:sensors_plus/sensors_plus.dart';
import 'package:sensors_plus_aurora/events/als_event.dart';
import 'package:sensors_plus_aurora/events/compass_event.dart';
import 'package:sensors_plus_aurora/events/orientation_event.dart';
import 'package:sensors_plus_aurora/events/proximity_event.dart';
import 'package:sensors_plus_aurora/events/tap_event.dart';
import 'package:sensors_plus_aurora/sensors_plus_aurora.dart';
/// Package sensors_plus
///
/// A broadcast stream of events from the device accelerometer.
accelerometerEvents.listen(
(AccelerometerEvent event) {
debugPrint(event.toString());
},
onError: (error) {
debugPrint(error.toString());
}
);
/// A broadcast stream of events from the device gyroscope.
gyroscopeEvents.listen(
(GyroscopeEvent event) {
debugPrint(event.toString());
},
onError: (error) {
debugPrint(error.toString());
}
);
/// A broadcast stream of events from the device magnetometer.
magnetometerEvents.listen(
(MagnetometerEvent event) {
debugPrint(event.toString());
},
onError: (error) {
debugPrint(error.toString());
}
);
/// Custom Aurora OS events
///
/// A broadcast stream of events from the Aurora OS device orientation.
orientationEvents?.listen(
(OrientationEvent event) {
debugPrint(event.toString());
},
onError: (error) {
debugPrint(error.toString());
}
);
/// A broadcast stream of events from the Aurora OS device compass.
compassEvents?.listen(
(CompassEvent event) {
debugPrint(event.toString());
},
onError: (error) {
debugPrint(error.toString());
}
);
/// A broadcast stream of events from the Aurora OS device tap.
tapEvents?.listen(
(TapEvent event) {
debugPrint(event.toString());
},
onError: (error) {
debugPrint(error.toString());
}
);
/// A broadcast stream of events from the Aurora OS device ALS.
alsEvents?.listen(
(ALSEvent event) {
debugPrint(event.toString());
},
onError: (error) {
debugPrint(error.toString());
}
);
/// A broadcast stream of events from the Aurora OS device proximity.
proximityEvents?.listen(
(ProximityEvent event) {
debugPrint(event.toString());
},
onError: (error) {
debugPrint(error.toString());
}
);
``` ```

67
packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h

@ -11,13 +11,19 @@
#include <QtCore> #include <QtCore>
#include <datatypes/unsigned.h> #include <sensormanagerinterface.h>
#include <abstractsensor_i.h> #include <orientationsensor_i.h>
#include <accelerometersensor_i.h> #include <accelerometersensor_i.h>
#include <compasssensor_i.h>
#include <tapsensor_i.h>
#include <alssensor_i.h>
#include <proximitysensor_i.h>
#include <rotationsensor_i.h>
#include <magnetometersensor_i.h>
class PLUGIN_EXPORT SensorsPlusAuroraPlugin final class PLUGIN_EXPORT SensorsPlusAuroraPlugin final
: public QObject : public QObject,
, public PluginInterface public PluginInterface
{ {
Q_OBJECT Q_OBJECT
@ -25,19 +31,54 @@ public:
void RegisterWithRegistrar(PluginRegistrar &registrar) override; void RegisterWithRegistrar(PluginRegistrar &registrar) override;
public slots: public slots:
void eventSensorOrientation(const Unsigned &data); void EventSensorOrientation(const Unsigned &data);
void eventSensorAccelerometer(const XYZ& data); void EventSensorAccelerometer(const XYZ &data);
void EventSensorCompass(const Compass &data);
void EventSensorTap(const Tap &data);
void EventSensorALS(const Unsigned &data);
void EventSensorProximity(const Proximity &data);
void EventSensorRotation(const XYZ &data);
void EventSensorMagnetometer(const MagneticField &data);
private: private:
void onMethodCall(const MethodCall &call); template <typename T>
void onListenSensorOrientation(); bool RegisterSensorInterface(QString sensor);
void onListenSensorAccelerometer(); void EventChannelNull(std::string channel);
void unimplemented(const MethodCall &call); void EventChannelData(std::string channel, std::vector<Encodable> result);
void EnableSensorOrientation();
void DisableSensorOrientation();
void EnableSensorAccelerometer();
void DisableSensorAccelerometer();
void EnableSensorCompass();
void DisableSensorCompass();
void EnableSensorTap();
void DisableSensorTap();
void EnableSensorALS();
void DisableSensorALS();
void EnableSensorProximity();
void DisableSensorProximity();
void EnableSensorRotation();
void DisableSensorRotation();
void EnableSensorMagnetometer();
void DisableSensorMagnetometer();
private: private:
bool m_isSendSensorOrientation = false; OrientationSensorChannelInterface *m_ifaceOrientation = nullptr;
bool m_isSendSensorAccelerometer = false; AccelerometerSensorChannelInterface *m_ifaceAccelerometer = nullptr;
AbstractSensorChannelInterface *m_iface = nullptr; CompassSensorChannelInterface *m_ifaceCompass = nullptr;
TapSensorChannelInterface *m_ifaceTap = nullptr;
ALSSensorChannelInterface *m_ifaceALS = nullptr;
ProximitySensorChannelInterface *m_ifaceProximity = nullptr;
RotationSensorChannelInterface *m_ifaceRotation = nullptr;
MagnetometerSensorChannelInterface *m_ifaceMagnetometer = nullptr;
}; };
#endif /* FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H */ #endif /* FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H */

559
packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp

@ -10,164 +10,515 @@
#include <sensormanagerinterface.h> #include <sensormanagerinterface.h>
#include <orientationsensor_i.h> #include <orientationsensor_i.h>
#include <accelerometersensor_i.h> #include <accelerometersensor_i.h>
#include <compasssensor_i.h>
#include <tapsensor_i.h>
#include <alssensor_i.h>
#include <proximitysensor_i.h>
#include <rotationsensor_i.h>
#include <magnetometersensor_i.h>
namespace KeyChannel
{
constexpr auto Orientation = "sensors_plus_aurora_orientationsensor";
constexpr auto Accelerometer = "sensors_plus_aurora_accelerometersensor";
constexpr auto Compass = "sensors_plus_aurora_compasssensor";
constexpr auto Tap = "sensors_plus_aurora_tapsensor";
constexpr auto ALS = "sensors_plus_aurora_alssensor";
constexpr auto Proximity = "sensors_plus_aurora_proximitysensor";
constexpr auto Rotation = "sensors_plus_aurora_rotationsensor";
constexpr auto Magnetometer = "sensors_plus_aurora_magnetometersensor";
}
static AbstractSensorChannelInterface *ifaceOrientation; namespace KeySensor
static AbstractSensorChannelInterface *ifaceAccelerometer; {
constexpr auto Orientation = "orientationsensor";
constexpr auto Accelerometer = "accelerometersensor";
constexpr auto Compass = "compasssensor";
constexpr auto Tap = "tapsensor";
constexpr auto ALS = "alssensor";
constexpr auto Proximity = "proximitysensor";
constexpr auto Rotation = "rotationsensor";
constexpr auto Magnetometer = "magnetometersensor";
} /* namespace */
namespace { void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar &registrar)
{
registrar.RegisterEventChannel(
KeyChannel::Orientation, MethodCodecType::Standard,
[this](const Encodable &)
{ EnableSensorOrientation(); return EventResponse(); },
[this](const Encodable &)
{ DisableSensorOrientation(); return EventResponse(); });
registrar.RegisterEventChannel(
KeyChannel::Accelerometer, MethodCodecType::Standard,
[this](const Encodable &)
{ EnableSensorAccelerometer(); return EventResponse(); },
[this](const Encodable &)
{ DisableSensorAccelerometer(); return EventResponse(); });
registrar.RegisterEventChannel(
KeyChannel::Compass, MethodCodecType::Standard,
[this](const Encodable &)
{ EnableSensorCompass(); return EventResponse(); },
[this](const Encodable &)
{ DisableSensorCompass(); return EventResponse(); });
registrar.RegisterEventChannel(
KeyChannel::Tap, MethodCodecType::Standard,
[this](const Encodable &)
{ EnableSensorTap(); return EventResponse(); },
[this](const Encodable &)
{ DisableSensorTap(); return EventResponse(); });
registrar.RegisterEventChannel(
KeyChannel::ALS, MethodCodecType::Standard,
[this](const Encodable &)
{ EnableSensorALS(); return EventResponse(); },
[this](const Encodable &)
{ DisableSensorALS(); return EventResponse(); });
registrar.RegisterEventChannel(
KeyChannel::Proximity, MethodCodecType::Standard,
[this](const Encodable &)
{ EnableSensorProximity(); return EventResponse(); },
[this](const Encodable &)
{ DisableSensorProximity(); return EventResponse(); });
registrar.RegisterEventChannel(
KeyChannel::Rotation, MethodCodecType::Standard,
[this](const Encodable &)
{ EnableSensorRotation(); return EventResponse(); },
[this](const Encodable &)
{ DisableSensorRotation(); return EventResponse(); });
registrar.RegisterEventChannel(
KeyChannel::Magnetometer, MethodCodecType::Standard,
[this](const Encodable &)
{ EnableSensorMagnetometer(); return EventResponse(); },
[this](const Encodable &)
{ DisableSensorMagnetometer(); return EventResponse(); });
}
constexpr auto METHOD_LISTEN_SENSOR = "listenSensor"; template <typename T>
bool SensorsPlusAuroraPlugin::RegisterSensorInterface(QString sensor)
{
SensorManagerInterface &sm = SensorManagerInterface::instance();
if (!sm.isValid())
{
return false;
}
} /* namespace */ QDBusReply<bool> reply(sm.loadPlugin(sensor));
if (!reply.isValid() || !reply.value())
{
return false;
}
void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar &registrar) sm.registerSensorInterface<T>(sensor);
return true;
}
void SensorsPlusAuroraPlugin::EventChannelNull(std::string channel)
{
EventChannel(channel, MethodCodecType::Standard).SendEvent(nullptr);
}
void SensorsPlusAuroraPlugin::EventChannelData(std::string channel, std::vector<Encodable> result)
{
EventChannel(channel, MethodCodecType::Standard).SendEvent(result);
}
/**
* Orientation
*/
void SensorsPlusAuroraPlugin::EnableSensorOrientation()
{
if (m_ifaceOrientation == nullptr)
{
if (!RegisterSensorInterface<OrientationSensorChannelInterface>(KeySensor::Orientation))
{
EventChannelNull(KeyChannel::Orientation);
return;
}
m_ifaceOrientation = OrientationSensorChannelInterface::interface(KeySensor::Orientation);
if (!m_ifaceOrientation)
{
EventChannelNull(KeyChannel::Orientation);
return;
}
connect(m_ifaceOrientation,
SIGNAL(orientationChanged(const Unsigned &)),
this,
SLOT(EventSensorOrientation(const Unsigned &)));
}
m_ifaceOrientation->start();
EventSensorOrientation(m_ifaceOrientation->orientation());
}
void SensorsPlusAuroraPlugin::DisableSensorOrientation()
{ {
registrar.RegisterMethodChannel("sensors_plus_aurora", if (m_ifaceOrientation == nullptr)
MethodCodecType::Standard, {
[this](const MethodCall &call) { this->onMethodCall(call); });
registrar.RegisterEventChannel(
"sensors_aurora_orientation",
MethodCodecType::Standard,
[this](const Encodable &)
{
this->m_isSendSensorOrientation = true;
onListenSensorOrientation();
return EventResponse();
},
[this](const Encodable &)
{
this->m_isSendSensorOrientation = false;
return EventResponse();
});
registrar.RegisterEventChannel(
"sensors_aurora_accelerometer",
MethodCodecType::Standard,
[this](const Encodable &)
{
this->m_isSendSensorAccelerometer = true;
onListenSensorAccelerometer();
return EventResponse();
},
[this](const Encodable &)
{
this->m_isSendSensorAccelerometer = false;
return EventResponse();
});
}
void SensorsPlusAuroraPlugin::onMethodCall(const MethodCall &call)
{
const auto &method = call.GetMethod();
if (method == "listenSensor") {
// onListenSensor();
return; return;
} }
unimplemented(call); m_ifaceOrientation->stop();
}
void SensorsPlusAuroraPlugin::EventSensorOrientation(const Unsigned &data)
{
std::vector<Encodable> result;
result.push_back(data.x());
EventChannelData(KeyChannel::Orientation, result);
} }
void SensorsPlusAuroraPlugin::onListenSensorOrientation() /**
* Accelerometer
*/
void SensorsPlusAuroraPlugin::EnableSensorAccelerometer()
{ {
if (ifaceOrientation != nullptr) { if (m_ifaceAccelerometer == nullptr)
{
if (!RegisterSensorInterface<AccelerometerSensorChannelInterface>(KeySensor::Accelerometer))
{
EventChannelNull(KeyChannel::Accelerometer);
return;
}
m_ifaceAccelerometer = AccelerometerSensorChannelInterface::interface(KeySensor::Accelerometer);
if (!m_ifaceAccelerometer)
{
EventChannelNull(KeyChannel::Accelerometer);
return;
}
connect(m_ifaceAccelerometer,
SIGNAL(dataAvailable(const XYZ &)),
this,
SLOT(EventSensorAccelerometer(const XYZ &)));
}
m_ifaceAccelerometer->start();
EventSensorAccelerometer(m_ifaceAccelerometer->get());
}
void SensorsPlusAuroraPlugin::DisableSensorAccelerometer()
{
if (m_ifaceAccelerometer == nullptr)
{
return; return;
} }
SensorManagerInterface &sm = SensorManagerInterface::instance(); m_ifaceAccelerometer->stop();
if (!sm.isValid()) { }
qDebug() << "Failed to create SensorManagerInterface";
exit(0); void SensorsPlusAuroraPlugin::EventSensorAccelerometer(const XYZ &data)
{
std::vector<Encodable> result;
result.push_back(data.x());
result.push_back(data.y());
result.push_back(data.z());
EventChannelData(KeyChannel::Accelerometer, result);
}
/**
* Compass
*/
void SensorsPlusAuroraPlugin::EnableSensorCompass()
{
if (m_ifaceCompass == nullptr)
{
if (!RegisterSensorInterface<CompassSensorChannelInterface>(KeySensor::Compass))
{
EventChannelNull(KeyChannel::Compass);
return;
}
m_ifaceCompass = CompassSensorChannelInterface::interface(KeySensor::Compass);
if (!m_ifaceCompass)
{
EventChannelNull(KeyChannel::Compass);
return;
}
connect(m_ifaceCompass,
SIGNAL(dataAvailable(const Compass &)),
this,
SLOT(EventSensorCompass(const Compass &)));
} }
QDBusReply<bool> reply(sm.loadPlugin("orientationsensor")); m_ifaceCompass->start();
if (!reply.isValid() || !reply.value()) { EventSensorCompass(m_ifaceCompass->get());
qDebug() << "Failed to load plugin"; }
exit(0);
void SensorsPlusAuroraPlugin::DisableSensorCompass()
{
if (m_ifaceCompass == nullptr)
{
return;
} }
sm.registerSensorInterface<OrientationSensorChannelInterface>("orientationsensor"); m_ifaceCompass->stop();
}
ifaceOrientation = OrientationSensorChannelInterface::interface("orientationsensor"); void SensorsPlusAuroraPlugin::EventSensorCompass(const Compass &data)
{
std::vector<Encodable> result;
result.push_back(data.degrees());
result.push_back(data.level());
EventChannelData(KeyChannel::Compass, result);
}
if (!ifaceOrientation) { /**
qDebug() << "Cannot get OrientationSensorChannelInterface"; * Tap
exit(0); */
void SensorsPlusAuroraPlugin::EnableSensorTap()
{
if (m_ifaceTap == nullptr)
{
if (!RegisterSensorInterface<TapSensorChannelInterface>(KeySensor::Tap))
{
EventChannelNull(KeyChannel::Tap);
return;
}
m_ifaceTap = TapSensorChannelInterface::interface(KeySensor::Tap);
if (!m_ifaceTap)
{
EventChannelNull(KeyChannel::Tap);
return;
}
connect(m_ifaceTap,
SIGNAL(dataAvailable(const Tap &)),
this,
SLOT(EventSensorTap(const Tap &)));
} }
connect(ifaceOrientation, m_ifaceTap->start();
SIGNAL(orientationChanged(const Unsigned&)), }
this,
SLOT(eventSensorOrientation(const Unsigned&)) void SensorsPlusAuroraPlugin::DisableSensorTap()
); {
if (m_ifaceTap == nullptr)
{
return;
}
m_ifaceTap->stop();
}
ifaceOrientation->start(); void SensorsPlusAuroraPlugin::EventSensorTap(const Tap &data)
{
std::vector<Encodable> result;
result.push_back(static_cast<int>(data.direction()));
result.push_back(static_cast<int>(data.type()));
EventChannelData(KeyChannel::Tap, result);
} }
void SensorsPlusAuroraPlugin::eventSensorOrientation(const Unsigned &data) /**
* ALS
*/
void SensorsPlusAuroraPlugin::EnableSensorALS()
{ {
if (this->m_isSendSensorOrientation) if (m_ifaceALS == nullptr)
{ {
EventChannel("sensors_aurora_orientation", MethodCodecType::Standard) if (!RegisterSensorInterface<ALSSensorChannelInterface>(KeySensor::ALS))
.SendEvent(data.x()); {
EventChannelNull(KeyChannel::ALS);
return;
}
m_ifaceALS = ALSSensorChannelInterface::interface(KeySensor::ALS);
if (!m_ifaceALS)
{
EventChannelNull(KeyChannel::ALS);
return;
}
connect(m_ifaceALS,
SIGNAL(ALSChanged(const Unsigned &)),
this,
SLOT(EventSensorALS(const Unsigned &)));
} }
m_ifaceALS->start();
EventSensorALS(m_ifaceALS->lux());
} }
void SensorsPlusAuroraPlugin::onListenSensorAccelerometer() void SensorsPlusAuroraPlugin::DisableSensorALS()
{ {
if (ifaceAccelerometer != nullptr) { if (m_ifaceALS == nullptr)
{
return; return;
} }
SensorManagerInterface &sm = SensorManagerInterface::instance(); m_ifaceALS->stop();
if (!sm.isValid()) { }
qDebug() << "Failed to create SensorManagerInterface";
exit(0); void SensorsPlusAuroraPlugin::EventSensorALS(const Unsigned &data)
{
std::vector<Encodable> result;
result.push_back(data.x());
EventChannelData(KeyChannel::ALS, result);
}
/**
* Proximity
*/
void SensorsPlusAuroraPlugin::EnableSensorProximity()
{
if (m_ifaceProximity == nullptr)
{
if (!RegisterSensorInterface<ProximitySensorChannelInterface>(KeySensor::Proximity))
{
EventChannelNull(KeyChannel::Proximity);
return;
}
m_ifaceProximity = ProximitySensorChannelInterface::interface(KeySensor::Proximity);
if (!m_ifaceProximity)
{
EventChannelNull(KeyChannel::Proximity);
return;
}
connect(m_ifaceProximity,
SIGNAL(reflectanceDataAvailable(const Proximity &)),
this,
SLOT(EventSensorProximity(const Proximity &)));
} }
QDBusReply<bool> reply(sm.loadPlugin("accelerometersensor")); m_ifaceProximity->start();
if (!reply.isValid() || !reply.value()) { EventSensorProximity(m_ifaceProximity->proximityReflectance());
qDebug() << "Failed to load plugin"; }
exit(0);
void SensorsPlusAuroraPlugin::DisableSensorProximity()
{
if (m_ifaceProximity == nullptr)
{
return;
} }
sm.registerSensorInterface<AccelerometerSensorChannelInterface>("accelerometersensor"); m_ifaceProximity->stop();
}
ifaceAccelerometer = AccelerometerSensorChannelInterface::interface("accelerometersensor"); void SensorsPlusAuroraPlugin::EventSensorProximity(const Proximity &data)
{
std::vector<Encodable> result;
result.push_back(data.withinProximity() ? 1 : 0);
EventChannelData(KeyChannel::Proximity, result);
}
if (!ifaceAccelerometer) { /**
qDebug() << "Cannot get AccelerometerSensorChannelInterface"; * Rotation
exit(0); */
void SensorsPlusAuroraPlugin::EnableSensorRotation()
{
if (m_ifaceRotation == nullptr)
{
if (!RegisterSensorInterface<RotationSensorChannelInterface>(KeySensor::Rotation))
{
EventChannelNull(KeyChannel::Rotation);
return;
}
m_ifaceRotation = RotationSensorChannelInterface::interface(KeySensor::Rotation);
if (!m_ifaceRotation)
{
EventChannelNull(KeyChannel::Rotation);
return;
}
connect(m_ifaceRotation,
SIGNAL(dataAvailable(const XYZ &)),
this,
SLOT(EventSensorRotation(const XYZ &)));
} }
connect(ifaceAccelerometer, m_ifaceRotation->start();
SIGNAL(dataAvailable(const XYZ&)), EventSensorRotation(m_ifaceRotation->rotation());
this, }
SLOT(eventSensorAccelerometer(const XYZ&))
);
ifaceAccelerometer->start(); void SensorsPlusAuroraPlugin::DisableSensorRotation()
{
if (m_ifaceRotation == nullptr)
{
return;
}
m_ifaceRotation->stop();
} }
void SensorsPlusAuroraPlugin::eventSensorAccelerometer(const XYZ& data) void SensorsPlusAuroraPlugin::EventSensorRotation(const XYZ &data)
{
std::vector<Encodable> result;
result.push_back(data.x());
result.push_back(data.y());
result.push_back(data.z());
EventChannelData(KeyChannel::Rotation, result);
}
/**
* Magnetometer
*/
void SensorsPlusAuroraPlugin::EnableSensorMagnetometer()
{ {
if (this->m_isSendSensorAccelerometer) if (m_ifaceMagnetometer == nullptr)
{ {
std::vector<Encodable> result; if (!RegisterSensorInterface<MagnetometerSensorChannelInterface>(KeySensor::Magnetometer))
{
EventChannelNull(KeyChannel::Magnetometer);
return;
}
m_ifaceMagnetometer = MagnetometerSensorChannelInterface::interface(KeySensor::Magnetometer);
if (!m_ifaceMagnetometer)
{
EventChannelNull(KeyChannel::Magnetometer);
return;
}
connect(m_ifaceMagnetometer,
SIGNAL(dataAvailable(const MagneticField &)),
this,
SLOT(EventSensorMagnetometer(const MagneticField &)));
}
result.push_back(data.x()); m_ifaceMagnetometer->start();
result.push_back(data.y()); EventSensorMagnetometer(m_ifaceMagnetometer->magneticField());
result.push_back(data.z()); }
EventChannel("sensors_aurora_accelerometer", MethodCodecType::Standard) void SensorsPlusAuroraPlugin::DisableSensorMagnetometer()
.SendEvent(result); {
if (m_ifaceMagnetometer == nullptr)
{
return;
} }
m_ifaceMagnetometer->stop();
} }
void SensorsPlusAuroraPlugin::unimplemented(const MethodCall &call) void SensorsPlusAuroraPlugin::EventSensorMagnetometer(const MagneticField &data)
{ {
call.SendSuccessResponse(nullptr); std::vector<Encodable> result;
result.push_back(data.x());
result.push_back(data.y());
result.push_back(data.z());
EventChannelData(KeyChannel::Magnetometer, result);
} }
#include "moc_sensors_plus_aurora_plugin.cpp" #include "moc_sensors_plus_aurora_plugin.cpp"

11
packages/sensors_plus/sensors_plus_aurora/lib/events/als_event.dart

@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
class ALSEvent {
ALSEvent(this.degrees);
final int degrees;
@override
String toString() => '[ALSEvent (degrees: $degrees)]';
}

13
packages/sensors_plus/sensors_plus_aurora/lib/events/compass_event.dart

@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
class CompassEvent {
CompassEvent(this.degrees, this.level);
final int degrees;
final int level;
@override
String toString() => '[CompassEvent (degrees: $degrees, level: $level)]';
}

6
packages/sensors_plus/sensors_plus_aurora/lib/orientation_event.dart → packages/sensors_plus/sensors_plus_aurora/lib/events/orientation_event.dart

@ -4,16 +4,22 @@
enum OrientationEvent { enum OrientationEvent {
/// The orientation is unknown. /// The orientation is unknown.
undefined, undefined,
/// The Top edge of the device is pointing up. /// The Top edge of the device is pointing up.
topUp, topUp,
/// The Top edge of the device is pointing down. /// The Top edge of the device is pointing down.
topDown, topDown,
/// The Left edge of the device is pointing up. /// The Left edge of the device is pointing up.
leftUp, leftUp,
/// The Right edge of the device is pointing up. /// The Right edge of the device is pointing up.
rightUp, rightUp,
/// The Face of the device is pointing up. /// The Face of the device is pointing up.
faceUp, faceUp,
/// The Face of the device is pointing down. /// The Face of the device is pointing down.
faceDown faceDown
} }

11
packages/sensors_plus/sensors_plus_aurora/lib/events/proximity_event.dart

@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
class ProximityEvent {
ProximityEvent(this.withinProximity);
final bool withinProximity;
@override
String toString() => '[ProximityEvent (withinProximity: $withinProximity)]';
}

53
packages/sensors_plus/sensors_plus_aurora/lib/events/tap_event.dart

@ -0,0 +1,53 @@
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
/// Direction of tap. The last six directions may not be supported
/// depending on hardware.
enum TapDirection {
/// Left or right side tapped
x,
/// Top or down side tapped
y,
/// Face or bottom tapped
z,
/// Tapped from left to right
leftRight,
/// Tapped from right to left
rightLeft,
/// Tapped from top to bottom
topBottom,
/// Tapped from bottom to top
bottomTop,
/// Tapped from face to back
faceBack,
/// Tapped from back to face
backFace
}
/// Type of tap.
enum TapType {
/// Double tap
doubleTap,
/// Single tap.
singleTap
}
class TapEvent {
TapEvent(this.direction, this.type);
final TapDirection direction;
final TapType type;
@override
String toString() => '[TapEvent (direction: $direction, level: $type)]';
}

66
packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart

@ -2,7 +2,11 @@
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:sensors_plus_aurora/orientation_event.dart'; import 'package:sensors_plus_aurora/events/als_event.dart';
import 'package:sensors_plus_aurora/events/compass_event.dart';
import 'package:sensors_plus_aurora/events/orientation_event.dart';
import 'package:sensors_plus_aurora/events/proximity_event.dart';
import 'package:sensors_plus_aurora/events/tap_event.dart';
import 'package:sensors_plus_platform_interface/sensors_plus_platform_interface.dart'; import 'package:sensors_plus_platform_interface/sensors_plus_platform_interface.dart';
import 'sensors_plus_aurora_platform_interface.dart'; import 'sensors_plus_aurora_platform_interface.dart';
@ -15,15 +19,75 @@ Stream<OrientationEvent>? get orientationEvents {
return null; return null;
} }
/// A broadcast stream of events from the Aurora OS device compass.
Stream<CompassEvent>? get compassEvents {
if (TargetPlatform.aurora == defaultTargetPlatform) {
return SensorsPlusAurora().onChangeCompass;
}
return null;
}
/// A broadcast stream of events from the Aurora OS device tap.
Stream<TapEvent>? get tapEvents {
if (TargetPlatform.aurora == defaultTargetPlatform) {
return SensorsPlusAurora().onChangeTap;
}
return null;
}
/// A broadcast stream of events from the Aurora OS device ALS.
Stream<ALSEvent>? get alsEvents {
if (TargetPlatform.aurora == defaultTargetPlatform) {
return SensorsPlusAurora().onChangeALS;
}
return null;
}
/// A broadcast stream of events from the Aurora OS device proximity.
Stream<ProximityEvent>? get proximityEvents {
if (TargetPlatform.aurora == defaultTargetPlatform) {
return SensorsPlusAurora().onChangeProximity;
}
return null;
}
class SensorsPlusAurora extends SensorsPlatform { class SensorsPlusAurora extends SensorsPlatform {
static void registerWith() { static void registerWith() {
SensorsPlatform.instance = SensorsPlusAurora(); SensorsPlatform.instance = SensorsPlusAurora();
} }
/// orientationsensor
Stream<OrientationEvent> get onChangeOrientation => Stream<OrientationEvent> get onChangeOrientation =>
SensorsPlusAuroraPlatform.instance.onChangeOrientation(); SensorsPlusAuroraPlatform.instance.onChangeOrientation();
/// accelerometersensor
@override @override
Stream<AccelerometerEvent> get accelerometerEvents => Stream<AccelerometerEvent> get accelerometerEvents =>
SensorsPlusAuroraPlatform.instance.onChangeAccelerometer(); SensorsPlusAuroraPlatform.instance.onChangeAccelerometer();
/// compasssensor
Stream<CompassEvent> get onChangeCompass =>
SensorsPlusAuroraPlatform.instance.onChangeCompass();
/// tapsensor
Stream<TapEvent> get onChangeTap =>
SensorsPlusAuroraPlatform.instance.onChangeTap();
/// alssensor
Stream<ALSEvent> get onChangeALS =>
SensorsPlusAuroraPlatform.instance.onChangeALS();
/// proximitysensor
Stream<ProximityEvent> get onChangeProximity =>
SensorsPlusAuroraPlatform.instance.onChangeProximity();
/// rotationsensor
@override
Stream<GyroscopeEvent> get gyroscopeEvents =>
SensorsPlusAuroraPlatform.instance.onChangeRotation();
/// magnetometersensor
@override
Stream<MagnetometerEvent> get magnetometerEvents =>
SensorsPlusAuroraPlatform.instance.onChangeMagnetometer();
} }

111
packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart

@ -3,7 +3,11 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:sensors_plus_aurora/orientation_event.dart'; import 'package:sensors_plus_aurora/events/als_event.dart';
import 'package:sensors_plus_aurora/events/compass_event.dart';
import 'package:sensors_plus_aurora/events/orientation_event.dart';
import 'package:sensors_plus_aurora/events/proximity_event.dart';
import 'package:sensors_plus_aurora/events/tap_event.dart';
import 'package:sensors_plus_platform_interface/sensors_plus_platform_interface.dart'; import 'package:sensors_plus_platform_interface/sensors_plus_platform_interface.dart';
import 'sensors_plus_aurora_platform_interface.dart'; import 'sensors_plus_aurora_platform_interface.dart';
@ -14,12 +18,20 @@ class MethodChannelSensorsPlusAurora extends SensorsPlusAuroraPlatform {
@visibleForTesting @visibleForTesting
final methodChannel = const MethodChannel('sensors_plus_aurora'); final methodChannel = const MethodChannel('sensors_plus_aurora');
List<int> _loadData(dynamic data, String key) {
if (data == null) {
throw "Failed to load sensor '$key'";
}
return (data as List<Object?>).map((e) => int.parse(e.toString())).toList();
}
@override @override
Stream<OrientationEvent> onChangeOrientation() async* { Stream<OrientationEvent> onChangeOrientation() async* {
await for (final event in const EventChannel('sensors_aurora_orientation') await for (final data
.receiveBroadcastStream()) { in const EventChannel('sensors_plus_aurora_orientationsensor')
int result = (event as int?) ?? 0; .receiveBroadcastStream()) {
switch (result) { switch (_loadData(data, 'orientationsensor')[0]) {
case 1: case 1:
yield OrientationEvent.rightUp; yield OrientationEvent.rightUp;
break; break;
@ -46,13 +58,90 @@ class MethodChannelSensorsPlusAurora extends SensorsPlusAuroraPlatform {
@override @override
Stream<AccelerometerEvent> onChangeAccelerometer() async* { Stream<AccelerometerEvent> onChangeAccelerometer() async* {
await for (final event in const EventChannel('sensors_aurora_accelerometer') await for (final data
.receiveBroadcastStream()) { in const EventChannel('sensors_plus_aurora_accelerometersensor')
final list = (event as List<Object?>); .receiveBroadcastStream()) {
final result = _loadData(data, 'accelerometersensor');
yield AccelerometerEvent( yield AccelerometerEvent(
(list[0] as int?)?.toDouble() ?? 0, result[0].toDouble(),
(list[1] as int?)?.toDouble() ?? 0, result[1].toDouble(),
(list[2] as int?)?.toDouble() ?? 0, result[2].toDouble(),
);
}
}
@override
Stream<CompassEvent> onChangeCompass() async* {
await for (final data
in const EventChannel('sensors_plus_aurora_compasssensor')
.receiveBroadcastStream()) {
final result = _loadData(data, 'compasssensor');
yield CompassEvent(
result[0],
result[1],
);
}
}
@override
Stream<TapEvent> onChangeTap() async* {
await for (final data in const EventChannel('sensors_plus_aurora_tapsensor')
.receiveBroadcastStream()) {
final result = _loadData(data, 'tapsensor');
yield TapEvent(
TapDirection.values[result[0]],
TapType.values[result[1]],
);
}
}
@override
Stream<ALSEvent> onChangeALS() async* {
await for (final data in const EventChannel('sensors_plus_aurora_alssensor')
.receiveBroadcastStream()) {
final result = _loadData(data, 'alssensor');
yield ALSEvent(
result[0],
);
}
}
@override
Stream<ProximityEvent> onChangeProximity() async* {
await for (final data
in const EventChannel('sensors_plus_aurora_proximitysensor')
.receiveBroadcastStream()) {
final result = _loadData(data, 'proximitysensor');
yield ProximityEvent(
result[0] == 1,
);
}
}
@override
Stream<GyroscopeEvent> onChangeRotation() async* {
await for (final data
in const EventChannel('sensors_plus_aurora_rotationsensor')
.receiveBroadcastStream()) {
final result = _loadData(data, 'rotationsensor');
yield GyroscopeEvent(
result[0].toDouble(),
result[1].toDouble(),
result[2].toDouble(),
);
}
}
@override
Stream<MagnetometerEvent> onChangeMagnetometer() async* {
await for (final data
in const EventChannel('sensors_plus_aurora_magnetometersensor')
.receiveBroadcastStream()) {
final result = _loadData(data, 'magnetometersensor');
yield MagnetometerEvent(
result[0].toDouble(),
result[1].toDouble(),
result[2].toDouble(),
); );
} }
} }

30
packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart

@ -2,7 +2,11 @@
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:sensors_plus_aurora/orientation_event.dart'; import 'package:sensors_plus_aurora/events/als_event.dart';
import 'package:sensors_plus_aurora/events/compass_event.dart';
import 'package:sensors_plus_aurora/events/orientation_event.dart';
import 'package:sensors_plus_aurora/events/proximity_event.dart';
import 'package:sensors_plus_aurora/events/tap_event.dart';
import 'package:sensors_plus_platform_interface/sensors_plus_platform_interface.dart'; import 'package:sensors_plus_platform_interface/sensors_plus_platform_interface.dart';
import 'sensors_plus_aurora_method_channel.dart'; import 'sensors_plus_aurora_method_channel.dart';
@ -35,4 +39,28 @@ abstract class SensorsPlusAuroraPlatform extends PlatformInterface {
Stream<AccelerometerEvent> onChangeAccelerometer() { Stream<AccelerometerEvent> onChangeAccelerometer() {
throw UnimplementedError('onChangeAccelerometer() has not been implemented.'); throw UnimplementedError('onChangeAccelerometer() has not been implemented.');
} }
Stream<CompassEvent> onChangeCompass() {
throw UnimplementedError('onChangeCompass() has not been implemented.');
}
Stream<TapEvent> onChangeTap() {
throw UnimplementedError('onChangeTap() has not been implemented.');
}
Stream<ALSEvent> onChangeALS() {
throw UnimplementedError('onChangeALS() has not been implemented.');
}
Stream<ProximityEvent> onChangeProximity() {
throw UnimplementedError('onChangeProximity() has not been implemented.');
}
Stream<GyroscopeEvent> onChangeRotation() {
throw UnimplementedError('onChangeRotation() has not been implemented.');
}
Stream<MagnetometerEvent> onChangeMagnetometer() {
throw UnimplementedError('onChangeMagnetometer() has not been implemented.');
}
} }

Loading…
Cancel
Save