Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 47 additions & 5 deletions de1plus/de1_de1.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,21 @@ namespace eval ::de1::state {

proc init {} {

::de1::state::reset_framenumbers
unset -nocomplain ::de1::state::_previous_shotsample_update_time
::de1::state::reset_shotsample_tracking init

msg -DEBUG "::de1::state::init done"
}

proc reset_shotsample_tracking {{reason ""}} {

set ::de1(current_frame_number) 0
unset -nocomplain ::de1::_previous_shotsample_update_time

if { $reason ne "" } {
msg -DEBUG "::de1::state::reset_shotsample_tracking (${reason})"
}
}

proc current_state {} {

expr { $::de1_num_state($::de1(state)) }
Expand Down Expand Up @@ -520,6 +529,7 @@ namespace eval ::de1::state::update {

set this_state [::de1::state::current_state]
set this_substate [::de1::state::current_substate]
set this_flow_phase [::de1::state::flow_phase $this_state $this_substate]

array set ShotSample {}

Expand All @@ -531,6 +541,16 @@ namespace eval ::de1::state::update {
return
}

set previous_frame_number $::de1(current_frame_number)
if { $this_flow_phase == "during" \
&& $ShotSample(FrameNumber) < $previous_frame_number } {
msg -WARN "Ignoring stale ShotSample for session=$::de1(shot_session_id)" \
"state=$this_state substate=$this_substate" \
"frame=$ShotSample(FrameNumber) < current=$previous_frame_number" \
"sample_time=$ShotSample(SampleTime)"
return
}

# SampleTime not present in prior code
set ::de1(pressure) $ShotSample(GroupPressure)
set ::de1(flow) $ShotSample(GroupFlow)
Expand All @@ -555,7 +575,12 @@ namespace eval ::de1::state::update {
# Much of this proc could be refactored into ::de1 and ::gui
# Neither ::previous_timer nor ShotSample(Timer) were used elsewhere in prior code

if { [info exists ::de1::_previous_shotsample_update_time] } {
if { $this_flow_phase != "during" } {
unset -nocomplain ::de1::_previous_shotsample_update_time
}

if { $this_flow_phase == "during" \
&& [info exists ::de1::_previous_shotsample_update_time] } {

set dhc [expr { $ShotSample(SampleTime) \
- $::de1::_previous_shotsample_update_time }]
Expand All @@ -566,7 +591,9 @@ namespace eval ::de1::state::update {
set intersample_time 0.0
}

set ::de1::_previous_shotsample_update_time $ShotSample(SampleTime)
if { $this_flow_phase == "during" } {
set ::de1::_previous_shotsample_update_time $ShotSample(SampleTime)
}


set water_volume_dispensed_since_last_update \
Expand Down Expand Up @@ -801,6 +828,8 @@ namespace eval ::de1::sav {

proc start_active {} {

::de1::state::reset_shotsample_tracking flow_start

if {$::de1(scale_device_handle) != 0} {
msg -NOTICE "::de1::sav::start_active: disabled SAV because scale is connected"
}
Expand Down Expand Up @@ -965,12 +994,25 @@ namespace eval ::de1::sav {

if { $::de1(pour_volume) >= $_target } {

set total_volume \
[expr {$::de1(preinfusion_volume) + $::de1(pour_volume)}]
msg -NOTICE "AUTOSTOP volume reason=volume" \
"session=$::de1(shot_session_id)" \
"state=[::de1::state::current_state]" \
"substate=[::de1::state::current_substate]" \
"frame=$::de1(current_frame_number)" \
"current=$::de1(pour_volume)" \
"target=$_target" \
"preinfusion=$::de1(preinfusion_volume)" \
"total=$total_volume" \
"autostop=$::de1(app_autostop_triggered)"

start_idle
set ::de1(app_autostop_triggered) True

msg -INFO "Volume based stop was triggered at:" \
"${::de1(pour_volume)} ml for" \
"${_target} ml target"
"${_target} ml target in session $::de1(shot_session_id)"

::gui::notify::de1_event sav_stop
}
Expand Down
26 changes: 17 additions & 9 deletions de1plus/machine.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ array set ::de1 {
timer 0
hertz 50
volume 0
shot_session_id 0
wrote 0
cmdstack {}
widget_current_profile_name_color_normal "#ff6b6b"
Expand Down Expand Up @@ -841,20 +842,29 @@ proc start_steam {} {
}
}

proc reset_gui_starting_espresso {} {
proc begin_shot_session {{mode "unknown"}} {

set ::settings(history_saved) 0
incr ::de1(shot_session_id)

set ::de1(timer) 0
set ::de1(volume) 0
set ::de1(final_water_weight) 0
set ::de1(preinfusion_volume) 0
set ::de1(pour_volume) 0
set ::de1(current_frame_number) 0
::de1::state::reset_framenumbers

# only works if a BLE scale is attached
set ::de1(final_espresso_weight) 0
set ::de1(app_autostop_triggered) False
set ::de1(app_stepskip_triggered) False

::de1::state::reset_shotsample_tracking $mode

msg -DEBUG "Starting shot session id=$::de1(shot_session_id) mode=$mode"
}

proc reset_gui_starting_espresso {} {

set ::settings(history_saved) 0

begin_shot_session espresso

############
# this sets the time the espresso starts, used for recording this espresso to a history file
Expand Down Expand Up @@ -972,9 +982,7 @@ proc start_next_step {} {


proc reset_gui_starting_hotwater {} {
set ::de1(timer) 0
set ::de1(volume) 0
set ::de1(pour_volume) 0
begin_shot_session hotwater
incr ::settings(water_count)

save_settings
Expand Down