Fix local dev config and ALOTTTT OFF FLUTTER, im tired boss..
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import '../services/haptic_service.dart';
|
||||
import '../services/tts_service.dart';
|
||||
import 'obstacle_analyzer.dart';
|
||||
|
||||
abstract class ObstacleAlertStrategy {
|
||||
Future<void> alert(DetectionResult detection);
|
||||
}
|
||||
|
||||
class TtsOnlyObstacleAlertStrategy implements ObstacleAlertStrategy {
|
||||
final TtsService _ttsService;
|
||||
|
||||
const TtsOnlyObstacleAlertStrategy(this._ttsService);
|
||||
|
||||
@override
|
||||
Future<void> alert(DetectionResult detection) {
|
||||
return _ttsService.speakImmediate(detection.spokenId);
|
||||
}
|
||||
}
|
||||
|
||||
class HapticOnlyObstacleAlertStrategy implements ObstacleAlertStrategy {
|
||||
final HapticService _hapticService;
|
||||
|
||||
const HapticOnlyObstacleAlertStrategy(this._hapticService);
|
||||
|
||||
@override
|
||||
Future<void> alert(DetectionResult detection) {
|
||||
return _vibrateByDistance(detection);
|
||||
}
|
||||
|
||||
Future<void> _vibrateByDistance(DetectionResult detection) {
|
||||
final distance = detection.estimatedDistance.toLowerCase();
|
||||
if (distance.startsWith('very close')) {
|
||||
return _hapticService.obstacleVeryClose();
|
||||
}
|
||||
if (distance.startsWith('close')) {
|
||||
return _hapticService.obstacleClose();
|
||||
}
|
||||
return _hapticService.obstacleMedium();
|
||||
}
|
||||
}
|
||||
|
||||
class TtsWithHapticObstacleAlertStrategy implements ObstacleAlertStrategy {
|
||||
final TtsService _ttsService;
|
||||
final HapticService _hapticService;
|
||||
|
||||
const TtsWithHapticObstacleAlertStrategy(
|
||||
this._ttsService,
|
||||
this._hapticService,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> alert(DetectionResult detection) async {
|
||||
final haptic = HapticOnlyObstacleAlertStrategy(_hapticService);
|
||||
await haptic.alert(detection);
|
||||
await _ttsService.speakImmediate(detection.spokenId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user