Skip to content

Commit

Permalink
Add switchbox parking brake
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Vincent committed Sep 25, 2024
1 parent d991365 commit fefb3de
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion power-lights-panel/powerLights-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 29 additions & 6 deletions power-lights-panel/powerLights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -535,6 +540,7 @@ void powerLights::gpioParkBrakeInput()
globals.simVars->write(KEY_PARKING_BRAKE_SET, 0);
}
prevParkBrakeOffToggle = val;
return;
}

// Park brake on toggle
Expand All @@ -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;
}
}
}
4 changes: 3 additions & 1 deletion power-lights-panel/powerLights.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion power-lights-panel/simvarDefs.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <stdio.h>
#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)
Expand Down Expand Up @@ -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" },
Expand Down
1 change: 1 addition & 0 deletions power-lights-panel/simvarDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit fefb3de

Please sign in to comment.