From 5f779aef096ba1d3d24392703357c756d757d7e0 Mon Sep 17 00:00:00 2001 From: catvayor Date: Sun, 13 Oct 2024 21:09:25 +0200 Subject: [PATCH] fix(agb02): joystick on 0-255 --- machines/agb02/_configuration.nix | 15 +++++++++++++-- machines/agb02/agb/agb.cpp | 11 +++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/machines/agb02/_configuration.nix b/machines/agb02/_configuration.nix index dcf74bb..699b08f 100644 --- a/machines/agb02/_configuration.nix +++ b/machines/agb02/_configuration.nix @@ -1,5 +1,7 @@ { config, pkgs, lib, modulesPath, ... }: - +let + agb-control-box = pkgs.callPackage ./agb { }; +in { imports = [ "${modulesPath}/installer/sd-card/sd-image-aarch64.nix" @@ -17,9 +19,18 @@ networking.networkmanager.enable = true; environment.systemPackages = [ - (pkgs.callPackage ./agb {}) + agb-control-box pkgs.libgpiod ]; + systemd.services."agb-control-box" = { + wantedBy = [ "multi-user.target" ]; + unitConfig.Description = "The program of the control-box"; + serviceConfig = { + Restart = "always"; + ExecStart = "${agb-control-box}/bin/agb /dev/gpiochip0"; + }; + }; + system.stateVersion = "24.11"; } diff --git a/machines/agb02/agb/agb.cpp b/machines/agb02/agb/agb.cpp index 4eb3094..343be6a 100644 --- a/machines/agb02/agb/agb.cpp +++ b/machines/agb02/agb/agb.cpp @@ -13,7 +13,7 @@ constexpr std::chrono::microseconds poll_period = 5ms; constexpr std::chrono::microseconds server_ratelimit = 50ms; constexpr std::chrono::microseconds retry_timeout = 500ms; -constexpr std::pair joystick_movement(1.0, 1.0); +constexpr std::pair joystick_movement(.3, .3); const gpiod::line::offsets drive_down = { 21, 13, 6 }; @@ -119,8 +119,11 @@ int main(const int argc, char const* const* const argv) { if(bool(joystick_read[3])) spot_pos.second -= joystick_movement.second; if (bool(joystick_read[0]) || bool(joystick_read[1]) - || bool(joystick_read[2]) || bool(joystick_read[3])) + || bool(joystick_read[2]) || bool(joystick_read[3])){ + spot_pos.first = std::clamp(spot_pos.first, 0.0, 255.0); + spot_pos.second = std::clamp(spot_pos.second, 0.0, 255.0); has_changed = true; + } /// Buttons /// bool pressed = bool(line_reader.get_value(black_button)); @@ -164,8 +167,8 @@ int main(const int argc, char const* const* const argv) { "\"whiteButton\": {}," "\"blackButton\": {}" "}}\n", - spot_pos.first, - spot_pos.second, + uint8_t(spot_pos.first), + uint8_t(spot_pos.second), int(decoder_pos), white_pressed, black_pressed