Browse Source

Sub: Change gamepad controls for light brightness

mission-4.1.18
Jacob Walser 8 years ago committed by Andrew Tridgell
parent
commit
584171cf3c
  1. 74
      ArduSub/radio.cpp

74
ArduSub/radio.cpp

@ -144,53 +144,47 @@ void Sub::transform_manual_control_to_rc_override(int16_t x, int16_t y, int16_t
static int16_t mode; static int16_t mode;
static int16_t camTilt = 1500; static int16_t camTilt = 1500;
static int16_t lights = 1100; static int16_t lights = 1100;
static uint32_t lastLights; static uint32_t buttonDebounce;
static bool lightsBrighter = true;
// Button logic to arm/disarm motors (Start and back buttons)
if ( buttons & (1 << 4) ) {
init_arm_motors(true);
} else if ( buttons & (1 << 5) ) {
init_disarm_motors();
}
// Button logic to change camera tilt (D-pad up and down + left joystick click to center) // Debouncing timer
if ( buttons & (1 << 0) ) { if ( tnow_ms - buttonDebounce > 50 ) {
camTilt = constrain_float(camTilt+20,800,2200); buttonDebounce = tnow_ms;
} else if ( buttons & (1 << 1) ) {
camTilt = constrain_float(camTilt-20,800,2200);
} else if ( buttons & (1 << 6) ) {
camTilt = 1500; // Reset camera tilt
}
// Button logic for roll trim (D-pad left and right) // Button logic to arm/disarm motors (Start and back buttons)
if ( (buttons & ( 1 << 2 )) && rollTrim > -200 ) { if ( buttons & (1 << 4) ) {
rollTrim -= 10; init_arm_motors(true);
} else if ( (buttons & ( 1 << 3 )) && rollTrim < 200 ) { } else if ( buttons & (1 << 5) ) {
rollTrim += 10; init_disarm_motors();
} }
// Button logic for mode changes (B for stabilize, Y for altitude hold) // Button logic to change camera tilt (D-pad up and down + left joystick click to center)
if ( buttons & (1 << 14) ) { if ( buttons & (1 << 0) ) {
mode = 2000; camTilt = constrain_float(camTilt-30,800,2200);
} else if ( buttons & (1 << 12)) { } else if ( buttons & (1 << 1) ) {
mode = 1000; camTilt = constrain_float(camTilt+30,800,2200);
} } else if ( buttons & (1 << 6) ) {
camTilt = 1500; // Reset camera tilt
}
// Button logic for lights with cyclical dimming (right joystick click) // Button logic for roll trim (D-pad left and right)
if ( (buttons & (1 << 7)) && (tnow_ms - lastLights > 100) ) { if ( (buttons & ( 1 << 2 )) && rollTrim > -200 ) {
lastLights = tnow_ms; rollTrim -= 10;
} else if ( (buttons & ( 1 << 3 )) && rollTrim < 200 ) {
rollTrim += 10;
}
if ( lightsBrighter ) { // Button logic for mode changes (B for stabilize, Y for altitude hold)
lights += 200; if ( buttons & (1 << 14) ) {
} else { mode = 2000;
lights -= 200; } else if ( buttons & (1 << 12)) {
mode = 1000;
} }
if ( lights >= 1900 ) { // Button logic for lights with dimming (right bumper brighter, left bumper dimmer)
lightsBrighter = false; if ( buttons & (1 << 8) ) {
} else if ( lights <= 1100 ) { lights = constrain_float(lights-100,1100,1900);
lightsBrighter = true; } else if ( buttons & (1 << 9) ) {
lights = constrain_float(lights+100,1100,1900);
} }
} }

Loading…
Cancel
Save