From fefb3deb0256a8c25befe83526b75906089d406b Mon Sep 17 00:00:00 2001 From: Scott Vincent Date: Wed, 25 Sep 2024 16:42:07 +0100 Subject: [PATCH] Add switchbox parking brake --- power-lights-panel/powerLights-panel.cpp | 2 +- power-lights-panel/powerLights.cpp | 35 ++++++++++++++++++++---- power-lights-panel/powerLights.h | 4 ++- power-lights-panel/simvarDefs.cpp | 3 +- power-lights-panel/simvarDefs.h | 1 + 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/power-lights-panel/powerLights-panel.cpp b/power-lights-panel/powerLights-panel.cpp index 6872b3e..9e874e3 100644 --- a/power-lights-panel/powerLights-panel.cpp +++ b/power-lights-panel/powerLights-panel.cpp @@ -13,7 +13,7 @@ #include "simvars.h" #include "powerLights.h" -const char* powerLightsVersion = "v1.5.2"; +const char* powerLightsVersion = "v1.5.3"; const bool Debug = false; struct globalVars globals; diff --git a/power-lights-panel/powerLights.cpp b/power-lights-panel/powerLights.cpp index 72bc4e7..4de12ea 100644 --- a/power-lights-panel/powerLights.cpp +++ b/power-lights-panel/powerLights.cpp @@ -22,15 +22,17 @@ powerLights::powerLights() void powerLights::render() { #ifdef DEBUG - bleedTest--; - if (bleedTest < 0) { - bleedTest = 20; + lightsTest--; + if (lightsTest < 0) { + lightsTest = 20; } - if (bleedTest == 20) { + if (lightsTest == 20) { + globals.gpioCtrl->writeLed(apuMasterControl, true); globals.gpioCtrl->writeLed(apuStartControl, true); globals.gpioCtrl->writeLed(apuBleedControl, true); } - else if (bleedTest == 5) { + else if (lightsTest == 5) { + globals.gpioCtrl->writeLed(apuMasterControl, false); globals.gpioCtrl->writeLed(apuStartControl, false); globals.gpioCtrl->writeLed(apuBleedControl, false); } @@ -40,7 +42,7 @@ void powerLights::render() if (!globals.electrics) { // Turn off LEDS globals.gpioCtrl->writeLed(apuMasterControl, false); - globals.gpioCtrl->writeLed(apuStartControl, false); + //globals.gpioCtrl->writeLed(apuStartControl, false); globals.gpioCtrl->writeLed(apuBleedControl, false); // Make sure settings get re-initialised @@ -82,6 +84,9 @@ void powerLights::update() prevFlapsDownToggle = -1; prevParkBrakeOffToggle = -1; prevParkBrakeOnToggle = -1; + if (simVars->sbParkBrake != -1) { + prevSbParkBrake = 0; + } if (simVars->altAboveGround < 50) { // Start with parking brake on (will only turn on when electrics enabled!) if (!simVars->parkingBrakeOn) { @@ -535,6 +540,7 @@ void powerLights::gpioParkBrakeInput() globals.simVars->write(KEY_PARKING_BRAKE_SET, 0); } prevParkBrakeOffToggle = val; + return; } // Park brake on toggle @@ -546,5 +552,22 @@ void powerLights::gpioParkBrakeInput() globals.simVars->write(KEY_PARKING_BRAKE_SET, 1); } prevParkBrakeOnToggle = val; + return; + } + + // Check Switchbox parking brake + if (sbParkBrakeDelay > 0) { + sbParkBrakeDelay--; + } + else if (simVars->sbParkBrake != prevSbParkBrake) { + prevSbParkBrake = simVars->sbParkBrake; + if (simVars->sbParkBrake == 1 && !simVars->parkingBrakeOn) { + globals.simVars->write(KEY_PARKING_BRAKE_SET, 1); + sbParkBrakeDelay = 3; + } + else if (simVars->sbParkBrake == 0 && simVars->parkingBrakeOn) { + globals.simVars->write(KEY_PARKING_BRAKE_SET, 0); + sbParkBrakeDelay = 3; + } } } diff --git a/power-lights-panel/powerLights.h b/power-lights-panel/powerLights.h index 0bac8dc..91e6292 100644 --- a/power-lights-panel/powerLights.h +++ b/power-lights-panel/powerLights.h @@ -9,7 +9,7 @@ class powerLights SimVars* simVars; Aircraft loadedAircraft = UNDEFINED; bool airliner = false; - int bleedTest = 0; + int lightsTest = 0; bool apuMaster = false; bool apuStart = false; @@ -20,6 +20,8 @@ class powerLights int flapsDownVal = 20; int lastFlapsPos = -1; // 0 = up, 4 = full bool parkBrakeOn = true; + int prevSbParkBrake = -1; + int sbParkBrakeDelay = 0; // Hardware controls int battery1Control = -1; diff --git a/power-lights-panel/simvarDefs.cpp b/power-lights-panel/simvarDefs.cpp index 280e462..a52089f 100644 --- a/power-lights-panel/simvarDefs.cpp +++ b/power-lights-panel/simvarDefs.cpp @@ -1,7 +1,7 @@ #include #include "simvarDefs.h" -const char* versionString = "v2.0.2"; +const char* versionString = "v2.0.3"; const char* SimVarDefs[][2] = { // Vars for Jetbridge (must come first) @@ -33,6 +33,7 @@ const char* SimVarDefs[][2] = { { "SwitchBox Button 6", "jetbridge" }, { "SwitchBox Button 7", "jetbridge" }, { "SwitchBox Mode", "jetbridge" }, + { "SwitchBox Park Brake", "jetbridge" }, // Vars required for all panels (screensaver, aircraft identification etc.) { "Title", "string32" }, diff --git a/power-lights-panel/simvarDefs.h b/power-lights-panel/simvarDefs.h index bd06b86..0887cba 100644 --- a/power-lights-panel/simvarDefs.h +++ b/power-lights-panel/simvarDefs.h @@ -27,6 +27,7 @@ struct SimVars double sbEncoder[4]; // SwitchBox double sbButton[7]; // SwitchBox double sbMode; // SwitchBox + double sbParkBrake; // SwitchBox // Vars required for all panels (screensaver, aircraft identification etc.) char aircraft[32] = "\0";