Files
room_glitch/core/runtime/pi_gpio_client.gd
T
Jeff Luke c1b2195834 Expand Glitch operations hub, cabinet authoring, deployment, and RFID support
Operator hub
- Introduce Escape Gallery branding and Glitch: the Dark Machine room views
- Add cabinet illustrations, Pac-Man marquee/gameplay artwork, and waiting states
- Add device feedback panels with RFID readings, input/output states, and stale status
- Add logged operator hardware interventions with request deduplication

Room and cabinet authoring
- Add a visual custom-PCB connection editor with per-cabinet device inventory
- Support device IDs, bindings, wiring notes, input polarity, and validation
- Add physical-room label/dimension toggles and editable doorway annotations
- Preserve doorway changes through undo, save, and revert
- Expand cabinet profiles, room layout, and Glitch scenario resources

Scenarios and gameplay
- Add per-assignment game configuration and runtime feature validation
- Add timed test wins and Frogger individual-home objectives
- Add the three-cabinet timed/score/Frogger test scenario
- Add Cabinet 1 Pac-Man RFID credits, credit sound, and CREDIT 0/1 display
- Require physical Start after an accepted scan and prevent duplicate credits

Pi hardware and deployment
- Add GPIO feedback sampling and a separate multiplexed RFID helper
- Validate reader pin ownership and input/output conflicts
- Add SSH cabinet startup and Pi desktop-session service support
- Add master packaging, site setup, SSH enrollment, and staged cabinet releases
- Verify deployment manifests and support explicit activation/status/log commands

Documentation and verification
- Consolidate the root README around the current architecture and setup workflow
- Add the complete master/Pi/RFID export and deployment walkthrough
- Document network isolation, credentials, card identification, and rollback
- Add PCB, room-editor, feedback, credit, deployment, and controller tests
- Isolate protocol tests from designer-edited cabinet configurations

Known limitations
- RFID helper compilation and physical Pi commissioning remain unverified
- Fleet provisioning does not yet configure RFID-only installations completely
- Broader Pac-Man tests retain a ghost-capture assertion failure
- Staged exports must be rebuilt and checked before deploying runtime 2.3
2026-10-17 14:53:54 -07:00

77 lines
2.8 KiB
GDScript

extends Node
signal completed(id: int, ok: bool)
signal status_changed(message: String)
const URL := "http://127.0.0.1:8765"
var pending: Array[Dictionary] = []
var serial := 0
var busy := false
var device_feedback: Dictionary = {}
var feedback_received_ms: int = 0
var heartbeat: HTTPRequest
func _ready() -> void:
process_mode = Node.PROCESS_MODE_ALWAYS
heartbeat = HTTPRequest.new()
heartbeat.timeout = 1.0
add_child(heartbeat)
heartbeat.request_completed.connect(_feedback_response)
var timer := Timer.new()
timer.wait_time = 1.0
timer.timeout.connect(_heartbeat)
add_child(timer)
timer.start()
func _heartbeat() -> void:
if heartbeat.get_http_client_status() == HTTPClient.STATUS_DISCONNECTED:
heartbeat.request(URL + "/heartbeat", [], HTTPClient.METHOD_POST, "{}")
func send(payload: Dictionary) -> bool:
if pending.size() >= 32:
status_changed.emit("GPIO output queue is full")
return false
serial += 1
var id := serial
pending.append({"id": id, "payload": payload})
_pump.call_deferred()
while true:
var result: Array = await completed
if result[0] == id: return result[1]
return false
func _pump() -> void:
if busy or pending.is_empty(): return
busy = true
var item: Dictionary = pending[0]
var request := HTTPRequest.new()
request.timeout = 2.0
add_child(request)
var ok := false
var message := "GPIO bridge unavailable — start pi_gpio_bridge.py on this Pi"
var error := request.request(URL + "/output", ["Content-Type: application/json"], HTTPClient.METHOD_POST, JSON.stringify(item.payload))
if error == OK:
var response: Array = await request.request_completed
var body = JSON.parse_string(response[3].get_string_from_utf8())
ok = response[0] == HTTPRequest.RESULT_SUCCESS and response[1] == 200 and body is Dictionary and body.get("ok", false) == true
if body is Dictionary and body.has("error"): message = str(body.error)
request.queue_free()
pending.pop_front()
busy = false
status_changed.emit("GPIO %s accepted by Pi bridge" % item.payload.pin if ok else message)
completed.emit(item.id, ok)
_pump.call_deferred()
func _feedback_response(result: int, code: int, _headers: PackedStringArray, body: PackedByteArray) -> void:
if result != HTTPRequest.RESULT_SUCCESS or code != 200:
return
var data = JSON.parse_string(body.get_string_from_utf8())
if data is Dictionary and data.get("feedback") is Dictionary:
device_feedback = data.feedback
feedback_received_ms = Time.get_ticks_msec()
func get_feedback() -> Dictionary:
var result := device_feedback.duplicate(true)
result["fresh"] = feedback_received_ms > 0 and Time.get_ticks_msec() - feedback_received_ms < 4000
for device in result.get("devices", []):
device["age_ms"] = int(device.get("age_ms", 999999)) + maxi(0, Time.get_ticks_msec() - feedback_received_ms)
return result