Skip to content
18 changes: 16 additions & 2 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@ String shopError = 'Could not open the shop link';
String showLuxmeterConfig = 'Lux Meter Configurations';
String luxmeterConfigurations = 'Lux Meter Configurations';
String updatePeriod = 'Update Period';
String updatePeriodHint =
String luxmeterUpdatePeriodHint =
'Please provide time interval at which data will be updated (100 ms to 1000 ms)';
String highLimit = 'High Limit';
String highLimitHint =
String luxmeterHighLimitHint =
'Please provide the maximum limit of lux value to be recorded (10 Lx to 10000 Lx)';
String sensorGain = 'Sensor Gain';
String sensorGainHint = 'Please set gain of the sensor';
Expand All @@ -421,3 +421,17 @@ String 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.';
String baroMeterBulletPoint4 =
'Select the sensor by going to the Configure tab from the bottom navigation bar and choose BMP-180 in the drop down menu under Select Sensor.';
String soundmeterConfig = 'Soundmeter Configurations';
String barometerConfig = 'Barometer Configurations';
String baroUpdatePeriodHint =
'Please provide time interval at which data will be updated (100 ms to 2000 ms)';
String barometerHighLimitHint =
'Please provide the maximum limit of lux value to be recorded (0 atm to 1.10 atm)';
String gyroscopeConfigurations = 'Gyroscope Configurations';
String gyroscopeHighLimitHint =
'Please provide the maximum limit of lux value to be recorded (0 rad/s to 1000 rad/s)';
String accelerometerConfigurations = 'Accelerometer Configurations';
String accelerometerUpdatePeriodHint =
'Please provide time interval at which data will be updated';
String accelerometerHighLimitHint =
'Please provide the maximum limit of lux value to be recorded';
51 changes: 51 additions & 0 deletions lib/models/accelerometer_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class AccelerometerConfig {
final int updatePeriod;
final int highLimit;
final String activeSensor;
final int sensorGain;
final bool includeLocationData;

const AccelerometerConfig({
this.updatePeriod = 1000,
this.highLimit = 2000,
this.activeSensor = 'In-built Sensor',
this.sensorGain = 1,
this.includeLocationData = true,
});

AccelerometerConfig copyWith({
int? updatePeriod,
int? highLimit,
String? activeSensor,
int? sensorGain,
bool? includeLocationData,
}) {
return AccelerometerConfig(
updatePeriod: updatePeriod ?? this.updatePeriod,
highLimit: highLimit ?? this.highLimit,
activeSensor: activeSensor ?? this.activeSensor,
sensorGain: sensorGain ?? this.sensorGain,
includeLocationData: includeLocationData ?? this.includeLocationData,
);
}

Map<String, dynamic> toJson() {
return {
'updatePeriod': updatePeriod,
'highLimit': highLimit,
'activeSensor': activeSensor,
'sensorGain': sensorGain,
'includeLocationData': includeLocationData,
};
}

factory AccelerometerConfig.fromJson(Map<String, dynamic> json) {
return AccelerometerConfig(
updatePeriod: json['updatePeriod'] ?? 1000,
highLimit: json['highLimit'] ?? 2000,
activeSensor: json['activeSensor'] ?? 'In-built Sensor',
sensorGain: json['sensorGain'] ?? 1,
includeLocationData: json['includeLocationData'] ?? true,
);
}
}
45 changes: 45 additions & 0 deletions lib/models/barometer_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class BarometerConfig {
final int updatePeriod;
final double highLimit;
final String activeSensor;
final bool includeLocationData;

const BarometerConfig({
this.updatePeriod = 1000,
this.highLimit = 1.10,
this.activeSensor = 'In-built Sensor',
this.includeLocationData = true,
});

BarometerConfig copyWith({
int? updatePeriod,
double? highLimit,
String? activeSensor,
bool? includeLocationData,
}) {
return BarometerConfig(
updatePeriod: updatePeriod ?? this.updatePeriod,
highLimit: highLimit ?? this.highLimit,
activeSensor: activeSensor ?? this.activeSensor,
includeLocationData: includeLocationData ?? this.includeLocationData,
);
}

Map<String, dynamic> toJson() {
return {
'updatePeriod': updatePeriod,
'highLimit': highLimit,
'activeSensor': activeSensor,
'includeLocationData': includeLocationData,
};
}

factory BarometerConfig.fromJson(Map<String, dynamic> json) {
return BarometerConfig(
updatePeriod: json['updatePeriod'] ?? 1000,
highLimit: json['highLimit'] ?? 1.10,
activeSensor: json['activeSensor'] ?? 'In-built Sensor',
includeLocationData: json['includeLocationData'] ?? true,
);
}
}
45 changes: 45 additions & 0 deletions lib/models/gyroscope_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class GyroscopeConfig {
final int updatePeriod;
final int highLimit;
final int sensorGain;
final bool includeLocationData;

const GyroscopeConfig({
this.updatePeriod = 1000,
this.highLimit = 20,
this.sensorGain = 1,
this.includeLocationData = true,
});

GyroscopeConfig copyWith({
int? updatePeriod,
int? highLimit,
int? sensorGain,
bool? includeLocationData,
}) {
return GyroscopeConfig(
updatePeriod: updatePeriod ?? this.updatePeriod,
highLimit: highLimit ?? this.highLimit,
sensorGain: sensorGain ?? this.sensorGain,
includeLocationData: includeLocationData ?? this.includeLocationData,
);
}

Map<String, dynamic> toJson() {
return {
'updatePeriod': updatePeriod,
'highLimit': highLimit,
'sensorGain': sensorGain,
'includeLocationData': includeLocationData,
};
}

factory GyroscopeConfig.fromJson(Map<String, dynamic> json) {
return GyroscopeConfig(
updatePeriod: json['updatePeriod'] ?? 1000,
highLimit: json['highLimit'] ?? 20,
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
sensorGain: json['sensorGain'] ?? 1,
includeLocationData: json['includeLocationData'] ?? true,
);
}
}
25 changes: 25 additions & 0 deletions lib/models/soundmeter_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class SoundMeterConfig {
final bool includeLocationData;
const SoundMeterConfig({
this.includeLocationData = true,
});
SoundMeterConfig copyWith({
bool? includeLocationData,
}) {
return SoundMeterConfig(
includeLocationData: includeLocationData ?? this.includeLocationData,
);
}

Map<String, dynamic> toJson() {
return {
'includeLocationData': includeLocationData,
};
}

factory SoundMeterConfig.fromJson(Map<String, dynamic> json) {
return SoundMeterConfig(
includeLocationData: json['includeLocationData'] ?? true,
);
}
}
72 changes: 72 additions & 0 deletions lib/providers/accelerometer_config_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'package:flutter/foundation.dart';
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pslab/models/accelerometer_config.dart';

class AccelerometerConfigProvider extends ChangeNotifier {
AccelerometerConfig _config = const AccelerometerConfig();

AccelerometerConfig get config => _config;

AccelerometerConfigProvider() {
_loadConfigFromPrefs();
}

Future<void> _loadConfigFromPrefs() async {
final prefs = await SharedPreferences.getInstance();
final jsonString = prefs.getString('accelerometer_config');
if (jsonString != null) {
final Map<String, dynamic> jsonMap = json.decode(jsonString);
_config = AccelerometerConfig.fromJson(jsonMap);
notifyListeners();
}
}

Future<void> _saveConfigToPrefs() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(
'accelerometer_config', json.encode(_config.toJson()));
}

void updateConfig(AccelerometerConfig newConfig) {
_config = newConfig;
notifyListeners();
_saveConfigToPrefs();
}

void updateUpdatePeriod(int updatePeriod) {
_config = _config.copyWith(updatePeriod: updatePeriod);
notifyListeners();
_saveConfigToPrefs();
}

void updateHighLimit(int highLimit) {
_config = _config.copyWith(highLimit: highLimit);
notifyListeners();
_saveConfigToPrefs();
}

void updateActiveSensor(String activeSensor) {
_config = _config.copyWith(activeSensor: activeSensor);
notifyListeners();
_saveConfigToPrefs();
}

void updateSensorGain(int sensorGain) {
_config = _config.copyWith(sensorGain: sensorGain);
notifyListeners();
_saveConfigToPrefs();
}

void updateIncludeLocationData(bool includeLocationData) {
_config = _config.copyWith(includeLocationData: includeLocationData);
notifyListeners();
_saveConfigToPrefs();
}

void resetToDefaults() {
_config = const AccelerometerConfig();
notifyListeners();
_saveConfigToPrefs();
}
}
65 changes: 65 additions & 0 deletions lib/providers/barometer_config_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:flutter/foundation.dart';
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pslab/models/barometer_config.dart';

class BarometerConfigProvider extends ChangeNotifier {
BarometerConfig _config = const BarometerConfig();

BarometerConfig get config => _config;

BarometerConfigProvider() {
_loadConfigFromPrefs();
}

Future<void> _loadConfigFromPrefs() async {
final prefs = await SharedPreferences.getInstance();
final jsonString = prefs.getString('barometer_config');
if (jsonString != null) {
final Map<String, dynamic> jsonMap = json.decode(jsonString);
_config = BarometerConfig.fromJson(jsonMap);
notifyListeners();
}
}

Future<void> _saveConfigToPrefs() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('barometer_config', json.encode(_config.toJson()));
}

void updateConfig(BarometerConfig newConfig) {
_config = newConfig;
notifyListeners();
_saveConfigToPrefs();
}

void updateUpdatePeriod(int updatePeriod) {
_config = _config.copyWith(updatePeriod: updatePeriod);
notifyListeners();
_saveConfigToPrefs();
}

void updateHighLimit(double highLimit) {
_config = _config.copyWith(highLimit: highLimit);
notifyListeners();
_saveConfigToPrefs();
}

void updateActiveSensor(String activeSensor) {
_config = _config.copyWith(activeSensor: activeSensor);
notifyListeners();
_saveConfigToPrefs();
}

void updateIncludeLocationData(bool includeLocationData) {
_config = _config.copyWith(includeLocationData: includeLocationData);
notifyListeners();
_saveConfigToPrefs();
}

void resetToDefaults() {
_config = const BarometerConfig();
notifyListeners();
_saveConfigToPrefs();
}
}
Loading