Skip to content
Open
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
54 changes: 53 additions & 1 deletion de1plus/bluetooth.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -2363,6 +2363,23 @@ proc later_new_de1_connection_setup {} {
#set_feature_flags 1

set_heater_tweaks
# Push the machine's autonomous inactivity-sleep timeout so it self-sleeps
# even when the tablet is off/disconnected. Reuses the tablet's existing
# "return to sleep after" (screen_saver_delay) value, in minutes.
set_sleep_timeout_minutes $::settings(screen_saver_delay)

# Phase 2: sync the firmware wall-clock (and re-arm periodic re-sync) and push
# the weekly wake schedule, so the machine wakes/keeps-warm on schedule and
# self-sleeps off-schedule even with no tablet connected.
machine_clock_resync
set_wake_schedule

# Cup-warmer pre-warm is firmware-side and flash-persisted; push the app's
# setting so a change made while disconnected reaches the machine.
set_cupwarmer_preheat [ifexists ::settings(cupwarmer_prewarm_enable) 0] \
[ifexists ::settings(cupwarmer_prewarm_minutes) 30]
get_cupwarmer_status

get_refill_kit_present
get_sn

Expand Down Expand Up @@ -2781,7 +2798,15 @@ proc de1_ble_handler { event data } {

if {$cuuid eq $::de1(cuuid_0D)} {
set ::de1(last_ping) [clock seconds]
::de1::state::update::from_shotvalue $value $event_time
# Additive BLE: on a Bengle the high-resolution superset
# (BengleShotSample, 0xA013) is the sole shot-sample source
# and drives the chart. The stock 0xA00D still streams (so a
# stock DE1 app works), but we must NOT also chart it here or
# the chart would be double-sampled at 2x with broken
# intersample timing.
if {![::de1::packet::use_ble_v2]} {
::de1::state::update::from_shotvalue $value $event_time
}
set do_this 0
if {$do_this == 1} {
# this tries to handle bad write situations, but it might have side effects if it is not working correctly.
Expand All @@ -2793,6 +2818,22 @@ proc de1_ble_handler { event data } {
return
}
}
} elseif {$cuuid eq $::de1(cuuid_13)} {
# Additive BLE: BengleShotSample (0xA013) -- the Bengle
# self-contained high-resolution superset. On a Bengle this
# is the SOLE shot-sample source: it drives the pressure/flow/
# temp chart AND bridges integrated-scale weight/flow + milk
# into the scale pipeline (chart / SAW / display). All of that
# lives in _apply_shotvalue, shared with the stock v1 path.
set ::de1(last_ping) [clock seconds]
# Receiving 0xA013 is definitive proof this is a Bengle, so
# pin the protocol to v2 now. This gates off the stock 0xA00D
# charting path (use_ble_v2) from the very first sample,
# closing the connect-time window -- before the model MMR read
# lands -- where both 0xA00D and 0xA013 would otherwise chart.
# set_ble_protocol_version short-circuits once already at 2.
::de1::packet::set_ble_protocol_version 2
::de1::state::update::from_bengleshotvalue $value $event_time
} elseif {$cuuid eq $::de1(cuuid_05)} {
# MMR read
::bt::msg -INFO "MMR read: [::logging::format_mmr $value]"
Expand Down Expand Up @@ -2925,6 +2966,17 @@ proc de1_ble_handler { event data } {
} elseif {$mmr_id == "80385C"} {
::bt::msg -INFO "MMR read: steam_highflow_start: '$mmr_val'"
set ::de1(refill_kit_detected) $mmr_val
} elseif {$mmr_id == "803884"} {
# ScaleCalState — packed U32: Step(31:24) DetectedCell(23:20)
# SubState(19:16) SecondsRemaining(15:8) Status(7:0)
set raw [ifexists arr2(Data0)]
::bt::msg -INFO "MMR read: ScaleCalState raw=$raw"
::scale_cal::on_state_read $raw
} elseif {$mmr_id == "803888"} {
# ScaleCalWeight read-back (grams * 10)
set raw [ifexists arr2(Data0)]
::bt::msg -INFO "MMR read: ScaleCalWeight raw=$raw"
set ::scale_cal::cal_weight_readback $raw
} else {
::bt::msg -ERROR "Uknown type of direct MMR read" \
[::logging::format_mmr $value]
Expand Down
Loading