From 70d78efe327288b7ec03b9056f7e07657e448f80 Mon Sep 17 00:00:00 2001 From: Mimoja Date: Wed, 14 Apr 2021 18:55:15 +0200 Subject: [PATCH] Add MEATER support Signed-off-by: Mimoja --- de1plus/binary.tcl | 2 + de1plus/bluetooth.tcl | 195 +++++++++++++++----- de1plus/de1_comms.tcl | 4 + de1plus/machine.tcl | 18 +- de1plus/skins/default/de1_skin_settings.tcl | 6 +- de1plus/vars.tcl | 98 +++++++--- 6 files changed, 236 insertions(+), 87 deletions(-) diff --git a/de1plus/binary.tcl b/de1plus/binary.tcl index 275add9f..b2a584da 100644 --- a/de1plus/binary.tcl +++ b/de1plus/binary.tcl @@ -1491,6 +1491,8 @@ proc update_de1_state {statechar} { msg "try to connect to scale automatically (if it is currently disconnected)" ble_connect_to_scale + msg "try to connect to thermometer automatically (if it is currently disconnected)" + ble_connect_to_thermometer } } diff --git a/de1plus/bluetooth.tcl b/de1plus/bluetooth.tcl index 28535d7c..ecb73877 100755 --- a/de1plus/bluetooth.tcl +++ b/de1plus/bluetooth.tcl @@ -682,6 +682,44 @@ proc decentscale_tare {} { userdata_append "decentscale : tare" [list ble write $::de1(scale_device_handle) $::de1(suuid_decentscale) $::sinstance($::de1(suuid_decentscale)) $::de1(cuuid_decentscale_write) $::cinstance($::de1(cuuid_decentscale_write)) $tare] 0 } +### Meater + +proc meater_enable_notifications {} { + if {$::de1(thermometer_device_handle) == 0 || $::settings(thermometer_bluetooth_type) != "apptionmeater"} { + return + } + + if {[ifexists ::sinstance($::de1(suuid_meater))] == ""} { + msg "meater not connected, cannot enable weight notifications" + return + } + + userdata_append "enable meater notifications" [list ble enable $::de1(thermometer_device_handle) $::de1(suuid_meater) $::sinstance($::de1(suuid_meater)) $::de1(cuuid_meater) $::cinstance($::de1(cuuid_meater))] 1 +} + +proc meater_parse_response { value } { + binary scan $value s raw + set temp [expr $raw / 16.0] + + msg -DEBUG "Meater temperature is $temp" + process_temperature_value $temp +} + + +### MISC + +proc process_temperature_value {value} { + if { [::de1::state::current_state] == "Steam" && [::de1::state::current_substate] == "pouring"} { + msg -INFO "temperature: " $value $::settings(target_milk_temperature) + if {$value >= [expr $::settings(target_milk_temperature) - 10.0 ]} { + start_idle + msg -NOTICE [format "Steaming stopped for temperature at %.1f for target %.1f" $value $::settings(target_milk_temperature)] + } + } + + set ::de1(thermometer_temperature) $value +} + proc close_all_ble_and_exit {} { ### @@ -710,6 +748,12 @@ proc close_all_ble_and_exit {} { } } + msg "Closing thermometer" + if {$::de1(scale_device_handle) != 0} { + catch { + ble close $::de1(thermometer_device_handle) + } + } catch { if {$::settings(ble_unpair_at_exit) == 1} { @@ -1105,28 +1149,69 @@ proc ble_connect_to_scale {} { } -proc append_to_scale_bluetooth_list {address name type} { - #msg "Sca $address" - set ::scale_types($address) $type +set ::currently_connecting_thermometer_handle 0 +proc ble_connect_to_thermometer {} { + + if {$::de1(thermometer_device_handle) != 0} { + msg "Already connected to a thermometer, don't try again" + return + } + + if {[ifexists ::de1(in_fw_update_mode)] == 1} { + msg "in_fw_update_mode : ble_connect_to_thermometer" + return + } - foreach { entry } $::scale_bluetooth_list { + + if {$::settings(thermometer_bluetooth_address) == ""} { + msg "No Thermometer BLE address in settings, so not connecting to it" + return + } + + if {$::currently_connecting_thermometer_handle != 0} { + msg "Already trying to connect to Thermometer, so don't try again" + return + } + + if {[llength $::de1(cmdstack)] > 2} { + msg -INFO "Too much backpressure, waiting with the connect" + after 300 ble_connect_to_thermometer + return + } + + if {[catch { + set ::currently_connecting_thermometer_handle [ble connect [string toupper $::settings(thermometer_bluetooth_address)] de1_ble_handler false] + msg "Connecting to thermometer on $::settings(thermometer_bluetooth_address)" + set retcode 0 + } err] != 0} { + set ::currently_connecting_thermometer_handle 0 + set retcode 1 + msg "Failed to start to BLE connect to scale because: '$err'" + } + return $retcode +} + + +proc append_to_peripheral_list {address name connectiontype devicetype devicefamily} { + + foreach { entry } $::peripheral_device_list { if { [dict get $entry address] eq $address} { return } } if { $name == "" } { - set name $type + set name $devicefamily } - set newlist $::scale_bluetooth_list - lappend newlist [dict create address $address name $name type $type] + set newlist $::peripheral_device_list + lappend newlist [dict create address $address name $name type $connectiontype devicetype $devicetype devicefamily $devicefamily] - msg "Scan found Skale or Decent Scale: $address ($type)" - set ::scale_bluetooth_list $newlist + msg "Scan found $connectiontype peripheral: $address ($devicetype:$devicefamily)" + set ::peripheral_device_list $newlist catch { - fill_ble_scale_listbox + fill_peripheral_listbox } } @@ -1240,7 +1325,7 @@ proc de1_ble_handler { event data } { } } } elseif {[string first Skale $name] == 0} { - append_to_scale_bluetooth_list $address $name "atomaxskale" + append_to_peripheral_list $address $name "ble" "scale" "atomaxskale" if {$address == $::settings(scale_bluetooth_address)} { if {$::currently_connecting_scale_handle == 0} { @@ -1250,7 +1335,7 @@ proc de1_ble_handler { event data } { } } elseif {[string first "Decent Scale" $name] == 0} { - append_to_scale_bluetooth_list $address $name "decentscale" + append_to_peripheral_list $address $name "ble" "scale" "decentscale" if {$address == $::settings(scale_bluetooth_address)} { if {$::currently_connecting_scale_handle == 0} { @@ -1259,7 +1344,7 @@ proc de1_ble_handler { event data } { } } } elseif {[string first "FELICITA" $name] == 0} { - append_to_scale_bluetooth_list $address $name "felicita" + append_to_peripheral_list $address $name "ble" "scale" "felicita" if {$address == $::settings(scale_bluetooth_address)} { if {$::currently_connecting_scale_handle == 0} { @@ -1268,7 +1353,7 @@ proc de1_ble_handler { event data } { } } } elseif {[string first "HIROIA JIMMY" $name] == 0} { - append_to_scale_bluetooth_list $address $name "hiroiajimmy" + append_to_peripheral_list $address $name "ble" "scale" "hiroiajimmy" if {$address == $::settings(scale_bluetooth_address)} { if {$::currently_connecting_scale_handle == 0} { @@ -1283,7 +1368,7 @@ proc de1_ble_handler { event data } { if { [string first "PROCH" $name] != -1 } { set ::settings(force_acaia_heartbeat) 1 } - append_to_scale_bluetooth_list $address $name "acaiascale" + append_to_peripheral_list $address $name "ble" "scale" "acaiascale" if {$address == $::settings(scale_bluetooth_address)} { if {$::currently_connecting_scale_handle == 0} { @@ -1291,6 +1376,16 @@ proc de1_ble_handler { event data } { ble_connect_to_scale } } + } elseif {[string first "MEATER" $name] == 0} { + + append_to_peripheral_list $address $name "ble" "thermometer" "apptionmeater" + + if {$address == $::settings(thermometer_bluetooth_address)} { + if {$::currently_connecting_thermometer_handle == 0} { + msg "Not currently connecting to scale, so trying now" + ble_connect_to_thermometer + } + } } else { #msg "-- device $name found at address $address ($data)" } @@ -1302,6 +1397,14 @@ proc de1_ble_handler { event data } { de1_disconnect_handler $handle + } elseif {$address == $::settings(scale_bluetooth_address)} { + catch { + ble close $::currently_connecting_thermometer_handle + } + set ::currently_connecting_thermometer_handle 0 + if {$handle == $::de1(thermometer_device_handle)} { + set ::de1(thermometer_device_handle) 0 + } } elseif {$address == $::settings(scale_bluetooth_address)} { #set ::de1(scale_type) "" @@ -1334,12 +1437,12 @@ proc de1_ble_handler { event data } { ::device::scale::event::apply::on_disconnect_callbacks $event_dict - # john 1-11-19 automatic reconnection attempts eventually kill the bluetooth stack on android 5.1 # john might want to make this happen automatically on Android 8, though. For now, it's a setting, which might # eventually get auto-set as per the current Android version, if we can trust that to give us a reliable BLE stack. if {$::settings(automatically_ble_reconnect_forever_to_scale) == 1} { ble_connect_to_scale + ble_connect_to_thermometer } } @@ -1354,15 +1457,9 @@ proc de1_ble_handler { event data } { ble_connect_to_de1 } - #if {$::de1(scale_device_handle) == 0 && $::settings(scale_bluetooth_address) != "" && $::currently_connecting_scale_handle == 0} { - #userdata_append "connect to scale" ble_connect_to_scale - #ble_connect_to_scale - #} } set ::scanning 0 } elseif {$state eq "discovery"} { - #msg "discovery" - #ble_connect_to_de1 } elseif {$state eq "connected"} { if {$::de1(device_handle) == 0 && $address == $::settings(bluetooth_address)} { @@ -1373,17 +1470,29 @@ proc de1_ble_handler { event data } { de1_connect_handler $handle $address "DE1" - if {$::de1(scale_device_handle) != 0} { + if {$::de1(scale_device_handle) != 0 && $::de1(thermometer_device_handle) != 0 } { # if we're connected to both the scale and the DE1, stop scanning (or if there is not scale to connect to and we're connected to the de1) stop_scanner } + } elseif {$::de1(thermometer_device_handle) == 0 && $address == $::settings(thermometer_bluetooth_address)} { + set ::de1(thermometer_device_handle) $handle - } elseif {$::de1(scale_device_handle) == 0 && $address == $::settings(scale_bluetooth_address)} { + if {$::de1(device_handle) != 0 && $::de1(scale_device_handle) != 0} { + # if we're connected to both the scale and the DE1, stop scanning + stop_scanner + } + msg "thermometer '$::settings(thermometer_bluetooth_name)' connected $::settings(thermometer_bluetooth_address) $handle - $event $data" - #append_to_scale_bluetooth_list $address [ifexists ::scale_types($address)] - #append_to_scale_bluetooth_list $address $::settings(scale_type) + if {$::settings(thermometer_bluetooth_type) == "apptionmeater"} { + append_to_peripheral_list $address $::settings(thermometer_bluetooth_name) "ble" "thermometer" "apptionmeater" + meater_enable_notifications + } + + set ::currently_connecting_thermometer_handle 0 + + } elseif {$::de1(scale_device_handle) == 0 && $address == $::settings(scale_bluetooth_address)} { set ::de1(wrote) 0 set ::de1(scale_device_handle) $handle @@ -1397,9 +1506,8 @@ proc de1_ble_handler { event data } { set ::settings(scale_type) "atomaxskale" } - #set ::de1(scale_type) [ifexists ::scale_types($address)] if {$::settings(scale_type) == "decentscale"} { - append_to_scale_bluetooth_list $address $::settings(scale_bluetooth_name) "decentscale" + append_to_peripheral_list $address $::settings(scale_bluetooth_name) "ble" "scale" "decentscale" #after 500 decentscale_enable_lcd decentscale_tare @@ -1410,20 +1518,20 @@ proc de1_ble_handler { event data } { #after 5000 decentscale_timer_off } elseif {$::settings(scale_type) == "atomaxskale"} { - append_to_scale_bluetooth_list $address $::settings(scale_bluetooth_name) "atomaxskale" + append_to_peripheral_list $address $::settings(scale_bluetooth_name) "ble" "scale" "atomaxskale" #set ::de1(scale_type) "atomaxskale" skale_enable_lcd after 1000 skale_enable_weight_notifications after 2000 skale_enable_button_notifications after 3000 skale_enable_lcd } elseif {$::settings(scale_type) == "felicita"} { - append_to_scale_bluetooth_list $address $::settings(scale_bluetooth_name) "felicita" + append_to_peripheral_list $address $::settings(scale_bluetooth_name) "ble" "scale" "felicita" after 2000 felicita_enable_weight_notifications } elseif {$::settings(scale_type) == "hiroiajimmy"} { - append_to_scale_bluetooth_list $address $::settings(scale_bluetooth_name) "hiroiajimmy" + append_to_peripheral_list $address $::settings(scale_bluetooth_name) "ble" "scale" "hiroiajimmy" after 200 hiroia_enable_weight_notifications } elseif {$::settings(scale_type) == "acaiascale"} { - append_to_scale_bluetooth_list $address $::settings(scale_bluetooth_name) "acaiascale" + append_to_peripheral_list $address $::settings(scale_bluetooth_name) "ble" "scale" "acaiascale" acaia_send_ident after 500 acaia_send_config after 1000 acaia_enable_weight_notifications @@ -1433,7 +1541,7 @@ proc de1_ble_handler { event data } { } set ::currently_connecting_scale_handle 0 - if {$::de1(device_handle) != 0} { + if {$::de1(device_handle) != 0 && $::de1(thermometer_device_handle) != 0} { # if we're connected to both the scale and the DE1, stop scanning stop_scanner } @@ -1795,6 +1903,9 @@ proc de1_ble_handler { event data } { } elseif {$cuuid eq $::de1(cuuid_hiroiajimmy_status)} { # hiroia jimmy scale hiroia_parse_response $value + } elseif {$cuuid eq $::de1(cuuid_meater)} { + # meater thermometer + meater_parse_response $value } elseif {$cuuid eq $::de1(cuuid_skale_EF82)} { set t0 {} #set t1 {} @@ -1905,14 +2016,6 @@ proc de1_ble_handler { event data } { } service { msg "de1 service $event $data" - #if {$suuid == "0000180A-0000-1000-8000-00805F9B34FB"} { - # set ::scale_types($address) "atomaxskale" - # msg "atomaxskale FOUND $suuid" - #} elseif {$suuid == "83CDC3D4-3BA2-13FC-CC5E-106C351A9352"} { - # set ::scale_types($address) "decentscale" - # msg "decentscale FOUND $suuid" - #} - } descriptor { #msg "de1 descriptor $state: ${event}: ${data}" @@ -2054,7 +2157,7 @@ proc scanning_state_text {} { } #return [translate "Tap to select"] - if {[ifexists ::de1_needs_to_be_selected] == 1 || [ifexists ::scale_needs_to_be_selected] == 1} { + if {[ifexists ::de1_needs_to_be_selected] == 1 || [ifexists ::peripheral_needs_to_be_selected] == 1} { return [translate "Tap to select"] } @@ -2069,13 +2172,9 @@ proc scanning_restart {} { # insert enough dummy devices to overfill the list, to test whether scroll bars are working set ::de1_device_list [list [dict create address "12:32:16:18:90" name "ble3" type "ble"] [dict create address "10.1.1.20" name "wifi1" type "wifi"] [dict create address "12:32:56:78:91" name "dummy_ble2" type "ble"] [dict create address "12:32:56:78:92" name "dummy_ble3" type "ble"] [dict create address "ttyS0" name "dummy_usb" type "usb"] [dict create address "192.168.0.1" name "dummy_wifi2" type "wifi"]] - set ::scale_bluetooth_list [list [dict create address "51:32:56:78:90" name "ACAIAxxx" type "ble"] [dict create address "92:32:56:78:90" name "Skale2" type "ble"] [dict create address "12:32:56:78:92" name "ACAIA2xxx" type "ble"] [dict create address "12:32:56:78:93" name "Skale2b" type "ble"] ] - - set ::scale_types(12:32:56:78:90) "decentscale" - set ::scale_types(32:56:78:90:12) "decentscale" - set ::scale_types(56:78:90:12:32) "atomaxskale" + set ::peripheral_device_list [list [dict create address "51:32:56:78:90" name "ACAIAxxx" type "ble" devicetype "scale" devicefamily "acaiascale"] [dict create address "12:32:56:78:93" name "MEATER" type "ble" devicetype "thermometer" devicefamily "apptionmeater"] ] - after 200 fill_ble_scale_listbox + after 200 fill_peripheral_listbox after 400 fill_ble_listbox set ::scanning 1 diff --git a/de1plus/de1_comms.tcl b/de1plus/de1_comms.tcl index 29035d32..3329db22 100644 --- a/de1plus/de1_comms.tcl +++ b/de1plus/de1_comms.tcl @@ -236,6 +236,10 @@ proc de1_connect_handler { handle address name} { ble_connect_to_scale } + if {$::settings(thermometer_bluetooth_address) != ""} { + ble_connect_to_thermometer + } + incr ::successful_de1_connection_count set ::failed_attempt_count_connecting_to_de1 0 diff --git a/de1plus/machine.tcl b/de1plus/machine.tcl index 898bf3eb..fc965c90 100644 --- a/de1plus/machine.tcl +++ b/de1plus/machine.tcl @@ -40,6 +40,7 @@ array set ::de1 { device_handle 0 language_rtl 0 scale_device_handle 0 + thermometer_device_handle 0 decentscale_device_handle 0 suuid "0000A000-0000-1000-8000-00805F9B34FB" sinstance 12 @@ -73,6 +74,8 @@ array set ::de1 { suuid_hiroiajimmy "06C31822-8682-4744-9211-FEBC93E3BECE" cuuid_hiroiajimmy_cmd "06C31823-8682-4744-9211-FEBC93E3BECE" cuuid_hiroiajimmy_status "06C31824-8682-4744-9211-FEBC93E3BECE" + suuid_meater "A75CC7FC-C956-488F-AC2A-2DBC08B63A04" + cuuid_meater "7EDDA774-045E-4BBF-909B-45D1991A2876" cinstance 0 fan_threshold 0 tank_temperature_threshold 0 @@ -140,6 +143,7 @@ array set ::de1 { last_ping 0 steam_heater_temperature 150 connectivity "ble" + thermometer_temperature 0 } set ::de1(last_ping) [clock seconds] @@ -346,6 +350,9 @@ array set ::settings { scale_bluetooth_name {} skale_bluetooth_address {} bluetooth_address {} + thermometer_bluetooth_name {} + thermometer_bluetooth_address {} + thermometer_bluetooth_type {} water_max_vol 500 water_temperature 85 final_desired_shot_weight 36 @@ -439,6 +446,8 @@ array set ::settings { maximum_pressure_range_advanced 0.6 high_vibration_scale_filtering False last_version "1.34" + + target_milk_temperature 65 } # default de1plus skin @@ -455,13 +464,6 @@ if { $settings(bluetooth_address) != ""} { append_to_de1_list $settings(bluetooth_address) "DE1" "ble" } -#msg "init was run '$::settings(scale_type)'" - - #error "atomaxscale" -# initial filling of BLE scale list -#set ::scale_bluetooth_list $::settings(scale_bluetooth_address) - - array set ::de1_state { Sleep \x00 GoingToSleep \x01 @@ -515,7 +517,7 @@ array set ::de1_num_state { -set ::scale_bluetooth_list "" +set ::peripheral_device_list "" array set ::de1_num_state_reversed [reverse_array ::de1_num_state] diff --git a/de1plus/skins/default/de1_skin_settings.tcl b/de1plus/skins/default/de1_skin_settings.tcl index 90d9fb03..a1367013 100644 --- a/de1plus/skins/default/de1_skin_settings.tcl +++ b/de1plus/skins/default/de1_skin_settings.tcl @@ -902,11 +902,11 @@ add_de1_text "settings_4" 55 970 -text [translate "Connect"] -font Helv_10_bold add_de1_text "settings_4" 680 1100 -text [translate "Scale"] -font Helv_7_bold -fill "#7f879a" -justify "left" -anchor "nw" add_de1_variable "settings_4" 1240 1100 -text \[[translate "Remove"]\] -font Helv_7 -fill "#bec7db" -justify "right" -anchor "ne" -textvariable {[if {$::settings(scale_bluetooth_address) != ""} { return \[[translate "Remove"]\]} else {return "" } ] } - add_de1_button "settings_4" {say [translate {Remove}] $::settings(sound_button_in);set ::settings(scale_bluetooth_address) "";fill_ble_scale_listbox} 960 1100 1250 1140 "" + add_de1_button "settings_4" {say [translate {Remove}] $::settings(sound_button_in);set ::settings(scale_bluetooth_address) "";fill_peripheral_listbox} 960 1100 1250 1140 "" add_de1_widget "settings_4" listbox 670 1150 { set ::ble_scale_listbox_widget $widget - bind $widget <> ::change_scale_bluetooth_device - fill_ble_scale_listbox + bind $widget <> ::select_peripheral_device + fill_peripheral_listbox } -background #fbfaff -font Helv_9 -bd 0 -height 3 -width 15 -foreground #d3dbf3 -borderwidth 0 -selectborderwidth 0 -relief flat -highlightthickness 0 -selectmode single -selectbackground #c0c4e1 -yscrollcommand {scale_scroll_new $::ble_scale_listbox_widget ::ble_scale_slider} set ::ble_scale_slider 0 diff --git a/de1plus/vars.tcl b/de1plus/vars.tcl index 0102d29d..09345051 100644 --- a/de1plus/vars.tcl +++ b/de1plus/vars.tcl @@ -1754,6 +1754,22 @@ proc bluetooth_character {} { return "\uE018" } +proc thermometer_character {} { + if {[language] == "ar" || [language] == "he"} { + return "T:" + } + + return "\uF2C9" +} + +proc scale_character {} { + if {[language] == "ar" || [language] == "he"} { + return "SCALE:" + } + + return "\uF515" +} + proc usb_character {} { if {[language] == "ar" || [language] == "he"} { return "USB:" @@ -1819,41 +1835,54 @@ proc fill_ble_listbox {} { } proc fill_ble_scale_listbox {} { - + fill_peripheral_listbox +} + +proc fill_peripheral_listbox {} { set widget $::ble_scale_listbox_widget $widget delete 0 99999 set cnt 0 - set current_ble_number 0 set one_selected 0 - foreach d [lsort -dictionary -increasing $::scale_bluetooth_list] { + foreach d $::peripheral_device_list { set addr [dict get $d address] set name [dict get $d name] set type [dict get $d type] - set icon [bluetooth_character] + set devicetype [dict get $d devicetype] + set icon "UNKN:" + + if {$devicetype eq "thermometer"} { + set icon [thermometer_character] + } elseif {$devicetype eq "scale"} { + set icon [scale_character] + } elseif {$type eq "ble"} { + set icon [bluetooth_character] + } if { $name eq "" } { set name $type } - if {$addr == [ifexists ::settings(scale_bluetooth_address)]} { + if {$addr in [list $::settings(scale_bluetooth_address) $::settings(thermometer_bluetooth_address)]} { $widget insert $cnt " \[[checkboxchar]\] $icon $name" set one_selected 1 } else { $widget insert $cnt " \[ \] $icon $name" } - #$widget insert $cnt $addr + if {[ifexists ::settings(scale_bluetooth_address)] == $addr} { set current_ble_number $cnt } + incr cnt } + # We only highlight the scale $widget selection set $current_ble_number; - set ::scale_needs_to_be_selected 0 - if {[llength $::de1_device_list] > 0 && $one_selected == 0} { - set ::scale_needs_to_be_selected 1 + set ::peripheral_needs_to_be_selected 0 + if {[llength $::peripheral_device_list] > 0 && $one_selected == 0} { + set ::peripheral_needs_to_be_selected 1 } - + make_current_listbox_item_blue $widget } @@ -2520,47 +2549,60 @@ proc change_bluetooth_device {} { fill_ble_listbox } - - proc change_scale_bluetooth_device {} { - set w $::ble_scale_listbox_widget + select_peripheral_device +} +proc select_peripheral_device {} { + set w $::ble_scale_listbox_widget if {$w == ""} { return } if {[$w curselection] == ""} { - # no current selection - #return "" - msg "re-connecting to scale" - ble_connect_to_scale return } set selection_index [$w curselection] - set dic [lindex $::scale_bluetooth_list $selection_index] + + msg "selected item" $selection_index + set dic [lindex $::peripheral_device_list $selection_index] set addr [dict get $dic address] set name [dict get $dic name] + set type [dict get $dic type] + set devicetype [dict get $dic devicetype] + set devicefamily [dict get $dic devicefamily] if { $name == "" } { - set name [dict get $dic type] + set name $devicefamily + } + + if {$type ne "ble"} { + msg -WARNING "Non BLE peripheral requested for connect. Damn!" + return } - set ::settings(scale_bluetooth_address) $addr - set ::settings(scale_bluetooth_name) $name + msg "selected $devicetype $name @ $addr" - set ::settings(scale_type) [ifexists ::scale_types($addr)] - msg "set scale type to: '$::settings(scale_type)' $addr" + if {$devicetype eq "scale"} { + set ::settings(scale_bluetooth_address) $addr + set ::settings(scale_bluetooth_name) $name + set ::settings(scale_type) $devicefamily + msg "set scale type to: '$::settings(scale_type)' $addr" - if {$addr == $::settings(scale_bluetooth_address)} { ble_connect_to_scale - return + } elseif {$devicetype eq "thermometer"} { + set ::settings(thermometer_bluetooth_address) $addr + set ::settings(thermometer_bluetooth_name) $name + set ::settings(thermometer_bluetooth_type) $devicefamily + + ble_connect_to_thermometer } - #msg "scale types: [array get ::scale_types]" save_settings - ble_connect_to_scale + $::ble_scale_listbox_widget selection set $selection_index; + make_current_listbox_item_blue $::ble_scale_listbox_widget - fill_ble_scale_listbox + fill_peripheral_listbox }