Vitaliy Zarubin
1 year ago
30 changed files with 1600 additions and 22 deletions
@ -0,0 +1,11 @@ |
|||||||
|
// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
// SPDX-License-Identifier: BSD-3-Clause |
||||||
|
import 'package:flutter/widgets.dart'; |
||||||
|
import 'package:scoped_model/scoped_model.dart'; |
||||||
|
|
||||||
|
/// Model for [SensorsPlusPage] |
||||||
|
class SensorsPlusModel extends Model { |
||||||
|
/// Get [ScopedModel] |
||||||
|
static SensorsPlusModel of(BuildContext context) => |
||||||
|
ScopedModel.of<SensorsPlusModel>(context); |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
// SPDX-License-Identifier: BSD-3-Clause |
||||||
|
import 'package:flutter_example_packages/base/package/package_page.dart'; |
||||||
|
import 'package:get_it/get_it.dart'; |
||||||
|
|
||||||
|
import 'model.dart'; |
||||||
|
import 'page.dart'; |
||||||
|
|
||||||
|
/// Package values |
||||||
|
final packageSensorsPlus = PackagePage( |
||||||
|
key: 'sensors_plus', |
||||||
|
descEN: ''' |
||||||
|
A Flutter plugin to access the accelerometer, gyroscope, |
||||||
|
magnetometer sensors, etc. |
||||||
|
''', |
||||||
|
descRU: ''' |
||||||
|
Плагин Flutter для доступа к датчикам акселерометра, |
||||||
|
гироскопа, магнитометра и т.д. |
||||||
|
''', |
||||||
|
version: '3.0.2', |
||||||
|
isPlatformDependent: true, |
||||||
|
page: () => SensorsPlusPage(), |
||||||
|
init: () { |
||||||
|
GetIt.instance.registerFactory<SensorsPlusModel>(() => SensorsPlusModel()); |
||||||
|
}, |
||||||
|
); |
@ -0,0 +1,209 @@ |
|||||||
|
// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
// SPDX-License-Identifier: BSD-3-Clause |
||||||
|
import 'package:flutter/material.dart'; |
||||||
|
import 'package:flutter_example_packages/base/di/app_di.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/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_gen/gen_l10n/app_localizations.dart'; |
||||||
|
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'; |
||||||
|
|
||||||
|
import 'model.dart'; |
||||||
|
import 'package.dart'; |
||||||
|
|
||||||
|
class SensorsPlusPage extends AppStatefulWidget { |
||||||
|
SensorsPlusPage({ |
||||||
|
super.key, |
||||||
|
}); |
||||||
|
|
||||||
|
final Package package = packageSensorsPlus; |
||||||
|
|
||||||
|
@override |
||||||
|
State<SensorsPlusPage> createState() => _SensorsPlusPageState(); |
||||||
|
} |
||||||
|
|
||||||
|
class _SensorsPlusPageState extends AppState<SensorsPlusPage> { |
||||||
|
Stream<OrientationEvent>? _orientationEvents; |
||||||
|
Stream<AccelerometerEvent>? _accelerometerEvents; |
||||||
|
Stream<CompassEvent>? _compassEvents; |
||||||
|
Stream<TapEvent>? _tapEvents; |
||||||
|
Stream<ALSEvent>? _alsEvents; |
||||||
|
Stream<ProximityEvent>? _proximityEvents; |
||||||
|
Stream<GyroscopeEvent>? _gyroscopeEvents; |
||||||
|
Stream<MagnetometerEvent>? _magnetometerEvents; |
||||||
|
|
||||||
|
@override |
||||||
|
void initState() { |
||||||
|
super.initState(); |
||||||
|
|
||||||
|
try { |
||||||
|
_orientationEvents = orientationEvents; |
||||||
|
} catch (e) { |
||||||
|
debugPrint(e.toString()); |
||||||
|
} |
||||||
|
try { |
||||||
|
_accelerometerEvents = accelerometerEvents; |
||||||
|
} catch (e) { |
||||||
|
debugPrint(e.toString()); |
||||||
|
} |
||||||
|
try { |
||||||
|
_compassEvents = compassEvents; |
||||||
|
} catch (e) { |
||||||
|
debugPrint(e.toString()); |
||||||
|
} |
||||||
|
try { |
||||||
|
_tapEvents = tapEvents; |
||||||
|
} catch (e) { |
||||||
|
debugPrint(e.toString()); |
||||||
|
} |
||||||
|
try { |
||||||
|
_alsEvents = alsEvents; |
||||||
|
} catch (e) { |
||||||
|
debugPrint(e.toString()); |
||||||
|
} |
||||||
|
try { |
||||||
|
_proximityEvents = proximityEvents; |
||||||
|
} catch (e) { |
||||||
|
debugPrint(e.toString()); |
||||||
|
} |
||||||
|
try { |
||||||
|
_gyroscopeEvents = gyroscopeEvents; |
||||||
|
} catch (e) { |
||||||
|
debugPrint(e.toString()); |
||||||
|
} |
||||||
|
try { |
||||||
|
_magnetometerEvents = magnetometerEvents; |
||||||
|
} catch (e) { |
||||||
|
debugPrint(e.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
Widget buildWide( |
||||||
|
BuildContext context, |
||||||
|
MediaQueryData media, |
||||||
|
AppLocalizations l10n, |
||||||
|
) { |
||||||
|
return BlockLayout<SensorsPlusModel>( |
||||||
|
model: getIt<SensorsPlusModel>(), |
||||||
|
title: widget.package.key, |
||||||
|
builder: (context, child, model) { |
||||||
|
return SingleChildScrollView( |
||||||
|
child: Padding( |
||||||
|
padding: const EdgeInsets.all(20), |
||||||
|
child: Column( |
||||||
|
crossAxisAlignment: CrossAxisAlignment.start, |
||||||
|
children: [ |
||||||
|
BlockInfoPackage(widget.package), |
||||||
|
Visibility( |
||||||
|
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(), |
||||||
|
), |
||||||
|
), |
||||||
|
Visibility( |
||||||
|
visible: _magnetometerEvents != null, |
||||||
|
child: BlockItem( |
||||||
|
isShowProgress: false, |
||||||
|
title: l10n.sensorsPlusTitleMagnetometer, |
||||||
|
desc: l10n.sensorsPlusSubtitle('magnetometersensor'), |
||||||
|
stream: _magnetometerEvents, |
||||||
|
builder: (value) => value == null |
||||||
|
? l10n.sensorsPlusNotFound |
||||||
|
: value.toString(), |
||||||
|
), |
||||||
|
), |
||||||
|
], |
||||||
|
), |
||||||
|
), |
||||||
|
); |
||||||
|
}, |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
# Miscellaneous |
||||||
|
*.class |
||||||
|
*.log |
||||||
|
*.pyc |
||||||
|
*.swp |
||||||
|
.DS_Store |
||||||
|
.atom/ |
||||||
|
.buildlog/ |
||||||
|
.history |
||||||
|
.svn/ |
||||||
|
migrate_working_dir/ |
||||||
|
|
||||||
|
# IntelliJ related |
||||||
|
*.iml |
||||||
|
*.ipr |
||||||
|
*.iws |
||||||
|
.idea/ |
||||||
|
|
||||||
|
# The .vscode folder contains launch configuration and tasks you configure in |
||||||
|
# VS Code which you may wish to be included in version control, so this line |
||||||
|
# is commented out by default. |
||||||
|
#.vscode/ |
||||||
|
|
||||||
|
# Flutter/Dart/Pub related |
||||||
|
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. |
||||||
|
/pubspec.lock |
||||||
|
**/doc/api/ |
||||||
|
.dart_tool/ |
||||||
|
.packages |
||||||
|
build/ |
@ -0,0 +1,30 @@ |
|||||||
|
# This file tracks properties of this Flutter project. |
||||||
|
# Used by Flutter tool to assess capabilities and perform upgrades etc. |
||||||
|
# |
||||||
|
# This file should be version controlled. |
||||||
|
|
||||||
|
version: |
||||||
|
revision: 135454af32477f815a7525073027a3ff9eff1bfd |
||||||
|
channel: aurora |
||||||
|
|
||||||
|
project_type: plugin |
||||||
|
|
||||||
|
# Tracks metadata for the flutter migrate command |
||||||
|
migration: |
||||||
|
platforms: |
||||||
|
- platform: root |
||||||
|
create_revision: 135454af32477f815a7525073027a3ff9eff1bfd |
||||||
|
base_revision: 135454af32477f815a7525073027a3ff9eff1bfd |
||||||
|
- platform: aurora |
||||||
|
create_revision: 135454af32477f815a7525073027a3ff9eff1bfd |
||||||
|
base_revision: 135454af32477f815a7525073027a3ff9eff1bfd |
||||||
|
|
||||||
|
# User provided section |
||||||
|
|
||||||
|
# List of Local paths (relative to this file) that should be |
||||||
|
# ignored by the migrate tool. |
||||||
|
# |
||||||
|
# Files that are not part of the templates will be ignored by default. |
||||||
|
unmanaged_files: |
||||||
|
- 'lib/main.dart' |
||||||
|
- 'ios/Runner.xcodeproj/project.pbxproj' |
@ -0,0 +1,138 @@ |
|||||||
|
# sensors_plus_aurora |
||||||
|
|
||||||
|
The Aurora implementation of [`sensors_plus`](https://pub.dev/packages/sensors_plus). |
||||||
|
|
||||||
|
## Usage |
||||||
|
|
||||||
|
This package is not an _endorsed_ implementation of `sensors_plus`. |
||||||
|
Therefore, you have to include `sensors_plus_aurora` alongside `sensors_plus` as dependencies in your `pubspec.yaml` file. |
||||||
|
|
||||||
|
**pubspec.yaml** |
||||||
|
|
||||||
|
```yaml |
||||||
|
dependencies: |
||||||
|
sensors_plus: ^4.0.0 |
||||||
|
sensors_plus_aurora: |
||||||
|
git: |
||||||
|
url: https://gitlab.com/omprussia/flutter/flutter-plugins.git |
||||||
|
ref: master |
||||||
|
path: packages/sensors_plus/sensors_plus_aurora |
||||||
|
``` |
||||||
|
|
||||||
|
## 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. |
||||||
|
|
||||||
|
***.desktop** |
||||||
|
|
||||||
|
```desktop |
||||||
|
Permissions=Sensors |
||||||
|
``` |
||||||
|
***.spec** |
||||||
|
|
||||||
|
```spec |
||||||
|
BuildRequires: pkgconfig(sensord-qt5) |
||||||
|
``` |
||||||
|
|
||||||
|
***.dart** |
||||||
|
|
||||||
|
```dart |
||||||
|
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()); |
||||||
|
} |
||||||
|
); |
||||||
|
``` |
@ -0,0 +1,4 @@ |
|||||||
|
# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
# SPDX-License-Identifier: BSD-3-Clause |
||||||
|
|
||||||
|
include: package:flutter_lints/flutter.yaml |
@ -0,0 +1,34 @@ |
|||||||
|
# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
# SPDX-License-Identifier: BSD-3-Clause |
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.10) |
||||||
|
|
||||||
|
set(PROJECT_NAME sensors_plus_aurora) |
||||||
|
set(PLUGIN_NAME sensors_plus_aurora_platform_plugin) |
||||||
|
|
||||||
|
project(${PROJECT_NAME} LANGUAGES CXX) |
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17) |
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-psabi") |
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "-O3") |
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED) |
||||||
|
find_package(Qt5 COMPONENTS Core Network DBus REQUIRED) |
||||||
|
|
||||||
|
pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) |
||||||
|
pkg_check_modules(SensordQt5 REQUIRED IMPORTED_TARGET sensord-qt5) |
||||||
|
|
||||||
|
add_library(${PLUGIN_NAME} SHARED sensors_plus_aurora_plugin.cpp) |
||||||
|
set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden AUTOMOC ON) |
||||||
|
|
||||||
|
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::FlutterEmbedder) |
||||||
|
target_link_libraries(${PLUGIN_NAME} PUBLIC Qt5::Core Qt5::Network Qt5::DBus) |
||||||
|
target_link_libraries(${PLUGIN_NAME} PUBLIC PkgConfig::SensordQt5) |
||||||
|
|
||||||
|
target_include_directories(${PLUGIN_NAME} PRIVATE ${FLUTTER_DIR}) |
||||||
|
target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) |
||||||
|
target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}) |
||||||
|
|
||||||
|
target_compile_definitions(${PLUGIN_NAME} PRIVATE PLUGIN_IMPL) |
@ -0,0 +1,15 @@ |
|||||||
|
/**
|
||||||
|
* SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
* SPDX-License-Identifier: BSD-3-Clause |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_GLOBALS_H |
||||||
|
#define FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_GLOBALS_H |
||||||
|
|
||||||
|
#ifdef PLUGIN_IMPL |
||||||
|
#define PLUGIN_EXPORT __attribute__((visibility("default"))) |
||||||
|
#else |
||||||
|
#define PLUGIN_EXPORT |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif /* FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_GLOBALS_H */ |
@ -0,0 +1,82 @@ |
|||||||
|
/**
|
||||||
|
* SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
* SPDX-License-Identifier: BSD-3-Clause |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H |
||||||
|
#define FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H |
||||||
|
|
||||||
|
#include <flutter/plugin-interface.h> |
||||||
|
#include <sensors_plus_aurora/globals.h> |
||||||
|
|
||||||
|
#include <QtCore> |
||||||
|
|
||||||
|
#include <accelerometersensor_i.h> |
||||||
|
#include <alssensor_i.h> |
||||||
|
#include <compasssensor_i.h> |
||||||
|
#include <magnetometersensor_i.h> |
||||||
|
#include <orientationsensor_i.h> |
||||||
|
#include <proximitysensor_i.h> |
||||||
|
#include <rotationsensor_i.h> |
||||||
|
#include <sensormanagerinterface.h> |
||||||
|
#include <tapsensor_i.h> |
||||||
|
|
||||||
|
class PLUGIN_EXPORT SensorsPlusAuroraPlugin final : public QObject, public PluginInterface |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
void RegisterWithRegistrar(PluginRegistrar ®istrar) override; |
||||||
|
|
||||||
|
public slots: |
||||||
|
void EventSensorOrientation(const Unsigned &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: |
||||||
|
template<typename T> |
||||||
|
bool RegisterSensorInterface(QString sensor); |
||||||
|
void EventChannelNull(const std::string &channel); |
||||||
|
void EventChannelData(const std::string &channel, const Encodable::List &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: |
||||||
|
OrientationSensorChannelInterface *m_ifaceOrientation = nullptr; |
||||||
|
AccelerometerSensorChannelInterface *m_ifaceAccelerometer = 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 */ |
@ -0,0 +1,493 @@ |
|||||||
|
/**
|
||||||
|
* SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
* SPDX-License-Identifier: BSD-3-Clause |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <flutter/method-channel.h> |
||||||
|
#include <sensors_plus_aurora/sensors_plus_aurora_plugin.h> |
||||||
|
#include <QDebug> |
||||||
|
|
||||||
|
#include <accelerometersensor_i.h> |
||||||
|
#include <alssensor_i.h> |
||||||
|
#include <compasssensor_i.h> |
||||||
|
#include <magnetometersensor_i.h> |
||||||
|
#include <orientationsensor_i.h> |
||||||
|
#include <proximitysensor_i.h> |
||||||
|
#include <rotationsensor_i.h> |
||||||
|
#include <sensormanagerinterface.h> |
||||||
|
#include <tapsensor_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"; |
||||||
|
} // namespace KeyChannel
|
||||||
|
|
||||||
|
namespace KeySensor { |
||||||
|
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 KeySensor
|
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) |
||||||
|
{ |
||||||
|
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(); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
template<typename T> |
||||||
|
bool SensorsPlusAuroraPlugin::RegisterSensorInterface(QString sensor) |
||||||
|
{ |
||||||
|
SensorManagerInterface &sm = SensorManagerInterface::instance(); |
||||||
|
if (!sm.isValid()) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
QDBusReply<bool> reply(sm.loadPlugin(sensor)); |
||||||
|
if (!reply.isValid() || !reply.value()) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
sm.registerSensorInterface<T>(sensor); |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::EventChannelNull(const std::string &channel) |
||||||
|
{ |
||||||
|
EventChannel(channel, MethodCodecType::Standard).SendEvent(nullptr); |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::EventChannelData(const std::string &channel, const Encodable::List &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() |
||||||
|
{ |
||||||
|
if (m_ifaceOrientation) { |
||||||
|
m_ifaceOrientation->stop(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::EventSensorOrientation(const Unsigned &data) |
||||||
|
{ |
||||||
|
EventChannelData(KeyChannel::Orientation, Encodable::List {data.x()}); |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* Accelerometer |
||||||
|
*/ |
||||||
|
void SensorsPlusAuroraPlugin::EnableSensorAccelerometer() |
||||||
|
{ |
||||||
|
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) { |
||||||
|
m_ifaceAccelerometer->stop(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::EventSensorAccelerometer(const XYZ &data) |
||||||
|
{ |
||||||
|
EventChannelData(KeyChannel::Accelerometer, Encodable::List {data.x(), data.y(), data.z()}); |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 &))); |
||||||
|
} |
||||||
|
|
||||||
|
m_ifaceCompass->start(); |
||||||
|
EventSensorCompass(m_ifaceCompass->get()); |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::DisableSensorCompass() |
||||||
|
{ |
||||||
|
if (m_ifaceCompass) { |
||||||
|
m_ifaceCompass->stop(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::EventSensorCompass(const Compass &data) |
||||||
|
{ |
||||||
|
EventChannelData(KeyChannel::Compass, Encodable::List {data.degrees(), data.level()}); |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* Tap |
||||||
|
*/ |
||||||
|
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 &))); |
||||||
|
} |
||||||
|
|
||||||
|
m_ifaceTap->start(); |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::DisableSensorTap() |
||||||
|
{ |
||||||
|
if (m_ifaceTap) { |
||||||
|
m_ifaceTap->stop(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::EventSensorTap(const Tap &data) |
||||||
|
{ |
||||||
|
EventChannelData(KeyChannel::Tap, Encodable::List { |
||||||
|
static_cast<int>(data.direction()), |
||||||
|
static_cast<int>(data.type()) |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* ALS |
||||||
|
*/ |
||||||
|
void SensorsPlusAuroraPlugin::EnableSensorALS() |
||||||
|
{ |
||||||
|
if (m_ifaceALS == nullptr) { |
||||||
|
if (!RegisterSensorInterface<ALSSensorChannelInterface>(KeySensor::ALS)) { |
||||||
|
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::DisableSensorALS() |
||||||
|
{ |
||||||
|
if (m_ifaceALS) { |
||||||
|
m_ifaceALS->stop(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::EventSensorALS(const Unsigned &data) |
||||||
|
{ |
||||||
|
EventChannelData(KeyChannel::ALS, Encodable::List {data.x()}); |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 &))); |
||||||
|
} |
||||||
|
|
||||||
|
m_ifaceProximity->start(); |
||||||
|
EventSensorProximity(m_ifaceProximity->proximityReflectance()); |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::DisableSensorProximity() |
||||||
|
{ |
||||||
|
if (m_ifaceProximity) { |
||||||
|
m_ifaceProximity->stop(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::EventSensorProximity(const Proximity &data) |
||||||
|
{ |
||||||
|
EventChannelData(KeyChannel::Proximity, Encodable::List {data.withinProximity() ? 1 : 0}); |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotation |
||||||
|
*/ |
||||||
|
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 &))); |
||||||
|
} |
||||||
|
|
||||||
|
m_ifaceRotation->start(); |
||||||
|
EventSensorRotation(m_ifaceRotation->rotation()); |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::DisableSensorRotation() |
||||||
|
{ |
||||||
|
if (m_ifaceRotation) { |
||||||
|
m_ifaceRotation->stop(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::EventSensorRotation(const XYZ &data) |
||||||
|
{ |
||||||
|
EventChannelData(KeyChannel::Rotation, Encodable::List {data.x(), data.y(), data.z()}); |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* Magnetometer |
||||||
|
*/ |
||||||
|
void SensorsPlusAuroraPlugin::EnableSensorMagnetometer() |
||||||
|
{ |
||||||
|
if (m_ifaceMagnetometer == nullptr) { |
||||||
|
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 &))); |
||||||
|
} |
||||||
|
|
||||||
|
m_ifaceMagnetometer->start(); |
||||||
|
EventSensorMagnetometer(m_ifaceMagnetometer->magneticField()); |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::DisableSensorMagnetometer() |
||||||
|
{ |
||||||
|
if (m_ifaceMagnetometer) { |
||||||
|
m_ifaceMagnetometer->stop(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SensorsPlusAuroraPlugin::EventSensorMagnetometer(const MagneticField &data) |
||||||
|
{ |
||||||
|
EventChannelData(KeyChannel::Magnetometer, Encodable::List {data.x(), data.y(), data.z()}); |
||||||
|
} |
||||||
|
|
||||||
|
#include "moc_sensors_plus_aurora_plugin.cpp" |
@ -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)]'; |
||||||
|
} |
@ -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)]'; |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
// SPDX-License-Identifier: BSD-3-Clause |
||||||
|
|
||||||
|
enum OrientationEvent { |
||||||
|
/// The orientation is unknown. |
||||||
|
undefined, |
||||||
|
|
||||||
|
/// The Top edge of the device is pointing up. |
||||||
|
topUp, |
||||||
|
|
||||||
|
/// The Top edge of the device is pointing down. |
||||||
|
topDown, |
||||||
|
|
||||||
|
/// The Left edge of the device is pointing up. |
||||||
|
leftUp, |
||||||
|
|
||||||
|
/// The Right edge of the device is pointing up. |
||||||
|
rightUp, |
||||||
|
|
||||||
|
/// The Face of the device is pointing up. |
||||||
|
faceUp, |
||||||
|
|
||||||
|
/// The Face of the device is pointing down. |
||||||
|
faceDown |
||||||
|
} |
@ -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)]'; |
||||||
|
} |
@ -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)]'; |
||||||
|
} |
@ -0,0 +1,93 @@ |
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
// SPDX-License-Identifier: BSD-3-Clause |
||||||
|
|
||||||
|
import 'package:flutter/foundation.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 'sensors_plus_aurora_platform_interface.dart'; |
||||||
|
|
||||||
|
/// A broadcast stream of events from the Aurora OS device orientation. |
||||||
|
Stream<OrientationEvent>? get orientationEvents { |
||||||
|
if (TargetPlatform.aurora == defaultTargetPlatform) { |
||||||
|
return SensorsPlusAurora().onChangeOrientation; |
||||||
|
} |
||||||
|
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 { |
||||||
|
static void registerWith() { |
||||||
|
SensorsPlatform.instance = SensorsPlusAurora(); |
||||||
|
} |
||||||
|
|
||||||
|
/// orientationsensor |
||||||
|
Stream<OrientationEvent> get onChangeOrientation => |
||||||
|
SensorsPlusAuroraPlatform.instance.onChangeOrientation(); |
||||||
|
|
||||||
|
/// accelerometersensor |
||||||
|
@override |
||||||
|
Stream<AccelerometerEvent> get accelerometerEvents => |
||||||
|
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(); |
||||||
|
} |
@ -0,0 +1,148 @@ |
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
// SPDX-License-Identifier: BSD-3-Clause |
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart'; |
||||||
|
import 'package:flutter/services.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 'sensors_plus_aurora_platform_interface.dart'; |
||||||
|
|
||||||
|
/// An implementation of [SensorsPlusAuroraPlatform] that uses method channels. |
||||||
|
class MethodChannelSensorsPlusAurora extends SensorsPlusAuroraPlatform { |
||||||
|
/// The method channel used to interact with the native platform. |
||||||
|
@visibleForTesting |
||||||
|
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 |
||||||
|
Stream<OrientationEvent> onChangeOrientation() async* { |
||||||
|
await for (final data |
||||||
|
in const EventChannel('sensors_plus_aurora_orientationsensor') |
||||||
|
.receiveBroadcastStream()) { |
||||||
|
switch (_loadData(data, 'orientationsensor')[0]) { |
||||||
|
case 1: |
||||||
|
yield OrientationEvent.rightUp; |
||||||
|
break; |
||||||
|
case 2: |
||||||
|
yield OrientationEvent.leftUp; |
||||||
|
break; |
||||||
|
case 3: |
||||||
|
yield OrientationEvent.topDown; |
||||||
|
break; |
||||||
|
case 4: |
||||||
|
yield OrientationEvent.topUp; |
||||||
|
break; |
||||||
|
case 5: |
||||||
|
yield OrientationEvent.faceDown; |
||||||
|
break; |
||||||
|
case 6: |
||||||
|
yield OrientationEvent.faceUp; |
||||||
|
break; |
||||||
|
default: |
||||||
|
yield OrientationEvent.undefined; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
Stream<AccelerometerEvent> onChangeAccelerometer() async* { |
||||||
|
await for (final data |
||||||
|
in const EventChannel('sensors_plus_aurora_accelerometersensor') |
||||||
|
.receiveBroadcastStream()) { |
||||||
|
final result = _loadData(data, 'accelerometersensor'); |
||||||
|
yield AccelerometerEvent( |
||||||
|
result[0].toDouble(), |
||||||
|
result[1].toDouble(), |
||||||
|
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(), |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
// SPDX-License-Identifier: BSD-3-Clause |
||||||
|
|
||||||
|
import 'package:plugin_platform_interface/plugin_platform_interface.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 'sensors_plus_aurora_method_channel.dart'; |
||||||
|
|
||||||
|
abstract class SensorsPlusAuroraPlatform extends PlatformInterface { |
||||||
|
/// Constructs a SensorsPlusAuroraPlatform. |
||||||
|
SensorsPlusAuroraPlatform() : super(token: _token); |
||||||
|
|
||||||
|
static final Object _token = Object(); |
||||||
|
|
||||||
|
static SensorsPlusAuroraPlatform _instance = MethodChannelSensorsPlusAurora(); |
||||||
|
|
||||||
|
/// The default instance of [SensorsPlusAuroraPlatform] to use. |
||||||
|
/// |
||||||
|
/// Defaults to [MethodChannelSensorsPlusAurora]. |
||||||
|
static SensorsPlusAuroraPlatform get instance => _instance; |
||||||
|
|
||||||
|
/// Platform-specific implementations should set this with their own |
||||||
|
/// platform-specific class that extends [SensorsPlusAuroraPlatform] when |
||||||
|
/// they register themselves. |
||||||
|
static set instance(SensorsPlusAuroraPlatform instance) { |
||||||
|
PlatformInterface.verifyToken(instance, _token); |
||||||
|
_instance = instance; |
||||||
|
} |
||||||
|
|
||||||
|
Stream<OrientationEvent> onChangeOrientation() { |
||||||
|
throw UnimplementedError('onChangeOrientation() has not been implemented.'); |
||||||
|
} |
||||||
|
|
||||||
|
Stream<AccelerometerEvent> onChangeAccelerometer() { |
||||||
|
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.'); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <community@omp.ru> |
||||||
|
# SPDX-License-Identifier: BSD-3-Clause |
||||||
|
|
||||||
|
name: sensors_plus_aurora |
||||||
|
description: A new Flutter plugin project. |
||||||
|
version: 0.0.1 |
||||||
|
|
||||||
|
environment: |
||||||
|
sdk: '>=2.18.6 <4.0.0' |
||||||
|
flutter: ">=3.0.0" |
||||||
|
|
||||||
|
dependencies: |
||||||
|
flutter: |
||||||
|
sdk: flutter |
||||||
|
plugin_platform_interface: ^2.0.2 |
||||||
|
sensors_plus_platform_interface: ^1.1.3 |
||||||
|
|
||||||
|
dev_dependencies: |
||||||
|
flutter_test: |
||||||
|
sdk: flutter |
||||||
|
flutter_lints: ^2.0.0 |
||||||
|
|
||||||
|
flutter: |
||||||
|
plugin: |
||||||
|
platforms: |
||||||
|
aurora: |
||||||
|
pluginClass: SensorsPlusAuroraPlugin |
||||||
|
dartPluginClass: SensorsPlusAurora |
Loading…
Reference in new issue