Skip to content

Commit

Permalink
#139 - Read maxTemp from config for Temperature Fan
Browse files Browse the repository at this point in the history
  • Loading branch information
Clon1998 committed Apr 9, 2023
1 parent f822e8f commit 923a930
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
19 changes: 19 additions & 0 deletions lib/data/dto/config/config_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
import 'package:flutter/foundation.dart';
import 'package:mobileraker/data/dto/config/config_file_entry_enum.dart';
import 'package:mobileraker/data/dto/config/config_gcode_macro.dart';
import 'package:mobileraker/data/dto/config/fan/config_controller_fan.dart';
import 'package:mobileraker/data/dto/config/fan/config_fan.dart';
import 'package:mobileraker/data/dto/config/fan/config_generic_fan.dart';
import 'package:mobileraker/data/dto/config/fan/config_heater_fan.dart';
import 'package:mobileraker/data/dto/config/fan/config_print_cooling_fan.dart';
import 'package:mobileraker/data/dto/config/fan/config_temperature_fan.dart';
import 'package:mobileraker/data/dto/config/led/config_dotstar.dart';
import 'package:mobileraker/data/dto/config/led/config_dumb_led.dart';
import 'package:mobileraker/data/dto/config/led/config_led.dart';
import 'package:mobileraker/data/dto/config/led/config_neopixel.dart';
import 'package:mobileraker/data/dto/config/led/config_pca_led.dart';
import 'package:mobileraker/logger.dart';

import 'config_extruder.dart';
import 'config_heater_bed.dart';
Expand All @@ -17,11 +24,13 @@ import 'config_stepper.dart';
class ConfigFile {
ConfigPrinter? configPrinter;
ConfigHeaterBed? configHeaterBed;
ConfigPrintCoolingFan? configPrintCoolingFan;
Map<String, ConfigExtruder> extruders = {};
Map<String, ConfigOutput> outputs = {};
Map<String, ConfigStepper> steppers = {};
Map<String, ConfigGcodeMacro> gcodeMacros = {};
Map<String, ConfigLed> leds = {};
Map<String, ConfigFan> fans = {};

ConfigFile();

Expand Down Expand Up @@ -72,6 +81,16 @@ class ConfigFile {
object == ConfigFileEntry.pca9632.name) {
//pca9533 and pcapca9632
leds[objectName] = ConfigPcaLed.fromJson(objectName, jsonChild);
} else if (object == ConfigFileEntry.fan.name) {
configPrintCoolingFan = ConfigPrintCoolingFan.fromJson(jsonChild);
} else if (object == ConfigFileEntry.heater_fan.name) {
fans[objectName] = ConfigHeaterFan.fromJson(objectName, jsonChild);
} else if (object == ConfigFileEntry.controller_fan.name) {
fans[objectName] = ConfigControllerFan.fromJson(objectName, jsonChild);
} else if (object == ConfigFileEntry.temperature_fan.name) {
fans[objectName] = ConfigTemperatureFan.fromJson(objectName, jsonChild);
} else if (object == ConfigFileEntry.fan_generic.name) {
fans[objectName] = ConfigGenericFan.fromJson(objectName, jsonChild);
}
}
//ToDo parse the config for e.g. EXTRUDERS (Temp settings), ...
Expand Down
9 changes: 8 additions & 1 deletion lib/data/dto/config/config_file_entry_enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ enum ConfigFileEntry {
neopixel,
led,
pca9533,
pca9632;
pca9632,
fan,
heater_fan,
controller_fan,
temperature_fan,
fan_generic;



const ConfigFileEntry();
}
4 changes: 2 additions & 2 deletions lib/data/dto/config/fan/config_controller_fan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ConfigControllerFan extends ConfigFan with _$ConfigControllerFan {
@JsonKey(name: 'fan_speed') @Default(1) double fanSpeed,
@JsonKey(name: 'idle_timeout') @Default(30) int idleTimeout,
@JsonKey(name: 'idle_speed') @Default(1.0) double idleSpeed,
required String heater,
required String stepper,
@Default([]) List<String> heater,
@Default([]) List<String> stepper,

}) = _ConfigControllerFan;

Expand Down
2 changes: 1 addition & 1 deletion lib/data/dto/config/fan/config_heater_fan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ConfigHeaterFan extends ConfigFan with _$ConfigHeaterFan {
@JsonKey(name: 'enable_pin') String? enablePin,
@JsonKey(name: 'heater_temp') @Default(50) double heaterTemp,
@JsonKey(name: 'fan_speed') @Default(1) double fanSpeed,
required String heater,
required List<String> heater,
}) = _ConfigHeaterFan;

factory ConfigHeaterFan.fromJson(String name, Map<String, dynamic> json) =>
Expand Down
5 changes: 2 additions & 3 deletions lib/data/dto/config/fan/config_print_cooling_fan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ class ConfigPrintCoolingFan extends ConfigFan with _$ConfigPrintCoolingFan {
@JsonKey(name: 'enable_pin') String? enablePin,
}) = _ConfigPrintCoolingFan;

factory ConfigPrintCoolingFan.fromJson(
String name, Map<String, dynamic> json) =>
_$ConfigPrintCoolingFanFromJson({...json, 'name': name});
factory ConfigPrintCoolingFan.fromJson(Map<String, dynamic> json) =>
_$ConfigPrintCoolingFanFromJson({...json});

@override
String get name => 'Print cooling fan';
Expand Down
5 changes: 4 additions & 1 deletion lib/data/model/hive/machine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Machine extends HiveObject {
bool trustUntrustedCertificate;
@HiveField(20)
OctoEverywhere? octoEverywhere;
@HiveField(21, defaultValue: [])
List<String> camOrdering;

PrintState? get lastPrintState =>
EnumToString.fromString(PrintState.values, _lastPrintState ?? '');
Expand All @@ -58,7 +60,8 @@ class Machine extends HiveObject {
this.apiKey,
this.temperaturePresets = const [],
this.trustUntrustedCertificate = false,
this.octoEverywhere});
this.octoEverywhere,
this.camOrdering = const []});

@override
Future<void> save() async {
Expand Down
8 changes: 6 additions & 2 deletions lib/ui/screens/dashboard/tabs/general_tab_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flip_card/flip_card_controller.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:mobileraker/data/dto/config/fan/config_temperature_fan.dart';
import 'package:mobileraker/data/dto/files/gcode_file.dart';
import 'package:mobileraker/data/dto/machine/extruder.dart';
import 'package:mobileraker/data/dto/machine/fans/temperature_fan.dart';
Expand Down Expand Up @@ -139,6 +140,9 @@ class GeneralTabViewController
}

editTemperatureFan(TemperatureFan temperatureFan) {
var configFan =
state.value?.printerData.configFile.fans[temperatureFan.name];

ref
.read(dialogServiceProvider)
.show(DialogRequest(
Expand All @@ -151,8 +155,8 @@ class GeneralTabViewController
confirmBtn: tr('general.confirm'),
data: NumberEditDialogArguments(
current: temperatureFan.target.round(),
min: 0,
max: 100,
min: (configFan != null && configFan is ConfigTemperatureFan)? configFan.minTemp : 0,
max: (configFan != null && configFan is ConfigTemperatureFan)? configFan.maxTemp : 100,
)))
.then((value) {
if (value == null || !value.confirmed || value.data == null) return;
Expand Down

0 comments on commit 923a930

Please sign in to comment.