machine_state.dart 9.1 KB

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