You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.0 KiB
104 lines
3.0 KiB
import 'dart:async';
|
|
|
|
import 'package:ble_service/ble_service.dart';
|
|
import 'package:flutter_intro/flutter_intro.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:get_storage/get_storage.dart';
|
|
|
|
class NoviceGuideService extends GetxService {
|
|
final GetStorage _storage = GetStorage();
|
|
|
|
final BleService _bleService = BleService();
|
|
StreamSubscription<dynamic>? _statusSubscription;
|
|
|
|
bool isHomeGuide = false;
|
|
bool isAIGuide = true;
|
|
|
|
RxBool isWakeup = false.obs;
|
|
|
|
int aiStep = 0;
|
|
|
|
List aiStepsList = [
|
|
{
|
|
'start': '对小言说:“今天天气怎么样”',
|
|
'input': '今天天气怎么样',
|
|
'send': '小言会为你实时为你播报天气',
|
|
'end': '小言能实时为你播报天气,试试其他指令吧',
|
|
},
|
|
{
|
|
'start': '对小言说:“请播放一组摇滚乐”',
|
|
'input': '请播放一组摇滚乐',
|
|
'send': '小言会为你搜寻到一组音乐',
|
|
'end': '小言已成功为您搜寻到一组音乐,试试其他指令吧',
|
|
},
|
|
{
|
|
'start': '对小言说:“导航到深圳机场”',
|
|
'input': '导航到深圳机场',
|
|
'send': '小言会为你规划路线',
|
|
'end': '小言已成功为您导航到深圳机场,试试其他指令吧',
|
|
},
|
|
{
|
|
'start': '对小言说:“明天下午3点创建会议提醒”',
|
|
'input': '明天下午3点创建会议提醒',
|
|
'send': '小言会为你创建会议提醒',
|
|
'end': '小言已成功为您创建会议提醒,试试其他指令吧',
|
|
},
|
|
{
|
|
'start': '对小言说:“拨打妈妈的电话”',
|
|
'input': '拨打妈妈的电话',
|
|
'send': '小言会为你拨打电话',
|
|
'end': '小言已成功为您拨打电话,试试其他指令吧',
|
|
},
|
|
{
|
|
'start': '对小言说:“给爸爸发短信说晚上回家吃饭’”',
|
|
'input': '给爸爸发短信说晚上回家吃饭’',
|
|
'send': '小言会为你发送短信',
|
|
'end': '短信已发送,语音操控更便捷',
|
|
},
|
|
];
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
// isHomeGuide = _storage.read('home_guide') ?? false;
|
|
// isAIGuide = _storage.read('ai_guide') ?? false;
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
closeWakeupListen();
|
|
super.onClose();
|
|
}
|
|
|
|
void startHomeGuide() async {
|
|
if (!isHomeGuide) {
|
|
await Future.delayed(const Duration(milliseconds: 200));
|
|
isHomeGuide = true;
|
|
_storage.write('home_guide', true);
|
|
Intro.of(Get.context!).start(group: 'home');
|
|
}
|
|
}
|
|
|
|
void startAIGuide() async {
|
|
if (!isAIGuide) {
|
|
await Future.delayed(const Duration(milliseconds: 200));
|
|
isAIGuide = true;
|
|
_storage.write('ai_guide', true);
|
|
Intro.of(Get.context!).start(group: 'ai');
|
|
}
|
|
}
|
|
|
|
void startWakeupListen() {
|
|
_bleService.setWakeup(false);
|
|
_statusSubscription = _bleService.onStatusUpdated.listen((event) {
|
|
if (event is Map && event['type'] == 'wakeup') {
|
|
isWakeup.value = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
void closeWakeupListen() {
|
|
_bleService.setWakeup(true);
|
|
_statusSubscription?.cancel();
|
|
}
|
|
}
|
|
|