feat: 重构项目 2.0.0 (#6)

* feat: 重构项目

* feat: 添加 bluez_central_manager

* feat: 联合插件

* feat: 拆分项目

* feat: 实现 linux 部分接口

* feat: 重新创建项目

* feat: 定义接口

* feat: 实现接入插件

* feat: 清空接入插件示例代码

* feat: 开发 linux 插件

* feat: 调整接口

* 临时提交

* feat: 实现 Android 接口

* fix: 修复 Android 问题

* fix: 移除多余文件

* feat: 重构项目 (#5)

* fix: 移除多余的状态判断

* fix: 外围设备断开时检查是否存在未完成的操作

* feat: 尝试使用 win32 实现接口

* fix: 修复大小写问题

* feat: 实现 macOS 接口

* feat: 实现 macOS 接口

* fix:支持使用16位短字符串生成UUID

* fix: 修复未清理已完成操作的问题

* fix: 规范命名

* 添加蓝牙使用描述

* fix: 更新 README.md
This commit is contained in:
Mr剑侠客
2023-08-17 17:49:26 +08:00
committed by GitHub
parent 3abe9d5b3d
commit d1726b52fa
371 changed files with 15666 additions and 15993 deletions

30
bluetooth_low_energy_windows/.gitignore vendored Normal file
View File

@ -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/

View File

@ -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: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
channel: stable
project_type: plugin
# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
- platform: windows
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
# 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'

View File

@ -0,0 +1,4 @@
## 2.0.0
- Rewrite the whole project with federated plugins.
- Support macOS and Linux.

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 yanshouwang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,15 @@
# bluetooth_low_energy_windows
The Windows implementation of [`bluetooth_low_energy`][1].
## Usage
This package is [endorsed][2], which means you can simply use `bluetooth_low_energy`
normally. This package will be automatically included in your app when you do,
so you do not need to add it to your `pubspec.yaml`.
However, if you `import` this package to use any of its APIs directly, you
should add it to your `pubspec.yaml` as usual.
[1]: https://pub.dev/packages/bluetooth_low_energy
[2]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin

View File

@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

View File

@ -0,0 +1,9 @@
import 'package:bluetooth_low_energy_platform_interface/bluetooth_low_energy_platform_interface.dart';
import 'src/my_central_controller.dart';
abstract class BluetoothLowEnergyWindows {
static void registerWith() {
CentralController.instance = MyCentralController();
}
}

View File

@ -0,0 +1,120 @@
import 'dart:typed_data';
import 'package:bluetooth_low_energy_platform_interface/bluetooth_low_energy_platform_interface.dart';
import 'package:win32/win32.dart' as win32;
class MyCentralController extends CentralController {
@override
// TODO: implement state
CentralState get state => throw UnimplementedError();
@override
// TODO: implement stateChanged
Stream<CentralStateChangedEventArgs> get stateChanged =>
throw UnimplementedError();
@override
// TODO: implement discovered
Stream<CentralDiscoveredEventArgs> get discovered =>
throw UnimplementedError();
@override
// TODO: implement peripheralStateChanged
Stream<PeripheralStateChangedEventArgs> get peripheralStateChanged =>
throw UnimplementedError();
@override
// TODO: implement characteristicValueChanged
Stream<GattCharacteristicValueChangedEventArgs>
get characteristicValueChanged => throw UnimplementedError();
@override
Future<void> setUp() {
// TODO: implement setUp
throw UnimplementedError();
}
@override
Future<void> tearDown() {
// TODO: implement tearDown
throw UnimplementedError();
}
@override
Future<void> startDiscovery() {
// TODO: implement startDiscovery
throw UnimplementedError();
}
@override
Future<void> stopDiscovery() {
// TODO: implement stopDiscovery
throw UnimplementedError();
}
@override
Future<void> connect(Peripheral peripheral) {
// TODO: implement connect
throw UnimplementedError();
}
@override
Future<void> disconnect(Peripheral peripheral) {
// TODO: implement disconnect
throw UnimplementedError();
}
@override
Future<void> discoverGATT(Peripheral peripheral) {
// TODO: implement discoverGATT
throw UnimplementedError();
}
@override
Future<List<GattService>> getServices(Peripheral peripheral) {
// TODO: implement getServices
throw UnimplementedError();
}
@override
Future<List<GattCharacteristic>> getCharacteristics(GattService service) {
// TODO: implement getCharacteristics
throw UnimplementedError();
}
@override
Future<List<GattDescriptor>> getDescriptors(
GattCharacteristic characteristic) {
// TODO: implement getDescriptors
throw UnimplementedError();
}
@override
Future<Uint8List> readCharacteristic(GattCharacteristic characteristic) {
// TODO: implement readCharacteristic
throw UnimplementedError();
}
@override
Future<void> writeCharacteristic(GattCharacteristic characteristic,
{required Uint8List value, required GattCharacteristicWriteType type}) {
// TODO: implement writeCharacteristic
throw UnimplementedError();
}
@override
Future<void> notifyCharacteristic(GattCharacteristic characteristic,
{required bool state}) {
// TODO: implement notifyCharacteristic
throw UnimplementedError();
}
@override
Future<Uint8List> readDescriptor(GattDescriptor descriptor) {
// TODO: implement readDescriptor
throw UnimplementedError();
}
@override
Future<void> writeDescriptor(GattDescriptor descriptor,
{required Uint8List value}) {
// TODO: implement writeDescriptor
throw UnimplementedError();
}
}

View File

@ -0,0 +1,28 @@
name: bluetooth_low_energy_windows
description: Windows implementation of the bluetooth_low_energy plugin.
version: 2.0.0
homepage: https://github.com/yanshouwang/bluetooth_low_energy
environment:
sdk: ">=3.0.0 <4.0.0"
flutter: ">=3.3.0"
dependencies:
flutter:
sdk: flutter
bluetooth_low_energy_platform_interface:
path: ../bluetooth_low_energy_platform_interface
win32: ^5.0.6
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
plugin:
implements: bluetooth_low_energy
platforms:
windows:
pluginClass: BluetoothLowEnergyWindowsPluginCApi
dartPluginClass: BluetoothLowEnergyWindows

View File

@ -0,0 +1,17 @@
flutter/
# Visual Studio user-specific files.
*.suo
*.user
*.userosscache
*.sln.docstates
# Visual Studio build-related files.
x64/
x86/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

View File

@ -0,0 +1,53 @@
# The Flutter tooling requires that developers have a version of Visual Studio
# installed that includes CMake 3.14 or later. You should not increase this
# version, as doing so will cause the plugin to fail to compile for some
# customers of the plugin.
cmake_minimum_required(VERSION 3.14)
# Project-level configuration.
set(PROJECT_NAME "bluetooth_low_energy_windows")
project(${PROJECT_NAME} LANGUAGES CXX)
# This value is used when generating builds using this plugin, so it must
# not be changed
set(PLUGIN_NAME "bluetooth_low_energy_windows_plugin")
# Any new source files that you add to the plugin should be added here.
list(APPEND PLUGIN_SOURCES
"bluetooth_low_energy_windows_plugin.cpp"
"bluetooth_low_energy_windows_plugin.h"
)
# Define the plugin library target. Its name must not be changed (see comment
# on PLUGIN_NAME above).
add_library(${PLUGIN_NAME} SHARED
"include/bluetooth_low_energy_windows/bluetooth_low_energy_windows_plugin_c_api.h"
"bluetooth_low_energy_windows_plugin_c_api.cpp"
${PLUGIN_SOURCES}
)
# Apply a standard set of build settings that are configured in the
# application-level CMakeLists.txt. This can be removed for plugins that want
# full control over build settings.
apply_standard_settings(${PLUGIN_NAME})
# Symbols are hidden by default to reduce the chance of accidental conflicts
# between plugins. This should not be removed; any symbols that should be
# exported should be explicitly exported with the FLUTTER_PLUGIN_EXPORT macro.
set_target_properties(${PLUGIN_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
# Source include directories and library dependencies. Add any plugin-specific
# dependencies here.
target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
# List of absolute paths to libraries that should be bundled with the plugin.
# This list could contain prebuilt libraries, or libraries created by an
# external build triggered from this build file.
set(bluetooth_low_energy_windows_bundled_libraries
""
PARENT_SCOPE
)

View File

@ -0,0 +1,59 @@
#include "bluetooth_low_energy_windows_plugin.h"
// This must be included before many other Windows headers.
#include <windows.h>
// For getPlatformVersion; remove unless needed for your plugin implementation.
#include <VersionHelpers.h>
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
#include <flutter/standard_method_codec.h>
#include <memory>
#include <sstream>
namespace bluetooth_low_energy_windows {
// static
void BluetoothLowEnergyWindowsPlugin::RegisterWithRegistrar(
flutter::PluginRegistrarWindows *registrar) {
auto channel =
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
registrar->messenger(), "bluetooth_low_energy_windows",
&flutter::StandardMethodCodec::GetInstance());
auto plugin = std::make_unique<BluetoothLowEnergyWindowsPlugin>();
channel->SetMethodCallHandler(
[plugin_pointer = plugin.get()](const auto &call, auto result) {
plugin_pointer->HandleMethodCall(call, std::move(result));
});
registrar->AddPlugin(std::move(plugin));
}
BluetoothLowEnergyWindowsPlugin::BluetoothLowEnergyWindowsPlugin() {}
BluetoothLowEnergyWindowsPlugin::~BluetoothLowEnergyWindowsPlugin() {}
void BluetoothLowEnergyWindowsPlugin::HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
if (method_call.method_name().compare("getPlatformVersion") == 0) {
std::ostringstream version_stream;
version_stream << "Windows ";
if (IsWindows10OrGreater()) {
version_stream << "10+";
} else if (IsWindows8OrGreater()) {
version_stream << "8";
} else if (IsWindows7OrGreater()) {
version_stream << "7";
}
result->Success(flutter::EncodableValue(version_stream.str()));
} else {
result->NotImplemented();
}
}
} // namespace bluetooth_low_energy_windows

View File

@ -0,0 +1,32 @@
#ifndef FLUTTER_PLUGIN_BLUETOOTH_LOW_ENERGY_WINDOWS_PLUGIN_H_
#define FLUTTER_PLUGIN_BLUETOOTH_LOW_ENERGY_WINDOWS_PLUGIN_H_
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
#include <memory>
namespace bluetooth_low_energy_windows {
class BluetoothLowEnergyWindowsPlugin : public flutter::Plugin {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
BluetoothLowEnergyWindowsPlugin();
virtual ~BluetoothLowEnergyWindowsPlugin();
// Disallow copy and assign.
BluetoothLowEnergyWindowsPlugin(const BluetoothLowEnergyWindowsPlugin&) = delete;
BluetoothLowEnergyWindowsPlugin& operator=(const BluetoothLowEnergyWindowsPlugin&) = delete;
private:
// Called when a method is called on this plugin's channel from Dart.
void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
};
} // namespace bluetooth_low_energy_windows
#endif // FLUTTER_PLUGIN_BLUETOOTH_LOW_ENERGY_WINDOWS_PLUGIN_H_

View File

@ -0,0 +1,12 @@
#include "include/bluetooth_low_energy_windows/bluetooth_low_energy_windows_plugin_c_api.h"
#include <flutter/plugin_registrar_windows.h>
#include "bluetooth_low_energy_windows_plugin.h"
void BluetoothLowEnergyWindowsPluginCApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar) {
bluetooth_low_energy_windows::BluetoothLowEnergyWindowsPlugin::RegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
}

View File

@ -0,0 +1,23 @@
#ifndef FLUTTER_PLUGIN_BLUETOOTH_LOW_ENERGY_WINDOWS_PLUGIN_C_API_H_
#define FLUTTER_PLUGIN_BLUETOOTH_LOW_ENERGY_WINDOWS_PLUGIN_C_API_H_
#include <flutter_plugin_registrar.h>
#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
#else
#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport)
#endif
#if defined(__cplusplus)
extern "C" {
#endif
FLUTTER_PLUGIN_EXPORT void BluetoothLowEnergyWindowsPluginCApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar);
#if defined(__cplusplus)
} // extern "C"
#endif
#endif // FLUTTER_PLUGIN_BLUETOOTH_LOW_ENERGY_WINDOWS_PLUGIN_C_API_H_