Skip to content

Commit

Permalink
#139 - Added dtos for fan configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Clon1998 committed Apr 9, 2023
1 parent 791d828 commit 94ec585
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/data/dto/config/fan/config_controller_fan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mobileraker/data/dto/config/fan/config_fan.dart';

part 'config_controller_fan.freezed.dart';

part 'config_controller_fan.g.dart';

@freezed
class ConfigControllerFan extends ConfigFan with _$ConfigControllerFan {
const ConfigControllerFan._();

const factory ConfigControllerFan({
required String name,
required String pin,
@JsonKey(name: 'max_power') @Default(1) double maxPower,
@JsonKey(name: 'shutdown_speed') @Default(0) double shutdownSpeed,
@JsonKey(name: 'cycle_time') @Default(0.010) double cycleTime,
@JsonKey(name: 'hardware_pwm') @Default(false) bool hardwarePwm,
@JsonKey(name: 'kick_start_time') @Default(0.100) double kickStartTime,
@JsonKey(name: 'off_below') @Default(0) double offBelow,
@JsonKey(name: 'tachometer_pin') String? tachometerPin,
@JsonKey(name: 'tachometer_ppr') @Default(2) int? tachometerPpr,
@JsonKey(name: 'tachometer_poll_interval')
@Default(0.0015)
double? tachometerPollInterval,
@JsonKey(name: 'enable_pin') String? enablePin,
@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,

}) = _ConfigControllerFan;

factory ConfigControllerFan.fromJson(String name, Map<String, dynamic> json) =>
_$ConfigControllerFanFromJson({...json, 'name': name});
}
16 changes: 16 additions & 0 deletions lib/data/dto/config/fan/config_fan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
abstract class ConfigFan {
const ConfigFan();

abstract final String name;
abstract final String pin;
abstract final double maxPower;
abstract final double shutdownSpeed;
abstract final double cycleTime;
abstract final bool hardwarePwm;
abstract final double kickStartTime;
abstract final double offBelow;
abstract final String? tachometerPin;
abstract final int? tachometerPpr;
abstract final double? tachometerPollInterval;
abstract final String? enablePin;
}
31 changes: 31 additions & 0 deletions lib/data/dto/config/fan/config_generic_fan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mobileraker/data/dto/config/fan/config_fan.dart';

part 'config_generic_fan.freezed.dart';

part 'config_generic_fan.g.dart';

@freezed
class ConfigGenericFan extends ConfigFan with _$ConfigGenericFan {
const ConfigGenericFan._();

const factory ConfigGenericFan({
required String name,
required String pin,
@JsonKey(name: 'max_power') @Default(1) double maxPower,
@JsonKey(name: 'shutdown_speed') @Default(0) double shutdownSpeed,
@JsonKey(name: 'cycle_time') @Default(0.010) double cycleTime,
@JsonKey(name: 'hardware_pwm') @Default(false) bool hardwarePwm,
@JsonKey(name: 'kick_start_time') @Default(0.100) double kickStartTime,
@JsonKey(name: 'off_below') @Default(0) double offBelow,
@JsonKey(name: 'tachometer_pin') String? tachometerPin,
@JsonKey(name: 'tachometer_ppr') @Default(2) int? tachometerPpr,
@JsonKey(name: 'tachometer_poll_interval')
@Default(0.0015)
double? tachometerPollInterval,
@JsonKey(name: 'enable_pin') String? enablePin,
}) = _ConfigGenericFan;

factory ConfigGenericFan.fromJson(String name, Map<String, dynamic> json) =>
_$ConfigGenericFanFromJson({...json, 'name': name});
}
34 changes: 34 additions & 0 deletions lib/data/dto/config/fan/config_heater_fan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mobileraker/data/dto/config/fan/config_fan.dart';

part 'config_heater_fan.freezed.dart';

part 'config_heater_fan.g.dart';

@freezed
class ConfigHeaterFan extends ConfigFan with _$ConfigHeaterFan {
const ConfigHeaterFan._();

const factory ConfigHeaterFan({
required String name,
required String pin,
@JsonKey(name: 'max_power') @Default(1) double maxPower,
@JsonKey(name: 'shutdown_speed') @Default(0) double shutdownSpeed,
@JsonKey(name: 'cycle_time') @Default(0.010) double cycleTime,
@JsonKey(name: 'hardware_pwm') @Default(false) bool hardwarePwm,
@JsonKey(name: 'kick_start_time') @Default(0.100) double kickStartTime,
@JsonKey(name: 'off_below') @Default(0) double offBelow,
@JsonKey(name: 'tachometer_pin') String? tachometerPin,
@JsonKey(name: 'tachometer_ppr') @Default(2) int? tachometerPpr,
@JsonKey(name: 'tachometer_poll_interval')
@Default(0.0015)
double? tachometerPollInterval,
@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,
}) = _ConfigHeaterFan;

factory ConfigHeaterFan.fromJson(String name, Map<String, dynamic> json) =>
_$ConfigHeaterFanFromJson({...json, 'name': name});
}
34 changes: 34 additions & 0 deletions lib/data/dto/config/fan/config_print_cooling_fan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mobileraker/data/dto/config/fan/config_fan.dart';

part 'config_print_cooling_fan.freezed.dart';

part 'config_print_cooling_fan.g.dart';

@freezed
class ConfigPrintCoolingFan extends ConfigFan with _$ConfigPrintCoolingFan {
const ConfigPrintCoolingFan._();

const factory ConfigPrintCoolingFan({
required String pin,
@JsonKey(name: 'max_power') @Default(1) double maxPower,
@JsonKey(name: 'shutdown_speed') @Default(0) double shutdownSpeed,
@JsonKey(name: 'cycle_time') @Default(0.010) double cycleTime,
@JsonKey(name: 'hardware_pwm') @Default(false) bool hardwarePwm,
@JsonKey(name: 'kick_start_time') @Default(0.100) double kickStartTime,
@JsonKey(name: 'off_below') @Default(0) double offBelow,
@JsonKey(name: 'tachometer_pin') String? tachometerPin,
@JsonKey(name: 'tachometer_ppr') @Default(2) int? tachometerPpr,
@JsonKey(name: 'tachometer_poll_interval')
@Default(0.0015)
double? tachometerPollInterval,
@JsonKey(name: 'enable_pin') String? enablePin,
}) = _ConfigPrintCoolingFan;

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

@override
String get name => 'Print cooling fan';
}
37 changes: 37 additions & 0 deletions lib/data/dto/config/fan/config_temperature_fan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mobileraker/data/dto/config/fan/config_fan.dart';

part 'config_temperature_fan.freezed.dart';

part 'config_temperature_fan.g.dart';

@freezed
class ConfigTemperatureFan extends ConfigFan with _$ConfigTemperatureFan {
const ConfigTemperatureFan._();

const factory ConfigTemperatureFan({
required String name,
required String pin,
@JsonKey(name: 'max_power') @Default(1) double maxPower,
@JsonKey(name: 'shutdown_speed') @Default(0) double shutdownSpeed,
@JsonKey(name: 'cycle_time') @Default(0.010) double cycleTime,
@JsonKey(name: 'hardware_pwm') @Default(false) bool hardwarePwm,
@JsonKey(name: 'kick_start_time') @Default(0.100) double kickStartTime,
@JsonKey(name: 'off_below') @Default(0) double offBelow,
@JsonKey(name: 'tachometer_pin') String? tachometerPin,
@JsonKey(name: 'tachometer_ppr') @Default(2) int? tachometerPpr,
@JsonKey(name: 'tachometer_poll_interval')
@Default(0.0015)
double? tachometerPollInterval,
@JsonKey(name: 'enable_pin') String? enablePin,
@JsonKey(name: 'min_temp') @Default(0) double minTemp,
@JsonKey(name: 'max_temp') @Default(50) double maxTemp,
@JsonKey(name: 'target_temp') @Default(40) double targetTemp,
@JsonKey(name: 'max_speed') @Default(1) double maxSpeed,
@JsonKey(name: 'min_speed') @Default(0.3) double minSpeed,
}) = _ConfigTemperatureFan;

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

0 comments on commit 94ec585

Please sign in to comment.