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> errorVibration() async => _tryVibrate(duration: 100, amplitude: 128);
Future<void> _tryVibrate({required int duration, required int amplitude}) async {
if (await _canVibrate()) {
Vibration.vibrate(
await Vibration.vibrate(
duration: duration,
amplitude: amplitude,
);

View file

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

View file

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

View file

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

View file

@ -19,7 +19,7 @@ class MeasureState extends SourceState {
}
abstract class MeasuredState extends ScreenState {
final double ev100;
final double? 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 {
final double? ev;
final bool isMetering;
final bool hasError;
final VoidCallback onTap;
const MeteringMeasureButton({
required this.ev,
required this.isMetering,
required this.hasError,
required this.onTap,
super.key,
});
@ -63,7 +65,12 @@ class _MeteringMeasureButtonState extends State<MeteringMeasureButton> {
color: Theme.of(context).colorScheme.onSurface,
size: Dimens.grid72 - Dimens.grid8,
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 {
final double? ev;
final bool isMetering;
final bool hasError;
final VoidCallback? onSwitchEvSourceType;
final VoidCallback onMeasure;
final VoidCallback onSettings;
@ -13,6 +14,7 @@ class MeteringBottomControlsProvider extends StatelessWidget {
const MeteringBottomControlsProvider({
required this.ev,
required this.isMetering,
required this.hasError,
required this.onSwitchEvSourceType,
required this.onMeasure,
required this.onSettings,
@ -36,6 +38,7 @@ class MeteringBottomControlsProvider extends StatelessWidget {
child: MeteringBottomControls(
ev: ev,
isMetering: isMetering,
hasError: hasError,
onSwitchEvSourceType: onSwitchEvSourceType,
onMeasure: onMeasure,
onSettings: onSettings,

View file

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

View file

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

View file

@ -63,7 +63,9 @@ class _MeteringScreenState extends State<MeteringScreen> {
BlocBuilder<MeteringBloc, MeteringState>(
builder: (context, state) => MeteringBottomControlsProvider(
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
? EvSourceTypeProvider.of(context).toggleType
: null,

View file

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