machine_state.dart 8.9 KB

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