Skip to content

Commit

Permalink
Merge pull request #7 from Kamoool/develop
Browse files Browse the repository at this point in the history
Merge v2.0 develop into main
  • Loading branch information
Kamoool committed Jul 8, 2022
2 parents f729e76 + f32579e commit a8a92d0
Show file tree
Hide file tree
Showing 15 changed files with 652 additions and 308 deletions.
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:qs_ds_app/screens/port_screen.dart';
import 'package:window_size/window_size.dart';
import 'dart:io' show Platform;
Expand Down Expand Up @@ -37,6 +38,7 @@ class _MyAppState extends State<MyApp> {
toolbarHeight: 0,
),
),
builder: EasyLoading.init(),
home: const PortScreen(),
);
}
Expand Down
84 changes: 84 additions & 0 deletions lib/model/constants_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
class ConstantsRepository {
static ConstantsRepository instance = ConstantsRepository.internal();

//General tab pulses numeric
final double pulsesNumericMin = 0.5;
final double pulsesNumericMax = 10;
final double pulsesNumericStep = 0.5;

//QS cut times numerics
final double qsCutNumericMin = 30;
final double qsCutNumericMax = 150;
final double qsCutNumericStep = 1;

//Sensor threshold numerics
final double sensorNumericMin = 1;
final double sensorNumericMax = 2000;
final double sensorNumericStep = 1;

//MinRPM numerics
final double minRPMNumericMin = 0;
final double minRPMNumericMax = 15500;
final double minRPMNumericStep = 100;

//MaxRPM numerics
final double maxRPMNumericMin = 500;
final double maxRPMNumericMax = 16000;
final double maxRPMNumericStep = 100;

//PreDelay numerics
final double preDelayNumericMin = 0;
final double preDelayNumericMax = 100;
final double preDelayNumericStep = 1;

//PostDelay numerics
final double postDelayNumericMin = 300;
final double postDelayNumericMax = 10000;
final double postDelayNumericStep = 10;

//DS blip times numerics
final double dsBlipNumericMin = 30;
final double dsBlipNumericMax = 300;
final double dsBlipNumericStep = 1;

//Average readings sensor numerics
final double averageReadingsNumericMin = 1;
final double averageReadingsNumericMax = 100;
final double averageReadingsNumericStep = 1;

//Sensor allowed numerics
final double sensorAllowedNumericMin = 1;
final double sensorAllowedNumericMax = 2047;
final double sensorAllowedNumericStep = 1;

//Sensor above numerics
final double sensorAboveNumericMin = 0;
final double sensorAboveNumericMax = 4095;
final double sensorAboveNumericStep = 1;

//Sensor below numerics
final double sensorBelowNumericMin = 0;
final double sensorBelowNumericMax = 4095;
final double sensorBelowNumericStep = 1;

//RPM Average numerics
final double averageRPMNumericMin = 1;
final double averageRPMNumericMax = 200;
final double averageRPMNumericStep = 1;

//DAC Adjustment numerics
final double adjustmentDACNumericMin = 1;
final double adjustmentDACNumericMax = 200;
final double adjustmentDACNumericStep = 1;

//Reading DAC numerics
final double readingDACNumericMin = 1000;
final double readingDACNumericMax = 500000;
final double readingDACNumericStep = 1000;

factory ConstantsRepository() {
return instance;
}

ConstantsRepository.internal();
}
53 changes: 41 additions & 12 deletions lib/model/serial_utils.dart → lib/model/serial_port_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,62 @@ class SerialPortUtils {
}

void disconnect() {
if (SettingsRepository().systemUnlocked) {
lockSession();
}
stopListener = true;
sendString('E');
sendString('X');
serialPort.close();
serialPort.dispose();
instance = null;
}

void cut(){
void cut() {
sendString('C');
}

void blip(){
void blip() {
sendString('B');
}

void readData(){
void readData() {
sendString('R');
}

void saveSettings(){
sendString(SettingsRepository().generateSaveSettings());
void readSystemData() {
if (SettingsRepository().systemUnlocked) {
unlockSession();
}
}

void unlockSession() {
sendString('K,${SettingsRepository().unlockPassword.value}');
}

void lockSession() {
SettingsRepository().systemUnlocked = false;
SettingsRepository().unlockPassword.value = '0';
sendString('N');
}

void saveSettings() {
sendString('S,${SettingsRepository().generateSaveSettings()}');
}

void saveSystemSettings() {
if (SettingsRepository().systemUnlocked) {
sendString('L,${SettingsRepository().generateSaveSystemSettings()}');
}
}

void resetSettings(){
sendString('W');
void resetSettings() {
sendString('T');
}

void resetSystemSettings() {
if (SettingsRepository().systemUnlocked) {
sendString('M,${SettingsRepository().unlockPassword.value}');
}
}

void sendString(String string) {
Expand All @@ -71,17 +102,15 @@ class SerialPortUtils {
reader.stream.listen((Uint8List data) {
b.add(data);
if (String.fromCharCodes(b.toBytes()).contains('\r\n')) {
List<String> stringList =
String.fromCharCodes(b.toBytes()).split('\r\n');
List<String> stringList = String.fromCharCodes(b.toBytes()).split('\r\n');
b.clear();
if (stringList[stringList.length - 1] == '') {
for (int i = 0; i < stringList.length - 1; i++) {
SettingsRepository().parseValues(stringList[i]);
notify!();
}
} else {
b.add(
Uint8List.fromList(stringList[stringList.length - 1].codeUnits));
b.add(Uint8List.fromList(stringList[stringList.length - 1].codeUnits));
for (int i = 0; i < stringList.length - 1; i++) {
SettingsRepository().parseValues(stringList[i]);
notify!();
Expand Down
29 changes: 28 additions & 1 deletion lib/model/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ enum SettingType {
MinRPMDS,
MaxRPMDS,
PostDelayQS,
PostDelayDS
PostDelayDS,
UnlockPassword,
AverageReadingsSensor,
SensorAllowedChange,
SensorBelowAdjust,
SensorAboveAdjust,
AverageRPM,
DACAdjustmentValue,
ReadingDAC,
ReadingDACConnected,
}

String generateLabel(SettingType settingType) {
Expand Down Expand Up @@ -117,6 +126,24 @@ String generateLabel(SettingType settingType) {
return 'Post-delay';
} else if (settingType == SettingType.PostDelayDS) {
return 'Post-delay';
} else if (settingType == SettingType.UnlockPassword) {
return 'Unlock password';
}else if (settingType == SettingType.AverageReadingsSensor) {
return 'Average sensor';
}else if (settingType == SettingType.SensorAllowedChange) {
return 'Sensor allowed';
}else if (settingType == SettingType.SensorAboveAdjust) {
return 'Sensor above';
}else if (settingType == SettingType.SensorBelowAdjust) {
return 'Sensor below';
}else if (settingType == SettingType.AverageRPM) {
return 'Average RPM';
}else if (settingType == SettingType.DACAdjustmentValue) {
return 'DAC Adjustment';
}else if (settingType == SettingType.ReadingDAC) {
return 'Readings DAC';
}else if (settingType == SettingType.ReadingDACConnected) {
return 'Readings connected';
} else {
return 'Wrong Type';
}
Expand Down
Loading

0 comments on commit a8a92d0

Please sign in to comment.