Skip to content

Commit 69d522d

Browse files
committed
Merge branch 'master' of https://github.com/tobiasguyer/gaggimate into all_features
2 parents 6e834d3 + 7e9fdde commit 69d522d

21 files changed

Lines changed: 856 additions & 1957 deletions

File tree

lib/GaggiMateController/src/GaggiMateController.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ void GaggiMateController::sendSensorData() {
350350
_comms.sendUnreliableBatch(batch, n); // telemetry: fire-and-forget
351351
} else {
352352
_comms.sendSensorData(this->thermocouple->read(), 0.0f, 0.0f, 0.0f, 0.0f, this->thermocouple->read2(), pumpPower, heaterPower);
353-
>>>>>>> 8a827ad511a86a41a654c764dab6f893d5680959
354353
}
355354
}
356355

lib/NanoPbComm/src/GaggiMateClient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ void GaggiMateClient::registerHandlers() {
191191
pressure = p.content.sensor.boilers[0].pressure;
192192
temperature2 = p.content.sensor.boilers[0].temperature2;
193193
}
194-
_sensorCb(temperature, pressure, p.content.sensor.puck_flow, p.content.sensor.pump_flow,
195-
p.content.sensor.puck_resistance, temperature2, p.content.sensor.pump_power, p.content.sensor.heater_power);
194+
_sensorCb(temperature, pressure, p.content.sensor.puck_flow, p.content.sensor.pump_flow, p.content.sensor.puck_resistance,
195+
temperature2, p.content.sensor.pump_power, p.content.sensor.heater_power);
196196
});
197197
_endpoint.on(gaggimate_Payload_button_tag, [this](const gm::Payload &p) {
198198
if (_buttonCb)

lib/NanoPbComm/src/GaggiMateClient.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ class GaggiMateClient {
2424
using SystemInfoCallback =
2525
std::function<void(const char *hardware, const char *version, uint32_t protocolVersion, bool dimming, bool pressure,
2626
bool ledControl, bool tof, std::vector<uint32_t> addons)>;
27-
using SensorCallback =
28-
std::function<void(float temperature, float pressure, float puckFlow, float pumpFlow, float puckResistance, float temperature2,
29-
float pumpPower, float heaterPower)>;
27+
using SensorCallback = std::function<void(float temperature, float pressure, float puckFlow, float pumpFlow, float temperature2,
28+
float puckResistance, float pumpPower, float heaterPower)>;
3029
using ButtonCallback = std::function<void(uint8_t index, bool pressed)>;
3130
using AutotuneResultCallback = std::function<void(float kp, float ki, float kd, float kf)>;
3231
using VolumetricCallback = std::function<void(float volume)>;

sim/comms/GaggiMateClient.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ class GaggiMateClient {
3939
using IncompatibleCallback = std::function<void(const String &info)>;
4040
using SystemInfoCallback =
4141
std::function<void(const char *hardware, const char *version, uint32_t protocolVersion, bool dimming, bool pressure,
42-
bool ledControl, bool tof, std::vector<uint32_t> addons)>;
43-
using SensorCallback =
44-
std::function<void(float temperature, float pressure, float puckFlow, float pumpFlow, float puckResistance,
45-
float pumpPower, float heaterPower)>;
42+
bool ledControl, bool tof, std::vector<uint32_t> addons)>;
43+
using SensorCallback = std::function<void(float temperature, float pressure, float puckFlow, float pumpFlow,
44+
float puckResistance, float pumpPower, float heaterPower)>;
4645
using ButtonCallback = std::function<void(uint8_t index, bool pressed)>;
4746
using AutotuneResultCallback = std::function<void(float kp, float ki, float kd, float kf)>;
4847
using VolumetricCallback = std::function<void(float volume)>;

sim/comms/MockController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
class MockController {
1010
public:
11-
using SensorFn = std::function<void(float temp, float pressure, float puckFlow, float pumpFlow, float puckResistance, float pumpPower, float heaterPower)>;
11+
using SensorFn = std::function<void(float temp, float pressure, float puckFlow, float pumpFlow, float puckResistance,
12+
float pumpPower, float heaterPower)>;
1213
using VolumetricFn = std::function<void(float volume)>;
1314
using TofFn = std::function<void(uint32_t distance)>;
1415

src/display/core/process/BrewProcess.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class BrewProcess : public Process {
2020
unsigned long previousPhaseFinished = 0;
2121
unsigned long finished = 0;
2222
PhaseExitReason lastExitReason = PhaseExitReason::NONE; // why the most recent phase ended (for shot history)
23-
double currentVolume = 0; // most recent volume pushed
23+
double phaseStartVolume = 0;
24+
double currentVolume = 0; // most recent volume pushed
2425
float currentFlow = 0.0f;
2526
float currentPressure = 0.0f;
2627
float waterPumped = 0.0f;
@@ -147,6 +148,7 @@ class BrewProcess : public Process {
147148
waterPumped = 0.0f;
148149
phaseIndex++;
149150
Phase nextPhase = profile.phases.at(phaseIndex);
151+
phaseStartVolume = currentVolume;
150152
phaseStartPressure = nextPhase.transition.adaptive ? currentPressure : getPumpPressure();
151153
phaseStartFlow = nextPhase.transition.adaptive ? currentFlow : getPumpFlow();
152154
currentPhase = nextPhase;
@@ -220,7 +222,12 @@ class BrewProcess : public Process {
220222
}
221223
}
222224

223-
float transitionAlpha() const {
225+
float transitionAlpha(float startValue, float endValue) const {
226+
float t = startValue / endValue;
227+
return applyEasing(t, currentPhase.transition.type);
228+
}
229+
230+
float transitionAlphaByTime() const {
224231
float dur_s = currentPhase.transition.duration;
225232
if (dur_s <= 0.0f) {
226233
dur_s = currentPhase.duration; // If the transition has no duration, use the phase duration
@@ -229,8 +236,28 @@ class BrewProcess : public Process {
229236
return 1.0f;
230237
}
231238
const unsigned long elapsedMs = millis() - currentPhaseStarted;
232-
float t = float(elapsedMs) / (dur_s * 1000.0f);
233-
return applyEasing(t, currentPhase.transition.type);
239+
return transitionAlpha(elapsedMs, dur_s * 1000.0f);
240+
}
241+
242+
float transitionAlpha() const {
243+
if (currentPhase.transition.target == TransitionTarget::VOLUMETRIC && target == ProcessTarget::VOLUMETRIC) {
244+
float endValue = currentPhase.transition.duration;
245+
if (endValue <= 0.0f && currentPhase.hasVolumetricTarget()) {
246+
endValue = currentPhase.getVolumetricTarget().value - phaseStartVolume;
247+
}
248+
return transitionAlpha(max(0.0, currentVolume - phaseStartVolume), endValue);
249+
}
250+
if (currentPhase.transition.target == TransitionTarget::PUMPED) {
251+
252+
float endValue = currentPhase.transition.duration;
253+
if (endValue <= 0.0f && currentPhase.hasVolumetricTarget()) {
254+
endValue = currentPhase.getVolumetricTarget().value;
255+
}
256+
if (endValue > 0.0f) {
257+
return transitionAlpha(waterPumped, endValue);
258+
}
259+
}
260+
return transitionAlphaByTime();
234261
}
235262
};
236263

src/display/models/profile.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum class PumpTarget {
1212
};
1313
enum class PhaseType { PHASE_TYPE_PREINFUSION, PHASE_TYPE_BREW };
1414
enum class TransitionType { INSTANT, LINEAR, EASE_IN, EASE_OUT, EASE_IN_OUT };
15+
enum class TransitionTarget { TIME, VOLUMETRIC, PUMPED };
1516

1617
// Why a phase ended; persisted as uint8_t in the .slog phase transitions, so values must stay stable.
1718
// NONE (0) doubles as "still running" and as the legacy/unknown value in old shot files.
@@ -47,6 +48,7 @@ struct PumpAdvanced {
4748

4849
struct Transition {
4950
TransitionType type;
51+
TransitionTarget target;
5052
float duration;
5153
bool adaptive;
5254
};
@@ -81,6 +83,24 @@ struct Phase {
8183
return Target{};
8284
}
8385

86+
bool hasPumpedTarget() const {
87+
for (const auto &target : targets) {
88+
if (target.type == TargetType::TARGET_TYPE_PUMPED && target.value > 0.0f) {
89+
return true;
90+
}
91+
}
92+
return false;
93+
}
94+
95+
Target getPumpedTarget() const {
96+
for (auto &target : targets) {
97+
if (target.type == TargetType::TARGET_TYPE_PUMPED) {
98+
return target;
99+
}
100+
}
101+
return Target{};
102+
}
103+
84104
void adjustDuration(float amount) { duration = std::max(0.5f, duration + amount); }
85105

86106
void adjustVolumetricTarget(float factor) {
@@ -98,6 +118,9 @@ struct Phase {
98118
for (const auto &target : targets) {
99119
switch (target.type) {
100120
case TargetType::TARGET_TYPE_VOLUMETRIC:
121+
if (target.value <= 0.0f) {
122+
break;
123+
}
101124
volumetricTested = enableVolumetric;
102125
if (enableVolumetric && target.isReached(volume)) {
103126
return PhaseExitReason::TARGET_VOLUMETRIC;
@@ -296,11 +319,20 @@ inline bool parseProfile(const JsonObject &obj, Profile &profile) {
296319
} else {
297320
phase.transition.type = TransitionType::INSTANT;
298321
}
322+
String target = transition["target"].as<String>();
323+
if (target == "volumetric") {
324+
phase.transition.target = TransitionTarget::VOLUMETRIC;
325+
} else if (target == "pumped") {
326+
phase.transition.target = TransitionTarget::PUMPED;
327+
} else {
328+
phase.transition.target = TransitionTarget::TIME;
329+
}
299330
phase.transition.duration = transition["duration"].as<float>();
300331
phase.transition.adaptive = transition["adaptive"].as<bool>();
301332
} else {
302333
phase.transition = Transition{
303334
.type = TransitionType::INSTANT,
335+
.target = TransitionTarget::TIME,
304336
.duration = 0,
305337
.adaptive = false,
306338
};
@@ -381,6 +413,13 @@ inline void writeProfile(JsonObject &obj, const Profile &profile) {
381413
transition["type"] = "instant";
382414
break;
383415
}
416+
if (phase.transition.target == TransitionTarget::VOLUMETRIC) {
417+
transition["target"] = "volumetric";
418+
} else if (phase.transition.target == TransitionTarget::PUMPED) {
419+
transition["target"] = "pumped";
420+
} else {
421+
transition["target"] = "time";
422+
}
384423
transition["duration"] = phase.transition.duration;
385424
transition["adaptive"] = phase.transition.adaptive;
386425

0 commit comments

Comments
 (0)