# MoYoung Glasses BLE Plugin - 详细使用指南 | Detailed Guide

这是一个完整的Flutter应用程序，演示了`moyoung_glasses_ble_plugin`的所有功能。

This is a complete Flutter application demonstrating all features of the `moyoung_glasses_ble_plugin`.

## 📱 功能演示 | Features Demonstrated

### 设备管理 | Device Management
- 蓝牙扫描和设备发现 | Bluetooth scanning and device discovery
- 设备连接和断开 | Device connection and disconnection
- 连接状态监控 | Connection state monitoring
- 设备信息获取 | Device information retrieval

### 📸 相机控制 | Camera Control
- 远程拍照 | Take photos remotely
- 开始/停止录像 | Start/stop video recording
- 照片和视频文件管理 | Photo and video file management

### 🎵 音频功能 | Audio Features
- 音频录制 | Audio recording
- 音频播放控制 | Audio playback control
- 文件同步 | File synchronization

### 🔧 设备工具 | Device Utilities
- 电池状态监控 | Battery status monitoring
- 设备时间同步 | Device time synchronization
- 固件版本检查 | Firmware version checking
- OTA固件更新 | OTA firmware updates

### 🤖 AI功能 | AI Features
- 语音助手集成 | Voice assistant integration
- 图像识别 | Image recognition
- 实时翻译 | Real-time translation
- 智能回复 | Smart replies

## 🚀 快速开始 | Getting Started

### 前置条件 | Prerequisites
- Flutter SDK >= 3.0.0
- Android SDK >= 21 (Android 5.0)
- iOS >= 11.0
- MoYoung智能眼镜设备 | A MoYoung smart glasses device

### 安装步骤 | Installation

1. 克隆仓库 | Clone this repository
2. 导航到示例目录 | Navigate to the example directory:
   ```bash
   cd example
   ```
3. 安装依赖 | Install dependencies:
   ```bash
   flutter pub get
   ```
4. 运行应用 | Run the app:
   ```bash
   flutter run
   ```

### 权限配置 | Permissions

#### Android
添加到 `android/app/src/main/AndroidManifest.xml`:
```xml
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
```

#### iOS
添加到 `ios/Runner/Info.plist`:
```xml
<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app needs Bluetooth access to connect with smart glasses</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>This app needs Bluetooth access to connect with smart glasses</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs location access to scan for Bluetooth devices</string>
```

## 📁 应用结构 | App Structure

```
lib/
├── main.dart                 # 主入口 | App entry point
├── glasses_scan_page.dart    # 眼镜扫描页面 | Device scanning interface
├── glasses_test_page.dart    # 功能测试页面 | Feature testing interface
└── device.dart              # 原有手环设备支持 | Legacy band device support
```

## 💡 使用指南 | Usage

1. **启动应用** - 应用会自动检查蓝牙权限 | Launch the app - automatically checks Bluetooth permissions
2. **扫描设备** - 点击"Scan"发现附近的智能眼镜 | Scan for devices - Tap "Scan" to discover nearby smart glasses
3. **连接设备** - 从列表选择设备进行连接 | Connect to device - Select a device from the list to connect
4. **测试功能** - 使用测试界面探索所有可用功能 | Test features - Use the test interface to explore all available features

## 🔑 关键代码示例 | Key Code Examples

### 初始化插件 | Initialize the Plugin
```dart
final MoYoungGlassesBle _glasses = MoYoungGlassesBle();
```

### 扫描设备 | Scan for Devices
```dart
await _glasses.startScan(10); // 扫描10秒 | Scan for 10 seconds

// 监听扫描结果 | Listen to scan results
_glasses.bleScanEveStm.listen((BleScanBean device) {
  print('Found device: ${device.name}');
});
```

### 连接设备 | Connect to Device
```dart
await _glasses.connect('{"address":"XX:XX:XX:XX:XX:XX"}');

// 监听连接状态 | Monitor connection state
_glasses.connStateEveStm.listen((ConnectStateBean state) {
  print('Connection state: ${state.status}');
});
```

### 拍照 | Take a Photo
```dart
await _glasses.takePhoto();

// 监听拍照结果 | Listen for photo results
_glasses.takePhotoEveStm.listen((TakePhotoBean result) {
  if (result.success) {
    print('Photo taken successfully');
  }
});
```

## ⚠️ 注意事项 | Important Notes

1. **设备兼容性** | Device Compatibility: 确保测试的眼镜设备支持当前SDK版本
2. **权限要求** | Permission Requirements: iOS和Android都需要蓝牙和位置权限
3. **连接稳定性** | Connection Stability: 保持设备距离在有效范围内
4. **电池状态** | Battery Status: 低电量可能影响某些功能的正常使用
5. **固件版本** | Firmware Version: 建议使用最新的设备固件

## 🔧 故障排除 | Troubleshooting

### 常见问题 | Common Issues

1. **蓝牙未启用** | Bluetooth not enabled
   - 确保设备蓝牙已开启 | Ensure Bluetooth is enabled on your device
   - 检查系统设置中的应用权限 | Check app permissions in system settings

2. **无法找到设备** | Cannot find devices
   - 确保智能眼镜已开机并处于配对模式 | Make sure the smart glasses are powered on and in pairing mode
   - 检查设备是否在蓝牙范围内 | Check that devices are within Bluetooth range

3. **连接失败** | Connection fails
   - 验证设备兼容性 | Verify device compatibility
   - 尝试重置智能眼镜 | Try resetting the smart glasses
   - 检查固件更新 | Check for firmware updates

4. **功能不工作** | Features not working
   - 确保设备已正确连接 | Ensure the device is properly connected
   - 检查电池电量 | Check battery level
   - 验证设备支持该特定功能 | Verify device supports the specific feature

### 调试模式 | Debug Mode

启用调试日志来排查问题 | Enable debug logging to troubleshoot issues:
```dart
// 在应用初始化中 | In your app initialization
MoYoungGlassesBle.setLogLevel(LogLevel.debug);
```

## 📞 支持与联系 | Support & Contact

- **GitHub Repository**: https://github.com/liangqian609/moyoung_glasses_ble_plugin
- **Technical Support**: jack@moyoung.com
- **Documentation**: 完整API文档可在仓库中查看 | Complete API documentation available in the repository

## 📄 许可证 | License

本示例应用采用MIT许可证 - 详情请查看LICENSE文件 | This example app is licensed under the MIT License - see the LICENSE file for details.

---

*最后更新 | Last Updated: 2026-01-26*
