indicate EV value error

This commit is contained in:
Vadim 2023-05-05 23:08:20 +02:00
parent 5602b1ed80
commit 9a21d5f2f5
11 changed files with 81 additions and 60 deletions

View file

@ -7,9 +7,11 @@ class HapticsService {
Future<void> responseVibration() async => _tryVibrate(duration: 50, amplitude: 128); Future<void> responseVibration() async => _tryVibrate(duration: 50, amplitude: 128);
Future<void> errorVibration() async => _tryVibrate(duration: 100, amplitude: 128);
Future<void> _tryVibrate({required int duration, required int amplitude}) async { Future<void> _tryVibrate({required int duration, required int amplitude}) async {
if (await _canVibrate()) { if (await _canVibrate()) {
Vibration.vibrate( await Vibration.vibrate(
duration: duration, duration: duration,
amplitude: amplitude, amplitude: amplitude,
); );

View file

@ -33,13 +33,18 @@ class MeteringInteractor {
bool get isHapticsEnabled => _userPreferencesService.haptics; bool get isHapticsEnabled => _userPreferencesService.haptics;
/// Executes vibration if haptics are enabled in settings /// Executes vibration if haptics are enabled in settings
void quickVibration() { Future<void> quickVibration() async {
if (_userPreferencesService.haptics) _hapticsService.quickVibration(); if (_userPreferencesService.haptics) await _hapticsService.quickVibration();
} }
/// Executes vibration if haptics are enabled in settings /// Executes vibration if haptics are enabled in settings
void responseVibration() { Future<void> responseVibration() async {
if (_userPreferencesService.haptics) _hapticsService.responseVibration(); if (_userPreferencesService.haptics) await _hapticsService.responseVibration();
}
/// Executes vibration if haptics are enabled in settings
Future<void> errorVibration() async {
if (_userPreferencesService.haptics) await _hapticsService.errorVibration();
} }
Future<bool> checkCameraPermission() async { Future<bool> checkCameraPermission() async {

View file

@ -32,7 +32,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
late IsoValue _iso = _userPreferencesService.iso; late IsoValue _iso = _userPreferencesService.iso;
late NdValue _nd = _userPreferencesService.ndFilter; late NdValue _nd = _userPreferencesService.ndFilter;
late Film _film = _userPreferencesService.film; late Film _film = _userPreferencesService.film;
double _ev100 = 0.0; double? _ev100 = 0.0;
bool _isMeteringInProgress = false; bool _isMeteringInProgress = false;
MeteringBloc( MeteringBloc(
@ -42,12 +42,13 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
this._equipmentProfileData, this._equipmentProfileData,
this.stopType, this.stopType,
) : super( ) : super(
MeteringEndedState( MeteringDataState(
ev: 0.0, ev: 0.0,
film: _userPreferencesService.film, film: _userPreferencesService.film,
iso: _userPreferencesService.iso, iso: _userPreferencesService.iso,
nd: _userPreferencesService.ndFilter, nd: _userPreferencesService.ndFilter,
exposurePairs: const [], exposurePairs: const [],
continuousMetering: false,
), ),
) { ) {
_communicationSubscription = _communicationBloc.stream _communicationSubscription = _communicationBloc.stream
@ -62,6 +63,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
on<NdChangedEvent>(_onNdChanged); on<NdChangedEvent>(_onNdChanged);
on<MeasureEvent>(_onMeasure); on<MeasureEvent>(_onMeasure);
on<MeasuredEvent>(_onMeasured); on<MeasuredEvent>(_onMeasured);
on<MeasureErrorEvent>(_onMeasureError);
} }
@override @override
@ -73,13 +75,13 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
void _onCommunicationState(communication_states.ScreenState communicationState) { void _onCommunicationState(communication_states.ScreenState communicationState) {
if (communicationState is communication_states.MeasuredState) { if (communicationState is communication_states.MeasuredState) {
_isMeteringInProgress = communicationState is communication_states.MeteringInProgressState; _isMeteringInProgress = communicationState is communication_states.MeteringInProgressState;
add(MeasuredEvent(communicationState.ev100)); _handleEv100(communicationState.ev100);
} }
} }
void _onStopTypeChanged(StopTypeChangedEvent event, Emitter emit) { void _onStopTypeChanged(StopTypeChangedEvent event, Emitter emit) {
stopType = event.stopType; stopType = event.stopType;
_emitMeasuredState(emit); _updateMeasurements();
} }
void _onEquipmentProfileChanged(EquipmentProfileChangedEvent event, Emitter emit) { void _onEquipmentProfileChanged(EquipmentProfileChangedEvent event, Emitter emit) {
@ -98,7 +100,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
_nd = event.equipmentProfileData.ndValues.first; _nd = event.equipmentProfileData.ndValues.first;
} }
_emitMeasuredState(emit); _updateMeasurements();
} }
void _onFilmChanged(FilmChangedEvent event, Emitter emit) { void _onFilmChanged(FilmChangedEvent event, Emitter emit) {
@ -111,7 +113,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
} }
_film = event.data; _film = event.data;
_userPreferencesService.film = event.data; _userPreferencesService.film = event.data;
_emitMeasuredState(emit); _updateMeasurements();
} }
void _onIsoChanged(IsoChangedEvent event, Emitter emit) { void _onIsoChanged(IsoChangedEvent event, Emitter emit) {
@ -120,47 +122,57 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
} }
_userPreferencesService.iso = event.isoValue; _userPreferencesService.iso = event.isoValue;
_iso = event.isoValue; _iso = event.isoValue;
_emitMeasuredState(emit); _updateMeasurements();
} }
void _onNdChanged(NdChangedEvent event, Emitter emit) { void _onNdChanged(NdChangedEvent event, Emitter emit) {
_userPreferencesService.ndFilter = event.ndValue; _userPreferencesService.ndFilter = event.ndValue;
_nd = event.ndValue; _nd = event.ndValue;
_emitMeasuredState(emit); _updateMeasurements();
} }
void _onMeasure(_, Emitter emit) { void _onMeasure(MeasureEvent _, Emitter emit) {
_meteringInteractor.quickVibration(); _meteringInteractor.quickVibration();
_communicationBloc.add(const communication_events.MeasureEvent()); _communicationBloc.add(const communication_events.MeasureEvent());
_isMeteringInProgress = true; _isMeteringInProgress = true;
emit(const LoadingState()); emit(const LoadingState());
} }
void _updateMeasurements() => _handleEv100(_ev100);
void _handleEv100(double? ev100) {
if (ev100 == null || ev100.isNaN || ev100.isInfinite) {
add(const MeasureErrorEvent());
} else {
add(MeasuredEvent(ev100));
}
}
void _onMeasured(MeasuredEvent event, Emitter emit) { void _onMeasured(MeasuredEvent event, Emitter emit) {
_meteringInteractor.responseVibration(); _meteringInteractor.responseVibration();
_ev100 = event.ev100; _ev100 = event.ev100;
_emitMeasuredState(emit); final ev = event.ev100 + log2(_iso.value / 100) - _nd.stopReduction;
emit(MeteringDataState(
ev: ev,
film: _film,
iso: _iso,
nd: _nd,
exposurePairs: _buildExposureValues(ev),
continuousMetering: _isMeteringInProgress,
));
} }
void _emitMeasuredState(Emitter emit) { void _onMeasureError(MeasureErrorEvent _, Emitter emit) {
final ev = _ev100 + log2(_iso.value / 100) - _nd.stopReduction; _meteringInteractor.errorVibration();
emit( _ev100 = null;
_isMeteringInProgress emit(MeteringDataState(
? MeteringInProgressState( ev: null,
ev: ev, film: _film,
film: _film, iso: _iso,
iso: _iso, nd: _nd,
nd: _nd, exposurePairs: const [],
exposurePairs: _buildExposureValues(ev), continuousMetering: _isMeteringInProgress,
) ));
: MeteringEndedState(
ev: ev,
film: _film,
iso: _iso,
nd: _nd,
exposurePairs: _buildExposureValues(ev),
),
);
} }
List<ExposurePair> _buildExposureValues(double ev) { List<ExposurePair> _buildExposureValues(double ev) {

View file

@ -15,7 +15,7 @@ class MeasureEvent extends ScreenEvent {
} }
abstract class MeasuredEvent extends SourceEvent { abstract class MeasuredEvent extends SourceEvent {
final double ev100; final double? ev100;
const MeasuredEvent(this.ev100); const MeasuredEvent(this.ev100);
} }

View file

@ -19,7 +19,7 @@ class MeasureState extends SourceState {
} }
abstract class MeasuredState extends ScreenState { abstract class MeasuredState extends ScreenState {
final double ev100; final double? ev100;
const MeasuredState(this.ev100); const MeasuredState(this.ev100);
} }

View file

@ -6,11 +6,13 @@ import 'package:lightmeter/screens/shared/filled_circle/widget_circle_filled.dar
class MeteringMeasureButton extends StatefulWidget { class MeteringMeasureButton extends StatefulWidget {
final double? ev; final double? ev;
final bool isMetering; final bool isMetering;
final bool hasError;
final VoidCallback onTap; final VoidCallback onTap;
const MeteringMeasureButton({ const MeteringMeasureButton({
required this.ev, required this.ev,
required this.isMetering, required this.isMetering,
required this.hasError,
required this.onTap, required this.onTap,
super.key, super.key,
}); });
@ -63,7 +65,12 @@ class _MeteringMeasureButtonState extends State<MeteringMeasureButton> {
color: Theme.of(context).colorScheme.onSurface, color: Theme.of(context).colorScheme.onSurface,
size: Dimens.grid72 - Dimens.grid8, size: Dimens.grid72 - Dimens.grid8,
child: Center( child: Center(
child: widget.ev != null ? _EvValueText(ev: widget.ev!) : null, child: widget.hasError
? Icon(
Icons.error,
color: Theme.of(context).colorScheme.surface,
)
: (widget.ev != null ? _EvValueText(ev: widget.ev!) : null),
), ),
), ),
), ),

View file

@ -6,6 +6,7 @@ import 'package:lightmeter/screens/metering/components/bottom_controls/widget_bo
class MeteringBottomControlsProvider extends StatelessWidget { class MeteringBottomControlsProvider extends StatelessWidget {
final double? ev; final double? ev;
final bool isMetering; final bool isMetering;
final bool hasError;
final VoidCallback? onSwitchEvSourceType; final VoidCallback? onSwitchEvSourceType;
final VoidCallback onMeasure; final VoidCallback onMeasure;
final VoidCallback onSettings; final VoidCallback onSettings;
@ -13,6 +14,7 @@ class MeteringBottomControlsProvider extends StatelessWidget {
const MeteringBottomControlsProvider({ const MeteringBottomControlsProvider({
required this.ev, required this.ev,
required this.isMetering, required this.isMetering,
required this.hasError,
required this.onSwitchEvSourceType, required this.onSwitchEvSourceType,
required this.onMeasure, required this.onMeasure,
required this.onSettings, required this.onSettings,
@ -36,6 +38,7 @@ class MeteringBottomControlsProvider extends StatelessWidget {
child: MeteringBottomControls( child: MeteringBottomControls(
ev: ev, ev: ev,
isMetering: isMetering, isMetering: isMetering,
hasError: hasError,
onSwitchEvSourceType: onSwitchEvSourceType, onSwitchEvSourceType: onSwitchEvSourceType,
onMeasure: onMeasure, onMeasure: onMeasure,
onSettings: onSettings, onSettings: onSettings,

View file

@ -7,6 +7,7 @@ import 'package:provider/provider.dart';
class MeteringBottomControls extends StatelessWidget { class MeteringBottomControls extends StatelessWidget {
final double? ev; final double? ev;
final bool isMetering; final bool isMetering;
final bool hasError;
final VoidCallback? onSwitchEvSourceType; final VoidCallback? onSwitchEvSourceType;
final VoidCallback onMeasure; final VoidCallback onMeasure;
final VoidCallback onSettings; final VoidCallback onSettings;
@ -14,6 +15,7 @@ class MeteringBottomControls extends StatelessWidget {
const MeteringBottomControls({ const MeteringBottomControls({
required this.ev, required this.ev,
required this.isMetering, required this.isMetering,
required this.hasError,
required this.onSwitchEvSourceType, required this.onSwitchEvSourceType,
required this.onMeasure, required this.onMeasure,
required this.onSettings, required this.onSettings,
@ -54,6 +56,7 @@ class MeteringBottomControls extends StatelessWidget {
MeteringMeasureButton( MeteringMeasureButton(
ev: ev, ev: ev,
isMetering: isMetering, isMetering: isMetering,
hasError: hasError,
onTap: onMeasure, onTap: onMeasure,
), ),
Expanded( Expanded(

View file

@ -44,3 +44,7 @@ class MeasuredEvent extends MeteringEvent {
const MeasuredEvent(this.ev100); const MeasuredEvent(this.ev100);
} }
class MeasureErrorEvent extends MeteringEvent {
const MeasureErrorEvent();
}

View file

@ -63,7 +63,9 @@ class _MeteringScreenState extends State<MeteringScreen> {
BlocBuilder<MeteringBloc, MeteringState>( BlocBuilder<MeteringBloc, MeteringState>(
builder: (context, state) => MeteringBottomControlsProvider( builder: (context, state) => MeteringBottomControlsProvider(
ev: state is MeteringDataState ? state.ev : null, ev: state is MeteringDataState ? state.ev : null,
isMetering: state is LoadingState || state is MeteringInProgressState, isMetering:
state is LoadingState || state is MeteringDataState && state.continuousMetering,
hasError: state is MeteringDataState && state.hasError,
onSwitchEvSourceType: context.read<Environment>().hasLightSensor onSwitchEvSourceType: context.read<Environment>().hasLightSensor
? EvSourceTypeProvider.of(context).toggleType ? EvSourceTypeProvider.of(context).toggleType
: null, : null,

View file

@ -12,12 +12,13 @@ class LoadingState extends MeteringState {
const LoadingState(); const LoadingState();
} }
abstract class MeteringDataState extends MeteringState { class MeteringDataState extends MeteringState {
final double ev; final double? ev;
final Film film; final Film film;
final IsoValue iso; final IsoValue iso;
final NdValue nd; final NdValue nd;
final List<ExposurePair> exposurePairs; final List<ExposurePair> exposurePairs;
final bool continuousMetering;
const MeteringDataState({ const MeteringDataState({
required this.ev, required this.ev,
@ -25,28 +26,10 @@ abstract class MeteringDataState extends MeteringState {
required this.iso, required this.iso,
required this.nd, required this.nd,
required this.exposurePairs, required this.exposurePairs,
required this.continuousMetering,
}); });
ExposurePair? get fastest => exposurePairs.isEmpty ? null : exposurePairs.first; ExposurePair? get fastest => exposurePairs.isEmpty ? null : exposurePairs.first;
ExposurePair? get slowest => exposurePairs.isEmpty ? null : exposurePairs.last; ExposurePair? get slowest => exposurePairs.isEmpty ? null : exposurePairs.last;
} bool get hasError => ev == null;
class MeteringInProgressState extends MeteringDataState {
const MeteringInProgressState({
required super.ev,
required super.film,
required super.iso,
required super.nd,
required super.exposurePairs,
});
}
class MeteringEndedState extends MeteringDataState {
const MeteringEndedState({
required super.ev,
required super.film,
required super.iso,
required super.nd,
required super.exposurePairs,
});
} }