Skip to content

Commit 47ffe4f

Browse files
Jashan32marcnause
authored andcommitted
added lower limit to gyroscope
1 parent aaafaff commit 47ffe4f

6 files changed

Lines changed: 64 additions & 16 deletions

File tree

lib/l10n/app_en.arb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@
393393
"ms": "ms",
394394
"inBuiltSensor": "In-built Sensor",
395395
"updatePeriodErrorMessage": "Entered update period is not within the limits!",
396-
"highLimitErrorMessage": "High limit must be between 10 and 200 m/s².",
397-
"lowLimitErrorMessage": "Negative acceleration limit magnitude must be between 10 and 200 m/s².",
396+
"highLimitErrorMessage": "Entered High limit is not within the limits!",
397+
"lowLimitErrorMessage": "Entered Low limit is not within the limits!",
398398
"baroMeterBulletPoint1": "The Barometer can be used to measure Atmospheric pressure. This instrument is compatible with either the built in pressure sensor on any android device or the BMP-180 pressure sensor",
399399
"baroMeterBulletPoint2": "If you want to use the sensor BMP-180, connect the sensor to PSLab device as shown in the figure.",
400400
"baroMeterBulletPoint3": "The above pin configuration has to be same except for the pin GND. GND is meant for Ground and any of the PSLab device GND pins can be used since they are common.",
@@ -460,6 +460,7 @@
460460
"barometerHighLimitHint": "Please provide the maximum limit of atm value to be recorded (0 atm to 1.10 atm)",
461461
"gyroscopeConfigurations": "Gyroscope Configurations",
462462
"gyroscopeHighLimitHint": "Please provide the maximum limit of angular velocity value to be recorded (0 rad/s to 1000 rad/s)",
463+
"gyroscopeLowLimitHint": "Please provide the magnitude of the negative angular velocity limit to be recorded (0 rad/s to 1000 rad/s)",
463464
"accelerometerConfigurations": "Accelerometer Configurations",
464465
"accelerometerUpdatePeriodHint": "Please provide time interval at which data will be updated",
465466
"accelerometerHighLimitHint": "Please provide the maximum limit of acceleration value to be recorded",

lib/l10n/app_hi.arb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@
391391
"ms": "ms",
392392
"inBuiltSensor": "बिल्ट-इन सेंसर",
393393
"updatePeriodErrorMessage": "लिखा गया अपडेट टाइम लिमिट से बाहर है!",
394-
"highLimitErrorMessage": "हाई लिमिट 10 से 200 m/s² के बीच होनी चाहिए।",
395-
"lowLimitErrorMessage": "नेगेटिव एक्सेलेरेशन लिमिट का मान 10 से 200 m/s² के बीच होना चाहिए।",
394+
"highLimitErrorMessage": "लिखी गई हाई लिमिट लिमिट से बाहर है!",
395+
"lowLimitErrorMessage": "लिखी गई लो लिमिट सीमा से बाहर है!",
396396
"baroMeterBulletPoint1": "बैरोमीटर से हवा का प्रेशर मापते हैं। यह किसी भी Android डिवाइस के बिल्ट-इन प्रेशर सेंसर या BMP-180 प्रेशर सेंसर के साथ चलता है",
397397
"baroMeterBulletPoint2": "अगर BMP-180 सेंसर यूज़ करना है तो फोटो की तरह सेंसर को PSLab डिवाइस से जोड़ें।",
398398
"baroMeterBulletPoint3": "ऊपर वाला पिन कनेक्शन GND पिन को छोड़कर बाकी सब वैसा ही होगा। GND ग्राउंड के लिए है और PSLab का कोई भी GND पिन यूज़ कर सकते हैं क्योंकि वो कॉमन हैं।",
@@ -452,6 +452,7 @@
452452
"barometerHighLimitHint": "रिकॉर्ड करने के लिए atm की मैक्स लिमिट बताएं (0 atm से 1.10 atm)",
453453
"gyroscopeConfigurations": "जायरोस्कोप सेटिंग्स",
454454
"gyroscopeHighLimitHint": "रिकॉर्ड करने के लिए एंगुलर वेलोसिटी की मैक्स लिमिट बताएं (0 rad/s से 1000 rad/s)",
455+
"gyroscopeLowLimitHint": "रिकॉर्ड करने के लिए एंगुलर वेलोसिटी की मिन लिमिट बताएं (0 rad/s से 1000 rad/s)",
455456
"accelerometerConfigurations": "एक्सेलेरोमीटर सेटिंग्स",
456457
"accelerometerUpdatePeriodHint": "वो टाइम इंटरवल बताएं जिस पर डेटा अपडेट होगा",
457458
"accelerometerHighLimitHint": "रिकॉर्ड करने के लिए एक्सेलेरेशन की मैक्स लिमिट बताएं",

lib/models/gyroscope_config.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@ class GyroscopeConfig {
22
final int updatePeriod;
33
final int highLimit;
44
final int sensorGain;
5+
final int lowLimit;
56
final bool includeLocationData;
67

78
const GyroscopeConfig({
89
this.updatePeriod = 1000,
9-
this.highLimit = 20,
10+
this.highLimit = 200,
11+
this.lowLimit = 200,
1012
this.sensorGain = 1,
1113
this.includeLocationData = true,
1214
});
1315

1416
GyroscopeConfig copyWith({
1517
int? updatePeriod,
1618
int? highLimit,
19+
int? lowLimit,
1720
int? sensorGain,
1821
bool? includeLocationData,
1922
}) {
2023
return GyroscopeConfig(
2124
updatePeriod: updatePeriod ?? this.updatePeriod,
2225
highLimit: highLimit ?? this.highLimit,
26+
lowLimit: lowLimit ?? this.lowLimit,
2327
sensorGain: sensorGain ?? this.sensorGain,
2428
includeLocationData: includeLocationData ?? this.includeLocationData,
2529
);
@@ -29,6 +33,7 @@ class GyroscopeConfig {
2933
return {
3034
'updatePeriod': updatePeriod,
3135
'highLimit': highLimit,
36+
'lowLimit': lowLimit,
3237
'sensorGain': sensorGain,
3338
'includeLocationData': includeLocationData,
3439
};
@@ -37,7 +42,8 @@ class GyroscopeConfig {
3742
factory GyroscopeConfig.fromJson(Map<String, dynamic> json) {
3843
return GyroscopeConfig(
3944
updatePeriod: json['updatePeriod'] ?? 1000,
40-
highLimit: json['highLimit'] ?? 20,
45+
highLimit: json['highLimit'] ?? 200,
46+
lowLimit: json['lowLimit'] ?? 200,
4147
sensorGain: json['sensorGain'] ?? 1,
4248
includeLocationData: json['includeLocationData'] ?? true,
4349
);

lib/providers/gyroscope_config_provider.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class GyroscopeConfigProvider extends ChangeNotifier {
3333
_saveConfigToPrefs();
3434
}
3535

36+
void updateLowLimit(int lowLimit) {
37+
_config = _config.copyWith(lowLimit: lowLimit);
38+
notifyListeners();
39+
_saveConfigToPrefs();
40+
}
41+
3642
void updateUpdatePeriod(int updatePeriod) {
3743
_config = _config.copyWith(updatePeriod: updatePeriod);
3844
notifyListeners();

lib/providers/gyroscope_state_provider.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class GyroscopeProvider extends ChangeNotifier {
5151
bool get isPlaybackPaused => _isPlaybackPaused;
5252

5353
GyroscopeConfigProvider? _configProvider;
54-
double? get _currentLimit => _configProvider?.config.highLimit.toDouble();
54+
double? get _currentHighLimit => _configProvider?.config.highLimit.toDouble();
55+
double? get _currentLowLimit => _configProvider?.config.lowLimit.toDouble();
5556
Position? currentPosition;
5657
StreamSubscription? _locationStream;
5758

@@ -229,18 +230,24 @@ class GyroscopeProvider extends ChangeNotifier {
229230
}
230231

231232
void _updateData() {
232-
final limit = _currentLimit;
233+
final highLimit = _currentHighLimit;
234+
final lowLimit = _currentLowLimit;
233235

234-
final bool shouldClip = !_isPlayingBack && limit != null;
236+
final bool shouldClip = !_isPlayingBack;
235237

236-
final double x =
237-
(shouldClip && _gyroscopeEvent.x > limit) ? limit : _gyroscopeEvent.x;
238+
final double x;
239+
final double y;
240+
final double z;
238241

239-
final double y =
240-
(shouldClip && _gyroscopeEvent.y > limit) ? limit : _gyroscopeEvent.y;
241-
242-
final double z =
243-
(shouldClip && _gyroscopeEvent.z > limit) ? limit : _gyroscopeEvent.z;
242+
if (shouldClip && highLimit != null && lowLimit != null) {
243+
x = _gyroscopeEvent.x.clamp(-lowLimit, highLimit).toDouble();
244+
y = _gyroscopeEvent.y.clamp(-lowLimit, highLimit).toDouble();
245+
z = _gyroscopeEvent.z.clamp(-lowLimit, highLimit).toDouble();
246+
} else {
247+
x = _gyroscopeEvent.x;
248+
y = _gyroscopeEvent.y;
249+
z = _gyroscopeEvent.z;
250+
}
244251

245252
_gyroscopeEvent = GyroscopeEvent(x, y, z, DateTime.now());
246253
if (_isRecording) {

lib/view/gyroscope_config_screen.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class _GyroscopeConfigScreenState extends State<GyroscopeConfigScreen> {
1919
final TextEditingController _updatePeriodController = TextEditingController();
2020
final TextEditingController _highLimitController = TextEditingController();
2121
final TextEditingController _sensorGainController = TextEditingController();
22+
final TextEditingController _lowLimitController = TextEditingController();
2223
AppLocalizations get appLocalizations => getIt.get<AppLocalizations>();
2324

2425
@override
@@ -30,6 +31,7 @@ class _GyroscopeConfigScreenState extends State<GyroscopeConfigScreen> {
3031
_updatePeriodController.text = provider.config.updatePeriod.toString();
3132
_highLimitController.text = provider.config.highLimit.toString();
3233
_sensorGainController.text = provider.config.sensorGain.toString();
34+
_lowLimitController.text = provider.config.lowLimit.toString();
3335
});
3436
}
3537

@@ -38,6 +40,7 @@ class _GyroscopeConfigScreenState extends State<GyroscopeConfigScreen> {
3840
_updatePeriodController.dispose();
3941
_highLimitController.dispose();
4042
_sensorGainController.dispose();
43+
_lowLimitController.dispose();
4144
super.dispose();
4245
}
4346

@@ -138,6 +141,30 @@ class _GyroscopeConfigScreenState extends State<GyroscopeConfigScreen> {
138141
},
139142
hint: appLocalizations.gyroscopeHighLimitHint,
140143
),
144+
ConfigInputItem(
145+
title: appLocalizations.lowLimit,
146+
value:
147+
'${provider.config.lowLimit} ${appLocalizations.gyroscopeAxisLabel}',
148+
controller: _lowLimitController,
149+
onChanged: (value) {
150+
final intValue = int.tryParse(value);
151+
if (intValue != null &&
152+
intValue >= 0 &&
153+
intValue <= 1000) {
154+
provider.updateLowLimit(intValue);
155+
} else {
156+
ScaffoldMessenger.of(context).showSnackBar(
157+
SnackBar(
158+
content: Text(
159+
appLocalizations.lowLimitErrorMessage,
160+
style: TextStyle(color: snackBarContentColor),
161+
),
162+
backgroundColor: snackBarBackgroundColor),
163+
);
164+
}
165+
},
166+
hint: appLocalizations.gyroscopeLowLimitHint,
167+
),
141168
ConfigInputItem(
142169
title: appLocalizations.sensorGain,
143170
value: provider.config.sensorGain.toString(),

0 commit comments

Comments
 (0)