Skip to content

Commit

Permalink
add train disable to blocks, only connect to active hubs
Browse files Browse the repository at this point in the history
implements #161
  • Loading branch information
Novakasa committed Oct 1, 2023
1 parent 028ac9b commit 1e0ba6f
Show file tree
Hide file tree
Showing 14 changed files with 1,073 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

### Added

- Added "disable train" setting for blocks. Any train in a block with this setting enabled will not be connected via bluetooth. Layout Controllers will only need to connect when a device is assigned to one of it's ports. (https://github.com/Novakasa/brickrail/issues/161)

### Fixed

- Don't allow adding train to occupied block. This previously created invalid state.
Expand Down
6 changes: 6 additions & 0 deletions brickrail-gui/ble/ble_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ func are_hubs_ready():
if not $BLECommunicator.connected:
return false
for hub in hubs.values():
if not hub.active:
continue
if not hub.running:
return false
return true

func get_hub_status():
var status = {}
for hub in hubs.values():
if not hub.active:
continue
if hub.busy:
status[hub.name] = hub.status
return status
Expand Down Expand Up @@ -124,6 +128,8 @@ func clean_exit_coroutine():
func connect_and_run_all_coroutine():
yield(Devices.get_tree(), "idle_frame")
for hub in hubs.values():
if not hub.active:
continue
if not hub.connected:
var result = yield(hub.connect_coroutine(), "completed")
if result == "error":
Expand Down
6 changes: 6 additions & 0 deletions brickrail-gui/ble/ble_hub.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var busy = false
var status = "disconnected"
var battery_voltage = -1.0
var battery_current = -1.0
var active = false

var storage = {}

Expand All @@ -32,6 +33,7 @@ signal removing(name)
signal state_changed()
signal battery_changed()
signal skip_download_changed(value)
signal active_changed(p_active)

func set_skip_download(value):
skip_download = value
Expand Down Expand Up @@ -88,6 +90,10 @@ func _on_ble_communicator_status_changed():
func set_responsiveness(val):
responsiveness = val
emit_signal("responsiveness_changed", val)

func set_active(p_active):
active = p_active
emit_signal("active_changed", p_active)

func set_name(p_new_name):
var old_name = name
Expand Down
26 changes: 18 additions & 8 deletions brickrail-gui/ble/hub_control_gui.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,38 @@ scan_button = NodePath("HBoxContainer2/scan_button")

[node name="HBoxContainer2" type="HBoxContainer" parent="."]
margin_right = 237.0
margin_bottom = 20.0
margin_bottom = 40.0

[node name="ActiveButton" type="CheckButton" parent="HBoxContainer2"]
margin_right = 76.0
margin_bottom = 40.0
hint_tooltip = "Indicates whether hub will be connected via bluetooth when \"control devices\" is turned on.
This is set automatically when the hub is assigned to a train and the train is not in a \"disable train\" block.
Is also set automatically when a switch or crossing motor is assigned to a port of this hub."
button_mask = 0

[node name="BatteryLabel" type="Label" parent="HBoxContainer2"]
margin_top = 3.0
margin_bottom = 17.0
margin_left = 80.0
margin_top = 13.0
margin_right = 80.0
margin_bottom = 27.0

[node name="Control" type="Control" parent="HBoxContainer2"]
margin_left = 4.0
margin_left = 84.0
margin_right = 143.0
margin_bottom = 20.0
margin_bottom = 40.0
size_flags_horizontal = 3

[node name="scan_button" type="Button" parent="HBoxContainer2"]
margin_left = 147.0
margin_right = 237.0
margin_bottom = 20.0
margin_bottom = 40.0
text = "Scan for hub"

[node name="HBoxContainer" type="HBoxContainer" parent="."]
margin_top = 24.0
margin_top = 44.0
margin_right = 237.0
margin_bottom = 48.0
margin_bottom = 68.0

[node name="connect_button" type="Button" parent="HBoxContainer"]
margin_right = 64.0
Expand Down
7 changes: 6 additions & 1 deletion brickrail-gui/ble/hub_controls.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ func setup(p_hub):
_on_hubs_state_changed()
_err = hub.connect("battery_changed", self, "_on_hub_battery_changed")
_err = hub.connect("skip_download_changed", self, "_on_hub_skip_download_changed")
_err = hub.connect("active_changed", self, "_on_hub_active_changed")
$HBoxContainer/DownloadCheckbox.pressed = not hub.skip_download
$HBoxContainer2/ActiveButton.pressed = hub.active

func _on_hub_skip_download_changed(value):
$HBoxContainer/DownloadCheckbox.pressed = not value

func _on_hub_battery_changed():
$HBoxContainer2/BatteryLabel.text = ("Battery %.2f" % hub.battery_voltage) + "V"
$HBoxContainer2/BatteryLabel.text = ("%.2f" % hub.battery_voltage) + "V"

func _on_hub_active_changed(p_active):
$HBoxContainer2/ActiveButton.pressed = p_active

func _on_hubs_state_changed():
var controller = Devices.get_ble_controller()
Expand Down
Loading

0 comments on commit 1e0ba6f

Please sign in to comment.