From 4d54d442d569dd30f650cc26efdab36ff19c6a85 Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Wed, 2 Aug 2023 14:48:54 +0300 Subject: [PATCH 1/6] [sensors-plus] Start implementation package sensors_plus. OMP#OS-17084 --- example/app_run.sh | 131 ++++++++++++++++++ .../sensors_plus_aurora/.gitignore | 30 ++++ .../sensors_plus_aurora/.metadata | 30 ++++ .../sensors_plus_aurora/README.md | 22 +++ .../sensors_plus_aurora/analysis_options.yaml | 4 + .../sensors_plus_aurora/aurora/CMakeLists.txt | 26 ++++ .../include/sensors_plus_aurora/globals.h | 15 ++ .../sensors_plus_aurora_plugin.h | 23 +++ .../aurora/sensors_plus_aurora_plugin.cpp | 43 ++++++ .../lib/sensors_plus_aurora.dart | 8 ++ .../sensors_plus_aurora_method_channel.dart | 17 +++ ...ensors_plus_aurora_platform_interface.dart | 29 ++++ .../sensors_plus_aurora/pubspec.yaml | 26 ++++ ...nsors_plus_aurora_method_channel_test.dart | 27 ++++ .../test/sensors_plus_aurora_test.dart | 32 +++++ 15 files changed, 463 insertions(+) create mode 100755 example/app_run.sh create mode 100644 packages/sensors_plus/sensors_plus_aurora/.gitignore create mode 100644 packages/sensors_plus/sensors_plus_aurora/.metadata create mode 100644 packages/sensors_plus/sensors_plus_aurora/README.md create mode 100644 packages/sensors_plus/sensors_plus_aurora/analysis_options.yaml create mode 100644 packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt create mode 100644 packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/globals.h create mode 100644 packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h create mode 100644 packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp create mode 100644 packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart create mode 100644 packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart create mode 100644 packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart create mode 100644 packages/sensors_plus/sensors_plus_aurora/pubspec.yaml create mode 100644 packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart create mode 100644 packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart diff --git a/example/app_run.sh b/example/app_run.sh new file mode 100755 index 0000000..4457e55 --- /dev/null +++ b/example/app_run.sh @@ -0,0 +1,131 @@ +#!/bin/bash + +## Copyright (c) 2023. Open Mobile Platform LLC. +## License: Proprietary. +## +## SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +# SPDX-License-Identifier: BSD-3-Clause +## Contact: https://community.omprussia.ru/open-source +## +## This file is part of the Aurora OS Application Template project. +## +## Redistribution and use in source and binary forms, +## with or without modification, are permitted provided +## that the following conditions are met: +## +## * Redistributions of source code must retain the above copyright notice, +## this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright notice, +## this list of conditions and the following disclaimer +## in the documentation and/or other materials provided with the distribution. +## * Neither the name of the copyright holder nor the names of its contributors +## may be used to endorse or promote products derived from this software +## without specific prior written permission. +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +## FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +## IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +## OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +## LOSS OF USE, DATA, OR PROFITS; +## OR BUSINESS INTERRUPTION) +## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +## WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) +## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +## Build example, sign rpm, upload/install/run rpm to device + +## Usage +## +## chmod +x ./run.sh +## +## ./run.sh \ +## -d : \ +## -s /home/user/sign/folder + +sudo echo 'Start...'; + +## Flutter path +FLUTTER="$HOME/.local/opt/flutter/bin/flutter" + +## https://developer.auroraos.ru/doc/software_development/psdk/setup +## Install Platform SDK path +## You may not have set the PSDK_DIR environment variable. +## export PSDK_DIR=$HOME/AuroraPlatformSDK/sdks/aurora_psdk + +while getopts d:s: flag; do + case "${flag}" in + d) device=${OPTARG} ;; + s) sign=${OPTARG} ;; + *) + echo "usage: $0 [-d] [-s]" >&2 + exit 1 + ;; + esac +done + +## Update dependency +$FLUTTER pub get + +## Generate internationalizing +$FLUTTER pub run build_runner build + +## Run ffigen +# $FLUTTER pub run ffigen + +## Build aurora example app +{ + $FLUTTER build aurora --release +} || { + exit 1; +} + +if [ -n "$sign" ]; then + + key=$(ls "$sign"/*key.pem) + + if [ -z "$key" ]; then + echo "Key *key.pem not found." + exit + fi + + cert=$(ls "$sign"/*cert.pem) + + if [ -z "$cert" ]; then + echo "Key *cert.pem not found." + exit + fi + + ## Sign rpm system key + "$PSDK_DIR"/sdk-chroot rpmsign-external sign \ + --key "$key" \ + --cert "$cert" \ + build/aurora/arm/release/RPMS/*.rpm +fi + +if [ -n "$device" ]; then + + PACKAGE="ru.auroraos.flutter_example_packages" + + IFS=':' read -ra ADDR <<< "$device" + + D_IP="${ADDR[0]}" + D_PASS="${ADDR[1]}" + + # shellcheck disable=SC2012 + rpm=$(ls "$PWD"/build/aurora/arm/release/RPMS/*.rpm | sort -r | head -n 1) + + # upload rpm + scp "$rpm" defaultuser@"$D_IP:/home/defaultuser/Downloads" + + # install rpm + ssh -t defaultuser@"$D_IP" "echo $D_PASS | devel-su pkcon -y install-local /home/defaultuser/Downloads/$PACKAGE*.rpm" + + # run application + ssh -t defaultuser@"$D_IP" "/usr/bin/$PACKAGE" +fi diff --git a/packages/sensors_plus/sensors_plus_aurora/.gitignore b/packages/sensors_plus/sensors_plus_aurora/.gitignore new file mode 100644 index 0000000..96486fd --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/.gitignore @@ -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/ diff --git a/packages/sensors_plus/sensors_plus_aurora/.metadata b/packages/sensors_plus/sensors_plus_aurora/.metadata new file mode 100644 index 0000000..641645c --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/.metadata @@ -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' diff --git a/packages/sensors_plus/sensors_plus_aurora/README.md b/packages/sensors_plus/sensors_plus_aurora/README.md new file mode 100644 index 0000000..6bcd18c --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/README.md @@ -0,0 +1,22 @@ +# 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: ^3.0.2 + sensors_plus_aurora: ^0.0.0 # @todo Not published +``` + +***.dart** + +```dart +// @todo +``` diff --git a/packages/sensors_plus/sensors_plus_aurora/analysis_options.yaml b/packages/sensors_plus/sensors_plus_aurora/analysis_options.yaml new file mode 100644 index 0000000..9e47db5 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/analysis_options.yaml @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +# SPDX-License-Identifier: BSD-3-Clause + +include: package:flutter_lints/flutter.yaml diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt b/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt new file mode 100644 index 0000000..fce5f12 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt @@ -0,0 +1,26 @@ +# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +# 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) +pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) + +add_library(${PLUGIN_NAME} SHARED sensors_plus_aurora_plugin.cpp) + +set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) +target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::FlutterEmbedder) + +target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) +target_compile_definitions(${PLUGIN_NAME} PRIVATE PLUGIN_IMPL) diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/globals.h b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/globals.h new file mode 100644 index 0000000..e07cf5f --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/globals.h @@ -0,0 +1,15 @@ +/** + * SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC + * 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 */ diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h new file mode 100644 index 0000000..a429249 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h @@ -0,0 +1,23 @@ +/** + * SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H +#define FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H + +#include +#include + +class PLUGIN_EXPORT SensorsPlusAuroraPlugin final : public PluginInterface +{ +public: + void RegisterWithRegistrar(PluginRegistrar ®istrar) override; + +private: + void onMethodCall(const MethodCall &call); + void onGetPlatformVersion(const MethodCall &call); + void unimplemented(const MethodCall &call); +}; + +#endif /* FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H */ diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp new file mode 100644 index 0000000..20224e0 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp @@ -0,0 +1,43 @@ +/** + * SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include + +void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) +{ + registrar.RegisterMethodChannel("sensors_plus_aurora", + MethodCodecType::Standard, + [this](const MethodCall &call) { this->onMethodCall(call); }); +} + +void SensorsPlusAuroraPlugin::onMethodCall(const MethodCall &call) +{ + const auto &method = call.GetMethod(); + + if (method == "getPlatformVersion") { + onGetPlatformVersion(call); + return; + } + + unimplemented(call); +} + +void SensorsPlusAuroraPlugin::onGetPlatformVersion(const MethodCall &call) +{ + utsname uname_data{}; + uname(&uname_data); + + std::string preamble = "Aurora (Linux): "; + std::string version = preamble + uname_data.version; + + call.SendSuccessResponse(version); +} + +void SensorsPlusAuroraPlugin::unimplemented(const MethodCall &call) +{ + call.SendSuccessResponse(nullptr); +} diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart new file mode 100644 index 0000000..bb338af --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart @@ -0,0 +1,8 @@ + +import 'sensors_plus_aurora_platform_interface.dart'; + +class SensorsPlusAurora { + Future getPlatformVersion() { + return SensorsPlusAuroraPlatform.instance.getPlatformVersion(); + } +} diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart new file mode 100644 index 0000000..3276f07 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart @@ -0,0 +1,17 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.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'); + + @override + Future getPlatformVersion() async { + final version = await methodChannel.invokeMethod('getPlatformVersion'); + return version; + } +} diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart new file mode 100644 index 0000000..b3f71e4 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart @@ -0,0 +1,29 @@ +import 'package:plugin_platform_interface/plugin_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; + } + + Future getPlatformVersion() { + throw UnimplementedError('platformVersion() has not been implemented.'); + } +} diff --git a/packages/sensors_plus/sensors_plus_aurora/pubspec.yaml b/packages/sensors_plus/sensors_plus_aurora/pubspec.yaml new file mode 100644 index 0000000..f78c456 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/pubspec.yaml @@ -0,0 +1,26 @@ +# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +# 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 <3.0.0' + flutter: ">=3.0.0" + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + +flutter: + plugin: + platforms: + aurora: + pluginClass: SensorsPlusAuroraPlugin diff --git a/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart b/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart new file mode 100644 index 0000000..8b01cf9 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause + +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:sensors_plus_aurora/sensors_plus_aurora_method_channel.dart'; + +void main() { + MethodChannelSensorsPlusAurora platform = MethodChannelSensorsPlusAurora(); + const MethodChannel channel = MethodChannel('sensors_plus_aurora'); + + TestWidgetsFlutterBinding.ensureInitialized(); + + setUp(() { + channel.setMockMethodCallHandler((MethodCall methodCall) async { + return '42'; + }); + }); + + tearDown(() { + channel.setMockMethodCallHandler(null); + }); + + test('getPlatformVersion', () async { + expect(await platform.getPlatformVersion(), '42'); + }); +} diff --git a/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart b/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart new file mode 100644 index 0000000..59beaa1 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart @@ -0,0 +1,32 @@ +// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause + +import 'package:flutter_test/flutter_test.dart'; +import 'package:sensors_plus_aurora/sensors_plus_aurora.dart'; +import 'package:sensors_plus_aurora/sensors_plus_aurora_platform_interface.dart'; +import 'package:sensors_plus_aurora/sensors_plus_aurora_method_channel.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +class MockSensorsPlusAuroraPlatform + with MockPlatformInterfaceMixin + implements SensorsPlusAuroraPlatform { + + @override + Future getPlatformVersion() => Future.value('42'); +} + +void main() { + final SensorsPlusAuroraPlatform initialPlatform = SensorsPlusAuroraPlatform.instance; + + test('$MethodChannelSensorsPlusAurora is the default instance', () { + expect(initialPlatform, isInstanceOf()); + }); + + test('getPlatformVersion', () async { + SensorsPlusAurora sensorsPlusAuroraPlugin = SensorsPlusAurora(); + MockSensorsPlusAuroraPlatform fakePlatform = MockSensorsPlusAuroraPlatform(); + SensorsPlusAuroraPlatform.instance = fakePlatform; + + expect(await sensorsPlusAuroraPlugin.getPlatformVersion(), '42'); + }); +} From 66d515b8dbacafc5e0b32b3a55d407a2d2f9f51f Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Wed, 2 Aug 2023 15:28:17 +0300 Subject: [PATCH 2/6] [sensors-plus] Add start package demo sensors. OMP#OS-17084 --- example/lib/packages/packages.dart | 2 + example/lib/packages/sensors_plus/model.dart | 11 + .../lib/packages/sensors_plus/package.dart | 26 + example/lib/packages/sensors_plus/page.dart | 53 + example/pubspec.lock | 1138 +++++++++++++++++ 5 files changed, 1230 insertions(+) create mode 100644 example/lib/packages/sensors_plus/model.dart create mode 100644 example/lib/packages/sensors_plus/package.dart create mode 100644 example/lib/packages/sensors_plus/page.dart create mode 100644 example/pubspec.lock diff --git a/example/lib/packages/packages.dart b/example/lib/packages/packages.dart index f590335..ee6c781 100644 --- a/example/lib/packages/packages.dart +++ b/example/lib/packages/packages.dart @@ -29,6 +29,7 @@ import 'package:flutter_example_packages/packages/provider/package.dart'; import 'package:flutter_example_packages/packages/qr_flutter/package.dart'; import 'package:flutter_example_packages/packages/rxdart/package.dart'; import 'package:flutter_example_packages/packages/scoped_model/package.dart'; +import 'package:flutter_example_packages/packages/sensors_plus/package.dart'; import 'package:flutter_example_packages/packages/shared_preferences/package.dart'; import 'package:flutter_example_packages/packages/sqflite/package.dart'; import 'package:flutter_example_packages/packages/translator/package.dart'; @@ -66,6 +67,7 @@ final packages = [ packageQrFlutter, packageRxdart, packageScopedModel, + packageSensorsPlus, packageSharedPreferences, packageSqflite, packageTranslator, diff --git a/example/lib/packages/sensors_plus/model.dart b/example/lib/packages/sensors_plus/model.dart new file mode 100644 index 0000000..50cfb69 --- /dev/null +++ b/example/lib/packages/sensors_plus/model.dart @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +// 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(context); +} diff --git a/example/lib/packages/sensors_plus/package.dart b/example/lib/packages/sensors_plus/package.dart new file mode 100644 index 0000000..a4a065f --- /dev/null +++ b/example/lib/packages/sensors_plus/package.dart @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +// 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, + and magnetometer sensors. + ''', + descRU: ''' + Плагин Flutter для доступа к датчикам акселерометра, + гироскопа и магнитометра. + ''', + version: '3.0.2', + isPlatformDependent: false, + page: () => SensorsPlusPage(), + init: () { + GetIt.instance.registerFactory(() => SensorsPlusModel()); + }, +); diff --git a/example/lib/packages/sensors_plus/page.dart b/example/lib/packages/sensors_plus/page.dart new file mode 100644 index 0000000..d2ffe96 --- /dev/null +++ b/example/lib/packages/sensors_plus/page.dart @@ -0,0 +1,53 @@ +// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +// 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/layouts/block_layout.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +import 'model.dart'; +import 'package.dart'; + +class SensorsPlusPage extends AppStatefulWidget { + SensorsPlusPage({ + super.key, + }); + + final Package package = packageSensorsPlus; + + @override + State createState() => _SensorsPlusPageState(); +} + +class _SensorsPlusPageState extends AppState { + @override + Widget buildWide( + BuildContext context, + MediaQueryData media, + AppLocalizations l10n, + ) { + return BlockLayout( + model: getIt(), + 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), + const Center( + child: Text('YES'), + ) + ], + ), + ), + ); + }, + ); + } +} diff --git a/example/pubspec.lock b/example/pubspec.lock new file mode 100644 index 0000000..ce03bd3 --- /dev/null +++ b/example/pubspec.lock @@ -0,0 +1,1138 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "50.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + url: "https://pub.dartlang.org" + source: hosted + version: "5.2.0" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.1" + asn1lib: + dependency: transitive + description: + name: asn1lib + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.1" + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.9.0" + battery_plus: + dependency: "direct main" + description: + name: battery_plus + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.2" + battery_plus_aurora: + dependency: "direct main" + description: + path: "packages/battery_plus/battery_plus_aurora" + ref: flutter_example_packages + resolved-ref: "0e7f1d3e354fac9e71cc9251b80958f2938176ba" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" + battery_plus_platform_interface: + dependency: transitive + description: + name: battery_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.2" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + build: + dependency: transitive + description: + name: build + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.1" + build_config: + dependency: transitive + description: + name: build_config + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + build_daemon: + dependency: transitive + description: + name: build_daemon + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + build_runner: + dependency: "direct dev" + description: + name: build_runner + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.3" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + url: "https://pub.dartlang.org" + source: hosted + version: "7.2.7" + built_collection: + dependency: transitive + description: + name: built_collection + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + url: "https://pub.dartlang.org" + source: hosted + version: "8.6.1" + cached_network_image: + dependency: "direct main" + description: + name: cached_network_image + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.3" + cached_network_image_platform_interface: + dependency: transitive + description: + name: cached_network_image_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + cached_network_image_web: + dependency: transitive + description: + name: cached_network_image_web + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + code_builder: + dependency: transitive + description: + name: code_builder + url: "https://pub.dartlang.org" + source: hosted + version: "4.4.0" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.16.0" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" + crypto: + dependency: "direct main" + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.5" + dart_style: + dependency: transitive + description: + name: dart_style + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.5" + dartz: + dependency: "direct main" + description: + name: dartz + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.1" + dbus: + dependency: transitive + description: + name: dbus + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.8" + device_info_plus: + dependency: "direct main" + description: + name: device_info_plus + url: "https://pub.dartlang.org" + source: hosted + version: "8.2.2" + device_info_plus_aurora: + dependency: "direct main" + description: + path: "packages/device_info_plus/device_info_plus_aurora" + ref: flutter_example_packages + resolved-ref: "0e7f1d3e354fac9e71cc9251b80958f2938176ba" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" + device_info_plus_platform_interface: + dependency: transitive + description: + name: device_info_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "7.0.0" + encrypt: + dependency: transitive + description: + name: encrypt + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.1" + equatable: + dependency: "direct main" + description: + name: equatable + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.4" + fixnum: + dependency: transitive + description: + name: fixnum + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_blurhash: + dependency: transitive + description: + name: flutter_blurhash + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.0" + flutter_cache_manager: + dependency: "direct main" + description: + name: flutter_cache_manager + url: "https://pub.dartlang.org" + source: hosted + version: "3.3.1" + flutter_keyboard_visibility: + dependency: "direct main" + description: + name: flutter_keyboard_visibility + url: "https://pub.dartlang.org" + source: hosted + version: "5.4.1" + flutter_keyboard_visibility_aurora: + dependency: "direct main" + description: + path: "packages/flutter_keyboard_visibility/flutter_keyboard_visibility_aurora" + ref: flutter_example_packages + resolved-ref: "0e7f1d3e354fac9e71cc9251b80958f2938176ba" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" + flutter_keyboard_visibility_linux: + dependency: transitive + description: + name: flutter_keyboard_visibility_linux + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + flutter_keyboard_visibility_macos: + dependency: transitive + description: + name: flutter_keyboard_visibility_macos + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + flutter_keyboard_visibility_platform_interface: + dependency: transitive + description: + name: flutter_keyboard_visibility_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + flutter_keyboard_visibility_web: + dependency: transitive + description: + name: flutter_keyboard_visibility_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + flutter_keyboard_visibility_windows: + dependency: transitive + description: + name: flutter_keyboard_visibility_windows + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + flutter_local_notifications: + dependency: "direct main" + description: + name: flutter_local_notifications + url: "https://pub.dartlang.org" + source: hosted + version: "14.1.2" + flutter_local_notifications_aurora: + dependency: "direct main" + description: + path: "packages/flutter_local_notifications/flutter_local_notifications_aurora" + ref: flutter_example_packages + resolved-ref: "0e7f1d3e354fac9e71cc9251b80958f2938176ba" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" + flutter_local_notifications_linux: + dependency: transitive + description: + name: flutter_local_notifications_linux + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0+1" + flutter_local_notifications_platform_interface: + dependency: transitive + description: + name: flutter_local_notifications_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "7.0.0+1" + flutter_localizations: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_markdown: + dependency: "direct main" + description: + name: flutter_markdown + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.15" + flutter_secure_storage: + dependency: "direct main" + description: + name: flutter_secure_storage + url: "https://pub.dartlang.org" + source: hosted + version: "8.0.0" + flutter_secure_storage_aurora: + dependency: "direct main" + description: + path: "packages/flutter_secure_storage/flutter_secure_storage_aurora" + ref: flutter_example_packages + resolved-ref: "0e7f1d3e354fac9e71cc9251b80958f2938176ba" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" + flutter_secure_storage_linux: + dependency: transitive + description: + name: flutter_secure_storage_linux + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.3" + flutter_secure_storage_macos: + dependency: transitive + description: + name: flutter_secure_storage_macos + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" + flutter_secure_storage_platform_interface: + dependency: transitive + description: + name: flutter_secure_storage_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + flutter_secure_storage_web: + dependency: transitive + description: + name: flutter_secure_storage_web + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + flutter_secure_storage_windows: + dependency: transitive + description: + name: flutter_secure_storage_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + freezed: + dependency: "direct dev" + description: + name: freezed + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.3" + freezed_annotation: + dependency: "direct main" + description: + name: freezed_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.1" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.0" + get_it: + dependency: "direct main" + description: + name: get_it + url: "https://pub.dartlang.org" + source: hosted + version: "7.6.0" + glob: + dependency: transitive + description: + name: glob + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + google_fonts: + dependency: "direct main" + description: + name: google_fonts + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.4" + graphs: + dependency: transitive + description: + name: graphs + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.1" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.13.5" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.2" + intl: + dependency: "direct main" + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.17.0" + io: + dependency: transitive + description: + name: io + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" + json_annotation: + dependency: "direct main" + description: + name: json_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "4.8.0" + json_serializable: + dependency: "direct dev" + description: + name: json_serializable + url: "https://pub.dartlang.org" + source: hosted + version: "6.6.1" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + markdown: + dependency: transitive + description: + name: markdown + url: "https://pub.dartlang.org" + source: hosted + version: "7.0.1" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.12" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.5" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + nested: + dependency: transitive + description: + name: nested + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + octo_image: + dependency: transitive + description: + name: octo_image + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + package_info_plus: + dependency: "direct main" + description: + name: package_info_plus + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.2" + package_info_plus_aurora: + dependency: "direct main" + description: + path: "packages/package_info_plus/package_info_plus_aurora" + ref: flutter_example_packages + resolved-ref: "0e7f1d3e354fac9e71cc9251b80958f2938176ba" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + path: + dependency: "direct main" + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.2" + path_provider: + dependency: "direct main" + description: + name: path_provider + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.15" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.27" + path_provider_aurora: + dependency: "direct main" + description: + path: "packages/path_provider/path_provider_aurora" + ref: flutter_example_packages + resolved-ref: "0e7f1d3e354fac9e71cc9251b80958f2938176ba" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" + path_provider_foundation: + dependency: transitive + description: + name: path_provider_foundation + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.4" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.11" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.7" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.0" + photo_view: + dependency: "direct main" + description: + name: photo_view + url: "https://pub.dartlang.org" + source: hosted + version: "0.14.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.5" + pointycastle: + dependency: transitive + description: + name: pointycastle + url: "https://pub.dartlang.org" + source: hosted + version: "3.7.3" + pool: + dependency: transitive + description: + name: pool + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.1" + provider: + dependency: "direct main" + description: + name: provider + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.5" + pub_semver: + dependency: transitive + description: + name: pub_semver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.3" + qr: + dependency: transitive + description: + name: qr + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + qr_flutter: + dependency: "direct main" + description: + name: qr_flutter + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0" + rxdart: + dependency: "direct main" + description: + name: rxdart + url: "https://pub.dartlang.org" + source: hosted + version: "0.27.7" + scoped_model: + dependency: "direct main" + description: + name: scoped_model + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + shared_preferences_android: + dependency: transitive + description: + name: shared_preferences_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + shared_preferences_aurora: + dependency: "direct main" + description: + path: "packages/shared_preferences/shared_preferences_aurora" + ref: flutter_example_packages + resolved-ref: "0e7f1d3e354fac9e71cc9251b80958f2938176ba" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" + shared_preferences_foundation: + dependency: transitive + description: + name: shared_preferences_foundation + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.2" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.0" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.0" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.3.0" + shelf: + dependency: transitive + description: + name: shelf + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.1" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_gen: + dependency: transitive + description: + name: source_gen + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.2" + source_helper: + dependency: transitive + description: + name: source_helper + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.3" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.0" + sqflite: + dependency: "direct main" + description: + name: sqflite + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.8+4" + sqflite_aurora: + dependency: "direct main" + description: + path: "packages/sqflite/sqflite_aurora" + ref: flutter_example_packages + resolved-ref: "0e7f1d3e354fac9e71cc9251b80958f2938176ba" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "2.2.6+aurora1" + sqflite_common: + dependency: transitive + description: + name: sqflite_common + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.5+1" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + stream_transform: + dependency: transitive + description: + name: stream_transform + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + synchronized: + dependency: transitive + description: + name: synchronized + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.12" + timezone: + dependency: transitive + description: + name: timezone + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.2" + timing: + dependency: transitive + description: + name: timing + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + translator: + dependency: "direct main" + description: + name: translator + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.7" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.2" + universal_io: + dependency: "direct main" + description: + name: universal_io + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + upower: + dependency: transitive + description: + name: upower + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.0" + uuid: + dependency: transitive + description: + name: uuid + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.7" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" + wakelock: + dependency: "direct main" + description: + name: wakelock + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.2" + wakelock_aurora: + dependency: "direct main" + description: + path: "packages/wakelock/wakelock_aurora" + ref: flutter_example_packages + resolved-ref: "0e7f1d3e354fac9e71cc9251b80958f2938176ba" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" + wakelock_macos: + dependency: transitive + description: + name: wakelock_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.0" + wakelock_platform_interface: + dependency: transitive + description: + name: wakelock_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" + wakelock_web: + dependency: transitive + description: + name: wakelock_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.0" + wakelock_windows: + dependency: transitive + description: + name: wakelock_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.1" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.4" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + xdga_directories: + dependency: "direct main" + description: + path: "packages/xdga_directories" + ref: flutter_example_packages + resolved-ref: "0e7f1d3e354fac9e71cc9251b80958f2938176ba" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.0" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" +sdks: + dart: ">=2.18.6 <3.0.0" + flutter: ">=3.3.0" From 3a0c1b01d8bde13a068a1991c51ca4529bc6dec7 Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Wed, 2 Aug 2023 19:12:23 +0300 Subject: [PATCH 3/6] [sensors-plus] Add Qt to plugin. OMP#OS-17084 --- example/app_run.sh | 37 +---------- .../ru.auroraos.flutter_example_packages.spec | 1 + .../lib/packages/sensors_plus/package.dart | 2 +- example/lib/packages/sensors_plus/page.dart | 20 ++++++ example/pubspec.lock | 21 ++++++ example/pubspec.yaml | 6 ++ .../sensors_plus_aurora/aurora/CMakeLists.txt | 10 ++- .../sensors_plus_aurora_plugin.h | 19 +++++- .../aurora/sensors_plus_aurora_plugin.cpp | 65 ++++++++++++++++--- .../lib/sensors_plus_aurora.dart | 4 +- .../sensors_plus_aurora_method_channel.dart | 4 +- ...ensors_plus_aurora_platform_interface.dart | 4 +- 12 files changed, 138 insertions(+), 55 deletions(-) diff --git a/example/app_run.sh b/example/app_run.sh index 4457e55..1a7744b 100755 --- a/example/app_run.sh +++ b/example/app_run.sh @@ -1,42 +1,7 @@ #!/bin/bash -## Copyright (c) 2023. Open Mobile Platform LLC. -## License: Proprietary. -## -## SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC +# SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC # SPDX-License-Identifier: BSD-3-Clause -## Contact: https://community.omprussia.ru/open-source -## -## This file is part of the Aurora OS Application Template project. -## -## Redistribution and use in source and binary forms, -## with or without modification, are permitted provided -## that the following conditions are met: -## -## * Redistributions of source code must retain the above copyright notice, -## this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright notice, -## this list of conditions and the following disclaimer -## in the documentation and/or other materials provided with the distribution. -## * Neither the name of the copyright holder nor the names of its contributors -## may be used to endorse or promote products derived from this software -## without specific prior written permission. -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -## FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -## IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -## OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -## LOSS OF USE, DATA, OR PROFITS; -## OR BUSINESS INTERRUPTION) -## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -## WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) -## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## Build example, sign rpm, upload/install/run rpm to device diff --git a/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec b/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec index 2c965f8..560769d 100644 --- a/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec +++ b/example/aurora/rpm/ru.auroraos.flutter_example_packages.spec @@ -11,6 +11,7 @@ Source0: %{name}-%{version}.tar.zst BuildRequires: cmake BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(flutter-embedder) +BuildRequires: pkgconfig(sensord-qt5) %description %{summary}. diff --git a/example/lib/packages/sensors_plus/package.dart b/example/lib/packages/sensors_plus/package.dart index a4a065f..76c2b77 100644 --- a/example/lib/packages/sensors_plus/package.dart +++ b/example/lib/packages/sensors_plus/package.dart @@ -18,7 +18,7 @@ final packageSensorsPlus = PackagePage( гироскопа и магнитометра. ''', version: '3.0.2', - isPlatformDependent: false, + isPlatformDependent: true, page: () => SensorsPlusPage(), init: () { GetIt.instance.registerFactory(() => SensorsPlusModel()); diff --git a/example/lib/packages/sensors_plus/page.dart b/example/lib/packages/sensors_plus/page.dart index d2ffe96..8a1c6ee 100644 --- a/example/lib/packages/sensors_plus/page.dart +++ b/example/lib/packages/sensors_plus/page.dart @@ -7,6 +7,8 @@ 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/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/sensors_plus_aurora.dart'; import 'model.dart'; import 'package.dart'; @@ -23,6 +25,24 @@ class SensorsPlusPage extends AppStatefulWidget { } class _SensorsPlusPageState extends AppState { + + @override + void initState() { + super.initState(); + + /// Listen change + // accelerometerEvents.listen((AccelerometerEvent event) { + // debugPrint(event.toString()); + // }, + // onError: (error) { + // debugPrint(error.toString()); + // }, + // cancelOnError: true, + // ); + + SensorsPlusAurora().listenSensor().then((value) => debugPrint('yes')); + } + @override Widget buildWide( BuildContext context, diff --git a/example/pubspec.lock b/example/pubspec.lock index ce03bd3..a27313f 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -812,6 +812,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + sensors_plus: + dependency: "direct main" + description: + name: sensors_plus + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.3" + sensors_plus_aurora: + dependency: "direct main" + description: + path: "../packages/sensors_plus/sensors_plus_aurora" + relative: true + source: path + version: "0.0.1" + sensors_plus_platform_interface: + dependency: transitive + description: + name: sensors_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.3" shared_preferences: dependency: "direct main" description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 6312323..372c6d5 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -154,6 +154,12 @@ dependencies: ref: master path: packages/sqflite/sqflite_aurora + ## https://pub.dev/packages/sensors_plus + sensors_plus: ^3.0.3 + ## https://os-git.omprussia.ru/non-oss/flutter/flutter-plugins/-/tree/master/packages/sensors_plus/sensors_plus_aurora + sensors_plus_aurora: + path: ../packages/sensors_plus/sensors_plus_aurora + dev_dependencies: flutter_test: sdk: diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt b/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt index fce5f12..3b554a9 100644 --- a/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/CMakeLists.txt @@ -15,12 +15,20 @@ 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) -set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) 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) diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h index a429249..0403b1c 100644 --- a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h @@ -9,15 +9,30 @@ #include #include -class PLUGIN_EXPORT SensorsPlusAuroraPlugin final : public PluginInterface +#include + +#include +#include + +class PLUGIN_EXPORT SensorsPlusAuroraPlugin final + : public QObject + , public PluginInterface { + Q_OBJECT + public: void RegisterWithRegistrar(PluginRegistrar ®istrar) override; +public slots: + void receivedData(const Unsigned &data); + private: void onMethodCall(const MethodCall &call); - void onGetPlatformVersion(const MethodCall &call); + void onListenSensor(const MethodCall &call); void unimplemented(const MethodCall &call); + +private: + AbstractSensorChannelInterface *m_iface = nullptr; }; #endif /* FLUTTER_PLUGIN_SENSORS_PLUS_AURORA_PLUGIN_H */ diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp index 20224e0..89e7d23 100644 --- a/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp @@ -5,7 +5,18 @@ #include #include -#include +#include + +#include +#include + +static AbstractSensorChannelInterface *iface; + +namespace { + +constexpr auto METHOD_LISTEN_SENSOR = "listenSensor"; + +} /* namespace */ void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) { @@ -18,26 +29,62 @@ void SensorsPlusAuroraPlugin::onMethodCall(const MethodCall &call) { const auto &method = call.GetMethod(); - if (method == "getPlatformVersion") { - onGetPlatformVersion(call); + if (method == "listenSensor") { + onListenSensor(call); return; } unimplemented(call); } -void SensorsPlusAuroraPlugin::onGetPlatformVersion(const MethodCall &call) +void SensorsPlusAuroraPlugin::onListenSensor(const MethodCall &call) { - utsname uname_data{}; - uname(&uname_data); + if (iface != nullptr) { + unimplemented(call); + return; + } + + SensorManagerInterface &sm = SensorManagerInterface::instance(); + if (!sm.isValid()) { + qDebug() << "Failed to create SensorManagerInterface"; + exit(0); + } + + QDBusReply reply(sm.loadPlugin("orientationsensor")); + if (!reply.isValid() || !reply.value()) { + qDebug() << "Failed to load plugin"; + exit(0); + } - std::string preamble = "Aurora (Linux): "; - std::string version = preamble + uname_data.version; + sm.registerSensorInterface("orientationsensor"); - call.SendSuccessResponse(version); + iface = OrientationSensorChannelInterface::interface("orientationsensor"); + qDebug() << "iface -> " << iface->thread(); + + if (!iface) { + qDebug() << "Cannot get OrientationSensorChannelInterface"; + exit(0); + } + + connect(iface, SIGNAL(orientationChanged(const Unsigned&)), + this, SLOT(receivedData(const Unsigned&))); + + qDebug() << "Created sensor: " << iface->description(); + iface->start(); + + qDebug() << "Received data start"; + + unimplemented(call); +} + +void SensorsPlusAuroraPlugin::receivedData(const Unsigned &data) +{ + qDebug() << "receivedData: " << data.x(); } void SensorsPlusAuroraPlugin::unimplemented(const MethodCall &call) { call.SendSuccessResponse(nullptr); } + +#include "moc_sensors_plus_aurora_plugin.cpp" diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart index bb338af..4c2003a 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart @@ -2,7 +2,7 @@ import 'sensors_plus_aurora_platform_interface.dart'; class SensorsPlusAurora { - Future getPlatformVersion() { - return SensorsPlusAuroraPlatform.instance.getPlatformVersion(); + Future listenSensor() { + return SensorsPlusAuroraPlatform.instance.listenSensor(); } } diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart index 3276f07..dbd3a52 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart @@ -10,8 +10,8 @@ class MethodChannelSensorsPlusAurora extends SensorsPlusAuroraPlatform { final methodChannel = const MethodChannel('sensors_plus_aurora'); @override - Future getPlatformVersion() async { - final version = await methodChannel.invokeMethod('getPlatformVersion'); + Future listenSensor() async { + final version = await methodChannel.invokeMethod('listenSensor'); return version; } } diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart index b3f71e4..728a052 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart @@ -23,7 +23,7 @@ abstract class SensorsPlusAuroraPlatform extends PlatformInterface { _instance = instance; } - Future getPlatformVersion() { - throw UnimplementedError('platformVersion() has not been implemented.'); + Future listenSensor() { + throw UnimplementedError('listenSensor() has not been implemented.'); } } From 4a653eb09b9bd462399d300a058a3bd1e776dea6 Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Thu, 3 Aug 2023 16:44:39 +0300 Subject: [PATCH 4/6] [sensors-plus] Add onChangeOrientation, accelerometerEvents. OMP#OS-17084 --- example/aurora/main.cpp | 2 + example/lib/packages/sensors_plus/page.dart | 51 ++++++-- example/pubspec.lock | 8 +- .../sensors_plus_aurora_plugin.h | 9 +- .../aurora/sensors_plus_aurora_plugin.cpp | 115 +++++++++++++++--- .../lib/orientation_event.dart | 19 +++ .../lib/sensors_plus_aurora.dart | 27 +++- .../sensors_plus_aurora_method_channel.dart | 48 +++++++- ...ensors_plus_aurora_platform_interface.dart | 13 +- .../sensors_plus_aurora/pubspec.yaml | 2 + ...nsors_plus_aurora_method_channel_test.dart | 27 ---- .../test/sensors_plus_aurora_test.dart | 32 ----- 12 files changed, 251 insertions(+), 102 deletions(-) create mode 100644 packages/sensors_plus/sensors_plus_aurora/lib/orientation_event.dart delete mode 100644 packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart delete mode 100644 packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart diff --git a/example/aurora/main.cpp b/example/aurora/main.cpp index 6677776..383acc5 100644 --- a/example/aurora/main.cpp +++ b/example/aurora/main.cpp @@ -3,10 +3,12 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include +#include #include "generated_plugin_registrant.h" int main(int argc, char *argv[]) { Application::Initialize(argc, argv); + EnableQtCompatibility(); RegisterPlugins(); Application::Launch(); return 0; diff --git a/example/lib/packages/sensors_plus/page.dart b/example/lib/packages/sensors_plus/page.dart index 8a1c6ee..427bb33 100644 --- a/example/lib/packages/sensors_plus/page.dart +++ b/example/lib/packages/sensors_plus/page.dart @@ -8,6 +8,7 @@ import 'package:flutter_example_packages/widgets/blocks/block_info_package.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/orientation_event.dart'; import 'package:sensors_plus_aurora/sensors_plus_aurora.dart'; import 'model.dart'; @@ -25,22 +26,42 @@ class SensorsPlusPage extends AppStatefulWidget { } class _SensorsPlusPageState extends AppState { + OrientationEvent orientation = OrientationEvent.undefined; + AccelerometerEvent accelerometer = AccelerometerEvent(0, 0, 0); @override void initState() { super.initState(); - /// Listen change - // accelerometerEvents.listen((AccelerometerEvent event) { - // debugPrint(event.toString()); - // }, - // onError: (error) { - // debugPrint(error.toString()); - // }, - // cancelOnError: true, - // ); + /// Accelerometer change + accelerometerEvents.listen( + (AccelerometerEvent event) { + if (mounted) { + setState(() { + accelerometer = event; + }); + } + }, + onError: (error) { + debugPrint(error.toString()); + }, + cancelOnError: true, + ); - SensorsPlusAurora().listenSensor().then((value) => debugPrint('yes')); + /// Only Aurora OS orientation change + orientationEvents?.listen( + (OrientationEvent event) { + if (mounted) { + setState(() { + orientation = event; + }); + } + }, + onError: (error) { + debugPrint(error.toString()); + }, + cancelOnError: true, + ); } @override @@ -60,9 +81,13 @@ class _SensorsPlusPageState extends AppState { crossAxisAlignment: CrossAxisAlignment.start, children: [ BlockInfoPackage(widget.package), - const Center( - child: Text('YES'), - ) + Center( + child: Text('Orientation: $orientation'), + ), + const SizedBox(height: 20,), + Center( + child: Text('Accelerometer: $accelerometer'), + ), ], ), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index a27313f..e32084a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -683,7 +683,7 @@ packages: name: path_provider_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.27" + version: "2.1.0" path_provider_aurora: dependency: "direct main" description: @@ -699,14 +699,14 @@ packages: name: path_provider_foundation url: "https://pub.dartlang.org" source: hosted - version: "2.2.4" + version: "2.3.0" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "2.1.11" + version: "2.2.0" path_provider_platform_interface: dependency: transitive description: @@ -720,7 +720,7 @@ packages: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.1.7" + version: "2.2.0" petitparser: dependency: transitive description: diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h index 0403b1c..2e121ab 100644 --- a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h @@ -13,6 +13,7 @@ #include #include +#include class PLUGIN_EXPORT SensorsPlusAuroraPlugin final : public QObject @@ -24,14 +25,18 @@ public: void RegisterWithRegistrar(PluginRegistrar ®istrar) override; public slots: - void receivedData(const Unsigned &data); + void eventSensorOrientation(const Unsigned &data); + void eventSensorAccelerometer(const XYZ& data); private: void onMethodCall(const MethodCall &call); - void onListenSensor(const MethodCall &call); + void onListenSensorOrientation(); + void onListenSensorAccelerometer(); void unimplemented(const MethodCall &call); private: + bool m_isSendSensorOrientation = false; + bool m_isSendSensorAccelerometer = false; AbstractSensorChannelInterface *m_iface = nullptr; }; diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp index 89e7d23..8aced7e 100644 --- a/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp @@ -9,8 +9,10 @@ #include #include +#include -static AbstractSensorChannelInterface *iface; +static AbstractSensorChannelInterface *ifaceOrientation; +static AbstractSensorChannelInterface *ifaceAccelerometer; namespace { @@ -23,6 +25,36 @@ void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) registrar.RegisterMethodChannel("sensors_plus_aurora", 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) @@ -30,17 +62,16 @@ void SensorsPlusAuroraPlugin::onMethodCall(const MethodCall &call) const auto &method = call.GetMethod(); if (method == "listenSensor") { - onListenSensor(call); + // onListenSensor(); return; } unimplemented(call); } -void SensorsPlusAuroraPlugin::onListenSensor(const MethodCall &call) +void SensorsPlusAuroraPlugin::onListenSensorOrientation() { - if (iface != nullptr) { - unimplemented(call); + if (ifaceOrientation != nullptr) { return; } @@ -58,28 +89,80 @@ void SensorsPlusAuroraPlugin::onListenSensor(const MethodCall &call) sm.registerSensorInterface("orientationsensor"); - iface = OrientationSensorChannelInterface::interface("orientationsensor"); - qDebug() << "iface -> " << iface->thread(); + ifaceOrientation = OrientationSensorChannelInterface::interface("orientationsensor"); - if (!iface) { + if (!ifaceOrientation) { qDebug() << "Cannot get OrientationSensorChannelInterface"; exit(0); } - connect(iface, SIGNAL(orientationChanged(const Unsigned&)), - this, SLOT(receivedData(const Unsigned&))); + connect(ifaceOrientation, + SIGNAL(orientationChanged(const Unsigned&)), + this, + SLOT(eventSensorOrientation(const Unsigned&)) + ); - qDebug() << "Created sensor: " << iface->description(); - iface->start(); + ifaceOrientation->start(); +} - qDebug() << "Received data start"; +void SensorsPlusAuroraPlugin::eventSensorOrientation(const Unsigned &data) +{ + if (this->m_isSendSensorOrientation) + { + EventChannel("sensors_aurora_orientation", MethodCodecType::Standard) + .SendEvent(data.x()); + } +} - unimplemented(call); +void SensorsPlusAuroraPlugin::onListenSensorAccelerometer() +{ + if (ifaceAccelerometer != nullptr) { + return; + } + + SensorManagerInterface &sm = SensorManagerInterface::instance(); + if (!sm.isValid()) { + qDebug() << "Failed to create SensorManagerInterface"; + exit(0); + } + + QDBusReply reply(sm.loadPlugin("accelerometersensor")); + if (!reply.isValid() || !reply.value()) { + qDebug() << "Failed to load plugin"; + exit(0); + } + + sm.registerSensorInterface("accelerometersensor"); + + ifaceAccelerometer = AccelerometerSensorChannelInterface::interface("accelerometersensor"); + + if (!ifaceAccelerometer) { + qDebug() << "Cannot get AccelerometerSensorChannelInterface"; + exit(0); + } + + connect(ifaceAccelerometer, + SIGNAL(dataAvailable(const XYZ&)), + this, + SLOT(eventSensorAccelerometer(const XYZ&)) + ); + + ifaceAccelerometer->start(); } -void SensorsPlusAuroraPlugin::receivedData(const Unsigned &data) +void SensorsPlusAuroraPlugin::eventSensorAccelerometer(const XYZ& data) { - qDebug() << "receivedData: " << data.x(); + if (this->m_isSendSensorAccelerometer) + { + std::vector result; + + result.push_back(data.x()); + result.push_back(data.y()); + result.push_back(data.z()); + + EventChannel("sensors_aurora_accelerometer", MethodCodecType::Standard) + .SendEvent(result); + } } void SensorsPlusAuroraPlugin::unimplemented(const MethodCall &call) diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/orientation_event.dart b/packages/sensors_plus/sensors_plus_aurora/lib/orientation_event.dart new file mode 100644 index 0000000..8ba764f --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/lib/orientation_event.dart @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// 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 +} diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart index 4c2003a..98dd33f 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart @@ -1,8 +1,29 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause + +import 'package:flutter/foundation.dart'; +import 'package:sensors_plus_aurora/orientation_event.dart'; +import 'package:sensors_plus_platform_interface/sensors_plus_platform_interface.dart'; import 'sensors_plus_aurora_platform_interface.dart'; -class SensorsPlusAurora { - Future listenSensor() { - return SensorsPlusAuroraPlatform.instance.listenSensor(); +/// A broadcast stream of events from the Aurora OS device orientation. +Stream? get orientationEvents { + if (TargetPlatform.aurora == defaultTargetPlatform) { + return SensorsPlusAurora().onChangeOrientation; + } + return null; +} + +class SensorsPlusAurora extends SensorsPlatform { + static void registerWith() { + SensorsPlatform.instance = SensorsPlusAurora(); } + + Stream get onChangeOrientation => + SensorsPlusAuroraPlatform.instance.onChangeOrientation(); + + @override + Stream get accelerometerEvents => + SensorsPlusAuroraPlatform.instance.onChangeAccelerometer(); } diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart index dbd3a52..c1cf24a 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart @@ -1,5 +1,10 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause + import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; +import 'package:sensors_plus_aurora/orientation_event.dart'; +import 'package:sensors_plus_platform_interface/sensors_plus_platform_interface.dart'; import 'sensors_plus_aurora_platform_interface.dart'; @@ -10,8 +15,45 @@ class MethodChannelSensorsPlusAurora extends SensorsPlusAuroraPlatform { final methodChannel = const MethodChannel('sensors_plus_aurora'); @override - Future listenSensor() async { - final version = await methodChannel.invokeMethod('listenSensor'); - return version; + Stream onChangeOrientation() async* { + await for (final event in const EventChannel('sensors_aurora_orientation') + .receiveBroadcastStream()) { + int result = (event as int?) ?? 0; + switch (result) { + 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 onChangeAccelerometer() async* { + await for (final event in const EventChannel('sensors_aurora_accelerometer') + .receiveBroadcastStream()) { + final list = (event as List); + yield AccelerometerEvent( + (list[0] as int?)?.toDouble() ?? 0, + (list[1] as int?)?.toDouble() ?? 0, + (list[2] as int?)?.toDouble() ?? 0, + ); + } } } diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart index 728a052..9ccb897 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart @@ -1,4 +1,9 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause + import 'package:plugin_platform_interface/plugin_platform_interface.dart'; +import 'package:sensors_plus_aurora/orientation_event.dart'; +import 'package:sensors_plus_platform_interface/sensors_plus_platform_interface.dart'; import 'sensors_plus_aurora_method_channel.dart'; @@ -23,7 +28,11 @@ abstract class SensorsPlusAuroraPlatform extends PlatformInterface { _instance = instance; } - Future listenSensor() { - throw UnimplementedError('listenSensor() has not been implemented.'); + Stream onChangeOrientation() { + throw UnimplementedError('onChangeOrientation() has not been implemented.'); + } + + Stream onChangeAccelerometer() { + throw UnimplementedError('onChangeAccelerometer() has not been implemented.'); } } diff --git a/packages/sensors_plus/sensors_plus_aurora/pubspec.yaml b/packages/sensors_plus/sensors_plus_aurora/pubspec.yaml index f78c456..fad8b75 100644 --- a/packages/sensors_plus/sensors_plus_aurora/pubspec.yaml +++ b/packages/sensors_plus/sensors_plus_aurora/pubspec.yaml @@ -13,6 +13,7 @@ dependencies: flutter: sdk: flutter plugin_platform_interface: ^2.0.2 + sensors_plus_platform_interface: ^1.1.3 dev_dependencies: flutter_test: @@ -24,3 +25,4 @@ flutter: platforms: aurora: pluginClass: SensorsPlusAuroraPlugin + dartPluginClass: SensorsPlusAurora diff --git a/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart b/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart deleted file mode 100644 index 8b01cf9..0000000 --- a/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_method_channel_test.dart +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC -// SPDX-License-Identifier: BSD-3-Clause - -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:sensors_plus_aurora/sensors_plus_aurora_method_channel.dart'; - -void main() { - MethodChannelSensorsPlusAurora platform = MethodChannelSensorsPlusAurora(); - const MethodChannel channel = MethodChannel('sensors_plus_aurora'); - - TestWidgetsFlutterBinding.ensureInitialized(); - - setUp(() { - channel.setMockMethodCallHandler((MethodCall methodCall) async { - return '42'; - }); - }); - - tearDown(() { - channel.setMockMethodCallHandler(null); - }); - - test('getPlatformVersion', () async { - expect(await platform.getPlatformVersion(), '42'); - }); -} diff --git a/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart b/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart deleted file mode 100644 index 59beaa1..0000000 --- a/packages/sensors_plus/sensors_plus_aurora/test/sensors_plus_aurora_test.dart +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC -// SPDX-License-Identifier: BSD-3-Clause - -import 'package:flutter_test/flutter_test.dart'; -import 'package:sensors_plus_aurora/sensors_plus_aurora.dart'; -import 'package:sensors_plus_aurora/sensors_plus_aurora_platform_interface.dart'; -import 'package:sensors_plus_aurora/sensors_plus_aurora_method_channel.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - -class MockSensorsPlusAuroraPlatform - with MockPlatformInterfaceMixin - implements SensorsPlusAuroraPlatform { - - @override - Future getPlatformVersion() => Future.value('42'); -} - -void main() { - final SensorsPlusAuroraPlatform initialPlatform = SensorsPlusAuroraPlatform.instance; - - test('$MethodChannelSensorsPlusAurora is the default instance', () { - expect(initialPlatform, isInstanceOf()); - }); - - test('getPlatformVersion', () async { - SensorsPlusAurora sensorsPlusAuroraPlugin = SensorsPlusAurora(); - MockSensorsPlusAuroraPlatform fakePlatform = MockSensorsPlusAuroraPlatform(); - SensorsPlusAuroraPlatform.instance = fakePlatform; - - expect(await sensorsPlusAuroraPlugin.getPlatformVersion(), '42'); - }); -} From 46c8e52bd959dd8e35910dd7d70a0296e67ec90b Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Fri, 4 Aug 2023 17:23:55 +0300 Subject: [PATCH 5/6] [sensors-plus] Add all sensors. OMP#OS-17084 --- example/lib/l10n/app_en.arb | 20 + example/lib/l10n/app_ru.arb | 20 + .../flutter_keyboard_visibility/page.dart | 2 +- example/lib/packages/sensors_plus/page.dart | 185 ++++-- example/lib/packages/translator/page.dart | 2 +- example/lib/widgets/blocks/block_item.dart | 10 +- .../sensors_plus_aurora/README.md | 112 +++- .../sensors_plus_aurora_plugin.h | 67 ++- .../aurora/sensors_plus_aurora_plugin.cpp | 559 ++++++++++++++---- .../lib/events/als_event.dart | 11 + .../lib/events/compass_event.dart | 13 + .../lib/{ => events}/orientation_event.dart | 6 + .../lib/events/proximity_event.dart | 11 + .../lib/events/tap_event.dart | 53 ++ .../lib/sensors_plus_aurora.dart | 66 ++- .../sensors_plus_aurora_method_channel.dart | 111 +++- ...ensors_plus_aurora_platform_interface.dart | 30 +- 17 files changed, 1103 insertions(+), 175 deletions(-) create mode 100644 packages/sensors_plus/sensors_plus_aurora/lib/events/als_event.dart create mode 100644 packages/sensors_plus/sensors_plus_aurora/lib/events/compass_event.dart rename packages/sensors_plus/sensors_plus_aurora/lib/{ => events}/orientation_event.dart (98%) create mode 100644 packages/sensors_plus/sensors_plus_aurora/lib/events/proximity_event.dart create mode 100644 packages/sensors_plus/sensors_plus_aurora/lib/events/tap_event.dart diff --git a/example/lib/l10n/app_en.arb b/example/lib/l10n/app_en.arb index 2647a5f..2b16cb3 100644 --- a/example/lib/l10n/app_en.arb +++ b/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": {}, "providerTitle": "Provider", "providerSubtitle": "Simple example use provider package", diff --git a/example/lib/l10n/app_ru.arb b/example/lib/l10n/app_ru.arb index b8bd5e4..326f2bc 100644 --- a/example/lib/l10n/app_ru.arb +++ b/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": {}, "providerTitle": "Provider", "providerSubtitle": "Простой пример использования пакета provider", diff --git a/example/lib/packages/flutter_keyboard_visibility/page.dart b/example/lib/packages/flutter_keyboard_visibility/page.dart index 59f9a37..fa22dcd 100644 --- a/example/lib/packages/flutter_keyboard_visibility/page.dart +++ b/example/lib/packages/flutter_keyboard_visibility/page.dart @@ -99,7 +99,7 @@ class _FlutterKeyboardVisibilityPageState title: l10n.flutterKeyboardVisibilityTitleHeight, desc: l10n.flutterKeyboardVisibilityDescHeight, value: _keyboardHeight, - builder: (value) => value.toInt().toString(), + builder: (value) => value?.toInt().toString(), ), ), const SizedBox(height: 20), diff --git a/example/lib/packages/sensors_plus/page.dart b/example/lib/packages/sensors_plus/page.dart index 427bb33..7304772 100644 --- a/example/lib/packages/sensors_plus/page.dart +++ b/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/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/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 'model.dart'; @@ -26,42 +31,59 @@ class SensorsPlusPage extends AppStatefulWidget { } class _SensorsPlusPageState extends AppState { - OrientationEvent orientation = OrientationEvent.undefined; - AccelerometerEvent accelerometer = AccelerometerEvent(0, 0, 0); + Stream? _orientationEvents; + Stream? _accelerometerEvents; + Stream? _compassEvents; + Stream? _tapEvents; + Stream? _alsEvents; + Stream? _proximityEvents; + Stream? _gyroscopeEvents; + Stream? _magnetometerEvents; @override void initState() { super.initState(); - /// Accelerometer change - accelerometerEvents.listen( - (AccelerometerEvent event) { - if (mounted) { - setState(() { - accelerometer = event; - }); - } - }, - onError: (error) { - debugPrint(error.toString()); - }, - cancelOnError: true, - ); - - /// Only Aurora OS orientation change - orientationEvents?.listen( - (OrientationEvent event) { - if (mounted) { - setState(() { - orientation = event; - }); - } - }, - onError: (error) { - debugPrint(error.toString()); - }, - cancelOnError: true, - ); + 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 @@ -81,12 +103,101 @@ class _SensorsPlusPageState extends AppState { crossAxisAlignment: CrossAxisAlignment.start, children: [ BlockInfoPackage(widget.package), - Center( - child: Text('Orientation: $orientation'), + 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(), + ), ), - const SizedBox(height: 20,), - Center( - child: Text('Accelerometer: $accelerometer'), + 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(), + ), ), ], ), diff --git a/example/lib/packages/translator/page.dart b/example/lib/packages/translator/page.dart index 7d2fafd..eb75e5d 100644 --- a/example/lib/packages/translator/page.dart +++ b/example/lib/packages/translator/page.dart @@ -45,7 +45,7 @@ class _TranslatorPageState extends AppState { title: l10n.translatorTitle, desc: l10n.translatorSubtitle, future: model.translate(l10n.translatorText), - builder: (value) => value.text, + builder: (value) => value?.text, ), ], ), diff --git a/example/lib/widgets/blocks/block_item.dart b/example/lib/widgets/blocks/block_item.dart index 57fe8ad..042ddab 100644 --- a/example/lib/widgets/blocks/block_item.dart +++ b/example/lib/widgets/blocks/block_item.dart @@ -15,6 +15,7 @@ class BlockItem extends AppStatelessWidget { this.future, this.stream, this.builder, + this.isShowProgress = true, }); final String? title; @@ -22,7 +23,8 @@ class BlockItem extends AppStatelessWidget { final T? value; final Stream? stream; final Future? future; - final Function(T)? builder; + final Function(T?)? builder; + final bool isShowProgress; AsyncWidgetBuilder get widgetBuilder => (BuildContext context, AsyncSnapshot snapshot) { @@ -47,14 +49,14 @@ class BlockItem extends AppStatelessWidget { ], ), ), - if (snapshot.hasData) + if (!isShowProgress) TextBodyMedium( builder == null ? snapshot.data.toString() - : builder?.call(snapshot.data as T), + : builder?.call(snapshot.data), fontWeight: FontWeight.bold, ), - if (!snapshot.hasData) + if (isShowProgress) const SizedBox( width: 16, height: 16, diff --git a/packages/sensors_plus/sensors_plus_aurora/README.md b/packages/sensors_plus/sensors_plus_aurora/README.md index 6bcd18c..b004c18 100644 --- a/packages/sensors_plus/sensors_plus_aurora/README.md +++ b/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 dependencies: 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 -// @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()); + } +); ``` diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h index 2e121ab..e7cc98c 100644 --- a/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/include/sensors_plus_aurora/sensors_plus_aurora_plugin.h @@ -11,13 +11,19 @@ #include -#include -#include +#include +#include #include +#include +#include +#include +#include +#include +#include class PLUGIN_EXPORT SensorsPlusAuroraPlugin final - : public QObject - , public PluginInterface + : public QObject, + public PluginInterface { Q_OBJECT @@ -25,19 +31,54 @@ public: void RegisterWithRegistrar(PluginRegistrar ®istrar) override; public slots: - void eventSensorOrientation(const Unsigned &data); - void eventSensorAccelerometer(const XYZ& data); + 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: - void onMethodCall(const MethodCall &call); - void onListenSensorOrientation(); - void onListenSensorAccelerometer(); - void unimplemented(const MethodCall &call); + template + bool RegisterSensorInterface(QString sensor); + void EventChannelNull(std::string channel); + void EventChannelData(std::string channel, std::vector 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: - bool m_isSendSensorOrientation = false; - bool m_isSendSensorAccelerometer = false; - AbstractSensorChannelInterface *m_iface = nullptr; + 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 */ diff --git a/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp index 8aced7e..225ab74 100644 --- a/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp +++ b/packages/sensors_plus/sensors_plus_aurora/aurora/sensors_plus_aurora_plugin.cpp @@ -10,164 +10,515 @@ #include #include #include +#include +#include +#include +#include +#include +#include + +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; -static AbstractSensorChannelInterface *ifaceAccelerometer; +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 */ -namespace { +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(); }); +} -constexpr auto METHOD_LISTEN_SENSOR = "listenSensor"; +template +bool SensorsPlusAuroraPlugin::RegisterSensorInterface(QString sensor) +{ + SensorManagerInterface &sm = SensorManagerInterface::instance(); + if (!sm.isValid()) + { + return false; + } -} /* namespace */ + QDBusReply reply(sm.loadPlugin(sensor)); + if (!reply.isValid() || !reply.value()) + { + return false; + } -void SensorsPlusAuroraPlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) + sm.registerSensorInterface(sensor); + + return true; +} + +void SensorsPlusAuroraPlugin::EventChannelNull(std::string channel) +{ + EventChannel(channel, MethodCodecType::Standard).SendEvent(nullptr); +} + +void SensorsPlusAuroraPlugin::EventChannelData(std::string channel, std::vector result) +{ + EventChannel(channel, MethodCodecType::Standard).SendEvent(result); +} + +/** + * Orientation + */ +void SensorsPlusAuroraPlugin::EnableSensorOrientation() +{ + if (m_ifaceOrientation == nullptr) + { + if (!RegisterSensorInterface(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", - 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(); + if (m_ifaceOrientation == nullptr) + { return; } - unimplemented(call); + m_ifaceOrientation->stop(); +} + +void SensorsPlusAuroraPlugin::EventSensorOrientation(const Unsigned &data) +{ + std::vector 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(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; } - SensorManagerInterface &sm = SensorManagerInterface::instance(); - if (!sm.isValid()) { - qDebug() << "Failed to create SensorManagerInterface"; - exit(0); + m_ifaceAccelerometer->stop(); +} + +void SensorsPlusAuroraPlugin::EventSensorAccelerometer(const XYZ &data) +{ + std::vector 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(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 reply(sm.loadPlugin("orientationsensor")); - if (!reply.isValid() || !reply.value()) { - qDebug() << "Failed to load plugin"; - exit(0); + m_ifaceCompass->start(); + EventSensorCompass(m_ifaceCompass->get()); +} + +void SensorsPlusAuroraPlugin::DisableSensorCompass() +{ + if (m_ifaceCompass == nullptr) + { + return; } - sm.registerSensorInterface("orientationsensor"); + m_ifaceCompass->stop(); +} - ifaceOrientation = OrientationSensorChannelInterface::interface("orientationsensor"); +void SensorsPlusAuroraPlugin::EventSensorCompass(const Compass &data) +{ + std::vector result; + result.push_back(data.degrees()); + result.push_back(data.level()); + EventChannelData(KeyChannel::Compass, result); +} - if (!ifaceOrientation) { - qDebug() << "Cannot get OrientationSensorChannelInterface"; - exit(0); +/** + * Tap + */ +void SensorsPlusAuroraPlugin::EnableSensorTap() +{ + if (m_ifaceTap == nullptr) + { + if (!RegisterSensorInterface(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, - SIGNAL(orientationChanged(const Unsigned&)), - this, - SLOT(eventSensorOrientation(const Unsigned&)) - ); + m_ifaceTap->start(); +} + +void SensorsPlusAuroraPlugin::DisableSensorTap() +{ + if (m_ifaceTap == nullptr) + { + return; + } + + m_ifaceTap->stop(); +} - ifaceOrientation->start(); +void SensorsPlusAuroraPlugin::EventSensorTap(const Tap &data) +{ + std::vector result; + result.push_back(static_cast(data.direction())); + result.push_back(static_cast(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) - .SendEvent(data.x()); + if (!RegisterSensorInterface(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::onListenSensorAccelerometer() +void SensorsPlusAuroraPlugin::DisableSensorALS() { - if (ifaceAccelerometer != nullptr) { + if (m_ifaceALS == nullptr) + { return; } - SensorManagerInterface &sm = SensorManagerInterface::instance(); - if (!sm.isValid()) { - qDebug() << "Failed to create SensorManagerInterface"; - exit(0); + m_ifaceALS->stop(); +} + +void SensorsPlusAuroraPlugin::EventSensorALS(const Unsigned &data) +{ + std::vector result; + result.push_back(data.x()); + EventChannelData(KeyChannel::ALS, result); +} + +/** + * Proximity + */ +void SensorsPlusAuroraPlugin::EnableSensorProximity() +{ + if (m_ifaceProximity == nullptr) + { + if (!RegisterSensorInterface(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 reply(sm.loadPlugin("accelerometersensor")); - if (!reply.isValid() || !reply.value()) { - qDebug() << "Failed to load plugin"; - exit(0); + m_ifaceProximity->start(); + EventSensorProximity(m_ifaceProximity->proximityReflectance()); +} + +void SensorsPlusAuroraPlugin::DisableSensorProximity() +{ + if (m_ifaceProximity == nullptr) + { + return; } - sm.registerSensorInterface("accelerometersensor"); + m_ifaceProximity->stop(); +} - ifaceAccelerometer = AccelerometerSensorChannelInterface::interface("accelerometersensor"); +void SensorsPlusAuroraPlugin::EventSensorProximity(const Proximity &data) +{ + std::vector result; + result.push_back(data.withinProximity() ? 1 : 0); + EventChannelData(KeyChannel::Proximity, result); +} - if (!ifaceAccelerometer) { - qDebug() << "Cannot get AccelerometerSensorChannelInterface"; - exit(0); +/** + * Rotation + */ +void SensorsPlusAuroraPlugin::EnableSensorRotation() +{ + if (m_ifaceRotation == nullptr) + { + if (!RegisterSensorInterface(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, - SIGNAL(dataAvailable(const XYZ&)), - this, - SLOT(eventSensorAccelerometer(const XYZ&)) - ); + m_ifaceRotation->start(); + EventSensorRotation(m_ifaceRotation->rotation()); +} - 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 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 result; + if (!RegisterSensorInterface(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()); - result.push_back(data.y()); - result.push_back(data.z()); + m_ifaceMagnetometer->start(); + EventSensorMagnetometer(m_ifaceMagnetometer->magneticField()); +} - EventChannel("sensors_aurora_accelerometer", MethodCodecType::Standard) - .SendEvent(result); +void SensorsPlusAuroraPlugin::DisableSensorMagnetometer() +{ + 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 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" diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/events/als_event.dart b/packages/sensors_plus/sensors_plus_aurora/lib/events/als_event.dart new file mode 100644 index 0000000..c23368c --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/lib/events/als_event.dart @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause + +class ALSEvent { + ALSEvent(this.degrees); + + final int degrees; + + @override + String toString() => '[ALSEvent (degrees: $degrees)]'; +} diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/events/compass_event.dart b/packages/sensors_plus/sensors_plus_aurora/lib/events/compass_event.dart new file mode 100644 index 0000000..9e42086 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/lib/events/compass_event.dart @@ -0,0 +1,13 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// 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)]'; +} diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/orientation_event.dart b/packages/sensors_plus/sensors_plus_aurora/lib/events/orientation_event.dart similarity index 98% rename from packages/sensors_plus/sensors_plus_aurora/lib/orientation_event.dart rename to packages/sensors_plus/sensors_plus_aurora/lib/events/orientation_event.dart index 8ba764f..3b743da 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/orientation_event.dart +++ b/packages/sensors_plus/sensors_plus_aurora/lib/events/orientation_event.dart @@ -4,16 +4,22 @@ 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 } diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/events/proximity_event.dart b/packages/sensors_plus/sensors_plus_aurora/lib/events/proximity_event.dart new file mode 100644 index 0000000..ffda18c --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/lib/events/proximity_event.dart @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause + +class ProximityEvent { + ProximityEvent(this.withinProximity); + + final bool withinProximity; + + @override + String toString() => '[ProximityEvent (withinProximity: $withinProximity)]'; +} diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/events/tap_event.dart b/packages/sensors_plus/sensors_plus_aurora/lib/events/tap_event.dart new file mode 100644 index 0000000..df4e031 --- /dev/null +++ b/packages/sensors_plus/sensors_plus_aurora/lib/events/tap_event.dart @@ -0,0 +1,53 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// 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)]'; +} diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart index 98dd33f..05776f3 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora.dart @@ -2,7 +2,11 @@ // SPDX-License-Identifier: BSD-3-Clause 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 'sensors_plus_aurora_platform_interface.dart'; @@ -15,15 +19,75 @@ Stream? get orientationEvents { return null; } +/// A broadcast stream of events from the Aurora OS device compass. +Stream? get compassEvents { + if (TargetPlatform.aurora == defaultTargetPlatform) { + return SensorsPlusAurora().onChangeCompass; + } + return null; +} + +/// A broadcast stream of events from the Aurora OS device tap. +Stream? get tapEvents { + if (TargetPlatform.aurora == defaultTargetPlatform) { + return SensorsPlusAurora().onChangeTap; + } + return null; +} + +/// A broadcast stream of events from the Aurora OS device ALS. +Stream? get alsEvents { + if (TargetPlatform.aurora == defaultTargetPlatform) { + return SensorsPlusAurora().onChangeALS; + } + return null; +} + +/// A broadcast stream of events from the Aurora OS device proximity. +Stream? get proximityEvents { + if (TargetPlatform.aurora == defaultTargetPlatform) { + return SensorsPlusAurora().onChangeProximity; + } + return null; +} + class SensorsPlusAurora extends SensorsPlatform { static void registerWith() { SensorsPlatform.instance = SensorsPlusAurora(); } + /// orientationsensor Stream get onChangeOrientation => SensorsPlusAuroraPlatform.instance.onChangeOrientation(); + /// accelerometersensor @override Stream get accelerometerEvents => SensorsPlusAuroraPlatform.instance.onChangeAccelerometer(); + + /// compasssensor + Stream get onChangeCompass => + SensorsPlusAuroraPlatform.instance.onChangeCompass(); + + /// tapsensor + Stream get onChangeTap => + SensorsPlusAuroraPlatform.instance.onChangeTap(); + + /// alssensor + Stream get onChangeALS => + SensorsPlusAuroraPlatform.instance.onChangeALS(); + + /// proximitysensor + Stream get onChangeProximity => + SensorsPlusAuroraPlatform.instance.onChangeProximity(); + + /// rotationsensor + @override + Stream get gyroscopeEvents => + SensorsPlusAuroraPlatform.instance.onChangeRotation(); + + /// magnetometersensor + @override + Stream get magnetometerEvents => + SensorsPlusAuroraPlatform.instance.onChangeMagnetometer(); } diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart index c1cf24a..dae0a05 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_method_channel.dart +++ b/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/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 'sensors_plus_aurora_platform_interface.dart'; @@ -14,12 +18,20 @@ class MethodChannelSensorsPlusAurora extends SensorsPlusAuroraPlatform { @visibleForTesting final methodChannel = const MethodChannel('sensors_plus_aurora'); + List _loadData(dynamic data, String key) { + if (data == null) { + throw "Failed to load sensor '$key'"; + } + + return (data as List).map((e) => int.parse(e.toString())).toList(); + } + @override Stream onChangeOrientation() async* { - await for (final event in const EventChannel('sensors_aurora_orientation') - .receiveBroadcastStream()) { - int result = (event as int?) ?? 0; - switch (result) { + await for (final data + in const EventChannel('sensors_plus_aurora_orientationsensor') + .receiveBroadcastStream()) { + switch (_loadData(data, 'orientationsensor')[0]) { case 1: yield OrientationEvent.rightUp; break; @@ -46,13 +58,90 @@ class MethodChannelSensorsPlusAurora extends SensorsPlusAuroraPlatform { @override Stream onChangeAccelerometer() async* { - await for (final event in const EventChannel('sensors_aurora_accelerometer') - .receiveBroadcastStream()) { - final list = (event as List); + await for (final data + in const EventChannel('sensors_plus_aurora_accelerometersensor') + .receiveBroadcastStream()) { + final result = _loadData(data, 'accelerometersensor'); yield AccelerometerEvent( - (list[0] as int?)?.toDouble() ?? 0, - (list[1] as int?)?.toDouble() ?? 0, - (list[2] as int?)?.toDouble() ?? 0, + result[0].toDouble(), + result[1].toDouble(), + result[2].toDouble(), + ); + } + } + + @override + Stream 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 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 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 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 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 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(), ); } } diff --git a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart index 9ccb897..859ed25 100644 --- a/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart +++ b/packages/sensors_plus/sensors_plus_aurora/lib/sensors_plus_aurora_platform_interface.dart @@ -2,7 +2,11 @@ // SPDX-License-Identifier: BSD-3-Clause 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 'sensors_plus_aurora_method_channel.dart'; @@ -35,4 +39,28 @@ abstract class SensorsPlusAuroraPlatform extends PlatformInterface { Stream onChangeAccelerometer() { throw UnimplementedError('onChangeAccelerometer() has not been implemented.'); } + + Stream onChangeCompass() { + throw UnimplementedError('onChangeCompass() has not been implemented.'); + } + + Stream onChangeTap() { + throw UnimplementedError('onChangeTap() has not been implemented.'); + } + + Stream onChangeALS() { + throw UnimplementedError('onChangeALS() has not been implemented.'); + } + + Stream onChangeProximity() { + throw UnimplementedError('onChangeProximity() has not been implemented.'); + } + + Stream onChangeRotation() { + throw UnimplementedError('onChangeRotation() has not been implemented.'); + } + + Stream onChangeMagnetometer() { + throw UnimplementedError('onChangeMagnetometer() has not been implemented.'); + } } From 2efecf03526293c2a0b9ab9e77482b34d227b486 Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Fri, 4 Aug 2023 17:39:01 +0300 Subject: [PATCH 6/6] [sensors-plus] Add permission, update readme. OMP#OS-17084 --- .../desktop/ru.auroraos.flutter_example_packages.desktop | 2 +- packages/sensors_plus/sensors_plus_aurora/README.md | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/example/aurora/desktop/ru.auroraos.flutter_example_packages.desktop b/example/aurora/desktop/ru.auroraos.flutter_example_packages.desktop index 385dfe0..62dc6da 100644 --- a/example/aurora/desktop/ru.auroraos.flutter_example_packages.desktop +++ b/example/aurora/desktop/ru.auroraos.flutter_example_packages.desktop @@ -7,6 +7,6 @@ Exec=/usr/bin/ru.auroraos.flutter_example_packages X-Nemo-Application-Type=silica-qt5 [X-Application] -Permissions=DeviceInfo,UserDirs +Permissions=DeviceInfo,UserDirs,Sensors OrganizationName=ru.auroraos ApplicationName=flutter_example_packages diff --git a/packages/sensors_plus/sensors_plus_aurora/README.md b/packages/sensors_plus/sensors_plus_aurora/README.md index b004c18..805330e 100644 --- a/packages/sensors_plus/sensors_plus_aurora/README.md +++ b/packages/sensors_plus/sensors_plus_aurora/README.md @@ -27,7 +27,12 @@ dependencies: - 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** +***.desktop** + +```desktop +Permissions=Sensors +``` +***.spec** ```spec BuildRequires: pkgconfig(sensord-qt5)