machine_state.dart 8.7 KB

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