Skip to content

Commit

Permalink
update many deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Dec 21, 2024
1 parent 60def20 commit 3502b19
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 46 deletions.
16 changes: 10 additions & 6 deletions lib/Backend/Definitions/Device/device_definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ enum DeviceState { standby, runAction, busy }

enum GlowtipStatus { glowtip, noGlowtip, unknown }

enum tailControlStatus { tailControl, legacy, unknown }
enum TailControlStatus { tailControl, legacy, unknown }

@freezed
class BluetoothUartService with _$BluetoothUartService {
const factory BluetoothUartService({
required String bleDeviceService,
required String bleRxCharacteristic,
required String bleTxCharacteristic,
required String label,
}) = _BluetoothUartService;
}

Expand All @@ -139,17 +140,20 @@ final List<BluetoothUartService> uartServices = const [
bleDeviceService: "3af2108b-d066-42da-a7d4-55648fa0a9b6",
bleRxCharacteristic: "c6612b64-0087-4974-939e-68968ef294b0",
bleTxCharacteristic: "5bfd6484-ddee-4723-bfe6-b653372bbfd6",
label: "Legacy Gear",
),
BluetoothUartService(
bleDeviceService: "927dee04-ddd4-4582-8e42-69dc9fbfae66",
bleRxCharacteristic: "0b646a19-371e-4327-b169-9632d56c0e84",
bleTxCharacteristic: "05e026d8-b395-4416-9f8a-c00d6c3781b9",
label: "Legacy Ears",
),
// TailCoNTROL uuids
BluetoothUartService(
bleDeviceService: "19f8ade2-d0c6-4c0a-912a-30601d9b3060",
bleRxCharacteristic: "567a99d6-a442-4ac0-b676-4993bf95f805",
bleTxCharacteristic: "5e4d86ac-ef2f-466f-a857-8776d45ffbc2",
label: "TailCoNTROL",
),
];

Expand Down Expand Up @@ -184,7 +188,7 @@ class BaseStatefulDevice {
final ValueNotifier<GearConfigInfo> gearConfigInfo = ValueNotifier(GearConfigInfo());
final ValueNotifier<FWInfo?> fwInfo = ValueNotifier(null);
final ValueNotifier<bool> hasUpdate = ValueNotifier(false);
final ValueNotifier<tailControlStatus> isTailCoNTROL = ValueNotifier(tailControlStatus.unknown);
final ValueNotifier<TailControlStatus> isTailCoNTROL = ValueNotifier(TailControlStatus.unknown);

late final Stream<String> rxCharacteristicStream;
late final CommandQueue commandQueue;
Expand Down Expand Up @@ -228,16 +232,16 @@ class BaseStatefulDevice {
bluetoothUartService.addListener(
() {
if (bluetoothUartService.value == null) {
isTailCoNTROL.value = tailControlStatus.unknown;
isTailCoNTROL.value = TailControlStatus.unknown;
return;
}

isTailCoNTROL.value = bluetoothUartService.value ==
uartServices.firstWhere(
(element) => element.bleDeviceService.toLowerCase() == "19f8ade2-d0c6-4c0a-912a-30601d9b3060",
)
? tailControlStatus.tailControl
: tailControlStatus.legacy;
? TailControlStatus.tailControl
: TailControlStatus.legacy;
},
);
}
Expand All @@ -260,7 +264,7 @@ class BaseStatefulDevice {
stopWatch.reset();
mtu.value = -1;
mandatoryOtaRequired.value = false;
isTailCoNTROL.value = tailControlStatus.unknown;
isTailCoNTROL.value = TailControlStatus.unknown;
bluetoothUartService.value = null;
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/Backend/action_registry.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:built_collection/built_collection.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import 'Bluetooth/bluetooth_manager.dart';
Expand Down Expand Up @@ -300,13 +301,13 @@ class GetAvailableActions extends _$GetAvailableActions {
if (baseAction.deviceCategory.contains(baseStatefulDevice.baseDeviceDefinition.deviceType) && ((baseAction.actionCategory == ActionCategory.glowtip && baseStatefulDevice.hasGlowtip.value == GlowtipStatus.glowtip) || baseAction.actionCategory != ActionCategory.glowtip)) {
// Handle migrating ears to unified firmware
if (baseAction.deviceCategory.contains(DeviceType.ears) && baseStatefulDevice.baseDeviceDefinition.deviceType == DeviceType.ears) {
if (baseStatefulDevice.isTailCoNTROL.value == tailControlStatus.tailControl) {
if (baseStatefulDevice.isTailCoNTROL.value == TailControlStatus.tailControl) {
// skip legacy moves
if (baseAction is EarsMoveList) {
continue;
}
// skip unified moves for legacy firmware ears
} else if (baseStatefulDevice.isTailCoNTROL.value == tailControlStatus.legacy) {
} else if (baseStatefulDevice.isTailCoNTROL.value == TailControlStatus.legacy) {
if (baseAction is CommandAction) {
continue;
}
Expand Down Expand Up @@ -339,7 +340,7 @@ class GetAvailableActions extends _$GetAvailableActions {
}

@Riverpod(keepAlive: true)
BuiltMap<ActionCategory, BuiltSet<BaseAction>> getAllActions(GetAllActionsRef ref) {
BuiltMap<ActionCategory, BuiltSet<BaseAction>> getAllActions(Ref ref) {
Map<ActionCategory, Set<BaseAction>> sortedActions = {};
final BuiltList<MoveList> moveLists = ref.watch(moveListsProvider);
final BuiltList<AudioAction> audioActions = ref.watch(userAudioActionsProvider);
Expand All @@ -366,7 +367,7 @@ BuiltMap<ActionCategory, BuiltSet<BaseAction>> getAllActions(GetAllActionsRef re
}

@Riverpod(keepAlive: true)
BaseAction? getActionFromUUID(GetActionFromUUIDRef ref, String? uuid) {
BaseAction? getActionFromUUID(Ref ref, String? uuid) {
if (uuid == null) {
return null;
}
Expand Down
5 changes: 2 additions & 3 deletions lib/Backend/app_shortcuts.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:built_collection/built_collection.dart';
import 'package:collection/collection.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
Expand All @@ -16,7 +15,7 @@ part 'app_shortcuts.g.dart';
const QuickActions quickActions = QuickActions();

@Riverpod(keepAlive: true)
Future<void> appShortcuts(AppShortcutsRef ref) async {
Future<void> appShortcuts(Ref ref) async {
await Future.delayed(const Duration(seconds: 5));
quickActions.initialize((shortcutType) {
BaseAction? action = ref.read(getActionFromUUIDProvider(shortcutType));
Expand All @@ -35,7 +34,7 @@ Future<void> updateShortcuts(BuiltList<FavoriteAction> favoriteActions, Ref ref)
.map(
(e) => ref.read(getActionFromUUIDProvider(e.actionUUID)),
)
.whereNotNull();
.nonNulls;

quickActions.setShortcutItems(
allActions
Expand Down
15 changes: 8 additions & 7 deletions lib/Backend/device_registry.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:built_collection/built_collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart' as log;
import 'package:riverpod_annotation/riverpod_annotation.dart';

Expand Down Expand Up @@ -74,7 +75,7 @@ class DeviceRegistry {
}

@Riverpod(keepAlive: true)
BuiltSet<BaseStatefulDevice> getByAction(GetByActionRef ref, BaseAction baseAction) {
BuiltSet<BaseStatefulDevice> getByAction(Ref ref, BaseAction baseAction) {
deviceRegistryLogger.info("Getting devices for action::$baseAction");
Set<BaseStatefulDevice> foundDevices = {};
final BuiltList<BaseStatefulDevice> watch = ref.watch(getAvailableIdleGearProvider);
Expand Down Expand Up @@ -109,7 +110,7 @@ class GetAvailableIdleGear extends _$GetAvailableIdleGear {
}

@Riverpod(keepAlive: true)
BuiltSet<DeviceType> getAvailableGearTypes(GetAvailableGearTypesRef ref) {
BuiltSet<DeviceType> getAvailableGearTypes(Ref ref) {
final BuiltList<BaseStatefulDevice> watch = ref.watch(getAvailableGearProvider);
return watch
.map(
Expand All @@ -119,13 +120,13 @@ BuiltSet<DeviceType> getAvailableGearTypes(GetAvailableGearTypesRef ref) {
}

@Riverpod(keepAlive: true)
BuiltList<BaseStatefulDevice> getAvailableIdleGearForAction(GetAvailableIdleGearForActionRef ref, BaseAction baseAction) {
BuiltList<BaseStatefulDevice> getAvailableIdleGearForAction(Ref ref, BaseAction baseAction) {
final BuiltList<BaseStatefulDevice> watch = ref.watch(getAvailableIdleGearProvider);
return watch.where((element) => baseAction.deviceCategory.contains(element.baseDeviceDefinition.deviceType)).toBuiltList();
}

@Riverpod(keepAlive: true)
BuiltList<BaseStatefulDevice> getAvailableIdleGearForType(GetAvailableIdleGearForTypeRef ref, BuiltSet<DeviceType> deviceTypes) {
BuiltList<BaseStatefulDevice> getAvailableIdleGearForType(Ref ref, BuiltSet<DeviceType> deviceTypes) {
final Iterable<BaseStatefulDevice> watch = ref.watch(getAvailableIdleGearProvider);
return watch
.where(
Expand All @@ -135,7 +136,7 @@ BuiltList<BaseStatefulDevice> getAvailableIdleGearForType(GetAvailableIdleGearFo
}

@Riverpod(keepAlive: true)
BuiltList<BaseStatefulDevice> getAvailableGearForType(GetAvailableGearForTypeRef ref, BuiltSet<DeviceType> deviceTypes) {
BuiltList<BaseStatefulDevice> getAvailableGearForType(Ref ref, BuiltSet<DeviceType> deviceTypes) {
final BuiltList<BaseStatefulDevice> watch = ref.watch(getAvailableGearProvider);
return watch
.where(
Expand All @@ -145,7 +146,7 @@ BuiltList<BaseStatefulDevice> getAvailableGearForType(GetAvailableGearForTypeRef
}

@Riverpod(keepAlive: true)
BuiltList<BaseStatefulDevice> getKnownGearForType(GetKnownGearForTypeRef ref, BuiltSet<DeviceType> deviceTypes) {
BuiltList<BaseStatefulDevice> getKnownGearForType(Ref ref, BuiltSet<DeviceType> deviceTypes) {
final BuiltMap<String, BaseStatefulDevice> watch = ref.watch(knownDevicesProvider);
return watch.values
.where(
Expand Down Expand Up @@ -197,7 +198,7 @@ class GetAvailableGear extends _$GetAvailableGear {
}

@Riverpod(keepAlive: true)
bool isAllKnownGearConnected(IsAllKnownGearConnectedRef ref) {
bool isAllKnownGearConnected(Ref ref) {
var knownGear = ref.watch(knownDevicesProvider);
BuiltList<BaseStatefulDevice> connectedGear = ref.watch(getAvailableGearProvider);
return knownGear.length == connectedGear.length;
Expand Down
9 changes: 5 additions & 4 deletions lib/Backend/firmware_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:crypto/crypto.dart';
import 'package:dio/dio.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:logging/logging.dart';
import 'package:package_info_plus/package_info_plus.dart';
Expand Down Expand Up @@ -38,7 +39,7 @@ class FWInfo with _$FWInfo {
}

@Riverpod(keepAlive: true)
Future<List<FWInfo>?> getBaseFirmwareInfo(GetBaseFirmwareInfoRef ref, String url) async {
Future<List<FWInfo>?> getBaseFirmwareInfo(Ref ref, String url) async {
Dio dio = await initDio();
Future<Response<String>> valueFuture = dio.get(url, options: Options(responseType: ResponseType.json))
..onError((error, stackTrace) {
Expand All @@ -57,7 +58,7 @@ Future<List<FWInfo>?> getBaseFirmwareInfo(GetBaseFirmwareInfoRef ref, String url
}

@Riverpod()
Future<FWInfo?> getFirmwareInfo(GetFirmwareInfoRef ref, String url, String hwVer) async {
Future<FWInfo?> getFirmwareInfo(Ref ref, String url, String hwVer) async {
if (url.isEmpty || hwVer.isEmpty) {
return null;
}
Expand Down Expand Up @@ -87,7 +88,7 @@ Future<FWInfo?> getFirmwareInfo(GetFirmwareInfoRef ref, String url, String hwVer
}

@Riverpod()
Future<FWInfo?> checkForFWUpdate(CheckForFWUpdateRef ref, BaseStatefulDevice baseStatefulDevice) async {
Future<FWInfo?> checkForFWUpdate(Ref ref, BaseStatefulDevice baseStatefulDevice) async {
if (baseStatefulDevice.fwInfo.value != null) {
return baseStatefulDevice.fwInfo.value;
}
Expand All @@ -106,7 +107,7 @@ Future<FWInfo?> checkForFWUpdate(CheckForFWUpdateRef ref, BaseStatefulDevice bas
}

@Riverpod()
Future<bool> hasOtaUpdate(HasOtaUpdateRef ref, BaseStatefulDevice baseStatefulDevice) async {
Future<bool> hasOtaUpdate(Ref ref, BaseStatefulDevice baseStatefulDevice) async {
FWInfo? fwInfo = await ref.read(checkForFWUpdateProvider(baseStatefulDevice).future);
Version fwVersion = baseStatefulDevice.fwVersion.value;

Expand Down
6 changes: 3 additions & 3 deletions lib/Backend/move_lists.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Future<void> runAction(BaseAction action, BaseStatefulDevice device) async {
} else if (action is MoveList) {
sequencesLogger.info("Starting MoveList ${action.name}.");
//plausible.event(name: "Run Sequence", props: {"Sequence Repeat": action.repeat.toInt().toString(), "Sequence Device Type": device.baseDeviceDefinition.deviceType.name, "Sequence Moves": action.moves.length.toString()});
if (action.moves.isNotEmpty && action.moves.length <= 5 && (device.baseDeviceDefinition.deviceType != DeviceType.ears || device.isTailCoNTROL.value == tailControlStatus.tailControl)) {
if (action.moves.isNotEmpty && action.moves.length <= 5 && (device.baseDeviceDefinition.deviceType != DeviceType.ears || device.isTailCoNTROL.value == TailControlStatus.tailControl)) {
int preset = 1; //TODO: store
String cmd = "USERMOVE U${preset}P${action.moves.length}N${action.repeat.toInt()}";
String a = ''; // servo 1 position
Expand Down Expand Up @@ -283,14 +283,14 @@ List<BluetoothMessage> generateMoveCommand(Move move, BaseStatefulDevice device,
List<BluetoothMessage> commands = [];
if (move.moveType == MoveType.home) {
//TODO: Remove for TAILCoNTROL update
if (device.baseDeviceDefinition.deviceType == DeviceType.ears && device.isTailCoNTROL.value != tailControlStatus.tailControl) {
if (device.baseDeviceDefinition.deviceType == DeviceType.ears && device.isTailCoNTROL.value != TailControlStatus.tailControl) {
commands.add(BluetoothMessage(message: "EARHOME", device: device, priority: priority, responseMSG: noResponseMsg ? null : "EARHOME END", type: type, timestamp: DateTime.now()));
} else {
commands.add(BluetoothMessage(message: "TAILHM", device: device, priority: priority, responseMSG: noResponseMsg ? null : "END TAILHM", type: type, timestamp: DateTime.now()));
}
} else if (move.moveType == MoveType.move) {
//TODO: Remove for TAILCoNTROL update
if (device.baseDeviceDefinition.deviceType == DeviceType.ears && device.isTailCoNTROL.value != tailControlStatus.tailControl) {
if (device.baseDeviceDefinition.deviceType == DeviceType.ears && device.isTailCoNTROL.value != TailControlStatus.tailControl) {
commands
..add(
BluetoothMessage(
Expand Down
6 changes: 3 additions & 3 deletions lib/Backend/sensors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
bool hasLegacyEars = ref
.read(getAvailableIdleGearForTypeProvider([DeviceType.ears].toBuiltSet()))
.where(
(p0) => p0.isTailCoNTROL.value == tailControlStatus.legacy,
(p0) => p0.isTailCoNTROL.value == TailControlStatus.legacy,
)
.isNotEmpty;
// add a glowtip action if it exists
Expand Down Expand Up @@ -292,9 +292,9 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
runAction(baseAction, baseStatefulDevice);
if (!const [ActionCategory.glowtip].contains(baseAction.actionCategory)) {
// handle tailcontrol migration by not counting the actions as used.
if (baseAction is CommandAction && baseStatefulDevice.baseDeviceDefinition.deviceType == DeviceType.ears && baseStatefulDevice.isTailCoNTROL.value == tailControlStatus.legacy) {
if (baseAction is CommandAction && baseStatefulDevice.baseDeviceDefinition.deviceType == DeviceType.ears && baseStatefulDevice.isTailCoNTROL.value == TailControlStatus.legacy) {
continue;
} else if (baseAction is EarsMoveList && baseStatefulDevice.baseDeviceDefinition.deviceType == DeviceType.ears && baseStatefulDevice.isTailCoNTROL.value == tailControlStatus.tailControl) {
} else if (baseAction is EarsMoveList && baseStatefulDevice.baseDeviceDefinition.deviceType == DeviceType.ears && baseStatefulDevice.isTailCoNTROL.value == TailControlStatus.tailControl) {
continue;
}
sentDeviceTypes.add(baseStatefulDevice.baseDeviceDefinition.deviceType);
Expand Down
7 changes: 4 additions & 3 deletions lib/Backend/wear_bridge.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:built_collection/built_collection.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:logging/logging.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
Expand All @@ -23,7 +24,7 @@ StreamSubscription<Map<String, dynamic>>? _contextStreamSubscription;
final _watch = WatchConnectivity();

@Riverpod(keepAlive: true)
Future<void> initWear(InitWearRef ref) async {
Future<void> initWear(Ref ref) async {
await Future.delayed(const Duration(seconds: 5));
try {
// Get the state of device connectivity
Expand All @@ -34,7 +35,7 @@ Future<void> initWear(InitWearRef ref) async {
(event) => _wearLogger.info("Watch Context: $event"),
);

ref.read(updateWearActionsProvider);
//ref.read(updateWearActionsProvider);
} catch (e, s) {
_wearLogger.severe("exception setting up Wear $e", e, s);
}
Expand Down Expand Up @@ -65,7 +66,7 @@ Future<Map<String, dynamic>> applicationContext() {
}

@Riverpod()
Future<void> updateWearActions(UpdateWearActionsRef ref) async {
Future<void> updateWearActions(Ref ref) async {
if (await isWear()) {
return;
}
Expand Down
23 changes: 20 additions & 3 deletions lib/Frontend/Widgets/manage_gear.dart
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ class _ManageGearDebugState extends State<ManageGearDebug> {
Text("UNSUPPORTED: ${widget.device.baseDeviceDefinition.unsupported}"),
Text("MIN FIRMWARE: ${widget.device.baseDeviceDefinition.minVersion}"),
Text("NVS Config: ${widget.device.gearConfigInfo.value}"),
Text("UART Service: ${widget.device.bluetoothUartService.value}"),
],
),
),
Expand Down Expand Up @@ -584,7 +583,7 @@ class _ManageGearDebugState extends State<ManageGearDebug> {
),
ListTile(
title: const Text("isTailCoNTROL"),
trailing: DropdownMenu<tailControlStatus>(
trailing: DropdownMenu<TailControlStatus>(
initialSelection: widget.device.isTailCoNTROL.value,
onSelected: (value) {
if (value != null) {
Expand All @@ -595,13 +594,31 @@ class _ManageGearDebugState extends State<ManageGearDebug> {
);
}
},
dropdownMenuEntries: tailControlStatus.values
dropdownMenuEntries: TailControlStatus.values
.map(
(e) => DropdownMenuEntry(value: e, label: e.name),
)
.toList(),
),
),
ListTile(
title: const Text("bluetoothUartService"),
trailing: DropdownMenu<BluetoothUartService>(
initialSelection: widget.device.bluetoothUartService.value,
onSelected: (value) {
setState(
() {
widget.device.bluetoothUartService.value = value;
},
);
},
dropdownMenuEntries: uartServices
.map(
(e) => DropdownMenuEntry(value: e, label: e.label),
)
.toList(),
),
),
ListTile(
title: const Text("RSSI Level"),
subtitle: Slider(
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/Widgets/tail_blog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class _TailBlogImageState extends ConsumerState<TailBlogImage> {
}

@Riverpod(keepAlive: true)
Future<Widget> getBlogImage(GetBlogImageRef ref, String url) async {
Future<Widget> getBlogImage(Ref ref, String url) async {
if (!await tailBlogConnectivityCheck()) {
return Container();
}
Expand Down
Loading

0 comments on commit 3502b19

Please sign in to comment.