From c19994b9579aea8e95a629d8259e03b0009a4198 Mon Sep 17 00:00:00 2001 From: Caleb Denio Date: Fri, 6 Nov 2026 23:10:19 -0700 Subject: [PATCH] more --- src/arduino_router.zig | 8 +++++++- src/main.zig | 16 ++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/arduino_router.zig b/src/arduino_router.zig index b69908d..e4cb4c9 100644 --- a/src/arduino_router.zig +++ b/src/arduino_router.zig @@ -2,6 +2,12 @@ const std = @import("std"); const net = std.Io.net; const msgpack = @import("msgpack"); +const RpcType = enum(u8) { + request = 0, + response = 1, + notification = 2, +}; + pub const ArduinoRouter = struct { stream: net.Stream, io: std.Io, @@ -17,7 +23,7 @@ pub const ArduinoRouter = struct { var request = try msgpack.Payload.arrPayload(3, allocator); defer request.free(allocator); - try request.setArrElement(0, msgpack.Payload.intToPayload(2)); + try request.setArrElement(0, msgpack.Payload.intToPayload(@backingInt(RpcType.notification))); const methodPayload = try msgpack.Payload.strToPayload(method, allocator); defer methodPayload.free(allocator); diff --git a/src/main.zig b/src/main.zig index 0205c9e..81a62ff 100644 --- a/src/main.zig +++ b/src/main.zig @@ -59,15 +59,13 @@ const App = struct { var regs: [0xB4]u8 = @splat(0x00); for (feed.value.vehicles) |vehicle| { - const thing = self.led_map.get(vehicle.nearest_station.id); - - if (thing) |value| { - std.debug.print("train at {s}, setting reg {} to {}\n", .{ vehicle.nearest_station.id, value.column, value.row }); - regs[value.led_reg()] |= (@as(u8, 1) << (value.column)); - if (regs[value.pwm_reg()] == 0) { - regs[value.pwm_reg()] = 50; + if (self.led_map.get(vehicle.nearest_station.id)) |led| { + std.debug.print("train at {s}, setting reg {} to {}\n", .{ vehicle.nearest_station.id, led.column, led.row }); + regs[led.led_reg()] |= (@as(u8, 1) << (led.column)); + if (regs[led.pwm_reg()] == 0) { + regs[led.pwm_reg()] = 50; } else { - regs[value.pwm_reg()] = 127; + regs[led.pwm_reg()] = 127; } } } @@ -81,8 +79,6 @@ const App = struct { msgpack.Payload.uintToPayload(value), // value }); try io.sleep(.fromMilliseconds(5), .real); - - std.debug.print("{x} IS {x}\n", .{ reg, value }); } try self.router.notify(allocator, "displayFrame", &.{msgpack.Payload.intToPayload(~self.current_frame)});