machine_state.dart 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import 'diagnostic_entry.dart';
  2. import 'temperature_sample.dart';
  3. class MachineState {
  4. final double temperature;
  5. final double targetTemperature;
  6. final bool isHeating;
  7. final bool isBrewing;
  8. final int shotTimer;
  9. final String connectionStatus;
  10. final String? commandError;
  11. final List<double> temperatureHistory;
  12. final List<TemperatureSample> temperatureSamples;
  13. final List<DiagnosticEntry> diagnosticLog;
  14. final DateTime? lastTelemetryAt;
  15. final bool telemetryStale;
  16. final String transportName;
  17. final bool firmwareUpdating;
  18. final double firmwareProgress;
  19. final String firmwareUpdateStatus;
  20. // Second temperature sensor (group-head / inline sensor, when present)
  21. final double sensor2Temperature;
  22. final List<double> sensor2TemperatureHistory;
  23. // Configuration Parameters
  24. final double preinfusionTime;
  25. final int preinfusionPower;
  26. final double brewTemperature;
  27. final double steamTemperature;
  28. // PID Parameters
  29. final double pidP;
  30. final double pidI;
  31. final double pidD;
  32. final double pidIWindDownMin;
  33. final double pidIWindDownMax;
  34. final int pidPollingInterval;
  35. // Statistics
  36. final int shotCounter;
  37. final int grinderCounter;
  38. // Pressure Profiling
  39. final int pressureStart;
  40. final int pressureEnd;
  41. final int pressurePeriod;
  42. // Real-time Power
  43. final double heatingPower; // 0.0 to 1.0
  44. // Advanced Logic
  45. final bool valveClosedWhilePaused;
  46. final int proActivePercentage;
  47. final int autoShutoffMinutes;
  48. // Scheduling
  49. final bool wakeupEnabled;
  50. final String wakeupTime;
  51. final bool shutdownEnabled;
  52. final String shutdownTime;
  53. // Ionic 2 / Hardware features
  54. final bool preinfusionEnabled;
  55. final double preinfusionPauseTime;
  56. final int output0;
  57. final int output1;
  58. final int output2;
  59. final bool installedAsTimer;
  60. final bool powerButtonFlipsBack;
  61. // Firmware / compatibility
  62. final bool
  63. isLegacyV4Firmware; // V4 firmware uses scale=1 for pistrt/piprd instead of 1000
  64. final String
  65. firmwareVersion; // Full uname string from device (e.g. "meCoffee V5.3.1")
  66. // Automation
  67. final int maxShotTime; // shtmx – stops shot after N seconds (0 = disabled)
  68. final bool continuousMode; // tmpcntns – keep heating without shot trigger
  69. MachineState({
  70. this.temperature = 0.0,
  71. this.targetTemperature = 101.0,
  72. this.isHeating = false,
  73. this.isBrewing = false,
  74. this.shotTimer = 0,
  75. this.connectionStatus = 'Disconnected',
  76. this.commandError,
  77. this.temperatureHistory = const [],
  78. this.temperatureSamples = const [],
  79. this.diagnosticLog = const [],
  80. this.lastTelemetryAt,
  81. this.telemetryStale = true,
  82. this.transportName = '',
  83. this.firmwareUpdating = false,
  84. this.firmwareProgress = 0,
  85. this.firmwareUpdateStatus = '',
  86. this.sensor2Temperature = 0.0,
  87. this.sensor2TemperatureHistory = const [],
  88. this.preinfusionTime = 3.0,
  89. this.preinfusionPower = 100,
  90. this.brewTemperature = 101.0,
  91. this.steamTemperature = 125.0,
  92. this.pidP = 20.0,
  93. this.pidI = 0.3,
  94. this.pidD = 128.0,
  95. this.pidIWindDownMin = 0.0,
  96. this.pidIWindDownMax = 20.0,
  97. this.pidPollingInterval = 1000,
  98. this.shotCounter = 0,
  99. this.grinderCounter = 0,
  100. this.pressureStart = 100,
  101. this.pressureEnd = 100,
  102. this.pressurePeriod = 25,
  103. this.heatingPower = 0.0,
  104. this.valveClosedWhilePaused = false,
  105. this.proActivePercentage = 33,
  106. this.autoShutoffMinutes = 60,
  107. this.wakeupEnabled = false,
  108. this.wakeupTime = "07:00",
  109. this.shutdownEnabled = false,
  110. this.shutdownTime = "22:00",
  111. this.preinfusionEnabled = true,
  112. this.preinfusionPauseTime = 3.0,
  113. this.output0 = 112,
  114. this.output1 = 98,
  115. this.output2 = 118,
  116. this.installedAsTimer = false,
  117. this.powerButtonFlipsBack = false,
  118. this.isLegacyV4Firmware = false,
  119. this.firmwareVersion = '',
  120. this.maxShotTime = 60,
  121. this.continuousMode = false,
  122. });
  123. MachineState copyWith({
  124. double? temperature,
  125. double? targetTemperature,
  126. bool? isHeating,
  127. bool? isBrewing,
  128. int? shotTimer,
  129. String? connectionStatus,
  130. String? commandError,
  131. bool clearCommandError = false,
  132. List<double>? temperatureHistory,
  133. List<TemperatureSample>? temperatureSamples,
  134. List<DiagnosticEntry>? diagnosticLog,
  135. DateTime? lastTelemetryAt,
  136. bool clearLastTelemetry = false,
  137. bool? telemetryStale,
  138. String? transportName,
  139. bool? firmwareUpdating,
  140. double? firmwareProgress,
  141. String? firmwareUpdateStatus,
  142. double? sensor2Temperature,
  143. List<double>? sensor2TemperatureHistory,
  144. double? preinfusionTime,
  145. int? preinfusionPower,
  146. double? brewTemperature,
  147. double? steamTemperature,
  148. double? pidP,
  149. double? pidI,
  150. double? pidD,
  151. double? pidIWindDownMin,
  152. double? pidIWindDownMax,
  153. int? pidPollingInterval,
  154. int? shotCounter,
  155. int? grinderCounter,
  156. int? pressureStart,
  157. int? pressureEnd,
  158. int? pressurePeriod,
  159. double? heatingPower,
  160. bool? valveClosedWhilePaused,
  161. int? proActivePercentage,
  162. int? autoShutoffMinutes,
  163. bool? wakeupEnabled,
  164. String? wakeupTime,
  165. bool? shutdownEnabled,
  166. String? shutdownTime,
  167. bool? preinfusionEnabled,
  168. double? preinfusionPauseTime,
  169. int? output0,
  170. int? output1,
  171. int? output2,
  172. bool? installedAsTimer,
  173. bool? powerButtonFlipsBack,
  174. bool? isLegacyV4Firmware,
  175. String? firmwareVersion,
  176. int? maxShotTime,
  177. bool? continuousMode,
  178. }) {
  179. return MachineState(
  180. temperature: temperature ?? this.temperature,
  181. targetTemperature: targetTemperature ?? this.targetTemperature,
  182. isHeating: isHeating ?? this.isHeating,
  183. isBrewing: isBrewing ?? this.isBrewing,
  184. shotTimer: shotTimer ?? this.shotTimer,
  185. connectionStatus: connectionStatus ?? this.connectionStatus,
  186. commandError: clearCommandError
  187. ? null
  188. : commandError ?? this.commandError,
  189. temperatureHistory: temperatureHistory ?? this.temperatureHistory,
  190. temperatureSamples: temperatureSamples ?? this.temperatureSamples,
  191. diagnosticLog: diagnosticLog ?? this.diagnosticLog,
  192. lastTelemetryAt: clearLastTelemetry
  193. ? null
  194. : lastTelemetryAt ?? this.lastTelemetryAt,
  195. telemetryStale: telemetryStale ?? this.telemetryStale,
  196. transportName: transportName ?? this.transportName,
  197. firmwareUpdating: firmwareUpdating ?? this.firmwareUpdating,
  198. firmwareProgress: firmwareProgress ?? this.firmwareProgress,
  199. firmwareUpdateStatus: firmwareUpdateStatus ?? this.firmwareUpdateStatus,
  200. sensor2Temperature: sensor2Temperature ?? this.sensor2Temperature,
  201. sensor2TemperatureHistory:
  202. sensor2TemperatureHistory ?? this.sensor2TemperatureHistory,
  203. preinfusionTime: preinfusionTime ?? this.preinfusionTime,
  204. preinfusionPower: preinfusionPower ?? this.preinfusionPower,
  205. brewTemperature: brewTemperature ?? this.brewTemperature,
  206. steamTemperature: steamTemperature ?? this.steamTemperature,
  207. pidP: pidP ?? this.pidP,
  208. pidI: pidI ?? this.pidI,
  209. pidD: pidD ?? this.pidD,
  210. pidIWindDownMin: pidIWindDownMin ?? this.pidIWindDownMin,
  211. pidIWindDownMax: pidIWindDownMax ?? this.pidIWindDownMax,
  212. pidPollingInterval: pidPollingInterval ?? this.pidPollingInterval,
  213. shotCounter: shotCounter ?? this.shotCounter,
  214. grinderCounter: grinderCounter ?? this.grinderCounter,
  215. pressureStart: pressureStart ?? this.pressureStart,
  216. pressureEnd: pressureEnd ?? this.pressureEnd,
  217. pressurePeriod: pressurePeriod ?? this.pressurePeriod,
  218. heatingPower: heatingPower ?? this.heatingPower,
  219. valveClosedWhilePaused:
  220. valveClosedWhilePaused ?? this.valveClosedWhilePaused,
  221. proActivePercentage: proActivePercentage ?? this.proActivePercentage,
  222. autoShutoffMinutes: autoShutoffMinutes ?? this.autoShutoffMinutes,
  223. wakeupEnabled: wakeupEnabled ?? this.wakeupEnabled,
  224. wakeupTime: wakeupTime ?? this.wakeupTime,
  225. shutdownEnabled: shutdownEnabled ?? this.shutdownEnabled,
  226. shutdownTime: shutdownTime ?? this.shutdownTime,
  227. preinfusionEnabled: preinfusionEnabled ?? this.preinfusionEnabled,
  228. preinfusionPauseTime: preinfusionPauseTime ?? this.preinfusionPauseTime,
  229. output0: output0 ?? this.output0,
  230. output1: output1 ?? this.output1,
  231. output2: output2 ?? this.output2,
  232. installedAsTimer: installedAsTimer ?? this.installedAsTimer,
  233. powerButtonFlipsBack: powerButtonFlipsBack ?? this.powerButtonFlipsBack,
  234. isLegacyV4Firmware: isLegacyV4Firmware ?? this.isLegacyV4Firmware,
  235. firmwareVersion: firmwareVersion ?? this.firmwareVersion,
  236. maxShotTime: maxShotTime ?? this.maxShotTime,
  237. continuousMode: continuousMode ?? this.continuousMode,
  238. );
  239. }
  240. }