fix(agb02): joystick on 0-255

This commit is contained in:
catvayor 2024-10-13 21:09:25 +02:00
parent 5bbc38c6ca
commit 5f779aef09
Signed by: lbailly
GPG key ID: CE3E645251AC63F3
2 changed files with 20 additions and 6 deletions

View file

@ -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";
}

View file

@ -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<double, double> joystick_movement(1.0, 1.0);
constexpr std::pair<double, double> 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