Skip to content

Commit

Permalink
fix duplicate messages for hub status
Browse files Browse the repository at this point in the history
closes #172

Also clarify disconnected during operation error
  • Loading branch information
Novakasa committed Jan 3, 2024
1 parent 2994147 commit 3e3f121
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Fixed

- Fix duplicate status messages for hubs in log messages panel (https://github.com/Novakasa/brickrail/issues/172).
- Fix invalid ble-server state when hub disconnects during program running (e.g. when battery is removed) (https://github.com/Novakasa/brickrail/issues/160).
- Fix pybricks error with motors with rotation encoders in pybricks 3.3-stable (https://github.com/Novakasa/brickrail/issues/174).
- Don't allow adding train to occupied block. This previously created invalid state.
Expand Down
20 changes: 18 additions & 2 deletions brickrail-gui/ble/ble_hub.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var communicator: BLECommunicator
var responsiveness = false
var busy = false
var status = "disconnected"
var prev_state = "disconnected"
var battery_voltage = -1.0
var battery_current = -1.0
var active = false
Expand Down Expand Up @@ -66,14 +67,17 @@ func _init(p_name, p_program):
GuiApi.show_info("[%s] io_hub outdated, program will be redownloaded" % name)
set_skip_download(false)
else:
GuiApi.show_info("[%s] New hub, program will be downloaded" % name)
# GuiApi.show_info("[%s] New hub, program will be downloaded" % name)
set_skip_download(false)

func _on_state_changed():
if status == prev_state:
return
if busy:
GuiApi.show_info("[%s] %s..." % [name, status])
else:
GuiApi.show_info("[%s] %s" % [name, status])
prev_state = status

func _on_ble_communicator_status_changed():
if not communicator.connected:
Expand Down Expand Up @@ -181,7 +185,19 @@ func _on_data_received(key, data):
if data == "program_start_timeout":
return
elif "ENODEV" in data:
GuiApi.show_error("Hub '"+name+"' missing motor or sensor!")
var msg = "Hub '"+name+"' missing motor or sensor!"
var more_info = msg
more_info += "\n\nFor trains:"
more_info += "\nThe motor needs to be plugged into Port A"
more_info += "\nThe Color and Distance sensor needs to be plugged into Port B"
more_info += "\n\nFor Layout controllers:"
more_info += "\nmake sure each switch is configured correctly!"
GuiApi.show_error(msg, more_info)
elif "disconnected during operation" in data:
var msg = "Hub '"+name+"' disconnected unexpectedly!"
var more_info = msg
more_info += "\n\nThis could be caused by:\n- low battery\n- bluetooth interference\n- unreliable bluetooth adapter"
GuiApi.show_error(msg, more_info)
else:
GuiApi.show_error("Hub '"+name+"' Program Error: " + data)
emit_signal("program_error", data)
Expand Down

0 comments on commit 3e3f121

Please sign in to comment.