From ff6af732db8e592eed3baf51e98d9e9e10d4bc39 Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Mon, 1 Apr 2024 23:18:12 -0500 Subject: [PATCH 01/20] New Sketch Throttle Controller and Inner Grip --- .gitmodules | 9 + .../4A9A1-THROTTLE_CONTROLLER.ino | 313 ++++++++++++++++++ .../4A9A1-THROTTLE_CONTROLLER/Makefile | 8 + .../4A9A1A1-THROTTLE_INNER_GRIP.ino | 154 +++++++++ .../4A9A1A1-THROTTLE_INNER_GRIP/Makefile | 8 + embedded/templates/OHSketchTemplate/Makefile | 2 +- libraries/Arduino-FOC | 1 + libraries/Arduino-FOC-drivers | 1 + libraries/Joystick_ESP32S2 | 1 + 9 files changed, 496 insertions(+), 1 deletion(-) create mode 100644 embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino create mode 100644 embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile create mode 100644 embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino create mode 100644 embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/Makefile create mode 160000 libraries/Arduino-FOC create mode 160000 libraries/Arduino-FOC-drivers create mode 160000 libraries/Joystick_ESP32S2 diff --git a/.gitmodules b/.gitmodules index 6c2d9ae..5086493 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,3 +25,12 @@ [submodule "libraries/ArduinoJoystickLibrary"] path = libraries/ArduinoJoystickLibrary url = https://github.com/MHeironimus/ArduinoJoystickLibrary.git +[submodule "libraries/Joystick_ESP32S2"] + path = libraries/Joystick_ESP32S2 + url = https://github.com/schnoog/Joystick_ESP32S2.git +[submodule "libraries/Arduino-FOC"] + path = libraries/Arduino-FOC + url = https://github.com/simplefoc/Arduino-FOC.git +[submodule "libraries/Arduino-FOC-drivers"] + path = libraries/Arduino-FOC-drivers + url = https://github.com/simplefoc/Arduino-FOC-drivers.git diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino new file mode 100644 index 0000000..0cab8d8 --- /dev/null +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino @@ -0,0 +1,313 @@ +/************************************************************************************** + * ____ _ _ _ + * / __ \ | | | | | | + * | | | |_ __ ___ _ __ | |__| | ___ _ __ _ __ ___| |_ + * | | | | '_ \ / _ \ '_ \| __ |/ _ \| '__| '_ \ / _ \ __| + * | |__| | |_) | __/ | | | | | | (_) | | | | | | __/ |_ + * \____/| .__/ \___|_| |_|_| |_|\___/|_| |_| |_|\___|\__| + * | | + * |_| + * ---------------------------------------------------------------------------------- + * Copyright 2016-2024 OpenHornet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---------------------------------------------------------------------------------- + * Note: All other portions of OpenHornet not within the 'OpenHornet-Software' + * GitHub repository is released under the Creative Commons Attribution - + * Non-Commercial - Share Alike License. (CC BY-NC-SA 4.0) + * ---------------------------------------------------------------------------------- + * This Project uses Doxygen as a documentation generator. + * Please use Doxygen capable comments. + **************************************************************************************/ + +/** + * @file 4A9A1-THROTTLE_CONTROLLER.ino + * @author Arribe + * @date 04.01.2024 + * @version u.0.0.1 + * @copyright Copyright 2016-2024 OpenHornet. Licensed under the Apache License, Version 2.0. + * @warning This sketch is based on a wiring diagram, and was not yet tested on hardware. The throttle solenoids weren't working. (Remove this line once tested on hardware and in system.) + * @brief Controls the THROTTLE QUADRANT. + * + * @details + * + * * **Reference Designator:** 4A9A1 + * * **Intended Board:** CONTROLLER_Throttle + * * **RS485 Bus Address:** NA + * + * ### Wiring diagram: + * PIN | Function + * --- | --- + * 12 | J2 OUTBD_CSx + * 5 | J3 INBD_CSy + * 40 | INBD_MAX_LIMIT + * 38 | INBD_IDLE_LIMIT + * 36 | OUTBD_MAX_LIMIT + * 34 | OUTBD_IDLE_LIMIT + * 21 | EXT_LTS + * 17 | RAID_FLIR + * 15 | ATC_ENGAGE + * 39 | MAX_SOL_SIG + * 37 | IDLE_SOL_SIG + * +* +* ## Hall Sensor Zero via #define SET_THROTTLE_ZERO +* It may be helpful to zero the hall sensors when both throttles are at ground idle position. +* If the Hall sensors are not zeroed out the reads my increase when advancing the throttles forward, and then loop around to a +* lower value which is confusing for the Window's game controller and its calibration utility. +* +* ## Disabling the max limit switches via #define DISABLE_MAX_LIMIT_SWITCHES 1 +* The max limit switches make running the window's game controller calibarion challenging, and prevents moving the throttles to max +* without pushing a 'button' on the controller advancing the calibarion to the next screen. +* +* ## Reverse External Light Switch Movement +* Reversing the external lights switch may be needed by some (like me) who inadvertently put the switch / wires on backwards. +* Gave an option in code to reverse instead of pulling the outer grip apart to fix physically. +* +*/ + +#define DISABLE_MAX_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used +#define DISABLE_IDLE_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used +//#define SET_THROTTLE_ZERO ///< Define to determine if code should allow the hall sensors to set its zero position based on initial position. +#define DISABLE_MAX_LIMIT_SWITCHES 1 ///< disables the max limit switches, change to 0 if you want them enabled, 1 is disabled. +#define REVERSE_EXT_LTS 0 ///< Reverses the read of the external lights switch, set to 0 or 1 if switch movement doesn't trigger in Window's game controller when switch toggle is forward + +#define DCSBIOS_DISABLE_SERVO ///< So the code will compile with an ESP32 +#define DCSBIOS_DEFAULT_SERIAL + +#include +#include "Joystick_ESP32S2.h" +#include "SimpleFOC.h" +#include "SimpleFOCDrivers.h" +#include "encoders/mt6835/MagneticSensorMT6835.h" +#include "DcsBios.h" + +// Define pins for DCS-BIOS per interconnect diagram. +#define OUTBD_CSX 12 ///< J2 OUTBD_CSx +#define INBD_CSY 5 ///< J3 INBD_CSy +#define INBD_MAX_LIMIT 40 ///< INBD_MAX_LIMIT +#define INBD_IDLE_LIMIT 38 ///< INBD_IDLE_LIMIT +#define OUTBD_MAX_LIMIT 36 ///< OUTBD_MAX_LIMIT +#define OUTBD_IDLE_LIMIT 34 ///< OUTBD_IDLE_LIMIT +#define EXT_LTS 21 ///< EXT_LTS +#define RAID_FLIR 17 ///< RAID_FLIR +#define ATC_ENGAGE 15 ///< ATC_ENGAGE +#define MAX_SOL_SIG 39 ///< MAX_SOL_SIG +#define IDLE_SOL_SIG 37 ///< IDLE_SOL_SIG + +//Declare variables for custom non-DCS Bios logic +bool wowLeft = false; ///< Weight-on-wheels for solenoid logic. +bool wowRight = false; ///< Weight-on-wheels for solenoid logic. +bool wowNose = false; ///< Weight-on-wheels for solenoid logic. +bool launchBarExtended = false; ///< launch bar used for Max solenoid logic. +bool arrestingHookUp = true; ///< hook up used for Max solenoid logic. + + +Joystick_ Joystick = Joystick_( + JOYSTICK_DEFAULT_REPORT_ID, + JOYSTICK_TYPE_JOYSTICK, + 18, + 0, + true, + true, + true, + true, + true, + false, + false, + false, + false, + false, + false); + +const bool testAutoSendMode = false; + +SPISettings myMT6835SPISettings(1000000, MT6835_BITORDER, SPI_MODE3); +MagneticSensorMT6835 outboardThrottle = MagneticSensorMT6835(OUTBD_CSX, myMT6835SPISettings); +MagneticSensorMT6835 inboardThrottle = MagneticSensorMT6835(INBD_CSY, myMT6835SPISettings); + + +int pins[7] = { OUTBD_MAX_LIMIT, OUTBD_IDLE_LIMIT, INBD_MAX_LIMIT, INBD_IDLE_LIMIT, EXT_LTS, RAID_FLIR, ATC_ENGAGE }; + +// DCSBios reads to save airplane state information. +void onExtWowLeftChange(unsigned int newValue) { + wowLeft = newValue; +} +DcsBios::IntegerBuffer extWowLeftBuffer(0x74d8, 0x0100, 8, onExtWowLeftChange); + +void onExtWowRightChange(unsigned int newValue) { + wowRight = newValue; +} +DcsBios::IntegerBuffer extWowRightBuffer(0x74d6, 0x8000, 15, onExtWowRightChange); + +void onExtWowNoseChange(unsigned int newValue) { + wowNose = newValue; +} +DcsBios::IntegerBuffer extWowNoseBuffer(0x74d6, 0x4000, 14, onExtWowNoseChange); + +void onHookLeverChange(unsigned int newValue) { + arrestingHookUp = newValue; // 1 is hook up +} +DcsBios::IntegerBuffer hookLeverBuffer(0x74a0, 0x0200, 9, onHookLeverChange); + +void onLaunchBarSwChange(unsigned int newValue) { + launchBarExtended = newValue; // 1 is extended +} +DcsBios::IntegerBuffer launchBarSwBuffer(0x7480, 0x2000, 13, onLaunchBarSwChange); + +/** +* Arduino Setup Function +* +* Arduino standard Setup Function. Code who should be executed +* only once at the programm start, belongs in this function. +* +* @note If SET_THROTTLE_ZERO defined the code will read the hall sensors' initial position at power on to set that as zero. +* If used ensure that the throttles are pulled back to the ground idle (not fuel-cut-off/min position). +* +* ### Flight Idle Detent Solenoid +* If weight-on-wheels is true, pull flight idle detent down to allow throttle movement to ground idle position. +* +* ### Afterburner Lockout Detent Solenoid +* If weight-on-wheels is true, and launch bar is extended or the hook is down then raise the afterburner +* lockout detent to prevent inadvertent selection of afterburner. Otherwise pull the afterburner lockout detent down. +* +* @note If DISABLE_MAX_SOL_SIG or DISABLE_IDLE_SOL_SIG are not defined the solenoids will be used based on the logic from DCS state. +* +* @todo When flight idle detent is fixed mechanically for more consistent usage, explore using the aircraft's g-load to simiulate high-G +* maneuvers causing the flight idle stop to retract and allow inadvertent selection of ground idle. +* +*/ +void setup() { + + // Run DCS Bios setup function + DcsBios::setup(); + + Wire.begin(SDA, SCL); + Serial.begin(115200); + + outboardThrottle.init(); + inboardThrottle.init(); + inboardThrottle.setRotationDirection(-1); // reverse hall sensor rotation so both throttles read as increasing when moving forward + +#ifdef SET_THROTTLE_ZERO + //throttle needs to be all the way back to ground idle when plugged into the computer to set the zero value. + outboardThrottle.setZeroFromCurrentPosition(); + inboardThrottle.setZeroFromCurrentPosition(); +#endif + + // set pinmode for the throttle controller's inputs. + for (int j = 0; j < 7; j++) { + pinMode(pins[j], INPUT_PULLUP); + } + + pinMode(IDLE_SOL_SIG, OUTPUT); + pinMode(MAX_SOL_SIG, OUTPUT); + + digitalWrite(IDLE_SOL_SIG, LOW); + digitalWrite(MAX_SOL_SIG, LOW); + + Joystick.setXAxisRange(0, 1024); // TDC X-axis + Joystick.setYAxisRange(0, 1024); // TDC Y-axis + Joystick.setZAxisRange(0, 1024); // Radar Elevation + Joystick.setRxAxisRange(0, 2048); // Outboard Throttle Arm + Joystick.setRyAxisRange(0, 2048); // Inboard Throttle Arm + Joystick.begin(); +} + +/** +* Arduino Loop Function +* +* Arduino standard Loop Function. Code who should be executed +* over and over in a loop, belongs in this function. +*/ +void loop() { + + //Run DCS Bios loop function + DcsBios::loop(); + + uint32_t temp; // temp value to hold the analog reads in preparation of doing logic. + + outboardThrottle.update(); // update the outboard hall sensor to prep for read. + temp = outboardThrottle.readRawAngle21(); // read outboard hall sensor + Joystick.setRxAxis(map(temp, 0, 707444, 0, 2048)); //0 and 707444 came from reading the Serial Monitor for the min/max values to then plug into this line. + // Uncomment the code below if you wish to pass the outboard throttle's raw values to the serial monitor + //Serial.print("outbThrottle: "); + //Serial.print(temp); + + inboardThrottle.update(); // update the inboard hall sensor to prep for read + temp = inboardThrottle.readRawAngle21(); // read inboard hall sensor + Joystick.setRyAxis(map(temp, 0, 707444, 0, 2048)); //0 and 707444 came from reading the Serial Monitor for the min/max values to then plug into this line. + // Uncomment the code below if you wish to pass the inboard throttle's raw values to the serial monitor + //Serial.print(" inbThrottle: "); + //Serial.print(valueY); + //Serial.print("\n"); + + // Read the pins and set the joystick's button state + for (int j = 0; j < 7; j++) { + if ((DISABLE_MAX_LIMIT_SWITCHES == 1) && ((j != 0) && (j != 2))) { // If the max throttle limit switches are disabled, skip the read + if ((REVERSE_EXT_LTS == 1) && (j == 5)) { // if REVERSE_EXT_LTS defined as 1 reverse the read value compared to the other pins + Joystick.setButton(j, digitalRead(pins[j])); + } else + Joystick.setButton(j, !digitalRead(pins[j])); + } + } + + int index = 0; // Initialize the index to keep track of which inner grip button we're reading + Wire.requestFrom(49, 17); // request inner grip pro-mini return current button state info + + while (Wire.available()) { // While something to read from the inner grip + if (index < 11) { // first 11 values are button presses + Joystick.setButton(index + 7, Wire.read()); // inner throttle's digital button reads, set as joystick button state + } + // Remaining Index values are inner grip analog reads + else if (index == 11) { // TDC X-axis + byte tempLow = Wire.read(); // read low byte + byte tempHi = Wire.read(); // read high byte + temp = (tempHi << 8) + tempLow; //rebuild the TDC X-axis value + Joystick.setXAxis(map(temp, 0, 65000, 0, 1024)); + + } else if (index == 12) { // TDC Y-axis + byte tempLow = Wire.read(); // read low byte + byte tempHi = Wire.read(); // read high byte + temp = (tempHi << 8) + tempLow; //rebuild the TDC Y-axis value + Joystick.setYAxis(map(temp, 0, 65000, 0, 1024)); + + } else if (index == 13) { + byte tempLow = Wire.read(); // read low byte + byte tempHi = Wire.read(); // read high byte + temp = (tempHi << 8) + tempLow; //rebuild the Antenna axis value + Joystick.setZAxis(map(temp, 754, 978, 0, 1024)); // mapped values determined by reading the retured elevation on the serial monitor + // enable the lines below to see the Elevation knob's analog read values. + //Serial.print(" Elevation: "); + //Serial.print((tempHi << 8) + tempLow); + //Serial.print("\n"); + } + index++; // increment the index for the next iteration through the while loop + } + +#ifndef DISABLE_IDLE_SOL_SIG + if (wowLeft == wowRight == wowNose == true) { + digitalWrite(IDLE_SOL_SIG, HIGH); + } else { + digitalWrite(IDLE_SOL_SIG, LOW); + } +#endif + +#ifndef DISABLE_MAX_SOL_SIG + if ((wowLeft == wowRight == wowNose == true) && ((launchBarExtended == true) || (arrestingHookUp == false))) { + digitalWrite(MAX_SOL_SIG, LOW); // With weight-on-wheels, if the lanuch bar is extended or the hook is down then raise afterburner lockout / detent to prevent inadvertent afterburner selection. + } else { + digitalWrite(MAX_SOL_SIG, HIGH); // Otherwise pull the afterburner lockout / detent. + } +#endif +} diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile new file mode 100644 index 0000000..91a9cef --- /dev/null +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile @@ -0,0 +1,8 @@ +# Any extra libraries included by this sketch (space separated) +LIBRARIES = Adafruit_NeoPixel Servo dcs-bios-arduino-library TCA9534 Wire ArduinoJoystickLibrary + +# Uncomment one of the following to choose the target board +# include $(ROOTDIR)/include/mega2560.mk +include $(ROOTDIR)/include/promicro.mk +# include $(ROOTDIR)/include/promini.mk +# include $(ROOTDIR)/include/s2mini.mk diff --git a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino new file mode 100644 index 0000000..6bbf250 --- /dev/null +++ b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino @@ -0,0 +1,154 @@ +/************************************************************************************** + * ____ _ _ _ + * / __ \ | | | | | | + * | | | |_ __ ___ _ __ | |__| | ___ _ __ _ __ ___| |_ + * | | | | '_ \ / _ \ '_ \| __ |/ _ \| '__| '_ \ / _ \ __| + * | |__| | |_) | __/ | | | | | | (_) | | | | | | __/ |_ + * \____/| .__/ \___|_| |_|_| |_|\___/|_| |_| |_|\___|\__| + * | | + * |_| + * ---------------------------------------------------------------------------------- + * Copyright 2016-2024 OpenHornet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---------------------------------------------------------------------------------- + * Note: All other portions of OpenHornet not within the 'OpenHornet-Software' + * GitHub repository is released under the Creative Commons Attribution - + * Non-Commercial - Share Alike License. (CC BY-NC-SA 4.0) + * ---------------------------------------------------------------------------------- + * This Project uses Doxygen as a documentation generator. + * Please use Doxygen capable comments. + **************************************************************************************/ + +/** + * @file 4A9A1A1-THROTTLE_INNER_GRIP.ino + * @author Arribe + * @date 04.01.2024 + * @version 0.0.1 + * @copyright Copyright 2016-2024 OpenHornet. Licensed under the Apache License, Version 2.0. + * @brief Controls the THROTTLE INNER GRIP + * + * @details + * + * * **Reference Designator:** 4A9A1A1 + * * **Intended Board:** THROTTLE_INNER_GRIP + * * **RS485 Bus Address:** NA + * + * ### Wiring diagram: + * PIN | Function + * --- | --- + * 2 | CAGE_UNCAGE + * 3 | SPEEDBREAK_RETRACT + * 4 | SPEEDBREAK_EXTEND + * 7 | COUNTERMEASURES_AFT + * 8 | COUNTERMEASURES_FWD + * 9 | PUSH - coms switch + * A3 | JOY_X + * A2 | JOY_Y + * A1 | JOY_SW + * A0 | ANTENNA_ELEVATION + * 13 | D - coms switch + * 12 | C - coms switch + * 11 | B - coms switch + * 10 | A - coms switch + * SCL | I2C_SCK + * SDA | I2C_DATA + * + */ + +#include + +// Define pins inner grip pro-mini +#define CAGE_UNCAGE 2 ///< CAGE_UNCAGE +#define SPEEDBREAK_RETRACT 3 ///< SPEEDBREAK_RETRACT +#define SPEEDBREAK_EXTEND 4 ///< SPEEDBREAK_EXTEND +#define COUNTERMEASURES_AFT 7 ///< COUNTERMEASURES_AFT +#define COUNTERMEASURES_FWD 8 ///< COUNTERMEASURES_FWD +#define PUSH 9 ///< PUSH - coms switch +#define JOY_X A3 ///< JOY_X +#define JOY_Y A2 ///< JOY_Y +#define JOY_SW A1 ///< JOY_SW +#define ANTENNA_ELEVATION A0 ///< ANTENNA_ELEVATION +#define D 13 ///< D - coms switch +#define C 12 ///< C - coms switch +#define B 11 ///< B - coms switch +#define A 10 ///< A - coms switch + +/// array of button pins for looping through to get button state +int buttonMap[11] = { CAGE_UNCAGE, SPEEDBREAK_RETRACT, SPEEDBREAK_EXTEND, COUNTERMEASURES_AFT, COUNTERMEASURES_FWD, D, C, B, A, PUSH, JOY_SW }; + +/** +* Arduino Setup Function +* +* Arduino standard Setup Function. Code who should be executed +* only once at the programm start, belongs in this function. +*/ +void setup() { + Wire.begin(49); // join i2c bus with address #49 + Wire.onRequest(requestEvent); // register requestEvent + + + pinMode(CAGE_UNCAGE, INPUT_PULLUP); + pinMode(SPEEDBREAK_RETRACT, INPUT_PULLUP); + pinMode(SPEEDBREAK_EXTEND, INPUT_PULLUP); + pinMode(COUNTERMEASURES_AFT, INPUT_PULLUP); + pinMode(COUNTERMEASURES_FWD, INPUT_PULLUP); + pinMode(ANTENNA_ELEVATION, INPUT_PULLUP); + pinMode(D, INPUT_PULLUP); + pinMode(C, INPUT_PULLUP); + pinMode(B, INPUT_PULLUP); + pinMode(A, INPUT_PULLUP); + pinMode(PUSH, INPUT_PULLUP); + pinMode(JOY_SW, INPUT_PULLUP); + pinMode(JOY_X, INPUT_PULLUP); + pinMode(JOY_Y, INPUT_PULLUP); +} + +/** +* Arduino Loop Function +* +* Arduino standard Loop Function. Code who should be executed +* over and over in a loop, belongs in this function. +* +* @note The loop is empty +*/ +void loop() { +} + +/** +* Function that returns the sate of the inboard throttle grip controls when prompted by the throttle controller. +* Writes each button / analog read back to the throttle controller in the same order each time. +* The Wire library only sends one byte at a time. The analog read values need to be split into low and high bytes +* so the controller can properly reassemble the 2 byte numeric value. +* +* @note There is minimal logic for the inner grip pro-mini given the extra steps for reprogramming. +*/ + +void requestEvent() { + /// Loop through all of the digital reads and write value to the controller. + for (int i = 0; i < 11; i++) { + Wire.write(!digitalRead(buttonMap[i])); //write state of buttons + } + + int temp = analogRead(JOY_X); // get the analog read of the TDC X azis. + Wire.write(lowByte(temp)); // write out the low byte to the controller + Wire.write(highByte(temp)); // write out the high byte to the controller + + temp = analogRead(JOY_Y); // get the analog read of the TDC Y azis. + Wire.write(lowByte(temp)); // write out the low byte to the controller + Wire.write(highByte(temp)); // write out the high byte to the controller + + temp = analogRead(ANTENNA_ELEVATION); // get the analog read of the Antenna Elevation azis. + Wire.write(lowByte(temp)); // write out the low byte to the controller + Wire.write(highByte(temp)); // write out the high byte to the controller +} diff --git a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/Makefile b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/Makefile new file mode 100644 index 0000000..1adbeef --- /dev/null +++ b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/Makefile @@ -0,0 +1,8 @@ +# Any extra libraries included by this sketch (space separated) +LIBRARIES = Adafruit_NeoPixel Servo dcs-bios-arduino-library TCA9534 Wire ArduinoJoystickLibrary + +# Uncomment one of the following to choose the target board +# include $(ROOTDIR)/include/mega2560.mk +# include $(ROOTDIR)/include/promicro.mk +include $(ROOTDIR)/include/promini.mk +# include $(ROOTDIR)/include/s2mini.mk diff --git a/embedded/templates/OHSketchTemplate/Makefile b/embedded/templates/OHSketchTemplate/Makefile index 91a9cef..905b06b 100644 --- a/embedded/templates/OHSketchTemplate/Makefile +++ b/embedded/templates/OHSketchTemplate/Makefile @@ -1,5 +1,5 @@ # Any extra libraries included by this sketch (space separated) -LIBRARIES = Adafruit_NeoPixel Servo dcs-bios-arduino-library TCA9534 Wire ArduinoJoystickLibrary +LIBRARIES = Adafruit_NeoPixel Servo dcs-bios-arduino-library TCA9534 Wire ArduinoJoystickLibrary Stepper Joystick_ESP32S2 Arduino-FOC Arduino-FOC-drivers # Uncomment one of the following to choose the target board # include $(ROOTDIR)/include/mega2560.mk diff --git a/libraries/Arduino-FOC b/libraries/Arduino-FOC new file mode 160000 index 0000000..6eed7b0 --- /dev/null +++ b/libraries/Arduino-FOC @@ -0,0 +1 @@ +Subproject commit 6eed7b00c9bc1e9f7ea7984aa02a9f7ea98db19b diff --git a/libraries/Arduino-FOC-drivers b/libraries/Arduino-FOC-drivers new file mode 160000 index 0000000..bfd07bd --- /dev/null +++ b/libraries/Arduino-FOC-drivers @@ -0,0 +1 @@ +Subproject commit bfd07bd17eadcdae43ba0a85d74fe07ed04e26fc diff --git a/libraries/Joystick_ESP32S2 b/libraries/Joystick_ESP32S2 new file mode 160000 index 0000000..6baeb23 --- /dev/null +++ b/libraries/Joystick_ESP32S2 @@ -0,0 +1 @@ +Subproject commit 6baeb23662d6ee0973470c217f8f49e3f3ef5556 From e2cd5b6268156535005ba87031fcd84914fcf6be Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Mon, 1 Apr 2024 23:28:23 -0500 Subject: [PATCH 02/20] Update Makefile --- .../OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile index 91a9cef..7350827 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile @@ -1,8 +1,8 @@ # Any extra libraries included by this sketch (space separated) -LIBRARIES = Adafruit_NeoPixel Servo dcs-bios-arduino-library TCA9534 Wire ArduinoJoystickLibrary +LIBRARIES = Adafruit_NeoPixel Servo dcs-bios-arduino-library TCA9534 Wire ArduinoJoystickLibrary Stepper Joystick_ESP32S2 Arduino-FOC Arduino-FOC-drivers # Uncomment one of the following to choose the target board # include $(ROOTDIR)/include/mega2560.mk -include $(ROOTDIR)/include/promicro.mk +# include $(ROOTDIR)/include/promicro.mk # include $(ROOTDIR)/include/promini.mk -# include $(ROOTDIR)/include/s2mini.mk +include $(ROOTDIR)/include/s2mini.mk From 296e4f021d172b8f87b8d8ff4defd22404fe1cc9 Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Mon, 1 Apr 2024 23:42:42 -0500 Subject: [PATCH 03/20] Update 4A9A1-THROTTLE_CONTROLLER.ino --- .../4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino index 0cab8d8..afa4f90 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino @@ -86,11 +86,11 @@ #define DCSBIOS_DEFAULT_SERIAL #include -#include "Joystick_ESP32S2.h" #include "SimpleFOC.h" #include "SimpleFOCDrivers.h" #include "encoders/mt6835/MagneticSensorMT6835.h" #include "DcsBios.h" +#include "Joystick_ESP32S2.h" // Define pins for DCS-BIOS per interconnect diagram. #define OUTBD_CSX 12 ///< J2 OUTBD_CSx From 063ac348d4b02d75fd8fc63cf463cfd714a5a601 Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:01:34 -0500 Subject: [PATCH 04/20] Update 4A9A1-THROTTLE_CONTROLLER.ino --- .../4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino index afa4f90..d3717a1 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino @@ -86,6 +86,7 @@ #define DCSBIOS_DEFAULT_SERIAL #include +#include #include "SimpleFOC.h" #include "SimpleFOCDrivers.h" #include "encoders/mt6835/MagneticSensorMT6835.h" From bbcdfe4c576650b64fae60fb179ab666c5eee39b Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:38:38 -0500 Subject: [PATCH 05/20] Update 4A9A1A1-THROTTLE_INNER_GRIP.ino --- .../4A9A1A1-THROTTLE_INNER_GRIP.ino | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino index 6bbf250..aa53161 100644 --- a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino +++ b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino @@ -131,24 +131,36 @@ void loop() { * The Wire library only sends one byte at a time. The analog read values need to be split into low and high bytes * so the controller can properly reassemble the 2 byte numeric value. * +* Passes inner grip reads to throttle controller in this order: +* CAGE_UNCAGE, SPEEDBREAK_RETRACT, SPEEDBREAK_EXTEND, COUNTERMEASURES_AFT, COUNTERMEASURES_FWD, D, C, B, A, PUSH, JOY_SW, +* JOY_X, JOY_Y, ANTENNA_ELEVATION +* * @note There is minimal logic for the inner grip pro-mini given the extra steps for reprogramming. */ void requestEvent() { - /// Loop through all of the digital reads and write value to the controller. - for (int i = 0; i < 11; i++) { - Wire.write(!digitalRead(buttonMap[i])); //write state of buttons - } + + Wire.write(!digitalRead(CAGE_UNCAGE)); + Wire.write(!digitalRead(SPEEDBREAK_RETRACT)); + Wire.write(!digitalRead(SPEEDBREAK_EXTEND)); + Wire.write(!digitalRead(COUNTERMEASURES_AFT)); + Wire.write(!digitalRead(COUNTERMEASURES_FWD)); + Wire.write(!digitalRead(D)); + Wire.write(!digitalRead(C)); + Wire.write(!digitalRead(B)); + Wire.write(!digitalRead(A)); + Wire.write(!digitalRead(PUSH)); + Wire.write(!digitalRead(JOY_SW)); int temp = analogRead(JOY_X); // get the analog read of the TDC X azis. - Wire.write(lowByte(temp)); // write out the low byte to the controller - Wire.write(highByte(temp)); // write out the high byte to the controller + Wire.write(lowByte(temp)); // write out the low byte to the controller + Wire.write(highByte(temp)); // write out the high byte to the controller - temp = analogRead(JOY_Y); // get the analog read of the TDC Y azis. - Wire.write(lowByte(temp)); // write out the low byte to the controller - Wire.write(highByte(temp)); // write out the high byte to the controller + temp = analogRead(JOY_Y); // get the analog read of the TDC Y azis. + Wire.write(lowByte(temp)); // write out the low byte to the controller + Wire.write(highByte(temp)); // write out the high byte to the controller - temp = analogRead(ANTENNA_ELEVATION); // get the analog read of the Antenna Elevation azis. - Wire.write(lowByte(temp)); // write out the low byte to the controller - Wire.write(highByte(temp)); // write out the high byte to the controller + temp = analogRead(ANTENNA_ELEVATION); // get the analog read of the Antenna Elevation azis. + Wire.write(lowByte(temp)); // write out the low byte to the controller + Wire.write(highByte(temp)); // write out the high byte to the controller } From 79f94c59bc672338316bd0f140f88577babf51e0 Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:40:39 -0500 Subject: [PATCH 06/20] Update 4A9A1A1-THROTTLE_INNER_GRIP.ino --- .../4A9A1A1-THROTTLE_INNER_GRIP.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino index aa53161..ecb3bf6 100644 --- a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino +++ b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino @@ -92,6 +92,9 @@ int buttonMap[11] = { CAGE_UNCAGE, SPEEDBREAK_RETRACT, SPEEDBREAK_EXTEND, COUNTE * * Arduino standard Setup Function. Code who should be executed * only once at the programm start, belongs in this function. +* +* Joins I2C bus with address #49, registering requestEvent() +* */ void setup() { Wire.begin(49); // join i2c bus with address #49 From f6014b23939e18465c8254d4b06d90c0096c1cbb Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Tue, 2 Apr 2024 09:18:34 -0500 Subject: [PATCH 07/20] Update 4A9A1A1-THROTTLE_INNER_GRIP.ino --- .../4A9A1A1-THROTTLE_INNER_GRIP.ino | 3 --- 1 file changed, 3 deletions(-) diff --git a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino index ecb3bf6..4de5fda 100644 --- a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino +++ b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino @@ -84,9 +84,6 @@ #define B 11 ///< B - coms switch #define A 10 ///< A - coms switch -/// array of button pins for looping through to get button state -int buttonMap[11] = { CAGE_UNCAGE, SPEEDBREAK_RETRACT, SPEEDBREAK_EXTEND, COUNTERMEASURES_AFT, COUNTERMEASURES_FWD, D, C, B, A, PUSH, JOY_SW }; - /** * Arduino Setup Function * From 8a68dce7efdf0e07443b8997b940db5857473984 Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:04:33 -0500 Subject: [PATCH 08/20] refactored based on feed back, and worked through the mapped values limitations. --- .../4A9A1-THROTTLE_CONTROLLER.ino | 145 +++++++++++++----- .../4A9A1A1-THROTTLE_INNER_GRIP.ino | 2 + 2 files changed, 106 insertions(+), 41 deletions(-) diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino index d3717a1..e9bf683 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino @@ -41,6 +41,8 @@ * * @details * + * @attention Uses Simple FOC libraries with license avialable here: https://github.com/simplefoc/Arduino-FOC/blob/master/LICENSE + * * * **Reference Designator:** 4A9A1 * * **Intended Board:** CONTROLLER_Throttle * * **RS485 Bus Address:** NA @@ -78,18 +80,17 @@ #define DISABLE_MAX_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used #define DISABLE_IDLE_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used -//#define SET_THROTTLE_ZERO ///< Define to determine if code should allow the hall sensors to set its zero position based on initial position. -#define DISABLE_MAX_LIMIT_SWITCHES 1 ///< disables the max limit switches, change to 0 if you want them enabled, 1 is disabled. -#define REVERSE_EXT_LTS 0 ///< Reverses the read of the external lights switch, set to 0 or 1 if switch movement doesn't trigger in Window's game controller when switch toggle is forward +#define SET_THROTTLE_ZERO ///< Define to determine if code should allow the hall sensors to set its zero position based on initial position +#define DISABLE_MAX_LIMIT_SWITCHES ///< disables the max limit switches, comment out line if the max limit switches should be used #define DCSBIOS_DISABLE_SERVO ///< So the code will compile with an ESP32 #define DCSBIOS_DEFAULT_SERIAL #include #include -#include "SimpleFOC.h" -#include "SimpleFOCDrivers.h" -#include "encoders/mt6835/MagneticSensorMT6835.h" +#include "SimpleFOC.h" // https://github.com/simplefoc/Arduino-FOC/blob/master/LICENSE +#include "SimpleFOCDrivers.h" // https://github.com/simplefoc/Arduino-FOC/blob/master/LICENSE +#include "encoders/mt6835/MagneticSensorMT6835.h" // https://github.com/simplefoc/Arduino-FOC/blob/master/LICENSE #include "DcsBios.h" #include "Joystick_ESP32S2.h" @@ -103,8 +104,29 @@ #define EXT_LTS 21 ///< EXT_LTS #define RAID_FLIR 17 ///< RAID_FLIR #define ATC_ENGAGE 15 ///< ATC_ENGAGE -#define MAX_SOL_SIG 39 ///< MAX_SOL_SIG -#define IDLE_SOL_SIG 37 ///< IDLE_SOL_SIG +#define MAX_SOL_SIG 39 ///< MAX_SOL_SIG +#define IDLE_SOL_SIG 37 ///< IDLE_SOL_SIG + +/** +* Inner grip control with index +* CAGE_UNCAGE, SPEEDBREAK_RETRACT, SPEEDBREAK_EXTEND, COUNTERMEASURES_AFT, COUNTERMEASURES_FWD, D, C, B, A, PUSH, JOY_SW, JOY_X, JOY_Y, ANTENNA_ELEVATION +* +*/ +#define CAGE_UNCAGE 0 +#define SPEEDBREAK_RETRACT 1 +#define SPEEDBREAK_EXTEND 2 +#define COUNTERMEASURES_AFT 3 +#define COUNTERMEASURES_FWD 4 +#define D 5 +#define C 6 +#define B 7 +#define A 8 +#define PUSH 9 +#define JOY_SW 10 +#define JOY_X 11 +#define JOY_Y 12 +#define ANTENNA_ELEVATION 13 + //Declare variables for custom non-DCS Bios logic bool wowLeft = false; ///< Weight-on-wheels for solenoid logic. @@ -137,9 +159,6 @@ SPISettings myMT6835SPISettings(1000000, MT6835_BITORDER, SPI_MODE3); MagneticSensorMT6835 outboardThrottle = MagneticSensorMT6835(OUTBD_CSX, myMT6835SPISettings); MagneticSensorMT6835 inboardThrottle = MagneticSensorMT6835(INBD_CSY, myMT6835SPISettings); - -int pins[7] = { OUTBD_MAX_LIMIT, OUTBD_IDLE_LIMIT, INBD_MAX_LIMIT, INBD_IDLE_LIMIT, EXT_LTS, RAID_FLIR, ATC_ENGAGE }; - // DCSBios reads to save airplane state information. void onExtWowLeftChange(unsigned int newValue) { wowLeft = newValue; @@ -170,8 +189,8 @@ DcsBios::IntegerBuffer launchBarSwBuffer(0x7480, 0x2000, 13, onLaunchBarSwChange * Arduino Setup Function * * Arduino standard Setup Function. Code who should be executed -* only once at the programm start, belongs in this function. -* +* only once at the program start, belongs in this function. +* * @note If SET_THROTTLE_ZERO defined the code will read the hall sensors' initial position at power on to set that as zero. * If used ensure that the throttles are pulled back to the ground idle (not fuel-cut-off/min position). * @@ -206,10 +225,13 @@ void setup() { inboardThrottle.setZeroFromCurrentPosition(); #endif - // set pinmode for the throttle controller's inputs. - for (int j = 0; j < 7; j++) { - pinMode(pins[j], INPUT_PULLUP); - } + pinMode(OUTBD_MAX_LIMIT, INPUT_PULLUP); + pinMode(OUTBD_IDLE_LIMIT, INPUT_PULLUP); + pinMode(INBD_MAX_LIMIT, INPUT_PULLUP); + pinMode(INBD_IDLE_LIMIT, INPUT_PULLUP); + pinMode(EXT_LTS, INPUT_PULLUP); + pinMode(RAID_FLIR, INPUT_PULLUP); + pinMode(ATC_ENGAGE, INPUT_PULLUP); pinMode(IDLE_SOL_SIG, OUTPUT); pinMode(MAX_SOL_SIG, OUTPUT); @@ -217,11 +239,11 @@ void setup() { digitalWrite(IDLE_SOL_SIG, LOW); digitalWrite(MAX_SOL_SIG, LOW); - Joystick.setXAxisRange(0, 1024); // TDC X-axis - Joystick.setYAxisRange(0, 1024); // TDC Y-axis - Joystick.setZAxisRange(0, 1024); // Radar Elevation - Joystick.setRxAxisRange(0, 2048); // Outboard Throttle Arm - Joystick.setRyAxisRange(0, 2048); // Inboard Throttle Arm + Joystick.setXAxisRange(0, 1024); // TDC X-axis + Joystick.setYAxisRange(0, 1024); // TDC Y-axis + Joystick.setZAxisRange(0, 1024); // Radar Elevation + Joystick.setRxAxisRange(0, 65535); // Outboard Throttle Arm + Joystick.setRyAxisRange(0, 65535); // Inboard Throttle Arm Joystick.begin(); } @@ -230,6 +252,25 @@ void setup() { * * Arduino standard Loop Function. Code who should be executed * over and over in a loop, belongs in this function. +* +* @attention To setup the throttle reads, uncomment the serial print lines in the loop section. +* Then open a serial monitor to observe the min and max values for the outboard and inboard throttles. +* Set the 3rd parametr (max input) of the map function to be at least as large if not a little larger than the observed max values. +* If the max value isn't set high enough the values can loop back around to 0 prior to throttle advancing all the way forward. +* Windows game controller calibration may be used to adjust the upper and lower bounds as long as the mapped values don't loop back to 0. +* +* @todo If it's determined that users won't have to tweak the mapped value maxes, +* remove the temp reads for the hall sensors and combine the outboard and inboard throttle lines like: +* +* `temp = outboardThrottle.readRawAngle21(); // read outboard hall sensor` \n +* `Joystick.setRxAxis(mapHallSensor(temp, 0, 750000, 0, 65535));` +* +* Into one line: +* `Joystick.setRxAxis(mapHallSensor(outboardThrottle.readRawAngle21(), 0, 750000, 0, 65535));` +* +* @note Inner grip values sent to throttle controller in this order: +* CAGE_UNCAGE, SPEEDBREAK_RETRACT, SPEEDBREAK_EXTEND, COUNTERMEASURES_AFT, COUNTERMEASURES_FWD, D, C, B, A, PUSH, JOY_SW, +* JOY_X, JOY_Y, ANTENNA_ELEVATION */ void loop() { @@ -240,50 +281,54 @@ void loop() { outboardThrottle.update(); // update the outboard hall sensor to prep for read. temp = outboardThrottle.readRawAngle21(); // read outboard hall sensor - Joystick.setRxAxis(map(temp, 0, 707444, 0, 2048)); //0 and 707444 came from reading the Serial Monitor for the min/max values to then plug into this line. + Joystick.setRxAxis(mapHallSensor(temp, 0, 750000, 0, 65535)); //0 and 750000 came from reading the Serial Monitor for the min/max values to then plug into this line. // Uncomment the code below if you wish to pass the outboard throttle's raw values to the serial monitor //Serial.print("outbThrottle: "); //Serial.print(temp); inboardThrottle.update(); // update the inboard hall sensor to prep for read temp = inboardThrottle.readRawAngle21(); // read inboard hall sensor - Joystick.setRyAxis(map(temp, 0, 707444, 0, 2048)); //0 and 707444 came from reading the Serial Monitor for the min/max values to then plug into this line. + Joystick.setRyAxis(mapHallSensor(temp, 0, 750000, 0, 65535)); //0 and 740000 came from reading the Serial Monitor for the min/max values to then plug into this line. // Uncomment the code below if you wish to pass the inboard throttle's raw values to the serial monitor //Serial.print(" inbThrottle: "); - //Serial.print(valueY); + //Serial.print(temp); //Serial.print("\n"); - // Read the pins and set the joystick's button state - for (int j = 0; j < 7; j++) { - if ((DISABLE_MAX_LIMIT_SWITCHES == 1) && ((j != 0) && (j != 2))) { // If the max throttle limit switches are disabled, skip the read - if ((REVERSE_EXT_LTS == 1) && (j == 5)) { // if REVERSE_EXT_LTS defined as 1 reverse the read value compared to the other pins - Joystick.setButton(j, digitalRead(pins[j])); - } else - Joystick.setButton(j, !digitalRead(pins[j])); - } - } + // determine if max limit switches are included or not + #ifndef DISABLE_MAX_LIMIT_SWITCHES + Joystick.setButton(0, !digitalRead(OUTBD_MAX_LIMIT)); + Joystick.setButton(1, !digitalRead(INBD_MAX_LIMIT)); + #endif + + Joystick.setButton(2, !digitalRead(OUTBD_IDLE_LIMIT)); + Joystick.setButton(3, !digitalRead(INBD_IDLE_LIMIT)); + Joystick.setButton(4, !digitalRead(EXT_LTS)); + Joystick.setButton(5, !digitalRead(RAID_FLIR)); + Joystick.setButton(6, !digitalRead(ATC_ENGAGE)); + + int index = 0; // Initialize the index to keep track of which inner grip button we're reading + Wire.requestFrom(49, 17); // request inner grip pro-mini return current button state info - int index = 0; // Initialize the index to keep track of which inner grip button we're reading - Wire.requestFrom(49, 17); // request inner grip pro-mini return current button state info - while (Wire.available()) { // While something to read from the inner grip - if (index < 11) { // first 11 values are button presses + + while (Wire.available()) { // While something to read from the inner grip + if (index < JOY_X) { // The first sets of values are button presses until we get to axis values Joystick.setButton(index + 7, Wire.read()); // inner throttle's digital button reads, set as joystick button state } // Remaining Index values are inner grip analog reads - else if (index == 11) { // TDC X-axis + else if (index == JOY_X) { // TDC X-axis byte tempLow = Wire.read(); // read low byte byte tempHi = Wire.read(); // read high byte temp = (tempHi << 8) + tempLow; //rebuild the TDC X-axis value Joystick.setXAxis(map(temp, 0, 65000, 0, 1024)); - } else if (index == 12) { // TDC Y-axis + } else if (index == JOY_Y) { // TDC Y-axis byte tempLow = Wire.read(); // read low byte byte tempHi = Wire.read(); // read high byte temp = (tempHi << 8) + tempLow; //rebuild the TDC Y-axis value Joystick.setYAxis(map(temp, 0, 65000, 0, 1024)); - } else if (index == 13) { + } else if (index == ANTENNA_ELEVATION) { byte tempLow = Wire.read(); // read low byte byte tempHi = Wire.read(); // read high byte temp = (tempHi << 8) + tempLow; //rebuild the Antenna axis value @@ -312,3 +357,21 @@ void loop() { } #endif } + +/** +* Rewrite of the Arduino map function to set inputs and values used to be unsigned long long +* The standard map function was overflowing back to negative values when the mapped values reached 2800. +* +*/ + +long mapHallSensor(unsigned long long x, unsigned long long in_min, unsigned long long in_max, unsigned long long out_min, unsigned long long out_max) { + const unsigned long long run = in_max - in_min; + if(run == 0){ + log_e("map(): Invalid input range, min == max"); + return -1; // AVR returns -1, SAM returns 0 + } + const unsigned long long rise = out_max - out_min; + const unsigned long long delta = x - in_min; + return (delta * rise) / run + out_min; +} + diff --git a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino index 4de5fda..5c5eab3 100644 --- a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino +++ b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino @@ -92,6 +92,8 @@ * * Joins I2C bus with address #49, registering requestEvent() * +* @todo Add error handling as needed. +* */ void setup() { Wire.begin(49); // join i2c bus with address #49 From 2500cb62d094e3caf2adb951e2af04237eef271f Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:06:46 -0500 Subject: [PATCH 09/20] Update 4A9A1-THROTTLE_CONTROLLER.ino --- .../4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino index e9bf683..e0d2edd 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino @@ -43,6 +43,8 @@ * * @attention Uses Simple FOC libraries with license avialable here: https://github.com/simplefoc/Arduino-FOC/blob/master/LICENSE * + * @todo Extract just the code for MT6935 hall sensors from the Simple FOC library. + * * * **Reference Designator:** 4A9A1 * * **Intended Board:** CONTROLLER_Throttle * * **RS485 Bus Address:** NA From 375b2c67762c5bd69c26a8f56b803c6ea211bf2a Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:10:09 -0500 Subject: [PATCH 10/20] Update 4A9A1-THROTTLE_CONTROLLER.ino --- .../4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino index e0d2edd..ec271ee 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino @@ -42,6 +42,7 @@ * @details * * @attention Uses Simple FOC libraries with license avialable here: https://github.com/simplefoc/Arduino-FOC/blob/master/LICENSE + * @todo Review Simple FOC library MIT copyright for compatibility. Update copy right notice above as needed for the usage as a git-submodule. * * @todo Extract just the code for MT6935 hall sensors from the Simple FOC library. * From 33fce486c3b6c24099dcf75964efd426af7dfa2c Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:27:36 -0500 Subject: [PATCH 11/20] Update 4A9A1-THROTTLE_CONTROLLER.ino --- .../4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino index ec271ee..0a16f47 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino @@ -68,7 +68,7 @@ * * ## Hall Sensor Zero via #define SET_THROTTLE_ZERO * It may be helpful to zero the hall sensors when both throttles are at ground idle position. -* If the Hall sensors are not zeroed out the reads my increase when advancing the throttles forward, and then loop around to a +* If the Hall sensors are not zeroed out the reads may increase when advancing the throttles forward, and then loop around to a * lower value which is confusing for the Window's game controller and its calibration utility. * * ## Disabling the max limit switches via #define DISABLE_MAX_LIMIT_SWITCHES 1 From a83a43c82e058004b11b79e433b8496bcd63c0f0 Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Wed, 3 Apr 2024 21:56:58 -0500 Subject: [PATCH 12/20] testing adding the Arduino library as a submodule Trying to fix the CI compile issue with for the SPI.h include on SimpleFOC. --- .gitmodules | 3 + .../4A9A1-THROTTLE_CONTROLLER.ino | 141 +++++++++++------- libraries/ArduinoCore-avr | 1 + 3 files changed, 90 insertions(+), 55 deletions(-) create mode 160000 libraries/ArduinoCore-avr diff --git a/.gitmodules b/.gitmodules index 5086493..d42ecae 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,3 +34,6 @@ [submodule "libraries/Arduino-FOC-drivers"] path = libraries/Arduino-FOC-drivers url = https://github.com/simplefoc/Arduino-FOC-drivers.git +[submodule "libraries/ArduinoCore-avr"] + path = libraries/ArduinoCore-avr + url = https://github.com/arduino/ArduinoCore-avr diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino index 0a16f47..9e6f055 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino @@ -81,10 +81,10 @@ * */ -#define DISABLE_MAX_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used -#define DISABLE_IDLE_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used +#define DISABLE_MAX_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used +#define DISABLE_IDLE_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used #define SET_THROTTLE_ZERO ///< Define to determine if code should allow the hall sensors to set its zero position based on initial position -#define DISABLE_MAX_LIMIT_SWITCHES ///< disables the max limit switches, comment out line if the max limit switches should be used +//#define DISABLE_MAX_LIMIT_SWITCHES ///< disables the max limit switches, comment out line if the max limit switches should be used #define DCSBIOS_DISABLE_SERVO ///< So the code will compile with an ESP32 #define DCSBIOS_DEFAULT_SERIAL @@ -242,9 +242,9 @@ void setup() { digitalWrite(IDLE_SOL_SIG, LOW); digitalWrite(MAX_SOL_SIG, LOW); - Joystick.setXAxisRange(0, 1024); // TDC X-axis - Joystick.setYAxisRange(0, 1024); // TDC Y-axis - Joystick.setZAxisRange(0, 1024); // Radar Elevation + Joystick.setXAxisRange(0, 1024); // TDC X-axis + Joystick.setYAxisRange(0, 1024); // TDC Y-axis + Joystick.setZAxisRange(0, 1024); // Radar Elevation Joystick.setRxAxisRange(0, 65535); // Outboard Throttle Arm Joystick.setRyAxisRange(0, 65535); // Inboard Throttle Arm Joystick.begin(); @@ -282,26 +282,26 @@ void loop() { uint32_t temp; // temp value to hold the analog reads in preparation of doing logic. - outboardThrottle.update(); // update the outboard hall sensor to prep for read. - temp = outboardThrottle.readRawAngle21(); // read outboard hall sensor + outboardThrottle.update(); // update the outboard hall sensor to prep for read. + temp = outboardThrottle.readRawAngle21(); // read outboard hall sensor Joystick.setRxAxis(mapHallSensor(temp, 0, 750000, 0, 65535)); //0 and 750000 came from reading the Serial Monitor for the min/max values to then plug into this line. // Uncomment the code below if you wish to pass the outboard throttle's raw values to the serial monitor //Serial.print("outbThrottle: "); //Serial.print(temp); - inboardThrottle.update(); // update the inboard hall sensor to prep for read - temp = inboardThrottle.readRawAngle21(); // read inboard hall sensor + inboardThrottle.update(); // update the inboard hall sensor to prep for read + temp = inboardThrottle.readRawAngle21(); // read inboard hall sensor Joystick.setRyAxis(mapHallSensor(temp, 0, 750000, 0, 65535)); //0 and 740000 came from reading the Serial Monitor for the min/max values to then plug into this line. - // Uncomment the code below if you wish to pass the inboard throttle's raw values to the serial monitor - //Serial.print(" inbThrottle: "); - //Serial.print(temp); - //Serial.print("\n"); +// Uncomment the code below if you wish to pass the inboard throttle's raw values to the serial monitor +//Serial.print(" inbThrottle: "); +//Serial.print(temp); +//Serial.print("\n"); - // determine if max limit switches are included or not - #ifndef DISABLE_MAX_LIMIT_SWITCHES +// determine if max limit switches are included or not +#ifndef DISABLE_MAX_LIMIT_SWITCHES Joystick.setButton(0, !digitalRead(OUTBD_MAX_LIMIT)); Joystick.setButton(1, !digitalRead(INBD_MAX_LIMIT)); - #endif +#endif Joystick.setButton(2, !digitalRead(OUTBD_IDLE_LIMIT)); Joystick.setButton(3, !digitalRead(INBD_IDLE_LIMIT)); @@ -309,37 +309,69 @@ void loop() { Joystick.setButton(5, !digitalRead(RAID_FLIR)); Joystick.setButton(6, !digitalRead(ATC_ENGAGE)); - int index = 0; // Initialize the index to keep track of which inner grip button we're reading - Wire.requestFrom(49, 17); // request inner grip pro-mini return current button state info - + int index = 0; // Initialize the index to keep track of which inner grip button we're reading + byte tempLow; //variable for holding low byte of inner grip's analog reads + byte tempHi; //variable for holding high byte of inner grip's analog reads + Wire.requestFrom(49, 17); // request inner grip pro-mini return current button state info - while (Wire.available()) { // While something to read from the inner grip - if (index < JOY_X) { // The first sets of values are button presses until we get to axis values - Joystick.setButton(index + 7, Wire.read()); // inner throttle's digital button reads, set as joystick button state - } - // Remaining Index values are inner grip analog reads - else if (index == JOY_X) { // TDC X-axis - byte tempLow = Wire.read(); // read low byte - byte tempHi = Wire.read(); // read high byte - temp = (tempHi << 8) + tempLow; //rebuild the TDC X-axis value - Joystick.setXAxis(map(temp, 0, 65000, 0, 1024)); - - } else if (index == JOY_Y) { // TDC Y-axis - byte tempLow = Wire.read(); // read low byte - byte tempHi = Wire.read(); // read high byte - temp = (tempHi << 8) + tempLow; //rebuild the TDC Y-axis value - Joystick.setYAxis(map(temp, 0, 65000, 0, 1024)); - - } else if (index == ANTENNA_ELEVATION) { - byte tempLow = Wire.read(); // read low byte - byte tempHi = Wire.read(); // read high byte - temp = (tempHi << 8) + tempLow; //rebuild the Antenna axis value - Joystick.setZAxis(map(temp, 754, 978, 0, 1024)); // mapped values determined by reading the retured elevation on the serial monitor - // enable the lines below to see the Elevation knob's analog read values. - //Serial.print(" Elevation: "); - //Serial.print((tempHi << 8) + tempLow); - //Serial.print("\n"); + while (Wire.available()) { // While something to read from the inner grip + switch (index) { + case CAGE_UNCAGE: + Joystick.setButton(7, Wire.read()); + break; + case SPEEDBREAK_RETRACT: + Joystick.setButton(8, Wire.read()); + break; + case SPEEDBREAK_EXTEND: + Joystick.setButton(9, Wire.read()); + break; + case COUNTERMEASURES_AFT: + Joystick.setButton(10, Wire.read()); + break; + case COUNTERMEASURES_FWD: + Joystick.setButton(11, Wire.read()); + break; + case D: + Joystick.setButton(12, Wire.read()); + break; + case C: + Joystick.setButton(13, Wire.read()); + break; + case B: + Joystick.setButton(14, Wire.read()); + break; + case A: + Joystick.setButton(15, Wire.read()); + break; + case PUSH: + Joystick.setButton(16, Wire.read()); + break; + case JOY_SW: + Joystick.setButton(17, Wire.read()); + break; + case JOY_X: + tempLow = Wire.read(); // read low byte + tempHi = Wire.read(); // read high byte + temp = (tempHi << 8) + tempLow; //rebuild the TDC X-axis value + Joystick.setXAxis(map(temp, 0, 65000, 0, 1024)); + break; + case JOY_Y: + tempLow = Wire.read(); // read low byte + tempHi = Wire.read(); // read high byte + temp = (tempHi << 8) + tempLow; //rebuild the TDC Y-axis value + Joystick.setYAxis(map(temp, 0, 65000, 0, 1024)); + break; + case ANTENNA_ELEVATION: + tempLow = Wire.read(); // read low byte + tempHi = Wire.read(); // read high byte + temp = (tempHi << 8) + tempLow; //rebuild the Antenna axis value + Joystick.setZAxis(map(temp, 754, 978, 0, 1024)); // mapped values determined by reading the retured elevation on the serial monitor + // enable the lines below to see the Elevation knob's analog read values. + //Serial.print(" Elevation: "); + //Serial.print((tempHi << 8) + tempLow); + //Serial.print("\n"); + break; } index++; // increment the index for the next iteration through the while loop } @@ -368,13 +400,12 @@ void loop() { */ long mapHallSensor(unsigned long long x, unsigned long long in_min, unsigned long long in_max, unsigned long long out_min, unsigned long long out_max) { - const unsigned long long run = in_max - in_min; - if(run == 0){ - log_e("map(): Invalid input range, min == max"); - return -1; // AVR returns -1, SAM returns 0 - } - const unsigned long long rise = out_max - out_min; - const unsigned long long delta = x - in_min; - return (delta * rise) / run + out_min; + const unsigned long long run = in_max - in_min; + if (run == 0) { + log_e("map(): Invalid input range, min == max"); + return -1; // AVR returns -1, SAM returns 0 + } + const unsigned long long rise = out_max - out_min; + const unsigned long long delta = x - in_min; + return (delta * rise) / run + out_min; } - diff --git a/libraries/ArduinoCore-avr b/libraries/ArduinoCore-avr new file mode 160000 index 0000000..6309212 --- /dev/null +++ b/libraries/ArduinoCore-avr @@ -0,0 +1 @@ +Subproject commit 63092126a406402022f943ac048fa195ed7e944b From 819c123939ccb40010576183f127d6d7abc612cf Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Wed, 3 Apr 2024 22:07:49 -0500 Subject: [PATCH 13/20] Update Makefile --- embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile index 7350827..08d9151 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile @@ -1,5 +1,5 @@ # Any extra libraries included by this sketch (space separated) -LIBRARIES = Adafruit_NeoPixel Servo dcs-bios-arduino-library TCA9534 Wire ArduinoJoystickLibrary Stepper Joystick_ESP32S2 Arduino-FOC Arduino-FOC-drivers +LIBRARIES = Adafruit_NeoPixel Servo dcs-bios-arduino-library TCA9534 Wire ArduinoJoystickLibrary Stepper Joystick_ESP32S2 Arduino-FOC Arduino-FOC-drivers ArduinoCore_avr # Uncomment one of the following to choose the target board # include $(ROOTDIR)/include/mega2560.mk From 2af12bdf33de01edd1ed28f69d22fded38dee22d Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Wed, 3 Apr 2024 22:11:11 -0500 Subject: [PATCH 14/20] Revert "testing adding the Arduino library as a submodule" This reverts commit a83a43c82e058004b11b79e433b8496bcd63c0f0. --- .gitmodules | 3 - .../4A9A1-THROTTLE_CONTROLLER.ino | 141 +++++++----------- libraries/ArduinoCore-avr | 1 - 3 files changed, 55 insertions(+), 90 deletions(-) delete mode 160000 libraries/ArduinoCore-avr diff --git a/.gitmodules b/.gitmodules index d42ecae..5086493 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,6 +34,3 @@ [submodule "libraries/Arduino-FOC-drivers"] path = libraries/Arduino-FOC-drivers url = https://github.com/simplefoc/Arduino-FOC-drivers.git -[submodule "libraries/ArduinoCore-avr"] - path = libraries/ArduinoCore-avr - url = https://github.com/arduino/ArduinoCore-avr diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino index 9e6f055..0a16f47 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino @@ -81,10 +81,10 @@ * */ -#define DISABLE_MAX_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used -#define DISABLE_IDLE_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used +#define DISABLE_MAX_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used +#define DISABLE_IDLE_SOL_SIG ///< If defined the solenoid will be disabled in code, comment out line if the solenoid is used #define SET_THROTTLE_ZERO ///< Define to determine if code should allow the hall sensors to set its zero position based on initial position -//#define DISABLE_MAX_LIMIT_SWITCHES ///< disables the max limit switches, comment out line if the max limit switches should be used +#define DISABLE_MAX_LIMIT_SWITCHES ///< disables the max limit switches, comment out line if the max limit switches should be used #define DCSBIOS_DISABLE_SERVO ///< So the code will compile with an ESP32 #define DCSBIOS_DEFAULT_SERIAL @@ -242,9 +242,9 @@ void setup() { digitalWrite(IDLE_SOL_SIG, LOW); digitalWrite(MAX_SOL_SIG, LOW); - Joystick.setXAxisRange(0, 1024); // TDC X-axis - Joystick.setYAxisRange(0, 1024); // TDC Y-axis - Joystick.setZAxisRange(0, 1024); // Radar Elevation + Joystick.setXAxisRange(0, 1024); // TDC X-axis + Joystick.setYAxisRange(0, 1024); // TDC Y-axis + Joystick.setZAxisRange(0, 1024); // Radar Elevation Joystick.setRxAxisRange(0, 65535); // Outboard Throttle Arm Joystick.setRyAxisRange(0, 65535); // Inboard Throttle Arm Joystick.begin(); @@ -282,26 +282,26 @@ void loop() { uint32_t temp; // temp value to hold the analog reads in preparation of doing logic. - outboardThrottle.update(); // update the outboard hall sensor to prep for read. - temp = outboardThrottle.readRawAngle21(); // read outboard hall sensor + outboardThrottle.update(); // update the outboard hall sensor to prep for read. + temp = outboardThrottle.readRawAngle21(); // read outboard hall sensor Joystick.setRxAxis(mapHallSensor(temp, 0, 750000, 0, 65535)); //0 and 750000 came from reading the Serial Monitor for the min/max values to then plug into this line. // Uncomment the code below if you wish to pass the outboard throttle's raw values to the serial monitor //Serial.print("outbThrottle: "); //Serial.print(temp); - inboardThrottle.update(); // update the inboard hall sensor to prep for read - temp = inboardThrottle.readRawAngle21(); // read inboard hall sensor + inboardThrottle.update(); // update the inboard hall sensor to prep for read + temp = inboardThrottle.readRawAngle21(); // read inboard hall sensor Joystick.setRyAxis(mapHallSensor(temp, 0, 750000, 0, 65535)); //0 and 740000 came from reading the Serial Monitor for the min/max values to then plug into this line. -// Uncomment the code below if you wish to pass the inboard throttle's raw values to the serial monitor -//Serial.print(" inbThrottle: "); -//Serial.print(temp); -//Serial.print("\n"); + // Uncomment the code below if you wish to pass the inboard throttle's raw values to the serial monitor + //Serial.print(" inbThrottle: "); + //Serial.print(temp); + //Serial.print("\n"); -// determine if max limit switches are included or not -#ifndef DISABLE_MAX_LIMIT_SWITCHES + // determine if max limit switches are included or not + #ifndef DISABLE_MAX_LIMIT_SWITCHES Joystick.setButton(0, !digitalRead(OUTBD_MAX_LIMIT)); Joystick.setButton(1, !digitalRead(INBD_MAX_LIMIT)); -#endif + #endif Joystick.setButton(2, !digitalRead(OUTBD_IDLE_LIMIT)); Joystick.setButton(3, !digitalRead(INBD_IDLE_LIMIT)); @@ -309,69 +309,37 @@ void loop() { Joystick.setButton(5, !digitalRead(RAID_FLIR)); Joystick.setButton(6, !digitalRead(ATC_ENGAGE)); - int index = 0; // Initialize the index to keep track of which inner grip button we're reading - byte tempLow; //variable for holding low byte of inner grip's analog reads - byte tempHi; //variable for holding high byte of inner grip's analog reads - + int index = 0; // Initialize the index to keep track of which inner grip button we're reading Wire.requestFrom(49, 17); // request inner grip pro-mini return current button state info - while (Wire.available()) { // While something to read from the inner grip - switch (index) { - case CAGE_UNCAGE: - Joystick.setButton(7, Wire.read()); - break; - case SPEEDBREAK_RETRACT: - Joystick.setButton(8, Wire.read()); - break; - case SPEEDBREAK_EXTEND: - Joystick.setButton(9, Wire.read()); - break; - case COUNTERMEASURES_AFT: - Joystick.setButton(10, Wire.read()); - break; - case COUNTERMEASURES_FWD: - Joystick.setButton(11, Wire.read()); - break; - case D: - Joystick.setButton(12, Wire.read()); - break; - case C: - Joystick.setButton(13, Wire.read()); - break; - case B: - Joystick.setButton(14, Wire.read()); - break; - case A: - Joystick.setButton(15, Wire.read()); - break; - case PUSH: - Joystick.setButton(16, Wire.read()); - break; - case JOY_SW: - Joystick.setButton(17, Wire.read()); - break; - case JOY_X: - tempLow = Wire.read(); // read low byte - tempHi = Wire.read(); // read high byte - temp = (tempHi << 8) + tempLow; //rebuild the TDC X-axis value - Joystick.setXAxis(map(temp, 0, 65000, 0, 1024)); - break; - case JOY_Y: - tempLow = Wire.read(); // read low byte - tempHi = Wire.read(); // read high byte - temp = (tempHi << 8) + tempLow; //rebuild the TDC Y-axis value - Joystick.setYAxis(map(temp, 0, 65000, 0, 1024)); - break; - case ANTENNA_ELEVATION: - tempLow = Wire.read(); // read low byte - tempHi = Wire.read(); // read high byte - temp = (tempHi << 8) + tempLow; //rebuild the Antenna axis value - Joystick.setZAxis(map(temp, 754, 978, 0, 1024)); // mapped values determined by reading the retured elevation on the serial monitor - // enable the lines below to see the Elevation knob's analog read values. - //Serial.print(" Elevation: "); - //Serial.print((tempHi << 8) + tempLow); - //Serial.print("\n"); - break; + + + while (Wire.available()) { // While something to read from the inner grip + if (index < JOY_X) { // The first sets of values are button presses until we get to axis values + Joystick.setButton(index + 7, Wire.read()); // inner throttle's digital button reads, set as joystick button state + } + // Remaining Index values are inner grip analog reads + else if (index == JOY_X) { // TDC X-axis + byte tempLow = Wire.read(); // read low byte + byte tempHi = Wire.read(); // read high byte + temp = (tempHi << 8) + tempLow; //rebuild the TDC X-axis value + Joystick.setXAxis(map(temp, 0, 65000, 0, 1024)); + + } else if (index == JOY_Y) { // TDC Y-axis + byte tempLow = Wire.read(); // read low byte + byte tempHi = Wire.read(); // read high byte + temp = (tempHi << 8) + tempLow; //rebuild the TDC Y-axis value + Joystick.setYAxis(map(temp, 0, 65000, 0, 1024)); + + } else if (index == ANTENNA_ELEVATION) { + byte tempLow = Wire.read(); // read low byte + byte tempHi = Wire.read(); // read high byte + temp = (tempHi << 8) + tempLow; //rebuild the Antenna axis value + Joystick.setZAxis(map(temp, 754, 978, 0, 1024)); // mapped values determined by reading the retured elevation on the serial monitor + // enable the lines below to see the Elevation knob's analog read values. + //Serial.print(" Elevation: "); + //Serial.print((tempHi << 8) + tempLow); + //Serial.print("\n"); } index++; // increment the index for the next iteration through the while loop } @@ -400,12 +368,13 @@ void loop() { */ long mapHallSensor(unsigned long long x, unsigned long long in_min, unsigned long long in_max, unsigned long long out_min, unsigned long long out_max) { - const unsigned long long run = in_max - in_min; - if (run == 0) { - log_e("map(): Invalid input range, min == max"); - return -1; // AVR returns -1, SAM returns 0 - } - const unsigned long long rise = out_max - out_min; - const unsigned long long delta = x - in_min; - return (delta * rise) / run + out_min; + const unsigned long long run = in_max - in_min; + if(run == 0){ + log_e("map(): Invalid input range, min == max"); + return -1; // AVR returns -1, SAM returns 0 + } + const unsigned long long rise = out_max - out_min; + const unsigned long long delta = x - in_min; + return (delta * rise) / run + out_min; } + diff --git a/libraries/ArduinoCore-avr b/libraries/ArduinoCore-avr deleted file mode 160000 index 6309212..0000000 --- a/libraries/ArduinoCore-avr +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 63092126a406402022f943ac048fa195ed7e944b From bc77fe083d7fc0a4d1ebba9860e90a320ecb6739 Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Wed, 3 Apr 2024 22:11:34 -0500 Subject: [PATCH 15/20] Revert "Update Makefile" This reverts commit 819c123939ccb40010576183f127d6d7abc612cf. --- embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile index 08d9151..7350827 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/Makefile @@ -1,5 +1,5 @@ # Any extra libraries included by this sketch (space separated) -LIBRARIES = Adafruit_NeoPixel Servo dcs-bios-arduino-library TCA9534 Wire ArduinoJoystickLibrary Stepper Joystick_ESP32S2 Arduino-FOC Arduino-FOC-drivers ArduinoCore_avr +LIBRARIES = Adafruit_NeoPixel Servo dcs-bios-arduino-library TCA9534 Wire ArduinoJoystickLibrary Stepper Joystick_ESP32S2 Arduino-FOC Arduino-FOC-drivers # Uncomment one of the following to choose the target board # include $(ROOTDIR)/include/mega2560.mk From cb70eba16fff09f35522731a57b8b71b8a761fad Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Wed, 3 Apr 2024 22:12:31 -0500 Subject: [PATCH 16/20] Delete .gitmodules --- .gitmodules | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 5086493..0000000 --- a/.gitmodules +++ /dev/null @@ -1,36 +0,0 @@ -[submodule "libraries/dcs-bios-arduino-library"] - path = libraries/dcs-bios-arduino-library - url = https://github.com/DCS-Skunkworks/dcs-bios-arduino-library.git -[submodule "libraries/Arduino_Boards"] - path = libraries/Arduino_Boards - url = https://github.com/sparkfun/Arduino_Boards.git -[submodule "libraries/Adafruit_NeoPixel"] - path = libraries/Adafruit_NeoPixel - url = https://github.com/adafruit/Adafruit_NeoPixel.git -[submodule "include/Arduino-Makefile"] - path = include/Arduino-Makefile - url = https://github.com/sudar/Arduino-Makefile.git -[submodule "libraries/Servo"] - path = libraries/Servo - url = https://github.com/arduino-libraries/Servo.git -[submodule "libraries/arduino-esp32"] - path = libraries/arduino-esp32 - url = https://github.com/espressif/arduino-esp32.git -[submodule "include/makeEspArduino"] - path = include/makeEspArduino - url = https://github.com/plerup/makeEspArduino.git -[submodule "libraries/TCA9534"] - path = libraries/TCA9534 - url = https://github.com/balzreber/TCA9534.git -[submodule "libraries/ArduinoJoystickLibrary"] - path = libraries/ArduinoJoystickLibrary - url = https://github.com/MHeironimus/ArduinoJoystickLibrary.git -[submodule "libraries/Joystick_ESP32S2"] - path = libraries/Joystick_ESP32S2 - url = https://github.com/schnoog/Joystick_ESP32S2.git -[submodule "libraries/Arduino-FOC"] - path = libraries/Arduino-FOC - url = https://github.com/simplefoc/Arduino-FOC.git -[submodule "libraries/Arduino-FOC-drivers"] - path = libraries/Arduino-FOC-drivers - url = https://github.com/simplefoc/Arduino-FOC-drivers.git From b3bd712d716b8f9a0028f4d0bac6ae6b7ab37786 Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Wed, 3 Apr 2024 22:16:49 -0500 Subject: [PATCH 17/20] Adding the SPI.h files directly to the throttle folder for SimpleFOC --- .../4A9A1-THROTTLE_CONTROLLER/SPI.cpp | 201 +++++++++++ .../4A9A1-THROTTLE_CONTROLLER/SPI.h | 324 ++++++++++++++++++ 2 files changed, 525 insertions(+) create mode 100644 embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/SPI.cpp create mode 100644 embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/SPI.h diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/SPI.cpp b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/SPI.cpp new file mode 100644 index 0000000..af14e07 --- /dev/null +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/SPI.cpp @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2010 by Cristian Maglie + * Copyright (c) 2014 by Paul Stoffregen (Transaction API) + * Copyright (c) 2014 by Matthijs Kooijman (SPISettings AVR) + * Copyright (c) 2014 by Andrew J. Kroll (atomicity fixes) + * SPI Master library for arduino. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +#include "SPI.h" + +SPIClass SPI; + +uint8_t SPIClass::initialized = 0; +uint8_t SPIClass::interruptMode = 0; +uint8_t SPIClass::interruptMask = 0; +uint8_t SPIClass::interruptSave = 0; +#ifdef SPI_TRANSACTION_MISMATCH_LED +uint8_t SPIClass::inTransactionFlag = 0; +#endif + +void SPIClass::begin() +{ + uint8_t sreg = SREG; + noInterrupts(); // Protect from a scheduler and prevent transactionBegin + if (!initialized) { + // Set SS to high so a connected chip will be "deselected" by default + uint8_t port = digitalPinToPort(SS); + uint8_t bit = digitalPinToBitMask(SS); + volatile uint8_t *reg = portModeRegister(port); + + // if the SS pin is not already configured as an output + // then set it high (to enable the internal pull-up resistor) + if(!(*reg & bit)){ + digitalWrite(SS, HIGH); + } + + // When the SS pin is set as OUTPUT, it can be used as + // a general purpose output port (it doesn't influence + // SPI operations). + pinMode(SS, OUTPUT); + + // Warning: if the SS pin ever becomes a LOW INPUT then SPI + // automatically switches to Slave, so the data direction of + // the SS pin MUST be kept as OUTPUT. + SPCR |= _BV(MSTR); + SPCR |= _BV(SPE); + + // Set direction register for SCK and MOSI pin. + // MISO pin automatically overrides to INPUT. + // By doing this AFTER enabling SPI, we avoid accidentally + // clocking in a single bit since the lines go directly + // from "input" to SPI control. + // http://code.google.com/p/arduino/issues/detail?id=888 + pinMode(SCK, OUTPUT); + pinMode(MOSI, OUTPUT); + } + initialized++; // reference count + SREG = sreg; +} + +void SPIClass::end() { + uint8_t sreg = SREG; + noInterrupts(); // Protect from a scheduler and prevent transactionBegin + // Decrease the reference counter + if (initialized) + initialized--; + // If there are no more references disable SPI + if (!initialized) { + SPCR &= ~_BV(SPE); + interruptMode = 0; + #ifdef SPI_TRANSACTION_MISMATCH_LED + inTransactionFlag = 0; + #endif + } + SREG = sreg; +} + +// mapping of interrupt numbers to bits within SPI_AVR_EIMSK +#if defined(__AVR_ATmega32U4__) + #define SPI_INT0_MASK (1< + * Copyright (c) 2014 by Paul Stoffregen (Transaction API) + * Copyright (c) 2014 by Matthijs Kooijman (SPISettings AVR) + * Copyright (c) 2014 by Andrew J. Kroll (atomicity fixes) + * SPI Master library for arduino. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +#ifndef _SPI_H_INCLUDED +#define _SPI_H_INCLUDED + +#include + +// SPI_HAS_TRANSACTION means SPI has beginTransaction(), endTransaction(), +// usingInterrupt(), and SPISetting(clock, bitOrder, dataMode) +#define SPI_HAS_TRANSACTION 1 + +// SPI_HAS_NOTUSINGINTERRUPT means that SPI has notUsingInterrupt() method +#define SPI_HAS_NOTUSINGINTERRUPT 1 + +// SPI_ATOMIC_VERSION means that SPI has atomicity fixes and what version. +// This way when there is a bug fix you can check this define to alert users +// of your code if it uses better version of this library. +// This also implies everything that SPI_HAS_TRANSACTION as documented above is +// available too. +#define SPI_ATOMIC_VERSION 1 + +// Uncomment this line to add detection of mismatched begin/end transactions. +// A mismatch occurs if other libraries fail to use SPI.endTransaction() for +// each SPI.beginTransaction(). Connect an LED to this pin. The LED will turn +// on if any mismatch is ever detected. +//#define SPI_TRANSACTION_MISMATCH_LED 5 + +#ifndef LSBFIRST +#define LSBFIRST 0 +#endif +#ifndef MSBFIRST +#define MSBFIRST 1 +#endif + +#define SPI_CLOCK_DIV4 0x00 +#define SPI_CLOCK_DIV16 0x01 +#define SPI_CLOCK_DIV64 0x02 +#define SPI_CLOCK_DIV128 0x03 +#define SPI_CLOCK_DIV2 0x04 +#define SPI_CLOCK_DIV8 0x05 +#define SPI_CLOCK_DIV32 0x06 + +#define SPI_MODE0 0x00 +#define SPI_MODE1 0x04 +#define SPI_MODE2 0x08 +#define SPI_MODE3 0x0C + +#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR +#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR +#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR + +// define SPI_AVR_EIMSK for AVR boards with external interrupt pins +#if defined(EIMSK) + #define SPI_AVR_EIMSK EIMSK +#elif defined(GICR) + #define SPI_AVR_EIMSK GICR +#elif defined(GIMSK) + #define SPI_AVR_EIMSK GIMSK +#endif + +class SPISettings { +public: + SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) { + if (__builtin_constant_p(clock)) { + init_AlwaysInline(clock, bitOrder, dataMode); + } else { + init_MightInline(clock, bitOrder, dataMode); + } + } + SPISettings() { + init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0); + } +private: + void init_MightInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) { + init_AlwaysInline(clock, bitOrder, dataMode); + } + void init_AlwaysInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) + __attribute__((__always_inline__)) { + // Clock settings are defined as follows. Note that this shows SPI2X + // inverted, so the bits form increasing numbers. Also note that + // fosc/64 appears twice + // SPR1 SPR0 ~SPI2X Freq + // 0 0 0 fosc/2 + // 0 0 1 fosc/4 + // 0 1 0 fosc/8 + // 0 1 1 fosc/16 + // 1 0 0 fosc/32 + // 1 0 1 fosc/64 + // 1 1 0 fosc/64 + // 1 1 1 fosc/128 + + // We find the fastest clock that is less than or equal to the + // given clock rate. The clock divider that results in clock_setting + // is 2 ^^ (clock_div + 1). If nothing is slow enough, we'll use the + // slowest (128 == 2 ^^ 7, so clock_div = 6). + uint8_t clockDiv; + + // When the clock is known at compile time, use this if-then-else + // cascade, which the compiler knows how to completely optimize + // away. When clock is not known, use a loop instead, which generates + // shorter code. + if (__builtin_constant_p(clock)) { + if (clock >= F_CPU / 2) { + clockDiv = 0; + } else if (clock >= F_CPU / 4) { + clockDiv = 1; + } else if (clock >= F_CPU / 8) { + clockDiv = 2; + } else if (clock >= F_CPU / 16) { + clockDiv = 3; + } else if (clock >= F_CPU / 32) { + clockDiv = 4; + } else if (clock >= F_CPU / 64) { + clockDiv = 5; + } else { + clockDiv = 6; + } + } else { + uint32_t clockSetting = F_CPU / 2; + clockDiv = 0; + while (clockDiv < 6 && clock < clockSetting) { + clockSetting /= 2; + clockDiv++; + } + } + + // Compensate for the duplicate fosc/64 + if (clockDiv == 6) + clockDiv = 7; + + // Invert the SPI2X bit + clockDiv ^= 0x1; + + // Pack into the SPISettings class + spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) | + (dataMode & SPI_MODE_MASK) | ((clockDiv >> 1) & SPI_CLOCK_MASK); + spsr = clockDiv & SPI_2XCLOCK_MASK; + } + uint8_t spcr; + uint8_t spsr; + friend class SPIClass; +}; + + +class SPIClass { +public: + // Initialize the SPI library + static void begin(); + + // If SPI is used from within an interrupt, this function registers + // that interrupt with the SPI library, so beginTransaction() can + // prevent conflicts. The input interruptNumber is the number used + // with attachInterrupt. If SPI is used from a different interrupt + // (eg, a timer), interruptNumber should be 255. + static void usingInterrupt(uint8_t interruptNumber); + // And this does the opposite. + static void notUsingInterrupt(uint8_t interruptNumber); + // Note: the usingInterrupt and notUsingInterrupt functions should + // not to be called from ISR context or inside a transaction. + // For details see: + // https://github.com/arduino/Arduino/pull/2381 + // https://github.com/arduino/Arduino/pull/2449 + + // Before using SPI.transfer() or asserting chip select pins, + // this function is used to gain exclusive access to the SPI bus + // and configure the correct settings. + inline static void beginTransaction(SPISettings settings) { + if (interruptMode > 0) { + uint8_t sreg = SREG; + noInterrupts(); + + #ifdef SPI_AVR_EIMSK + if (interruptMode == 1) { + interruptSave = SPI_AVR_EIMSK; + SPI_AVR_EIMSK &= ~interruptMask; + SREG = sreg; + } else + #endif + { + interruptSave = sreg; + } + } + + #ifdef SPI_TRANSACTION_MISMATCH_LED + if (inTransactionFlag) { + pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT); + digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH); + } + inTransactionFlag = 1; + #endif + + SPCR = settings.spcr; + SPSR = settings.spsr; + } + + // Write to the SPI bus (MOSI pin) and also receive (MISO pin) + inline static uint8_t transfer(uint8_t data) { + SPDR = data; + /* + * The following NOP introduces a small delay that can prevent the wait + * loop form iterating when running at the maximum speed. This gives + * about 10% more speed, even if it seems counter-intuitive. At lower + * speeds it is unnoticed. + */ + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; // wait + return SPDR; + } + inline static uint16_t transfer16(uint16_t data) { + union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } in, out; + in.val = data; + if (!(SPCR & _BV(DORD))) { + SPDR = in.msb; + asm volatile("nop"); // See transfer(uint8_t) function + while (!(SPSR & _BV(SPIF))) ; + out.msb = SPDR; + SPDR = in.lsb; + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; + out.lsb = SPDR; + } else { + SPDR = in.lsb; + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; + out.lsb = SPDR; + SPDR = in.msb; + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; + out.msb = SPDR; + } + return out.val; + } + inline static void transfer(void *buf, size_t count) { + if (count == 0) return; + uint8_t *p = (uint8_t *)buf; + SPDR = *p; + while (--count > 0) { + uint8_t out = *(p + 1); + while (!(SPSR & _BV(SPIF))) ; + uint8_t in = SPDR; + SPDR = out; + *p++ = in; + } + while (!(SPSR & _BV(SPIF))) ; + *p = SPDR; + } + // After performing a group of transfers and releasing the chip select + // signal, this function allows others to access the SPI bus + inline static void endTransaction(void) { + #ifdef SPI_TRANSACTION_MISMATCH_LED + if (!inTransactionFlag) { + pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT); + digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH); + } + inTransactionFlag = 0; + #endif + + if (interruptMode > 0) { + #ifdef SPI_AVR_EIMSK + uint8_t sreg = SREG; + #endif + noInterrupts(); + #ifdef SPI_AVR_EIMSK + if (interruptMode == 1) { + SPI_AVR_EIMSK = interruptSave; + SREG = sreg; + } else + #endif + { + SREG = interruptSave; + } + } + } + + // Disable the SPI bus + static void end(); + + // This function is deprecated. New applications should use + // beginTransaction() to configure SPI settings. + inline static void setBitOrder(uint8_t bitOrder) { + if (bitOrder == LSBFIRST) SPCR |= _BV(DORD); + else SPCR &= ~(_BV(DORD)); + } + // This function is deprecated. New applications should use + // beginTransaction() to configure SPI settings. + inline static void setDataMode(uint8_t dataMode) { + SPCR = (SPCR & ~SPI_MODE_MASK) | dataMode; + } + // This function is deprecated. New applications should use + // beginTransaction() to configure SPI settings. + inline static void setClockDivider(uint8_t clockDiv) { + SPCR = (SPCR & ~SPI_CLOCK_MASK) | (clockDiv & SPI_CLOCK_MASK); + SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((clockDiv >> 2) & SPI_2XCLOCK_MASK); + } + // These undocumented functions should not be used. SPI.transfer() + // polls the hardware flag which is automatically cleared as the + // AVR responds to SPI's interrupt + inline static void attachInterrupt() { SPCR |= _BV(SPIE); } + inline static void detachInterrupt() { SPCR &= ~_BV(SPIE); } + +private: + static uint8_t initialized; + static uint8_t interruptMode; // 0=none, 1=mask, 2=global + static uint8_t interruptMask; // which interrupts to mask + static uint8_t interruptSave; // temp storage, to restore state + #ifdef SPI_TRANSACTION_MISMATCH_LED + static uint8_t inTransactionFlag; + #endif +}; + +extern SPIClass SPI; + +#endif From 5f89bb0edc06a9de1c9f2c6cbfb8c2f5751f0d85 Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Wed, 3 Apr 2024 22:22:15 -0500 Subject: [PATCH 18/20] Revert "Delete .gitmodules" This reverts commit cb70eba16fff09f35522731a57b8b71b8a761fad. --- .gitmodules | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..5086493 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,36 @@ +[submodule "libraries/dcs-bios-arduino-library"] + path = libraries/dcs-bios-arduino-library + url = https://github.com/DCS-Skunkworks/dcs-bios-arduino-library.git +[submodule "libraries/Arduino_Boards"] + path = libraries/Arduino_Boards + url = https://github.com/sparkfun/Arduino_Boards.git +[submodule "libraries/Adafruit_NeoPixel"] + path = libraries/Adafruit_NeoPixel + url = https://github.com/adafruit/Adafruit_NeoPixel.git +[submodule "include/Arduino-Makefile"] + path = include/Arduino-Makefile + url = https://github.com/sudar/Arduino-Makefile.git +[submodule "libraries/Servo"] + path = libraries/Servo + url = https://github.com/arduino-libraries/Servo.git +[submodule "libraries/arduino-esp32"] + path = libraries/arduino-esp32 + url = https://github.com/espressif/arduino-esp32.git +[submodule "include/makeEspArduino"] + path = include/makeEspArduino + url = https://github.com/plerup/makeEspArduino.git +[submodule "libraries/TCA9534"] + path = libraries/TCA9534 + url = https://github.com/balzreber/TCA9534.git +[submodule "libraries/ArduinoJoystickLibrary"] + path = libraries/ArduinoJoystickLibrary + url = https://github.com/MHeironimus/ArduinoJoystickLibrary.git +[submodule "libraries/Joystick_ESP32S2"] + path = libraries/Joystick_ESP32S2 + url = https://github.com/schnoog/Joystick_ESP32S2.git +[submodule "libraries/Arduino-FOC"] + path = libraries/Arduino-FOC + url = https://github.com/simplefoc/Arduino-FOC.git +[submodule "libraries/Arduino-FOC-drivers"] + path = libraries/Arduino-FOC-drivers + url = https://github.com/simplefoc/Arduino-FOC-drivers.git From aa6b8eb77b76ef01196a4c1a5b09605f9eb7ba03 Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Wed, 3 Apr 2024 22:27:46 -0500 Subject: [PATCH 19/20] Revert "Adding the SPI.h files directly to the throttle folder for SimpleFOC" This reverts commit b3bd712d716b8f9a0028f4d0bac6ae6b7ab37786. --- .../4A9A1-THROTTLE_CONTROLLER/SPI.cpp | 201 ----------- .../4A9A1-THROTTLE_CONTROLLER/SPI.h | 324 ------------------ 2 files changed, 525 deletions(-) delete mode 100644 embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/SPI.cpp delete mode 100644 embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/SPI.h diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/SPI.cpp b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/SPI.cpp deleted file mode 100644 index af14e07..0000000 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/SPI.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2010 by Cristian Maglie - * Copyright (c) 2014 by Paul Stoffregen (Transaction API) - * Copyright (c) 2014 by Matthijs Kooijman (SPISettings AVR) - * Copyright (c) 2014 by Andrew J. Kroll (atomicity fixes) - * SPI Master library for arduino. - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of either the GNU General Public License version 2 - * or the GNU Lesser General Public License version 2.1, both as - * published by the Free Software Foundation. - */ - -#include "SPI.h" - -SPIClass SPI; - -uint8_t SPIClass::initialized = 0; -uint8_t SPIClass::interruptMode = 0; -uint8_t SPIClass::interruptMask = 0; -uint8_t SPIClass::interruptSave = 0; -#ifdef SPI_TRANSACTION_MISMATCH_LED -uint8_t SPIClass::inTransactionFlag = 0; -#endif - -void SPIClass::begin() -{ - uint8_t sreg = SREG; - noInterrupts(); // Protect from a scheduler and prevent transactionBegin - if (!initialized) { - // Set SS to high so a connected chip will be "deselected" by default - uint8_t port = digitalPinToPort(SS); - uint8_t bit = digitalPinToBitMask(SS); - volatile uint8_t *reg = portModeRegister(port); - - // if the SS pin is not already configured as an output - // then set it high (to enable the internal pull-up resistor) - if(!(*reg & bit)){ - digitalWrite(SS, HIGH); - } - - // When the SS pin is set as OUTPUT, it can be used as - // a general purpose output port (it doesn't influence - // SPI operations). - pinMode(SS, OUTPUT); - - // Warning: if the SS pin ever becomes a LOW INPUT then SPI - // automatically switches to Slave, so the data direction of - // the SS pin MUST be kept as OUTPUT. - SPCR |= _BV(MSTR); - SPCR |= _BV(SPE); - - // Set direction register for SCK and MOSI pin. - // MISO pin automatically overrides to INPUT. - // By doing this AFTER enabling SPI, we avoid accidentally - // clocking in a single bit since the lines go directly - // from "input" to SPI control. - // http://code.google.com/p/arduino/issues/detail?id=888 - pinMode(SCK, OUTPUT); - pinMode(MOSI, OUTPUT); - } - initialized++; // reference count - SREG = sreg; -} - -void SPIClass::end() { - uint8_t sreg = SREG; - noInterrupts(); // Protect from a scheduler and prevent transactionBegin - // Decrease the reference counter - if (initialized) - initialized--; - // If there are no more references disable SPI - if (!initialized) { - SPCR &= ~_BV(SPE); - interruptMode = 0; - #ifdef SPI_TRANSACTION_MISMATCH_LED - inTransactionFlag = 0; - #endif - } - SREG = sreg; -} - -// mapping of interrupt numbers to bits within SPI_AVR_EIMSK -#if defined(__AVR_ATmega32U4__) - #define SPI_INT0_MASK (1< - * Copyright (c) 2014 by Paul Stoffregen (Transaction API) - * Copyright (c) 2014 by Matthijs Kooijman (SPISettings AVR) - * Copyright (c) 2014 by Andrew J. Kroll (atomicity fixes) - * SPI Master library for arduino. - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of either the GNU General Public License version 2 - * or the GNU Lesser General Public License version 2.1, both as - * published by the Free Software Foundation. - */ - -#ifndef _SPI_H_INCLUDED -#define _SPI_H_INCLUDED - -#include - -// SPI_HAS_TRANSACTION means SPI has beginTransaction(), endTransaction(), -// usingInterrupt(), and SPISetting(clock, bitOrder, dataMode) -#define SPI_HAS_TRANSACTION 1 - -// SPI_HAS_NOTUSINGINTERRUPT means that SPI has notUsingInterrupt() method -#define SPI_HAS_NOTUSINGINTERRUPT 1 - -// SPI_ATOMIC_VERSION means that SPI has atomicity fixes and what version. -// This way when there is a bug fix you can check this define to alert users -// of your code if it uses better version of this library. -// This also implies everything that SPI_HAS_TRANSACTION as documented above is -// available too. -#define SPI_ATOMIC_VERSION 1 - -// Uncomment this line to add detection of mismatched begin/end transactions. -// A mismatch occurs if other libraries fail to use SPI.endTransaction() for -// each SPI.beginTransaction(). Connect an LED to this pin. The LED will turn -// on if any mismatch is ever detected. -//#define SPI_TRANSACTION_MISMATCH_LED 5 - -#ifndef LSBFIRST -#define LSBFIRST 0 -#endif -#ifndef MSBFIRST -#define MSBFIRST 1 -#endif - -#define SPI_CLOCK_DIV4 0x00 -#define SPI_CLOCK_DIV16 0x01 -#define SPI_CLOCK_DIV64 0x02 -#define SPI_CLOCK_DIV128 0x03 -#define SPI_CLOCK_DIV2 0x04 -#define SPI_CLOCK_DIV8 0x05 -#define SPI_CLOCK_DIV32 0x06 - -#define SPI_MODE0 0x00 -#define SPI_MODE1 0x04 -#define SPI_MODE2 0x08 -#define SPI_MODE3 0x0C - -#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR -#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR -#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR - -// define SPI_AVR_EIMSK for AVR boards with external interrupt pins -#if defined(EIMSK) - #define SPI_AVR_EIMSK EIMSK -#elif defined(GICR) - #define SPI_AVR_EIMSK GICR -#elif defined(GIMSK) - #define SPI_AVR_EIMSK GIMSK -#endif - -class SPISettings { -public: - SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) { - if (__builtin_constant_p(clock)) { - init_AlwaysInline(clock, bitOrder, dataMode); - } else { - init_MightInline(clock, bitOrder, dataMode); - } - } - SPISettings() { - init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0); - } -private: - void init_MightInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) { - init_AlwaysInline(clock, bitOrder, dataMode); - } - void init_AlwaysInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) - __attribute__((__always_inline__)) { - // Clock settings are defined as follows. Note that this shows SPI2X - // inverted, so the bits form increasing numbers. Also note that - // fosc/64 appears twice - // SPR1 SPR0 ~SPI2X Freq - // 0 0 0 fosc/2 - // 0 0 1 fosc/4 - // 0 1 0 fosc/8 - // 0 1 1 fosc/16 - // 1 0 0 fosc/32 - // 1 0 1 fosc/64 - // 1 1 0 fosc/64 - // 1 1 1 fosc/128 - - // We find the fastest clock that is less than or equal to the - // given clock rate. The clock divider that results in clock_setting - // is 2 ^^ (clock_div + 1). If nothing is slow enough, we'll use the - // slowest (128 == 2 ^^ 7, so clock_div = 6). - uint8_t clockDiv; - - // When the clock is known at compile time, use this if-then-else - // cascade, which the compiler knows how to completely optimize - // away. When clock is not known, use a loop instead, which generates - // shorter code. - if (__builtin_constant_p(clock)) { - if (clock >= F_CPU / 2) { - clockDiv = 0; - } else if (clock >= F_CPU / 4) { - clockDiv = 1; - } else if (clock >= F_CPU / 8) { - clockDiv = 2; - } else if (clock >= F_CPU / 16) { - clockDiv = 3; - } else if (clock >= F_CPU / 32) { - clockDiv = 4; - } else if (clock >= F_CPU / 64) { - clockDiv = 5; - } else { - clockDiv = 6; - } - } else { - uint32_t clockSetting = F_CPU / 2; - clockDiv = 0; - while (clockDiv < 6 && clock < clockSetting) { - clockSetting /= 2; - clockDiv++; - } - } - - // Compensate for the duplicate fosc/64 - if (clockDiv == 6) - clockDiv = 7; - - // Invert the SPI2X bit - clockDiv ^= 0x1; - - // Pack into the SPISettings class - spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) | - (dataMode & SPI_MODE_MASK) | ((clockDiv >> 1) & SPI_CLOCK_MASK); - spsr = clockDiv & SPI_2XCLOCK_MASK; - } - uint8_t spcr; - uint8_t spsr; - friend class SPIClass; -}; - - -class SPIClass { -public: - // Initialize the SPI library - static void begin(); - - // If SPI is used from within an interrupt, this function registers - // that interrupt with the SPI library, so beginTransaction() can - // prevent conflicts. The input interruptNumber is the number used - // with attachInterrupt. If SPI is used from a different interrupt - // (eg, a timer), interruptNumber should be 255. - static void usingInterrupt(uint8_t interruptNumber); - // And this does the opposite. - static void notUsingInterrupt(uint8_t interruptNumber); - // Note: the usingInterrupt and notUsingInterrupt functions should - // not to be called from ISR context or inside a transaction. - // For details see: - // https://github.com/arduino/Arduino/pull/2381 - // https://github.com/arduino/Arduino/pull/2449 - - // Before using SPI.transfer() or asserting chip select pins, - // this function is used to gain exclusive access to the SPI bus - // and configure the correct settings. - inline static void beginTransaction(SPISettings settings) { - if (interruptMode > 0) { - uint8_t sreg = SREG; - noInterrupts(); - - #ifdef SPI_AVR_EIMSK - if (interruptMode == 1) { - interruptSave = SPI_AVR_EIMSK; - SPI_AVR_EIMSK &= ~interruptMask; - SREG = sreg; - } else - #endif - { - interruptSave = sreg; - } - } - - #ifdef SPI_TRANSACTION_MISMATCH_LED - if (inTransactionFlag) { - pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT); - digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH); - } - inTransactionFlag = 1; - #endif - - SPCR = settings.spcr; - SPSR = settings.spsr; - } - - // Write to the SPI bus (MOSI pin) and also receive (MISO pin) - inline static uint8_t transfer(uint8_t data) { - SPDR = data; - /* - * The following NOP introduces a small delay that can prevent the wait - * loop form iterating when running at the maximum speed. This gives - * about 10% more speed, even if it seems counter-intuitive. At lower - * speeds it is unnoticed. - */ - asm volatile("nop"); - while (!(SPSR & _BV(SPIF))) ; // wait - return SPDR; - } - inline static uint16_t transfer16(uint16_t data) { - union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } in, out; - in.val = data; - if (!(SPCR & _BV(DORD))) { - SPDR = in.msb; - asm volatile("nop"); // See transfer(uint8_t) function - while (!(SPSR & _BV(SPIF))) ; - out.msb = SPDR; - SPDR = in.lsb; - asm volatile("nop"); - while (!(SPSR & _BV(SPIF))) ; - out.lsb = SPDR; - } else { - SPDR = in.lsb; - asm volatile("nop"); - while (!(SPSR & _BV(SPIF))) ; - out.lsb = SPDR; - SPDR = in.msb; - asm volatile("nop"); - while (!(SPSR & _BV(SPIF))) ; - out.msb = SPDR; - } - return out.val; - } - inline static void transfer(void *buf, size_t count) { - if (count == 0) return; - uint8_t *p = (uint8_t *)buf; - SPDR = *p; - while (--count > 0) { - uint8_t out = *(p + 1); - while (!(SPSR & _BV(SPIF))) ; - uint8_t in = SPDR; - SPDR = out; - *p++ = in; - } - while (!(SPSR & _BV(SPIF))) ; - *p = SPDR; - } - // After performing a group of transfers and releasing the chip select - // signal, this function allows others to access the SPI bus - inline static void endTransaction(void) { - #ifdef SPI_TRANSACTION_MISMATCH_LED - if (!inTransactionFlag) { - pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT); - digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH); - } - inTransactionFlag = 0; - #endif - - if (interruptMode > 0) { - #ifdef SPI_AVR_EIMSK - uint8_t sreg = SREG; - #endif - noInterrupts(); - #ifdef SPI_AVR_EIMSK - if (interruptMode == 1) { - SPI_AVR_EIMSK = interruptSave; - SREG = sreg; - } else - #endif - { - SREG = interruptSave; - } - } - } - - // Disable the SPI bus - static void end(); - - // This function is deprecated. New applications should use - // beginTransaction() to configure SPI settings. - inline static void setBitOrder(uint8_t bitOrder) { - if (bitOrder == LSBFIRST) SPCR |= _BV(DORD); - else SPCR &= ~(_BV(DORD)); - } - // This function is deprecated. New applications should use - // beginTransaction() to configure SPI settings. - inline static void setDataMode(uint8_t dataMode) { - SPCR = (SPCR & ~SPI_MODE_MASK) | dataMode; - } - // This function is deprecated. New applications should use - // beginTransaction() to configure SPI settings. - inline static void setClockDivider(uint8_t clockDiv) { - SPCR = (SPCR & ~SPI_CLOCK_MASK) | (clockDiv & SPI_CLOCK_MASK); - SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((clockDiv >> 2) & SPI_2XCLOCK_MASK); - } - // These undocumented functions should not be used. SPI.transfer() - // polls the hardware flag which is automatically cleared as the - // AVR responds to SPI's interrupt - inline static void attachInterrupt() { SPCR |= _BV(SPIE); } - inline static void detachInterrupt() { SPCR &= ~_BV(SPIE); } - -private: - static uint8_t initialized; - static uint8_t interruptMode; // 0=none, 1=mask, 2=global - static uint8_t interruptMask; // which interrupts to mask - static uint8_t interruptSave; // temp storage, to restore state - #ifdef SPI_TRANSACTION_MISMATCH_LED - static uint8_t inTransactionFlag; - #endif -}; - -extern SPIClass SPI; - -#endif From e70165caf858d2af6ecde6e3969f4cdf199def34 Mon Sep 17 00:00:00 2001 From: Arribe <47125808+Arribe@users.noreply.github.com> Date: Mon, 8 Apr 2024 09:34:16 -0500 Subject: [PATCH 20/20] Fixed spelling CI still doesn't work. --- .../4A9A1-THROTTLE_CONTROLLER.ino | 8 ++++---- .../4A9A1A1-THROTTLE_INNER_GRIP.ino | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino index 0a16f47..cb67358 100644 --- a/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino +++ b/embedded/OH4_Left_Console/4A9A1-THROTTLE_CONTROLLER/4A9A1-THROTTLE_CONTROLLER.ino @@ -112,12 +112,12 @@ /** * Inner grip control with index -* CAGE_UNCAGE, SPEEDBREAK_RETRACT, SPEEDBREAK_EXTEND, COUNTERMEASURES_AFT, COUNTERMEASURES_FWD, D, C, B, A, PUSH, JOY_SW, JOY_X, JOY_Y, ANTENNA_ELEVATION +* CAGE_UNCAGE, SPEEDBRAKE_RETRACT, SPEEDBRAKE_EXTEND, COUNTERMEASURES_AFT, COUNTERMEASURES_FWD, D, C, B, A, PUSH, JOY_SW, JOY_X, JOY_Y, ANTENNA_ELEVATION * */ #define CAGE_UNCAGE 0 -#define SPEEDBREAK_RETRACT 1 -#define SPEEDBREAK_EXTEND 2 +#define SPEEDBRAKE_RETRACT 1 +#define SPEEDBRAKE_EXTEND 2 #define COUNTERMEASURES_AFT 3 #define COUNTERMEASURES_FWD 4 #define D 5 @@ -272,7 +272,7 @@ void setup() { * `Joystick.setRxAxis(mapHallSensor(outboardThrottle.readRawAngle21(), 0, 750000, 0, 65535));` * * @note Inner grip values sent to throttle controller in this order: -* CAGE_UNCAGE, SPEEDBREAK_RETRACT, SPEEDBREAK_EXTEND, COUNTERMEASURES_AFT, COUNTERMEASURES_FWD, D, C, B, A, PUSH, JOY_SW, +* CAGE_UNCAGE, SPEEDBRAKE_RETRACT, SPEEDBRAKE_EXTEND, COUNTERMEASURES_AFT, COUNTERMEASURES_FWD, D, C, B, A, PUSH, JOY_SW, * JOY_X, JOY_Y, ANTENNA_ELEVATION */ void loop() { diff --git a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino index 5c5eab3..1475914 100644 --- a/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino +++ b/embedded/OH4_Left_Console/4A9A1A1-THROTTLE_INNER_GRIP/4A9A1A1-THROTTLE_INNER_GRIP.ino @@ -48,8 +48,8 @@ * PIN | Function * --- | --- * 2 | CAGE_UNCAGE - * 3 | SPEEDBREAK_RETRACT - * 4 | SPEEDBREAK_EXTEND + * 3 | SPEEDBRAKE_RETRACT + * 4 | SPEEDBRAKE_EXTEND * 7 | COUNTERMEASURES_AFT * 8 | COUNTERMEASURES_FWD * 9 | PUSH - coms switch @@ -70,8 +70,8 @@ // Define pins inner grip pro-mini #define CAGE_UNCAGE 2 ///< CAGE_UNCAGE -#define SPEEDBREAK_RETRACT 3 ///< SPEEDBREAK_RETRACT -#define SPEEDBREAK_EXTEND 4 ///< SPEEDBREAK_EXTEND +#define SPEEDBRAKE_RETRACT 3 ///< SPEEDBRAKE_RETRACT +#define SPEEDBRAKE_EXTEND 4 ///< SPEEDBRAKE_EXTEND #define COUNTERMEASURES_AFT 7 ///< COUNTERMEASURES_AFT #define COUNTERMEASURES_FWD 8 ///< COUNTERMEASURES_FWD #define PUSH 9 ///< PUSH - coms switch @@ -101,8 +101,8 @@ void setup() { pinMode(CAGE_UNCAGE, INPUT_PULLUP); - pinMode(SPEEDBREAK_RETRACT, INPUT_PULLUP); - pinMode(SPEEDBREAK_EXTEND, INPUT_PULLUP); + pinMode(SPEEDBRAKE_RETRACT, INPUT_PULLUP); + pinMode(SPEEDBRAKE_EXTEND, INPUT_PULLUP); pinMode(COUNTERMEASURES_AFT, INPUT_PULLUP); pinMode(COUNTERMEASURES_FWD, INPUT_PULLUP); pinMode(ANTENNA_ELEVATION, INPUT_PULLUP); @@ -134,7 +134,7 @@ void loop() { * so the controller can properly reassemble the 2 byte numeric value. * * Passes inner grip reads to throttle controller in this order: -* CAGE_UNCAGE, SPEEDBREAK_RETRACT, SPEEDBREAK_EXTEND, COUNTERMEASURES_AFT, COUNTERMEASURES_FWD, D, C, B, A, PUSH, JOY_SW, +* CAGE_UNCAGE, SPEEDBRAKE_RETRACT, SPEEDBRAKE_EXTEND, COUNTERMEASURES_AFT, COUNTERMEASURES_FWD, D, C, B, A, PUSH, JOY_SW, * JOY_X, JOY_Y, ANTENNA_ELEVATION * * @note There is minimal logic for the inner grip pro-mini given the extra steps for reprogramming. @@ -143,8 +143,8 @@ void loop() { void requestEvent() { Wire.write(!digitalRead(CAGE_UNCAGE)); - Wire.write(!digitalRead(SPEEDBREAK_RETRACT)); - Wire.write(!digitalRead(SPEEDBREAK_EXTEND)); + Wire.write(!digitalRead(SPEEDBRAKE_RETRACT)); + Wire.write(!digitalRead(SPEEDBRAKE_EXTEND)); Wire.write(!digitalRead(COUNTERMEASURES_AFT)); Wire.write(!digitalRead(COUNTERMEASURES_FWD)); Wire.write(!digitalRead(D));