From 8062605e0335819258925683fdcec27a9e8abf36 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sun, 14 May 2023 13:49:00 +0000 Subject: [PATCH 01/29] major update --- firmware/Makefile | 25 -- firmware/src/main.cpp | 971 +++++++++++++++++++++--------------------- 2 files changed, 493 insertions(+), 503 deletions(-) delete mode 100644 firmware/Makefile diff --git a/firmware/Makefile b/firmware/Makefile deleted file mode 100644 index 5bb8443..0000000 --- a/firmware/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -# Uncomment lines below if you have problems with $PATH -#SHELL := /bin/bash -#PATH := /usr/local/bin:$(PATH) - -all: - platformio run - -upload: - platformio run --target upload - -clean: - platformio run --target clean - -program: - platformio run --target program - -uploadfs: - platformio run --target uploadfs - -update: - platformio update - -bear: - platformio run --target clean - bear make all diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index 7010a9f..123f8f0 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -26,99 +26,150 @@ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU General Public License for more details. * - * Joystick based on standard teensy "Keypad" library for button scanning, standard teensy - * "usb_joystick" library for HID joystick usb data communication. + * Joystick based on standard teensy "usb_joystick" library for HID joystick usb data communication. * - * Layer 0 + * USB Joystick Layer 0 * - * | B7 | | B9 | - * --------------------------------------------- - * | B8 | | | B1 | B2 | | | B10 | - * | X1,Y1 | | B3 | B4 | | X2,Y2 | - * | Fn1 | | B5 |Y1 offset| B6 | | Fn2 | - * --------------------------------------------- + * | B1 | | B3 | + * | B2 | | B4 | + * -------------------------------------------- + * | | Fn1 | | B5 | | + * | | + * | X1,Y1 X2,Y2 | + * | | B6 | | B7 | | + * -------------------------------------------- * - * Layer 1 (Fn1) + * USB Joystick Layer 1 (Fn1) * - * | B17| | B19| - * --------------------------------------------- - * | B18 | | | B11| B12| | | B20 | - * | X1,Y1 | | B13| B14| | X3,Y2 | - * | Fn1 | | B15|Y1 offset| B16| | Fn2 | - * --------------------------------------------- + * | B1 | | B3 | + * | B8 | | B9 | + * -------------------------------------------- + * | | Fn1 | | Fn2 | | + * | | + * | X1,Y1 Fn1 toggle Fn1 toggle X3,Y2 | + * | | B10 | | B11 | | + * -------------------------------------------- + * + * USB Joystick Layer 2 (Fn2) * - * Layer 2 (Fn2) - * - * | B27| | B29| - * --------------------------------------------- - * | B28 | | | B21| B22| | | B30 | - * | X1,Y1 | | B23| B24| | X3,Y3 | - * | Fn1 | | B25|Y1 offset| B26| | Fn2 | - * --------------------------------------------- + * | B1 | | B3 | + * | B12 | | B13 | + * -------------------------------------------- + * | | Fn1 | | Fn2 | | + * | | + * | X1,Y1 X3,Y3 | + * | | B14 | | B15 | | + * -------------------------------------------- + * + * ELRS Layer * + * | CH7 | | CH9 | + * | HC8 | | CH10 | + * -------------------------------------------- + * | | Fn | | CH11 | | + * | | + * | X,Y Fn toggle Fn toggle X,Y | + * | CH1,CH2 | CH5 | | CH6 | CH3,CH4 | + * -------------------------------------------- + * * Features: * - * * 5 physical axis. - * * 6 joystick axis using layers. - * * 12 physical buttons. - * * 32 joystick buttons using three layers (Fn1 and Fn2). + * * USB HID Joystick. + * * ERLS protocol (CRSF) support. + * * 4 physical axis. + * * 6 joystick axis using layers (USB Joystick). + * * 8 physical buttons. + * * 15 joystick buttons using three layers (Fn1 and Fn2). */ #include -#include #include -#define USB_LED_NUM_LOCK 0 -#define USB_LED_CAPS_LOCK 1 -#define USB_LED_SCROLL_LOCK 2 +// CRSF +#define CRSF_MAX_CHANNEL 16 +#define CRSF_TYPE_CHANNELS 0x16 +#define CRSF_DIGITAL_CHANNEL_MIN 172 +#define CRSF_DIGITAL_CHANNEL_CENTER 992 +#define CRSF_DIGITAL_CHANNEL_MAX 1811 +#define CRSF_TIME_BETWEEN_FRAMES_US 1666 // 1.6 ms 500Hz +#define CRSF_PACKET_SIZE 26 +#define CRSF_CMD_PACKET_SIZE 8 -#define KEY_OFFSET 0xAA00 // Offset to apply for not interfere with already defined keyboard keys +// ELRS command +#define ELRS_ADDRESS 0xEE +#define ELRS_BIND_COMMAND 0xFF +#define ELRS_WIFI_COMMAND 0xFE +#define ELRS_PKT_RATE_COMMAND 0x01 +#define ELRS_TLM_RATIO_COMMAND 0x02 +#define ELRS_SWITCH_MODE_COMMAND 0x03 +#define ELRS_MODEL_MATCH_COMMAND 0x04 +#define ELRS_POWER_COMMAND 0x06 +#define ELRS_BLE_JOYSTIC_COMMAND 17 +#define ELRS_TYPE_SETTINGS_WRITE 0x2D +#define ELRS_ADDR_RADIO 0xEA +#define ELRS_SERIAL_PORT Serial1 +#define ELRS_SERIAL_BAUDRATE 400000 +#define ELRS_PKT_RATE 3 // 0 = 50Hz, 1 = 100Hz, 2 = 200Hz, 3 = 500Hz, 4 = 1000Hz +#define ELRS_POWER 2 // 0 = 10mW, 1 = 25mW, 2 = 100mW, 3 = 250mW, 4 = 500mW, 5 = 1000mW -#define NO_JOY 0 +// crc implementation from CRSF protocol document rev7 +static uint8_t crsf_crc8tab[256] = { + 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, + 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, + 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, + 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, + 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, + 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, + 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, + 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, + 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, + 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, + 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, + 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, + 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, + 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, + 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, + 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9}; -#define JOY_A1 1 + KEY_OFFSET -#define JOY_A2 2 + KEY_OFFSET -#define JOY_A3 3 + KEY_OFFSET -#define JOY_A4 4 + KEY_OFFSET -#define JOY_A5 5 + KEY_OFFSET -#define JOY_A6 6 + KEY_OFFSET -#define JOY_A7 7 + KEY_OFFSET -#define JOY_A8 8 + KEY_OFFSET -#define JOY_A9 9 + KEY_OFFSET -#define JOY_A10 10 + KEY_OFFSET -#define JOY_A11 11 + KEY_OFFSET -#define JOY_A12 12 + KEY_OFFSET -#define JOY_A13 13 + KEY_OFFSET -#define JOY_A14 14 + KEY_OFFSET -#define JOY_A15 15 + KEY_OFFSET -#define JOY_A16 16 + KEY_OFFSET -#define JOY_A17 17 + KEY_OFFSET -#define JOY_A18 18 + KEY_OFFSET -#define JOY_A19 19 + KEY_OFFSET -#define JOY_A20 20 + KEY_OFFSET -#define JOY_A21 21 + KEY_OFFSET -#define JOY_A22 22 + KEY_OFFSET -#define JOY_A23 23 + KEY_OFFSET -#define JOY_A24 24 + KEY_OFFSET -#define JOY_A25 25 + KEY_OFFSET -#define JOY_A26 26 + KEY_OFFSET -#define JOY_A27 27 + KEY_OFFSET -#define JOY_A28 28 + KEY_OFFSET -#define JOY_A29 29 + KEY_OFFSET -#define JOY_A30 30 + KEY_OFFSET -#define JOY_A31 31 + KEY_OFFSET -#define JOY_A32 32 + KEY_OFFSET +uint8_t crsf_packet[CRSF_PACKET_SIZE]; +uint8_t crsf_cmd_packet[CRSF_CMD_PACKET_SIZE]; +int16_t elrs_channels[CRSF_MAX_CHANNEL]; +bool elrs_init_done = false; +int elrs_init_counter = 0; -#define JOY_AHU1 49 + KEY_OFFSET -#define JOY_AHR1 50 + KEY_OFFSET -#define JOY_AHD1 51 + KEY_OFFSET -#define JOY_AHL1 52 + KEY_OFFSET +const int STATUS_LED = 13; +bool status_led_on = false; +int status_led_mode = 2; -#define KEY_FN1 61 + KEY_OFFSET // Function layer 1 button -#define KEY_FN2 62 + KEY_OFFSET // Function layer 2 button +const int BUTTON_LED_1 = 22; +bool button_led_1_on = false; +int button_led_1_mode = 0; -#define TAP_TIMEOUT 150 // Key tap timeout (ms) -#define NBR_OF_BUTTONS 12 // Number of buttons used (12 in this case) +const int BUTTON_LED_2 = 23; +bool button_led_2_on = false; +int button_led_2_mode = 0; + +unsigned long current_timestamp = 0; +unsigned long button_timestamp = 0; +unsigned long joystick_timestamp = 0; +unsigned long indicator_timestamp = 0; + +unsigned long current_timestamp_micros = 0; +unsigned long elrs_timestamp_micros = 0; + +const int BUTTON_FLU = 4; // Front left upper button +const int BUTTON_FLD = 5; // Front left lower button +const int BUTTON_FRU = 6; // Front right upper button +const int BUTTON_FRD = 7; // Front right lower button +const int BUTTON_TLU = 9; // top upper left button +const int BUTTON_TRU = 10; // Top upper right button +const int BUTTON_TLD = 8; // Top left lower button +const int BUTTON_TRD = 11; // Top right lower button + +bool toggle_button_10 = false; +bool toggle_button_11 = false; +int button_10_previous_value = HIGH; +int button_11_previous_value = HIGH; #define HID_AXIS_MAX 1023 #define HID_AXIS_MIN 0 @@ -129,90 +180,6 @@ #define DEADZONE_X 50 #define DEADZONE_Y 50 -struct Button -{ - int keypad_kchar = 0; - uint16_t keycode = NO_KEY; - uint16_t tap_keycode = NO_KEY; - uint16_t fn1_keycode = NO_KEY; - uint16_t fn2_keycode = NO_KEY; - bool hold_direct = true; - int kstate = IDLE; - uint16_t last_keycode = NO_KEY; - bool run_keycode = false; - int tap_state = 0; - bool tap_timeout_enable = false; - bool tap_release_enable = false; - unsigned long tap_timeout_timestamp = 0; - unsigned long tap_release_timestamp = 0; - bool tap_inhibit = false; -}; - -const byte KP_ROWS = 3; -const byte KP_COLS = 4; - -byte kp_rowPins[KP_ROWS] = {6, 7, 8}; -byte kp_colPins[KP_COLS] = {9, 10, 11, 12}; - -char kp_keys[KP_ROWS][KP_COLS] = { - {1, 2, 3, 4}, - {5, 6, 7, 8}, - {9, 10, 11, 12}}; - -Keypad kp_keypad = Keypad(makeKeymap(kp_keys), kp_rowPins, kp_colPins, KP_ROWS, KP_COLS); - - -/* Valid "Fn0 (hold) key" when using tap mode are: KEY_LEFT_SHIFT, KEY_RIGHT_SHIFT, KEY_LEFT_CTRL, KEY_RIGHT_CTRL, KEY_RIGHT_ALT, KEY_LEFT_GUI, KEY_RIGHT_GUI, KEY_FN1, KEY_FN2 - - * "Button ID" corresponding with the physical design of the actual keyboard. DO NOT CHANGE BTN ID! - - | 1 | | 4 | - --------------------------------------------- - | 5 | | | 2 | 3 | | | 8 | - | X1,Y1 | | 6 | 7 | | X3,Y3 | - | 9 | | 10 |Y1 offset| 11 | | 12 | - --------------------------------------------- - - * "Fn0 hold key" is normal key in non tap mode. In tap mode this key is the hold key. - * "Fn0 tap key" enables tap mode. - * "Fn1 key" is the layer 1 key to use. Don NOT add KEY_FN1 or KEY_FN2 to this layer. - * "Fn2 key" is the layer 2 key to use. Don NOT add KEY_FN1 or KEY_FN2 to this layer. - "Fn1 key" and "Fn2 key" are N/A when using tap mode and should me defined as NO_KEY. - * "Hold direct" enables sending PRESS command as soon as the hold key is pressed (regardless if you intend to press the tap key). - -/* Keymap config ----------------------------------------------------------------------------------------------------------------------------------- */ -// clang-format off -Button buttons[NBR_OF_BUTTONS] = - { -/* Btn ID Fn0 (hold) key Fn1 key Fn2 key */ - {1, JOY_A7, JOY_A17, JOY_A27, IDLE, NO_KEY, false}, - {2, JOY_A1, JOY_A11, JOY_A21, IDLE, NO_KEY, false}, - {3, JOY_A2, JOY_A12, JOY_A22, IDLE, NO_KEY, false}, - {4, JOY_A9, JOY_A19, JOY_A29, IDLE, NO_KEY, false}, - {5, JOY_A8, JOY_A18, JOY_A28, IDLE, NO_KEY, false}, - {6, JOY_A3, JOY_A13, JOY_A23, IDLE, NO_KEY, false}, - {7, JOY_A4, JOY_A14, JOY_A24, IDLE, NO_KEY, false}, - {8, JOY_A10, JOY_A20, JOY_A30, IDLE, NO_KEY, false}, - {9, KEY_FN1, NO_KEY, NO_KEY, IDLE, NO_KEY, false}, - {10, JOY_A5, JOY_A15, JOY_A25, IDLE, NO_KEY, false}, - {11, JOY_A6, JOY_A16, JOY_A26, IDLE, NO_KEY, false}, - {12, KEY_FN2, NO_KEY, NO_KEY, IDLE, NO_KEY, false}}; - -// clang-format on -/* End of keymap config ----------------------------------------------------------------------------------------------------------------------------- */ - -const int STATUS_LED = 13; -bool status_led_on = false; -int status_led_mode = 0; - -unsigned long current_timestamp = 0; -unsigned long button_timestamp = 0; -unsigned long indicator_timestamp = 0; - -bool key_pressed = false; - -int fn_mode = 0; - // USB HID data variables int xy_x1 = HID_AXIS_CENTER; int xy_y1 = HID_AXIS_CENTER; @@ -247,12 +214,6 @@ enum EEPROM_ADR MIN_Y2_ADR_LOW, CNT_Y2_ADR_HIGH, CNT_Y2_ADR_LOW, - MAX_X3_ADR_HIGH, - MAX_X3_ADR_LOW, - MIN_X3_ADR_HIGH, - MIN_X3_ADR_LOW, - CNT_X3_ADR_HIGH, - CNT_X3_ADR_LOW, EEPROM_ADR_NBR_OF_BYTES }; @@ -277,18 +238,16 @@ int joystick_y2_raw = 0; int joystick_y2_max = 4096; int joystick_y2_min = 0; int joystick_y2_center = joystick_y2_max/2; -int joystick_x3 = 0; -int joystick_x3_raw = 0; -int joystick_x3_max = 4096; -int joystick_x3_min = 0; -int joystick_x3_center = joystick_x3_max/2; float exp_constant = 0.2; #define CALIBRATION_OFF 0 -#define CALIBRATION_CENTER 1 -#define CALIBRATION_MINMAX 2 -int joystick_calibration_mode = 0; +#define CALIBRATION_INIT 1 +#define CALIBRATION_CENTER 2 +#define CALIBRATION_MINMAX 3 +int joystick_calibration_mode = CALIBRATION_OFF; + +// ----------------------------------------------- void save_to_eeprom(){ EEPROM.write(MAX_X1_ADR_LOW, joystick_x1_max); @@ -318,14 +277,6 @@ void save_to_eeprom(){ EEPROM.write(MIN_Y2_ADR_HIGH, joystick_y2_min >> 8); EEPROM.write(CNT_Y2_ADR_LOW, joystick_y2_center); EEPROM.write(CNT_Y2_ADR_HIGH, joystick_y2_center >> 8); - - EEPROM.write(MAX_X3_ADR_LOW, joystick_x3_max); - EEPROM.write(MAX_X3_ADR_HIGH, joystick_x3_max >> 8); - EEPROM.write(MIN_X3_ADR_LOW, joystick_x3_min); - EEPROM.write(MIN_X3_ADR_HIGH, joystick_x3_min >> 8); - EEPROM.write(CNT_X3_ADR_LOW, joystick_x3_center); - EEPROM.write(CNT_X3_ADR_HIGH, joystick_x3_center >> 8); - } void load_from_eeprom(){ @@ -356,17 +307,197 @@ void load_from_eeprom(){ joystick_y2_min |= EEPROM.read(MIN_Y2_ADR_LOW); joystick_y2_center = (EEPROM.read(CNT_Y2_ADR_HIGH) << 8); joystick_y2_center |= EEPROM.read(CNT_Y2_ADR_LOW); - - joystick_x3_max = (EEPROM.read(MAX_X3_ADR_HIGH) << 8); - joystick_x3_max |= EEPROM.read(MAX_X3_ADR_LOW); - joystick_x3_min = (EEPROM.read(MIN_X3_ADR_HIGH) << 8); - joystick_x3_min |= EEPROM.read(MIN_X3_ADR_LOW); - joystick_x3_center = (EEPROM.read(CNT_X3_ADR_HIGH) << 8); - joystick_x3_center |= EEPROM.read(CNT_X2_ADR_LOW); - } -void update_analog(){ +void process_io_data(){ + + // Check for calibration mode + if (joystick_calibration_mode == CALIBRATION_INIT){ + if (digitalRead(BUTTON_TLD) == HIGH){ + joystick_calibration_mode = CALIBRATION_CENTER; + } + return; + } + if (joystick_calibration_mode == CALIBRATION_CENTER){ + button_led_1_mode = 2; + button_led_2_mode = 0; + if (digitalRead(BUTTON_TLD) == LOW){ + joystick_calibration_mode = CALIBRATION_MINMAX; + button_led_1_mode = 0; + } + return; + } + if (joystick_calibration_mode == CALIBRATION_MINMAX){ + button_led_1_mode = 0; + button_led_2_mode = 2; + if (digitalRead(BUTTON_TRD) == LOW){ + joystick_calibration_mode = CALIBRATION_OFF; + save_to_eeprom(); + button_led_2_mode = 0; + } + return; + } + + // Check fn mode + int fn_mode = 0; + if (digitalRead(BUTTON_TLU) == LOW){ + fn_mode = 1; + if (digitalRead(BUTTON_TRU) == LOW){ + fn_mode = 2; + } + } + + // Check toggle buttons + if (fn_mode == 1){ + if (digitalRead(BUTTON_TLD) != button_10_previous_value){ + button_10_previous_value = digitalRead(BUTTON_TLD); + if (digitalRead(BUTTON_TLD) == LOW){ + if (toggle_button_10 == false){ + toggle_button_10 = true; + button_led_1_mode = 1; + } + else{ + toggle_button_10 = false; + button_led_1_mode = 0; + } + } + } + if (digitalRead(BUTTON_TRD) != button_11_previous_value){ + button_11_previous_value = digitalRead(BUTTON_TRD); + if (digitalRead(BUTTON_TRD) == LOW){ + if (toggle_button_11 == false){ + toggle_button_11 = true; + button_led_2_mode = 1; + } + else{ + toggle_button_11 = false; + button_led_2_mode = 0; + } + } + } + } + + // Set joystick buttons to released + for (int i = 1; i < 32; i++){ + Joystick.button(i, 0); + } + + // Set joystick hat to center position + Joystick.hat(-1); + + // Set joystick buttons to pressed + if (fn_mode == 2){ + + if (digitalRead(BUTTON_FLD) == LOW){ + Joystick.button(12, 1); + } + if (digitalRead(BUTTON_FRD) == LOW){ + Joystick.button(13, 1); + } + if (digitalRead(BUTTON_TLD) == LOW){ + Joystick.button(14, 1); + } + if (digitalRead(BUTTON_TRD) == LOW){ + Joystick.button(15, 1); + } + } + else if (fn_mode == 1){ + + if (digitalRead(BUTTON_FLD) == LOW){ + Joystick.button(8, 1); + } + if (digitalRead(BUTTON_FRD) == LOW){ + Joystick.button(9, 1); + } + } + else{ + if (digitalRead(BUTTON_FLD) == LOW){ + Joystick.button(2, 1); + } + if (digitalRead(BUTTON_FRD) == LOW){ + Joystick.button(4, 1); + } + if (digitalRead(BUTTON_TRU) == LOW){ + Joystick.button(5, 1); + } + if (digitalRead(BUTTON_TLD) == LOW){ + Joystick.button(6, 1); + } + if (digitalRead(BUTTON_TRD) == LOW){ + Joystick.button(7, 1); + } + } + + if (digitalRead(BUTTON_FLU) == LOW){ + Joystick.button(1, 1); + } + if (digitalRead(BUTTON_FRU) == LOW){ + Joystick.button(3, 1); + } + if (toggle_button_10){ + Joystick.button(10, 1); + } + if (toggle_button_11){ + Joystick.button(11, 1); + } + + // Set axis values + Joystick.X(joystick_x1); + Joystick.Y(joystick_y1); + + if (fn_mode == 2){ + Joystick.Z(HID_AXIS_CENTER); + Joystick.Zrotate(HID_AXIS_CENTER); + Joystick.sliderLeft(joystick_x2); + Joystick.sliderRight(joystick_y2); + } + else if (fn_mode == 1){ + Joystick.Z(HID_AXIS_CENTER); + Joystick.Zrotate(joystick_y2); + Joystick.sliderLeft(joystick_x2); + Joystick.sliderRight(HID_AXIS_CENTER); + } + else{ + Joystick.Z(joystick_x2); + Joystick.Zrotate(joystick_y2); + Joystick.sliderLeft(HID_AXIS_CENTER); + Joystick.sliderRight(HID_AXIS_CENTER); + } + + // Set ELRS analog channels + elrs_channels[0] = map(joystick_x1, HID_AXIS_MIN, HID_AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + elrs_channels[1] = map(joystick_y1, HID_AXIS_MIN, HID_AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + elrs_channels[2] = map(joystick_x2, HID_AXIS_MIN, HID_AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + elrs_channels[3] = map(joystick_y2, HID_AXIS_MIN, HID_AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + + // Set ELRS digital channels + for (int i = 4; i < CRSF_MAX_CHANNEL; i++){ + elrs_channels[i] = CRSF_DIGITAL_CHANNEL_MIN; + } + if (toggle_button_10){ + elrs_channels[4] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (toggle_button_11){ + elrs_channels[5] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (digitalRead(BUTTON_FLU) == LOW){ + elrs_channels[6] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (digitalRead(BUTTON_FLD) == LOW){ + elrs_channels[7] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (digitalRead(BUTTON_FRU) == LOW){ + elrs_channels[8] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (digitalRead(BUTTON_FRD) == LOW){ + elrs_channels[9] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (digitalRead(BUTTON_TRU) == LOW){ + elrs_channels[10] = CRSF_DIGITAL_CHANNEL_MAX; + } +} + +void read_io_data(){ if(joystick_counter == 0){ joystick_x1_raw = analogRead(0); @@ -382,17 +513,11 @@ void update_analog(){ } else if(joystick_counter == 3){ joystick_y2_raw = analogRead(3); - joystick_counter++; - } - else if(joystick_counter == 4){ - joystick_x3_raw = analogRead(4); joystick_counter = 0; if (joystick_calibration_mode == CALIBRATION_OFF){ - // ---------------------------------------------------------- - // Map X1 joystick values to proper HID values - // ---------------------------------------------------------- + // Calculate X1 joystick values if(joystick_x1_raw > (joystick_x1_center + DEADZONE_X)){ joystick_x1 = constrain(map(joystick_x1_raw, (joystick_x1_center + DEADZONE_X), joystick_x1_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); } @@ -402,9 +527,8 @@ void update_analog(){ else{ joystick_x1 = AXIS_CENTER; } - // ---------------------------------------------------------- - // Map Y1 joystick values to proper HID values - // ---------------------------------------------------------- + + // Calculate Y1 joystick values if(joystick_y1_raw > (joystick_y1_center + DEADZONE_Y)){ joystick_y1 = constrain(map(joystick_y1_raw, (joystick_y1_center + DEADZONE_Y), joystick_y1_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); } @@ -415,9 +539,7 @@ void update_analog(){ joystick_y1 = AXIS_CENTER; } - // ---------------------------------------------------------- - // Map X2 joystick values to proper HID values - // ---------------------------------------------------------- + // Calculate X2 joystick values if(joystick_x2_raw > (joystick_x2_center + DEADZONE_X)){ joystick_x2 = constrain(map(joystick_x2_raw, (joystick_x2_center + DEADZONE_X), joystick_x2_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); } @@ -427,9 +549,8 @@ void update_analog(){ else{ joystick_x2 = AXIS_CENTER; } - // ---------------------------------------------------------- - // Map Y1 joystick values to proper HID values - // ---------------------------------------------------------- + + // Calculate Y2 joystick values if(joystick_y2_raw > (joystick_y2_center + DEADZONE_Y)){ joystick_y2 = constrain(map(joystick_y2_raw, (joystick_y2_center + DEADZONE_Y), joystick_y2_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); } @@ -440,25 +561,7 @@ void update_analog(){ joystick_y2 = AXIS_CENTER; } - // ---------------------------------------------------------- - // Map X3 joystick values to proper HID values - // ---------------------------------------------------------- - if(joystick_x3_raw > (joystick_x3_center + DEADZONE_X)){ - joystick_x3 = constrain(map(joystick_x3_raw, (joystick_x3_center + DEADZONE_X), joystick_x3_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); - } - else if(joystick_x3_raw < (joystick_x3_center - DEADZONE_X)){ - joystick_x3 = constrain(map(joystick_x3_raw, joystick_x3_min, (joystick_x3_center - DEADZONE_X), AXIS_MIN, AXIS_CENTER), AXIS_MIN, AXIS_CENTER); - } - else{ - joystick_x3 = AXIS_CENTER; - } - - // ---------------------------------------------------------- - // Calculate new axis values after applying exp curve - // ---------------------------------------------------------- - // Normal mode - exp_constant = 0.2; - + // Calculate new X1 values after applying exp curve if (joystick_x1 != AXIS_CENTER){ float joystick_x_float = joystick_x1 / float(AXIS_MAX); float joystick_x_exp = exp_constant * (0.5 + 256 * pow((joystick_x_float - 0.5),9)) + (1 - exp_constant) * joystick_x_float; @@ -468,6 +571,8 @@ void update_analog(){ else{ joystick_x1 = HID_AXIS_CENTER; } + + // Calculate new Y1 values after applying exp curve if (joystick_y1 != AXIS_CENTER){ float joystick_y_float = joystick_y1 / float(AXIS_MAX); float joystick_y_exp = exp_constant * (0.5 + 256 * pow((joystick_y_float - 0.5),9)) + (1 - exp_constant) * joystick_y_float; @@ -477,7 +582,8 @@ void update_analog(){ else{ joystick_y1 = HID_AXIS_CENTER; } - + + // Calculate new X2 values after applying exp curve if (joystick_x2 != AXIS_CENTER){ float joystick_x_float = joystick_x2 / float(AXIS_MAX); float joystick_x_exp = exp_constant * (0.5 + 256 * pow((joystick_x_float - 0.5),9)) + (1 - exp_constant) * joystick_x_float; @@ -487,6 +593,8 @@ void update_analog(){ else{ joystick_x2 = HID_AXIS_CENTER; } + + // Calculate new Y2 values after applying exp curve if (joystick_y2 != AXIS_CENTER){ float joystick_y_float = joystick_y2 / float(AXIS_MAX); float joystick_y_exp = exp_constant * (0.5 + 256 * pow((joystick_y_float - 0.5),9)) + (1 - exp_constant) * joystick_y_float; @@ -496,28 +604,16 @@ void update_analog(){ else{ joystick_y2 = HID_AXIS_CENTER; } - - if (joystick_x3 != AXIS_CENTER){ - float joystick_x_float = joystick_x3 / float(AXIS_MAX); - float joystick_x_exp = exp_constant * (0.5 + 256 * pow((joystick_x_float - 0.5),9)) + (1 - exp_constant) * joystick_x_float; - joystick_x3 = int(joystick_x_exp * float(HID_AXIS_MAX)); - joystick_x3 = constrain(joystick_x3, HID_AXIS_MIN, HID_AXIS_MAX); - } - else{ - joystick_x3 = HID_AXIS_CENTER; - } } else{ - // ---------------------------------------------------------- // Calibration mode. - // ---------------------------------------------------------- - joystick_x1 = HID_AXIS_CENTER; joystick_x1 = HID_AXIS_CENTER; + joystick_y1 = HID_AXIS_CENTER; joystick_x2 = HID_AXIS_CENTER; joystick_y2 = HID_AXIS_CENTER; - joystick_x3 = HID_AXIS_CENTER; + // Calibrate joystick center values if (joystick_calibration_mode == CALIBRATION_CENTER){ joystick_x1_center = joystick_x1_raw; joystick_y1_center = joystick_y1_raw; @@ -532,11 +628,8 @@ void update_analog(){ joystick_x2_min = joystick_x2_center; joystick_y2_max = joystick_y2_center; joystick_y2_min = joystick_y2_center; - - joystick_x3_center = joystick_x3_raw; - joystick_x3_max = joystick_x3_center; - joystick_x3_min = joystick_x3_center; } + // Calibrate joystick min/max values else if (joystick_calibration_mode == CALIBRATION_MINMAX){ if(joystick_x1_raw > joystick_x1_max){ joystick_x1_max = joystick_x1_raw; @@ -563,220 +656,60 @@ void update_analog(){ if(joystick_y2_raw < joystick_y2_min){ joystick_y2_min = joystick_y2_raw; } - - if(joystick_x3_raw > joystick_x3_max){ - joystick_x3_max = joystick_x3_raw; - } - if(joystick_x3_raw < joystick_x3_min){ - joystick_x3_min = joystick_x3_raw; - } } } } } - -/** - Perform key action. - - @param keycode code to apply action. - @param kstate PRESSED or RELEASED. - @return Action applied. -*/ -bool set_key(uint16_t keycode, uint8_t kstate) -{ - /* Abort if keycode is invalid */ - if (keycode == NO_KEY || keycode == KEY_FN1 || keycode == KEY_FN2) - { - return false; +// CRSF CRC calculation via lookup table +uint8_t crsf_crc8(const uint8_t *ptr, uint8_t len) { + uint8_t crc = 0; + for (uint8_t i = 0; i < len; i++){ + crc = crsf_crc8tab[crc ^ *ptr++]; } - - /* Joystick buttons */ - else if (keycode >= JOY_A1 && keycode <= JOY_A32) { - if (kstate == RELEASED) { - Joystick.button(keycode-KEY_OFFSET, false); - } else if (kstate == PRESSED) { - Joystick.button(keycode-KEY_OFFSET, true); - } - } - - /* Joystick hat */ - else if (keycode >= JOY_AHU1 && keycode <= JOY_AHL1) { - if (kstate == RELEASED) { - Joystick.hat(-1); - } else if (kstate == PRESSED) { - Joystick.hat(((keycode-KEY_OFFSET)-(JOY_AHU1-KEY_OFFSET)) * 90); - } - } - - return true; + return crc; } -/** - Scan key matrix and perform processing for each key. +// Prepare CRSF data packet +void crsf_prepare_data_packet(uint8_t packet[], int16_t channels[]) { + packet[0] = ELRS_ADDRESS; // Header + packet[1] = 24; // length + packet[2] = CRSF_TYPE_CHANNELS; + packet[3] = (uint8_t)(channels[0] & 0x07FF); + packet[4] = (uint8_t)((channels[0] & 0x07FF) >> 8 | (channels[1] & 0x07FF) << 3); + packet[5] = (uint8_t)((channels[1] & 0x07FF) >> 5 | (channels[2] & 0x07FF) << 6); + packet[6] = (uint8_t)((channels[2] & 0x07FF) >> 2); + packet[7] = (uint8_t)((channels[2] & 0x07FF) >> 10 | (channels[3] & 0x07FF) << 1); + packet[8] = (uint8_t)((channels[3] & 0x07FF) >> 7 | (channels[4] & 0x07FF) << 4); + packet[9] = (uint8_t)((channels[4] & 0x07FF) >> 4 | (channels[5] & 0x07FF) << 7); + packet[10] = (uint8_t)((channels[5] & 0x07FF) >> 1); + packet[11] = (uint8_t)((channels[5] & 0x07FF) >> 9 | (channels[6] & 0x07FF) << 2); + packet[12] = (uint8_t)((channels[6] & 0x07FF) >> 6 | (channels[7] & 0x07FF) << 5); + packet[13] = (uint8_t)((channels[7] & 0x07FF) >> 3); + packet[14] = (uint8_t)((channels[8] & 0x07FF)); + packet[15] = (uint8_t)((channels[8] & 0x07FF) >> 8 | (channels[9] & 0x07FF) << 3); + packet[16] = (uint8_t)((channels[9] & 0x07FF) >> 5 | (channels[10] & 0x07FF) << 6); + packet[17] = (uint8_t)((channels[10] & 0x07FF) >> 2); + packet[18] = (uint8_t)((channels[10] & 0x07FF) >> 10 | (channels[11] & 0x07FF) << 1); + packet[19] = (uint8_t)((channels[11] & 0x07FF) >> 7 | (channels[12] & 0x07FF) << 4); + packet[20] = (uint8_t)((channels[12] & 0x07FF) >> 4 | (channels[13] & 0x07FF) << 7); // Channel not used by ELRS + packet[21] = (uint8_t)((channels[13] & 0x07FF) >> 1); // Channel not used by ELRS + packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2); // Channel not used by ELRS + packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5); // Channel not used by ELRS + packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3); // Channel not used by ELRS + packet[25] = crsf_crc8(&packet[2], packet[1] - 1); +} - @return void. -*/ -void scan_buttons() -{ - /* Scan keypad */ - if (kp_keypad.getKeys()) - { - - /* Enter bootloader if all reboot-buttons is pressed together */ - int reboot = 0; - for (int i = 0; i < LIST_MAX; i++) - { - if ((kp_keypad.key[i].kchar == 1) && (kp_keypad.key[i].kstate == PRESSED || kp_keypad.key[i].kstate == HOLD)) - { - reboot += 1; - } - if ((kp_keypad.key[i].kchar == 4) && (kp_keypad.key[i].kstate == PRESSED || kp_keypad.key[i].kstate == HOLD)) - { - reboot += 1; - } - if ((kp_keypad.key[i].kchar == 10) && (kp_keypad.key[i].kstate == PRESSED || kp_keypad.key[i].kstate == HOLD)) - { - reboot += 1; - } - if ((kp_keypad.key[i].kchar == 11) && (kp_keypad.key[i].kstate == PRESSED || kp_keypad.key[i].kstate == HOLD)) - { - reboot += 1; - } - } - if (reboot == 4) - { - _reboot_Teensyduino_(); - } - - /* Enter calibration mode if all calibration-buttons is pressed together */ - int calibrate = 0; - for (int i = 0; i < LIST_MAX; i++) - { - if ((kp_keypad.key[i].kchar == 2) && (kp_keypad.key[i].kstate == PRESSED || kp_keypad.key[i].kstate == HOLD)) - { - calibrate += 1; - } - if ((kp_keypad.key[i].kchar == 3) && (kp_keypad.key[i].kstate == PRESSED || kp_keypad.key[i].kstate == HOLD)) - { - calibrate += 1; - } - if ((kp_keypad.key[i].kchar == 10) && (kp_keypad.key[i].kstate == PRESSED || kp_keypad.key[i].kstate == HOLD)) - { - calibrate += 1; - } - if ((kp_keypad.key[i].kchar == 11) && (kp_keypad.key[i].kstate == PRESSED || kp_keypad.key[i].kstate == HOLD)) - { - calibrate += 1; - } - } - if (calibrate == 4) - { - joystick_calibration_mode = CALIBRATION_CENTER; - } - - /* Check for Fn mode */ - fn_mode = 0; - for (int i = 0; i < LIST_MAX; i++) - { - if (kp_keypad.key[i].kstate == PRESSED || kp_keypad.key[i].kstate == HOLD) - { - for (int j = 0; j < NBR_OF_BUTTONS; j++) - { - if (buttons[j].keypad_kchar == kp_keypad.key[i].kchar) - { - /* Check if FN1 key are defined to this button (Layer 0 and first position in combo array)*/ - if (buttons[j].keycode == KEY_FN1) - { - fn_mode++; - } - break; - } - } - } - } - - /* Process key press/release */ - for (int i = 0; i < LIST_MAX; i++) - { - if (kp_keypad.key[i].kstate == PRESSED) - { - for (int j = 0; j < NBR_OF_BUTTONS; j++) - { - if (buttons[j].keypad_kchar == kp_keypad.key[i].kchar && kp_keypad.key[i].stateChanged == true) - { - buttons[j].run_keycode = true; - buttons[j].kstate = PRESSED; - break; - } - } - } - else if (kp_keypad.key[i].kstate == RELEASED) - { - for (int j = 0; j < NBR_OF_BUTTONS; j++) - { - if (buttons[j].keypad_kchar == kp_keypad.key[i].kchar && kp_keypad.key[i].stateChanged == true) - { - buttons[j].run_keycode = true; - buttons[j].kstate = RELEASED; - break; - } - } - } - } - - - /* Check if any "non tap keys" has been pressed */ - for (int i = 0; i < NBR_OF_BUTTONS; i++) - { - if (buttons[i].run_keycode == true && buttons[i].tap_keycode == NO_KEY && buttons[i].kstate == PRESSED) - { - for (int j = 0; j < NBR_OF_BUTTONS; j++) - { - if (buttons[j].tap_keycode != NO_KEY) - { - buttons[j].tap_inhibit = true; - } - } - } - } - - /* Execute key commands */ - for (int i = 0; i < NBR_OF_BUTTONS; i++) - { - /* Check if key should be processed */ - if (buttons[i].run_keycode == true) - { - /* Check if key pressed or released */ - if (buttons[i].kstate == PRESSED) - { - if (fn_mode == 0) - { - set_key(buttons[i].keycode, PRESSED); - buttons[i].last_keycode = buttons[i].keycode; - } - else if (fn_mode == 1) - { - set_key(buttons[i].fn1_keycode, PRESSED); - buttons[i].last_keycode = buttons[i].fn1_keycode; - } - else if (fn_mode == 2) - { - set_key(buttons[i].fn2_keycode, PRESSED); - buttons[i].last_keycode = buttons[i].fn2_keycode; - } - } - else if (buttons[i].kstate == RELEASED) - { - /* Sending release command for last keycode related to this button */ - set_key(buttons[i].last_keycode, RELEASED); - } - /* Reset run_keycode flag */ - buttons[i].run_keycode = false; - } - } - - } +// Prepare CRSF setup packet +void crsf_prepare_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) { + packet_cmd[0] = ELRS_ADDRESS; // Header + packet_cmd[1] = 6; // length + packet_cmd[2] = ELRS_TYPE_SETTINGS_WRITE; + packet_cmd[3] = ELRS_ADDRESS; + packet_cmd[4] = ELRS_ADDR_RADIO; + packet_cmd[5] = command; + packet_cmd[6] = value; + packet_cmd[7] = crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); } void setup() @@ -784,59 +717,97 @@ void setup() /* Init HW */ pinMode(STATUS_LED, OUTPUT); digitalWrite(STATUS_LED, LOW); + + pinMode(BUTTON_LED_1, OUTPUT); + digitalWrite(BUTTON_LED_1, LOW); + + pinMode(BUTTON_LED_2, OUTPUT); + digitalWrite(BUTTON_LED_2, LOW); + + pinMode(BUTTON_FLD, INPUT_PULLUP); + pinMode(BUTTON_FLU, INPUT_PULLUP); + pinMode(BUTTON_FRD, INPUT_PULLUP); + pinMode(BUTTON_FRU, INPUT_PULLUP); + pinMode(BUTTON_TLD, INPUT_PULLUP); + pinMode(BUTTON_TRD, INPUT_PULLUP); + pinMode(BUTTON_TLU, INPUT_PULLUP); + pinMode(BUTTON_TRU, INPUT_PULLUP); // Set ADC resolution to 12bit analogReadResolution(12); analogReadAveraging(32); delay(500); + // Init EEPROM + load_from_eeprom(); + // Init Joystick Joystick.useManualSend(true); + // Check if calibration mode is enabled + if (digitalRead(BUTTON_TLD) == LOW){ + joystick_calibration_mode = CALIBRATION_INIT; + } + + // Check if bootloader mode is enabled + if (digitalRead(BUTTON_TRD) == LOW){ + _reboot_Teensyduino_(); + } + + // Init ELRS + ELRS_SERIAL_PORT.begin(ELRS_SERIAL_BAUDRATE); } void loop() { /* Update current time (ms) */ current_timestamp = millis(); + /* Update current time (us) */ + current_timestamp_micros = micros(); - /* Scan buttons 1ms */ - if (current_timestamp >= button_timestamp) + /* Read io value and process as fast as possible */ + read_io_data(); + + /* Send data every 1500us */ + if (current_timestamp_micros >= elrs_timestamp_micros) { - button_timestamp = current_timestamp + 100; - update_analog(); - //scan_buttons(); - - // ---------------------------------------------------------- - // Update joystick axis data - // ---------------------------------------------------------- - Joystick.X(joystick_x1); - Joystick.Y(joystick_y1); - - if (fn_mode == 2){ - Joystick.Z(HID_AXIS_CENTER); - Joystick.Zrotate(HID_AXIS_CENTER); - Joystick.sliderLeft(joystick_x2); - Joystick.sliderRight(joystick_y2); - } - else if (fn_mode == 1){ - Joystick.Z(HID_AXIS_CENTER); - Joystick.Zrotate(joystick_y2); - Joystick.sliderLeft(joystick_x2); - Joystick.sliderRight(HID_AXIS_CENTER); - } - else{ - Joystick.Z(joystick_x2); - Joystick.Zrotate(joystick_y2); - Joystick.sliderLeft(joystick_x3); - Joystick.sliderRight(joystick_x3); - } + process_io_data(); + + // Send USB Joystick data Joystick.send_now(); + + // Send ELRS data + if (elrs_init_done == true){ + crsf_prepare_data_packet(crsf_packet, elrs_channels); + ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); + } + else{ + if (elrs_init_counter < 500){ + crsf_prepare_data_packet(crsf_cmd_packet, elrs_channels); + ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + elrs_init_counter++; + } + else if (elrs_init_counter < 505){ + crsf_prepare_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, ELRS_PKT_RATE); + ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + elrs_init_counter++; + } + else if (elrs_init_counter < 510){ + crsf_prepare_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, ELRS_POWER); + ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + elrs_init_counter++; + } + else{ + elrs_init_done = true; + } + } + elrs_timestamp_micros = current_timestamp_micros + CRSF_TIME_BETWEEN_FRAMES_US; } /* Update indicator 200ms */ if (current_timestamp >= indicator_timestamp) { + /* Update status led */ if (status_led_mode == 2 && status_led_on == false) { digitalWrite(STATUS_LED, HIGH); @@ -858,6 +829,50 @@ void loop() status_led_on = false; } + /* Updated button led 1 */ + if (button_led_1_mode == 2 && button_led_1_on == false) + { + digitalWrite(BUTTON_LED_1, HIGH); + button_led_1_on = true; + } + else if (button_led_1_mode == 2 && button_led_1_on == true) + { + digitalWrite(BUTTON_LED_1, LOW); + button_led_1_on = false; + } + else if (button_led_1_mode == 1) + { + digitalWrite(BUTTON_LED_1, HIGH); + button_led_1_on = true; + } + else + { + digitalWrite(BUTTON_LED_1, LOW); + button_led_1_on = false; + } + + /* Updated button led 2 */ + if (button_led_2_mode == 2 && button_led_2_on == false) + { + digitalWrite(BUTTON_LED_2, HIGH); + button_led_2_on = true; + } + else if (button_led_2_mode == 2 && button_led_2_on == true) + { + digitalWrite(BUTTON_LED_2, LOW); + button_led_2_on = false; + } + else if (button_led_2_mode == 1) + { + digitalWrite(BUTTON_LED_2, HIGH); + button_led_2_on = true; + } + else + { + digitalWrite(BUTTON_LED_2, LOW); + button_led_2_on = false; + } + indicator_timestamp = current_timestamp + 200; } } From 3f0f19cfde605d517e7bb34aac7bf9d2fa18948c Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 15 May 2023 15:33:37 +0000 Subject: [PATCH 02/29] Code cleanup --- firmware/src/main.cpp | 535 ++++++++++++++++++++++-------------------- 1 file changed, 276 insertions(+), 259 deletions(-) diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index 123f8f0..ee07593 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -150,12 +150,12 @@ bool button_led_2_on = false; int button_led_2_mode = 0; unsigned long current_timestamp = 0; -unsigned long button_timestamp = 0; -unsigned long joystick_timestamp = 0; +unsigned long led_timestamp = 0; unsigned long indicator_timestamp = 0; +unsigned long send_usb_timestamp = 0; unsigned long current_timestamp_micros = 0; -unsigned long elrs_timestamp_micros = 0; +unsigned long send_elrs_timestamp_micros = 0; const int BUTTON_FLU = 4; // Front left upper button const int BUTTON_FLD = 5; // Front left lower button @@ -166,9 +166,9 @@ const int BUTTON_TRU = 10; // Top upper right button const int BUTTON_TLD = 8; // Top left lower button const int BUTTON_TRD = 11; // Top right lower button -bool toggle_button_10 = false; -bool toggle_button_11 = false; -int button_10_previous_value = HIGH; +bool toggle_button_arm = false; +bool toggle_button_mode = false; +int button_arm_previous_value = HIGH; int button_11_previous_value = HIGH; #define HID_AXIS_MAX 1023 @@ -180,14 +180,6 @@ int button_11_previous_value = HIGH; #define DEADZONE_X 50 #define DEADZONE_Y 50 -// USB HID data variables -int xy_x1 = HID_AXIS_CENTER; -int xy_y1 = HID_AXIS_CENTER; -int xy_x2 = HID_AXIS_CENTER; -int xy_y2 = HID_AXIS_CENTER; -int xy_x3 = HID_AXIS_CENTER; -int xy_y3 = HID_AXIS_CENTER; - enum EEPROM_ADR { MAX_X1_ADR_HIGH, @@ -219,21 +211,27 @@ enum EEPROM_ADR int joystick_counter = 0; int joystick_x1 = 0; +int joystick_x1_hid = 0; int joystick_x1_raw = 0; int joystick_x1_max = 4096; int joystick_x1_min = 0; int joystick_x1_center = joystick_x1_max/2; int joystick_y1 = 0; +int joystick_y1_hid = 0; +int joystick_y1_hid_rev = 0; +int joystick_y1_hid_rev_mode = 0; int joystick_y1_raw = 0; int joystick_y1_max = 4096; int joystick_y1_min = 0; int joystick_y1_center = joystick_y1_max/2; int joystick_x2 = 0; +int joystick_x2_hid = 0; int joystick_x2_raw = 0; int joystick_x2_max = 4096; int joystick_x2_min = 0; int joystick_x2_center = joystick_x2_max/2; int joystick_y2 = 0; +int joystick_y2_hid = 0; int joystick_y2_raw = 0; int joystick_y2_max = 4096; int joystick_y2_min = 0; @@ -241,6 +239,8 @@ int joystick_y2_center = joystick_y2_max/2; float exp_constant = 0.2; +int fn_mode = 0; + #define CALIBRATION_OFF 0 #define CALIBRATION_INIT 1 #define CALIBRATION_CENTER 2 @@ -309,194 +309,6 @@ void load_from_eeprom(){ joystick_y2_center |= EEPROM.read(CNT_Y2_ADR_LOW); } -void process_io_data(){ - - // Check for calibration mode - if (joystick_calibration_mode == CALIBRATION_INIT){ - if (digitalRead(BUTTON_TLD) == HIGH){ - joystick_calibration_mode = CALIBRATION_CENTER; - } - return; - } - if (joystick_calibration_mode == CALIBRATION_CENTER){ - button_led_1_mode = 2; - button_led_2_mode = 0; - if (digitalRead(BUTTON_TLD) == LOW){ - joystick_calibration_mode = CALIBRATION_MINMAX; - button_led_1_mode = 0; - } - return; - } - if (joystick_calibration_mode == CALIBRATION_MINMAX){ - button_led_1_mode = 0; - button_led_2_mode = 2; - if (digitalRead(BUTTON_TRD) == LOW){ - joystick_calibration_mode = CALIBRATION_OFF; - save_to_eeprom(); - button_led_2_mode = 0; - } - return; - } - - // Check fn mode - int fn_mode = 0; - if (digitalRead(BUTTON_TLU) == LOW){ - fn_mode = 1; - if (digitalRead(BUTTON_TRU) == LOW){ - fn_mode = 2; - } - } - - // Check toggle buttons - if (fn_mode == 1){ - if (digitalRead(BUTTON_TLD) != button_10_previous_value){ - button_10_previous_value = digitalRead(BUTTON_TLD); - if (digitalRead(BUTTON_TLD) == LOW){ - if (toggle_button_10 == false){ - toggle_button_10 = true; - button_led_1_mode = 1; - } - else{ - toggle_button_10 = false; - button_led_1_mode = 0; - } - } - } - if (digitalRead(BUTTON_TRD) != button_11_previous_value){ - button_11_previous_value = digitalRead(BUTTON_TRD); - if (digitalRead(BUTTON_TRD) == LOW){ - if (toggle_button_11 == false){ - toggle_button_11 = true; - button_led_2_mode = 1; - } - else{ - toggle_button_11 = false; - button_led_2_mode = 0; - } - } - } - } - - // Set joystick buttons to released - for (int i = 1; i < 32; i++){ - Joystick.button(i, 0); - } - - // Set joystick hat to center position - Joystick.hat(-1); - - // Set joystick buttons to pressed - if (fn_mode == 2){ - - if (digitalRead(BUTTON_FLD) == LOW){ - Joystick.button(12, 1); - } - if (digitalRead(BUTTON_FRD) == LOW){ - Joystick.button(13, 1); - } - if (digitalRead(BUTTON_TLD) == LOW){ - Joystick.button(14, 1); - } - if (digitalRead(BUTTON_TRD) == LOW){ - Joystick.button(15, 1); - } - } - else if (fn_mode == 1){ - - if (digitalRead(BUTTON_FLD) == LOW){ - Joystick.button(8, 1); - } - if (digitalRead(BUTTON_FRD) == LOW){ - Joystick.button(9, 1); - } - } - else{ - if (digitalRead(BUTTON_FLD) == LOW){ - Joystick.button(2, 1); - } - if (digitalRead(BUTTON_FRD) == LOW){ - Joystick.button(4, 1); - } - if (digitalRead(BUTTON_TRU) == LOW){ - Joystick.button(5, 1); - } - if (digitalRead(BUTTON_TLD) == LOW){ - Joystick.button(6, 1); - } - if (digitalRead(BUTTON_TRD) == LOW){ - Joystick.button(7, 1); - } - } - - if (digitalRead(BUTTON_FLU) == LOW){ - Joystick.button(1, 1); - } - if (digitalRead(BUTTON_FRU) == LOW){ - Joystick.button(3, 1); - } - if (toggle_button_10){ - Joystick.button(10, 1); - } - if (toggle_button_11){ - Joystick.button(11, 1); - } - - // Set axis values - Joystick.X(joystick_x1); - Joystick.Y(joystick_y1); - - if (fn_mode == 2){ - Joystick.Z(HID_AXIS_CENTER); - Joystick.Zrotate(HID_AXIS_CENTER); - Joystick.sliderLeft(joystick_x2); - Joystick.sliderRight(joystick_y2); - } - else if (fn_mode == 1){ - Joystick.Z(HID_AXIS_CENTER); - Joystick.Zrotate(joystick_y2); - Joystick.sliderLeft(joystick_x2); - Joystick.sliderRight(HID_AXIS_CENTER); - } - else{ - Joystick.Z(joystick_x2); - Joystick.Zrotate(joystick_y2); - Joystick.sliderLeft(HID_AXIS_CENTER); - Joystick.sliderRight(HID_AXIS_CENTER); - } - - // Set ELRS analog channels - elrs_channels[0] = map(joystick_x1, HID_AXIS_MIN, HID_AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); - elrs_channels[1] = map(joystick_y1, HID_AXIS_MIN, HID_AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); - elrs_channels[2] = map(joystick_x2, HID_AXIS_MIN, HID_AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); - elrs_channels[3] = map(joystick_y2, HID_AXIS_MIN, HID_AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); - - // Set ELRS digital channels - for (int i = 4; i < CRSF_MAX_CHANNEL; i++){ - elrs_channels[i] = CRSF_DIGITAL_CHANNEL_MIN; - } - if (toggle_button_10){ - elrs_channels[4] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (toggle_button_11){ - elrs_channels[5] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (digitalRead(BUTTON_FLU) == LOW){ - elrs_channels[6] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (digitalRead(BUTTON_FLD) == LOW){ - elrs_channels[7] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (digitalRead(BUTTON_FRU) == LOW){ - elrs_channels[8] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (digitalRead(BUTTON_FRD) == LOW){ - elrs_channels[9] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (digitalRead(BUTTON_TRU) == LOW){ - elrs_channels[10] = CRSF_DIGITAL_CHANNEL_MAX; - } -} - void read_io_data(){ if(joystick_counter == 0){ @@ -529,14 +341,11 @@ void read_io_data(){ } // Calculate Y1 joystick values - if(joystick_y1_raw > (joystick_y1_center + DEADZONE_Y)){ - joystick_y1 = constrain(map(joystick_y1_raw, (joystick_y1_center + DEADZONE_Y), joystick_y1_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); - } - else if(joystick_y1_raw < (joystick_y1_center - DEADZONE_Y)){ - joystick_y1 = constrain(map(joystick_y1_raw, joystick_y1_min, (joystick_y1_center - DEADZONE_Y), AXIS_MIN, AXIS_CENTER), AXIS_MIN, AXIS_CENTER); + if(joystick_y1_raw > (joystick_y1_min + DEADZONE_Y)){ + joystick_y1 = constrain(map(joystick_y1_raw, (joystick_y1_min + DEADZONE_Y), joystick_y1_max, AXIS_MIN, AXIS_MAX), AXIS_MIN, AXIS_MAX); } else{ - joystick_y1 = AXIS_CENTER; + joystick_y1 = AXIS_MIN; } // Calculate X2 joystick values @@ -565,56 +374,90 @@ void read_io_data(){ if (joystick_x1 != AXIS_CENTER){ float joystick_x_float = joystick_x1 / float(AXIS_MAX); float joystick_x_exp = exp_constant * (0.5 + 256 * pow((joystick_x_float - 0.5),9)) + (1 - exp_constant) * joystick_x_float; - joystick_x1 = int(joystick_x_exp * float(HID_AXIS_MAX)); - joystick_x1 = constrain(joystick_x1, HID_AXIS_MIN, HID_AXIS_MAX); + joystick_x1_hid = int(joystick_x_exp * float(HID_AXIS_MAX)); + joystick_x1_hid = constrain(joystick_x1_hid, HID_AXIS_MIN, HID_AXIS_MAX); } else{ - joystick_x1 = HID_AXIS_CENTER; + joystick_x1_hid = HID_AXIS_CENTER; } - // Calculate new Y1 values after applying exp curve - if (joystick_y1 != AXIS_CENTER){ - float joystick_y_float = joystick_y1 / float(AXIS_MAX); - float joystick_y_exp = exp_constant * (0.5 + 256 * pow((joystick_y_float - 0.5),9)) + (1 - exp_constant) * joystick_y_float; - joystick_y1 = int(joystick_y_exp * float(HID_AXIS_MAX)); - joystick_y1 = constrain(joystick_y1, HID_AXIS_MIN, HID_AXIS_MAX); - } - else{ - joystick_y1 = HID_AXIS_CENTER; - } + // Calculate new Y1 values + joystick_y1_hid = map(joystick_y1, AXIS_MIN, AXIS_MAX, HID_AXIS_CENTER, HID_AXIS_MAX); + joystick_y1_hid_rev = map(joystick_y1, AXIS_MIN, AXIS_MAX, HID_AXIS_CENTER, HID_AXIS_MIN); // Calculate new X2 values after applying exp curve if (joystick_x2 != AXIS_CENTER){ float joystick_x_float = joystick_x2 / float(AXIS_MAX); float joystick_x_exp = exp_constant * (0.5 + 256 * pow((joystick_x_float - 0.5),9)) + (1 - exp_constant) * joystick_x_float; - joystick_x2 = int(joystick_x_exp * float(HID_AXIS_MAX)); - joystick_x2 = constrain(joystick_x2, HID_AXIS_MIN, HID_AXIS_MAX); + joystick_x2_hid = int(joystick_x_exp * float(HID_AXIS_MAX)); + joystick_x2_hid = constrain(joystick_x2_hid, HID_AXIS_MIN, HID_AXIS_MAX); } else{ - joystick_x2 = HID_AXIS_CENTER; + joystick_x2_hid = HID_AXIS_CENTER; } // Calculate new Y2 values after applying exp curve if (joystick_y2 != AXIS_CENTER){ float joystick_y_float = joystick_y2 / float(AXIS_MAX); float joystick_y_exp = exp_constant * (0.5 + 256 * pow((joystick_y_float - 0.5),9)) + (1 - exp_constant) * joystick_y_float; - joystick_y2 = int(joystick_y_exp * float(HID_AXIS_MAX)); - joystick_y2 = constrain(joystick_y2, HID_AXIS_MIN, HID_AXIS_MAX); + joystick_y2_hid = int(joystick_y_exp * float(HID_AXIS_MAX)); + joystick_y2_hid = constrain(joystick_y2_hid, HID_AXIS_MIN, HID_AXIS_MAX); } else{ - joystick_y2 = HID_AXIS_CENTER; + joystick_y2_hid = HID_AXIS_CENTER; + } + + // Check fn mode + fn_mode = 0; + if (digitalRead(BUTTON_TLU) == LOW){ + fn_mode = 1; + if (digitalRead(BUTTON_TRU) == LOW){ + fn_mode = 2; + } + } + + // Check toggle buttons + if (digitalRead(BUTTON_FLU) == LOW){ + toggle_button_mode = true; + } + else if (digitalRead(BUTTON_FLD) == LOW){ + toggle_button_mode = false; + } + + if (fn_mode == 2){ + if (digitalRead(BUTTON_TRD) != button_arm_previous_value){ + button_arm_previous_value = digitalRead(BUTTON_TRD); + if (digitalRead(BUTTON_TRD) == LOW){ + if (toggle_button_arm == false){ + toggle_button_arm = true; + } + else{ + toggle_button_arm = false; + } + } + } } } else{ // Calibration mode. - joystick_x1 = HID_AXIS_CENTER; - joystick_y1 = HID_AXIS_CENTER; - joystick_x2 = HID_AXIS_CENTER; - joystick_y2 = HID_AXIS_CENTER; + joystick_x1 = AXIS_CENTER; + joystick_y1 = AXIS_CENTER; + joystick_x2 = AXIS_CENTER; + joystick_y2 = AXIS_CENTER; + joystick_x1_hid = HID_AXIS_CENTER; + joystick_y1_hid = HID_AXIS_CENTER; + joystick_x2_hid = HID_AXIS_CENTER; + joystick_y2_hid = HID_AXIS_CENTER; + // Check for calibration mode + if (joystick_calibration_mode == CALIBRATION_INIT){ + if (digitalRead(BUTTON_TLD) == HIGH){ + joystick_calibration_mode = CALIBRATION_CENTER; + } + } // Calibrate joystick center values - if (joystick_calibration_mode == CALIBRATION_CENTER){ + else if (joystick_calibration_mode == CALIBRATION_CENTER){ joystick_x1_center = joystick_x1_raw; joystick_y1_center = joystick_y1_raw; joystick_x1_max = joystick_x1_center; @@ -628,6 +471,10 @@ void read_io_data(){ joystick_x2_min = joystick_x2_center; joystick_y2_max = joystick_y2_center; joystick_y2_min = joystick_y2_center; + + if (digitalRead(BUTTON_TLD) == LOW){ + joystick_calibration_mode = CALIBRATION_MINMAX; + } } // Calibrate joystick min/max values else if (joystick_calibration_mode == CALIBRATION_MINMAX){ @@ -656,6 +503,11 @@ void read_io_data(){ if(joystick_y2_raw < joystick_y2_min){ joystick_y2_min = joystick_y2_raw; } + + if (digitalRead(BUTTON_TRD) == LOW){ + joystick_calibration_mode = CALIBRATION_OFF; + save_to_eeprom(); + } } } } @@ -751,6 +603,8 @@ void setup() // Check if bootloader mode is enabled if (digitalRead(BUTTON_TRD) == LOW){ + digitalWrite(BUTTON_LED_2, HIGH); + delay(200); _reboot_Teensyduino_(); } @@ -768,13 +622,146 @@ void loop() /* Read io value and process as fast as possible */ read_io_data(); - /* Send data every 1500us */ - if (current_timestamp_micros >= elrs_timestamp_micros) + if (current_timestamp >= send_usb_timestamp) { - process_io_data(); + // Set joystick buttons to released + for (int i = 1; i < 32; i++){ + Joystick.button(i, 0); + } + // Set joystick hat to center position + Joystick.hat(-1); + + // Set joystick buttons to pressed + if (fn_mode == 2){ + + if (digitalRead(BUTTON_FLD) == LOW){ + Joystick.button(12, 1); + } + if (digitalRead(BUTTON_FRD) == LOW){ + Joystick.button(13, 1); + } + if (digitalRead(BUTTON_TLD) == LOW){ + Joystick.button(14, 1); + } + } + else if (fn_mode == 1){ + + if (digitalRead(BUTTON_FLD) == LOW){ + Joystick.button(8, 1); + } + if (digitalRead(BUTTON_FRD) == LOW){ + Joystick.button(9, 1); + } + if (digitalRead(BUTTON_TLD) == LOW){ + Joystick.button(10, 1); + } + if (digitalRead(BUTTON_TRD) == LOW){ + Joystick.button(11, 1); + } + } + else{ + + if (digitalRead(BUTTON_FLD) == LOW){ + Joystick.button(2, 1); + } + if (digitalRead(BUTTON_FRD) == LOW){ + Joystick.button(4, 1); + } + if (digitalRead(BUTTON_TRU) == LOW){ + Joystick.button(5, 1); + } + if (digitalRead(BUTTON_TLD) == LOW){ + Joystick.button(6, 1); + } + if (digitalRead(BUTTON_TRD) == LOW){ + Joystick.button(7, 1); + } + } + + if (digitalRead(BUTTON_FLU) == LOW){ + Joystick.button(1, 1); + } + if (digitalRead(BUTTON_FRU) == LOW){ + Joystick.button(3, 1); + } + if (toggle_button_arm){ + Joystick.button(15, 1); + } + + // Check rev mode (reverse stick for Y1 axix) + if (joystick_y1 == AXIS_MIN){ + joystick_y1_hid_rev_mode = 1; + } + else if ((joystick_y1 > AXIS_MIN) && (fn_mode <= 1) && (joystick_y1_hid_rev_mode == 1)){ + joystick_y1_hid_rev_mode = 0; + } + else if ((joystick_y1 > AXIS_MIN) && (fn_mode > 1) && (joystick_y1_hid_rev_mode == 1)){ + joystick_y1_hid_rev_mode = 2; + } + + // Set axis values + if (joystick_y1_hid_rev_mode == 0){ + Joystick.Y(joystick_y1_hid); + } + else if (joystick_y1_hid_rev_mode == 2){ + Joystick.Y(joystick_y1_hid_rev); + } + + Joystick.X(joystick_x1_hid); + + if (fn_mode == 2){ + Joystick.Z(HID_AXIS_CENTER); + Joystick.Zrotate(HID_AXIS_CENTER); + Joystick.sliderLeft(joystick_x2_hid); + Joystick.sliderRight(joystick_y2_hid); + } + else if (fn_mode == 1){ + Joystick.Z(HID_AXIS_CENTER); + Joystick.Zrotate(joystick_y2_hid); + Joystick.sliderLeft(joystick_x2_hid); + Joystick.sliderRight(HID_AXIS_CENTER); + } + else{ + Joystick.Z(joystick_x2_hid); + Joystick.Zrotate(joystick_y2_hid); + Joystick.sliderLeft(HID_AXIS_CENTER); + Joystick.sliderRight(HID_AXIS_CENTER); + } + // Send USB Joystick data Joystick.send_now(); + send_usb_timestamp = current_timestamp + 5; + } + + /* Send data every CRSF_TIME_BETWEEN_FRAMES_US */ + if (current_timestamp_micros >= send_elrs_timestamp_micros) + { + // Set ELRS analog channels + elrs_channels[0] = map(joystick_x1, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + elrs_channels[1] = map(joystick_y1, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + elrs_channels[2] = map(joystick_x2, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + elrs_channels[3] = map(joystick_y2, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + + // Set ELRS digital channels + for (int i = 4; i < CRSF_MAX_CHANNEL; i++){ + elrs_channels[i] = CRSF_DIGITAL_CHANNEL_MIN; + } + if (toggle_button_arm){ + elrs_channels[4] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (toggle_button_mode){ + elrs_channels[5] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (digitalRead(BUTTON_FRU) == LOW){ + elrs_channels[6] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (digitalRead(BUTTON_FRD) == LOW){ + elrs_channels[7] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (digitalRead(BUTTON_TRU) == LOW){ + elrs_channels[8] = CRSF_DIGITAL_CHANNEL_MAX; + } // Send ELRS data if (elrs_init_done == true){ @@ -782,16 +769,19 @@ void loop() ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); } else{ + // Setting up initial communication link between ERLS TX and Teensy (give ERLS TX time to auto detect Teensy) if (elrs_init_counter < 500){ - crsf_prepare_data_packet(crsf_cmd_packet, elrs_channels); - ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + crsf_prepare_data_packet(crsf_packet, elrs_channels); + ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); elrs_init_counter++; } + // Send command to update TX packet rate to 500Hz else if (elrs_init_counter < 505){ crsf_prepare_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, ELRS_PKT_RATE); ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); elrs_init_counter++; } + // Send command to update TX power to 100mW else if (elrs_init_counter < 510){ crsf_prepare_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, ELRS_POWER); ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); @@ -801,33 +791,32 @@ void loop() elrs_init_done = true; } } - elrs_timestamp_micros = current_timestamp_micros + CRSF_TIME_BETWEEN_FRAMES_US; + send_elrs_timestamp_micros = current_timestamp_micros + CRSF_TIME_BETWEEN_FRAMES_US; } - - /* Update indicator 200ms */ - if (current_timestamp >= indicator_timestamp) + + /* Update leds 200ms */ + if (current_timestamp >= led_timestamp) { - /* Update status led */ - if (status_led_mode == 2 && status_led_on == false) - { - digitalWrite(STATUS_LED, HIGH); - status_led_on = true; + // Set led mode + button_led_1_mode = 0; + button_led_2_mode = 0; + + if (joystick_calibration_mode == CALIBRATION_INIT){ + button_led_1_mode = 1; + button_led_2_mode = 1; } - else if (status_led_mode == 2 && status_led_on == true) - { - digitalWrite(STATUS_LED, LOW); - status_led_on = false; + else if (joystick_calibration_mode == CALIBRATION_CENTER){ + button_led_1_mode = 2; + button_led_2_mode = 0; } - else if (status_led_mode == 1) - { - digitalWrite(STATUS_LED, HIGH); - status_led_on = true; - } - else - { - digitalWrite(STATUS_LED, LOW); - status_led_on = false; + else if (joystick_calibration_mode == CALIBRATION_MINMAX){ + button_led_1_mode = 0; + button_led_2_mode = 2; } + else if (joystick_y1_hid_rev_mode == 2){ + button_led_1_mode = 2; + button_led_2_mode = 2; + } /* Updated button led 1 */ if (button_led_1_mode == 2 && button_led_1_on == false) @@ -873,6 +862,34 @@ void loop() button_led_2_on = false; } + led_timestamp = current_timestamp + 200; + } + + /* Update indicator 200ms */ + if (current_timestamp >= indicator_timestamp) + { + /* Update status led */ + if (status_led_mode == 2 && status_led_on == false) + { + digitalWrite(STATUS_LED, HIGH); + status_led_on = true; + } + else if (status_led_mode == 2 && status_led_on == true) + { + digitalWrite(STATUS_LED, LOW); + status_led_on = false; + } + else if (status_led_mode == 1) + { + digitalWrite(STATUS_LED, HIGH); + status_led_on = true; + } + else + { + digitalWrite(STATUS_LED, LOW); + status_led_on = false; + } + indicator_timestamp = current_timestamp + 200; } } From e89ffee2215c8cbe0725927e56849479c1d8c579 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 15 May 2023 19:05:40 +0000 Subject: [PATCH 03/29] Changed toggle for USB --- firmware/src/main.cpp | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index ee07593..1abf9f7 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -382,8 +382,7 @@ void read_io_data(){ } // Calculate new Y1 values - joystick_y1_hid = map(joystick_y1, AXIS_MIN, AXIS_MAX, HID_AXIS_CENTER, HID_AXIS_MAX); - joystick_y1_hid_rev = map(joystick_y1, AXIS_MIN, AXIS_MAX, HID_AXIS_CENTER, HID_AXIS_MIN); + joystick_y1_hid = map(joystick_y1, AXIS_MIN, AXIS_MAX, HID_AXIS_MIN, HID_AXIS_MAX); // Calculate new X2 values after applying exp curve if (joystick_x2 != AXIS_CENTER){ @@ -424,7 +423,7 @@ void read_io_data(){ toggle_button_mode = false; } - if (fn_mode == 2){ + if (fn_mode == 1){ if (digitalRead(BUTTON_TRD) != button_arm_previous_value){ button_arm_previous_value = digitalRead(BUTTON_TRD); if (digitalRead(BUTTON_TRD) == LOW){ @@ -644,6 +643,9 @@ void loop() if (digitalRead(BUTTON_TLD) == LOW){ Joystick.button(14, 1); } + if (digitalRead(BUTTON_TRD) == LOW){ + Joystick.button(15, 1); + } } else if (fn_mode == 1){ @@ -685,29 +687,9 @@ void loop() if (digitalRead(BUTTON_FRU) == LOW){ Joystick.button(3, 1); } - if (toggle_button_arm){ - Joystick.button(15, 1); - } - - // Check rev mode (reverse stick for Y1 axix) - if (joystick_y1 == AXIS_MIN){ - joystick_y1_hid_rev_mode = 1; - } - else if ((joystick_y1 > AXIS_MIN) && (fn_mode <= 1) && (joystick_y1_hid_rev_mode == 1)){ - joystick_y1_hid_rev_mode = 0; - } - else if ((joystick_y1 > AXIS_MIN) && (fn_mode > 1) && (joystick_y1_hid_rev_mode == 1)){ - joystick_y1_hid_rev_mode = 2; - } // Set axis values - if (joystick_y1_hid_rev_mode == 0){ - Joystick.Y(joystick_y1_hid); - } - else if (joystick_y1_hid_rev_mode == 2){ - Joystick.Y(joystick_y1_hid_rev); - } - + Joystick.Y(joystick_y1_hid); Joystick.X(joystick_x1_hid); if (fn_mode == 2){ @@ -813,10 +795,11 @@ void loop() button_led_1_mode = 0; button_led_2_mode = 2; } - else if (joystick_y1_hid_rev_mode == 2){ - button_led_1_mode = 2; - button_led_2_mode = 2; - } + else if ((joystick_x1 != AXIS_CENTER) || (joystick_y1 != AXIS_MIN) || + (joystick_x2 != AXIS_CENTER) || (joystick_y2 != AXIS_CENTER)){ + button_led_1_mode = 1; + button_led_2_mode = 1; + } /* Updated button led 1 */ if (button_led_1_mode == 2 && button_led_1_on == false) From 218e3a9048443f9036c368269c32452d6ea7f529 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 16 May 2023 09:10:48 +0000 Subject: [PATCH 04/29] Changed to ResponsiveAnalogRead library for all analog inputs --- firmware/src/ResponsiveAnalogRead.cpp | 140 ++++++++++++++++++++++++++ firmware/src/ResponsiveAnalogRead.h | 89 ++++++++++++++++ firmware/src/main.cpp | 24 ++++- 3 files changed, 249 insertions(+), 4 deletions(-) create mode 100644 firmware/src/ResponsiveAnalogRead.cpp create mode 100644 firmware/src/ResponsiveAnalogRead.h diff --git a/firmware/src/ResponsiveAnalogRead.cpp b/firmware/src/ResponsiveAnalogRead.cpp new file mode 100644 index 0000000..fa345de --- /dev/null +++ b/firmware/src/ResponsiveAnalogRead.cpp @@ -0,0 +1,140 @@ +/* + * ResponsiveAnalogRead.cpp + * Arduino library for eliminating noise in analogRead inputs without decreasing responsiveness + * + * Copyright (c) 2016 Damien Clarke + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "ResponsiveAnalogRead.h" + +void ResponsiveAnalogRead::begin(int pin, bool sleepEnable, float snapMultiplier){ + pinMode(pin, INPUT ); // ensure button pin is an input + digitalWrite(pin, LOW ); // ensure pullup is off on button pin + + this->pin = pin; + this->sleepEnable = sleepEnable; + setSnapMultiplier(snapMultiplier); + + +} + + +void ResponsiveAnalogRead::update() +{ + rawValue = analogRead(pin); + this->update(rawValue); +} + +void ResponsiveAnalogRead::update(int rawValueRead) +{ + rawValue = rawValueRead; + prevResponsiveValue = responsiveValue; + responsiveValue = getResponsiveValue(rawValue); + responsiveValueHasChanged = responsiveValue != prevResponsiveValue; +} + +int ResponsiveAnalogRead::getResponsiveValue(int newValue) +{ + // if sleep and edge snap are enabled and the new value is very close to an edge, drag it a little closer to the edges + // This'll make it easier to pull the output values right to the extremes without sleeping, + // and it'll make movements right near the edge appear larger, making it easier to wake up + if(sleepEnable && edgeSnapEnable) { + if(newValue < activityThreshold) { + newValue = (newValue * 2) - activityThreshold; + } else if(newValue > analogResolution - activityThreshold) { + newValue = (newValue * 2) - analogResolution + activityThreshold; + } + } + + // get difference between new input value and current smooth value + unsigned int diff = abs(newValue - smoothValue); + + // measure the difference between the new value and current value + // and use another exponential moving average to work out what + // the current margin of error is + errorEMA += ((newValue - smoothValue) - errorEMA) * 0.4; + + // if sleep has been enabled, sleep when the amount of error is below the activity threshold + if(sleepEnable) { + // recalculate sleeping status + sleeping = abs(errorEMA) < activityThreshold; + } + + // if we're allowed to sleep, and we're sleeping + // then don't update responsiveValue this loop + // just output the existing responsiveValue + if(sleepEnable && sleeping) { + return (int)smoothValue; + } + + // use a 'snap curve' function, where we pass in the diff (x) and get back a number from 0-1. + // We want small values of x to result in an output close to zero, so when the smooth value is close to the input value + // it'll smooth out noise aggressively by responding slowly to sudden changes. + // We want a small increase in x to result in a much higher output value, so medium and large movements are snappy and responsive, + // and aren't made sluggish by unnecessarily filtering out noise. A hyperbola (f(x) = 1/x) curve is used. + // First x has an offset of 1 applied, so x = 0 now results in a value of 1 from the hyperbola function. + // High values of x tend toward 0, but we want an output that begins at 0 and tends toward 1, so 1-y flips this up the right way. + // Finally the result is multiplied by 2 and capped at a maximum of one, which means that at a certain point all larger movements are maximally snappy + + // then multiply the input by SNAP_MULTIPLER so input values fit the snap curve better. + float snap = snapCurve(diff * snapMultiplier); + + // when sleep is enabled, the emphasis is stopping on a responsiveValue quickly, and it's less about easing into position. + // If sleep is enabled, add a small amount to snap so it'll tend to snap into a more accurate position before sleeping starts. + if(sleepEnable) { + snap *= 0.5 + 0.5; + } + + // calculate the exponential moving average based on the snap + smoothValue += (newValue - smoothValue) * snap; + + // ensure output is in bounds + if(smoothValue < 0.0) { + smoothValue = 0.0; + } else if(smoothValue > analogResolution - 1) { + smoothValue = analogResolution - 1; + } + + // expected output is an integer + return (int)smoothValue; +} + +float ResponsiveAnalogRead::snapCurve(float x) +{ + float y = 1.0 / (x + 1.0); + y = (1.0 - y) * 2.0; + if(y > 1.0) { + return 1.0; + } + return y; +} + +void ResponsiveAnalogRead::setSnapMultiplier(float newMultiplier) +{ + if(newMultiplier > 1.0) { + newMultiplier = 1.0; + } + if(newMultiplier < 0.0) { + newMultiplier = 0.0; + } + snapMultiplier = newMultiplier; +} diff --git a/firmware/src/ResponsiveAnalogRead.h b/firmware/src/ResponsiveAnalogRead.h new file mode 100644 index 0000000..15ade2b --- /dev/null +++ b/firmware/src/ResponsiveAnalogRead.h @@ -0,0 +1,89 @@ +/* + * ResponsiveAnalogRead.h + * Arduino library for eliminating noise in analogRead inputs without decreasing responsiveness + * + * Copyright (c) 2016 Damien Clarke + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef RESPONSIVE_ANALOG_READ_H +#define RESPONSIVE_ANALOG_READ_H + +#include + +class ResponsiveAnalogRead +{ + public: + + // pin - the pin to read + // sleepEnable - enabling sleep will cause values to take less time to stop changing and potentially stop changing more abruptly, + // where as disabling sleep will cause values to ease into their correct position smoothly + // snapMultiplier - a value from 0 to 1 that controls the amount of easing + // increase this to lessen the amount of easing (such as 0.1) and make the responsive values more responsive + // but doing so may cause more noise to seep through if sleep is not enabled + + ResponsiveAnalogRead(){}; //default constructor must be followed by call to begin function + ResponsiveAnalogRead(int pin, bool sleepEnable, float snapMultiplier = 0.01){ + begin(pin, sleepEnable, snapMultiplier); + }; + + void begin(int pin, bool sleepEnable, float snapMultiplier = 0.01); // use with default constructor to initialize + + inline int getValue() { return responsiveValue; } // get the responsive value from last update + inline int getRawValue() { return rawValue; } // get the raw analogRead() value from last update + inline bool hasChanged() { return responsiveValueHasChanged; } // returns true if the responsive value has changed during the last update + inline bool isSleeping() { return sleeping; } // returns true if the algorithm is currently in sleeping mode + void update(); // updates the value by performing an analogRead() and calculating a responsive value based off it + void update(int rawValueRead); // updates the value accepting a value and calculating a responsive value based off it + + void setSnapMultiplier(float newMultiplier); + inline void enableSleep() { sleepEnable = true; } + inline void disableSleep() { sleepEnable = false; } + inline void enableEdgeSnap() { edgeSnapEnable = true; } + // edge snap ensures that values at the edges of the spectrum (0 and 1023) can be easily reached when sleep is enabled + inline void disableEdgeSnap() { edgeSnapEnable = false; } + inline void setActivityThreshold(float newThreshold) { activityThreshold = newThreshold; } + // the amount of movement that must take place to register as activity and start moving the output value. Defaults to 4.0 + inline void setAnalogResolution(int resolution) { analogResolution = resolution; } + // if your ADC is something other than 10bit (1024), set that here + + private: + int pin; + int analogResolution = 1024; + float snapMultiplier; + bool sleepEnable; + float activityThreshold = 4.0; + bool edgeSnapEnable = true; + + float smoothValue; + unsigned long lastActivityMS; + float errorEMA = 0.0; + bool sleeping = false; + + int rawValue; + int responsiveValue; + int prevResponsiveValue; + bool responsiveValueHasChanged; + + int getResponsiveValue(int newValue); + float snapCurve(float x); +}; + +#endif diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index 1abf9f7..d23a1d0 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -84,6 +84,7 @@ #include #include +#include "ResponsiveAnalogRead.h" // CRSF #define CRSF_MAX_CHANNEL 16 @@ -241,6 +242,11 @@ float exp_constant = 0.2; int fn_mode = 0; +ResponsiveAnalogRead analog_x1(A0, true); +ResponsiveAnalogRead analog_y1(A1, true); +ResponsiveAnalogRead analog_x2(A2, true); +ResponsiveAnalogRead analog_y2(A3, true); + #define CALIBRATION_OFF 0 #define CALIBRATION_INIT 1 #define CALIBRATION_CENTER 2 @@ -312,19 +318,19 @@ void load_from_eeprom(){ void read_io_data(){ if(joystick_counter == 0){ - joystick_x1_raw = analogRead(0); + joystick_x1_raw = analog_x1.getValue(); joystick_counter++; } else if(joystick_counter == 1){ - joystick_y1_raw = analogRead(1); + joystick_y1_raw = analog_y1.getValue(); joystick_counter++; } else if(joystick_counter == 2){ - joystick_x2_raw = analogRead(2); + joystick_x2_raw = analog_x2.getValue(); joystick_counter++; } else if(joystick_counter == 3){ - joystick_y2_raw = analogRead(3); + joystick_y2_raw = analog_y2.getValue(); joystick_counter = 0; if (joystick_calibration_mode == CALIBRATION_OFF){ @@ -589,6 +595,11 @@ void setup() analogReadAveraging(32); delay(500); + analog_x1.setAnalogResolution(4096); + analog_y1.setAnalogResolution(4096); + analog_x2.setAnalogResolution(4096); + analog_y2.setAnalogResolution(4096); + // Init EEPROM load_from_eeprom(); @@ -619,6 +630,11 @@ void loop() current_timestamp_micros = micros(); /* Read io value and process as fast as possible */ + analog_x1.update(); + analog_y1.update(); + analog_x2.update(); + analog_y2.update(); + read_io_data(); if (current_timestamp >= send_usb_timestamp) From 0ba7584d567a4c67f8dd4f4d7fe9300ba14f7097 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 16 May 2023 20:53:44 +0000 Subject: [PATCH 05/29] Code cleanup. Added support for two different gimbal (M10 and M7) --- .../{src => lib}/ResponsiveAnalogRead.cpp | 0 firmware/{src => lib}/ResponsiveAnalogRead.h | 0 firmware/src/{main.cpp => cmdr_joystick.cpp} | 918 +++++++++--------- 3 files changed, 453 insertions(+), 465 deletions(-) rename firmware/{src => lib}/ResponsiveAnalogRead.cpp (100%) rename firmware/{src => lib}/ResponsiveAnalogRead.h (100%) rename firmware/src/{main.cpp => cmdr_joystick.cpp} (52%) diff --git a/firmware/src/ResponsiveAnalogRead.cpp b/firmware/lib/ResponsiveAnalogRead.cpp similarity index 100% rename from firmware/src/ResponsiveAnalogRead.cpp rename to firmware/lib/ResponsiveAnalogRead.cpp diff --git a/firmware/src/ResponsiveAnalogRead.h b/firmware/lib/ResponsiveAnalogRead.h similarity index 100% rename from firmware/src/ResponsiveAnalogRead.h rename to firmware/lib/ResponsiveAnalogRead.h diff --git a/firmware/src/main.cpp b/firmware/src/cmdr_joystick.cpp similarity index 52% rename from firmware/src/main.cpp rename to firmware/src/cmdr_joystick.cpp index d23a1d0..17d3089 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -138,39 +138,40 @@ int16_t elrs_channels[CRSF_MAX_CHANNEL]; bool elrs_init_done = false; int elrs_init_counter = 0; -const int STATUS_LED = 13; +const int STATUS_LED_PIN = 13; bool status_led_on = false; int status_led_mode = 2; -const int BUTTON_LED_1 = 22; +const int BUTTON_LED_1_PIN = 22; bool button_led_1_on = false; int button_led_1_mode = 0; -const int BUTTON_LED_2 = 23; +const int BUTTON_LED_2_PIN = 23; bool button_led_2_on = false; int button_led_2_mode = 0; unsigned long current_timestamp = 0; -unsigned long led_timestamp = 0; +unsigned long process_data_timestamp = 0; unsigned long indicator_timestamp = 0; unsigned long send_usb_timestamp = 0; unsigned long current_timestamp_micros = 0; unsigned long send_elrs_timestamp_micros = 0; -const int BUTTON_FLU = 4; // Front left upper button -const int BUTTON_FLD = 5; // Front left lower button -const int BUTTON_FRU = 6; // Front right upper button -const int BUTTON_FRD = 7; // Front right lower button -const int BUTTON_TLU = 9; // top upper left button -const int BUTTON_TRU = 10; // Top upper right button -const int BUTTON_TLD = 8; // Top left lower button -const int BUTTON_TRD = 11; // Top right lower button +const int BUTTON_FLU_PIN = 4; // Front left upper button +const int BUTTON_FLD_PIN = 5; // Front left lower button +const int BUTTON_FRU_PIN = 6; // Front right upper button +const int BUTTON_FRD_PIN = 7; // Front right lower button +const int BUTTON_TLU_PIN = 9; // top upper left button +const int BUTTON_TRU_PIN = 10; // Top upper right button +const int BUTTON_TLD_PIN = 8; // Top left lower button +const int BUTTON_TRD_PIN = 11; // Top right lower button + +const int GIMBAL_MODE_PIN = 21; // Open = M7, Closed (GND) = M10 bool toggle_button_arm = false; bool toggle_button_mode = false; -int button_arm_previous_value = HIGH; -int button_11_previous_value = HIGH; +int toggle_button_arm_previous_value = HIGH; #define HID_AXIS_MAX 1023 #define HID_AXIS_MIN 0 @@ -213,7 +214,6 @@ enum EEPROM_ADR int joystick_counter = 0; int joystick_x1 = 0; int joystick_x1_hid = 0; -int joystick_x1_raw = 0; int joystick_x1_max = 4096; int joystick_x1_min = 0; int joystick_x1_center = joystick_x1_max/2; @@ -221,19 +221,16 @@ int joystick_y1 = 0; int joystick_y1_hid = 0; int joystick_y1_hid_rev = 0; int joystick_y1_hid_rev_mode = 0; -int joystick_y1_raw = 0; int joystick_y1_max = 4096; int joystick_y1_min = 0; int joystick_y1_center = joystick_y1_max/2; int joystick_x2 = 0; int joystick_x2_hid = 0; -int joystick_x2_raw = 0; int joystick_x2_max = 4096; int joystick_x2_min = 0; int joystick_x2_center = joystick_x2_max/2; int joystick_y2 = 0; int joystick_y2_hid = 0; -int joystick_y2_raw = 0; int joystick_y2_max = 4096; int joystick_y2_min = 0; int joystick_y2_center = joystick_y2_max/2; @@ -241,11 +238,12 @@ int joystick_y2_center = joystick_y2_max/2; float exp_constant = 0.2; int fn_mode = 0; +int gimbal_mode = 0; ResponsiveAnalogRead analog_x1(A0, true); ResponsiveAnalogRead analog_y1(A1, true); -ResponsiveAnalogRead analog_x2(A2, true); -ResponsiveAnalogRead analog_y2(A3, true); +ResponsiveAnalogRead analog_x2(A3, true); +ResponsiveAnalogRead analog_y2(A2, true); #define CALIBRATION_OFF 0 #define CALIBRATION_INIT 1 @@ -315,211 +313,8 @@ void load_from_eeprom(){ joystick_y2_center |= EEPROM.read(CNT_Y2_ADR_LOW); } -void read_io_data(){ - - if(joystick_counter == 0){ - joystick_x1_raw = analog_x1.getValue(); - joystick_counter++; - } - else if(joystick_counter == 1){ - joystick_y1_raw = analog_y1.getValue(); - joystick_counter++; - } - else if(joystick_counter == 2){ - joystick_x2_raw = analog_x2.getValue(); - joystick_counter++; - } - else if(joystick_counter == 3){ - joystick_y2_raw = analog_y2.getValue(); - joystick_counter = 0; - - if (joystick_calibration_mode == CALIBRATION_OFF){ - - // Calculate X1 joystick values - if(joystick_x1_raw > (joystick_x1_center + DEADZONE_X)){ - joystick_x1 = constrain(map(joystick_x1_raw, (joystick_x1_center + DEADZONE_X), joystick_x1_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); - } - else if(joystick_x1_raw < (joystick_x1_center - DEADZONE_X)){ - joystick_x1 = constrain(map(joystick_x1_raw, joystick_x1_min, (joystick_x1_center - DEADZONE_X), AXIS_MIN, AXIS_CENTER), AXIS_MIN, AXIS_CENTER); - } - else{ - joystick_x1 = AXIS_CENTER; - } - - // Calculate Y1 joystick values - if(joystick_y1_raw > (joystick_y1_min + DEADZONE_Y)){ - joystick_y1 = constrain(map(joystick_y1_raw, (joystick_y1_min + DEADZONE_Y), joystick_y1_max, AXIS_MIN, AXIS_MAX), AXIS_MIN, AXIS_MAX); - } - else{ - joystick_y1 = AXIS_MIN; - } - - // Calculate X2 joystick values - if(joystick_x2_raw > (joystick_x2_center + DEADZONE_X)){ - joystick_x2 = constrain(map(joystick_x2_raw, (joystick_x2_center + DEADZONE_X), joystick_x2_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); - } - else if(joystick_x2_raw < (joystick_x2_center - DEADZONE_X)){ - joystick_x2 = constrain(map(joystick_x2_raw, joystick_x2_min, (joystick_x2_center - DEADZONE_X), AXIS_MIN, AXIS_CENTER), AXIS_MIN, AXIS_CENTER); - } - else{ - joystick_x2 = AXIS_CENTER; - } - - // Calculate Y2 joystick values - if(joystick_y2_raw > (joystick_y2_center + DEADZONE_Y)){ - joystick_y2 = constrain(map(joystick_y2_raw, (joystick_y2_center + DEADZONE_Y), joystick_y2_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); - } - else if(joystick_y2_raw < (joystick_y2_center - DEADZONE_Y)){ - joystick_y2 = constrain(map(joystick_y2_raw, joystick_y2_min, (joystick_y2_center - DEADZONE_Y), AXIS_MIN, AXIS_CENTER), AXIS_MIN, AXIS_CENTER); - } - else{ - joystick_y2 = AXIS_CENTER; - } - - // Calculate new X1 values after applying exp curve - if (joystick_x1 != AXIS_CENTER){ - float joystick_x_float = joystick_x1 / float(AXIS_MAX); - float joystick_x_exp = exp_constant * (0.5 + 256 * pow((joystick_x_float - 0.5),9)) + (1 - exp_constant) * joystick_x_float; - joystick_x1_hid = int(joystick_x_exp * float(HID_AXIS_MAX)); - joystick_x1_hid = constrain(joystick_x1_hid, HID_AXIS_MIN, HID_AXIS_MAX); - } - else{ - joystick_x1_hid = HID_AXIS_CENTER; - } - - // Calculate new Y1 values - joystick_y1_hid = map(joystick_y1, AXIS_MIN, AXIS_MAX, HID_AXIS_MIN, HID_AXIS_MAX); - - // Calculate new X2 values after applying exp curve - if (joystick_x2 != AXIS_CENTER){ - float joystick_x_float = joystick_x2 / float(AXIS_MAX); - float joystick_x_exp = exp_constant * (0.5 + 256 * pow((joystick_x_float - 0.5),9)) + (1 - exp_constant) * joystick_x_float; - joystick_x2_hid = int(joystick_x_exp * float(HID_AXIS_MAX)); - joystick_x2_hid = constrain(joystick_x2_hid, HID_AXIS_MIN, HID_AXIS_MAX); - } - else{ - joystick_x2_hid = HID_AXIS_CENTER; - } - - // Calculate new Y2 values after applying exp curve - if (joystick_y2 != AXIS_CENTER){ - float joystick_y_float = joystick_y2 / float(AXIS_MAX); - float joystick_y_exp = exp_constant * (0.5 + 256 * pow((joystick_y_float - 0.5),9)) + (1 - exp_constant) * joystick_y_float; - joystick_y2_hid = int(joystick_y_exp * float(HID_AXIS_MAX)); - joystick_y2_hid = constrain(joystick_y2_hid, HID_AXIS_MIN, HID_AXIS_MAX); - } - else{ - joystick_y2_hid = HID_AXIS_CENTER; - } - - // Check fn mode - fn_mode = 0; - if (digitalRead(BUTTON_TLU) == LOW){ - fn_mode = 1; - if (digitalRead(BUTTON_TRU) == LOW){ - fn_mode = 2; - } - } - - // Check toggle buttons - if (digitalRead(BUTTON_FLU) == LOW){ - toggle_button_mode = true; - } - else if (digitalRead(BUTTON_FLD) == LOW){ - toggle_button_mode = false; - } - - if (fn_mode == 1){ - if (digitalRead(BUTTON_TRD) != button_arm_previous_value){ - button_arm_previous_value = digitalRead(BUTTON_TRD); - if (digitalRead(BUTTON_TRD) == LOW){ - if (toggle_button_arm == false){ - toggle_button_arm = true; - } - else{ - toggle_button_arm = false; - } - } - } - } - } - else{ - - // Calibration mode. - joystick_x1 = AXIS_CENTER; - joystick_y1 = AXIS_CENTER; - joystick_x2 = AXIS_CENTER; - joystick_y2 = AXIS_CENTER; - joystick_x1_hid = HID_AXIS_CENTER; - joystick_y1_hid = HID_AXIS_CENTER; - joystick_x2_hid = HID_AXIS_CENTER; - joystick_y2_hid = HID_AXIS_CENTER; - - // Check for calibration mode - if (joystick_calibration_mode == CALIBRATION_INIT){ - if (digitalRead(BUTTON_TLD) == HIGH){ - joystick_calibration_mode = CALIBRATION_CENTER; - } - } - // Calibrate joystick center values - else if (joystick_calibration_mode == CALIBRATION_CENTER){ - joystick_x1_center = joystick_x1_raw; - joystick_y1_center = joystick_y1_raw; - joystick_x1_max = joystick_x1_center; - joystick_x1_min = joystick_x1_center; - joystick_y1_max = joystick_y1_center; - joystick_y1_min = joystick_y1_center; - - joystick_x2_center = joystick_x2_raw; - joystick_y2_center = joystick_y2_raw; - joystick_x2_max = joystick_x2_center; - joystick_x2_min = joystick_x2_center; - joystick_y2_max = joystick_y2_center; - joystick_y2_min = joystick_y2_center; - - if (digitalRead(BUTTON_TLD) == LOW){ - joystick_calibration_mode = CALIBRATION_MINMAX; - } - } - // Calibrate joystick min/max values - else if (joystick_calibration_mode == CALIBRATION_MINMAX){ - if(joystick_x1_raw > joystick_x1_max){ - joystick_x1_max = joystick_x1_raw; - } - if(joystick_x1_raw < joystick_x1_min){ - joystick_x1_min = joystick_x1_raw; - } - if(joystick_y1_raw > joystick_y1_max){ - joystick_y1_max = joystick_y1_raw; - } - if(joystick_y1_raw < joystick_y1_min){ - joystick_y1_min = joystick_y1_raw; - } - - if(joystick_x2_raw > joystick_x2_max){ - joystick_x2_max = joystick_x2_raw; - } - if(joystick_x2_raw < joystick_x2_min){ - joystick_x2_min = joystick_x2_raw; - } - if(joystick_y2_raw > joystick_y2_max){ - joystick_y2_max = joystick_y2_raw; - } - if(joystick_y2_raw < joystick_y2_min){ - joystick_y2_min = joystick_y2_raw; - } - - if (digitalRead(BUTTON_TRD) == LOW){ - joystick_calibration_mode = CALIBRATION_OFF; - save_to_eeprom(); - } - } - } - } -} - // CRSF CRC calculation via lookup table -uint8_t crsf_crc8(const uint8_t *ptr, uint8_t len) { +uint8_t calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) { uint8_t crc = 0; for (uint8_t i = 0; i < len; i++){ crc = crsf_crc8tab[crc ^ *ptr++]; @@ -528,7 +323,7 @@ uint8_t crsf_crc8(const uint8_t *ptr, uint8_t len) { } // Prepare CRSF data packet -void crsf_prepare_data_packet(uint8_t packet[], int16_t channels[]) { +void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) { packet[0] = ELRS_ADDRESS; // Header packet[1] = 24; // length packet[2] = CRSF_TYPE_CHANNELS; @@ -554,11 +349,11 @@ void crsf_prepare_data_packet(uint8_t packet[], int16_t channels[]) { packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2); // Channel not used by ELRS packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5); // Channel not used by ELRS packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3); // Channel not used by ELRS - packet[25] = crsf_crc8(&packet[2], packet[1] - 1); + packet[25] = calculate_crsf_crc8(&packet[2], packet[1] - 1); } // Prepare CRSF setup packet -void crsf_prepare_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) { +void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) { packet_cmd[0] = ELRS_ADDRESS; // Header packet_cmd[1] = 6; // length packet_cmd[2] = ELRS_TYPE_SETTINGS_WRITE; @@ -566,35 +361,424 @@ void crsf_prepare_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t valu packet_cmd[4] = ELRS_ADDR_RADIO; packet_cmd[5] = command; packet_cmd[6] = value; - packet_cmd[7] = crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); + packet_cmd[7] = calculate_crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); +} + +void send_elrs_data(){ + + // Set ELRS analog channels + elrs_channels[0] = map(joystick_x1, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + elrs_channels[1] = map(joystick_y1, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + elrs_channels[2] = map(joystick_x2, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + elrs_channels[3] = map(joystick_y2, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + + // Set ELRS digital channels + for (int i = 4; i < CRSF_MAX_CHANNEL; i++){ + elrs_channels[i] = CRSF_DIGITAL_CHANNEL_MIN; + } + if (toggle_button_arm){ + elrs_channels[4] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (toggle_button_mode){ + elrs_channels[5] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (digitalRead(BUTTON_FRU_PIN) == LOW){ + elrs_channels[6] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (digitalRead(BUTTON_FRD_PIN) == LOW){ + elrs_channels[7] = CRSF_DIGITAL_CHANNEL_MAX; + } + if (digitalRead(BUTTON_TRU_PIN) == LOW){ + elrs_channels[8] = CRSF_DIGITAL_CHANNEL_MAX; + } + + // Send ELRS data + if (elrs_init_done == true){ + prepare_crsf_data_packet(crsf_packet, elrs_channels); + ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); + } + else{ + // Setting up initial communication link between ERLS TX and Teensy (give ERLS TX time to auto detect Teensy) + if (elrs_init_counter < 500){ + prepare_crsf_data_packet(crsf_packet, elrs_channels); + ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); + elrs_init_counter++; + } + // Send command to update TX packet rate to 500Hz + else if (elrs_init_counter < 505){ + prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, ELRS_PKT_RATE); + ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + elrs_init_counter++; + } + // Send command to update TX power to 100mW + else if (elrs_init_counter < 510){ + prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, ELRS_POWER); + ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + elrs_init_counter++; + } + else{ + elrs_init_done = true; + } + } +} + +void send_usb_data(){ + + // Set joystick buttons to released + for (int i = 1; i < 32; i++){ + Joystick.button(i, 0); + } + + // Set joystick hat to center position + Joystick.hat(-1); + + // Set joystick buttons to pressed + if (fn_mode == 2){ + + if (digitalRead(BUTTON_FLD_PIN) == LOW){ + Joystick.button(12, 1); + } + if (digitalRead(BUTTON_FRD_PIN) == LOW){ + Joystick.button(13, 1); + } + if (digitalRead(BUTTON_TLD_PIN) == LOW){ + Joystick.button(14, 1); + } + if (digitalRead(BUTTON_TRD_PIN) == LOW){ + Joystick.button(15, 1); + } + } + else if (fn_mode == 1){ + + if (digitalRead(BUTTON_FLD_PIN) == LOW){ + Joystick.button(8, 1); + } + if (digitalRead(BUTTON_FRD_PIN) == LOW){ + Joystick.button(9, 1); + } + if (digitalRead(BUTTON_TLD_PIN) == LOW){ + Joystick.button(10, 1); + } + if (digitalRead(BUTTON_TRD_PIN) == LOW){ + Joystick.button(11, 1); + } + } + else{ + + if (digitalRead(BUTTON_FLD_PIN) == LOW){ + Joystick.button(2, 1); + } + if (digitalRead(BUTTON_FRD_PIN) == LOW){ + Joystick.button(4, 1); + } + if (digitalRead(BUTTON_TRU_PIN) == LOW){ + Joystick.button(5, 1); + } + if (digitalRead(BUTTON_TLD_PIN) == LOW){ + Joystick.button(6, 1); + } + if (digitalRead(BUTTON_TRD_PIN) == LOW){ + Joystick.button(7, 1); + } + } + + if (digitalRead(BUTTON_FLU_PIN) == LOW){ + Joystick.button(1, 1); + } + if (digitalRead(BUTTON_FRU_PIN) == LOW){ + Joystick.button(3, 1); + } + + // Set axis values + Joystick.Zrotate(joystick_x1_hid); + Joystick.Z(joystick_y1_hid); + + if (fn_mode == 2){ + Joystick.X(HID_AXIS_CENTER); + Joystick.Y(HID_AXIS_CENTER); + Joystick.sliderRight(joystick_x2_hid); + Joystick.sliderLeft(joystick_y2_hid); + } + else if (fn_mode == 1){ + Joystick.X(joystick_x2_hid); + Joystick.Y(HID_AXIS_CENTER); + Joystick.sliderRight(HID_AXIS_CENTER); + Joystick.sliderLeft(joystick_y2_hid); + } + else{ + Joystick.X(joystick_x2_hid); + Joystick.Y(joystick_y2_hid); + Joystick.sliderRight(HID_AXIS_CENTER); + Joystick.sliderLeft(HID_AXIS_CENTER); + } + + // Send USB Joystick data + Joystick.send_now(); +} + +void process_input_data(){ + + int analog_x1_inv = 0; + int analog_y1_inv = 0; + int analog_x2_inv = 0; + int analog_y2_inv = 0; + + if (gimbal_mode == 1){ + // FrSky M10 Gimbal + analog_x1_inv = constrain(AXIS_MAX - analog_x1.getValue(), AXIS_MIN, AXIS_MAX); + analog_y1_inv = constrain(analog_y1.getValue(), AXIS_MIN, AXIS_MAX); + analog_x2_inv = constrain(analog_x2.getValue(), AXIS_MIN, AXIS_MAX); + analog_y2_inv = constrain(AXIS_MAX - analog_y2.getValue(), AXIS_MIN, AXIS_MAX); + } + else{ + // FrSky M7 Gimbal + analog_x1_inv = constrain(analog_x1.getValue(), AXIS_MIN, AXIS_MAX); + analog_y1_inv = constrain(AXIS_MAX - analog_y1.getValue(), AXIS_MIN, AXIS_MAX); + analog_x2_inv = constrain(AXIS_MAX - analog_x2.getValue(), AXIS_MIN, AXIS_MAX); + analog_y2_inv = constrain(analog_y2.getValue(), AXIS_MIN, AXIS_MAX); + } + + if (joystick_calibration_mode == CALIBRATION_OFF){ + + // Calculate X1 joystick values + if(analog_x1_inv > (joystick_x1_center + DEADZONE_X)){ + joystick_x1 = constrain(map(analog_x1_inv, (joystick_x1_center + DEADZONE_X), joystick_x1_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); + } + else if(analog_x1_inv < (joystick_x1_center - DEADZONE_X)){ + joystick_x1 = constrain(map(analog_x1_inv, joystick_x1_min, (joystick_x1_center - DEADZONE_X), AXIS_MIN, AXIS_CENTER), AXIS_MIN, AXIS_CENTER); + } + else{ + joystick_x1 = AXIS_CENTER; + } + + // Calculate Y1 joystick values + if(analog_y1_inv > (joystick_y1_min + DEADZONE_Y)){ + joystick_y1 = constrain(map(analog_y1_inv, (joystick_y1_min + DEADZONE_Y), joystick_y1_max, AXIS_MIN, AXIS_MAX), AXIS_MIN, AXIS_MAX); + } + else{ + joystick_y1 = AXIS_MIN; + } + + // Calculate X2 joystick values + if(analog_x2_inv > (joystick_x2_center + DEADZONE_X)){ + joystick_x2 = constrain(map(analog_x2_inv, (joystick_x2_center + DEADZONE_X), joystick_x2_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); + } + else if(analog_x2_inv < (joystick_x2_center - DEADZONE_X)){ + joystick_x2 = constrain(map(analog_x2_inv, joystick_x2_min, (joystick_x2_center - DEADZONE_X), AXIS_MIN, AXIS_CENTER), AXIS_MIN, AXIS_CENTER); + } + else{ + joystick_x2 = AXIS_CENTER; + } + + // Calculate Y2 joystick values + if(analog_y2_inv > (joystick_y2_center + DEADZONE_Y)){ + joystick_y2 = constrain(map(analog_y2_inv, (joystick_y2_center + DEADZONE_Y), joystick_y2_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); + } + else if(analog_y2_inv < (joystick_y2_center - DEADZONE_Y)){ + joystick_y2 = constrain(map(analog_y2_inv, joystick_y2_min, (joystick_y2_center - DEADZONE_Y), AXIS_MIN, AXIS_CENTER), AXIS_MIN, AXIS_CENTER); + } + else{ + joystick_y2 = AXIS_CENTER; + } + + // Calculate new X1 values after applying exp curve + if (joystick_x1 != AXIS_CENTER){ + float joystick_x_float = joystick_x1 / float(AXIS_MAX); + float joystick_x_exp = exp_constant * (0.5 + 256 * pow((joystick_x_float - 0.5),9)) + (1 - exp_constant) * joystick_x_float; + joystick_x1_hid = int(joystick_x_exp * float(HID_AXIS_MAX)); + joystick_x1_hid = constrain(joystick_x1_hid, HID_AXIS_MIN, HID_AXIS_MAX); + } + else{ + joystick_x1_hid = HID_AXIS_CENTER; + } + + // Calculate new Y1 values + joystick_y1_hid = map(joystick_y1, AXIS_MIN, AXIS_MAX, HID_AXIS_MIN, HID_AXIS_MAX); + + // Calculate new X2 values after applying exp curve + if (joystick_x2 != AXIS_CENTER){ + float joystick_x_float = joystick_x2 / float(AXIS_MAX); + float joystick_x_exp = exp_constant * (0.5 + 256 * pow((joystick_x_float - 0.5),9)) + (1 - exp_constant) * joystick_x_float; + joystick_x2_hid = int(joystick_x_exp * float(HID_AXIS_MAX)); + joystick_x2_hid = constrain(joystick_x2_hid, HID_AXIS_MIN, HID_AXIS_MAX); + } + else{ + joystick_x2_hid = HID_AXIS_CENTER; + } + + // Calculate new Y2 values after applying exp curve + if (joystick_y2 != AXIS_CENTER){ + float joystick_y_float = joystick_y2 / float(AXIS_MAX); + float joystick_y_exp = exp_constant * (0.5 + 256 * pow((joystick_y_float - 0.5),9)) + (1 - exp_constant) * joystick_y_float; + joystick_y2_hid = int(joystick_y_exp * float(HID_AXIS_MAX)); + joystick_y2_hid = constrain(joystick_y2_hid, HID_AXIS_MIN, HID_AXIS_MAX); + } + else{ + joystick_y2_hid = HID_AXIS_CENTER; + } + + // Check fn mode + fn_mode = 0; + if (digitalRead(BUTTON_TLU_PIN) == LOW){ + fn_mode = 1; + if (digitalRead(BUTTON_TRU_PIN) == LOW){ + fn_mode = 2; + } + } + + // Check toggle mode buttons + if (digitalRead(BUTTON_FLU_PIN) == LOW){ + toggle_button_mode = true; + } + else if (digitalRead(BUTTON_FLD_PIN) == LOW){ + toggle_button_mode = false; + } + + // Check toggle arm button + if (fn_mode == 1){ + if (digitalRead(BUTTON_TRD_PIN) != toggle_button_arm_previous_value){ + toggle_button_arm_previous_value = digitalRead(BUTTON_TRD_PIN); + if (digitalRead(BUTTON_TRD_PIN) == LOW){ + if (toggle_button_arm == false){ + toggle_button_arm = true; + } + else{ + toggle_button_arm = false; + } + } + } + } + } + else{ + + // Calibration mode. + joystick_x1 = AXIS_CENTER; + joystick_y1 = AXIS_CENTER; + joystick_x2 = AXIS_CENTER; + joystick_y2 = AXIS_CENTER; + joystick_x1_hid = HID_AXIS_CENTER; + joystick_y1_hid = HID_AXIS_CENTER; + joystick_x2_hid = HID_AXIS_CENTER; + joystick_y2_hid = HID_AXIS_CENTER; + + // Check for calibration mode + if (joystick_calibration_mode == CALIBRATION_INIT){ + if (digitalRead(BUTTON_TLD_PIN) == HIGH){ + joystick_calibration_mode = CALIBRATION_CENTER; + } + } + + // Calibrate joystick center values + else if (joystick_calibration_mode == CALIBRATION_CENTER){ + joystick_x1_center = analog_x1_inv; + joystick_y1_center = analog_y1_inv; + joystick_x1_max = joystick_x1_center; + joystick_x1_min = joystick_x1_center; + joystick_y1_max = joystick_y1_center; + joystick_y1_min = joystick_y1_center; + + joystick_x2_center = analog_x2_inv; + joystick_y2_center = analog_y2_inv; + joystick_x2_max = joystick_x2_center; + joystick_x2_min = joystick_x2_center; + joystick_y2_max = joystick_y2_center; + joystick_y2_min = joystick_y2_center; + + if (digitalRead(BUTTON_TLD_PIN) == LOW){ + joystick_calibration_mode = CALIBRATION_MINMAX; + } + } + + // Calibrate joystick min/max values + else if (joystick_calibration_mode == CALIBRATION_MINMAX){ + if(analog_x1_inv > joystick_x1_max){ + joystick_x1_max = analog_x1_inv; + } + if(analog_x1_inv < joystick_x1_min){ + joystick_x1_min = analog_x1_inv; + } + if(analog_y1_inv > joystick_y1_max){ + joystick_y1_max = analog_y1_inv; + } + if(analog_y1_inv < joystick_y1_min){ + joystick_y1_min = analog_y1_inv; + } + + if(analog_x2_inv > joystick_x2_max){ + joystick_x2_max = analog_x2_inv; + } + if(analog_x2_inv < joystick_x2_min){ + joystick_x2_min = analog_x2_inv; + } + if(analog_y2_inv > joystick_y2_max){ + joystick_y2_max = analog_y2_inv; + } + if(analog_y2_inv < joystick_y2_min){ + joystick_y2_min = analog_y2_inv; + } + + if (digitalRead(BUTTON_TRD_PIN) == LOW){ + joystick_calibration_mode = CALIBRATION_OFF; + save_to_eeprom(); + } + } + } +} + +/* Update indicator 0=Off, 1=On, 2=Blink */ +void update_indicator(int mode, bool ¤t_state, int pin){ + + if (mode == 2 && current_state == false) + { + digitalWrite(pin, HIGH); + current_state = true; + } + else if (mode == 2 && current_state == true) + { + digitalWrite(pin, LOW); + current_state = false; + } + else if (mode == 1) + { + digitalWrite(pin, HIGH); + current_state = true; + } + else + { + digitalWrite(pin, LOW); + current_state = false; + } } void setup() { /* Init HW */ - pinMode(STATUS_LED, OUTPUT); - digitalWrite(STATUS_LED, LOW); + pinMode(STATUS_LED_PIN, OUTPUT); + digitalWrite(STATUS_LED_PIN, LOW); - pinMode(BUTTON_LED_1, OUTPUT); - digitalWrite(BUTTON_LED_1, LOW); + pinMode(BUTTON_LED_1_PIN, OUTPUT); + digitalWrite(BUTTON_LED_1_PIN, LOW); - pinMode(BUTTON_LED_2, OUTPUT); - digitalWrite(BUTTON_LED_2, LOW); + pinMode(BUTTON_LED_2_PIN, OUTPUT); + digitalWrite(BUTTON_LED_2_PIN, LOW); - pinMode(BUTTON_FLD, INPUT_PULLUP); - pinMode(BUTTON_FLU, INPUT_PULLUP); - pinMode(BUTTON_FRD, INPUT_PULLUP); - pinMode(BUTTON_FRU, INPUT_PULLUP); - pinMode(BUTTON_TLD, INPUT_PULLUP); - pinMode(BUTTON_TRD, INPUT_PULLUP); - pinMode(BUTTON_TLU, INPUT_PULLUP); - pinMode(BUTTON_TRU, INPUT_PULLUP); + pinMode(BUTTON_FLD_PIN, INPUT_PULLUP); + pinMode(BUTTON_FLU_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRD_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRU_PIN, INPUT_PULLUP); + pinMode(BUTTON_TLD_PIN, INPUT_PULLUP); + pinMode(BUTTON_TRD_PIN, INPUT_PULLUP); + pinMode(BUTTON_TLU_PIN, INPUT_PULLUP); + pinMode(BUTTON_TRU_PIN, INPUT_PULLUP); + + pinMode(GIMBAL_MODE_PIN, INPUT_PULLUP); // Set ADC resolution to 12bit analogReadResolution(12); analogReadAveraging(32); delay(500); + // Set analog (lib) resolution to 12bit analog_x1.setAnalogResolution(4096); analog_y1.setAnalogResolution(4096); analog_x2.setAnalogResolution(4096); @@ -607,17 +791,22 @@ void setup() Joystick.useManualSend(true); // Check if calibration mode is enabled - if (digitalRead(BUTTON_TLD) == LOW){ + if (digitalRead(BUTTON_TLD_PIN) == LOW){ joystick_calibration_mode = CALIBRATION_INIT; } // Check if bootloader mode is enabled - if (digitalRead(BUTTON_TRD) == LOW){ - digitalWrite(BUTTON_LED_2, HIGH); + if (digitalRead(BUTTON_TRD_PIN) == LOW){ + digitalWrite(BUTTON_LED_2_PIN, HIGH); delay(200); _reboot_Teensyduino_(); } + // Check what gimbal mode is selected + if (digitalRead(GIMBAL_MODE_PIN) == LOW){ + gimbal_mode = 1; + } + // Init ELRS ELRS_SERIAL_PORT.begin(ELRS_SERIAL_BAUDRATE); } @@ -629,179 +818,43 @@ void loop() /* Update current time (us) */ current_timestamp_micros = micros(); - /* Read io value and process as fast as possible */ + /* Read io value as fast as possible */ analog_x1.update(); analog_y1.update(); analog_x2.update(); analog_y2.update(); - read_io_data(); + /* Process data with 1ms interval*/ + if (current_timestamp >= process_data_timestamp) + { + process_input_data(); + process_data_timestamp = current_timestamp + 1; + } + /* Update/Send USB data with 5ms interval*/ if (current_timestamp >= send_usb_timestamp) { - // Set joystick buttons to released - for (int i = 1; i < 32; i++){ - Joystick.button(i, 0); - } - - // Set joystick hat to center position - Joystick.hat(-1); - - // Set joystick buttons to pressed - if (fn_mode == 2){ - - if (digitalRead(BUTTON_FLD) == LOW){ - Joystick.button(12, 1); - } - if (digitalRead(BUTTON_FRD) == LOW){ - Joystick.button(13, 1); - } - if (digitalRead(BUTTON_TLD) == LOW){ - Joystick.button(14, 1); - } - if (digitalRead(BUTTON_TRD) == LOW){ - Joystick.button(15, 1); - } - } - else if (fn_mode == 1){ - - if (digitalRead(BUTTON_FLD) == LOW){ - Joystick.button(8, 1); - } - if (digitalRead(BUTTON_FRD) == LOW){ - Joystick.button(9, 1); - } - if (digitalRead(BUTTON_TLD) == LOW){ - Joystick.button(10, 1); - } - if (digitalRead(BUTTON_TRD) == LOW){ - Joystick.button(11, 1); - } - } - else{ - - if (digitalRead(BUTTON_FLD) == LOW){ - Joystick.button(2, 1); - } - if (digitalRead(BUTTON_FRD) == LOW){ - Joystick.button(4, 1); - } - if (digitalRead(BUTTON_TRU) == LOW){ - Joystick.button(5, 1); - } - if (digitalRead(BUTTON_TLD) == LOW){ - Joystick.button(6, 1); - } - if (digitalRead(BUTTON_TRD) == LOW){ - Joystick.button(7, 1); - } - } - - if (digitalRead(BUTTON_FLU) == LOW){ - Joystick.button(1, 1); - } - if (digitalRead(BUTTON_FRU) == LOW){ - Joystick.button(3, 1); - } - - // Set axis values - Joystick.Y(joystick_y1_hid); - Joystick.X(joystick_x1_hid); - - if (fn_mode == 2){ - Joystick.Z(HID_AXIS_CENTER); - Joystick.Zrotate(HID_AXIS_CENTER); - Joystick.sliderLeft(joystick_x2_hid); - Joystick.sliderRight(joystick_y2_hid); - } - else if (fn_mode == 1){ - Joystick.Z(HID_AXIS_CENTER); - Joystick.Zrotate(joystick_y2_hid); - Joystick.sliderLeft(joystick_x2_hid); - Joystick.sliderRight(HID_AXIS_CENTER); - } - else{ - Joystick.Z(joystick_x2_hid); - Joystick.Zrotate(joystick_y2_hid); - Joystick.sliderLeft(HID_AXIS_CENTER); - Joystick.sliderRight(HID_AXIS_CENTER); - } - - // Send USB Joystick data - Joystick.send_now(); + send_usb_data(); send_usb_timestamp = current_timestamp + 5; } - /* Send data every CRSF_TIME_BETWEEN_FRAMES_US */ + /* Update/Send ERLS data with 1,6ms interval */ if (current_timestamp_micros >= send_elrs_timestamp_micros) { - // Set ELRS analog channels - elrs_channels[0] = map(joystick_x1, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); - elrs_channels[1] = map(joystick_y1, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); - elrs_channels[2] = map(joystick_x2, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); - elrs_channels[3] = map(joystick_y2, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); - - // Set ELRS digital channels - for (int i = 4; i < CRSF_MAX_CHANNEL; i++){ - elrs_channels[i] = CRSF_DIGITAL_CHANNEL_MIN; - } - if (toggle_button_arm){ - elrs_channels[4] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (toggle_button_mode){ - elrs_channels[5] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (digitalRead(BUTTON_FRU) == LOW){ - elrs_channels[6] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (digitalRead(BUTTON_FRD) == LOW){ - elrs_channels[7] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (digitalRead(BUTTON_TRU) == LOW){ - elrs_channels[8] = CRSF_DIGITAL_CHANNEL_MAX; - } - - // Send ELRS data - if (elrs_init_done == true){ - crsf_prepare_data_packet(crsf_packet, elrs_channels); - ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); - } - else{ - // Setting up initial communication link between ERLS TX and Teensy (give ERLS TX time to auto detect Teensy) - if (elrs_init_counter < 500){ - crsf_prepare_data_packet(crsf_packet, elrs_channels); - ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); - elrs_init_counter++; - } - // Send command to update TX packet rate to 500Hz - else if (elrs_init_counter < 505){ - crsf_prepare_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, ELRS_PKT_RATE); - ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); - elrs_init_counter++; - } - // Send command to update TX power to 100mW - else if (elrs_init_counter < 510){ - crsf_prepare_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, ELRS_POWER); - ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); - elrs_init_counter++; - } - else{ - elrs_init_done = true; - } - } + send_elrs_data(); send_elrs_timestamp_micros = current_timestamp_micros + CRSF_TIME_BETWEEN_FRAMES_US; } - /* Update leds 200ms */ - if (current_timestamp >= led_timestamp) + /* Update indicator 200ms */ + if (current_timestamp >= indicator_timestamp) { // Set led mode button_led_1_mode = 0; button_led_2_mode = 0; if (joystick_calibration_mode == CALIBRATION_INIT){ - button_led_1_mode = 1; - button_led_2_mode = 1; + button_led_1_mode = 2; + button_led_2_mode = 2; } else if (joystick_calibration_mode == CALIBRATION_CENTER){ button_led_1_mode = 2; @@ -818,77 +871,12 @@ void loop() } /* Updated button led 1 */ - if (button_led_1_mode == 2 && button_led_1_on == false) - { - digitalWrite(BUTTON_LED_1, HIGH); - button_led_1_on = true; - } - else if (button_led_1_mode == 2 && button_led_1_on == true) - { - digitalWrite(BUTTON_LED_1, LOW); - button_led_1_on = false; - } - else if (button_led_1_mode == 1) - { - digitalWrite(BUTTON_LED_1, HIGH); - button_led_1_on = true; - } - else - { - digitalWrite(BUTTON_LED_1, LOW); - button_led_1_on = false; - } - + update_indicator(button_led_1_mode, button_led_1_on, BUTTON_LED_1_PIN); /* Updated button led 2 */ - if (button_led_2_mode == 2 && button_led_2_on == false) - { - digitalWrite(BUTTON_LED_2, HIGH); - button_led_2_on = true; - } - else if (button_led_2_mode == 2 && button_led_2_on == true) - { - digitalWrite(BUTTON_LED_2, LOW); - button_led_2_on = false; - } - else if (button_led_2_mode == 1) - { - digitalWrite(BUTTON_LED_2, HIGH); - button_led_2_on = true; - } - else - { - digitalWrite(BUTTON_LED_2, LOW); - button_led_2_on = false; - } - - led_timestamp = current_timestamp + 200; - } - - /* Update indicator 200ms */ - if (current_timestamp >= indicator_timestamp) - { + update_indicator(button_led_2_mode, button_led_2_on, BUTTON_LED_2_PIN); /* Update status led */ - if (status_led_mode == 2 && status_led_on == false) - { - digitalWrite(STATUS_LED, HIGH); - status_led_on = true; - } - else if (status_led_mode == 2 && status_led_on == true) - { - digitalWrite(STATUS_LED, LOW); - status_led_on = false; - } - else if (status_led_mode == 1) - { - digitalWrite(STATUS_LED, HIGH); - status_led_on = true; - } - else - { - digitalWrite(STATUS_LED, LOW); - status_led_on = false; - } - + update_indicator(status_led_mode, status_led_on, STATUS_LED_PIN); + indicator_timestamp = current_timestamp + 200; } } From 959d81c7b4fc31574e004f33e0d2ffd2a5495785 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Fri, 19 May 2023 19:29:38 +0000 Subject: [PATCH 06/29] Update file cmdr_joystick.cpp --- firmware/src/cmdr_joystick.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index 17d3089..ba13325 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -82,6 +82,7 @@ * * 15 joystick buttons using three layers (Fn1 and Fn2). */ + #include #include #include "ResponsiveAnalogRead.h" From 649e8559fd8cd1077ebf422acf3bb24705a399d9 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sun, 21 May 2023 05:57:17 +0000 Subject: [PATCH 07/29] Code cleanup --- firmware/compile_commands.json | 422 ++++++++++++ firmware/src/cmdr_joystick.cpp | 1150 +++++++++++++------------------- firmware/src/erls.cpp | 180 +++++ firmware/src/erls.h | 63 ++ 4 files changed, 1129 insertions(+), 686 deletions(-) create mode 100644 firmware/compile_commands.json create mode 100644 firmware/src/erls.cpp create mode 100644 firmware/src/erls.h diff --git a/firmware/compile_commands.json b/firmware/compile_commands.json new file mode 100644 index 0000000..3257583 --- /dev/null +++ b/firmware/compile_commands.json @@ -0,0 +1,422 @@ +[ + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/AudioStream.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/AudioStream.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/AudioStream.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/AudioStream.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/CrashReport.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/CrashReport.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/CrashReport.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/CrashReport.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/DMAChannel.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/DMAChannel.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/DMAChannel.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/DMAChannel.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/EventResponder.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/EventResponder.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/EventResponder.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/EventResponder.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial1.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial1.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial1.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial1.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial2.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial2.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial2.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial2.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial3.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial3.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial3.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial3.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial4.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial4.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial4.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial4.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial5.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial5.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial5.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial5.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial6.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial6.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial6.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial6.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/IPAddress.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/IPAddress.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/IPAddress.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/IPAddress.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/IntervalTimer.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/IntervalTimer.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/IntervalTimer.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/IntervalTimer.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/Print.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Print.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Print.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/Print.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/Stream.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Stream.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Stream.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/Stream.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/Time.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Time.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Time.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/Time.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/Tone.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Tone.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Tone.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/Tone.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/WMath.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/WMath.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/WMath.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/WMath.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/WString.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/WString.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/WString.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/WString.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/analog.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/analog.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/analog.c", + "output": ".pio/build/teensylc/FrameworkArduino/analog.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/avr_emulation.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/avr_emulation.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/avr_emulation.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/avr_emulation.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/eeprom.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/eeprom.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/eeprom.c", + "output": ".pio/build/teensylc/FrameworkArduino/eeprom.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/keylayouts.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/keylayouts.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/keylayouts.c", + "output": ".pio/build/teensylc/FrameworkArduino/keylayouts.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/main.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/main.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/main.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/main.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/math_helper.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/math_helper.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/math_helper.c", + "output": ".pio/build/teensylc/FrameworkArduino/math_helper.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -mthumb -mcpu=cortex-m0plus -mno-unaligned-access -x assembler-with-cpp -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 -c -o .pio/build/teensylc/FrameworkArduino/memcpy-armv7m.S.o /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/memcpy-armv7m.S", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/memcpy-armv7m.S", + "output": ".pio/build/teensylc/FrameworkArduino/memcpy-armv7m.S.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -mthumb -mcpu=cortex-m0plus -mno-unaligned-access -x assembler-with-cpp -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 -c -o .pio/build/teensylc/FrameworkArduino/memset.S.o /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/memset.S", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/memset.S", + "output": ".pio/build/teensylc/FrameworkArduino/memset.S.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/mk20dx128.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/mk20dx128.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/mk20dx128.c", + "output": ".pio/build/teensylc/FrameworkArduino/mk20dx128.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/new.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/new.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/new.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/new.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/nonstd.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/nonstd.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/nonstd.c", + "output": ".pio/build/teensylc/FrameworkArduino/nonstd.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/pins_teensy.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/pins_teensy.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/pins_teensy.c", + "output": ".pio/build/teensylc/FrameworkArduino/pins_teensy.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/ser_print.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/ser_print.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/ser_print.c", + "output": ".pio/build/teensylc/FrameworkArduino/ser_print.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial1.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial1.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial1.c", + "output": ".pio/build/teensylc/FrameworkArduino/serial1.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial2.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial2.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial2.c", + "output": ".pio/build/teensylc/FrameworkArduino/serial2.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial3.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial3.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial3.c", + "output": ".pio/build/teensylc/FrameworkArduino/serial3.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial4.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial4.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial4.c", + "output": ".pio/build/teensylc/FrameworkArduino/serial4.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial5.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial5.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial5.c", + "output": ".pio/build/teensylc/FrameworkArduino/serial5.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial6.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial6.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial6.c", + "output": ".pio/build/teensylc/FrameworkArduino/serial6.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial6_lpuart.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial6_lpuart.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial6_lpuart.c", + "output": ".pio/build/teensylc/FrameworkArduino/serial6_lpuart.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/serialEvent.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent1.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent1.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent1.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/serialEvent1.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent2.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent2.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent2.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/serialEvent2.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent3.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent3.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent3.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/serialEvent3.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent4.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent4.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent4.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/serialEvent4.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent5.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent5.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent5.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/serialEvent5.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent6.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent6.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent6.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/serialEvent6.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEventUSB1.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEventUSB1.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEventUSB1.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/serialEventUSB1.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEventUSB2.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEventUSB2.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEventUSB2.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/serialEventUSB2.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/touch.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/touch.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/touch.c", + "output": ".pio/build/teensylc/FrameworkArduino/touch.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/usb_audio.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_audio.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_audio.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/usb_audio.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_desc.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_desc.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_desc.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_desc.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_dev.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_dev.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_dev.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_dev.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/usb_flightsim.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_flightsim.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_flightsim.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/usb_flightsim.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/usb_inst.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_inst.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_inst.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/usb_inst.cpp.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_joystick.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_joystick.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_joystick.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_joystick.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_keyboard.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_keyboard.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_keyboard.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_keyboard.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_mem.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mem.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mem.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_mem.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_midi.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_midi.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_midi.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_midi.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_mouse.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mouse.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mouse.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_mouse.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_mtp.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mtp.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mtp.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_mtp.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_rawhid.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_rawhid.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_rawhid.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_rawhid.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_seremu.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_seremu.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_seremu.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_seremu.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_serial.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_serial.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_serial2.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial2.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial2.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_serial2.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_serial3.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial3.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial3.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_serial3.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_touch.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_touch.c", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_touch.c", + "output": ".pio/build/teensylc/FrameworkArduino/usb_touch.c.o" + }, + { + "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/yield.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/yield.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/yield.cpp", + "output": ".pio/build/teensylc/FrameworkArduino/yield.cpp.o" + }, + { + "command": "arm-none-eabi-g++ -o .pio/build/teensylc/lib155/ResponsiveAnalogRead/ResponsiveAnalogRead.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/libraries/ResponsiveAnalogRead/src -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/libraries/ResponsiveAnalogRead/src/ResponsiveAnalogRead.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/libraries/ResponsiveAnalogRead/src/ResponsiveAnalogRead.cpp", + "output": ".pio/build/teensylc/lib155/ResponsiveAnalogRead/ResponsiveAnalogRead.cpp.o" + }, + { + "command": "arm-none-eabi-g++ -o .pio/build/teensylc/libab5/EEPROM/EEPROM.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/libraries/EEPROM -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/libraries/EEPROM/EEPROM.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "/home/cm/.platformio/packages/framework-arduinoteensy/libraries/EEPROM/EEPROM.cpp", + "output": ".pio/build/teensylc/libab5/EEPROM/EEPROM.cpp.o" + }, + { + "command": "arm-none-eabi-g++ -o .pio/build/teensylc/src/cmdr_joystick.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -Iinclude -Isrc -I/home/cm/.platformio/packages/framework-arduinoteensy/libraries/EEPROM -I/home/cm/.platformio/packages/framework-arduinoteensy/libraries/ResponsiveAnalogRead/src -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 src/cmdr_joystick.cpp", + "directory": "/home/cm/projects/cmdr-joystick/firmware", + "file": "src/cmdr_joystick.cpp", + "output": ".pio/build/teensylc/src/cmdr_joystick.cpp.o" + } +] diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index 17d3089..233941f 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -1,4 +1,4 @@ - /* +/* * ======================================================================================================= * ------------------------------------------------------------------------------------------------------- * ---####################-----###########-------###########-----############--############-############-- @@ -27,160 +27,69 @@ * A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * Joystick based on standard teensy "usb_joystick" library for HID joystick usb data communication. - * - * USB Joystick Layer 0 - * - * | B1 | | B3 | - * | B2 | | B4 | - * -------------------------------------------- - * | | Fn1 | | B5 | | - * | | - * | X1,Y1 X2,Y2 | - * | | B6 | | B7 | | - * -------------------------------------------- - * - * USB Joystick Layer 1 (Fn1) - * - * | B1 | | B3 | - * | B8 | | B9 | - * -------------------------------------------- - * | | Fn1 | | Fn2 | | - * | | - * | X1,Y1 Fn1 toggle Fn1 toggle X3,Y2 | - * | | B10 | | B11 | | - * -------------------------------------------- - * - * USB Joystick Layer 2 (Fn2) - * - * | B1 | | B3 | - * | B12 | | B13 | - * -------------------------------------------- - * | | Fn1 | | Fn2 | | - * | | - * | X1,Y1 X3,Y3 | - * | | B14 | | B15 | | - * -------------------------------------------- - * - * ELRS Layer - * - * | CH7 | | CH9 | - * | HC8 | | CH10 | - * -------------------------------------------- - * | | Fn | | CH11 | | - * | | - * | X,Y Fn toggle Fn toggle X,Y | - * | CH1,CH2 | CH5 | | CH6 | CH3,CH4 | - * -------------------------------------------- - * - * Features: - * - * * USB HID Joystick. - * * ERLS protocol (CRSF) support. - * * 4 physical axis. - * * 6 joystick axis using layers (USB Joystick). - * * 8 physical buttons. - * * 15 joystick buttons using three layers (Fn1 and Fn2). */ #include #include +#include "erls.h" #include "ResponsiveAnalogRead.h" -// CRSF -#define CRSF_MAX_CHANNEL 16 -#define CRSF_TYPE_CHANNELS 0x16 -#define CRSF_DIGITAL_CHANNEL_MIN 172 -#define CRSF_DIGITAL_CHANNEL_CENTER 992 -#define CRSF_DIGITAL_CHANNEL_MAX 1811 -#define CRSF_TIME_BETWEEN_FRAMES_US 1666 // 1.6 ms 500Hz -#define CRSF_PACKET_SIZE 26 -#define CRSF_CMD_PACKET_SIZE 8 - -// ELRS command -#define ELRS_ADDRESS 0xEE -#define ELRS_BIND_COMMAND 0xFF -#define ELRS_WIFI_COMMAND 0xFE -#define ELRS_PKT_RATE_COMMAND 0x01 -#define ELRS_TLM_RATIO_COMMAND 0x02 -#define ELRS_SWITCH_MODE_COMMAND 0x03 -#define ELRS_MODEL_MATCH_COMMAND 0x04 -#define ELRS_POWER_COMMAND 0x06 -#define ELRS_BLE_JOYSTIC_COMMAND 17 -#define ELRS_TYPE_SETTINGS_WRITE 0x2D -#define ELRS_ADDR_RADIO 0xEA -#define ELRS_SERIAL_PORT Serial1 -#define ELRS_SERIAL_BAUDRATE 400000 -#define ELRS_PKT_RATE 3 // 0 = 50Hz, 1 = 100Hz, 2 = 200Hz, 3 = 500Hz, 4 = 1000Hz -#define ELRS_POWER 2 // 0 = 10mW, 1 = 25mW, 2 = 100mW, 3 = 250mW, 4 = 500mW, 5 = 1000mW - -// crc implementation from CRSF protocol document rev7 -static uint8_t crsf_crc8tab[256] = { - 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, - 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, - 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, - 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, - 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, - 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, - 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, - 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, - 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, - 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, - 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, - 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, - 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, - 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, - 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, - 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9}; - -uint8_t crsf_packet[CRSF_PACKET_SIZE]; -uint8_t crsf_cmd_packet[CRSF_CMD_PACKET_SIZE]; -int16_t elrs_channels[CRSF_MAX_CHANNEL]; -bool elrs_init_done = false; -int elrs_init_counter = 0; +#define LED_MODE_OFF 0 +#define LED_MODE_ON 1 +#define LED_MODE_BLINK 2 +#define LED_ON HIGH +#define LED_OFF LOW const int STATUS_LED_PIN = 13; bool status_led_on = false; -int status_led_mode = 2; +int status_led_mode = LED_MODE_BLINK; const int BUTTON_LED_1_PIN = 22; bool button_led_1_on = false; -int button_led_1_mode = 0; +int button_led_1_mode = LED_MODE_OFF; const int BUTTON_LED_2_PIN = 23; bool button_led_2_on = false; -int button_led_2_mode = 0; - -unsigned long current_timestamp = 0; -unsigned long process_data_timestamp = 0; -unsigned long indicator_timestamp = 0; -unsigned long send_usb_timestamp = 0; +int button_led_2_mode = LED_MODE_OFF; +#define TIME_US_1ms 1000 +#define TIME_US_5ms 5000 +#define TIME_US_200ms 200000 unsigned long current_timestamp_micros = 0; +unsigned long process_data_timestamp_micros = 0; +unsigned long indicator_timestamp_micros = 0; +unsigned long send_usb_timestamp_micros = 0; unsigned long send_elrs_timestamp_micros = 0; -const int BUTTON_FLU_PIN = 4; // Front left upper button -const int BUTTON_FLD_PIN = 5; // Front left lower button -const int BUTTON_FRU_PIN = 6; // Front right upper button -const int BUTTON_FRD_PIN = 7; // Front right lower button -const int BUTTON_TLU_PIN = 9; // top upper left button -const int BUTTON_TRU_PIN = 10; // Top upper right button -const int BUTTON_TLD_PIN = 8; // Top left lower button -const int BUTTON_TRD_PIN = 11; // Top right lower button +#define BUTTON_PRESSED LOW +#define BUTTON_NOT_PRESSED HIGH +const int BUTTON_FRONT_LEFT_UPPER_PIN = 4; +const int BUTTON_FRONT_LEFT_LOWER_PIN = 5; +const int BUTTON_FRONT_RIGHT_UPPER_PIN = 6; +const int BUTTON_FRONT_RIGHT_LOWER_PIN = 7; +const int BUTTON_TOP_LEFT_UPPER_PIN = 9; +const int BUTTON_TOP_RIGHT_UPPER_PIN = 10; +const int BUTTON_TOP_LEFT_LOWER_PIN = 8; +const int BUTTON_TOP_RIGHT_LOWER_PIN = 11; -const int GIMBAL_MODE_PIN = 21; // Open = M7, Closed (GND) = M10 +#define GIMBAL_MODE_FRSKY_M7 0 +#define GIMBAL_MODE_FRSKY_M10 1 +const int GIMBAL_MODE_PIN = 21; +int gimbal_mode = GIMBAL_MODE_FRSKY_M7; bool toggle_button_arm = false; bool toggle_button_mode = false; int toggle_button_arm_previous_value = HIGH; -#define HID_AXIS_MAX 1023 -#define HID_AXIS_MIN 0 -#define HID_AXIS_CENTER 512 -#define AXIS_MAX 4096 -#define AXIS_MIN 0 -#define AXIS_CENTER 2048 +#define AXIS_10BIT_MAX 1023 +#define AXIS_10BIT_MIN 0 +#define AXIS_10BIT_CENTER 512 +#define AXIS_12BIT_MAX 4096 +#define AXIS_12BIT_MIN 0 +#define AXIS_12BIT_CENTER 2048 #define DEADZONE_X 50 #define DEADZONE_Y 50 +#define JOYSTICK_HAT_CENTER -1 enum EEPROM_ADR { @@ -212,33 +121,26 @@ enum EEPROM_ADR }; int joystick_counter = 0; -int joystick_x1 = 0; -int joystick_x1_hid = 0; -int joystick_x1_max = 4096; -int joystick_x1_min = 0; -int joystick_x1_center = joystick_x1_max/2; -int joystick_y1 = 0; -int joystick_y1_hid = 0; -int joystick_y1_hid_rev = 0; -int joystick_y1_hid_rev_mode = 0; -int joystick_y1_max = 4096; -int joystick_y1_min = 0; -int joystick_y1_center = joystick_y1_max/2; -int joystick_x2 = 0; -int joystick_x2_hid = 0; -int joystick_x2_max = 4096; -int joystick_x2_min = 0; -int joystick_x2_center = joystick_x2_max/2; -int joystick_y2 = 0; -int joystick_y2_hid = 0; -int joystick_y2_max = 4096; -int joystick_y2_min = 0; -int joystick_y2_center = joystick_y2_max/2; +int joystick_x1_12bit = 0; +int joystick_x1_12bit_max = 4096; +int joystick_x1_12bit_min = 0; +int joystick_x1_12bit_center = joystick_x1_12bit_max / 2; +int joystick_y1_12bit = 0; +int joystick_y1_12bit_max = 4096; +int joystick_y1_12bit_min = 0; +int joystick_y1_12bit_center = joystick_y1_12bit_max / 2; +int joystick_x2_12bit = 0; +int joystick_x2_12bit_max = 4096; +int joystick_x2_12bit_min = 0; +int joystick_x2_12bit_center = joystick_x2_12bit_max / 2; +int joystick_y2_12bit = 0; +int joystick_y2_12bit_max = 4096; +int joystick_y2_12bit_min = 0; +int joystick_y2_12bit_center = joystick_y2_12bit_max / 2; float exp_constant = 0.2; int fn_mode = 0; -int gimbal_mode = 0; ResponsiveAnalogRead analog_x1(A0, true); ResponsiveAnalogRead analog_y1(A1, true); @@ -251,502 +153,379 @@ ResponsiveAnalogRead analog_y2(A2, true); #define CALIBRATION_MINMAX 3 int joystick_calibration_mode = CALIBRATION_OFF; -// ----------------------------------------------- +/** + * @brief Save calibration data to EEPROM + */ +void save_to_eeprom() +{ + EEPROM.write(MAX_X1_ADR_LOW, joystick_x1_12bit_max); + EEPROM.write(MAX_X1_ADR_HIGH, joystick_x1_12bit_max >> 8); + EEPROM.write(MIN_X1_ADR_LOW, joystick_x1_12bit_min); + EEPROM.write(MIN_X1_ADR_HIGH, joystick_x1_12bit_min >> 8); + EEPROM.write(CNT_X1_ADR_LOW, joystick_x1_12bit_center); + EEPROM.write(CNT_X1_ADR_HIGH, joystick_x1_12bit_center >> 8); -void save_to_eeprom(){ - EEPROM.write(MAX_X1_ADR_LOW, joystick_x1_max); - EEPROM.write(MAX_X1_ADR_HIGH, joystick_x1_max >> 8); - EEPROM.write(MIN_X1_ADR_LOW, joystick_x1_min); - EEPROM.write(MIN_X1_ADR_HIGH, joystick_x1_min >> 8); - EEPROM.write(CNT_X1_ADR_LOW, joystick_x1_center); - EEPROM.write(CNT_X1_ADR_HIGH, joystick_x1_center >> 8); - - EEPROM.write(MAX_Y1_ADR_LOW, joystick_y1_max); - EEPROM.write(MAX_Y1_ADR_HIGH, joystick_y1_max >> 8); - EEPROM.write(MIN_Y1_ADR_LOW, joystick_y1_min); - EEPROM.write(MIN_Y1_ADR_HIGH, joystick_y1_min >> 8); - EEPROM.write(CNT_Y1_ADR_LOW, joystick_y1_center); - EEPROM.write(CNT_Y1_ADR_HIGH, joystick_y1_center >> 8); - - EEPROM.write(MAX_X2_ADR_LOW, joystick_x2_max); - EEPROM.write(MAX_X2_ADR_HIGH, joystick_x2_max >> 8); - EEPROM.write(MIN_X2_ADR_LOW, joystick_x2_min); - EEPROM.write(MIN_X2_ADR_HIGH, joystick_x2_min >> 8); - EEPROM.write(CNT_X2_ADR_LOW, joystick_x2_center); - EEPROM.write(CNT_X2_ADR_HIGH, joystick_x2_center >> 8); - - EEPROM.write(MAX_Y2_ADR_LOW, joystick_y2_max); - EEPROM.write(MAX_Y2_ADR_HIGH, joystick_y2_max >> 8); - EEPROM.write(MIN_Y2_ADR_LOW, joystick_y2_min); - EEPROM.write(MIN_Y2_ADR_HIGH, joystick_y2_min >> 8); - EEPROM.write(CNT_Y2_ADR_LOW, joystick_y2_center); - EEPROM.write(CNT_Y2_ADR_HIGH, joystick_y2_center >> 8); + EEPROM.write(MAX_Y1_ADR_LOW, joystick_y1_12bit_max); + EEPROM.write(MAX_Y1_ADR_HIGH, joystick_y1_12bit_max >> 8); + EEPROM.write(MIN_Y1_ADR_LOW, joystick_y1_12bit_min); + EEPROM.write(MIN_Y1_ADR_HIGH, joystick_y1_12bit_min >> 8); + EEPROM.write(CNT_Y1_ADR_LOW, joystick_y1_12bit_center); + EEPROM.write(CNT_Y1_ADR_HIGH, joystick_y1_12bit_center >> 8); + + EEPROM.write(MAX_X2_ADR_LOW, joystick_x2_12bit_max); + EEPROM.write(MAX_X2_ADR_HIGH, joystick_x2_12bit_max >> 8); + EEPROM.write(MIN_X2_ADR_LOW, joystick_x2_12bit_min); + EEPROM.write(MIN_X2_ADR_HIGH, joystick_x2_12bit_min >> 8); + EEPROM.write(CNT_X2_ADR_LOW, joystick_x2_12bit_center); + EEPROM.write(CNT_X2_ADR_HIGH, joystick_x2_12bit_center >> 8); + + EEPROM.write(MAX_Y2_ADR_LOW, joystick_y2_12bit_max); + EEPROM.write(MAX_Y2_ADR_HIGH, joystick_y2_12bit_max >> 8); + EEPROM.write(MIN_Y2_ADR_LOW, joystick_y2_12bit_min); + EEPROM.write(MIN_Y2_ADR_HIGH, joystick_y2_12bit_min >> 8); + EEPROM.write(CNT_Y2_ADR_LOW, joystick_y2_12bit_center); + EEPROM.write(CNT_Y2_ADR_HIGH, joystick_y2_12bit_center >> 8); } -void load_from_eeprom(){ - joystick_x1_max = (EEPROM.read(MAX_X1_ADR_HIGH) << 8); - joystick_x1_max |= EEPROM.read(MAX_X1_ADR_LOW); - joystick_x1_min = (EEPROM.read(MIN_X1_ADR_HIGH) << 8); - joystick_x1_min |= EEPROM.read(MIN_X1_ADR_LOW); - joystick_x1_center = (EEPROM.read(CNT_X1_ADR_HIGH) << 8); - joystick_x1_center |= EEPROM.read(CNT_X1_ADR_LOW); +/** + * @brief Load calibration data from EEPROM + */ +void load_from_eeprom() +{ + joystick_x1_12bit_max = (EEPROM.read(MAX_X1_ADR_HIGH) << 8); + joystick_x1_12bit_max |= EEPROM.read(MAX_X1_ADR_LOW); + joystick_x1_12bit_min = (EEPROM.read(MIN_X1_ADR_HIGH) << 8); + joystick_x1_12bit_min |= EEPROM.read(MIN_X1_ADR_LOW); + joystick_x1_12bit_center = (EEPROM.read(CNT_X1_ADR_HIGH) << 8); + joystick_x1_12bit_center |= EEPROM.read(CNT_X1_ADR_LOW); - joystick_y1_max = (EEPROM.read(MAX_Y1_ADR_HIGH) << 8); - joystick_y1_max |= EEPROM.read(MAX_Y1_ADR_LOW); - joystick_y1_min = (EEPROM.read(MIN_Y1_ADR_HIGH) << 8); - joystick_y1_min |= EEPROM.read(MIN_Y1_ADR_LOW); - joystick_y1_center = (EEPROM.read(CNT_Y1_ADR_HIGH) << 8); - joystick_y1_center |= EEPROM.read(CNT_Y1_ADR_LOW); - - joystick_x2_max = (EEPROM.read(MAX_X2_ADR_HIGH) << 8); - joystick_x2_max |= EEPROM.read(MAX_X2_ADR_LOW); - joystick_x2_min = (EEPROM.read(MIN_X2_ADR_HIGH) << 8); - joystick_x2_min |= EEPROM.read(MIN_X2_ADR_LOW); - joystick_x2_center = (EEPROM.read(CNT_X2_ADR_HIGH) << 8); - joystick_x2_center |= EEPROM.read(CNT_X2_ADR_LOW); + joystick_y1_12bit_max = (EEPROM.read(MAX_Y1_ADR_HIGH) << 8); + joystick_y1_12bit_max |= EEPROM.read(MAX_Y1_ADR_LOW); + joystick_y1_12bit_min = (EEPROM.read(MIN_Y1_ADR_HIGH) << 8); + joystick_y1_12bit_min |= EEPROM.read(MIN_Y1_ADR_LOW); + joystick_y1_12bit_center = (EEPROM.read(CNT_Y1_ADR_HIGH) << 8); + joystick_y1_12bit_center |= EEPROM.read(CNT_Y1_ADR_LOW); - joystick_y2_max = (EEPROM.read(MAX_Y2_ADR_HIGH) << 8); - joystick_y2_max |= EEPROM.read(MAX_Y2_ADR_LOW); - joystick_y2_min = (EEPROM.read(MIN_Y2_ADR_HIGH) << 8); - joystick_y2_min |= EEPROM.read(MIN_Y2_ADR_LOW); - joystick_y2_center = (EEPROM.read(CNT_Y2_ADR_HIGH) << 8); - joystick_y2_center |= EEPROM.read(CNT_Y2_ADR_LOW); + joystick_x2_12bit_max = (EEPROM.read(MAX_X2_ADR_HIGH) << 8); + joystick_x2_12bit_max |= EEPROM.read(MAX_X2_ADR_LOW); + joystick_x2_12bit_min = (EEPROM.read(MIN_X2_ADR_HIGH) << 8); + joystick_x2_12bit_min |= EEPROM.read(MIN_X2_ADR_LOW); + joystick_x2_12bit_center = (EEPROM.read(CNT_X2_ADR_HIGH) << 8); + joystick_x2_12bit_center |= EEPROM.read(CNT_X2_ADR_LOW); + + joystick_y2_12bit_max = (EEPROM.read(MAX_Y2_ADR_HIGH) << 8); + joystick_y2_12bit_max |= EEPROM.read(MAX_Y2_ADR_LOW); + joystick_y2_12bit_min = (EEPROM.read(MIN_Y2_ADR_HIGH) << 8); + joystick_y2_12bit_min |= EEPROM.read(MIN_Y2_ADR_LOW); + joystick_y2_12bit_center = (EEPROM.read(CNT_Y2_ADR_HIGH) << 8); + joystick_y2_12bit_center |= EEPROM.read(CNT_Y2_ADR_LOW); } -// CRSF CRC calculation via lookup table -uint8_t calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) { - uint8_t crc = 0; - for (uint8_t i = 0; i < len; i++){ - crc = crsf_crc8tab[crc ^ *ptr++]; +/** + * @brief Calibrate all joystick axis + * + * @param analog_x1 + * @param analog_y1 + * @param analog_x2 + * @param analog_y2 + */ +void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) +{ + + joystick_x1_12bit = AXIS_12BIT_CENTER; + joystick_y1_12bit = AXIS_12BIT_CENTER; + joystick_x2_12bit = AXIS_12BIT_CENTER; + joystick_y2_12bit = AXIS_12BIT_CENTER; + + // Check for calibration mode + if (joystick_calibration_mode == CALIBRATION_INIT) + { + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_NOT_PRESSED) + { + joystick_calibration_mode = CALIBRATION_CENTER; + } + } + + // Calibrate joystick center values + else if (joystick_calibration_mode == CALIBRATION_CENTER) + { + joystick_x1_12bit_center = analog_x1; + joystick_y1_12bit_center = analog_y1; + joystick_x1_12bit_max = joystick_x1_12bit_center; + joystick_x1_12bit_min = joystick_x1_12bit_center; + joystick_y1_12bit_max = joystick_y1_12bit_center; + joystick_y1_12bit_min = joystick_y1_12bit_center; + + joystick_x2_12bit_center = analog_x2; + joystick_y2_12bit_center = analog_y2; + joystick_x2_12bit_max = joystick_x2_12bit_center; + joystick_x2_12bit_min = joystick_x2_12bit_center; + joystick_y2_12bit_max = joystick_y2_12bit_center; + joystick_y2_12bit_min = joystick_y2_12bit_center; + + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) + { + joystick_calibration_mode = CALIBRATION_MINMAX; + } + } + + // Calibrate joystick min/max values + else if (joystick_calibration_mode == CALIBRATION_MINMAX) + { + if (analog_x1 > joystick_x1_12bit_max) joystick_x1_12bit_max = analog_x1; + if (analog_x1 < joystick_x1_12bit_min) joystick_x1_12bit_min = analog_x1; + if (analog_y1 > joystick_y1_12bit_max) joystick_y1_12bit_max = analog_y1; + if (analog_y1 < joystick_y1_12bit_min) joystick_y1_12bit_min = analog_y1; + if (analog_x2 > joystick_x2_12bit_max) joystick_x2_12bit_max = analog_x2; + if (analog_x2 < joystick_x2_12bit_min) joystick_x2_12bit_min = analog_x2; + if (analog_y2 > joystick_y2_12bit_max) joystick_y2_12bit_max = analog_y2; + if (analog_y2 < joystick_y2_12bit_min) joystick_y2_12bit_min = analog_y2; + + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) + { + joystick_calibration_mode = CALIBRATION_OFF; + save_to_eeprom(); + } } - return crc; } -// Prepare CRSF data packet -void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) { - packet[0] = ELRS_ADDRESS; // Header - packet[1] = 24; // length - packet[2] = CRSF_TYPE_CHANNELS; - packet[3] = (uint8_t)(channels[0] & 0x07FF); - packet[4] = (uint8_t)((channels[0] & 0x07FF) >> 8 | (channels[1] & 0x07FF) << 3); - packet[5] = (uint8_t)((channels[1] & 0x07FF) >> 5 | (channels[2] & 0x07FF) << 6); - packet[6] = (uint8_t)((channels[2] & 0x07FF) >> 2); - packet[7] = (uint8_t)((channels[2] & 0x07FF) >> 10 | (channels[3] & 0x07FF) << 1); - packet[8] = (uint8_t)((channels[3] & 0x07FF) >> 7 | (channels[4] & 0x07FF) << 4); - packet[9] = (uint8_t)((channels[4] & 0x07FF) >> 4 | (channels[5] & 0x07FF) << 7); - packet[10] = (uint8_t)((channels[5] & 0x07FF) >> 1); - packet[11] = (uint8_t)((channels[5] & 0x07FF) >> 9 | (channels[6] & 0x07FF) << 2); - packet[12] = (uint8_t)((channels[6] & 0x07FF) >> 6 | (channels[7] & 0x07FF) << 5); - packet[13] = (uint8_t)((channels[7] & 0x07FF) >> 3); - packet[14] = (uint8_t)((channels[8] & 0x07FF)); - packet[15] = (uint8_t)((channels[8] & 0x07FF) >> 8 | (channels[9] & 0x07FF) << 3); - packet[16] = (uint8_t)((channels[9] & 0x07FF) >> 5 | (channels[10] & 0x07FF) << 6); - packet[17] = (uint8_t)((channels[10] & 0x07FF) >> 2); - packet[18] = (uint8_t)((channels[10] & 0x07FF) >> 10 | (channels[11] & 0x07FF) << 1); - packet[19] = (uint8_t)((channels[11] & 0x07FF) >> 7 | (channels[12] & 0x07FF) << 4); - packet[20] = (uint8_t)((channels[12] & 0x07FF) >> 4 | (channels[13] & 0x07FF) << 7); // Channel not used by ELRS - packet[21] = (uint8_t)((channels[13] & 0x07FF) >> 1); // Channel not used by ELRS - packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2); // Channel not used by ELRS - packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5); // Channel not used by ELRS - packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3); // Channel not used by ELRS - packet[25] = calculate_crsf_crc8(&packet[2], packet[1] - 1); -} - -// Prepare CRSF setup packet -void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) { - packet_cmd[0] = ELRS_ADDRESS; // Header - packet_cmd[1] = 6; // length - packet_cmd[2] = ELRS_TYPE_SETTINGS_WRITE; - packet_cmd[3] = ELRS_ADDRESS; - packet_cmd[4] = ELRS_ADDR_RADIO; - packet_cmd[5] = command; - packet_cmd[6] = value; - packet_cmd[7] = calculate_crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); -} - -void send_elrs_data(){ +/** + * @brief Save joystick calibration values to EEPROM + */ +void send_erls_data() +{ // Set ELRS analog channels - elrs_channels[0] = map(joystick_x1, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); - elrs_channels[1] = map(joystick_y1, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); - elrs_channels[2] = map(joystick_x2, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); - elrs_channels[3] = map(joystick_y2, AXIS_MIN, AXIS_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); + erls_set_data(map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 0); + erls_set_data(map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 1); + erls_set_data(map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 2); + erls_set_data(map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 3); // Set ELRS digital channels - for (int i = 4; i < CRSF_MAX_CHANNEL; i++){ - elrs_channels[i] = CRSF_DIGITAL_CHANNEL_MIN; - } - if (toggle_button_arm){ - elrs_channels[4] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (toggle_button_mode){ - elrs_channels[5] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (digitalRead(BUTTON_FRU_PIN) == LOW){ - elrs_channels[6] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (digitalRead(BUTTON_FRD_PIN) == LOW){ - elrs_channels[7] = CRSF_DIGITAL_CHANNEL_MAX; - } - if (digitalRead(BUTTON_TRU_PIN) == LOW){ - elrs_channels[8] = CRSF_DIGITAL_CHANNEL_MAX; + for (int i = 4; i < CRSF_MAX_CHANNEL; i++) + { + erls_set_data(CRSF_DIGITAL_CHANNEL_MIN, i); } - // Send ELRS data - if (elrs_init_done == true){ - prepare_crsf_data_packet(crsf_packet, elrs_channels); - ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); - } - else{ - // Setting up initial communication link between ERLS TX and Teensy (give ERLS TX time to auto detect Teensy) - if (elrs_init_counter < 500){ - prepare_crsf_data_packet(crsf_packet, elrs_channels); - ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); - elrs_init_counter++; - } - // Send command to update TX packet rate to 500Hz - else if (elrs_init_counter < 505){ - prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, ELRS_PKT_RATE); - ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); - elrs_init_counter++; - } - // Send command to update TX power to 100mW - else if (elrs_init_counter < 510){ - prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, ELRS_POWER); - ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); - elrs_init_counter++; - } - else{ - elrs_init_done = true; - } - } + if (toggle_button_arm) erls_set_data(CRSF_DIGITAL_CHANNEL_MAX, 4); + if (toggle_button_mode) erls_set_data(CRSF_DIGITAL_CHANNEL_MAX, 5); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) erls_set_data(CRSF_DIGITAL_CHANNEL_MAX, 6); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) erls_set_data(CRSF_DIGITAL_CHANNEL_MAX, 7); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) erls_set_data(CRSF_DIGITAL_CHANNEL_MAX, 8); + + // Send ELRS data + erls_send_data(); } -void send_usb_data(){ +/** + * Send USB data to PC + */ +void send_usb_data() +{ + // Set USB analog channels + int joystick_x1_10bit = map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); + int joystick_y1_10bit = map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); + int joystick_x2_10bit = map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); + int joystick_y2_10bit = map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); - // Set joystick buttons to released - for (int i = 1; i < 32; i++){ - Joystick.button(i, 0); - } + Joystick.Zrotate(joystick_x1_10bit); + Joystick.Z(joystick_y1_10bit); - // Set joystick hat to center position - Joystick.hat(-1); - - // Set joystick buttons to pressed - if (fn_mode == 2){ - - if (digitalRead(BUTTON_FLD_PIN) == LOW){ - Joystick.button(12, 1); - } - if (digitalRead(BUTTON_FRD_PIN) == LOW){ - Joystick.button(13, 1); - } - if (digitalRead(BUTTON_TLD_PIN) == LOW){ - Joystick.button(14, 1); - } - if (digitalRead(BUTTON_TRD_PIN) == LOW){ - Joystick.button(15, 1); - } - } - else if (fn_mode == 1){ - - if (digitalRead(BUTTON_FLD_PIN) == LOW){ - Joystick.button(8, 1); - } - if (digitalRead(BUTTON_FRD_PIN) == LOW){ - Joystick.button(9, 1); - } - if (digitalRead(BUTTON_TLD_PIN) == LOW){ - Joystick.button(10, 1); - } - if (digitalRead(BUTTON_TRD_PIN) == LOW){ - Joystick.button(11, 1); - } - } - else{ - - if (digitalRead(BUTTON_FLD_PIN) == LOW){ - Joystick.button(2, 1); - } - if (digitalRead(BUTTON_FRD_PIN) == LOW){ - Joystick.button(4, 1); - } - if (digitalRead(BUTTON_TRU_PIN) == LOW){ - Joystick.button(5, 1); - } - if (digitalRead(BUTTON_TLD_PIN) == LOW){ - Joystick.button(6, 1); - } - if (digitalRead(BUTTON_TRD_PIN) == LOW){ - Joystick.button(7, 1); - } - } - - if (digitalRead(BUTTON_FLU_PIN) == LOW){ - Joystick.button(1, 1); - } - if (digitalRead(BUTTON_FRU_PIN) == LOW){ - Joystick.button(3, 1); - } - - // Set axis values - Joystick.Zrotate(joystick_x1_hid); - Joystick.Z(joystick_y1_hid); - - if (fn_mode == 2){ - Joystick.X(HID_AXIS_CENTER); - Joystick.Y(HID_AXIS_CENTER); - Joystick.sliderRight(joystick_x2_hid); - Joystick.sliderLeft(joystick_y2_hid); - } - else if (fn_mode == 1){ - Joystick.X(joystick_x2_hid); - Joystick.Y(HID_AXIS_CENTER); - Joystick.sliderRight(HID_AXIS_CENTER); - Joystick.sliderLeft(joystick_y2_hid); - } - else{ - Joystick.X(joystick_x2_hid); - Joystick.Y(joystick_y2_hid); - Joystick.sliderRight(HID_AXIS_CENTER); - Joystick.sliderLeft(HID_AXIS_CENTER); - } - - // Send USB Joystick data - Joystick.send_now(); -} - -void process_input_data(){ - - int analog_x1_inv = 0; - int analog_y1_inv = 0; - int analog_x2_inv = 0; - int analog_y2_inv = 0; - - if (gimbal_mode == 1){ - // FrSky M10 Gimbal - analog_x1_inv = constrain(AXIS_MAX - analog_x1.getValue(), AXIS_MIN, AXIS_MAX); - analog_y1_inv = constrain(analog_y1.getValue(), AXIS_MIN, AXIS_MAX); - analog_x2_inv = constrain(analog_x2.getValue(), AXIS_MIN, AXIS_MAX); - analog_y2_inv = constrain(AXIS_MAX - analog_y2.getValue(), AXIS_MIN, AXIS_MAX); - } - else{ - // FrSky M7 Gimbal - analog_x1_inv = constrain(analog_x1.getValue(), AXIS_MIN, AXIS_MAX); - analog_y1_inv = constrain(AXIS_MAX - analog_y1.getValue(), AXIS_MIN, AXIS_MAX); - analog_x2_inv = constrain(AXIS_MAX - analog_x2.getValue(), AXIS_MIN, AXIS_MAX); - analog_y2_inv = constrain(analog_y2.getValue(), AXIS_MIN, AXIS_MAX); - } - - if (joystick_calibration_mode == CALIBRATION_OFF){ - - // Calculate X1 joystick values - if(analog_x1_inv > (joystick_x1_center + DEADZONE_X)){ - joystick_x1 = constrain(map(analog_x1_inv, (joystick_x1_center + DEADZONE_X), joystick_x1_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); - } - else if(analog_x1_inv < (joystick_x1_center - DEADZONE_X)){ - joystick_x1 = constrain(map(analog_x1_inv, joystick_x1_min, (joystick_x1_center - DEADZONE_X), AXIS_MIN, AXIS_CENTER), AXIS_MIN, AXIS_CENTER); - } - else{ - joystick_x1 = AXIS_CENTER; - } - - // Calculate Y1 joystick values - if(analog_y1_inv > (joystick_y1_min + DEADZONE_Y)){ - joystick_y1 = constrain(map(analog_y1_inv, (joystick_y1_min + DEADZONE_Y), joystick_y1_max, AXIS_MIN, AXIS_MAX), AXIS_MIN, AXIS_MAX); - } - else{ - joystick_y1 = AXIS_MIN; - } - - // Calculate X2 joystick values - if(analog_x2_inv > (joystick_x2_center + DEADZONE_X)){ - joystick_x2 = constrain(map(analog_x2_inv, (joystick_x2_center + DEADZONE_X), joystick_x2_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); - } - else if(analog_x2_inv < (joystick_x2_center - DEADZONE_X)){ - joystick_x2 = constrain(map(analog_x2_inv, joystick_x2_min, (joystick_x2_center - DEADZONE_X), AXIS_MIN, AXIS_CENTER), AXIS_MIN, AXIS_CENTER); - } - else{ - joystick_x2 = AXIS_CENTER; - } - - // Calculate Y2 joystick values - if(analog_y2_inv > (joystick_y2_center + DEADZONE_Y)){ - joystick_y2 = constrain(map(analog_y2_inv, (joystick_y2_center + DEADZONE_Y), joystick_y2_max, AXIS_CENTER, AXIS_MAX), AXIS_CENTER, AXIS_MAX); - } - else if(analog_y2_inv < (joystick_y2_center - DEADZONE_Y)){ - joystick_y2 = constrain(map(analog_y2_inv, joystick_y2_min, (joystick_y2_center - DEADZONE_Y), AXIS_MIN, AXIS_CENTER), AXIS_MIN, AXIS_CENTER); - } - else{ - joystick_y2 = AXIS_CENTER; - } - - // Calculate new X1 values after applying exp curve - if (joystick_x1 != AXIS_CENTER){ - float joystick_x_float = joystick_x1 / float(AXIS_MAX); - float joystick_x_exp = exp_constant * (0.5 + 256 * pow((joystick_x_float - 0.5),9)) + (1 - exp_constant) * joystick_x_float; - joystick_x1_hid = int(joystick_x_exp * float(HID_AXIS_MAX)); - joystick_x1_hid = constrain(joystick_x1_hid, HID_AXIS_MIN, HID_AXIS_MAX); - } - else{ - joystick_x1_hid = HID_AXIS_CENTER; - } - - // Calculate new Y1 values - joystick_y1_hid = map(joystick_y1, AXIS_MIN, AXIS_MAX, HID_AXIS_MIN, HID_AXIS_MAX); - - // Calculate new X2 values after applying exp curve - if (joystick_x2 != AXIS_CENTER){ - float joystick_x_float = joystick_x2 / float(AXIS_MAX); - float joystick_x_exp = exp_constant * (0.5 + 256 * pow((joystick_x_float - 0.5),9)) + (1 - exp_constant) * joystick_x_float; - joystick_x2_hid = int(joystick_x_exp * float(HID_AXIS_MAX)); - joystick_x2_hid = constrain(joystick_x2_hid, HID_AXIS_MIN, HID_AXIS_MAX); - } - else{ - joystick_x2_hid = HID_AXIS_CENTER; - } - - // Calculate new Y2 values after applying exp curve - if (joystick_y2 != AXIS_CENTER){ - float joystick_y_float = joystick_y2 / float(AXIS_MAX); - float joystick_y_exp = exp_constant * (0.5 + 256 * pow((joystick_y_float - 0.5),9)) + (1 - exp_constant) * joystick_y_float; - joystick_y2_hid = int(joystick_y_exp * float(HID_AXIS_MAX)); - joystick_y2_hid = constrain(joystick_y2_hid, HID_AXIS_MIN, HID_AXIS_MAX); - } - else{ - joystick_y2_hid = HID_AXIS_CENTER; - } - - // Check fn mode - fn_mode = 0; - if (digitalRead(BUTTON_TLU_PIN) == LOW){ - fn_mode = 1; - if (digitalRead(BUTTON_TRU_PIN) == LOW){ - fn_mode = 2; - } - } - - // Check toggle mode buttons - if (digitalRead(BUTTON_FLU_PIN) == LOW){ - toggle_button_mode = true; - } - else if (digitalRead(BUTTON_FLD_PIN) == LOW){ - toggle_button_mode = false; - } - - // Check toggle arm button - if (fn_mode == 1){ - if (digitalRead(BUTTON_TRD_PIN) != toggle_button_arm_previous_value){ - toggle_button_arm_previous_value = digitalRead(BUTTON_TRD_PIN); - if (digitalRead(BUTTON_TRD_PIN) == LOW){ - if (toggle_button_arm == false){ - toggle_button_arm = true; - } - else{ - toggle_button_arm = false; - } - } - } - } - } - else{ - - // Calibration mode. - joystick_x1 = AXIS_CENTER; - joystick_y1 = AXIS_CENTER; - joystick_x2 = AXIS_CENTER; - joystick_y2 = AXIS_CENTER; - joystick_x1_hid = HID_AXIS_CENTER; - joystick_y1_hid = HID_AXIS_CENTER; - joystick_x2_hid = HID_AXIS_CENTER; - joystick_y2_hid = HID_AXIS_CENTER; - - // Check for calibration mode - if (joystick_calibration_mode == CALIBRATION_INIT){ - if (digitalRead(BUTTON_TLD_PIN) == HIGH){ - joystick_calibration_mode = CALIBRATION_CENTER; - } - } - - // Calibrate joystick center values - else if (joystick_calibration_mode == CALIBRATION_CENTER){ - joystick_x1_center = analog_x1_inv; - joystick_y1_center = analog_y1_inv; - joystick_x1_max = joystick_x1_center; - joystick_x1_min = joystick_x1_center; - joystick_y1_max = joystick_y1_center; - joystick_y1_min = joystick_y1_center; - - joystick_x2_center = analog_x2_inv; - joystick_y2_center = analog_y2_inv; - joystick_x2_max = joystick_x2_center; - joystick_x2_min = joystick_x2_center; - joystick_y2_max = joystick_y2_center; - joystick_y2_min = joystick_y2_center; - - if (digitalRead(BUTTON_TLD_PIN) == LOW){ - joystick_calibration_mode = CALIBRATION_MINMAX; - } - } - - // Calibrate joystick min/max values - else if (joystick_calibration_mode == CALIBRATION_MINMAX){ - if(analog_x1_inv > joystick_x1_max){ - joystick_x1_max = analog_x1_inv; - } - if(analog_x1_inv < joystick_x1_min){ - joystick_x1_min = analog_x1_inv; - } - if(analog_y1_inv > joystick_y1_max){ - joystick_y1_max = analog_y1_inv; - } - if(analog_y1_inv < joystick_y1_min){ - joystick_y1_min = analog_y1_inv; - } - - if(analog_x2_inv > joystick_x2_max){ - joystick_x2_max = analog_x2_inv; - } - if(analog_x2_inv < joystick_x2_min){ - joystick_x2_min = analog_x2_inv; - } - if(analog_y2_inv > joystick_y2_max){ - joystick_y2_max = analog_y2_inv; - } - if(analog_y2_inv < joystick_y2_min){ - joystick_y2_min = analog_y2_inv; - } - - if (digitalRead(BUTTON_TRD_PIN) == LOW){ - joystick_calibration_mode = CALIBRATION_OFF; - save_to_eeprom(); - } - } - } -} - -/* Update indicator 0=Off, 1=On, 2=Blink */ -void update_indicator(int mode, bool ¤t_state, int pin){ - - if (mode == 2 && current_state == false) + if (fn_mode == 2) { - digitalWrite(pin, HIGH); - current_state = true; + Joystick.X(AXIS_10BIT_CENTER); + Joystick.Y(AXIS_10BIT_CENTER); + Joystick.sliderRight(joystick_x2_10bit); + Joystick.sliderLeft(joystick_y2_10bit); } - else if (mode == 2 && current_state == true) + else if (fn_mode == 1) { - digitalWrite(pin, LOW); - current_state = false; - } - else if (mode == 1) - { - digitalWrite(pin, HIGH); - current_state = true; + Joystick.X(AXIS_10BIT_CENTER); + Joystick.Y(joystick_y2_10bit); + Joystick.sliderRight(joystick_x2_10bit); + Joystick.sliderLeft(AXIS_10BIT_CENTER); } else { - digitalWrite(pin, LOW); - current_state = false; + Joystick.X(joystick_x2_10bit); + Joystick.Y(joystick_y2_10bit); + Joystick.sliderRight(AXIS_10BIT_CENTER); + Joystick.sliderLeft(AXIS_10BIT_CENTER); + } + + // Set USB digital channels + for (int i = 1; i < 32; i++) + { + Joystick.button(i, 0); + } + + Joystick.hat(JOYSTICK_HAT_CENTER); + + if (fn_mode == 2) + { + if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(12, 1); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(13, 1); + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(14, 1); + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(15, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(16, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(17, 1); + } + else if (fn_mode == 1) + { + if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(8, 1); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(9, 1); + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(10, 1); + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(11, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(1, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(2, 1); + } + else + { + if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(3, 1); + if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(4, 1); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(5, 1); + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(6, 1); + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(7, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(1, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(2, 1); + } + + Joystick.send_now(); +} + +/** + * @brief Apply calibration to 12-bit gimbal value + * + * @param gimbal_value + * @param min_value + * @param max_value + * @param center_value + * @param deadband_value + * @param expo_value + */ +int apply_calibration_12bit(int gimbal_value, int min_value, int max_value, int center_value, int deadband_value, int expo_value) +{ + + int calibrated_value = AXIS_12BIT_CENTER; + + if (gimbal_value > (center_value + deadband_value)) + { + calibrated_value = constrain(map(gimbal_value, (center_value + deadband_value), max_value, AXIS_12BIT_CENTER, AXIS_12BIT_MAX), AXIS_12BIT_CENTER, AXIS_12BIT_MAX); + } + else if (gimbal_value < (center_value - deadband_value)) + { + calibrated_value = constrain(map(gimbal_value, min_value, (center_value - deadband_value), AXIS_12BIT_MIN, AXIS_12BIT_CENTER), AXIS_12BIT_MIN, AXIS_12BIT_CENTER); + } + + if (expo_value != 0) + { + float joystick_x_float = calibrated_value / float(AXIS_12BIT_MAX); + /* Calculate expo using 9th order polynomial function with 0.5 as center point */ + float joystick_x_exp = expo_value * (0.5 + 256 * pow((joystick_x_float - 0.5), 9)) + (1 - expo_value) * joystick_x_float; + calibrated_value = constrain(int(joystick_x_exp * float(AXIS_12BIT_MAX)), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + } + + return calibrated_value; +} + +/** + * @brief Process input data from gimbal and buttons + */ +void process_input_data() +{ + + int analog_x1_gimbal_value = 0; + int analog_y1_gimbal_value = 0; + int analog_x2_gimbal_value = 0; + int analog_y2_gimbal_value = 0; + + if (gimbal_mode == GIMBAL_MODE_FRSKY_M10) + { + analog_x1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y1_gimbal_value = constrain(analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_x2_gimbal_value = constrain(analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + } + else if (gimbal_mode == GIMBAL_MODE_FRSKY_M7) + { + analog_x1_gimbal_value = constrain(analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_x2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y2_gimbal_value = constrain(analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + } + + if (joystick_calibration_mode != CALIBRATION_OFF) + { + calibrate_axis(analog_x1_gimbal_value, analog_y1_gimbal_value, analog_x2_gimbal_value, analog_y2_gimbal_value); + return; + } + + joystick_x1_12bit = apply_calibration_12bit(analog_x1_gimbal_value, joystick_x1_12bit_min, joystick_x1_12bit_max, joystick_x1_12bit_center, DEADZONE_X, exp_constant); + joystick_y1_12bit = apply_calibration_12bit(analog_y1_gimbal_value, joystick_y1_12bit_min, joystick_y1_12bit_max, joystick_y1_12bit_center, DEADZONE_Y, 0); + joystick_x2_12bit = apply_calibration_12bit(analog_x2_gimbal_value, joystick_x2_12bit_min, joystick_x2_12bit_max, joystick_x2_12bit_center, DEADZONE_X, exp_constant); + joystick_y2_12bit = apply_calibration_12bit(analog_y2_gimbal_value, joystick_y2_12bit_min, joystick_y2_12bit_max, joystick_y2_12bit_center, DEADZONE_Y, exp_constant); + + // Check fn mode + fn_mode = 0; + if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) + { + fn_mode = 1; + if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) + { + fn_mode = 2; + } + } + + // Check toggle mode buttons + if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) + { + toggle_button_mode = true; + } + else if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) + { + toggle_button_mode = false; + } + + // Check toggle arm button + if ((fn_mode == 1) && (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) != toggle_button_arm_previous_value)) + { + if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == false)) + { + toggle_button_arm = true; + } + else if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == true)) + { + toggle_button_arm = false; + } + toggle_button_arm_previous_value = digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN); + } +} + +/** + * @brief Update indicator LED + */ +void update_indicator(int led_mode, bool ¤t_led_state, int led_pin) +{ + + if (led_mode == LED_MODE_BLINK && current_led_state == false) + { + digitalWrite(led_pin, LED_ON); + current_led_state = true; + } + else if (led_mode == LED_MODE_BLINK && current_led_state == true) + { + digitalWrite(led_pin, LED_OFF); + current_led_state = false; + } + else if (led_mode == LED_MODE_ON) + { + digitalWrite(led_pin, LED_ON); + current_led_state = true; + } + else + { + digitalWrite(led_pin, LED_OFF); + current_led_state = false; } } @@ -754,29 +533,29 @@ void setup() { /* Init HW */ pinMode(STATUS_LED_PIN, OUTPUT); - digitalWrite(STATUS_LED_PIN, LOW); - - pinMode(BUTTON_LED_1_PIN, OUTPUT); - digitalWrite(BUTTON_LED_1_PIN, LOW); - - pinMode(BUTTON_LED_2_PIN, OUTPUT); - digitalWrite(BUTTON_LED_2_PIN, LOW); + digitalWrite(STATUS_LED_PIN, LED_OFF); + + pinMode(BUTTON_LED_1_PIN, OUTPUT); + digitalWrite(BUTTON_LED_1_PIN, LED_OFF); + + pinMode(BUTTON_LED_2_PIN, OUTPUT); + digitalWrite(BUTTON_LED_2_PIN, LED_OFF); + + pinMode(BUTTON_FRONT_LEFT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRONT_LEFT_UPPER_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRONT_RIGHT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRONT_RIGHT_UPPER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_LEFT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_RIGHT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_LEFT_UPPER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_RIGHT_UPPER_PIN, INPUT_PULLUP); - pinMode(BUTTON_FLD_PIN, INPUT_PULLUP); - pinMode(BUTTON_FLU_PIN, INPUT_PULLUP); - pinMode(BUTTON_FRD_PIN, INPUT_PULLUP); - pinMode(BUTTON_FRU_PIN, INPUT_PULLUP); - pinMode(BUTTON_TLD_PIN, INPUT_PULLUP); - pinMode(BUTTON_TRD_PIN, INPUT_PULLUP); - pinMode(BUTTON_TLU_PIN, INPUT_PULLUP); - pinMode(BUTTON_TRU_PIN, INPUT_PULLUP); - pinMode(GIMBAL_MODE_PIN, INPUT_PULLUP); // Set ADC resolution to 12bit - analogReadResolution(12); + analogReadResolution(12); analogReadAveraging(32); - delay(500); + delay(500); // Set analog (lib) resolution to 12bit analog_x1.setAnalogResolution(4096); @@ -784,27 +563,30 @@ void setup() analog_x2.setAnalogResolution(4096); analog_y2.setAnalogResolution(4096); - // Init EEPROM + // Init EEPROM load_from_eeprom(); // Init Joystick Joystick.useManualSend(true); - - // Check if calibration mode is enabled - if (digitalRead(BUTTON_TLD_PIN) == LOW){ + + // Check if calibration mode is enabled + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) + { joystick_calibration_mode = CALIBRATION_INIT; } - // Check if bootloader mode is enabled - if (digitalRead(BUTTON_TRD_PIN) == LOW){ + // Check if bootloader mode is enabled + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) + { digitalWrite(BUTTON_LED_2_PIN, HIGH); delay(200); - _reboot_Teensyduino_(); + _reboot_Teensyduino_(); } - // Check what gimbal mode is selected - if (digitalRead(GIMBAL_MODE_PIN) == LOW){ - gimbal_mode = 1; + // Check what gimbal mode is selected + if (digitalRead(GIMBAL_MODE_PIN) == LOW) + { + gimbal_mode = GIMBAL_MODE_FRSKY_M10; } // Init ELRS @@ -813,70 +595,66 @@ void setup() void loop() { - /* Update current time (ms) */ - current_timestamp = millis(); - /* Update current time (us) */ current_timestamp_micros = micros(); - /* Read io value as fast as possible */ analog_x1.update(); analog_y1.update(); analog_x2.update(); analog_y2.update(); - + /* Process data with 1ms interval*/ - if (current_timestamp >= process_data_timestamp) + if (current_timestamp_micros >= process_data_timestamp_micros) { process_input_data(); - process_data_timestamp = current_timestamp + 1; + process_data_timestamp_micros = current_timestamp_micros + TIME_US_1ms; } /* Update/Send USB data with 5ms interval*/ - if (current_timestamp >= send_usb_timestamp) + if (current_timestamp_micros >= send_usb_timestamp_micros) { send_usb_data(); - send_usb_timestamp = current_timestamp + 5; + send_usb_timestamp_micros = current_timestamp_micros + TIME_US_5ms; } - - /* Update/Send ERLS data with 1,6ms interval */ + + /* Update/Send ERLS data with about 1,6ms interval */ if (current_timestamp_micros >= send_elrs_timestamp_micros) { - send_elrs_data(); + send_erls_data(); send_elrs_timestamp_micros = current_timestamp_micros + CRSF_TIME_BETWEEN_FRAMES_US; } - - /* Update indicator 200ms */ - if (current_timestamp >= indicator_timestamp) + + /* Update indicator with 200ms interval */ + if (current_timestamp_micros >= indicator_timestamp_micros) { - // Set led mode - button_led_1_mode = 0; - button_led_2_mode = 0; - - if (joystick_calibration_mode == CALIBRATION_INIT){ - button_led_1_mode = 2; - button_led_2_mode = 2; + button_led_1_mode = LED_MODE_OFF; + button_led_2_mode = LED_MODE_OFF; + + if (joystick_calibration_mode == CALIBRATION_INIT) + { + button_led_1_mode = LED_MODE_BLINK; + button_led_2_mode = LED_MODE_BLINK; } - else if (joystick_calibration_mode == CALIBRATION_CENTER){ - button_led_1_mode = 2; - button_led_2_mode = 0; + else if (joystick_calibration_mode == CALIBRATION_CENTER) + { + button_led_1_mode = LED_MODE_BLINK; + button_led_2_mode = LED_MODE_OFF; } - else if (joystick_calibration_mode == CALIBRATION_MINMAX){ - button_led_1_mode = 0; - button_led_2_mode = 2; + else if (joystick_calibration_mode == CALIBRATION_MINMAX) + { + button_led_1_mode = LED_MODE_OFF; + button_led_2_mode = LED_MODE_BLINK; } - else if ((joystick_x1 != AXIS_CENTER) || (joystick_y1 != AXIS_MIN) || - (joystick_x2 != AXIS_CENTER) || (joystick_y2 != AXIS_CENTER)){ - button_led_1_mode = 1; - button_led_2_mode = 1; + else if ((joystick_x1_12bit != AXIS_12BIT_CENTER) || (joystick_y1_12bit != AXIS_12BIT_MIN) || + (joystick_x2_12bit != AXIS_12BIT_CENTER) || (joystick_y2_12bit != AXIS_12BIT_CENTER)) + { + button_led_1_mode = LED_MODE_ON; + button_led_2_mode = LED_MODE_ON; } - /* Updated button led 1 */ update_indicator(button_led_1_mode, button_led_1_on, BUTTON_LED_1_PIN); - /* Updated button led 2 */ update_indicator(button_led_2_mode, button_led_2_on, BUTTON_LED_2_PIN); - /* Update status led */ update_indicator(status_led_mode, status_led_on, STATUS_LED_PIN); - - indicator_timestamp = current_timestamp + 200; + + indicator_timestamp_micros = current_timestamp_micros + TIME_US_200ms; } } diff --git a/firmware/src/erls.cpp b/firmware/src/erls.cpp new file mode 100644 index 0000000..85217c3 --- /dev/null +++ b/firmware/src/erls.cpp @@ -0,0 +1,180 @@ +/* + * ======================================================================================================= + * ------------------------------------------------------------------------------------------------------- + * ---####################-----###########-------###########-----############--############-############-- + * --######################---#############-----#############---- -- - --- + * --###### ##---##### ###-----### #####---------##-------#######------#------------- + * -- -------------- --- ----- --- ----- ---------##-------#------------#------------- + * --#####--------------------#####------####-####------#####---------##-------###########--############-- + * -- -------------------- ------ ------ --------- ------- -- -- + * --#####--------------------#####--------#####--------#####--------------------------------------------- + * -- -------------------- -------- -------- --------------------------------------------- + * --######--------------##---#####---------------------#####---------------- ERLS ----------------------- + * --##################### ---#####---------------------#####--------------------------------------------- + * ---################### ----#####---------------------#####--------------------------------------------- + * --- ----- --------------------- --------------------------------------------- + * ------------------------------------------------------------------------------------------------------- + * ======================================================================================================= + * + * Copyright 2023 Christoffer Martinsson + * + * CMtec ERLS can be redistributed and/or modified under the terms of the GNU General + * Public License (Version 2), as published by the Free Software Foundation. + * A copy of the license can be found online at www.gnu.o urg/licenses. + * + * CMtec ERLS is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + */ + +#include "erls.h" + +uint8_t crsf_packet[CRSF_PACKET_SIZE]; +uint8_t crsf_cmd_packet[CRSF_CMD_PACKET_SIZE]; +int16_t elrs_channels[CRSF_MAX_CHANNEL]; + +bool elrs_init_done = false; +int elrs_init_counter = 0; + +// crc implementation from CRSF protocol document rev7 +static uint8_t crsf_crc8tab[256] = { + 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, + 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, + 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, + 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, + 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, + 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, + 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, + 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, + 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, + 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, + 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, + 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, + 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, + 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, + 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, + 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9}; + +/** + * @brief Calculate the CRC8 of a CRSF packet + * + * @param ptr The packet to be calculated + * @param len The length of the packet + */ +uint8_t calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) +{ + uint8_t crc = 0; + for (uint8_t i = 0; i < len; i++) + { + crc = crsf_crc8tab[crc ^ *ptr++]; + } + return crc; +} + +/** + * @brief Prepare a CRSF data packet + * + * @param packet The packet to be prepared + * @param channels The channels to be sent + */ +void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) +{ + packet[0] = ELRS_ADDRESS; // Header + packet[1] = 24; // length + packet[2] = CRSF_TYPE_CHANNELS; + packet[3] = (uint8_t)(channels[0] & 0x07FF); + packet[4] = (uint8_t)((channels[0] & 0x07FF) >> 8 | (channels[1] & 0x07FF) << 3); + packet[5] = (uint8_t)((channels[1] & 0x07FF) >> 5 | (channels[2] & 0x07FF) << 6); + packet[6] = (uint8_t)((channels[2] & 0x07FF) >> 2); + packet[7] = (uint8_t)((channels[2] & 0x07FF) >> 10 | (channels[3] & 0x07FF) << 1); + packet[8] = (uint8_t)((channels[3] & 0x07FF) >> 7 | (channels[4] & 0x07FF) << 4); + packet[9] = (uint8_t)((channels[4] & 0x07FF) >> 4 | (channels[5] & 0x07FF) << 7); + packet[10] = (uint8_t)((channels[5] & 0x07FF) >> 1); + packet[11] = (uint8_t)((channels[5] & 0x07FF) >> 9 | (channels[6] & 0x07FF) << 2); + packet[12] = (uint8_t)((channels[6] & 0x07FF) >> 6 | (channels[7] & 0x07FF) << 5); + packet[13] = (uint8_t)((channels[7] & 0x07FF) >> 3); + packet[14] = (uint8_t)((channels[8] & 0x07FF)); + packet[15] = (uint8_t)((channels[8] & 0x07FF) >> 8 | (channels[9] & 0x07FF) << 3); + packet[16] = (uint8_t)((channels[9] & 0x07FF) >> 5 | (channels[10] & 0x07FF) << 6); + packet[17] = (uint8_t)((channels[10] & 0x07FF) >> 2); + packet[18] = (uint8_t)((channels[10] & 0x07FF) >> 10 | (channels[11] & 0x07FF) << 1); + packet[19] = (uint8_t)((channels[11] & 0x07FF) >> 7 | (channels[12] & 0x07FF) << 4); + packet[20] = (uint8_t)((channels[12] & 0x07FF) >> 4 | (channels[13] & 0x07FF) << 7); // Channel not used by ELRS + packet[21] = (uint8_t)((channels[13] & 0x07FF) >> 1); // Channel not used by ELRS + packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2); // Channel not used by ELRS + packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5); // Channel not used by ELRS + packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3); // Channel not used by ELRS + packet[25] = calculate_crsf_crc8(&packet[2], packet[1] - 1); +} + +/** + * @brief Prepare CRSF command packet + * + * @param packet_cmd + * @param command + * @param value + */ +void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) +{ + packet_cmd[0] = ELRS_ADDRESS; // Header + packet_cmd[1] = 6; // length + packet_cmd[2] = ELRS_TYPE_SETTINGS_WRITE; + packet_cmd[3] = ELRS_ADDRESS; + packet_cmd[4] = ELRS_ADDR_RADIO; + packet_cmd[5] = command; + packet_cmd[6] = value; + packet_cmd[7] = calculate_crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); +} + +/** + * @brief Set data to be sent to ERLS TX + * + * @param value + * @param channel + */ +void erls_set_data(int16_t value, uint8_t channel) +{ + elrs_channels[channel] = value; +} + +/** + * @brief Send data to ERLS TX + * + */ +void erls_send_data() +{ + + if (elrs_init_done == true) + { + prepare_crsf_data_packet(crsf_packet, elrs_channels); + ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); + } + else + { + // Setting up initial communication link between ERLS TX and Teensy (give ERLS TX time to auto detect Teensy) + if (elrs_init_counter < 500) + { + prepare_crsf_data_packet(crsf_packet, elrs_channels); + ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); + elrs_init_counter++; + } + // Send command to update TX packet rate to 500Hz + else if (elrs_init_counter < 505) + { + prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, ELRS_PKT_RATE); + ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + elrs_init_counter++; + } + // Send command to update TX power to 100mW + else if (elrs_init_counter < 510) + { + prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, ELRS_POWER); + ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + elrs_init_counter++; + } + else + { + elrs_init_done = true; + } + } +} \ No newline at end of file diff --git a/firmware/src/erls.h b/firmware/src/erls.h new file mode 100644 index 0000000..e09c85f --- /dev/null +++ b/firmware/src/erls.h @@ -0,0 +1,63 @@ + /* + * ======================================================================================================= + * ------------------------------------------------------------------------------------------------------- + * ---####################-----###########-------###########-----############--############-############-- + * --######################---#############-----#############---- -- - --- + * --###### ##---##### ###-----### #####---------##-------#######------#------------- + * -- -------------- --- ----- --- ----- ---------##-------#------------#------------- + * --#####--------------------#####------####-####------#####---------##-------###########--############-- + * -- -------------------- ------ ------ --------- ------- -- -- + * --#####--------------------#####--------#####--------#####--------------------------------------------- + * -- -------------------- -------- -------- --------------------------------------------- + * --######--------------##---#####---------------------#####---------------- ERLS ----------------------- + * --##################### ---#####---------------------#####--------------------------------------------- + * ---################### ----#####---------------------#####--------------------------------------------- + * --- ----- --------------------- --------------------------------------------- + * ------------------------------------------------------------------------------------------------------- + * ======================================================================================================= + * + * Copyright 2023 Christoffer Martinsson + * + * CMtec ERLS can be redistributed and/or modified under the terms of the GNU General + * Public License (Version 2), as published by the Free Software Foundation. + * A copy of the license can be found online at www.gnu.o urg/licenses. + * + * CMtec ERLS is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + */ + +#include + +// CRSF +#define CRSF_MAX_CHANNEL 16 +#define CRSF_TYPE_CHANNELS 0x16 +#define CRSF_DIGITAL_CHANNEL_MIN 172 +#define CRSF_DIGITAL_CHANNEL_CENTER 992 +#define CRSF_DIGITAL_CHANNEL_MAX 1811 +#define CRSF_TIME_BETWEEN_FRAMES_US 1666 // 1.6 ms 500Hz +#define CRSF_PACKET_SIZE 26 +#define CRSF_CMD_PACKET_SIZE 8 + +// ELRS command +#define ELRS_ADDRESS 0xEE +#define ELRS_BIND_COMMAND 0xFF +#define ELRS_WIFI_COMMAND 0xFE +#define ELRS_PKT_RATE_COMMAND 0x01 +#define ELRS_TLM_RATIO_COMMAND 0x02 +#define ELRS_SWITCH_MODE_COMMAND 0x03 +#define ELRS_MODEL_MATCH_COMMAND 0x04 +#define ELRS_POWER_COMMAND 0x06 +#define ELRS_BLE_JOYSTIC_COMMAND 17 +#define ELRS_TYPE_SETTINGS_WRITE 0x2D +#define ELRS_ADDR_RADIO 0xEA +#define ELRS_SERIAL_PORT Serial1 +#define ELRS_SERIAL_BAUDRATE 400000 +#define ELRS_PKT_RATE 3 // 0 = 50Hz, 1 = 100Hz, 2 = 200Hz, 3 = 500Hz, 4 = 1000Hz +#define ELRS_POWER 2 // 0 = 10mW, 1 = 25mW, 2 = 100mW, 3 = 250mW, 4 = 500mW, 5 = 1000mW + + +void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]); +void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value); +void erls_set_data(int16_t value, uint8_t channel); +void erls_send_data(); \ No newline at end of file From 727f113124dce209ac8071202a65c3b006fc2ba5 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 22 May 2023 23:25:56 +0000 Subject: [PATCH 08/29] Changed to OOP coding --- .gitignore | 1 + firmware/src/{erls.cpp => ElrsTx.cpp} | 192 ++++++++++++++---------- firmware/src/ElrsTx.h | 119 +++++++++++++++ firmware/src/IndicatorLed.cpp | 101 +++++++++++++ firmware/src/{erls.h => IndicatorLed.h} | 56 +++---- firmware/src/cmdr_joystick.cpp | 164 ++++++++------------ 6 files changed, 414 insertions(+), 219 deletions(-) create mode 100644 .gitignore rename firmware/src/{erls.cpp => ElrsTx.cpp} (52%) create mode 100644 firmware/src/ElrsTx.h create mode 100644 firmware/src/IndicatorLed.cpp rename firmware/src/{erls.h => IndicatorLed.h} (60%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7f6dc73 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +firmware/.cache/clangd/index diff --git a/firmware/src/erls.cpp b/firmware/src/ElrsTx.cpp similarity index 52% rename from firmware/src/erls.cpp rename to firmware/src/ElrsTx.cpp index 85217c3..4694ed1 100644 --- a/firmware/src/erls.cpp +++ b/firmware/src/ElrsTx.cpp @@ -27,127 +27,153 @@ * A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ -#include "erls.h" +#include "ElrsTx.h" -uint8_t crsf_packet[CRSF_PACKET_SIZE]; -uint8_t crsf_cmd_packet[CRSF_CMD_PACKET_SIZE]; -int16_t elrs_channels[CRSF_MAX_CHANNEL]; +/** + * @brief Construct a new ElrsTx object + * + * @param serial The serial port to use + */ +ElrsTx::ElrsTx(HardwareSerial& serial): _serial(serial) { } -bool elrs_init_done = false; -int elrs_init_counter = 0; +/** + * @brief Initialize the ELRS transmitter + */ +void ElrsTx::begin(int packet_rate, int tx_power) +{ + const int ELRS_SERIAL_BAUDRATE = 400000; + + _serial.begin(ELRS_SERIAL_BAUDRATE); -// crc implementation from CRSF protocol document rev7 -static uint8_t crsf_crc8tab[256] = { - 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, - 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, - 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, - 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, - 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, - 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, - 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, - 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, - 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, - 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, - 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, - 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, - 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, - 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, - 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, - 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9}; + _packet_rate = packet_rate; + _tx_power = tx_power; +} /** * @brief Calculate the CRC8 of a CRSF packet * * @param ptr The packet to be calculated * @param len The length of the packet + * @return The CRC8 of the packet */ -uint8_t calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) +uint8_t ElrsTx::calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) { uint8_t crc = 0; for (uint8_t i = 0; i < len; i++) { - crc = crsf_crc8tab[crc ^ *ptr++]; + crc = CRSF_CRC8TAB[crc ^ *ptr++]; } return crc; } /** - * @brief Prepare a CRSF data packet + * @brief Prepare a normal CRSF data packet * - * @param packet The packet to be prepared - * @param channels The channels to be sent + * packet format: + * 0 - header + * 1 - length + * 2 - type + * 3-24 - data (16 11bit channels in 8bit format) + * 25 - crc + * + * @param packet Resulting packet + * @param channels Channel data */ -void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) +void ElrsTx::prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) { - packet[0] = ELRS_ADDRESS; // Header - packet[1] = 24; // length - packet[2] = CRSF_TYPE_CHANNELS; - packet[3] = (uint8_t)(channels[0] & 0x07FF); - packet[4] = (uint8_t)((channels[0] & 0x07FF) >> 8 | (channels[1] & 0x07FF) << 3); - packet[5] = (uint8_t)((channels[1] & 0x07FF) >> 5 | (channels[2] & 0x07FF) << 6); - packet[6] = (uint8_t)((channels[2] & 0x07FF) >> 2); - packet[7] = (uint8_t)((channels[2] & 0x07FF) >> 10 | (channels[3] & 0x07FF) << 1); - packet[8] = (uint8_t)((channels[3] & 0x07FF) >> 7 | (channels[4] & 0x07FF) << 4); - packet[9] = (uint8_t)((channels[4] & 0x07FF) >> 4 | (channels[5] & 0x07FF) << 7); - packet[10] = (uint8_t)((channels[5] & 0x07FF) >> 1); - packet[11] = (uint8_t)((channels[5] & 0x07FF) >> 9 | (channels[6] & 0x07FF) << 2); - packet[12] = (uint8_t)((channels[6] & 0x07FF) >> 6 | (channels[7] & 0x07FF) << 5); - packet[13] = (uint8_t)((channels[7] & 0x07FF) >> 3); - packet[14] = (uint8_t)((channels[8] & 0x07FF)); - packet[15] = (uint8_t)((channels[8] & 0x07FF) >> 8 | (channels[9] & 0x07FF) << 3); - packet[16] = (uint8_t)((channels[9] & 0x07FF) >> 5 | (channels[10] & 0x07FF) << 6); - packet[17] = (uint8_t)((channels[10] & 0x07FF) >> 2); + const int CRSF_TYPE_CHANNELS = 0x16; + + packet[0] = ELRS_ADDRESS; + packet[1] = 24; + packet[2] = CRSF_TYPE_CHANNELS; + packet[3] = (uint8_t)(channels[0] & 0x07FF); + packet[4] = (uint8_t)((channels[0] & 0x07FF) >> 8 | (channels[1] & 0x07FF) << 3); + packet[5] = (uint8_t)((channels[1] & 0x07FF) >> 5 | (channels[2] & 0x07FF) << 6); + packet[6] = (uint8_t)((channels[2] & 0x07FF) >> 2); + packet[7] = (uint8_t)((channels[2] & 0x07FF) >> 10 | (channels[3] & 0x07FF) << 1); + packet[8] = (uint8_t)((channels[3] & 0x07FF) >> 7 | (channels[4] & 0x07FF) << 4); + packet[9] = (uint8_t)((channels[4] & 0x07FF) >> 4 | (channels[5] & 0x07FF) << 7); + packet[10] = (uint8_t)((channels[5] & 0x07FF) >> 1); + packet[11] = (uint8_t)((channels[5] & 0x07FF) >> 9 | (channels[6] & 0x07FF) << 2); + packet[12] = (uint8_t)((channels[6] & 0x07FF) >> 6 | (channels[7] & 0x07FF) << 5); + packet[13] = (uint8_t)((channels[7] & 0x07FF) >> 3); + packet[14] = (uint8_t)((channels[8] & 0x07FF)); + packet[15] = (uint8_t)((channels[8] & 0x07FF) >> 8 | (channels[9] & 0x07FF) << 3); + packet[16] = (uint8_t)((channels[9] & 0x07FF) >> 5 | (channels[10] & 0x07FF) << 6); + packet[17] = (uint8_t)((channels[10] & 0x07FF) >> 2); packet[18] = (uint8_t)((channels[10] & 0x07FF) >> 10 | (channels[11] & 0x07FF) << 1); - packet[19] = (uint8_t)((channels[11] & 0x07FF) >> 7 | (channels[12] & 0x07FF) << 4); - packet[20] = (uint8_t)((channels[12] & 0x07FF) >> 4 | (channels[13] & 0x07FF) << 7); // Channel not used by ELRS - packet[21] = (uint8_t)((channels[13] & 0x07FF) >> 1); // Channel not used by ELRS - packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2); // Channel not used by ELRS - packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5); // Channel not used by ELRS - packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3); // Channel not used by ELRS - packet[25] = calculate_crsf_crc8(&packet[2], packet[1] - 1); + packet[19] = (uint8_t)((channels[11] & 0x07FF) >> 7 | (channels[12] & 0x07FF) << 4); + packet[20] = (uint8_t)((channels[12] & 0x07FF) >> 4 | (channels[13] & 0x07FF) << 7); + packet[21] = (uint8_t)((channels[13] & 0x07FF) >> 1); + packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2); + packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5); + packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3); + packet[25] = calculate_crsf_crc8(&packet[2], packet[1] - 1); } /** * @brief Prepare CRSF command packet * - * @param packet_cmd - * @param command - * @param value + * packet format: + * 0 - header + * 1 - length + * 2 - type + * 3 - address + * 4 - address radio + * 5 - command + * 6 - value + * 7 - crc + * + * command list: + * ELRS_BIND_COMMAND = 0xFF; + * ELRS_WIFI_COMMAND = 0xFE; + * ELRS_TLM_RATIO_COMMAND = 0x02; + * ELRS_SWITCH_MODE_COMMAND = 0x03; + * ELRS_MODEL_MATCH_COMMAND = 0x04; + * ELRS_BLE_JOYSTIC_COMMAND = 17; + * + * @param packet_cmd Resulting packet + * @param command Command to be sent + * @param value Value to be sent */ -void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) +void ElrsTx::prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) { - packet_cmd[0] = ELRS_ADDRESS; // Header - packet_cmd[1] = 6; // length - packet_cmd[2] = ELRS_TYPE_SETTINGS_WRITE; - packet_cmd[3] = ELRS_ADDRESS; - packet_cmd[4] = ELRS_ADDR_RADIO; - packet_cmd[5] = command; - packet_cmd[6] = value; - packet_cmd[7] = calculate_crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); + const int ELRS_ADDR_RADIO = 0xEA; + const int ELRS_TYPE_SETTINGS_WRITE = 0x2D; + + packet_cmd[0] = ELRS_ADDRESS; + packet_cmd[1] = 6; + packet_cmd[2] = ELRS_TYPE_SETTINGS_WRITE; + packet_cmd[3] = ELRS_ADDRESS; + packet_cmd[4] = ELRS_ADDR_RADIO; + packet_cmd[5] = command; + packet_cmd[6] = value; + packet_cmd[7] = calculate_crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); } /** - * @brief Set data to be sent to ERLS TX + * @brief Set ELRS channel data * - * @param value - * @param channel + * @param value Value (0-2048) to be set + * @param channel Channel (0-11) to be set */ -void erls_set_data(int16_t value, uint8_t channel) +void ElrsTx::set_data(int16_t value, uint8_t channel) { elrs_channels[channel] = value; } /** - * @brief Send data to ERLS TX - * + * @brief Send data to ERLS TX. This function should be called within the main loop with a 1.6ms interval */ -void erls_send_data() +void ElrsTx::send_data() { - + const int ELRS_PKT_RATE_COMMAND = 0x01; + const int ELRS_POWER_COMMAND = 0x06; + if (elrs_init_done == true) { prepare_crsf_data_packet(crsf_packet, elrs_channels); - ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); + _serial.write(crsf_packet, CRSF_PACKET_SIZE); } else { @@ -155,21 +181,21 @@ void erls_send_data() if (elrs_init_counter < 500) { prepare_crsf_data_packet(crsf_packet, elrs_channels); - ELRS_SERIAL_PORT.write(crsf_packet, CRSF_PACKET_SIZE); + _serial.write(crsf_packet, CRSF_PACKET_SIZE); elrs_init_counter++; } - // Send command to update TX packet rate to 500Hz + // Send command to update TX packet rate else if (elrs_init_counter < 505) { - prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, ELRS_PKT_RATE); - ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, _packet_rate); + _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); elrs_init_counter++; } - // Send command to update TX power to 100mW + // Send command to update TX power else if (elrs_init_counter < 510) { - prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, ELRS_POWER); - ELRS_SERIAL_PORT.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, _tx_power); + _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); elrs_init_counter++; } else diff --git a/firmware/src/ElrsTx.h b/firmware/src/ElrsTx.h new file mode 100644 index 0000000..65b2a50 --- /dev/null +++ b/firmware/src/ElrsTx.h @@ -0,0 +1,119 @@ + /* + * ======================================================================================================= + * ------------------------------------------------------------------------------------------------------- + * ---####################-----###########-------###########-----############--############-############-- + * --######################---#############-----#############---- -- - --- + * --###### ##---##### ###-----### #####---------##-------#######------#------------- + * -- -------------- --- ----- --- ----- ---------##-------#------------#------------- + * --#####--------------------#####------####-####------#####---------##-------###########--############-- + * -- -------------------- ------ ------ --------- ------- -- -- + * --#####--------------------#####--------#####--------#####--------------------------------------------- + * -- -------------------- -------- -------- --------------------------------------------- + * --######--------------##---#####---------------------#####---------------- ERLS ----------------------- + * --##################### ---#####---------------------#####--------------------------------------------- + * ---################### ----#####---------------------#####--------------------------------------------- + * --- ----- --------------------- --------------------------------------------- + * ------------------------------------------------------------------------------------------------------- + * ======================================================================================================= + * + * Copyright 2023 Christoffer Martinsson + * + * CMtec ERLS can be redistributed and/or modified under the terms of the GNU General + * Public License (Version 2), as published by the Free Software Foundation. + * A copy of the license can be found online at www.gnu.o urg/licenses. + * + * CMtec ERLS is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + */ + +#ifndef ELRSTX_H +#define ELRSTX_H + +#include + +// CRSF +const int CRSF_MAX_CHANNEL = 16; +const int CRSF_TYPE_CHANNELS = 0x16; +const int CRSF_DIGITAL_CHANNEL_MIN = 172; +const int CRSF_DIGITAL_CHANNEL_CENTER = 992; +const int CRSF_DIGITAL_CHANNEL_MAX = 1811; +const int CRSF_TIME_BETWEEN_FRAMES_US = 1666; +const int CRSF_PACKET_SIZE = 26; +const int CRSF_CMD_PACKET_SIZE = 8; + +// ERLS others +const int ELRS_ADDR_RADIO = 0xEA; +const int ELRS_SERIAL_BAUDRATE = 400000; + +// ELRS command +const int ELRS_ADDRESS = 0xEE; +const int ELRS_BIND_COMMAND = 0xFF; +const int ELRS_WIFI_COMMAND = 0xFE; +const int ELRS_PKT_RATE_COMMAND = 0x01; +const int ELRS_TLM_RATIO_COMMAND = 0x02; +const int ELRS_SWITCH_MODE_COMMAND = 0x03; +const int ELRS_MODEL_MATCH_COMMAND = 0x04; +const int ELRS_POWER_COMMAND = 0x06; +const int ELRS_BLE_JOYSTIC_COMMAND = 17; +const int ELRS_TYPE_SETTINGS_WRITE = 0x2D; + +// ERLS command values +const int ELRS_PACKET_RATE_50Hz = 0; +const int ELRS_PACKET_RATE_100Hz = 1; +const int ELRS_PACKET_RATE_200Hz = 2; +const int ELRS_PACKET_RATE_500Hz = 3; +const int ELRS_TX_POWER_10mW = 0; +const int ELRS_TX_POWER_25mW = 1; +const int ELRS_TX_POWER_100mW = 2; +const int ELRS_TX_POWER_250mW = 3; +const int ELRS_TX_POWER_500mW = 4; +const int ELRS_TX_POWER_1000mW = 5; + +class ElrsTx +{ + public: + ElrsTx(HardwareSerial& serial); + + void set_data(int16_t value, uint8_t channel); + void send_data(); + void begin(int packet_rate, int tx_power); + + private: + uint8_t crsf_packet[CRSF_PACKET_SIZE]; + uint8_t crsf_cmd_packet[CRSF_CMD_PACKET_SIZE]; + int16_t elrs_channels[CRSF_MAX_CHANNEL]; + + bool elrs_init_done = false; + int elrs_init_counter = 0; + + HardwareSerial& _serial; + int _packet_rate; + int _tx_power; + + // crc implementation from CRSF protocol document rev7 + const uint8_t CRSF_CRC8TAB[256] = { + 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, + 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, + 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, + 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, + 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, + 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, + 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, + 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, + 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, + 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, + 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, + 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, + 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, + 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, + 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, + 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9}; + + uint8_t calculate_crsf_crc8(const uint8_t *ptr, uint8_t len); + void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]); + void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value); + +}; + +#endif \ No newline at end of file diff --git a/firmware/src/IndicatorLed.cpp b/firmware/src/IndicatorLed.cpp new file mode 100644 index 0000000..3001d73 --- /dev/null +++ b/firmware/src/IndicatorLed.cpp @@ -0,0 +1,101 @@ +/* + * ======================================================================================================= + * ------------------------------------------------------------------------------------------------------- + * ---####################-----###########-------###########-----############--############-############-- + * --######################---#############-----#############---- -- - --- + * --###### ##---##### ###-----### #####---------##-------#######------#------------- + * -- -------------- --- ----- --- ----- ---------##-------#------------#------------- + * --#####--------------------#####------####-####------#####---------##-------###########--############-- + * -- -------------------- ------ ------ --------- ------- -- -- + * --#####--------------------#####--------#####--------#####--------------------------------------------- + * -- -------------------- -------- -------- --------------------------------------------- + * --######--------------##---#####---------------------#####---------------- IndicatorLed --------------- + * --##################### ---#####---------------------#####--------------------------------------------- + * ---################### ----#####---------------------#####--------------------------------------------- + * --- ----- --------------------- --------------------------------------------- + * ------------------------------------------------------------------------------------------------------- + * ======================================================================================================= + * + * Copyright 2023 Christoffer Martinsson + * + * CMtec ERLS can be redistributed and/or modified under the terms of the GNU General + * Public License (Version 2), as published by the Free Software Foundation. + * A copy of the license can be found online at www.gnu.o urg/licenses. + * + * CMtec ERLS is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + */ + +#include "IndicatorLed.h" + +/** + * @brief Construct a new Indicator Led:: Indicator Led object + * + * @param pin Pin number for indicator LED + */ +IndicatorLed::IndicatorLed(int pin) +{ + _pin = pin; +} + +/** + * @brief Initialize indicator LED + */ +void IndicatorLed::begin() +{ + pinMode(_pin, OUTPUT); + digitalWrite(_pin, LOW); +} + +/** + * @brief Turn on indicator LED + */ +void IndicatorLed::on() +{ + led_mode = LED_ON; +} + +/** + * @brief Turn off indicator LED + */ +void IndicatorLed::off() +{ + led_mode = LED_OFF; +} + +/** + * @brief Blink indicator LED + */ +void IndicatorLed::blink() +{ + led_mode = LED_BLINK; +} + +/** + * @brief Update indicator LED. Call this function in the main loop with a 200-500 ms interval. + */ +void IndicatorLed::update() +{ + + if (led_mode == LED_BLINK && current_state == LED_OFF) + { + digitalWrite(_pin, HIGH); + current_state = LED_ON; + } + else if (led_mode == LED_BLINK && current_state == LED_ON) + { + digitalWrite(_pin, LOW); + current_state = LED_OFF; + } + else if (led_mode == LED_ON) + { + digitalWrite(_pin, HIGH); + current_state = LED_ON; + } + else + { + digitalWrite(_pin, LOW); + current_state = LED_OFF; + } +} diff --git a/firmware/src/erls.h b/firmware/src/IndicatorLed.h similarity index 60% rename from firmware/src/erls.h rename to firmware/src/IndicatorLed.h index e09c85f..dc188e5 100644 --- a/firmware/src/erls.h +++ b/firmware/src/IndicatorLed.h @@ -1,4 +1,4 @@ - /* +/* * ======================================================================================================= * ------------------------------------------------------------------------------------------------------- * ---####################-----###########-------###########-----############--############-############-- @@ -9,7 +9,7 @@ * -- -------------------- ------ ------ --------- ------- -- -- * --#####--------------------#####--------#####--------#####--------------------------------------------- * -- -------------------- -------- -------- --------------------------------------------- - * --######--------------##---#####---------------------#####---------------- ERLS ----------------------- + * --######--------------##---#####---------------------#####---------------- IndicatorLed --------------- * --##################### ---#####---------------------#####--------------------------------------------- * ---################### ----#####---------------------#####--------------------------------------------- * --- ----- --------------------- --------------------------------------------- @@ -27,37 +27,29 @@ * A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ +#ifndef INDICATORLED_H +#define INDICATORLED_H + #include -// CRSF -#define CRSF_MAX_CHANNEL 16 -#define CRSF_TYPE_CHANNELS 0x16 -#define CRSF_DIGITAL_CHANNEL_MIN 172 -#define CRSF_DIGITAL_CHANNEL_CENTER 992 -#define CRSF_DIGITAL_CHANNEL_MAX 1811 -#define CRSF_TIME_BETWEEN_FRAMES_US 1666 // 1.6 ms 500Hz -#define CRSF_PACKET_SIZE 26 -#define CRSF_CMD_PACKET_SIZE 8 +const int LED_OFF = 0; +const int LED_ON = 1; +const int LED_BLINK = 2; -// ELRS command -#define ELRS_ADDRESS 0xEE -#define ELRS_BIND_COMMAND 0xFF -#define ELRS_WIFI_COMMAND 0xFE -#define ELRS_PKT_RATE_COMMAND 0x01 -#define ELRS_TLM_RATIO_COMMAND 0x02 -#define ELRS_SWITCH_MODE_COMMAND 0x03 -#define ELRS_MODEL_MATCH_COMMAND 0x04 -#define ELRS_POWER_COMMAND 0x06 -#define ELRS_BLE_JOYSTIC_COMMAND 17 -#define ELRS_TYPE_SETTINGS_WRITE 0x2D -#define ELRS_ADDR_RADIO 0xEA -#define ELRS_SERIAL_PORT Serial1 -#define ELRS_SERIAL_BAUDRATE 400000 -#define ELRS_PKT_RATE 3 // 0 = 50Hz, 1 = 100Hz, 2 = 200Hz, 3 = 500Hz, 4 = 1000Hz -#define ELRS_POWER 2 // 0 = 10mW, 1 = 25mW, 2 = 100mW, 3 = 250mW, 4 = 500mW, 5 = 1000mW +class IndicatorLed +{ + public: + IndicatorLed(int pin); + void begin(); + void on(); + void off(); + void blink(); + void update(); + + private: + int _pin; + int led_mode = LED_OFF; + int current_state = LED_OFF; +}; - -void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]); -void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value); -void erls_set_data(int16_t value, uint8_t channel); -void erls_send_data(); \ No newline at end of file +#endif \ No newline at end of file diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index 07600e8..8efe249 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -32,38 +32,25 @@ #include #include -#include "erls.h" +#include "ElrsTx.h" +#include "IndicatorLed.h" #include "ResponsiveAnalogRead.h" -#define LED_MODE_OFF 0 -#define LED_MODE_ON 1 -#define LED_MODE_BLINK 2 -#define LED_ON HIGH -#define LED_OFF LOW +IndicatorLed status_led(13); +IndicatorLed button_led_1(22); +IndicatorLed button_led_2(23); -const int STATUS_LED_PIN = 13; -bool status_led_on = false; -int status_led_mode = LED_MODE_BLINK; - -const int BUTTON_LED_1_PIN = 22; -bool button_led_1_on = false; -int button_led_1_mode = LED_MODE_OFF; - -const int BUTTON_LED_2_PIN = 23; -bool button_led_2_on = false; -int button_led_2_mode = LED_MODE_OFF; - -#define TIME_US_1ms 1000 -#define TIME_US_5ms 5000 -#define TIME_US_200ms 200000 +const int TIME_US_1ms = 1000; +const int TIME_US_5ms = 5000; +const long TIME_US_200ms = 200000; unsigned long current_timestamp_micros = 0; unsigned long process_data_timestamp_micros = 0; unsigned long indicator_timestamp_micros = 0; unsigned long send_usb_timestamp_micros = 0; unsigned long send_elrs_timestamp_micros = 0; -#define BUTTON_PRESSED LOW -#define BUTTON_NOT_PRESSED HIGH +const int BUTTON_PRESSED = LOW; +const int BUTTON_NOT_PRESSED = HIGH; const int BUTTON_FRONT_LEFT_UPPER_PIN = 4; const int BUTTON_FRONT_LEFT_LOWER_PIN = 5; const int BUTTON_FRONT_RIGHT_UPPER_PIN = 6; @@ -73,8 +60,8 @@ const int BUTTON_TOP_RIGHT_UPPER_PIN = 10; const int BUTTON_TOP_LEFT_LOWER_PIN = 8; const int BUTTON_TOP_RIGHT_LOWER_PIN = 11; -#define GIMBAL_MODE_FRSKY_M7 0 -#define GIMBAL_MODE_FRSKY_M10 1 +const int GIMBAL_MODE_FRSKY_M7 = 0; +const int GIMBAL_MODE_FRSKY_M10 = 1; const int GIMBAL_MODE_PIN = 21; int gimbal_mode = GIMBAL_MODE_FRSKY_M7; @@ -82,15 +69,15 @@ bool toggle_button_arm = false; bool toggle_button_mode = false; int toggle_button_arm_previous_value = HIGH; -#define AXIS_10BIT_MAX 1023 -#define AXIS_10BIT_MIN 0 -#define AXIS_10BIT_CENTER 512 -#define AXIS_12BIT_MAX 4096 -#define AXIS_12BIT_MIN 0 -#define AXIS_12BIT_CENTER 2048 -#define DEADZONE_X 50 -#define DEADZONE_Y 50 -#define JOYSTICK_HAT_CENTER -1 +const int AXIS_10BIT_MAX = 1023; +const int AXIS_10BIT_MIN = 0; +const int AXIS_10BIT_CENTER = 512; +const int AXIS_12BIT_MAX = 4096; +const int AXIS_12BIT_MIN = 0; +const int AXIS_12BIT_CENTER = 2048; +const int DEADZONE_X = 50; +const int DEADZONE_Y = 50; +const int JOYSTICK_HAT_CENTER = -1; enum EEPROM_ADR { @@ -148,10 +135,12 @@ ResponsiveAnalogRead analog_y1(A1, true); ResponsiveAnalogRead analog_x2(A3, true); ResponsiveAnalogRead analog_y2(A2, true); -#define CALIBRATION_OFF 0 -#define CALIBRATION_INIT 1 -#define CALIBRATION_CENTER 2 -#define CALIBRATION_MINMAX 3 +ElrsTx elrs(Serial1); + +const int CALIBRATION_OFF = 0; +const int CALIBRATION_INIT = 1; +const int CALIBRATION_CENTER = 2; +const int CALIBRATION_MINMAX = 3; int joystick_calibration_mode = CALIBRATION_OFF; /** @@ -232,7 +221,6 @@ void load_from_eeprom() */ void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) { - joystick_x1_12bit = AXIS_12BIT_CENTER; joystick_y1_12bit = AXIS_12BIT_CENTER; joystick_x2_12bit = AXIS_12BIT_CENTER; @@ -293,29 +281,28 @@ void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) /** * @brief Save joystick calibration values to EEPROM */ -void send_erls_data() +void send_elrs_data() { - // Set ELRS analog channels - erls_set_data(map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 0); - erls_set_data(map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 1); - erls_set_data(map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 2); - erls_set_data(map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 3); + elrs.set_data(map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 0); + elrs.set_data(map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 1); + elrs.set_data(map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 2); + elrs.set_data(map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 3); // Set ELRS digital channels for (int i = 4; i < CRSF_MAX_CHANNEL; i++) { - erls_set_data(CRSF_DIGITAL_CHANNEL_MIN, i); + elrs.set_data(CRSF_DIGITAL_CHANNEL_MIN, i); } - if (toggle_button_arm) erls_set_data(CRSF_DIGITAL_CHANNEL_MAX, 4); - if (toggle_button_mode) erls_set_data(CRSF_DIGITAL_CHANNEL_MAX, 5); - if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) erls_set_data(CRSF_DIGITAL_CHANNEL_MAX, 6); - if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) erls_set_data(CRSF_DIGITAL_CHANNEL_MAX, 7); - if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) erls_set_data(CRSF_DIGITAL_CHANNEL_MAX, 8); + if (toggle_button_arm) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 4); + if (toggle_button_mode) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 5); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 6); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 7); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 8); // Send ELRS data - erls_send_data(); + elrs.send_data(); } /** @@ -502,45 +489,13 @@ void process_input_data() } } -/** - * @brief Update indicator LED - */ -void update_indicator(int led_mode, bool ¤t_led_state, int led_pin) -{ - - if (led_mode == LED_MODE_BLINK && current_led_state == false) - { - digitalWrite(led_pin, LED_ON); - current_led_state = true; - } - else if (led_mode == LED_MODE_BLINK && current_led_state == true) - { - digitalWrite(led_pin, LED_OFF); - current_led_state = false; - } - else if (led_mode == LED_MODE_ON) - { - digitalWrite(led_pin, LED_ON); - current_led_state = true; - } - else - { - digitalWrite(led_pin, LED_OFF); - current_led_state = false; - } -} - void setup() { /* Init HW */ - pinMode(STATUS_LED_PIN, OUTPUT); - digitalWrite(STATUS_LED_PIN, LED_OFF); - - pinMode(BUTTON_LED_1_PIN, OUTPUT); - digitalWrite(BUTTON_LED_1_PIN, LED_OFF); - - pinMode(BUTTON_LED_2_PIN, OUTPUT); - digitalWrite(BUTTON_LED_2_PIN, LED_OFF); + status_led.begin(); + status_led.blink(); + button_led_1.begin(); + button_led_2.begin(); pinMode(BUTTON_FRONT_LEFT_LOWER_PIN, INPUT_PULLUP); pinMode(BUTTON_FRONT_LEFT_UPPER_PIN, INPUT_PULLUP); @@ -579,7 +534,8 @@ void setup() // Check if bootloader mode is enabled if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) { - digitalWrite(BUTTON_LED_2_PIN, HIGH); + button_led_2.on(); + button_led_2.update(); delay(200); _reboot_Teensyduino_(); } @@ -591,7 +547,7 @@ void setup() } // Init ELRS - ELRS_SERIAL_PORT.begin(ELRS_SERIAL_BAUDRATE); + elrs.begin(ELRS_PACKET_RATE_500Hz, ELRS_TX_POWER_25mW); } void loop() @@ -620,41 +576,41 @@ void loop() /* Update/Send ERLS data with about 1,6ms interval */ if (current_timestamp_micros >= send_elrs_timestamp_micros) { - send_erls_data(); + send_elrs_data(); send_elrs_timestamp_micros = current_timestamp_micros + CRSF_TIME_BETWEEN_FRAMES_US; } /* Update indicator with 200ms interval */ if (current_timestamp_micros >= indicator_timestamp_micros) { - button_led_1_mode = LED_MODE_OFF; - button_led_2_mode = LED_MODE_OFF; + button_led_1.off(); + button_led_2.off(); if (joystick_calibration_mode == CALIBRATION_INIT) { - button_led_1_mode = LED_MODE_BLINK; - button_led_2_mode = LED_MODE_BLINK; + button_led_1.blink(); + button_led_2.blink(); } else if (joystick_calibration_mode == CALIBRATION_CENTER) { - button_led_1_mode = LED_MODE_BLINK; - button_led_2_mode = LED_MODE_OFF; + button_led_1.blink(); + button_led_2.off(); } else if (joystick_calibration_mode == CALIBRATION_MINMAX) { - button_led_1_mode = LED_MODE_OFF; - button_led_2_mode = LED_MODE_BLINK; + button_led_1.off(); + button_led_2.blink(); } else if ((joystick_x1_12bit != AXIS_12BIT_CENTER) || (joystick_y1_12bit != AXIS_12BIT_MIN) || (joystick_x2_12bit != AXIS_12BIT_CENTER) || (joystick_y2_12bit != AXIS_12BIT_CENTER)) { - button_led_1_mode = LED_MODE_ON; - button_led_2_mode = LED_MODE_ON; + button_led_1.on(); + button_led_2.on(); } - update_indicator(button_led_1_mode, button_led_1_on, BUTTON_LED_1_PIN); - update_indicator(button_led_2_mode, button_led_2_on, BUTTON_LED_2_PIN); - update_indicator(status_led_mode, status_led_on, STATUS_LED_PIN); + status_led.update(); + button_led_1.update(); + button_led_2.update(); indicator_timestamp_micros = current_timestamp_micros + TIME_US_200ms; } From 4709802879a03141ee982a576d3fc5a9b4b6e292 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sat, 27 May 2023 12:07:14 +0000 Subject: [PATCH 09/29] Added makefile --- firmware/Makefile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 firmware/Makefile diff --git a/firmware/Makefile b/firmware/Makefile new file mode 100644 index 0000000..21753a6 --- /dev/null +++ b/firmware/Makefile @@ -0,0 +1,19 @@ +# Uncomment lines below if you have problems with $PATH +#SHELL := /bin/bash +#PATH := /usr/local/bin:$(PATH) + +all: + pio run + +upload: + pio run --target upload + +clean: + pio run --target clean + +program: + pio run --target program + +db: + pio run -t compiledb + From c6107321d65cb34bd9bf47d713f8e00df2cc7d0c Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sat, 27 May 2023 12:07:52 +0000 Subject: [PATCH 10/29] Code cleanup --- firmware/src/cmdr_joystick.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index 8efe249..52fb685 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -32,9 +32,9 @@ #include #include +#include #include "ElrsTx.h" #include "IndicatorLed.h" -#include "ResponsiveAnalogRead.h" IndicatorLed status_led(13); IndicatorLed button_led_1(22); @@ -42,12 +42,12 @@ IndicatorLed button_led_2(23); const int TIME_US_1ms = 1000; const int TIME_US_5ms = 5000; -const long TIME_US_200ms = 200000; -unsigned long current_timestamp_micros = 0; -unsigned long process_data_timestamp_micros = 0; -unsigned long indicator_timestamp_micros = 0; -unsigned long send_usb_timestamp_micros = 0; -unsigned long send_elrs_timestamp_micros = 0; +const uint64_t TIME_US_200ms = 200000; +uint64_t current_timestamp_micros = 0; +uint64_t process_data_timestamp_micros = 0; +uint64_t indicator_timestamp_micros = 0; +uint64_t send_usb_timestamp_micros = 0; +uint64_t send_elrs_timestamp_micros = 0; const int BUTTON_PRESSED = LOW; const int BUTTON_NOT_PRESSED = HIGH; @@ -393,7 +393,6 @@ void send_usb_data() */ int apply_calibration_12bit(int gimbal_value, int min_value, int max_value, int center_value, int deadband_value, int expo_value) { - int calibrated_value = AXIS_12BIT_CENTER; if (gimbal_value > (center_value + deadband_value)) @@ -421,7 +420,6 @@ int apply_calibration_12bit(int gimbal_value, int min_value, int max_value, int */ void process_input_data() { - int analog_x1_gimbal_value = 0; int analog_y1_gimbal_value = 0; int analog_x2_gimbal_value = 0; From 1402a2f056cc1aaba0f25b43ed7d49495d36a763 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sat, 27 May 2023 06:08:22 +0200 Subject: [PATCH 11/29] Removed unnessesary user lib --- firmware/lib/ResponsiveAnalogRead.cpp | 140 -------------------------- firmware/lib/ResponsiveAnalogRead.h | 89 ---------------- 2 files changed, 229 deletions(-) delete mode 100644 firmware/lib/ResponsiveAnalogRead.cpp delete mode 100644 firmware/lib/ResponsiveAnalogRead.h diff --git a/firmware/lib/ResponsiveAnalogRead.cpp b/firmware/lib/ResponsiveAnalogRead.cpp deleted file mode 100644 index fa345de..0000000 --- a/firmware/lib/ResponsiveAnalogRead.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* - * ResponsiveAnalogRead.cpp - * Arduino library for eliminating noise in analogRead inputs without decreasing responsiveness - * - * Copyright (c) 2016 Damien Clarke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include "ResponsiveAnalogRead.h" - -void ResponsiveAnalogRead::begin(int pin, bool sleepEnable, float snapMultiplier){ - pinMode(pin, INPUT ); // ensure button pin is an input - digitalWrite(pin, LOW ); // ensure pullup is off on button pin - - this->pin = pin; - this->sleepEnable = sleepEnable; - setSnapMultiplier(snapMultiplier); - - -} - - -void ResponsiveAnalogRead::update() -{ - rawValue = analogRead(pin); - this->update(rawValue); -} - -void ResponsiveAnalogRead::update(int rawValueRead) -{ - rawValue = rawValueRead; - prevResponsiveValue = responsiveValue; - responsiveValue = getResponsiveValue(rawValue); - responsiveValueHasChanged = responsiveValue != prevResponsiveValue; -} - -int ResponsiveAnalogRead::getResponsiveValue(int newValue) -{ - // if sleep and edge snap are enabled and the new value is very close to an edge, drag it a little closer to the edges - // This'll make it easier to pull the output values right to the extremes without sleeping, - // and it'll make movements right near the edge appear larger, making it easier to wake up - if(sleepEnable && edgeSnapEnable) { - if(newValue < activityThreshold) { - newValue = (newValue * 2) - activityThreshold; - } else if(newValue > analogResolution - activityThreshold) { - newValue = (newValue * 2) - analogResolution + activityThreshold; - } - } - - // get difference between new input value and current smooth value - unsigned int diff = abs(newValue - smoothValue); - - // measure the difference between the new value and current value - // and use another exponential moving average to work out what - // the current margin of error is - errorEMA += ((newValue - smoothValue) - errorEMA) * 0.4; - - // if sleep has been enabled, sleep when the amount of error is below the activity threshold - if(sleepEnable) { - // recalculate sleeping status - sleeping = abs(errorEMA) < activityThreshold; - } - - // if we're allowed to sleep, and we're sleeping - // then don't update responsiveValue this loop - // just output the existing responsiveValue - if(sleepEnable && sleeping) { - return (int)smoothValue; - } - - // use a 'snap curve' function, where we pass in the diff (x) and get back a number from 0-1. - // We want small values of x to result in an output close to zero, so when the smooth value is close to the input value - // it'll smooth out noise aggressively by responding slowly to sudden changes. - // We want a small increase in x to result in a much higher output value, so medium and large movements are snappy and responsive, - // and aren't made sluggish by unnecessarily filtering out noise. A hyperbola (f(x) = 1/x) curve is used. - // First x has an offset of 1 applied, so x = 0 now results in a value of 1 from the hyperbola function. - // High values of x tend toward 0, but we want an output that begins at 0 and tends toward 1, so 1-y flips this up the right way. - // Finally the result is multiplied by 2 and capped at a maximum of one, which means that at a certain point all larger movements are maximally snappy - - // then multiply the input by SNAP_MULTIPLER so input values fit the snap curve better. - float snap = snapCurve(diff * snapMultiplier); - - // when sleep is enabled, the emphasis is stopping on a responsiveValue quickly, and it's less about easing into position. - // If sleep is enabled, add a small amount to snap so it'll tend to snap into a more accurate position before sleeping starts. - if(sleepEnable) { - snap *= 0.5 + 0.5; - } - - // calculate the exponential moving average based on the snap - smoothValue += (newValue - smoothValue) * snap; - - // ensure output is in bounds - if(smoothValue < 0.0) { - smoothValue = 0.0; - } else if(smoothValue > analogResolution - 1) { - smoothValue = analogResolution - 1; - } - - // expected output is an integer - return (int)smoothValue; -} - -float ResponsiveAnalogRead::snapCurve(float x) -{ - float y = 1.0 / (x + 1.0); - y = (1.0 - y) * 2.0; - if(y > 1.0) { - return 1.0; - } - return y; -} - -void ResponsiveAnalogRead::setSnapMultiplier(float newMultiplier) -{ - if(newMultiplier > 1.0) { - newMultiplier = 1.0; - } - if(newMultiplier < 0.0) { - newMultiplier = 0.0; - } - snapMultiplier = newMultiplier; -} diff --git a/firmware/lib/ResponsiveAnalogRead.h b/firmware/lib/ResponsiveAnalogRead.h deleted file mode 100644 index 15ade2b..0000000 --- a/firmware/lib/ResponsiveAnalogRead.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ResponsiveAnalogRead.h - * Arduino library for eliminating noise in analogRead inputs without decreasing responsiveness - * - * Copyright (c) 2016 Damien Clarke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef RESPONSIVE_ANALOG_READ_H -#define RESPONSIVE_ANALOG_READ_H - -#include - -class ResponsiveAnalogRead -{ - public: - - // pin - the pin to read - // sleepEnable - enabling sleep will cause values to take less time to stop changing and potentially stop changing more abruptly, - // where as disabling sleep will cause values to ease into their correct position smoothly - // snapMultiplier - a value from 0 to 1 that controls the amount of easing - // increase this to lessen the amount of easing (such as 0.1) and make the responsive values more responsive - // but doing so may cause more noise to seep through if sleep is not enabled - - ResponsiveAnalogRead(){}; //default constructor must be followed by call to begin function - ResponsiveAnalogRead(int pin, bool sleepEnable, float snapMultiplier = 0.01){ - begin(pin, sleepEnable, snapMultiplier); - }; - - void begin(int pin, bool sleepEnable, float snapMultiplier = 0.01); // use with default constructor to initialize - - inline int getValue() { return responsiveValue; } // get the responsive value from last update - inline int getRawValue() { return rawValue; } // get the raw analogRead() value from last update - inline bool hasChanged() { return responsiveValueHasChanged; } // returns true if the responsive value has changed during the last update - inline bool isSleeping() { return sleeping; } // returns true if the algorithm is currently in sleeping mode - void update(); // updates the value by performing an analogRead() and calculating a responsive value based off it - void update(int rawValueRead); // updates the value accepting a value and calculating a responsive value based off it - - void setSnapMultiplier(float newMultiplier); - inline void enableSleep() { sleepEnable = true; } - inline void disableSleep() { sleepEnable = false; } - inline void enableEdgeSnap() { edgeSnapEnable = true; } - // edge snap ensures that values at the edges of the spectrum (0 and 1023) can be easily reached when sleep is enabled - inline void disableEdgeSnap() { edgeSnapEnable = false; } - inline void setActivityThreshold(float newThreshold) { activityThreshold = newThreshold; } - // the amount of movement that must take place to register as activity and start moving the output value. Defaults to 4.0 - inline void setAnalogResolution(int resolution) { analogResolution = resolution; } - // if your ADC is something other than 10bit (1024), set that here - - private: - int pin; - int analogResolution = 1024; - float snapMultiplier; - bool sleepEnable; - float activityThreshold = 4.0; - bool edgeSnapEnable = true; - - float smoothValue; - unsigned long lastActivityMS; - float errorEMA = 0.0; - bool sleeping = false; - - int rawValue; - int responsiveValue; - int prevResponsiveValue; - bool responsiveValueHasChanged; - - int getResponsiveValue(int newValue); - float snapCurve(float x); -}; - -#endif From 86c205dccae94fa6455f3dce423158ee26631192 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sat, 27 May 2023 22:00:50 +0200 Subject: [PATCH 12/29] Added extra script for clangd --- firmware/extra_script.py | 5 +++++ firmware/platformio.ini | 1 + 2 files changed, 6 insertions(+) create mode 100644 firmware/extra_script.py diff --git a/firmware/extra_script.py b/firmware/extra_script.py new file mode 100644 index 0000000..b09c47d --- /dev/null +++ b/firmware/extra_script.py @@ -0,0 +1,5 @@ +import os +Import("env") + +# include toolchain paths +env.Replace(COMPILATIONDB_INCLUDE_TOOLCHAIN=True) diff --git a/firmware/platformio.ini b/firmware/platformio.ini index 17401a6..897596b 100644 --- a/firmware/platformio.ini +++ b/firmware/platformio.ini @@ -14,3 +14,4 @@ board = teensylc framework = arduino build_flags = -D USB_HID -D LAYOUT_SWEDISH -w board_build.f_cpu = 48000000L +extra_scripts = pre:extra_script.py From dceae922de61d1b176a9f3c929e38cb6c1a0d67e Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sat, 27 May 2023 23:31:10 +0000 Subject: [PATCH 13/29] Code cleanup --- firmware/src/ElrsTx.cpp | 199 ++++----- firmware/src/ElrsTx.h | 90 ++-- firmware/src/IndicatorLed.cpp | 56 +-- firmware/src/IndicatorLed.h | 29 +- firmware/src/cmdr_joystick.cpp | 739 +++++++++++++++------------------ 5 files changed, 512 insertions(+), 601 deletions(-) diff --git a/firmware/src/ElrsTx.cpp b/firmware/src/ElrsTx.cpp index 4694ed1..cda6ba8 100644 --- a/firmware/src/ElrsTx.cpp +++ b/firmware/src/ElrsTx.cpp @@ -34,19 +34,18 @@ * * @param serial The serial port to use */ -ElrsTx::ElrsTx(HardwareSerial& serial): _serial(serial) { } +ElrsTx::ElrsTx(HardwareSerial &serial) : _serial(serial) {} /** - * @brief Initialize the ELRS transmitter + * @brief Initialize the ELRS transmitter */ -void ElrsTx::begin(int packet_rate, int tx_power) -{ - const int ELRS_SERIAL_BAUDRATE = 400000; - - _serial.begin(ELRS_SERIAL_BAUDRATE); +void ElrsTx::begin(int packet_rate, int tx_power) { + const int ELRS_SERIAL_BAUDRATE = 400000; - _packet_rate = packet_rate; - _tx_power = tx_power; + _serial.begin(ELRS_SERIAL_BAUDRATE); + + _packet_rate = packet_rate; + _tx_power = tx_power; } /** @@ -56,14 +55,12 @@ void ElrsTx::begin(int packet_rate, int tx_power) * @param len The length of the packet * @return The CRC8 of the packet */ -uint8_t ElrsTx::calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) -{ - uint8_t crc = 0; - for (uint8_t i = 0; i < len; i++) - { - crc = CRSF_CRC8TAB[crc ^ *ptr++]; - } - return crc; +uint8_t ElrsTx::calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) { + uint8_t crc = 0; + for (uint8_t i = 0; i < len; i++) { + crc = CRSF_CRC8TAB[crc ^ *ptr++]; + } + return crc; } /** @@ -75,40 +72,39 @@ uint8_t ElrsTx::calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) * 2 - type * 3-24 - data (16 11bit channels in 8bit format) * 25 - crc - * - * @param packet Resulting packet - * @param channels Channel data + * + * @param packet Resulting packet + * @param channels Channel data */ -void ElrsTx::prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) -{ - const int CRSF_TYPE_CHANNELS = 0x16; - - packet[0] = ELRS_ADDRESS; - packet[1] = 24; - packet[2] = CRSF_TYPE_CHANNELS; - packet[3] = (uint8_t)(channels[0] & 0x07FF); - packet[4] = (uint8_t)((channels[0] & 0x07FF) >> 8 | (channels[1] & 0x07FF) << 3); - packet[5] = (uint8_t)((channels[1] & 0x07FF) >> 5 | (channels[2] & 0x07FF) << 6); - packet[6] = (uint8_t)((channels[2] & 0x07FF) >> 2); - packet[7] = (uint8_t)((channels[2] & 0x07FF) >> 10 | (channels[3] & 0x07FF) << 1); - packet[8] = (uint8_t)((channels[3] & 0x07FF) >> 7 | (channels[4] & 0x07FF) << 4); - packet[9] = (uint8_t)((channels[4] & 0x07FF) >> 4 | (channels[5] & 0x07FF) << 7); - packet[10] = (uint8_t)((channels[5] & 0x07FF) >> 1); - packet[11] = (uint8_t)((channels[5] & 0x07FF) >> 9 | (channels[6] & 0x07FF) << 2); - packet[12] = (uint8_t)((channels[6] & 0x07FF) >> 6 | (channels[7] & 0x07FF) << 5); - packet[13] = (uint8_t)((channels[7] & 0x07FF) >> 3); - packet[14] = (uint8_t)((channels[8] & 0x07FF)); - packet[15] = (uint8_t)((channels[8] & 0x07FF) >> 8 | (channels[9] & 0x07FF) << 3); - packet[16] = (uint8_t)((channels[9] & 0x07FF) >> 5 | (channels[10] & 0x07FF) << 6); - packet[17] = (uint8_t)((channels[10] & 0x07FF) >> 2); - packet[18] = (uint8_t)((channels[10] & 0x07FF) >> 10 | (channels[11] & 0x07FF) << 1); - packet[19] = (uint8_t)((channels[11] & 0x07FF) >> 7 | (channels[12] & 0x07FF) << 4); - packet[20] = (uint8_t)((channels[12] & 0x07FF) >> 4 | (channels[13] & 0x07FF) << 7); - packet[21] = (uint8_t)((channels[13] & 0x07FF) >> 1); - packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2); - packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5); - packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3); - packet[25] = calculate_crsf_crc8(&packet[2], packet[1] - 1); +void ElrsTx::prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) { + const int CRSF_TYPE_CHANNELS = 0x16; + + packet[0] = ELRS_ADDRESS; + packet[1] = 24; + packet[2] = CRSF_TYPE_CHANNELS; + packet[3] = (uint8_t)(channels[0] & 0x07FF); + packet[4] = (uint8_t)((channels[0] & 0x07FF) >> 8 | (channels[1] & 0x07FF) << 3); + packet[5] = (uint8_t)((channels[1] & 0x07FF) >> 5 | (channels[2] & 0x07FF) << 6); + packet[6] = (uint8_t)((channels[2] & 0x07FF) >> 2); + packet[7] = (uint8_t)((channels[2] & 0x07FF) >> 10 | (channels[3] & 0x07FF) << 1); + packet[8] = (uint8_t)((channels[3] & 0x07FF) >> 7 | (channels[4] & 0x07FF) << 4); + packet[9] = (uint8_t)((channels[4] & 0x07FF) >> 4 | (channels[5] & 0x07FF) << 7); + packet[10] = (uint8_t)((channels[5] & 0x07FF) >> 1); + packet[11] = (uint8_t)((channels[5] & 0x07FF) >> 9 | (channels[6] & 0x07FF) << 2); + packet[12] = (uint8_t)((channels[6] & 0x07FF) >> 6 | (channels[7] & 0x07FF) << 5); + packet[13] = (uint8_t)((channels[7] & 0x07FF) >> 3); + packet[14] = (uint8_t)((channels[8] & 0x07FF)); + packet[15] = (uint8_t)((channels[8] & 0x07FF) >> 8 | (channels[9] & 0x07FF) << 3); + packet[16] = (uint8_t)((channels[9] & 0x07FF) >> 5 | (channels[10] & 0x07FF) << 6); + packet[17] = (uint8_t)((channels[10] & 0x07FF) >> 2); + packet[18] = (uint8_t)((channels[10] & 0x07FF) >> 10 | (channels[11] & 0x07FF) << 1); + packet[19] = (uint8_t)((channels[11] & 0x07FF) >> 7 | (channels[12] & 0x07FF) << 4); + packet[20] = (uint8_t)((channels[12] & 0x07FF) >> 4 | (channels[13] & 0x07FF) << 7); + packet[21] = (uint8_t)((channels[13] & 0x07FF) >> 1); + packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2); + packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5); + packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3); + packet[25] = calculate_crsf_crc8(&packet[2], packet[1] - 1); } /** @@ -124,31 +120,30 @@ void ElrsTx::prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) * 6 - value * 7 - crc * - * command list: + * command list: * ELRS_BIND_COMMAND = 0xFF; * ELRS_WIFI_COMMAND = 0xFE; * ELRS_TLM_RATIO_COMMAND = 0x02; * ELRS_SWITCH_MODE_COMMAND = 0x03; * ELRS_MODEL_MATCH_COMMAND = 0x04; * ELRS_BLE_JOYSTIC_COMMAND = 17; - * - * @param packet_cmd Resulting packet - * @param command Command to be sent + * + * @param packet_cmd Resulting packet + * @param command Command to be sent * @param value Value to be sent */ -void ElrsTx::prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) -{ - const int ELRS_ADDR_RADIO = 0xEA; - const int ELRS_TYPE_SETTINGS_WRITE = 0x2D; - - packet_cmd[0] = ELRS_ADDRESS; - packet_cmd[1] = 6; - packet_cmd[2] = ELRS_TYPE_SETTINGS_WRITE; - packet_cmd[3] = ELRS_ADDRESS; - packet_cmd[4] = ELRS_ADDR_RADIO; - packet_cmd[5] = command; - packet_cmd[6] = value; - packet_cmd[7] = calculate_crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); +void ElrsTx::prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) { + const int ELRS_ADDR_RADIO = 0xEA; + const int ELRS_TYPE_SETTINGS_WRITE = 0x2D; + + packet_cmd[0] = ELRS_ADDRESS; + packet_cmd[1] = 6; + packet_cmd[2] = ELRS_TYPE_SETTINGS_WRITE; + packet_cmd[3] = ELRS_ADDRESS; + packet_cmd[4] = ELRS_ADDR_RADIO; + packet_cmd[5] = command; + packet_cmd[6] = value; + packet_cmd[7] = calculate_crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); } /** @@ -157,50 +152,38 @@ void ElrsTx::prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint * @param value Value (0-2048) to be set * @param channel Channel (0-11) to be set */ -void ElrsTx::set_data(int16_t value, uint8_t channel) -{ - elrs_channels[channel] = value; -} +void ElrsTx::set_data(int16_t value, uint8_t channel) { elrs_channels[channel] = value; } /** * @brief Send data to ERLS TX. This function should be called within the main loop with a 1.6ms interval */ -void ElrsTx::send_data() -{ - const int ELRS_PKT_RATE_COMMAND = 0x01; - const int ELRS_POWER_COMMAND = 0x06; - - if (elrs_init_done == true) - { - prepare_crsf_data_packet(crsf_packet, elrs_channels); - _serial.write(crsf_packet, CRSF_PACKET_SIZE); +void ElrsTx::send_data() { + const int ELRS_PKT_RATE_COMMAND = 0x01; + const int ELRS_POWER_COMMAND = 0x06; + + if (elrs_init_done == true) { + prepare_crsf_data_packet(crsf_packet, elrs_channels); + _serial.write(crsf_packet, CRSF_PACKET_SIZE); + } else { + // Setting up initial communication link between ERLS TX and Teensy (give ERLS TX time to auto detect Teensy) + if (elrs_init_counter < 500) { + prepare_crsf_data_packet(crsf_packet, elrs_channels); + _serial.write(crsf_packet, CRSF_PACKET_SIZE); + elrs_init_counter++; } - else - { - // Setting up initial communication link between ERLS TX and Teensy (give ERLS TX time to auto detect Teensy) - if (elrs_init_counter < 500) - { - prepare_crsf_data_packet(crsf_packet, elrs_channels); - _serial.write(crsf_packet, CRSF_PACKET_SIZE); - elrs_init_counter++; - } - // Send command to update TX packet rate - else if (elrs_init_counter < 505) - { - prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, _packet_rate); - _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); - elrs_init_counter++; - } - // Send command to update TX power - else if (elrs_init_counter < 510) - { - prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, _tx_power); - _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); - elrs_init_counter++; - } - else - { - elrs_init_done = true; - } + // Send command to update TX packet rate + else if (elrs_init_counter < 505) { + prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, _packet_rate); + _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + elrs_init_counter++; } -} \ No newline at end of file + // Send command to update TX power + else if (elrs_init_counter < 510) { + prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, _tx_power); + _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + elrs_init_counter++; + } else { + elrs_init_done = true; + } + } +} diff --git a/firmware/src/ElrsTx.h b/firmware/src/ElrsTx.h index 65b2a50..c7b53c8 100644 --- a/firmware/src/ElrsTx.h +++ b/firmware/src/ElrsTx.h @@ -1,4 +1,4 @@ - /* +/* * ======================================================================================================= * ------------------------------------------------------------------------------------------------------- * ---####################-----###########-------###########-----############--############-############-- @@ -32,18 +32,18 @@ #include -// CRSF +// CRSF const int CRSF_MAX_CHANNEL = 16; const int CRSF_TYPE_CHANNELS = 0x16; const int CRSF_DIGITAL_CHANNEL_MIN = 172; -const int CRSF_DIGITAL_CHANNEL_CENTER = 992; +const int CRSF_DIGITAL_CHANNEL_CENTER = 992; const int CRSF_DIGITAL_CHANNEL_MAX = 1811; -const int CRSF_TIME_BETWEEN_FRAMES_US = 1666; +const int CRSF_TIME_BETWEEN_FRAMES_US = 1666; const int CRSF_PACKET_SIZE = 26; const int CRSF_CMD_PACKET_SIZE = 8; // ERLS others -const int ELRS_ADDR_RADIO = 0xEA; +const int ELRS_ADDR_RADIO = 0xEA; const int ELRS_SERIAL_BAUDRATE = 400000; // ELRS command @@ -59,10 +59,10 @@ const int ELRS_BLE_JOYSTIC_COMMAND = 17; const int ELRS_TYPE_SETTINGS_WRITE = 0x2D; // ERLS command values -const int ELRS_PACKET_RATE_50Hz = 0; -const int ELRS_PACKET_RATE_100Hz = 1; -const int ELRS_PACKET_RATE_200Hz = 2; -const int ELRS_PACKET_RATE_500Hz = 3; +const int ELRS_PACKET_RATE_50Hz = 0; +const int ELRS_PACKET_RATE_100Hz = 1; +const int ELRS_PACKET_RATE_200Hz = 2; +const int ELRS_PACKET_RATE_500Hz = 3; const int ELRS_TX_POWER_10mW = 0; const int ELRS_TX_POWER_25mW = 1; const int ELRS_TX_POWER_100mW = 2; @@ -70,50 +70,40 @@ const int ELRS_TX_POWER_250mW = 3; const int ELRS_TX_POWER_500mW = 4; const int ELRS_TX_POWER_1000mW = 5; -class ElrsTx -{ - public: - ElrsTx(HardwareSerial& serial); - - void set_data(int16_t value, uint8_t channel); - void send_data(); - void begin(int packet_rate, int tx_power); - - private: - uint8_t crsf_packet[CRSF_PACKET_SIZE]; - uint8_t crsf_cmd_packet[CRSF_CMD_PACKET_SIZE]; - int16_t elrs_channels[CRSF_MAX_CHANNEL]; +class ElrsTx { +public: + ElrsTx(HardwareSerial &serial); - bool elrs_init_done = false; - int elrs_init_counter = 0; - - HardwareSerial& _serial; - int _packet_rate; - int _tx_power; + void set_data(int16_t value, uint8_t channel); + void send_data(); + void begin(int packet_rate, int tx_power); - // crc implementation from CRSF protocol document rev7 - const uint8_t CRSF_CRC8TAB[256] = { - 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, - 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, - 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, - 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, - 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, - 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, - 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, - 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, - 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, - 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, - 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, - 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, - 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, - 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, - 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, - 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9}; +private: + uint8_t crsf_packet[CRSF_PACKET_SIZE]; + uint8_t crsf_cmd_packet[CRSF_CMD_PACKET_SIZE]; + int16_t elrs_channels[CRSF_MAX_CHANNEL]; - uint8_t calculate_crsf_crc8(const uint8_t *ptr, uint8_t len); - void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]); - void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value); + bool elrs_init_done = false; + int elrs_init_counter = 0; + HardwareSerial &_serial; + int _packet_rate; + int _tx_power; + + // crc implementation from CRSF protocol document rev7 + const uint8_t CRSF_CRC8TAB[256] = { + 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, + 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, + 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, + 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, + 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, + 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, + 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, + 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9}; + + uint8_t calculate_crsf_crc8(const uint8_t *ptr, uint8_t len); + void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]); + void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value); }; -#endif \ No newline at end of file +#endif diff --git a/firmware/src/IndicatorLed.cpp b/firmware/src/IndicatorLed.cpp index 3001d73..34774bf 100644 --- a/firmware/src/IndicatorLed.cpp +++ b/firmware/src/IndicatorLed.cpp @@ -31,12 +31,12 @@ /** * @brief Construct a new Indicator Led:: Indicator Led object - * - * @param pin Pin number for indicator LED + * + * @param pin Pin number for indicator LED */ IndicatorLed::IndicatorLed(int pin) { - _pin = pin; + _pin = pin; } /** @@ -44,8 +44,8 @@ IndicatorLed::IndicatorLed(int pin) */ void IndicatorLed::begin() { - pinMode(_pin, OUTPUT); - digitalWrite(_pin, LOW); + pinMode(_pin, OUTPUT); + digitalWrite(_pin, LOW); } /** @@ -53,7 +53,7 @@ void IndicatorLed::begin() */ void IndicatorLed::on() { - led_mode = LED_ON; + led_mode = LED_ON; } /** @@ -61,7 +61,7 @@ void IndicatorLed::on() */ void IndicatorLed::off() { - led_mode = LED_OFF; + led_mode = LED_OFF; } /** @@ -69,7 +69,7 @@ void IndicatorLed::off() */ void IndicatorLed::blink() { - led_mode = LED_BLINK; + led_mode = LED_BLINK; } /** @@ -78,24 +78,24 @@ void IndicatorLed::blink() void IndicatorLed::update() { - if (led_mode == LED_BLINK && current_state == LED_OFF) - { - digitalWrite(_pin, HIGH); - current_state = LED_ON; - } - else if (led_mode == LED_BLINK && current_state == LED_ON) - { - digitalWrite(_pin, LOW); - current_state = LED_OFF; - } - else if (led_mode == LED_ON) - { - digitalWrite(_pin, HIGH); - current_state = LED_ON; - } - else - { - digitalWrite(_pin, LOW); - current_state = LED_OFF; - } + if (led_mode == LED_BLINK && current_state == LED_OFF) + { + digitalWrite(_pin, HIGH); + current_state = LED_ON; + } + else if (led_mode == LED_BLINK && current_state == LED_ON) + { + digitalWrite(_pin, LOW); + current_state = LED_OFF; + } + else if (led_mode == LED_ON) + { + digitalWrite(_pin, HIGH); + current_state = LED_ON; + } + else + { + digitalWrite(_pin, LOW); + current_state = LED_OFF; + } } diff --git a/firmware/src/IndicatorLed.h b/firmware/src/IndicatorLed.h index dc188e5..4d7b3a4 100644 --- a/firmware/src/IndicatorLed.h +++ b/firmware/src/IndicatorLed.h @@ -36,20 +36,19 @@ const int LED_OFF = 0; const int LED_ON = 1; const int LED_BLINK = 2; -class IndicatorLed -{ - public: - IndicatorLed(int pin); - void begin(); - void on(); - void off(); - void blink(); - void update(); - - private: - int _pin; - int led_mode = LED_OFF; - int current_state = LED_OFF; +class IndicatorLed { +public: + IndicatorLed(int pin); + void begin(); + void on(); + void off(); + void blink(); + void update(); + +private: + int _pin; + int led_mode = LED_OFF; + int current_state = LED_OFF; }; -#endif \ No newline at end of file +#endif diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index 52fb685..67a2acf 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -29,12 +29,11 @@ * Joystick based on standard teensy "usb_joystick" library for HID joystick usb data communication. */ - +#include "ElrsTx.h" +#include "IndicatorLed.h" #include #include #include -#include "ElrsTx.h" -#include "IndicatorLed.h" IndicatorLed status_led(13); IndicatorLed button_led_1(22); @@ -79,33 +78,32 @@ const int DEADZONE_X = 50; const int DEADZONE_Y = 50; const int JOYSTICK_HAT_CENTER = -1; -enum EEPROM_ADR -{ - MAX_X1_ADR_HIGH, - MAX_X1_ADR_LOW, - MIN_X1_ADR_HIGH, - MIN_X1_ADR_LOW, - CNT_X1_ADR_HIGH, - CNT_X1_ADR_LOW, - MAX_Y1_ADR_HIGH, - MAX_Y1_ADR_LOW, - MIN_Y1_ADR_HIGH, - MIN_Y1_ADR_LOW, - CNT_Y1_ADR_HIGH, - CNT_Y1_ADR_LOW, - MAX_X2_ADR_HIGH, - MAX_X2_ADR_LOW, - MIN_X2_ADR_HIGH, - MIN_X2_ADR_LOW, - CNT_X2_ADR_HIGH, - CNT_X2_ADR_LOW, - MAX_Y2_ADR_HIGH, - MAX_Y2_ADR_LOW, - MIN_Y2_ADR_HIGH, - MIN_Y2_ADR_LOW, - CNT_Y2_ADR_HIGH, - CNT_Y2_ADR_LOW, - EEPROM_ADR_NBR_OF_BYTES +enum EEPROM_ADR { + MAX_X1_ADR_HIGH, + MAX_X1_ADR_LOW, + MIN_X1_ADR_HIGH, + MIN_X1_ADR_LOW, + CNT_X1_ADR_HIGH, + CNT_X1_ADR_LOW, + MAX_Y1_ADR_HIGH, + MAX_Y1_ADR_LOW, + MIN_Y1_ADR_HIGH, + MIN_Y1_ADR_LOW, + CNT_Y1_ADR_HIGH, + CNT_Y1_ADR_LOW, + MAX_X2_ADR_HIGH, + MAX_X2_ADR_LOW, + MIN_X2_ADR_HIGH, + MIN_X2_ADR_LOW, + CNT_X2_ADR_HIGH, + CNT_X2_ADR_LOW, + MAX_Y2_ADR_HIGH, + MAX_Y2_ADR_LOW, + MIN_Y2_ADR_HIGH, + MIN_Y2_ADR_LOW, + CNT_Y2_ADR_HIGH, + CNT_Y2_ADR_LOW, + EEPROM_ADR_NBR_OF_BYTES }; int joystick_counter = 0; @@ -146,69 +144,67 @@ int joystick_calibration_mode = CALIBRATION_OFF; /** * @brief Save calibration data to EEPROM */ -void save_to_eeprom() -{ - EEPROM.write(MAX_X1_ADR_LOW, joystick_x1_12bit_max); - EEPROM.write(MAX_X1_ADR_HIGH, joystick_x1_12bit_max >> 8); - EEPROM.write(MIN_X1_ADR_LOW, joystick_x1_12bit_min); - EEPROM.write(MIN_X1_ADR_HIGH, joystick_x1_12bit_min >> 8); - EEPROM.write(CNT_X1_ADR_LOW, joystick_x1_12bit_center); - EEPROM.write(CNT_X1_ADR_HIGH, joystick_x1_12bit_center >> 8); +void save_to_eeprom() { + EEPROM.write(MAX_X1_ADR_LOW, joystick_x1_12bit_max); + EEPROM.write(MAX_X1_ADR_HIGH, joystick_x1_12bit_max >> 8); + EEPROM.write(MIN_X1_ADR_LOW, joystick_x1_12bit_min); + EEPROM.write(MIN_X1_ADR_HIGH, joystick_x1_12bit_min >> 8); + EEPROM.write(CNT_X1_ADR_LOW, joystick_x1_12bit_center); + EEPROM.write(CNT_X1_ADR_HIGH, joystick_x1_12bit_center >> 8); - EEPROM.write(MAX_Y1_ADR_LOW, joystick_y1_12bit_max); - EEPROM.write(MAX_Y1_ADR_HIGH, joystick_y1_12bit_max >> 8); - EEPROM.write(MIN_Y1_ADR_LOW, joystick_y1_12bit_min); - EEPROM.write(MIN_Y1_ADR_HIGH, joystick_y1_12bit_min >> 8); - EEPROM.write(CNT_Y1_ADR_LOW, joystick_y1_12bit_center); - EEPROM.write(CNT_Y1_ADR_HIGH, joystick_y1_12bit_center >> 8); + EEPROM.write(MAX_Y1_ADR_LOW, joystick_y1_12bit_max); + EEPROM.write(MAX_Y1_ADR_HIGH, joystick_y1_12bit_max >> 8); + EEPROM.write(MIN_Y1_ADR_LOW, joystick_y1_12bit_min); + EEPROM.write(MIN_Y1_ADR_HIGH, joystick_y1_12bit_min >> 8); + EEPROM.write(CNT_Y1_ADR_LOW, joystick_y1_12bit_center); + EEPROM.write(CNT_Y1_ADR_HIGH, joystick_y1_12bit_center >> 8); - EEPROM.write(MAX_X2_ADR_LOW, joystick_x2_12bit_max); - EEPROM.write(MAX_X2_ADR_HIGH, joystick_x2_12bit_max >> 8); - EEPROM.write(MIN_X2_ADR_LOW, joystick_x2_12bit_min); - EEPROM.write(MIN_X2_ADR_HIGH, joystick_x2_12bit_min >> 8); - EEPROM.write(CNT_X2_ADR_LOW, joystick_x2_12bit_center); - EEPROM.write(CNT_X2_ADR_HIGH, joystick_x2_12bit_center >> 8); + EEPROM.write(MAX_X2_ADR_LOW, joystick_x2_12bit_max); + EEPROM.write(MAX_X2_ADR_HIGH, joystick_x2_12bit_max >> 8); + EEPROM.write(MIN_X2_ADR_LOW, joystick_x2_12bit_min); + EEPROM.write(MIN_X2_ADR_HIGH, joystick_x2_12bit_min >> 8); + EEPROM.write(CNT_X2_ADR_LOW, joystick_x2_12bit_center); + EEPROM.write(CNT_X2_ADR_HIGH, joystick_x2_12bit_center >> 8); - EEPROM.write(MAX_Y2_ADR_LOW, joystick_y2_12bit_max); - EEPROM.write(MAX_Y2_ADR_HIGH, joystick_y2_12bit_max >> 8); - EEPROM.write(MIN_Y2_ADR_LOW, joystick_y2_12bit_min); - EEPROM.write(MIN_Y2_ADR_HIGH, joystick_y2_12bit_min >> 8); - EEPROM.write(CNT_Y2_ADR_LOW, joystick_y2_12bit_center); - EEPROM.write(CNT_Y2_ADR_HIGH, joystick_y2_12bit_center >> 8); + EEPROM.write(MAX_Y2_ADR_LOW, joystick_y2_12bit_max); + EEPROM.write(MAX_Y2_ADR_HIGH, joystick_y2_12bit_max >> 8); + EEPROM.write(MIN_Y2_ADR_LOW, joystick_y2_12bit_min); + EEPROM.write(MIN_Y2_ADR_HIGH, joystick_y2_12bit_min >> 8); + EEPROM.write(CNT_Y2_ADR_LOW, joystick_y2_12bit_center); + EEPROM.write(CNT_Y2_ADR_HIGH, joystick_y2_12bit_center >> 8); } /** * @brief Load calibration data from EEPROM */ -void load_from_eeprom() -{ - joystick_x1_12bit_max = (EEPROM.read(MAX_X1_ADR_HIGH) << 8); - joystick_x1_12bit_max |= EEPROM.read(MAX_X1_ADR_LOW); - joystick_x1_12bit_min = (EEPROM.read(MIN_X1_ADR_HIGH) << 8); - joystick_x1_12bit_min |= EEPROM.read(MIN_X1_ADR_LOW); - joystick_x1_12bit_center = (EEPROM.read(CNT_X1_ADR_HIGH) << 8); - joystick_x1_12bit_center |= EEPROM.read(CNT_X1_ADR_LOW); +void load_from_eeprom() { + joystick_x1_12bit_max = (EEPROM.read(MAX_X1_ADR_HIGH) << 8); + joystick_x1_12bit_max |= EEPROM.read(MAX_X1_ADR_LOW); + joystick_x1_12bit_min = (EEPROM.read(MIN_X1_ADR_HIGH) << 8); + joystick_x1_12bit_min |= EEPROM.read(MIN_X1_ADR_LOW); + joystick_x1_12bit_center = (EEPROM.read(CNT_X1_ADR_HIGH) << 8); + joystick_x1_12bit_center |= EEPROM.read(CNT_X1_ADR_LOW); - joystick_y1_12bit_max = (EEPROM.read(MAX_Y1_ADR_HIGH) << 8); - joystick_y1_12bit_max |= EEPROM.read(MAX_Y1_ADR_LOW); - joystick_y1_12bit_min = (EEPROM.read(MIN_Y1_ADR_HIGH) << 8); - joystick_y1_12bit_min |= EEPROM.read(MIN_Y1_ADR_LOW); - joystick_y1_12bit_center = (EEPROM.read(CNT_Y1_ADR_HIGH) << 8); - joystick_y1_12bit_center |= EEPROM.read(CNT_Y1_ADR_LOW); + joystick_y1_12bit_max = (EEPROM.read(MAX_Y1_ADR_HIGH) << 8); + joystick_y1_12bit_max |= EEPROM.read(MAX_Y1_ADR_LOW); + joystick_y1_12bit_min = (EEPROM.read(MIN_Y1_ADR_HIGH) << 8); + joystick_y1_12bit_min |= EEPROM.read(MIN_Y1_ADR_LOW); + joystick_y1_12bit_center = (EEPROM.read(CNT_Y1_ADR_HIGH) << 8); + joystick_y1_12bit_center |= EEPROM.read(CNT_Y1_ADR_LOW); - joystick_x2_12bit_max = (EEPROM.read(MAX_X2_ADR_HIGH) << 8); - joystick_x2_12bit_max |= EEPROM.read(MAX_X2_ADR_LOW); - joystick_x2_12bit_min = (EEPROM.read(MIN_X2_ADR_HIGH) << 8); - joystick_x2_12bit_min |= EEPROM.read(MIN_X2_ADR_LOW); - joystick_x2_12bit_center = (EEPROM.read(CNT_X2_ADR_HIGH) << 8); - joystick_x2_12bit_center |= EEPROM.read(CNT_X2_ADR_LOW); + joystick_x2_12bit_max = (EEPROM.read(MAX_X2_ADR_HIGH) << 8); + joystick_x2_12bit_max |= EEPROM.read(MAX_X2_ADR_LOW); + joystick_x2_12bit_min = (EEPROM.read(MIN_X2_ADR_HIGH) << 8); + joystick_x2_12bit_min |= EEPROM.read(MIN_X2_ADR_LOW); + joystick_x2_12bit_center = (EEPROM.read(CNT_X2_ADR_HIGH) << 8); + joystick_x2_12bit_center |= EEPROM.read(CNT_X2_ADR_LOW); - joystick_y2_12bit_max = (EEPROM.read(MAX_Y2_ADR_HIGH) << 8); - joystick_y2_12bit_max |= EEPROM.read(MAX_Y2_ADR_LOW); - joystick_y2_12bit_min = (EEPROM.read(MIN_Y2_ADR_HIGH) << 8); - joystick_y2_12bit_min |= EEPROM.read(MIN_Y2_ADR_LOW); - joystick_y2_12bit_center = (EEPROM.read(CNT_Y2_ADR_HIGH) << 8); - joystick_y2_12bit_center |= EEPROM.read(CNT_Y2_ADR_LOW); + joystick_y2_12bit_max = (EEPROM.read(MAX_Y2_ADR_HIGH) << 8); + joystick_y2_12bit_max |= EEPROM.read(MAX_Y2_ADR_LOW); + joystick_y2_12bit_min = (EEPROM.read(MIN_Y2_ADR_HIGH) << 8); + joystick_y2_12bit_min |= EEPROM.read(MIN_Y2_ADR_LOW); + joystick_y2_12bit_center = (EEPROM.read(CNT_Y2_ADR_HIGH) << 8); + joystick_y2_12bit_center |= EEPROM.read(CNT_Y2_ADR_LOW); } /** @@ -219,166 +215,145 @@ void load_from_eeprom() * @param analog_x2 * @param analog_y2 */ -void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) -{ - joystick_x1_12bit = AXIS_12BIT_CENTER; - joystick_y1_12bit = AXIS_12BIT_CENTER; - joystick_x2_12bit = AXIS_12BIT_CENTER; - joystick_y2_12bit = AXIS_12BIT_CENTER; +void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) { + joystick_x1_12bit = AXIS_12BIT_CENTER; + joystick_y1_12bit = AXIS_12BIT_CENTER; + joystick_x2_12bit = AXIS_12BIT_CENTER; + joystick_y2_12bit = AXIS_12BIT_CENTER; - // Check for calibration mode - if (joystick_calibration_mode == CALIBRATION_INIT) - { - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_NOT_PRESSED) - { - joystick_calibration_mode = CALIBRATION_CENTER; - } + // Check for calibration mode + if (joystick_calibration_mode == CALIBRATION_INIT) { + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_NOT_PRESSED) { + joystick_calibration_mode = CALIBRATION_CENTER; } + } - // Calibrate joystick center values - else if (joystick_calibration_mode == CALIBRATION_CENTER) - { - joystick_x1_12bit_center = analog_x1; - joystick_y1_12bit_center = analog_y1; - joystick_x1_12bit_max = joystick_x1_12bit_center; - joystick_x1_12bit_min = joystick_x1_12bit_center; - joystick_y1_12bit_max = joystick_y1_12bit_center; - joystick_y1_12bit_min = joystick_y1_12bit_center; + // Calibrate joystick center values + else if (joystick_calibration_mode == CALIBRATION_CENTER) { + joystick_x1_12bit_center = analog_x1; + joystick_y1_12bit_center = analog_y1; + joystick_x1_12bit_max = joystick_x1_12bit_center; + joystick_x1_12bit_min = joystick_x1_12bit_center; + joystick_y1_12bit_max = joystick_y1_12bit_center; + joystick_y1_12bit_min = joystick_y1_12bit_center; - joystick_x2_12bit_center = analog_x2; - joystick_y2_12bit_center = analog_y2; - joystick_x2_12bit_max = joystick_x2_12bit_center; - joystick_x2_12bit_min = joystick_x2_12bit_center; - joystick_y2_12bit_max = joystick_y2_12bit_center; - joystick_y2_12bit_min = joystick_y2_12bit_center; + joystick_x2_12bit_center = analog_x2; + joystick_y2_12bit_center = analog_y2; + joystick_x2_12bit_max = joystick_x2_12bit_center; + joystick_x2_12bit_min = joystick_x2_12bit_center; + joystick_y2_12bit_max = joystick_y2_12bit_center; + joystick_y2_12bit_min = joystick_y2_12bit_center; - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) - { - joystick_calibration_mode = CALIBRATION_MINMAX; - } + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) { + joystick_calibration_mode = CALIBRATION_MINMAX; } + } - // Calibrate joystick min/max values - else if (joystick_calibration_mode == CALIBRATION_MINMAX) - { - if (analog_x1 > joystick_x1_12bit_max) joystick_x1_12bit_max = analog_x1; - if (analog_x1 < joystick_x1_12bit_min) joystick_x1_12bit_min = analog_x1; - if (analog_y1 > joystick_y1_12bit_max) joystick_y1_12bit_max = analog_y1; - if (analog_y1 < joystick_y1_12bit_min) joystick_y1_12bit_min = analog_y1; - if (analog_x2 > joystick_x2_12bit_max) joystick_x2_12bit_max = analog_x2; - if (analog_x2 < joystick_x2_12bit_min) joystick_x2_12bit_min = analog_x2; - if (analog_y2 > joystick_y2_12bit_max) joystick_y2_12bit_max = analog_y2; - if (analog_y2 < joystick_y2_12bit_min) joystick_y2_12bit_min = analog_y2; + // Calibrate joystick min/max values + else if (joystick_calibration_mode == CALIBRATION_MINMAX) { + if (analog_x1 > joystick_x1_12bit_max) joystick_x1_12bit_max = analog_x1; + if (analog_x1 < joystick_x1_12bit_min) joystick_x1_12bit_min = analog_x1; + if (analog_y1 > joystick_y1_12bit_max) joystick_y1_12bit_max = analog_y1; + if (analog_y1 < joystick_y1_12bit_min) joystick_y1_12bit_min = analog_y1; + if (analog_x2 > joystick_x2_12bit_max) joystick_x2_12bit_max = analog_x2; + if (analog_x2 < joystick_x2_12bit_min) joystick_x2_12bit_min = analog_x2; + if (analog_y2 > joystick_y2_12bit_max) joystick_y2_12bit_max = analog_y2; + if (analog_y2 < joystick_y2_12bit_min) joystick_y2_12bit_min = analog_y2; - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) - { - joystick_calibration_mode = CALIBRATION_OFF; - save_to_eeprom(); - } + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) { + joystick_calibration_mode = CALIBRATION_OFF; + save_to_eeprom(); } + } } /** * @brief Save joystick calibration values to EEPROM */ -void send_elrs_data() -{ - // Set ELRS analog channels - elrs.set_data(map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 0); - elrs.set_data(map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 1); - elrs.set_data(map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 2); - elrs.set_data(map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 3); +void send_elrs_data() { + // Set ELRS analog channels + elrs.set_data(map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 0); + elrs.set_data(map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 1); + elrs.set_data(map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 2); + elrs.set_data(map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 3); - // Set ELRS digital channels - for (int i = 4; i < CRSF_MAX_CHANNEL; i++) - { - elrs.set_data(CRSF_DIGITAL_CHANNEL_MIN, i); - } + // Set ELRS digital channels + for (int i = 4; i < CRSF_MAX_CHANNEL; i++) { + elrs.set_data(CRSF_DIGITAL_CHANNEL_MIN, i); + } - if (toggle_button_arm) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 4); - if (toggle_button_mode) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 5); - if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 6); - if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 7); - if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 8); + if (toggle_button_arm) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 4); + if (toggle_button_mode) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 5); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 6); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 7); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 8); - // Send ELRS data - elrs.send_data(); + // Send ELRS data + elrs.send_data(); } /** * Send USB data to PC */ -void send_usb_data() -{ - // Set USB analog channels - int joystick_x1_10bit = map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); - int joystick_y1_10bit = map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); - int joystick_x2_10bit = map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); - int joystick_y2_10bit = map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); +void send_usb_data() { + // Set USB analog channels + int joystick_x1_10bit = map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); + int joystick_y1_10bit = map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); + int joystick_x2_10bit = map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); + int joystick_y2_10bit = map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); - Joystick.Zrotate(joystick_x1_10bit); - Joystick.Z(joystick_y1_10bit); + Joystick.Zrotate(joystick_x1_10bit); + Joystick.Z(joystick_y1_10bit); - if (fn_mode == 2) - { - Joystick.X(AXIS_10BIT_CENTER); - Joystick.Y(AXIS_10BIT_CENTER); - Joystick.sliderRight(joystick_x2_10bit); - Joystick.sliderLeft(joystick_y2_10bit); - } - else if (fn_mode == 1) - { - Joystick.X(AXIS_10BIT_CENTER); - Joystick.Y(joystick_y2_10bit); - Joystick.sliderRight(joystick_x2_10bit); - Joystick.sliderLeft(AXIS_10BIT_CENTER); - } - else - { - Joystick.X(joystick_x2_10bit); - Joystick.Y(joystick_y2_10bit); - Joystick.sliderRight(AXIS_10BIT_CENTER); - Joystick.sliderLeft(AXIS_10BIT_CENTER); - } + if (fn_mode == 2) { + Joystick.X(AXIS_10BIT_CENTER); + Joystick.Y(AXIS_10BIT_CENTER); + Joystick.sliderRight(joystick_x2_10bit); + Joystick.sliderLeft(joystick_y2_10bit); + } else if (fn_mode == 1) { + Joystick.X(AXIS_10BIT_CENTER); + Joystick.Y(joystick_y2_10bit); + Joystick.sliderRight(joystick_x2_10bit); + Joystick.sliderLeft(AXIS_10BIT_CENTER); + } else { + Joystick.X(joystick_x2_10bit); + Joystick.Y(joystick_y2_10bit); + Joystick.sliderRight(AXIS_10BIT_CENTER); + Joystick.sliderLeft(AXIS_10BIT_CENTER); + } - // Set USB digital channels - for (int i = 1; i < 32; i++) - { - Joystick.button(i, 0); - } + // Set USB digital channels + for (int i = 1; i < 32; i++) { + Joystick.button(i, 0); + } - Joystick.hat(JOYSTICK_HAT_CENTER); + Joystick.hat(JOYSTICK_HAT_CENTER); - if (fn_mode == 2) - { - if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(12, 1); - if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(13, 1); - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(14, 1); - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(15, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(16, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(17, 1); - } - else if (fn_mode == 1) - { - if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(8, 1); - if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(9, 1); - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(10, 1); - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(11, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(1, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(2, 1); - } - else - { - if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(3, 1); - if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(4, 1); - if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(5, 1); - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(6, 1); - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(7, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(1, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(2, 1); - } + if (fn_mode == 2) { + if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(12, 1); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(13, 1); + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(14, 1); + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(15, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(16, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(17, 1); + } else if (fn_mode == 1) { + if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(8, 1); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(9, 1); + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(10, 1); + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(11, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(1, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(2, 1); + } else { + if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(3, 1); + if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(4, 1); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(5, 1); + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(6, 1); + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(7, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(1, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(2, 1); + } - Joystick.send_now(); + Joystick.send_now(); } /** @@ -391,225 +366,189 @@ void send_usb_data() * @param deadband_value * @param expo_value */ -int apply_calibration_12bit(int gimbal_value, int min_value, int max_value, int center_value, int deadband_value, int expo_value) -{ - int calibrated_value = AXIS_12BIT_CENTER; +int apply_calibration_12bit(int gimbal_value, int min_value, int max_value, int center_value, int deadband_value, int expo_value) { + int calibrated_value = AXIS_12BIT_CENTER; - if (gimbal_value > (center_value + deadband_value)) - { - calibrated_value = constrain(map(gimbal_value, (center_value + deadband_value), max_value, AXIS_12BIT_CENTER, AXIS_12BIT_MAX), AXIS_12BIT_CENTER, AXIS_12BIT_MAX); - } - else if (gimbal_value < (center_value - deadband_value)) - { - calibrated_value = constrain(map(gimbal_value, min_value, (center_value - deadband_value), AXIS_12BIT_MIN, AXIS_12BIT_CENTER), AXIS_12BIT_MIN, AXIS_12BIT_CENTER); - } + if (gimbal_value > (center_value + deadband_value)) { + calibrated_value = constrain(map(gimbal_value, (center_value + deadband_value), max_value, AXIS_12BIT_CENTER, AXIS_12BIT_MAX), AXIS_12BIT_CENTER, AXIS_12BIT_MAX); + } else if (gimbal_value < (center_value - deadband_value)) { + calibrated_value = constrain(map(gimbal_value, min_value, (center_value - deadband_value), AXIS_12BIT_MIN, AXIS_12BIT_CENTER), AXIS_12BIT_MIN, AXIS_12BIT_CENTER); + } - if (expo_value != 0) - { - float joystick_x_float = calibrated_value / float(AXIS_12BIT_MAX); - /* Calculate expo using 9th order polynomial function with 0.5 as center point */ - float joystick_x_exp = expo_value * (0.5 + 256 * pow((joystick_x_float - 0.5), 9)) + (1 - expo_value) * joystick_x_float; - calibrated_value = constrain(int(joystick_x_exp * float(AXIS_12BIT_MAX)), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - } + if (expo_value != 0) { + float joystick_x_float = calibrated_value / float(AXIS_12BIT_MAX); + /* Calculate expo using 9th order polynomial function with 0.5 as center point */ + float joystick_x_exp = expo_value * (0.5 + 256 * pow((joystick_x_float - 0.5), 9)) + (1 - expo_value) * joystick_x_float; + calibrated_value = constrain(int(joystick_x_exp * float(AXIS_12BIT_MAX)), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + } - return calibrated_value; + return calibrated_value; } /** * @brief Process input data from gimbal and buttons */ -void process_input_data() -{ - int analog_x1_gimbal_value = 0; - int analog_y1_gimbal_value = 0; - int analog_x2_gimbal_value = 0; - int analog_y2_gimbal_value = 0; +void process_input_data() { + int analog_x1_gimbal_value = 0; + int analog_y1_gimbal_value = 0; + int analog_x2_gimbal_value = 0; + int analog_y2_gimbal_value = 0; - if (gimbal_mode == GIMBAL_MODE_FRSKY_M10) - { - analog_x1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_y1_gimbal_value = constrain(analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_x2_gimbal_value = constrain(analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_y2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - } - else if (gimbal_mode == GIMBAL_MODE_FRSKY_M7) - { - analog_x1_gimbal_value = constrain(analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_y1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_x2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_y2_gimbal_value = constrain(analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - } + if (gimbal_mode == GIMBAL_MODE_FRSKY_M10) { + analog_x1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y1_gimbal_value = constrain(analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_x2_gimbal_value = constrain(analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + } else if (gimbal_mode == GIMBAL_MODE_FRSKY_M7) { + analog_x1_gimbal_value = constrain(analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_x2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y2_gimbal_value = constrain(analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + } - if (joystick_calibration_mode != CALIBRATION_OFF) - { - calibrate_axis(analog_x1_gimbal_value, analog_y1_gimbal_value, analog_x2_gimbal_value, analog_y2_gimbal_value); - return; - } + if (joystick_calibration_mode != CALIBRATION_OFF) { + calibrate_axis(analog_x1_gimbal_value, analog_y1_gimbal_value, analog_x2_gimbal_value, analog_y2_gimbal_value); + return; + } - joystick_x1_12bit = apply_calibration_12bit(analog_x1_gimbal_value, joystick_x1_12bit_min, joystick_x1_12bit_max, joystick_x1_12bit_center, DEADZONE_X, exp_constant); - joystick_y1_12bit = apply_calibration_12bit(analog_y1_gimbal_value, joystick_y1_12bit_min, joystick_y1_12bit_max, joystick_y1_12bit_center, DEADZONE_Y, 0); - joystick_x2_12bit = apply_calibration_12bit(analog_x2_gimbal_value, joystick_x2_12bit_min, joystick_x2_12bit_max, joystick_x2_12bit_center, DEADZONE_X, exp_constant); - joystick_y2_12bit = apply_calibration_12bit(analog_y2_gimbal_value, joystick_y2_12bit_min, joystick_y2_12bit_max, joystick_y2_12bit_center, DEADZONE_Y, exp_constant); + joystick_x1_12bit = apply_calibration_12bit(analog_x1_gimbal_value, joystick_x1_12bit_min, joystick_x1_12bit_max, joystick_x1_12bit_center, DEADZONE_X, exp_constant); + joystick_y1_12bit = apply_calibration_12bit(analog_y1_gimbal_value, joystick_y1_12bit_min, joystick_y1_12bit_max, joystick_y1_12bit_center, DEADZONE_Y, 0); + joystick_x2_12bit = apply_calibration_12bit(analog_x2_gimbal_value, joystick_x2_12bit_min, joystick_x2_12bit_max, joystick_x2_12bit_center, DEADZONE_X, exp_constant); + joystick_y2_12bit = apply_calibration_12bit(analog_y2_gimbal_value, joystick_y2_12bit_min, joystick_y2_12bit_max, joystick_y2_12bit_center, DEADZONE_Y, exp_constant); - // Check fn mode - fn_mode = 0; - if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) - { - fn_mode = 1; - if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) - { - fn_mode = 2; - } + // Check fn mode + fn_mode = 0; + if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) { + fn_mode = 1; + if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) { + fn_mode = 2; } + } - // Check toggle mode buttons - if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) - { - toggle_button_mode = true; - } - else if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) - { - toggle_button_mode = false; - } + // Check toggle mode buttons + if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) { + toggle_button_mode = true; + } else if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) { + toggle_button_mode = false; + } - // Check toggle arm button - if ((fn_mode == 1) && (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) != toggle_button_arm_previous_value)) - { - if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == false)) - { - toggle_button_arm = true; - } - else if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == true)) - { - toggle_button_arm = false; - } - toggle_button_arm_previous_value = digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN); + // Check toggle arm button + if ((fn_mode == 1) && (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) != toggle_button_arm_previous_value)) { + if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == false)) { + toggle_button_arm = true; + } else if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == true)) { + toggle_button_arm = false; } + toggle_button_arm_previous_value = digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN); + } } -void setup() -{ - /* Init HW */ - status_led.begin(); - status_led.blink(); - button_led_1.begin(); - button_led_2.begin(); +void setup() { + /* Init HW */ + status_led.begin(); + status_led.blink(); + button_led_1.begin(); + button_led_2.begin(); - pinMode(BUTTON_FRONT_LEFT_LOWER_PIN, INPUT_PULLUP); - pinMode(BUTTON_FRONT_LEFT_UPPER_PIN, INPUT_PULLUP); - pinMode(BUTTON_FRONT_RIGHT_LOWER_PIN, INPUT_PULLUP); - pinMode(BUTTON_FRONT_RIGHT_UPPER_PIN, INPUT_PULLUP); - pinMode(BUTTON_TOP_LEFT_LOWER_PIN, INPUT_PULLUP); - pinMode(BUTTON_TOP_RIGHT_LOWER_PIN, INPUT_PULLUP); - pinMode(BUTTON_TOP_LEFT_UPPER_PIN, INPUT_PULLUP); - pinMode(BUTTON_TOP_RIGHT_UPPER_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRONT_LEFT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRONT_LEFT_UPPER_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRONT_RIGHT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRONT_RIGHT_UPPER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_LEFT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_RIGHT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_LEFT_UPPER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_RIGHT_UPPER_PIN, INPUT_PULLUP); - pinMode(GIMBAL_MODE_PIN, INPUT_PULLUP); + pinMode(GIMBAL_MODE_PIN, INPUT_PULLUP); - // Set ADC resolution to 12bit - analogReadResolution(12); - analogReadAveraging(32); - delay(500); + // Set ADC resolution to 12bit + analogReadResolution(12); + analogReadAveraging(32); + delay(500); - // Set analog (lib) resolution to 12bit - analog_x1.setAnalogResolution(4096); - analog_y1.setAnalogResolution(4096); - analog_x2.setAnalogResolution(4096); - analog_y2.setAnalogResolution(4096); + // Set analog (lib) resolution to 12bit + analog_x1.setAnalogResolution(4096); + analog_y1.setAnalogResolution(4096); + analog_x2.setAnalogResolution(4096); + analog_y2.setAnalogResolution(4096); - // Init EEPROM - load_from_eeprom(); + // Init EEPROM + load_from_eeprom(); - // Init Joystick - Joystick.useManualSend(true); + // Init Joystick + Joystick.useManualSend(true); - // Check if calibration mode is enabled - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) - { - joystick_calibration_mode = CALIBRATION_INIT; - } + // Check if calibration mode is enabled + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) { + joystick_calibration_mode = CALIBRATION_INIT; + } - // Check if bootloader mode is enabled - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) - { - button_led_2.on(); - button_led_2.update(); - delay(200); - _reboot_Teensyduino_(); - } + // Check if bootloader mode is enabled + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) { + button_led_2.on(); + button_led_2.update(); + delay(200); + _reboot_Teensyduino_(); + } - // Check what gimbal mode is selected - if (digitalRead(GIMBAL_MODE_PIN) == LOW) - { - gimbal_mode = GIMBAL_MODE_FRSKY_M10; - } + // Check what gimbal mode is selected + if (digitalRead(GIMBAL_MODE_PIN) == LOW) { + gimbal_mode = GIMBAL_MODE_FRSKY_M10; + } - // Init ELRS - elrs.begin(ELRS_PACKET_RATE_500Hz, ELRS_TX_POWER_25mW); + // Init ELRS + elrs.begin(ELRS_PACKET_RATE_500Hz, ELRS_TX_POWER_25mW); } -void loop() -{ - current_timestamp_micros = micros(); +void loop() { + current_timestamp_micros = micros(); - analog_x1.update(); - analog_y1.update(); - analog_x2.update(); - analog_y2.update(); + analog_x1.update(); + analog_y1.update(); + analog_x2.update(); + analog_y2.update(); - /* Process data with 1ms interval*/ - if (current_timestamp_micros >= process_data_timestamp_micros) - { - process_input_data(); - process_data_timestamp_micros = current_timestamp_micros + TIME_US_1ms; + /* Process data with 1ms interval*/ + if (current_timestamp_micros >= process_data_timestamp_micros) { + process_input_data(); + process_data_timestamp_micros = current_timestamp_micros + TIME_US_1ms; + } + + /* Update/Send USB data with 5ms interval*/ + if (current_timestamp_micros >= send_usb_timestamp_micros) { + send_usb_data(); + send_usb_timestamp_micros = current_timestamp_micros + TIME_US_5ms; + } + + /* Update/Send ERLS data with about 1,6ms interval */ + if (current_timestamp_micros >= send_elrs_timestamp_micros) { + send_elrs_data(); + send_elrs_timestamp_micros = current_timestamp_micros + CRSF_TIME_BETWEEN_FRAMES_US; + } + + /* Update indicator with 200ms interval */ + if (current_timestamp_micros >= indicator_timestamp_micros) { + button_led_1.off(); + button_led_2.off(); + + if (joystick_calibration_mode == CALIBRATION_INIT) { + button_led_1.blink(); + button_led_2.blink(); + } else if (joystick_calibration_mode == CALIBRATION_CENTER) { + button_led_1.blink(); + button_led_2.off(); + } else if (joystick_calibration_mode == CALIBRATION_MINMAX) { + button_led_1.off(); + button_led_2.blink(); + } else if ((joystick_x1_12bit != AXIS_12BIT_CENTER) || (joystick_y1_12bit != AXIS_12BIT_MIN) || (joystick_x2_12bit != AXIS_12BIT_CENTER) || (joystick_y2_12bit != AXIS_12BIT_CENTER)) { + button_led_1.on(); + button_led_2.on(); } - /* Update/Send USB data with 5ms interval*/ - if (current_timestamp_micros >= send_usb_timestamp_micros) - { - send_usb_data(); - send_usb_timestamp_micros = current_timestamp_micros + TIME_US_5ms; - } + status_led.update(); + button_led_1.update(); + button_led_2.update(); - /* Update/Send ERLS data with about 1,6ms interval */ - if (current_timestamp_micros >= send_elrs_timestamp_micros) - { - send_elrs_data(); - send_elrs_timestamp_micros = current_timestamp_micros + CRSF_TIME_BETWEEN_FRAMES_US; - } - - /* Update indicator with 200ms interval */ - if (current_timestamp_micros >= indicator_timestamp_micros) - { - button_led_1.off(); - button_led_2.off(); - - if (joystick_calibration_mode == CALIBRATION_INIT) - { - button_led_1.blink(); - button_led_2.blink(); - } - else if (joystick_calibration_mode == CALIBRATION_CENTER) - { - button_led_1.blink(); - button_led_2.off(); - } - else if (joystick_calibration_mode == CALIBRATION_MINMAX) - { - button_led_1.off(); - button_led_2.blink(); - } - else if ((joystick_x1_12bit != AXIS_12BIT_CENTER) || (joystick_y1_12bit != AXIS_12BIT_MIN) || - (joystick_x2_12bit != AXIS_12BIT_CENTER) || (joystick_y2_12bit != AXIS_12BIT_CENTER)) - { - button_led_1.on(); - button_led_2.on(); - } - - status_led.update(); - button_led_1.update(); - button_led_2.update(); - - indicator_timestamp_micros = current_timestamp_micros + TIME_US_200ms; - } + indicator_timestamp_micros = current_timestamp_micros + TIME_US_200ms; + } } From 8091cdc4a43f694d4461c2e263b059005aa852cf Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sat, 27 May 2023 23:33:19 +0000 Subject: [PATCH 14/29] Untracked compile_commands.json --- .gitignore | 1 + firmware/compile_commands.json | 422 --------------------------------- 2 files changed, 1 insertion(+), 422 deletions(-) delete mode 100644 firmware/compile_commands.json diff --git a/.gitignore b/.gitignore index 7f6dc73..841477f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ firmware/.cache/clangd/index +firmware/compile_commands.json diff --git a/firmware/compile_commands.json b/firmware/compile_commands.json deleted file mode 100644 index 3257583..0000000 --- a/firmware/compile_commands.json +++ /dev/null @@ -1,422 +0,0 @@ -[ - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/AudioStream.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/AudioStream.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/AudioStream.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/AudioStream.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/CrashReport.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/CrashReport.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/CrashReport.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/CrashReport.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/DMAChannel.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/DMAChannel.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/DMAChannel.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/DMAChannel.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/EventResponder.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/EventResponder.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/EventResponder.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/EventResponder.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial1.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial1.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial1.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial1.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial2.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial2.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial2.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial2.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial3.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial3.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial3.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial3.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial4.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial4.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial4.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial4.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial5.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial5.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial5.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial5.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/HardwareSerial6.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial6.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial6.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/HardwareSerial6.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/IPAddress.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/IPAddress.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/IPAddress.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/IPAddress.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/IntervalTimer.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/IntervalTimer.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/IntervalTimer.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/IntervalTimer.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/Print.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Print.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Print.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/Print.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/Stream.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Stream.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Stream.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/Stream.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/Time.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Time.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Time.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/Time.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/Tone.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Tone.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/Tone.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/Tone.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/WMath.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/WMath.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/WMath.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/WMath.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/WString.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/WString.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/WString.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/WString.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/analog.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/analog.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/analog.c", - "output": ".pio/build/teensylc/FrameworkArduino/analog.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/avr_emulation.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/avr_emulation.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/avr_emulation.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/avr_emulation.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/eeprom.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/eeprom.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/eeprom.c", - "output": ".pio/build/teensylc/FrameworkArduino/eeprom.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/keylayouts.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/keylayouts.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/keylayouts.c", - "output": ".pio/build/teensylc/FrameworkArduino/keylayouts.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/main.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/main.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/main.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/main.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/math_helper.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/math_helper.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/math_helper.c", - "output": ".pio/build/teensylc/FrameworkArduino/math_helper.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -mthumb -mcpu=cortex-m0plus -mno-unaligned-access -x assembler-with-cpp -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 -c -o .pio/build/teensylc/FrameworkArduino/memcpy-armv7m.S.o /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/memcpy-armv7m.S", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/memcpy-armv7m.S", - "output": ".pio/build/teensylc/FrameworkArduino/memcpy-armv7m.S.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -mthumb -mcpu=cortex-m0plus -mno-unaligned-access -x assembler-with-cpp -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 -c -o .pio/build/teensylc/FrameworkArduino/memset.S.o /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/memset.S", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/memset.S", - "output": ".pio/build/teensylc/FrameworkArduino/memset.S.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/mk20dx128.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/mk20dx128.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/mk20dx128.c", - "output": ".pio/build/teensylc/FrameworkArduino/mk20dx128.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/new.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/new.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/new.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/new.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/nonstd.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/nonstd.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/nonstd.c", - "output": ".pio/build/teensylc/FrameworkArduino/nonstd.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/pins_teensy.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/pins_teensy.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/pins_teensy.c", - "output": ".pio/build/teensylc/FrameworkArduino/pins_teensy.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/ser_print.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/ser_print.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/ser_print.c", - "output": ".pio/build/teensylc/FrameworkArduino/ser_print.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial1.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial1.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial1.c", - "output": ".pio/build/teensylc/FrameworkArduino/serial1.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial2.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial2.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial2.c", - "output": ".pio/build/teensylc/FrameworkArduino/serial2.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial3.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial3.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial3.c", - "output": ".pio/build/teensylc/FrameworkArduino/serial3.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial4.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial4.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial4.c", - "output": ".pio/build/teensylc/FrameworkArduino/serial4.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial5.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial5.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial5.c", - "output": ".pio/build/teensylc/FrameworkArduino/serial5.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial6.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial6.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial6.c", - "output": ".pio/build/teensylc/FrameworkArduino/serial6.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/serial6_lpuart.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial6_lpuart.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serial6_lpuart.c", - "output": ".pio/build/teensylc/FrameworkArduino/serial6_lpuart.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/serialEvent.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent1.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent1.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent1.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/serialEvent1.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent2.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent2.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent2.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/serialEvent2.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent3.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent3.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent3.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/serialEvent3.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent4.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent4.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent4.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/serialEvent4.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent5.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent5.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent5.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/serialEvent5.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEvent6.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent6.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEvent6.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/serialEvent6.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEventUSB1.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEventUSB1.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEventUSB1.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/serialEventUSB1.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/serialEventUSB2.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEventUSB2.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/serialEventUSB2.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/serialEventUSB2.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/touch.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/touch.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/touch.c", - "output": ".pio/build/teensylc/FrameworkArduino/touch.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/usb_audio.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_audio.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_audio.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/usb_audio.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_desc.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_desc.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_desc.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_desc.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_dev.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_dev.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_dev.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_dev.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/usb_flightsim.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_flightsim.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_flightsim.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/usb_flightsim.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/usb_inst.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_inst.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_inst.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/usb_inst.cpp.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_joystick.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_joystick.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_joystick.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_joystick.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_keyboard.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_keyboard.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_keyboard.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_keyboard.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_mem.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mem.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mem.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_mem.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_midi.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_midi.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_midi.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_midi.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_mouse.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mouse.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mouse.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_mouse.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_mtp.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mtp.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_mtp.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_mtp.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_rawhid.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_rawhid.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_rawhid.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_rawhid.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_seremu.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_seremu.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_seremu.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_seremu.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_serial.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_serial.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_serial2.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial2.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial2.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_serial2.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_serial3.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial3.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_serial3.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_serial3.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/teensylc/FrameworkArduino/usb_touch.c.o -c -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_touch.c", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_touch.c", - "output": ".pio/build/teensylc/FrameworkArduino/usb_touch.c.o" - }, - { - "command": "/home/cm/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/teensylc/FrameworkArduino/yield.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/yield.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3/yield.cpp", - "output": ".pio/build/teensylc/FrameworkArduino/yield.cpp.o" - }, - { - "command": "arm-none-eabi-g++ -o .pio/build/teensylc/lib155/ResponsiveAnalogRead/ResponsiveAnalogRead.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/libraries/ResponsiveAnalogRead/src -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/libraries/ResponsiveAnalogRead/src/ResponsiveAnalogRead.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/libraries/ResponsiveAnalogRead/src/ResponsiveAnalogRead.cpp", - "output": ".pio/build/teensylc/lib155/ResponsiveAnalogRead/ResponsiveAnalogRead.cpp.o" - }, - { - "command": "arm-none-eabi-g++ -o .pio/build/teensylc/libab5/EEPROM/EEPROM.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -I/home/cm/.platformio/packages/framework-arduinoteensy/libraries/EEPROM -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 /home/cm/.platformio/packages/framework-arduinoteensy/libraries/EEPROM/EEPROM.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "/home/cm/.platformio/packages/framework-arduinoteensy/libraries/EEPROM/EEPROM.cpp", - "output": ".pio/build/teensylc/libab5/EEPROM/EEPROM.cpp.o" - }, - { - "command": "arm-none-eabi-g++ -o .pio/build/teensylc/src/cmdr_joystick.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -w -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m0plus -nostdlib -fsingle-precision-constant -Os --specs=nano.specs -mno-unaligned-access -fsingle-precision-constant -DPLATFORMIO=60107 -D__MKL26Z64__ -DARDUINO_TEENSYLC -DUSB_HID -DLAYOUT_SWEDISH -DARDUINO=10805 -DTEENSYDUINO=157 -DCORE_TEENSY -DF_CPU=48000000L -DLAYOUT_US_ENGLISH -Iinclude -Isrc -I/home/cm/.platformio/packages/framework-arduinoteensy/libraries/EEPROM -I/home/cm/.platformio/packages/framework-arduinoteensy/libraries/ResponsiveAnalogRead/src -I/home/cm/.platformio/packages/framework-arduinoteensy/cores/teensy3 src/cmdr_joystick.cpp", - "directory": "/home/cm/projects/cmdr-joystick/firmware", - "file": "src/cmdr_joystick.cpp", - "output": ".pio/build/teensylc/src/cmdr_joystick.cpp.o" - } -] From b4ea94ab9431d571a417b4212a043e1ed428f088 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 29 May 2023 23:42:04 +0200 Subject: [PATCH 15/29] Updated makefile --- firmware/Makefile | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/firmware/Makefile b/firmware/Makefile index 21753a6..ac1d088 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -3,17 +3,11 @@ #PATH := /usr/local/bin:$(PATH) all: - pio run - -upload: - pio run --target upload + pio run && pio run -t compiledb clean: - pio run --target clean + pio run --t clean -program: - pio run --target program - -db: - pio run -t compiledb +upload: + pio run --t upload From 785cf274ba1621984f1bf3a7c250ee8dbdac8797 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 29 May 2023 23:45:09 +0200 Subject: [PATCH 16/29] Code cleanup --- firmware/src/ElrsTx.cpp | 175 ++++---- firmware/src/ElrsTx.h | 57 +-- firmware/src/IndicatorLed.cpp | 52 +-- firmware/src/IndicatorLed.h | 25 +- firmware/src/cmdr_joystick.cpp | 777 ++++++++++++++++++--------------- 5 files changed, 583 insertions(+), 503 deletions(-) diff --git a/firmware/src/ElrsTx.cpp b/firmware/src/ElrsTx.cpp index cda6ba8..a54e858 100644 --- a/firmware/src/ElrsTx.cpp +++ b/firmware/src/ElrsTx.cpp @@ -34,18 +34,21 @@ * * @param serial The serial port to use */ -ElrsTx::ElrsTx(HardwareSerial &serial) : _serial(serial) {} +ElrsTx::ElrsTx(HardwareSerial &serial) : _serial(serial) +{ +} /** * @brief Initialize the ELRS transmitter */ -void ElrsTx::begin(int packet_rate, int tx_power) { - const int ELRS_SERIAL_BAUDRATE = 400000; +void ElrsTx::begin(int packet_rate, int tx_power) +{ + const int ELRS_SERIAL_BAUDRATE = 400000; - _serial.begin(ELRS_SERIAL_BAUDRATE); + _serial.begin(ELRS_SERIAL_BAUDRATE); - _packet_rate = packet_rate; - _tx_power = tx_power; + _packet_rate = packet_rate; + _tx_power = tx_power; } /** @@ -55,12 +58,14 @@ void ElrsTx::begin(int packet_rate, int tx_power) { * @param len The length of the packet * @return The CRC8 of the packet */ -uint8_t ElrsTx::calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) { - uint8_t crc = 0; - for (uint8_t i = 0; i < len; i++) { - crc = CRSF_CRC8TAB[crc ^ *ptr++]; - } - return crc; +uint8_t ElrsTx::calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) +{ + uint8_t crc = 0; + for (uint8_t i = 0; i < len; i++) + { + crc = CRSF_CRC8TAB[crc ^ *ptr++]; + } + return crc; } /** @@ -76,35 +81,36 @@ uint8_t ElrsTx::calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) { * @param packet Resulting packet * @param channels Channel data */ -void ElrsTx::prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) { - const int CRSF_TYPE_CHANNELS = 0x16; +void ElrsTx::prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) +{ + const int CRSF_TYPE_CHANNELS = 0x16; - packet[0] = ELRS_ADDRESS; - packet[1] = 24; - packet[2] = CRSF_TYPE_CHANNELS; - packet[3] = (uint8_t)(channels[0] & 0x07FF); - packet[4] = (uint8_t)((channels[0] & 0x07FF) >> 8 | (channels[1] & 0x07FF) << 3); - packet[5] = (uint8_t)((channels[1] & 0x07FF) >> 5 | (channels[2] & 0x07FF) << 6); - packet[6] = (uint8_t)((channels[2] & 0x07FF) >> 2); - packet[7] = (uint8_t)((channels[2] & 0x07FF) >> 10 | (channels[3] & 0x07FF) << 1); - packet[8] = (uint8_t)((channels[3] & 0x07FF) >> 7 | (channels[4] & 0x07FF) << 4); - packet[9] = (uint8_t)((channels[4] & 0x07FF) >> 4 | (channels[5] & 0x07FF) << 7); - packet[10] = (uint8_t)((channels[5] & 0x07FF) >> 1); - packet[11] = (uint8_t)((channels[5] & 0x07FF) >> 9 | (channels[6] & 0x07FF) << 2); - packet[12] = (uint8_t)((channels[6] & 0x07FF) >> 6 | (channels[7] & 0x07FF) << 5); - packet[13] = (uint8_t)((channels[7] & 0x07FF) >> 3); - packet[14] = (uint8_t)((channels[8] & 0x07FF)); - packet[15] = (uint8_t)((channels[8] & 0x07FF) >> 8 | (channels[9] & 0x07FF) << 3); - packet[16] = (uint8_t)((channels[9] & 0x07FF) >> 5 | (channels[10] & 0x07FF) << 6); - packet[17] = (uint8_t)((channels[10] & 0x07FF) >> 2); - packet[18] = (uint8_t)((channels[10] & 0x07FF) >> 10 | (channels[11] & 0x07FF) << 1); - packet[19] = (uint8_t)((channels[11] & 0x07FF) >> 7 | (channels[12] & 0x07FF) << 4); - packet[20] = (uint8_t)((channels[12] & 0x07FF) >> 4 | (channels[13] & 0x07FF) << 7); - packet[21] = (uint8_t)((channels[13] & 0x07FF) >> 1); - packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2); - packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5); - packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3); - packet[25] = calculate_crsf_crc8(&packet[2], packet[1] - 1); + packet[0] = ELRS_ADDRESS; + packet[1] = 24; + packet[2] = CRSF_TYPE_CHANNELS; + packet[3] = (uint8_t)(channels[0] & 0x07FF); + packet[4] = (uint8_t)((channels[0] & 0x07FF) >> 8 | (channels[1] & 0x07FF) << 3); + packet[5] = (uint8_t)((channels[1] & 0x07FF) >> 5 | (channels[2] & 0x07FF) << 6); + packet[6] = (uint8_t)((channels[2] & 0x07FF) >> 2); + packet[7] = (uint8_t)((channels[2] & 0x07FF) >> 10 | (channels[3] & 0x07FF) << 1); + packet[8] = (uint8_t)((channels[3] & 0x07FF) >> 7 | (channels[4] & 0x07FF) << 4); + packet[9] = (uint8_t)((channels[4] & 0x07FF) >> 4 | (channels[5] & 0x07FF) << 7); + packet[10] = (uint8_t)((channels[5] & 0x07FF) >> 1); + packet[11] = (uint8_t)((channels[5] & 0x07FF) >> 9 | (channels[6] & 0x07FF) << 2); + packet[12] = (uint8_t)((channels[6] & 0x07FF) >> 6 | (channels[7] & 0x07FF) << 5); + packet[13] = (uint8_t)((channels[7] & 0x07FF) >> 3); + packet[14] = (uint8_t)((channels[8] & 0x07FF)); + packet[15] = (uint8_t)((channels[8] & 0x07FF) >> 8 | (channels[9] & 0x07FF) << 3); + packet[16] = (uint8_t)((channels[9] & 0x07FF) >> 5 | (channels[10] & 0x07FF) << 6); + packet[17] = (uint8_t)((channels[10] & 0x07FF) >> 2); + packet[18] = (uint8_t)((channels[10] & 0x07FF) >> 10 | (channels[11] & 0x07FF) << 1); + packet[19] = (uint8_t)((channels[11] & 0x07FF) >> 7 | (channels[12] & 0x07FF) << 4); + packet[20] = (uint8_t)((channels[12] & 0x07FF) >> 4 | (channels[13] & 0x07FF) << 7); + packet[21] = (uint8_t)((channels[13] & 0x07FF) >> 1); + packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2); + packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5); + packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3); + packet[25] = calculate_crsf_crc8(&packet[2], packet[1] - 1); } /** @@ -132,18 +138,19 @@ void ElrsTx::prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) { * @param command Command to be sent * @param value Value to be sent */ -void ElrsTx::prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) { - const int ELRS_ADDR_RADIO = 0xEA; - const int ELRS_TYPE_SETTINGS_WRITE = 0x2D; +void ElrsTx::prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) +{ + const int ELRS_ADDR_RADIO = 0xEA; + const int ELRS_TYPE_SETTINGS_WRITE = 0x2D; - packet_cmd[0] = ELRS_ADDRESS; - packet_cmd[1] = 6; - packet_cmd[2] = ELRS_TYPE_SETTINGS_WRITE; - packet_cmd[3] = ELRS_ADDRESS; - packet_cmd[4] = ELRS_ADDR_RADIO; - packet_cmd[5] = command; - packet_cmd[6] = value; - packet_cmd[7] = calculate_crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); + packet_cmd[0] = ELRS_ADDRESS; + packet_cmd[1] = 6; + packet_cmd[2] = ELRS_TYPE_SETTINGS_WRITE; + packet_cmd[3] = ELRS_ADDRESS; + packet_cmd[4] = ELRS_ADDR_RADIO; + packet_cmd[5] = command; + packet_cmd[6] = value; + packet_cmd[7] = calculate_crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); } /** @@ -152,38 +159,50 @@ void ElrsTx::prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint * @param value Value (0-2048) to be set * @param channel Channel (0-11) to be set */ -void ElrsTx::set_data(int16_t value, uint8_t channel) { elrs_channels[channel] = value; } +void ElrsTx::set_data(int16_t value, uint8_t channel) +{ + elrs_channels[channel] = value; +} /** * @brief Send data to ERLS TX. This function should be called within the main loop with a 1.6ms interval */ -void ElrsTx::send_data() { - const int ELRS_PKT_RATE_COMMAND = 0x01; - const int ELRS_POWER_COMMAND = 0x06; +void ElrsTx::send_data() +{ + const int ELRS_PKT_RATE_COMMAND = 0x01; + const int ELRS_POWER_COMMAND = 0x06; - if (elrs_init_done == true) { - prepare_crsf_data_packet(crsf_packet, elrs_channels); - _serial.write(crsf_packet, CRSF_PACKET_SIZE); - } else { - // Setting up initial communication link between ERLS TX and Teensy (give ERLS TX time to auto detect Teensy) - if (elrs_init_counter < 500) { - prepare_crsf_data_packet(crsf_packet, elrs_channels); - _serial.write(crsf_packet, CRSF_PACKET_SIZE); - elrs_init_counter++; + if (elrs_init_done == true) + { + prepare_crsf_data_packet(crsf_packet, elrs_channels); + _serial.write(crsf_packet, CRSF_PACKET_SIZE); } - // Send command to update TX packet rate - else if (elrs_init_counter < 505) { - prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, _packet_rate); - _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); - elrs_init_counter++; + else + { + // Setting up initial communication link between ERLS TX and Teensy (give ERLS TX time to auto detect Teensy) + if (elrs_init_counter < 500) + { + prepare_crsf_data_packet(crsf_packet, elrs_channels); + _serial.write(crsf_packet, CRSF_PACKET_SIZE); + elrs_init_counter++; + } + // Send command to update TX packet rate + else if (elrs_init_counter < 505) + { + prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, _packet_rate); + _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + elrs_init_counter++; + } + // Send command to update TX power + else if (elrs_init_counter < 510) + { + prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, _tx_power); + _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); + elrs_init_counter++; + } + else + { + elrs_init_done = true; + } } - // Send command to update TX power - else if (elrs_init_counter < 510) { - prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, _tx_power); - _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); - elrs_init_counter++; - } else { - elrs_init_done = true; - } - } } diff --git a/firmware/src/ElrsTx.h b/firmware/src/ElrsTx.h index c7b53c8..f8053a8 100644 --- a/firmware/src/ElrsTx.h +++ b/firmware/src/ElrsTx.h @@ -70,40 +70,41 @@ const int ELRS_TX_POWER_250mW = 3; const int ELRS_TX_POWER_500mW = 4; const int ELRS_TX_POWER_1000mW = 5; -class ElrsTx { -public: - ElrsTx(HardwareSerial &serial); +class ElrsTx +{ + public: + ElrsTx(HardwareSerial &serial); - void set_data(int16_t value, uint8_t channel); - void send_data(); - void begin(int packet_rate, int tx_power); + void set_data(int16_t value, uint8_t channel); + void send_data(); + void begin(int packet_rate, int tx_power); -private: - uint8_t crsf_packet[CRSF_PACKET_SIZE]; - uint8_t crsf_cmd_packet[CRSF_CMD_PACKET_SIZE]; - int16_t elrs_channels[CRSF_MAX_CHANNEL]; + private: + uint8_t crsf_packet[CRSF_PACKET_SIZE]; + uint8_t crsf_cmd_packet[CRSF_CMD_PACKET_SIZE]; + int16_t elrs_channels[CRSF_MAX_CHANNEL]; - bool elrs_init_done = false; - int elrs_init_counter = 0; + bool elrs_init_done = false; + int elrs_init_counter = 0; - HardwareSerial &_serial; - int _packet_rate; - int _tx_power; + HardwareSerial &_serial; + int _packet_rate; + int _tx_power; - // crc implementation from CRSF protocol document rev7 - const uint8_t CRSF_CRC8TAB[256] = { - 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, - 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, - 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, - 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, - 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, - 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, - 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, - 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9}; + // crc implementation from CRSF protocol document rev7 + const uint8_t CRSF_CRC8TAB[256] = { + 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, + 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, + 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, + 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, + 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, + 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, + 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, + 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9}; - uint8_t calculate_crsf_crc8(const uint8_t *ptr, uint8_t len); - void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]); - void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value); + uint8_t calculate_crsf_crc8(const uint8_t *ptr, uint8_t len); + void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]); + void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value); }; #endif diff --git a/firmware/src/IndicatorLed.cpp b/firmware/src/IndicatorLed.cpp index 34774bf..05a40c0 100644 --- a/firmware/src/IndicatorLed.cpp +++ b/firmware/src/IndicatorLed.cpp @@ -36,7 +36,7 @@ */ IndicatorLed::IndicatorLed(int pin) { - _pin = pin; + _pin = pin; } /** @@ -44,8 +44,8 @@ IndicatorLed::IndicatorLed(int pin) */ void IndicatorLed::begin() { - pinMode(_pin, OUTPUT); - digitalWrite(_pin, LOW); + pinMode(_pin, OUTPUT); + digitalWrite(_pin, LOW); } /** @@ -53,7 +53,7 @@ void IndicatorLed::begin() */ void IndicatorLed::on() { - led_mode = LED_ON; + led_mode = LED_ON; } /** @@ -61,7 +61,7 @@ void IndicatorLed::on() */ void IndicatorLed::off() { - led_mode = LED_OFF; + led_mode = LED_OFF; } /** @@ -69,7 +69,7 @@ void IndicatorLed::off() */ void IndicatorLed::blink() { - led_mode = LED_BLINK; + led_mode = LED_BLINK; } /** @@ -78,24 +78,24 @@ void IndicatorLed::blink() void IndicatorLed::update() { - if (led_mode == LED_BLINK && current_state == LED_OFF) - { - digitalWrite(_pin, HIGH); - current_state = LED_ON; - } - else if (led_mode == LED_BLINK && current_state == LED_ON) - { - digitalWrite(_pin, LOW); - current_state = LED_OFF; - } - else if (led_mode == LED_ON) - { - digitalWrite(_pin, HIGH); - current_state = LED_ON; - } - else - { - digitalWrite(_pin, LOW); - current_state = LED_OFF; - } + if (led_mode == LED_BLINK && current_state == LED_OFF) + { + digitalWrite(_pin, HIGH); + current_state = LED_ON; + } + else if (led_mode == LED_BLINK && current_state == LED_ON) + { + digitalWrite(_pin, LOW); + current_state = LED_OFF; + } + else if (led_mode == LED_ON) + { + digitalWrite(_pin, HIGH); + current_state = LED_ON; + } + else + { + digitalWrite(_pin, LOW); + current_state = LED_OFF; + } } diff --git a/firmware/src/IndicatorLed.h b/firmware/src/IndicatorLed.h index 4d7b3a4..a25a6fc 100644 --- a/firmware/src/IndicatorLed.h +++ b/firmware/src/IndicatorLed.h @@ -36,19 +36,20 @@ const int LED_OFF = 0; const int LED_ON = 1; const int LED_BLINK = 2; -class IndicatorLed { -public: - IndicatorLed(int pin); - void begin(); - void on(); - void off(); - void blink(); - void update(); +class IndicatorLed +{ + public: + IndicatorLed(int pin); + void begin(); + void on(); + void off(); + void blink(); + void update(); -private: - int _pin; - int led_mode = LED_OFF; - int current_state = LED_OFF; + private: + int _pin; + int led_mode = LED_OFF; + int current_state = LED_OFF; }; #endif diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index 67a2acf..77726e4 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -78,32 +78,33 @@ const int DEADZONE_X = 50; const int DEADZONE_Y = 50; const int JOYSTICK_HAT_CENTER = -1; -enum EEPROM_ADR { - MAX_X1_ADR_HIGH, - MAX_X1_ADR_LOW, - MIN_X1_ADR_HIGH, - MIN_X1_ADR_LOW, - CNT_X1_ADR_HIGH, - CNT_X1_ADR_LOW, - MAX_Y1_ADR_HIGH, - MAX_Y1_ADR_LOW, - MIN_Y1_ADR_HIGH, - MIN_Y1_ADR_LOW, - CNT_Y1_ADR_HIGH, - CNT_Y1_ADR_LOW, - MAX_X2_ADR_HIGH, - MAX_X2_ADR_LOW, - MIN_X2_ADR_HIGH, - MIN_X2_ADR_LOW, - CNT_X2_ADR_HIGH, - CNT_X2_ADR_LOW, - MAX_Y2_ADR_HIGH, - MAX_Y2_ADR_LOW, - MIN_Y2_ADR_HIGH, - MIN_Y2_ADR_LOW, - CNT_Y2_ADR_HIGH, - CNT_Y2_ADR_LOW, - EEPROM_ADR_NBR_OF_BYTES +enum EEPROM_ADR +{ + MAX_X1_ADR_HIGH, + MAX_X1_ADR_LOW, + MIN_X1_ADR_HIGH, + MIN_X1_ADR_LOW, + CNT_X1_ADR_HIGH, + CNT_X1_ADR_LOW, + MAX_Y1_ADR_HIGH, + MAX_Y1_ADR_LOW, + MIN_Y1_ADR_HIGH, + MIN_Y1_ADR_LOW, + CNT_Y1_ADR_HIGH, + CNT_Y1_ADR_LOW, + MAX_X2_ADR_HIGH, + MAX_X2_ADR_LOW, + MIN_X2_ADR_HIGH, + MIN_X2_ADR_LOW, + CNT_X2_ADR_HIGH, + CNT_X2_ADR_LOW, + MAX_Y2_ADR_HIGH, + MAX_Y2_ADR_LOW, + MIN_Y2_ADR_HIGH, + MIN_Y2_ADR_LOW, + CNT_Y2_ADR_HIGH, + CNT_Y2_ADR_LOW, + EEPROM_ADR_NBR_OF_BYTES }; int joystick_counter = 0; @@ -144,67 +145,69 @@ int joystick_calibration_mode = CALIBRATION_OFF; /** * @brief Save calibration data to EEPROM */ -void save_to_eeprom() { - EEPROM.write(MAX_X1_ADR_LOW, joystick_x1_12bit_max); - EEPROM.write(MAX_X1_ADR_HIGH, joystick_x1_12bit_max >> 8); - EEPROM.write(MIN_X1_ADR_LOW, joystick_x1_12bit_min); - EEPROM.write(MIN_X1_ADR_HIGH, joystick_x1_12bit_min >> 8); - EEPROM.write(CNT_X1_ADR_LOW, joystick_x1_12bit_center); - EEPROM.write(CNT_X1_ADR_HIGH, joystick_x1_12bit_center >> 8); +void save_to_eeprom() +{ + EEPROM.write(MAX_X1_ADR_LOW, joystick_x1_12bit_max); + EEPROM.write(MAX_X1_ADR_HIGH, joystick_x1_12bit_max >> 8); + EEPROM.write(MIN_X1_ADR_LOW, joystick_x1_12bit_min); + EEPROM.write(MIN_X1_ADR_HIGH, joystick_x1_12bit_min >> 8); + EEPROM.write(CNT_X1_ADR_LOW, joystick_x1_12bit_center); + EEPROM.write(CNT_X1_ADR_HIGH, joystick_x1_12bit_center >> 8); - EEPROM.write(MAX_Y1_ADR_LOW, joystick_y1_12bit_max); - EEPROM.write(MAX_Y1_ADR_HIGH, joystick_y1_12bit_max >> 8); - EEPROM.write(MIN_Y1_ADR_LOW, joystick_y1_12bit_min); - EEPROM.write(MIN_Y1_ADR_HIGH, joystick_y1_12bit_min >> 8); - EEPROM.write(CNT_Y1_ADR_LOW, joystick_y1_12bit_center); - EEPROM.write(CNT_Y1_ADR_HIGH, joystick_y1_12bit_center >> 8); + EEPROM.write(MAX_Y1_ADR_LOW, joystick_y1_12bit_max); + EEPROM.write(MAX_Y1_ADR_HIGH, joystick_y1_12bit_max >> 8); + EEPROM.write(MIN_Y1_ADR_LOW, joystick_y1_12bit_min); + EEPROM.write(MIN_Y1_ADR_HIGH, joystick_y1_12bit_min >> 8); + EEPROM.write(CNT_Y1_ADR_LOW, joystick_y1_12bit_center); + EEPROM.write(CNT_Y1_ADR_HIGH, joystick_y1_12bit_center >> 8); - EEPROM.write(MAX_X2_ADR_LOW, joystick_x2_12bit_max); - EEPROM.write(MAX_X2_ADR_HIGH, joystick_x2_12bit_max >> 8); - EEPROM.write(MIN_X2_ADR_LOW, joystick_x2_12bit_min); - EEPROM.write(MIN_X2_ADR_HIGH, joystick_x2_12bit_min >> 8); - EEPROM.write(CNT_X2_ADR_LOW, joystick_x2_12bit_center); - EEPROM.write(CNT_X2_ADR_HIGH, joystick_x2_12bit_center >> 8); + EEPROM.write(MAX_X2_ADR_LOW, joystick_x2_12bit_max); + EEPROM.write(MAX_X2_ADR_HIGH, joystick_x2_12bit_max >> 8); + EEPROM.write(MIN_X2_ADR_LOW, joystick_x2_12bit_min); + EEPROM.write(MIN_X2_ADR_HIGH, joystick_x2_12bit_min >> 8); + EEPROM.write(CNT_X2_ADR_LOW, joystick_x2_12bit_center); + EEPROM.write(CNT_X2_ADR_HIGH, joystick_x2_12bit_center >> 8); - EEPROM.write(MAX_Y2_ADR_LOW, joystick_y2_12bit_max); - EEPROM.write(MAX_Y2_ADR_HIGH, joystick_y2_12bit_max >> 8); - EEPROM.write(MIN_Y2_ADR_LOW, joystick_y2_12bit_min); - EEPROM.write(MIN_Y2_ADR_HIGH, joystick_y2_12bit_min >> 8); - EEPROM.write(CNT_Y2_ADR_LOW, joystick_y2_12bit_center); - EEPROM.write(CNT_Y2_ADR_HIGH, joystick_y2_12bit_center >> 8); + EEPROM.write(MAX_Y2_ADR_LOW, joystick_y2_12bit_max); + EEPROM.write(MAX_Y2_ADR_HIGH, joystick_y2_12bit_max >> 8); + EEPROM.write(MIN_Y2_ADR_LOW, joystick_y2_12bit_min); + EEPROM.write(MIN_Y2_ADR_HIGH, joystick_y2_12bit_min >> 8); + EEPROM.write(CNT_Y2_ADR_LOW, joystick_y2_12bit_center); + EEPROM.write(CNT_Y2_ADR_HIGH, joystick_y2_12bit_center >> 8); } /** * @brief Load calibration data from EEPROM */ -void load_from_eeprom() { - joystick_x1_12bit_max = (EEPROM.read(MAX_X1_ADR_HIGH) << 8); - joystick_x1_12bit_max |= EEPROM.read(MAX_X1_ADR_LOW); - joystick_x1_12bit_min = (EEPROM.read(MIN_X1_ADR_HIGH) << 8); - joystick_x1_12bit_min |= EEPROM.read(MIN_X1_ADR_LOW); - joystick_x1_12bit_center = (EEPROM.read(CNT_X1_ADR_HIGH) << 8); - joystick_x1_12bit_center |= EEPROM.read(CNT_X1_ADR_LOW); +void load_from_eeprom() +{ + joystick_x1_12bit_max = (EEPROM.read(MAX_X1_ADR_HIGH) << 8); + joystick_x1_12bit_max |= EEPROM.read(MAX_X1_ADR_LOW); + joystick_x1_12bit_min = (EEPROM.read(MIN_X1_ADR_HIGH) << 8); + joystick_x1_12bit_min |= EEPROM.read(MIN_X1_ADR_LOW); + joystick_x1_12bit_center = (EEPROM.read(CNT_X1_ADR_HIGH) << 8); + joystick_x1_12bit_center |= EEPROM.read(CNT_X1_ADR_LOW); - joystick_y1_12bit_max = (EEPROM.read(MAX_Y1_ADR_HIGH) << 8); - joystick_y1_12bit_max |= EEPROM.read(MAX_Y1_ADR_LOW); - joystick_y1_12bit_min = (EEPROM.read(MIN_Y1_ADR_HIGH) << 8); - joystick_y1_12bit_min |= EEPROM.read(MIN_Y1_ADR_LOW); - joystick_y1_12bit_center = (EEPROM.read(CNT_Y1_ADR_HIGH) << 8); - joystick_y1_12bit_center |= EEPROM.read(CNT_Y1_ADR_LOW); + joystick_y1_12bit_max = (EEPROM.read(MAX_Y1_ADR_HIGH) << 8); + joystick_y1_12bit_max |= EEPROM.read(MAX_Y1_ADR_LOW); + joystick_y1_12bit_min = (EEPROM.read(MIN_Y1_ADR_HIGH) << 8); + joystick_y1_12bit_min |= EEPROM.read(MIN_Y1_ADR_LOW); + joystick_y1_12bit_center = (EEPROM.read(CNT_Y1_ADR_HIGH) << 8); + joystick_y1_12bit_center |= EEPROM.read(CNT_Y1_ADR_LOW); - joystick_x2_12bit_max = (EEPROM.read(MAX_X2_ADR_HIGH) << 8); - joystick_x2_12bit_max |= EEPROM.read(MAX_X2_ADR_LOW); - joystick_x2_12bit_min = (EEPROM.read(MIN_X2_ADR_HIGH) << 8); - joystick_x2_12bit_min |= EEPROM.read(MIN_X2_ADR_LOW); - joystick_x2_12bit_center = (EEPROM.read(CNT_X2_ADR_HIGH) << 8); - joystick_x2_12bit_center |= EEPROM.read(CNT_X2_ADR_LOW); + joystick_x2_12bit_max = (EEPROM.read(MAX_X2_ADR_HIGH) << 8); + joystick_x2_12bit_max |= EEPROM.read(MAX_X2_ADR_LOW); + joystick_x2_12bit_min = (EEPROM.read(MIN_X2_ADR_HIGH) << 8); + joystick_x2_12bit_min |= EEPROM.read(MIN_X2_ADR_LOW); + joystick_x2_12bit_center = (EEPROM.read(CNT_X2_ADR_HIGH) << 8); + joystick_x2_12bit_center |= EEPROM.read(CNT_X2_ADR_LOW); - joystick_y2_12bit_max = (EEPROM.read(MAX_Y2_ADR_HIGH) << 8); - joystick_y2_12bit_max |= EEPROM.read(MAX_Y2_ADR_LOW); - joystick_y2_12bit_min = (EEPROM.read(MIN_Y2_ADR_HIGH) << 8); - joystick_y2_12bit_min |= EEPROM.read(MIN_Y2_ADR_LOW); - joystick_y2_12bit_center = (EEPROM.read(CNT_Y2_ADR_HIGH) << 8); - joystick_y2_12bit_center |= EEPROM.read(CNT_Y2_ADR_LOW); + joystick_y2_12bit_max = (EEPROM.read(MAX_Y2_ADR_HIGH) << 8); + joystick_y2_12bit_max |= EEPROM.read(MAX_Y2_ADR_LOW); + joystick_y2_12bit_min = (EEPROM.read(MIN_Y2_ADR_HIGH) << 8); + joystick_y2_12bit_min |= EEPROM.read(MIN_Y2_ADR_LOW); + joystick_y2_12bit_center = (EEPROM.read(CNT_Y2_ADR_HIGH) << 8); + joystick_y2_12bit_center |= EEPROM.read(CNT_Y2_ADR_LOW); } /** @@ -215,145 +218,166 @@ void load_from_eeprom() { * @param analog_x2 * @param analog_y2 */ -void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) { - joystick_x1_12bit = AXIS_12BIT_CENTER; - joystick_y1_12bit = AXIS_12BIT_CENTER; - joystick_x2_12bit = AXIS_12BIT_CENTER; - joystick_y2_12bit = AXIS_12BIT_CENTER; +void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) +{ + joystick_x1_12bit = AXIS_12BIT_CENTER; + joystick_y1_12bit = AXIS_12BIT_CENTER; + joystick_x2_12bit = AXIS_12BIT_CENTER; + joystick_y2_12bit = AXIS_12BIT_CENTER; - // Check for calibration mode - if (joystick_calibration_mode == CALIBRATION_INIT) { - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_NOT_PRESSED) { - joystick_calibration_mode = CALIBRATION_CENTER; + // Check for calibration mode + if (joystick_calibration_mode == CALIBRATION_INIT) + { + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_NOT_PRESSED) + { + joystick_calibration_mode = CALIBRATION_CENTER; + } } - } - // Calibrate joystick center values - else if (joystick_calibration_mode == CALIBRATION_CENTER) { - joystick_x1_12bit_center = analog_x1; - joystick_y1_12bit_center = analog_y1; - joystick_x1_12bit_max = joystick_x1_12bit_center; - joystick_x1_12bit_min = joystick_x1_12bit_center; - joystick_y1_12bit_max = joystick_y1_12bit_center; - joystick_y1_12bit_min = joystick_y1_12bit_center; + // Calibrate joystick center values + else if (joystick_calibration_mode == CALIBRATION_CENTER) + { + joystick_x1_12bit_center = analog_x1; + joystick_y1_12bit_center = analog_y1; + joystick_x1_12bit_max = joystick_x1_12bit_center; + joystick_x1_12bit_min = joystick_x1_12bit_center; + joystick_y1_12bit_max = joystick_y1_12bit_center; + joystick_y1_12bit_min = joystick_y1_12bit_center; - joystick_x2_12bit_center = analog_x2; - joystick_y2_12bit_center = analog_y2; - joystick_x2_12bit_max = joystick_x2_12bit_center; - joystick_x2_12bit_min = joystick_x2_12bit_center; - joystick_y2_12bit_max = joystick_y2_12bit_center; - joystick_y2_12bit_min = joystick_y2_12bit_center; + joystick_x2_12bit_center = analog_x2; + joystick_y2_12bit_center = analog_y2; + joystick_x2_12bit_max = joystick_x2_12bit_center; + joystick_x2_12bit_min = joystick_x2_12bit_center; + joystick_y2_12bit_max = joystick_y2_12bit_center; + joystick_y2_12bit_min = joystick_y2_12bit_center; - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) { - joystick_calibration_mode = CALIBRATION_MINMAX; + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) + { + joystick_calibration_mode = CALIBRATION_MINMAX; + } } - } - // Calibrate joystick min/max values - else if (joystick_calibration_mode == CALIBRATION_MINMAX) { - if (analog_x1 > joystick_x1_12bit_max) joystick_x1_12bit_max = analog_x1; - if (analog_x1 < joystick_x1_12bit_min) joystick_x1_12bit_min = analog_x1; - if (analog_y1 > joystick_y1_12bit_max) joystick_y1_12bit_max = analog_y1; - if (analog_y1 < joystick_y1_12bit_min) joystick_y1_12bit_min = analog_y1; - if (analog_x2 > joystick_x2_12bit_max) joystick_x2_12bit_max = analog_x2; - if (analog_x2 < joystick_x2_12bit_min) joystick_x2_12bit_min = analog_x2; - if (analog_y2 > joystick_y2_12bit_max) joystick_y2_12bit_max = analog_y2; - if (analog_y2 < joystick_y2_12bit_min) joystick_y2_12bit_min = analog_y2; + // Calibrate joystick min/max values + else if (joystick_calibration_mode == CALIBRATION_MINMAX) + { + if (analog_x1 > joystick_x1_12bit_max) joystick_x1_12bit_max = analog_x1; + if (analog_x1 < joystick_x1_12bit_min) joystick_x1_12bit_min = analog_x1; + if (analog_y1 > joystick_y1_12bit_max) joystick_y1_12bit_max = analog_y1; + if (analog_y1 < joystick_y1_12bit_min) joystick_y1_12bit_min = analog_y1; + if (analog_x2 > joystick_x2_12bit_max) joystick_x2_12bit_max = analog_x2; + if (analog_x2 < joystick_x2_12bit_min) joystick_x2_12bit_min = analog_x2; + if (analog_y2 > joystick_y2_12bit_max) joystick_y2_12bit_max = analog_y2; + if (analog_y2 < joystick_y2_12bit_min) joystick_y2_12bit_min = analog_y2; - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) { - joystick_calibration_mode = CALIBRATION_OFF; - save_to_eeprom(); + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) + { + joystick_calibration_mode = CALIBRATION_OFF; + save_to_eeprom(); + } } - } } /** * @brief Save joystick calibration values to EEPROM */ -void send_elrs_data() { - // Set ELRS analog channels - elrs.set_data(map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 0); - elrs.set_data(map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 1); - elrs.set_data(map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 2); - elrs.set_data(map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 3); +void send_elrs_data() +{ + // Set ELRS analog channels + elrs.set_data(map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 0); + elrs.set_data(map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 1); + elrs.set_data(map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 2); + elrs.set_data(map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 3); - // Set ELRS digital channels - for (int i = 4; i < CRSF_MAX_CHANNEL; i++) { - elrs.set_data(CRSF_DIGITAL_CHANNEL_MIN, i); - } + // Set ELRS digital channels + for (int i = 4; i < CRSF_MAX_CHANNEL; i++) + { + elrs.set_data(CRSF_DIGITAL_CHANNEL_MIN, i); + } - if (toggle_button_arm) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 4); - if (toggle_button_mode) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 5); - if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 6); - if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 7); - if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 8); + if (toggle_button_arm) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 4); + if (toggle_button_mode) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 5); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 6); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 7); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 8); - // Send ELRS data - elrs.send_data(); + // Send ELRS data + elrs.send_data(); } /** * Send USB data to PC */ -void send_usb_data() { - // Set USB analog channels - int joystick_x1_10bit = map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); - int joystick_y1_10bit = map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); - int joystick_x2_10bit = map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); - int joystick_y2_10bit = map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); +void send_usb_data() +{ + // Set USB analog channels + int joystick_x1_10bit = map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); + int joystick_y1_10bit = map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); + int joystick_x2_10bit = map(joystick_x2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); + int joystick_y2_10bit = map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); - Joystick.Zrotate(joystick_x1_10bit); - Joystick.Z(joystick_y1_10bit); + Joystick.Zrotate(joystick_x1_10bit); + Joystick.Z(joystick_y1_10bit); - if (fn_mode == 2) { - Joystick.X(AXIS_10BIT_CENTER); - Joystick.Y(AXIS_10BIT_CENTER); - Joystick.sliderRight(joystick_x2_10bit); - Joystick.sliderLeft(joystick_y2_10bit); - } else if (fn_mode == 1) { - Joystick.X(AXIS_10BIT_CENTER); - Joystick.Y(joystick_y2_10bit); - Joystick.sliderRight(joystick_x2_10bit); - Joystick.sliderLeft(AXIS_10BIT_CENTER); - } else { - Joystick.X(joystick_x2_10bit); - Joystick.Y(joystick_y2_10bit); - Joystick.sliderRight(AXIS_10BIT_CENTER); - Joystick.sliderLeft(AXIS_10BIT_CENTER); - } + if (fn_mode == 2) + { + Joystick.X(AXIS_10BIT_CENTER); + Joystick.Y(AXIS_10BIT_CENTER); + Joystick.sliderRight(joystick_x2_10bit); + Joystick.sliderLeft(joystick_y2_10bit); + } + else if (fn_mode == 1) + { + Joystick.X(AXIS_10BIT_CENTER); + Joystick.Y(joystick_y2_10bit); + Joystick.sliderRight(joystick_x2_10bit); + Joystick.sliderLeft(AXIS_10BIT_CENTER); + } + else + { + Joystick.X(joystick_x2_10bit); + Joystick.Y(joystick_y2_10bit); + Joystick.sliderRight(AXIS_10BIT_CENTER); + Joystick.sliderLeft(AXIS_10BIT_CENTER); + } - // Set USB digital channels - for (int i = 1; i < 32; i++) { - Joystick.button(i, 0); - } + // Set USB digital channels + for (int i = 1; i < 32; i++) + { + Joystick.button(i, 0); + } - Joystick.hat(JOYSTICK_HAT_CENTER); + Joystick.hat(JOYSTICK_HAT_CENTER); - if (fn_mode == 2) { - if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(12, 1); - if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(13, 1); - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(14, 1); - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(15, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(16, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(17, 1); - } else if (fn_mode == 1) { - if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(8, 1); - if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(9, 1); - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(10, 1); - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(11, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(1, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(2, 1); - } else { - if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(3, 1); - if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(4, 1); - if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(5, 1); - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(6, 1); - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(7, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(1, 1); - if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(2, 1); - } + if (fn_mode == 2) + { + if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(12, 1); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(13, 1); + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(14, 1); + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(15, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(16, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(17, 1); + } + else if (fn_mode == 1) + { + if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(8, 1); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(9, 1); + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(10, 1); + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(11, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(1, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(2, 1); + } + else + { + if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(3, 1); + if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(4, 1); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(5, 1); + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(6, 1); + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(7, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(1, 1); + if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(2, 1); + } - Joystick.send_now(); + Joystick.send_now(); } /** @@ -366,189 +390,224 @@ void send_usb_data() { * @param deadband_value * @param expo_value */ -int apply_calibration_12bit(int gimbal_value, int min_value, int max_value, int center_value, int deadband_value, int expo_value) { - int calibrated_value = AXIS_12BIT_CENTER; +int apply_calibration_12bit(int gimbal_value, int min_value, int max_value, int center_value, int deadband_value, int expo_value) +{ + int calibrated_value = AXIS_12BIT_CENTER; - if (gimbal_value > (center_value + deadband_value)) { - calibrated_value = constrain(map(gimbal_value, (center_value + deadband_value), max_value, AXIS_12BIT_CENTER, AXIS_12BIT_MAX), AXIS_12BIT_CENTER, AXIS_12BIT_MAX); - } else if (gimbal_value < (center_value - deadband_value)) { - calibrated_value = constrain(map(gimbal_value, min_value, (center_value - deadband_value), AXIS_12BIT_MIN, AXIS_12BIT_CENTER), AXIS_12BIT_MIN, AXIS_12BIT_CENTER); - } + if (gimbal_value > (center_value + deadband_value)) + { + calibrated_value = constrain(map(gimbal_value, (center_value + deadband_value), max_value, AXIS_12BIT_CENTER, AXIS_12BIT_MAX), AXIS_12BIT_CENTER, AXIS_12BIT_MAX); + } + else if (gimbal_value < (center_value - deadband_value)) + { + calibrated_value = constrain(map(gimbal_value, min_value, (center_value - deadband_value), AXIS_12BIT_MIN, AXIS_12BIT_CENTER), AXIS_12BIT_MIN, AXIS_12BIT_CENTER); + } - if (expo_value != 0) { - float joystick_x_float = calibrated_value / float(AXIS_12BIT_MAX); - /* Calculate expo using 9th order polynomial function with 0.5 as center point */ - float joystick_x_exp = expo_value * (0.5 + 256 * pow((joystick_x_float - 0.5), 9)) + (1 - expo_value) * joystick_x_float; - calibrated_value = constrain(int(joystick_x_exp * float(AXIS_12BIT_MAX)), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - } + if (expo_value != 0) + { + float joystick_x_float = calibrated_value / float(AXIS_12BIT_MAX); + /* Calculate expo using 9th order polynomial function with 0.5 as center point */ + float joystick_x_exp = expo_value * (0.5 + 256 * pow((joystick_x_float - 0.5), 9)) + (1 - expo_value) * joystick_x_float; + calibrated_value = constrain(int(joystick_x_exp * float(AXIS_12BIT_MAX)), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + } - return calibrated_value; + return calibrated_value; } /** * @brief Process input data from gimbal and buttons */ -void process_input_data() { - int analog_x1_gimbal_value = 0; - int analog_y1_gimbal_value = 0; - int analog_x2_gimbal_value = 0; - int analog_y2_gimbal_value = 0; +void process_input_data() +{ + int analog_x1_gimbal_value = 0; + int analog_y1_gimbal_value = 0; + int analog_x2_gimbal_value = 0; + int analog_y2_gimbal_value = 0; - if (gimbal_mode == GIMBAL_MODE_FRSKY_M10) { - analog_x1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_y1_gimbal_value = constrain(analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_x2_gimbal_value = constrain(analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_y2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - } else if (gimbal_mode == GIMBAL_MODE_FRSKY_M7) { - analog_x1_gimbal_value = constrain(analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_y1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_x2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - analog_y2_gimbal_value = constrain(analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - } - - if (joystick_calibration_mode != CALIBRATION_OFF) { - calibrate_axis(analog_x1_gimbal_value, analog_y1_gimbal_value, analog_x2_gimbal_value, analog_y2_gimbal_value); - return; - } - - joystick_x1_12bit = apply_calibration_12bit(analog_x1_gimbal_value, joystick_x1_12bit_min, joystick_x1_12bit_max, joystick_x1_12bit_center, DEADZONE_X, exp_constant); - joystick_y1_12bit = apply_calibration_12bit(analog_y1_gimbal_value, joystick_y1_12bit_min, joystick_y1_12bit_max, joystick_y1_12bit_center, DEADZONE_Y, 0); - joystick_x2_12bit = apply_calibration_12bit(analog_x2_gimbal_value, joystick_x2_12bit_min, joystick_x2_12bit_max, joystick_x2_12bit_center, DEADZONE_X, exp_constant); - joystick_y2_12bit = apply_calibration_12bit(analog_y2_gimbal_value, joystick_y2_12bit_min, joystick_y2_12bit_max, joystick_y2_12bit_center, DEADZONE_Y, exp_constant); - - // Check fn mode - fn_mode = 0; - if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) { - fn_mode = 1; - if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) { - fn_mode = 2; + if (gimbal_mode == GIMBAL_MODE_FRSKY_M10) + { + analog_x1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y1_gimbal_value = constrain(analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_x2_gimbal_value = constrain(analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); } - } - - // Check toggle mode buttons - if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) { - toggle_button_mode = true; - } else if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) { - toggle_button_mode = false; - } - - // Check toggle arm button - if ((fn_mode == 1) && (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) != toggle_button_arm_previous_value)) { - if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == false)) { - toggle_button_arm = true; - } else if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == true)) { - toggle_button_arm = false; - } - toggle_button_arm_previous_value = digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN); - } -} - -void setup() { - /* Init HW */ - status_led.begin(); - status_led.blink(); - button_led_1.begin(); - button_led_2.begin(); - - pinMode(BUTTON_FRONT_LEFT_LOWER_PIN, INPUT_PULLUP); - pinMode(BUTTON_FRONT_LEFT_UPPER_PIN, INPUT_PULLUP); - pinMode(BUTTON_FRONT_RIGHT_LOWER_PIN, INPUT_PULLUP); - pinMode(BUTTON_FRONT_RIGHT_UPPER_PIN, INPUT_PULLUP); - pinMode(BUTTON_TOP_LEFT_LOWER_PIN, INPUT_PULLUP); - pinMode(BUTTON_TOP_RIGHT_LOWER_PIN, INPUT_PULLUP); - pinMode(BUTTON_TOP_LEFT_UPPER_PIN, INPUT_PULLUP); - pinMode(BUTTON_TOP_RIGHT_UPPER_PIN, INPUT_PULLUP); - - pinMode(GIMBAL_MODE_PIN, INPUT_PULLUP); - - // Set ADC resolution to 12bit - analogReadResolution(12); - analogReadAveraging(32); - delay(500); - - // Set analog (lib) resolution to 12bit - analog_x1.setAnalogResolution(4096); - analog_y1.setAnalogResolution(4096); - analog_x2.setAnalogResolution(4096); - analog_y2.setAnalogResolution(4096); - - // Init EEPROM - load_from_eeprom(); - - // Init Joystick - Joystick.useManualSend(true); - - // Check if calibration mode is enabled - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) { - joystick_calibration_mode = CALIBRATION_INIT; - } - - // Check if bootloader mode is enabled - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) { - button_led_2.on(); - button_led_2.update(); - delay(200); - _reboot_Teensyduino_(); - } - - // Check what gimbal mode is selected - if (digitalRead(GIMBAL_MODE_PIN) == LOW) { - gimbal_mode = GIMBAL_MODE_FRSKY_M10; - } - - // Init ELRS - elrs.begin(ELRS_PACKET_RATE_500Hz, ELRS_TX_POWER_25mW); -} - -void loop() { - current_timestamp_micros = micros(); - - analog_x1.update(); - analog_y1.update(); - analog_x2.update(); - analog_y2.update(); - - /* Process data with 1ms interval*/ - if (current_timestamp_micros >= process_data_timestamp_micros) { - process_input_data(); - process_data_timestamp_micros = current_timestamp_micros + TIME_US_1ms; - } - - /* Update/Send USB data with 5ms interval*/ - if (current_timestamp_micros >= send_usb_timestamp_micros) { - send_usb_data(); - send_usb_timestamp_micros = current_timestamp_micros + TIME_US_5ms; - } - - /* Update/Send ERLS data with about 1,6ms interval */ - if (current_timestamp_micros >= send_elrs_timestamp_micros) { - send_elrs_data(); - send_elrs_timestamp_micros = current_timestamp_micros + CRSF_TIME_BETWEEN_FRAMES_US; - } - - /* Update indicator with 200ms interval */ - if (current_timestamp_micros >= indicator_timestamp_micros) { - button_led_1.off(); - button_led_2.off(); - - if (joystick_calibration_mode == CALIBRATION_INIT) { - button_led_1.blink(); - button_led_2.blink(); - } else if (joystick_calibration_mode == CALIBRATION_CENTER) { - button_led_1.blink(); - button_led_2.off(); - } else if (joystick_calibration_mode == CALIBRATION_MINMAX) { - button_led_1.off(); - button_led_2.blink(); - } else if ((joystick_x1_12bit != AXIS_12BIT_CENTER) || (joystick_y1_12bit != AXIS_12BIT_MIN) || (joystick_x2_12bit != AXIS_12BIT_CENTER) || (joystick_y2_12bit != AXIS_12BIT_CENTER)) { - button_led_1.on(); - button_led_2.on(); + else if (gimbal_mode == GIMBAL_MODE_FRSKY_M7) + { + analog_x1_gimbal_value = constrain(analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_x2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); + analog_y2_gimbal_value = constrain(analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); } - status_led.update(); - button_led_1.update(); - button_led_2.update(); + if (joystick_calibration_mode != CALIBRATION_OFF) + { + calibrate_axis(analog_x1_gimbal_value, analog_y1_gimbal_value, analog_x2_gimbal_value, analog_y2_gimbal_value); + return; + } - indicator_timestamp_micros = current_timestamp_micros + TIME_US_200ms; - } + joystick_x1_12bit = apply_calibration_12bit(analog_x1_gimbal_value, joystick_x1_12bit_min, joystick_x1_12bit_max, joystick_x1_12bit_center, DEADZONE_X, exp_constant); + joystick_y1_12bit = apply_calibration_12bit(analog_y1_gimbal_value, joystick_y1_12bit_min, joystick_y1_12bit_max, joystick_y1_12bit_center, DEADZONE_Y, 0); + joystick_x2_12bit = apply_calibration_12bit(analog_x2_gimbal_value, joystick_x2_12bit_min, joystick_x2_12bit_max, joystick_x2_12bit_center, DEADZONE_X, exp_constant); + joystick_y2_12bit = apply_calibration_12bit(analog_y2_gimbal_value, joystick_y2_12bit_min, joystick_y2_12bit_max, joystick_y2_12bit_center, DEADZONE_Y, exp_constant); + + // Check fn mode + fn_mode = 0; + if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) + { + fn_mode = 1; + if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) + { + fn_mode = 2; + } + } + + // Check toggle mode buttons + if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) + { + toggle_button_mode = true; + } + else if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) + { + toggle_button_mode = false; + } + + // Check toggle arm button + if ((fn_mode == 1) && (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) != toggle_button_arm_previous_value)) + { + if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == false)) + { + toggle_button_arm = true; + } + else if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == true)) + { + toggle_button_arm = false; + } + toggle_button_arm_previous_value = digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN); + } +} + +void setup() +{ + /* Init HW */ + status_led.begin(); + status_led.blink(); + button_led_1.begin(); + button_led_2.begin(); + + pinMode(BUTTON_FRONT_LEFT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRONT_LEFT_UPPER_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRONT_RIGHT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_FRONT_RIGHT_UPPER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_LEFT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_RIGHT_LOWER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_LEFT_UPPER_PIN, INPUT_PULLUP); + pinMode(BUTTON_TOP_RIGHT_UPPER_PIN, INPUT_PULLUP); + + pinMode(GIMBAL_MODE_PIN, INPUT_PULLUP); + + // Set ADC resolution to 12bit + analogReadResolution(12); + analogReadAveraging(32); + delay(500); + + // Set analog (lib) resolution to 12bit + analog_x1.setAnalogResolution(4096); + analog_y1.setAnalogResolution(4096); + analog_x2.setAnalogResolution(4096); + analog_y2.setAnalogResolution(4096); + + // Init EEPROM + load_from_eeprom(); + + // Init Joystick + Joystick.useManualSend(true); + + // Check if calibration mode is enabled + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) + { + joystick_calibration_mode = CALIBRATION_INIT; + } + + // Check if bootloader mode is enabled + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) + { + button_led_2.on(); + button_led_2.update(); + delay(200); + _reboot_Teensyduino_(); + } + + // Check what gimbal mode is selected + if (digitalRead(GIMBAL_MODE_PIN) == LOW) + { + gimbal_mode = GIMBAL_MODE_FRSKY_M10; + } + + // Init ELRS + elrs.begin(ELRS_PACKET_RATE_500Hz, ELRS_TX_POWER_25mW); +} + +void loop() +{ + current_timestamp_micros = micros(); + + analog_x1.update(); + analog_y1.update(); + analog_x2.update(); + analog_y2.update(); + + /* Process data with 1ms interval*/ + if (current_timestamp_micros >= process_data_timestamp_micros) + { + process_input_data(); + process_data_timestamp_micros = current_timestamp_micros + TIME_US_1ms; + } + + /* Update/Send USB data with 5ms interval*/ + if (current_timestamp_micros >= send_usb_timestamp_micros) + { + send_usb_data(); + send_usb_timestamp_micros = current_timestamp_micros + TIME_US_5ms; + } + + /* Update/Send ERLS data with about 1,6ms interval */ + if (current_timestamp_micros >= send_elrs_timestamp_micros) + { + send_elrs_data(); + send_elrs_timestamp_micros = current_timestamp_micros + CRSF_TIME_BETWEEN_FRAMES_US; + } + + /* Update indicator with 200ms interval */ + if (current_timestamp_micros >= indicator_timestamp_micros) + { + button_led_1.off(); + button_led_2.off(); + + if (joystick_calibration_mode == CALIBRATION_INIT) + { + button_led_1.blink(); + button_led_2.blink(); + } + else if (joystick_calibration_mode == CALIBRATION_CENTER) + { + button_led_1.blink(); + button_led_2.off(); + } + else if (joystick_calibration_mode == CALIBRATION_MINMAX) + { + button_led_1.off(); + button_led_2.blink(); + } + else if ((joystick_x1_12bit != AXIS_12BIT_CENTER) || (joystick_y1_12bit != AXIS_12BIT_MIN) || (joystick_x2_12bit != AXIS_12BIT_CENTER) || (joystick_y2_12bit != AXIS_12BIT_CENTER)) + { + button_led_1.on(); + button_led_2.on(); + } + + status_led.update(); + button_led_1.update(); + button_led_2.update(); + + indicator_timestamp_micros = current_timestamp_micros + TIME_US_200ms; + } } From e8557905d458ebfd0f6fdb86db8d5a847e2dac31 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 30 May 2023 13:01:55 +0200 Subject: [PATCH 17/29] Fixed error in makefile --- firmware/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/Makefile b/firmware/Makefile index ac1d088..5121a38 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -6,8 +6,8 @@ all: pio run && pio run -t compiledb clean: - pio run --t clean + pio run -t clean upload: - pio run --t upload + pio run -t upload From 143b4cfd59a18159f2db7ea6618c04eb1de08ae2 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 30 May 2023 13:02:57 +0200 Subject: [PATCH 18/29] Changed to teensy-cli for flashing --- firmware/platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/platformio.ini b/firmware/platformio.ini index 897596b..f00616c 100644 --- a/firmware/platformio.ini +++ b/firmware/platformio.ini @@ -15,3 +15,4 @@ framework = arduino build_flags = -D USB_HID -D LAYOUT_SWEDISH -w board_build.f_cpu = 48000000L extra_scripts = pre:extra_script.py +upload_protocol = teensy-cli From 248c95cd60e1aef422efeaeff5596d2b45fe32dd Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Sun, 4 Jun 2023 23:31:16 +0200 Subject: [PATCH 19/29] Moved license and logo to bottom --- firmware/.gitignore | 2 ++ firmware/platformio.ini | 2 +- firmware/src/cmdr_joystick.cpp | 63 +++++++++++++++++++--------------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/firmware/.gitignore b/firmware/.gitignore index b9f3806..050b399 100644 --- a/firmware/.gitignore +++ b/firmware/.gitignore @@ -1,2 +1,4 @@ .pio .vscode +.cache +compile_commands.json diff --git a/firmware/platformio.ini b/firmware/platformio.ini index f00616c..b86a206 100644 --- a/firmware/platformio.ini +++ b/firmware/platformio.ini @@ -12,7 +12,7 @@ platform = teensy board = teensylc framework = arduino -build_flags = -D USB_HID -D LAYOUT_SWEDISH -w +build_flags = -Isrc -Ilib -D USB_HID -D LAYOUT_SWEDISH -w board_build.f_cpu = 48000000L extra_scripts = pre:extra_script.py upload_protocol = teensy-cli diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index 77726e4..111937b 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -1,32 +1,9 @@ /* - * ======================================================================================================= - * ------------------------------------------------------------------------------------------------------- - * ---####################-----###########-------###########-----############--############-############-- - * --######################---#############-----#############---- -- - --- - * --###### ##---##### ###-----### #####---------##-------#######------#------------- - * -- -------------- --- ----- --- ----- ---------##-------#------------#------------- - * --#####--------------------#####------####-####------#####---------##-------###########--############-- - * -- -------------------- ------ ------ --------- ------- -- -- - * --#####--------------------#####--------#####--------#####--------------------------------------------- - * -- -------------------- -------- -------- --------------------------------------------- - * --######--------------##---#####---------------------#####---------- CMtec CMDR Joystick RC ----------- - * --##################### ---#####---------------------#####--------------------------------------------- - * ---################### ----#####---------------------#####--------------------------------------------- - * --- ----- --------------------- --------------------------------------------- - * ------------------------------------------------------------------------------------------------------- - * ======================================================================================================= - * - * Copyright 2022 Christoffer Martinsson - * - * CMtec CMDR Joystick RC can be redistributed and/or modified under the terms of the GNU General - * Public License (Version 2), as published by the Free Software Foundation. - * A copy of the license can be found online at www.gnu.o urg/licenses. - * - * CMtec CMDR Joystick RC is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * Joystick based on standard teensy "usb_joystick" library for HID joystick usb data communication. + * Project: CMtec CMDR Joystick RC + * Date: 2023-09-02 + * Author: Christoffer Martinsson + * Email: cm@cmtec.se + * License: Please refer to end of this file for license information */ #include "ElrsTx.h" @@ -611,3 +588,33 @@ void loop() indicator_timestamp_micros = current_timestamp_micros + TIME_US_200ms; } } +/* @License + * ======================================================================================================= + * ------------------------------------------------------------------------------------------------------- + * ---####################-----###########-------###########-----############--############-############-- + * --######################---#############-----#############---- -- - --- + * --###### ##---##### ###-----### #####---------##-------#######------#------------- + * -- -------------- --- ----- --- ----- ---------##-------#------------#------------- + * --#####--------------------#####------####-####------#####---------##-------###########--############-- + * -- -------------------- ------ ------ --------- ------- -- -- + * --#####--------------------#####--------#####--------#####--------------------------------------------- + * -- -------------------- -------- -------- --------------------------------------------- + * --######--------------##---#####---------------------#####--------------------------------------------- + * --##################### ---#####---------------------#####--------------------------------------------- + * ---################### ----#####---------------------#####--------------------------------------------- + * --- ----- --------------------- --------------------------------------------- + * ------------------------------------------------------------------------------------------------------- + * ======================================================================================================= + * + * Copyright 2022 Christoffer Martinsson + * + * CMtec CMDR Joystick RC can be redistributed and/or modified under the terms of the GNU General + * Public License (Version 2), as published by the Free Software Foundation. + * A copy of the license can be found online at www.gnu.o urg/licenses. + * + * CMtec CMDR Joystick RC is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * Joystick based on standard teensy "usb_joystick" library for HID joystick usb data communication. + */ From 8ba920c0d3958db823260e1b9b5f218da960f98b Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 5 Jun 2023 12:59:27 +0200 Subject: [PATCH 20/29] Code cleanup --- firmware/src/cmdr_joystick.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index 111937b..2762295 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -373,11 +373,13 @@ int apply_calibration_12bit(int gimbal_value, int min_value, int max_value, int if (gimbal_value > (center_value + deadband_value)) { - calibrated_value = constrain(map(gimbal_value, (center_value + deadband_value), max_value, AXIS_12BIT_CENTER, AXIS_12BIT_MAX), AXIS_12BIT_CENTER, AXIS_12BIT_MAX); + calibrated_value = constrain(map(gimbal_value, (center_value + deadband_value), max_value, AXIS_12BIT_CENTER, AXIS_12BIT_MAX), + AXIS_12BIT_CENTER, AXIS_12BIT_MAX); } else if (gimbal_value < (center_value - deadband_value)) { - calibrated_value = constrain(map(gimbal_value, min_value, (center_value - deadband_value), AXIS_12BIT_MIN, AXIS_12BIT_CENTER), AXIS_12BIT_MIN, AXIS_12BIT_CENTER); + calibrated_value = constrain(map(gimbal_value, min_value, (center_value - deadband_value), AXIS_12BIT_MIN, AXIS_12BIT_CENTER), + AXIS_12BIT_MIN, AXIS_12BIT_CENTER); } if (expo_value != 0) @@ -422,10 +424,14 @@ void process_input_data() return; } - joystick_x1_12bit = apply_calibration_12bit(analog_x1_gimbal_value, joystick_x1_12bit_min, joystick_x1_12bit_max, joystick_x1_12bit_center, DEADZONE_X, exp_constant); - joystick_y1_12bit = apply_calibration_12bit(analog_y1_gimbal_value, joystick_y1_12bit_min, joystick_y1_12bit_max, joystick_y1_12bit_center, DEADZONE_Y, 0); - joystick_x2_12bit = apply_calibration_12bit(analog_x2_gimbal_value, joystick_x2_12bit_min, joystick_x2_12bit_max, joystick_x2_12bit_center, DEADZONE_X, exp_constant); - joystick_y2_12bit = apply_calibration_12bit(analog_y2_gimbal_value, joystick_y2_12bit_min, joystick_y2_12bit_max, joystick_y2_12bit_center, DEADZONE_Y, exp_constant); + joystick_x1_12bit = apply_calibration_12bit(analog_x1_gimbal_value, joystick_x1_12bit_min, joystick_x1_12bit_max, + joystick_x1_12bit_center, DEADZONE_X, exp_constant); + joystick_y1_12bit = apply_calibration_12bit(analog_y1_gimbal_value, joystick_y1_12bit_min, joystick_y1_12bit_max, + joystick_y1_12bit_center, DEADZONE_Y, 0); + joystick_x2_12bit = apply_calibration_12bit(analog_x2_gimbal_value, joystick_x2_12bit_min, joystick_x2_12bit_max, + joystick_x2_12bit_center, DEADZONE_X, exp_constant); + joystick_y2_12bit = apply_calibration_12bit(analog_y2_gimbal_value, joystick_y2_12bit_min, joystick_y2_12bit_max, + joystick_y2_12bit_center, DEADZONE_Y, exp_constant); // Check fn mode fn_mode = 0; @@ -575,7 +581,8 @@ void loop() button_led_1.off(); button_led_2.blink(); } - else if ((joystick_x1_12bit != AXIS_12BIT_CENTER) || (joystick_y1_12bit != AXIS_12BIT_MIN) || (joystick_x2_12bit != AXIS_12BIT_CENTER) || (joystick_y2_12bit != AXIS_12BIT_CENTER)) + else if ((joystick_x1_12bit != AXIS_12BIT_CENTER) || (joystick_y1_12bit != AXIS_12BIT_MIN) || + (joystick_x2_12bit != AXIS_12BIT_CENTER) || (joystick_y2_12bit != AXIS_12BIT_CENTER)) { button_led_1.on(); button_led_2.on(); From 877c2b98c71ecf6c067c77e85b1c4a1b55f0aa70 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 5 Jun 2023 11:30:02 +0000 Subject: [PATCH 21/29] Add LICENSE --- LICENSE | 339 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 339 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0e5fc00 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + CMDR Joystick + Copyright (C) 2023 Christoffer Martinsson + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. From 3e6a6cc4838a53ade7ffd1e984d2c3d889e5bb96 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 5 Jun 2023 11:30:24 +0000 Subject: [PATCH 22/29] Add CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGELOG diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..6b3126c --- /dev/null +++ b/CHANGELOG @@ -0,0 +1 @@ +v1.0 From fe887a2d62fa248411c260b46bbc13a3185e8f37 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 5 Jun 2023 13:31:34 +0200 Subject: [PATCH 23/29] Code cleanup --- firmware/src/cmdr_joystick.cpp | 39 +++------------------------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index 2762295..eab4a6d 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -3,7 +3,7 @@ * Date: 2023-09-02 * Author: Christoffer Martinsson * Email: cm@cmtec.se - * License: Please refer to end of this file for license information + * License: Please refer to LICENSE file in root folder */ #include "ElrsTx.h" @@ -203,12 +203,9 @@ void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) joystick_y2_12bit = AXIS_12BIT_CENTER; // Check for calibration mode - if (joystick_calibration_mode == CALIBRATION_INIT) + if (joystick_calibration_mode == CALIBRATION_INIT && digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_NOT_PRESSED) { - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_NOT_PRESSED) - { - joystick_calibration_mode = CALIBRATION_CENTER; - } + joystick_calibration_mode = CALIBRATION_CENTER; } // Calibrate joystick center values @@ -595,33 +592,3 @@ void loop() indicator_timestamp_micros = current_timestamp_micros + TIME_US_200ms; } } -/* @License - * ======================================================================================================= - * ------------------------------------------------------------------------------------------------------- - * ---####################-----###########-------###########-----############--############-############-- - * --######################---#############-----#############---- -- - --- - * --###### ##---##### ###-----### #####---------##-------#######------#------------- - * -- -------------- --- ----- --- ----- ---------##-------#------------#------------- - * --#####--------------------#####------####-####------#####---------##-------###########--############-- - * -- -------------------- ------ ------ --------- ------- -- -- - * --#####--------------------#####--------#####--------#####--------------------------------------------- - * -- -------------------- -------- -------- --------------------------------------------- - * --######--------------##---#####---------------------#####--------------------------------------------- - * --##################### ---#####---------------------#####--------------------------------------------- - * ---################### ----#####---------------------#####--------------------------------------------- - * --- ----- --------------------- --------------------------------------------- - * ------------------------------------------------------------------------------------------------------- - * ======================================================================================================= - * - * Copyright 2022 Christoffer Martinsson - * - * CMtec CMDR Joystick RC can be redistributed and/or modified under the terms of the GNU General - * Public License (Version 2), as published by the Free Software Foundation. - * A copy of the license can be found online at www.gnu.o urg/licenses. - * - * CMtec CMDR Joystick RC is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * Joystick based on standard teensy "usb_joystick" library for HID joystick usb data communication. - */ From 985b0d43f3537a070c8f9bdab7f3084a83400d4b Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 6 Jun 2023 16:25:31 +0200 Subject: [PATCH 24/29] Moved library to submodule --- README.md | 91 --------------- firmware/lib/teensy-libc | 1 + firmware/src/ElrsTx.cpp | 208 --------------------------------- firmware/src/ElrsTx.h | 110 ----------------- firmware/src/IndicatorLed.cpp | 101 ---------------- firmware/src/IndicatorLed.h | 55 --------- firmware/src/cmdr_joystick.cpp | 4 +- 7 files changed, 3 insertions(+), 567 deletions(-) create mode 160000 firmware/lib/teensy-libc delete mode 100644 firmware/src/ElrsTx.cpp delete mode 100644 firmware/src/ElrsTx.h delete mode 100644 firmware/src/IndicatorLed.cpp delete mode 100644 firmware/src/IndicatorLed.h diff --git a/README.md b/README.md index 9782323..7faad59 100644 --- a/README.md +++ b/README.md @@ -1,92 +1 @@ # CMDR Joystick - - - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://git.cmtec.se/cm/cmdr-joystick.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://git.cmtec.se/cm/cmdr-joystick/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/firmware/lib/teensy-libc b/firmware/lib/teensy-libc new file mode 160000 index 0000000..6a2b179 --- /dev/null +++ b/firmware/lib/teensy-libc @@ -0,0 +1 @@ +Subproject commit 6a2b179d8f624d69b41a5d30df7b46080a1deec6 diff --git a/firmware/src/ElrsTx.cpp b/firmware/src/ElrsTx.cpp deleted file mode 100644 index a54e858..0000000 --- a/firmware/src/ElrsTx.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* - * ======================================================================================================= - * ------------------------------------------------------------------------------------------------------- - * ---####################-----###########-------###########-----############--############-############-- - * --######################---#############-----#############---- -- - --- - * --###### ##---##### ###-----### #####---------##-------#######------#------------- - * -- -------------- --- ----- --- ----- ---------##-------#------------#------------- - * --#####--------------------#####------####-####------#####---------##-------###########--############-- - * -- -------------------- ------ ------ --------- ------- -- -- - * --#####--------------------#####--------#####--------#####--------------------------------------------- - * -- -------------------- -------- -------- --------------------------------------------- - * --######--------------##---#####---------------------#####---------------- ERLS ----------------------- - * --##################### ---#####---------------------#####--------------------------------------------- - * ---################### ----#####---------------------#####--------------------------------------------- - * --- ----- --------------------- --------------------------------------------- - * ------------------------------------------------------------------------------------------------------- - * ======================================================================================================= - * - * Copyright 2023 Christoffer Martinsson - * - * CMtec ERLS can be redistributed and/or modified under the terms of the GNU General - * Public License (Version 2), as published by the Free Software Foundation. - * A copy of the license can be found online at www.gnu.o urg/licenses. - * - * CMtec ERLS is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - */ - -#include "ElrsTx.h" - -/** - * @brief Construct a new ElrsTx object - * - * @param serial The serial port to use - */ -ElrsTx::ElrsTx(HardwareSerial &serial) : _serial(serial) -{ -} - -/** - * @brief Initialize the ELRS transmitter - */ -void ElrsTx::begin(int packet_rate, int tx_power) -{ - const int ELRS_SERIAL_BAUDRATE = 400000; - - _serial.begin(ELRS_SERIAL_BAUDRATE); - - _packet_rate = packet_rate; - _tx_power = tx_power; -} - -/** - * @brief Calculate the CRC8 of a CRSF packet - * - * @param ptr The packet to be calculated - * @param len The length of the packet - * @return The CRC8 of the packet - */ -uint8_t ElrsTx::calculate_crsf_crc8(const uint8_t *ptr, uint8_t len) -{ - uint8_t crc = 0; - for (uint8_t i = 0; i < len; i++) - { - crc = CRSF_CRC8TAB[crc ^ *ptr++]; - } - return crc; -} - -/** - * @brief Prepare a normal CRSF data packet - * - * packet format: - * 0 - header - * 1 - length - * 2 - type - * 3-24 - data (16 11bit channels in 8bit format) - * 25 - crc - * - * @param packet Resulting packet - * @param channels Channel data - */ -void ElrsTx::prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]) -{ - const int CRSF_TYPE_CHANNELS = 0x16; - - packet[0] = ELRS_ADDRESS; - packet[1] = 24; - packet[2] = CRSF_TYPE_CHANNELS; - packet[3] = (uint8_t)(channels[0] & 0x07FF); - packet[4] = (uint8_t)((channels[0] & 0x07FF) >> 8 | (channels[1] & 0x07FF) << 3); - packet[5] = (uint8_t)((channels[1] & 0x07FF) >> 5 | (channels[2] & 0x07FF) << 6); - packet[6] = (uint8_t)((channels[2] & 0x07FF) >> 2); - packet[7] = (uint8_t)((channels[2] & 0x07FF) >> 10 | (channels[3] & 0x07FF) << 1); - packet[8] = (uint8_t)((channels[3] & 0x07FF) >> 7 | (channels[4] & 0x07FF) << 4); - packet[9] = (uint8_t)((channels[4] & 0x07FF) >> 4 | (channels[5] & 0x07FF) << 7); - packet[10] = (uint8_t)((channels[5] & 0x07FF) >> 1); - packet[11] = (uint8_t)((channels[5] & 0x07FF) >> 9 | (channels[6] & 0x07FF) << 2); - packet[12] = (uint8_t)((channels[6] & 0x07FF) >> 6 | (channels[7] & 0x07FF) << 5); - packet[13] = (uint8_t)((channels[7] & 0x07FF) >> 3); - packet[14] = (uint8_t)((channels[8] & 0x07FF)); - packet[15] = (uint8_t)((channels[8] & 0x07FF) >> 8 | (channels[9] & 0x07FF) << 3); - packet[16] = (uint8_t)((channels[9] & 0x07FF) >> 5 | (channels[10] & 0x07FF) << 6); - packet[17] = (uint8_t)((channels[10] & 0x07FF) >> 2); - packet[18] = (uint8_t)((channels[10] & 0x07FF) >> 10 | (channels[11] & 0x07FF) << 1); - packet[19] = (uint8_t)((channels[11] & 0x07FF) >> 7 | (channels[12] & 0x07FF) << 4); - packet[20] = (uint8_t)((channels[12] & 0x07FF) >> 4 | (channels[13] & 0x07FF) << 7); - packet[21] = (uint8_t)((channels[13] & 0x07FF) >> 1); - packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2); - packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5); - packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3); - packet[25] = calculate_crsf_crc8(&packet[2], packet[1] - 1); -} - -/** - * @brief Prepare CRSF command packet - * - * packet format: - * 0 - header - * 1 - length - * 2 - type - * 3 - address - * 4 - address radio - * 5 - command - * 6 - value - * 7 - crc - * - * command list: - * ELRS_BIND_COMMAND = 0xFF; - * ELRS_WIFI_COMMAND = 0xFE; - * ELRS_TLM_RATIO_COMMAND = 0x02; - * ELRS_SWITCH_MODE_COMMAND = 0x03; - * ELRS_MODEL_MATCH_COMMAND = 0x04; - * ELRS_BLE_JOYSTIC_COMMAND = 17; - * - * @param packet_cmd Resulting packet - * @param command Command to be sent - * @param value Value to be sent - */ -void ElrsTx::prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value) -{ - const int ELRS_ADDR_RADIO = 0xEA; - const int ELRS_TYPE_SETTINGS_WRITE = 0x2D; - - packet_cmd[0] = ELRS_ADDRESS; - packet_cmd[1] = 6; - packet_cmd[2] = ELRS_TYPE_SETTINGS_WRITE; - packet_cmd[3] = ELRS_ADDRESS; - packet_cmd[4] = ELRS_ADDR_RADIO; - packet_cmd[5] = command; - packet_cmd[6] = value; - packet_cmd[7] = calculate_crsf_crc8(&packet_cmd[2], packet_cmd[1] - 1); -} - -/** - * @brief Set ELRS channel data - * - * @param value Value (0-2048) to be set - * @param channel Channel (0-11) to be set - */ -void ElrsTx::set_data(int16_t value, uint8_t channel) -{ - elrs_channels[channel] = value; -} - -/** - * @brief Send data to ERLS TX. This function should be called within the main loop with a 1.6ms interval - */ -void ElrsTx::send_data() -{ - const int ELRS_PKT_RATE_COMMAND = 0x01; - const int ELRS_POWER_COMMAND = 0x06; - - if (elrs_init_done == true) - { - prepare_crsf_data_packet(crsf_packet, elrs_channels); - _serial.write(crsf_packet, CRSF_PACKET_SIZE); - } - else - { - // Setting up initial communication link between ERLS TX and Teensy (give ERLS TX time to auto detect Teensy) - if (elrs_init_counter < 500) - { - prepare_crsf_data_packet(crsf_packet, elrs_channels); - _serial.write(crsf_packet, CRSF_PACKET_SIZE); - elrs_init_counter++; - } - // Send command to update TX packet rate - else if (elrs_init_counter < 505) - { - prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_PKT_RATE_COMMAND, _packet_rate); - _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); - elrs_init_counter++; - } - // Send command to update TX power - else if (elrs_init_counter < 510) - { - prepare_crsf_cmd_packet(crsf_cmd_packet, ELRS_POWER_COMMAND, _tx_power); - _serial.write(crsf_cmd_packet, CRSF_CMD_PACKET_SIZE); - elrs_init_counter++; - } - else - { - elrs_init_done = true; - } - } -} diff --git a/firmware/src/ElrsTx.h b/firmware/src/ElrsTx.h deleted file mode 100644 index f8053a8..0000000 --- a/firmware/src/ElrsTx.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * ======================================================================================================= - * ------------------------------------------------------------------------------------------------------- - * ---####################-----###########-------###########-----############--############-############-- - * --######################---#############-----#############---- -- - --- - * --###### ##---##### ###-----### #####---------##-------#######------#------------- - * -- -------------- --- ----- --- ----- ---------##-------#------------#------------- - * --#####--------------------#####------####-####------#####---------##-------###########--############-- - * -- -------------------- ------ ------ --------- ------- -- -- - * --#####--------------------#####--------#####--------#####--------------------------------------------- - * -- -------------------- -------- -------- --------------------------------------------- - * --######--------------##---#####---------------------#####---------------- ERLS ----------------------- - * --##################### ---#####---------------------#####--------------------------------------------- - * ---################### ----#####---------------------#####--------------------------------------------- - * --- ----- --------------------- --------------------------------------------- - * ------------------------------------------------------------------------------------------------------- - * ======================================================================================================= - * - * Copyright 2023 Christoffer Martinsson - * - * CMtec ERLS can be redistributed and/or modified under the terms of the GNU General - * Public License (Version 2), as published by the Free Software Foundation. - * A copy of the license can be found online at www.gnu.o urg/licenses. - * - * CMtec ERLS is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - */ - -#ifndef ELRSTX_H -#define ELRSTX_H - -#include - -// CRSF -const int CRSF_MAX_CHANNEL = 16; -const int CRSF_TYPE_CHANNELS = 0x16; -const int CRSF_DIGITAL_CHANNEL_MIN = 172; -const int CRSF_DIGITAL_CHANNEL_CENTER = 992; -const int CRSF_DIGITAL_CHANNEL_MAX = 1811; -const int CRSF_TIME_BETWEEN_FRAMES_US = 1666; -const int CRSF_PACKET_SIZE = 26; -const int CRSF_CMD_PACKET_SIZE = 8; - -// ERLS others -const int ELRS_ADDR_RADIO = 0xEA; -const int ELRS_SERIAL_BAUDRATE = 400000; - -// ELRS command -const int ELRS_ADDRESS = 0xEE; -const int ELRS_BIND_COMMAND = 0xFF; -const int ELRS_WIFI_COMMAND = 0xFE; -const int ELRS_PKT_RATE_COMMAND = 0x01; -const int ELRS_TLM_RATIO_COMMAND = 0x02; -const int ELRS_SWITCH_MODE_COMMAND = 0x03; -const int ELRS_MODEL_MATCH_COMMAND = 0x04; -const int ELRS_POWER_COMMAND = 0x06; -const int ELRS_BLE_JOYSTIC_COMMAND = 17; -const int ELRS_TYPE_SETTINGS_WRITE = 0x2D; - -// ERLS command values -const int ELRS_PACKET_RATE_50Hz = 0; -const int ELRS_PACKET_RATE_100Hz = 1; -const int ELRS_PACKET_RATE_200Hz = 2; -const int ELRS_PACKET_RATE_500Hz = 3; -const int ELRS_TX_POWER_10mW = 0; -const int ELRS_TX_POWER_25mW = 1; -const int ELRS_TX_POWER_100mW = 2; -const int ELRS_TX_POWER_250mW = 3; -const int ELRS_TX_POWER_500mW = 4; -const int ELRS_TX_POWER_1000mW = 5; - -class ElrsTx -{ - public: - ElrsTx(HardwareSerial &serial); - - void set_data(int16_t value, uint8_t channel); - void send_data(); - void begin(int packet_rate, int tx_power); - - private: - uint8_t crsf_packet[CRSF_PACKET_SIZE]; - uint8_t crsf_cmd_packet[CRSF_CMD_PACKET_SIZE]; - int16_t elrs_channels[CRSF_MAX_CHANNEL]; - - bool elrs_init_done = false; - int elrs_init_counter = 0; - - HardwareSerial &_serial; - int _packet_rate; - int _tx_power; - - // crc implementation from CRSF protocol document rev7 - const uint8_t CRSF_CRC8TAB[256] = { - 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, - 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, - 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, - 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, - 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, - 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, - 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, - 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9}; - - uint8_t calculate_crsf_crc8(const uint8_t *ptr, uint8_t len); - void prepare_crsf_data_packet(uint8_t packet[], int16_t channels[]); - void prepare_crsf_cmd_packet(uint8_t packet_cmd[], uint8_t command, uint8_t value); -}; - -#endif diff --git a/firmware/src/IndicatorLed.cpp b/firmware/src/IndicatorLed.cpp deleted file mode 100644 index 05a40c0..0000000 --- a/firmware/src/IndicatorLed.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * ======================================================================================================= - * ------------------------------------------------------------------------------------------------------- - * ---####################-----###########-------###########-----############--############-############-- - * --######################---#############-----#############---- -- - --- - * --###### ##---##### ###-----### #####---------##-------#######------#------------- - * -- -------------- --- ----- --- ----- ---------##-------#------------#------------- - * --#####--------------------#####------####-####------#####---------##-------###########--############-- - * -- -------------------- ------ ------ --------- ------- -- -- - * --#####--------------------#####--------#####--------#####--------------------------------------------- - * -- -------------------- -------- -------- --------------------------------------------- - * --######--------------##---#####---------------------#####---------------- IndicatorLed --------------- - * --##################### ---#####---------------------#####--------------------------------------------- - * ---################### ----#####---------------------#####--------------------------------------------- - * --- ----- --------------------- --------------------------------------------- - * ------------------------------------------------------------------------------------------------------- - * ======================================================================================================= - * - * Copyright 2023 Christoffer Martinsson - * - * CMtec ERLS can be redistributed and/or modified under the terms of the GNU General - * Public License (Version 2), as published by the Free Software Foundation. - * A copy of the license can be found online at www.gnu.o urg/licenses. - * - * CMtec ERLS is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - */ - -#include "IndicatorLed.h" - -/** - * @brief Construct a new Indicator Led:: Indicator Led object - * - * @param pin Pin number for indicator LED - */ -IndicatorLed::IndicatorLed(int pin) -{ - _pin = pin; -} - -/** - * @brief Initialize indicator LED - */ -void IndicatorLed::begin() -{ - pinMode(_pin, OUTPUT); - digitalWrite(_pin, LOW); -} - -/** - * @brief Turn on indicator LED - */ -void IndicatorLed::on() -{ - led_mode = LED_ON; -} - -/** - * @brief Turn off indicator LED - */ -void IndicatorLed::off() -{ - led_mode = LED_OFF; -} - -/** - * @brief Blink indicator LED - */ -void IndicatorLed::blink() -{ - led_mode = LED_BLINK; -} - -/** - * @brief Update indicator LED. Call this function in the main loop with a 200-500 ms interval. - */ -void IndicatorLed::update() -{ - - if (led_mode == LED_BLINK && current_state == LED_OFF) - { - digitalWrite(_pin, HIGH); - current_state = LED_ON; - } - else if (led_mode == LED_BLINK && current_state == LED_ON) - { - digitalWrite(_pin, LOW); - current_state = LED_OFF; - } - else if (led_mode == LED_ON) - { - digitalWrite(_pin, HIGH); - current_state = LED_ON; - } - else - { - digitalWrite(_pin, LOW); - current_state = LED_OFF; - } -} diff --git a/firmware/src/IndicatorLed.h b/firmware/src/IndicatorLed.h deleted file mode 100644 index a25a6fc..0000000 --- a/firmware/src/IndicatorLed.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ======================================================================================================= - * ------------------------------------------------------------------------------------------------------- - * ---####################-----###########-------###########-----############--############-############-- - * --######################---#############-----#############---- -- - --- - * --###### ##---##### ###-----### #####---------##-------#######------#------------- - * -- -------------- --- ----- --- ----- ---------##-------#------------#------------- - * --#####--------------------#####------####-####------#####---------##-------###########--############-- - * -- -------------------- ------ ------ --------- ------- -- -- - * --#####--------------------#####--------#####--------#####--------------------------------------------- - * -- -------------------- -------- -------- --------------------------------------------- - * --######--------------##---#####---------------------#####---------------- IndicatorLed --------------- - * --##################### ---#####---------------------#####--------------------------------------------- - * ---################### ----#####---------------------#####--------------------------------------------- - * --- ----- --------------------- --------------------------------------------- - * ------------------------------------------------------------------------------------------------------- - * ======================================================================================================= - * - * Copyright 2023 Christoffer Martinsson - * - * CMtec ERLS can be redistributed and/or modified under the terms of the GNU General - * Public License (Version 2), as published by the Free Software Foundation. - * A copy of the license can be found online at www.gnu.o urg/licenses. - * - * CMtec ERLS is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - */ - -#ifndef INDICATORLED_H -#define INDICATORLED_H - -#include - -const int LED_OFF = 0; -const int LED_ON = 1; -const int LED_BLINK = 2; - -class IndicatorLed -{ - public: - IndicatorLed(int pin); - void begin(); - void on(); - void off(); - void blink(); - void update(); - - private: - int _pin; - int led_mode = LED_OFF; - int current_state = LED_OFF; -}; - -#endif diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index eab4a6d..8deeb22 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -6,10 +6,10 @@ * License: Please refer to LICENSE file in root folder */ -#include "ElrsTx.h" -#include "IndicatorLed.h" #include #include +#include +#include #include IndicatorLed status_led(13); From 727d76a25c018189651641cbeaf7d3f89321fbd2 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 6 Jun 2023 17:27:44 +0200 Subject: [PATCH 25/29] Changed to new clang format --- firmware/lib/teensy-libc | 2 +- firmware/src/cmdr_joystick.cpp | 154 ++++++++++----------------------- 2 files changed, 49 insertions(+), 107 deletions(-) diff --git a/firmware/lib/teensy-libc b/firmware/lib/teensy-libc index 6a2b179..88cb7c1 160000 --- a/firmware/lib/teensy-libc +++ b/firmware/lib/teensy-libc @@ -1 +1 @@ -Subproject commit 6a2b179d8f624d69b41a5d30df7b46080a1deec6 +Subproject commit 88cb7c10ca12ea33fb96aa10ae97a14d087da852 diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index 8deeb22..d3018da 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -55,8 +55,7 @@ const int DEADZONE_X = 50; const int DEADZONE_Y = 50; const int JOYSTICK_HAT_CENTER = -1; -enum EEPROM_ADR -{ +enum EEPROM_ADR { MAX_X1_ADR_HIGH, MAX_X1_ADR_LOW, MIN_X1_ADR_HIGH, @@ -122,8 +121,7 @@ int joystick_calibration_mode = CALIBRATION_OFF; /** * @brief Save calibration data to EEPROM */ -void save_to_eeprom() -{ +void save_to_eeprom() { EEPROM.write(MAX_X1_ADR_LOW, joystick_x1_12bit_max); EEPROM.write(MAX_X1_ADR_HIGH, joystick_x1_12bit_max >> 8); EEPROM.write(MIN_X1_ADR_LOW, joystick_x1_12bit_min); @@ -156,8 +154,7 @@ void save_to_eeprom() /** * @brief Load calibration data from EEPROM */ -void load_from_eeprom() -{ +void load_from_eeprom() { joystick_x1_12bit_max = (EEPROM.read(MAX_X1_ADR_HIGH) << 8); joystick_x1_12bit_max |= EEPROM.read(MAX_X1_ADR_LOW); joystick_x1_12bit_min = (EEPROM.read(MIN_X1_ADR_HIGH) << 8); @@ -195,22 +192,19 @@ void load_from_eeprom() * @param analog_x2 * @param analog_y2 */ -void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) -{ +void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) { joystick_x1_12bit = AXIS_12BIT_CENTER; joystick_y1_12bit = AXIS_12BIT_CENTER; joystick_x2_12bit = AXIS_12BIT_CENTER; joystick_y2_12bit = AXIS_12BIT_CENTER; // Check for calibration mode - if (joystick_calibration_mode == CALIBRATION_INIT && digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_NOT_PRESSED) - { + if (joystick_calibration_mode == CALIBRATION_INIT && digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_NOT_PRESSED) { joystick_calibration_mode = CALIBRATION_CENTER; } // Calibrate joystick center values - else if (joystick_calibration_mode == CALIBRATION_CENTER) - { + else if (joystick_calibration_mode == CALIBRATION_CENTER) { joystick_x1_12bit_center = analog_x1; joystick_y1_12bit_center = analog_y1; joystick_x1_12bit_max = joystick_x1_12bit_center; @@ -225,15 +219,13 @@ void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) joystick_y2_12bit_max = joystick_y2_12bit_center; joystick_y2_12bit_min = joystick_y2_12bit_center; - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) - { + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) { joystick_calibration_mode = CALIBRATION_MINMAX; } } // Calibrate joystick min/max values - else if (joystick_calibration_mode == CALIBRATION_MINMAX) - { + else if (joystick_calibration_mode == CALIBRATION_MINMAX) { if (analog_x1 > joystick_x1_12bit_max) joystick_x1_12bit_max = analog_x1; if (analog_x1 < joystick_x1_12bit_min) joystick_x1_12bit_min = analog_x1; if (analog_y1 > joystick_y1_12bit_max) joystick_y1_12bit_max = analog_y1; @@ -243,8 +235,7 @@ void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) if (analog_y2 > joystick_y2_12bit_max) joystick_y2_12bit_max = analog_y2; if (analog_y2 < joystick_y2_12bit_min) joystick_y2_12bit_min = analog_y2; - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) - { + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) { joystick_calibration_mode = CALIBRATION_OFF; save_to_eeprom(); } @@ -254,8 +245,7 @@ void calibrate_axis(int analog_x1, int analog_y1, int analog_x2, int analog_y2) /** * @brief Save joystick calibration values to EEPROM */ -void send_elrs_data() -{ +void send_elrs_data() { // Set ELRS analog channels elrs.set_data(map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 0); elrs.set_data(map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 1); @@ -263,8 +253,7 @@ void send_elrs_data() elrs.set_data(map(joystick_y2_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX), 3); // Set ELRS digital channels - for (int i = 4; i < CRSF_MAX_CHANNEL; i++) - { + for (int i = 4; i < CRSF_MAX_CHANNEL; i++) { elrs.set_data(CRSF_DIGITAL_CHANNEL_MIN, i); } @@ -281,8 +270,7 @@ void send_elrs_data() /** * Send USB data to PC */ -void send_usb_data() -{ +void send_usb_data() { // Set USB analog channels int joystick_x1_10bit = map(joystick_x1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); int joystick_y1_10bit = map(joystick_y1_12bit, AXIS_12BIT_MIN, AXIS_12BIT_MAX, AXIS_10BIT_MIN, AXIS_10BIT_MAX); @@ -292,22 +280,17 @@ void send_usb_data() Joystick.Zrotate(joystick_x1_10bit); Joystick.Z(joystick_y1_10bit); - if (fn_mode == 2) - { + if (fn_mode == 2) { Joystick.X(AXIS_10BIT_CENTER); Joystick.Y(AXIS_10BIT_CENTER); Joystick.sliderRight(joystick_x2_10bit); Joystick.sliderLeft(joystick_y2_10bit); - } - else if (fn_mode == 1) - { + } else if (fn_mode == 1) { Joystick.X(AXIS_10BIT_CENTER); Joystick.Y(joystick_y2_10bit); Joystick.sliderRight(joystick_x2_10bit); Joystick.sliderLeft(AXIS_10BIT_CENTER); - } - else - { + } else { Joystick.X(joystick_x2_10bit); Joystick.Y(joystick_y2_10bit); Joystick.sliderRight(AXIS_10BIT_CENTER); @@ -315,33 +298,27 @@ void send_usb_data() } // Set USB digital channels - for (int i = 1; i < 32; i++) - { + for (int i = 1; i < 32; i++) { Joystick.button(i, 0); } Joystick.hat(JOYSTICK_HAT_CENTER); - if (fn_mode == 2) - { + if (fn_mode == 2) { if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(12, 1); if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(13, 1); if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(14, 1); if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(15, 1); if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(16, 1); if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(17, 1); - } - else if (fn_mode == 1) - { + } else if (fn_mode == 1) { if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(8, 1); if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(9, 1); if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(10, 1); if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(11, 1); if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(1, 1); if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) Joystick.button(2, 1); - } - else - { + } else { if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(3, 1); if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(4, 1); if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) Joystick.button(5, 1); @@ -364,23 +341,18 @@ void send_usb_data() * @param deadband_value * @param expo_value */ -int apply_calibration_12bit(int gimbal_value, int min_value, int max_value, int center_value, int deadband_value, int expo_value) -{ +int apply_calibration_12bit(int gimbal_value, int min_value, int max_value, int center_value, int deadband_value, int expo_value) { int calibrated_value = AXIS_12BIT_CENTER; - if (gimbal_value > (center_value + deadband_value)) - { + if (gimbal_value > (center_value + deadband_value)) { calibrated_value = constrain(map(gimbal_value, (center_value + deadband_value), max_value, AXIS_12BIT_CENTER, AXIS_12BIT_MAX), AXIS_12BIT_CENTER, AXIS_12BIT_MAX); - } - else if (gimbal_value < (center_value - deadband_value)) - { + } else if (gimbal_value < (center_value - deadband_value)) { calibrated_value = constrain(map(gimbal_value, min_value, (center_value - deadband_value), AXIS_12BIT_MIN, AXIS_12BIT_CENTER), AXIS_12BIT_MIN, AXIS_12BIT_CENTER); } - if (expo_value != 0) - { + if (expo_value != 0) { float joystick_x_float = calibrated_value / float(AXIS_12BIT_MAX); /* Calculate expo using 9th order polynomial function with 0.5 as center point */ float joystick_x_exp = expo_value * (0.5 + 256 * pow((joystick_x_float - 0.5), 9)) + (1 - expo_value) * joystick_x_float; @@ -393,30 +365,25 @@ int apply_calibration_12bit(int gimbal_value, int min_value, int max_value, int /** * @brief Process input data from gimbal and buttons */ -void process_input_data() -{ +void process_input_data() { int analog_x1_gimbal_value = 0; int analog_y1_gimbal_value = 0; int analog_x2_gimbal_value = 0; int analog_y2_gimbal_value = 0; - if (gimbal_mode == GIMBAL_MODE_FRSKY_M10) - { + if (gimbal_mode == GIMBAL_MODE_FRSKY_M10) { analog_x1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); analog_y1_gimbal_value = constrain(analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); analog_x2_gimbal_value = constrain(analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); analog_y2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); - } - else if (gimbal_mode == GIMBAL_MODE_FRSKY_M7) - { + } else if (gimbal_mode == GIMBAL_MODE_FRSKY_M7) { analog_x1_gimbal_value = constrain(analog_x1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); analog_y1_gimbal_value = constrain(AXIS_12BIT_MAX - analog_y1.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); analog_x2_gimbal_value = constrain(AXIS_12BIT_MAX - analog_x2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); analog_y2_gimbal_value = constrain(analog_y2.getValue(), AXIS_12BIT_MIN, AXIS_12BIT_MAX); } - if (joystick_calibration_mode != CALIBRATION_OFF) - { + if (joystick_calibration_mode != CALIBRATION_OFF) { calibrate_axis(analog_x1_gimbal_value, analog_y1_gimbal_value, analog_x2_gimbal_value, analog_y2_gimbal_value); return; } @@ -432,42 +399,32 @@ void process_input_data() // Check fn mode fn_mode = 0; - if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) - { + if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) { fn_mode = 1; - if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) - { + if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) { fn_mode = 2; } } // Check toggle mode buttons - if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) - { + if (digitalRead(BUTTON_FRONT_LEFT_UPPER_PIN) == BUTTON_PRESSED) { toggle_button_mode = true; - } - else if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) - { + } else if (digitalRead(BUTTON_FRONT_LEFT_LOWER_PIN) == BUTTON_PRESSED) { toggle_button_mode = false; } // Check toggle arm button - if ((fn_mode == 1) && (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) != toggle_button_arm_previous_value)) - { - if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == false)) - { + if ((fn_mode == 1) && (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) != toggle_button_arm_previous_value)) { + if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == false)) { toggle_button_arm = true; - } - else if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == true)) - { + } else if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == true)) { toggle_button_arm = false; } toggle_button_arm_previous_value = digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN); } } -void setup() -{ +void setup() { /* Init HW */ status_led.begin(); status_led.blink(); @@ -503,14 +460,12 @@ void setup() Joystick.useManualSend(true); // Check if calibration mode is enabled - if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) - { + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) { joystick_calibration_mode = CALIBRATION_INIT; } // Check if bootloader mode is enabled - if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) - { + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) { button_led_2.on(); button_led_2.update(); delay(200); @@ -518,8 +473,7 @@ void setup() } // Check what gimbal mode is selected - if (digitalRead(GIMBAL_MODE_PIN) == LOW) - { + if (digitalRead(GIMBAL_MODE_PIN) == LOW) { gimbal_mode = GIMBAL_MODE_FRSKY_M10; } @@ -527,8 +481,7 @@ void setup() elrs.begin(ELRS_PACKET_RATE_500Hz, ELRS_TX_POWER_25mW); } -void loop() -{ +void loop() { current_timestamp_micros = micros(); analog_x1.update(); @@ -537,50 +490,39 @@ void loop() analog_y2.update(); /* Process data with 1ms interval*/ - if (current_timestamp_micros >= process_data_timestamp_micros) - { + if (current_timestamp_micros >= process_data_timestamp_micros) { process_input_data(); process_data_timestamp_micros = current_timestamp_micros + TIME_US_1ms; } /* Update/Send USB data with 5ms interval*/ - if (current_timestamp_micros >= send_usb_timestamp_micros) - { + if (current_timestamp_micros >= send_usb_timestamp_micros) { send_usb_data(); send_usb_timestamp_micros = current_timestamp_micros + TIME_US_5ms; } /* Update/Send ERLS data with about 1,6ms interval */ - if (current_timestamp_micros >= send_elrs_timestamp_micros) - { + if (current_timestamp_micros >= send_elrs_timestamp_micros) { send_elrs_data(); send_elrs_timestamp_micros = current_timestamp_micros + CRSF_TIME_BETWEEN_FRAMES_US; } /* Update indicator with 200ms interval */ - if (current_timestamp_micros >= indicator_timestamp_micros) - { + if (current_timestamp_micros >= indicator_timestamp_micros) { button_led_1.off(); button_led_2.off(); - if (joystick_calibration_mode == CALIBRATION_INIT) - { + if (joystick_calibration_mode == CALIBRATION_INIT) { button_led_1.blink(); button_led_2.blink(); - } - else if (joystick_calibration_mode == CALIBRATION_CENTER) - { + } else if (joystick_calibration_mode == CALIBRATION_CENTER) { button_led_1.blink(); button_led_2.off(); - } - else if (joystick_calibration_mode == CALIBRATION_MINMAX) - { + } else if (joystick_calibration_mode == CALIBRATION_MINMAX) { button_led_1.off(); button_led_2.blink(); - } - else if ((joystick_x1_12bit != AXIS_12BIT_CENTER) || (joystick_y1_12bit != AXIS_12BIT_MIN) || - (joystick_x2_12bit != AXIS_12BIT_CENTER) || (joystick_y2_12bit != AXIS_12BIT_CENTER)) - { + } else if ((joystick_x1_12bit != AXIS_12BIT_CENTER) || (joystick_y1_12bit != AXIS_12BIT_MIN) || + (joystick_x2_12bit != AXIS_12BIT_CENTER) || (joystick_y2_12bit != AXIS_12BIT_CENTER)) { button_led_1.on(); button_led_2.on(); } From fbe154a055cfef6bd1fc823181672356f59a18fe Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 6 Jun 2023 20:14:34 +0200 Subject: [PATCH 26/29] Fixed ELRS buttonmapping. Changed Arm toggle from one button to two button toggle --- firmware/src/cmdr_joystick.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/firmware/src/cmdr_joystick.cpp b/firmware/src/cmdr_joystick.cpp index d3018da..20ca156 100644 --- a/firmware/src/cmdr_joystick.cpp +++ b/firmware/src/cmdr_joystick.cpp @@ -43,7 +43,6 @@ int gimbal_mode = GIMBAL_MODE_FRSKY_M7; bool toggle_button_arm = false; bool toggle_button_mode = false; -int toggle_button_arm_previous_value = HIGH; const int AXIS_10BIT_MAX = 1023; const int AXIS_10BIT_MIN = 0; @@ -259,9 +258,10 @@ void send_elrs_data() { if (toggle_button_arm) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 4); if (toggle_button_mode) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 5); - if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 6); - if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 7); - if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 8); + if (digitalRead(BUTTON_TOP_LEFT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 6); + if (digitalRead(BUTTON_TOP_RIGHT_UPPER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 7); + if (digitalRead(BUTTON_TOP_LEFT_LOWER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 8); + if (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) elrs.set_data(CRSF_DIGITAL_CHANNEL_MAX, 9); // Send ELRS data elrs.send_data(); @@ -414,13 +414,10 @@ void process_input_data() { } // Check toggle arm button - if ((fn_mode == 1) && (digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) != toggle_button_arm_previous_value)) { - if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == false)) { - toggle_button_arm = true; - } else if ((digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN) == BUTTON_PRESSED) && (toggle_button_arm == true)) { - toggle_button_arm = false; - } - toggle_button_arm_previous_value = digitalRead(BUTTON_TOP_RIGHT_LOWER_PIN); + if (digitalRead(BUTTON_FRONT_RIGHT_UPPER_PIN) == BUTTON_PRESSED) { + toggle_button_arm = true; + } else if (digitalRead(BUTTON_FRONT_RIGHT_LOWER_PIN) == BUTTON_PRESSED) { + toggle_button_arm = false; } } From b8689baf0fc5e1ff39e028586dae1d5f56694bba Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 6 Jun 2023 20:14:44 +0200 Subject: [PATCH 27/29] Added readme --- README.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/README.md b/README.md index 7faad59..1ee29ae 100644 --- a/README.md +++ b/README.md @@ -1 +1,76 @@ # CMDR Joystick + +RC Joystick with 2 hall effect gimbals and 8 buttons for use both with simulators and ELRS Rx equipped quads. + +```cpp +| B3 | | B1 | +| Fn1| | B2 | +-------------------------------------------- +| | B4 | | B5 | | +| | +| X1,Y1 X2,Y2 | +| | B6 | | B7 | | +-------------------------------------------- + +USB Joystick Layer 1 (Fn1) + +| Fn2 | | B1 | +| Fn1 | | B2 | +-------------------------------------------- +| | B8 | | B9 | | +| | +| X1,Y1 X3,Y2 | +| | B10 | | B11 | | +-------------------------------------------- + +USB Joystick Layer 2 (Fn2) + +| Fn2 | | B16 | +| Fn1 | | B17 | +-------------------------------------------- +| | B12 | | B13 | | +| | +| X1,Y1 X3,Y3 | +| | B14 | | B15 | | +-------------------------------------------- + +ELRS Layer + +| CH6 on | | CH5 on | +| CH6 off | | CH5 off | +-------------------------------------------- +| | CH7 | | CH8 | | +| | +| X,Y X,Y | +| CH1,CH2 | CH9 | | CH10 | CH3,CH4 | +-------------------------------------------- +``` + +## Features + +- Ergonomic design (low profile) +- 2x Hall effect gimbals +- 8x Buttons +- Supports both USB HID joystick and ELRS Tx module + +## Build environment + +- Platformio + - env: teensylc + - platform: teensy + - board: teensylc + - framework: arduino +- Flashing via Teensy USB bootloader + - Pressing boot button on teensy + - Pressing all four corners on the keyboard + +## Hardware + +- 1x TeensyLC MCU +- 2x FrSky M7 or M10 gimbals +- 6x Kailh choc low profile switches +- 2x Cherry MX switches +- 1x PCB +- 1x Bottom case +- 1x Top plate +- 2x Gimbal spacers From 35a1c4c985273e0192770c5aab715ca9557c60fb Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 6 Jun 2023 20:37:07 +0200 Subject: [PATCH 28/29] Updated readme --- README.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1ee29ae..e552fc8 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,13 @@ RC Joystick with 2 hall effect gimbals and 8 buttons for use both with simulators and ELRS Rx equipped quads. +## Layout + ```cpp -| B3 | | B1 | -| Fn1| | B2 | +USB Joystick Layer 0 + +| B3 | | B1 | +| Fn1 | | B2 | -------------------------------------------- | | B4 | | B5 | | | | @@ -49,9 +53,11 @@ ELRS Layer ## Features - Ergonomic design (low profile) -- 2x Hall effect gimbals -- 8x Buttons +- Hall effect gimbals - Supports both USB HID joystick and ELRS Tx module +- Total 6x axis and 15x buttons (using Fn mode) implemented in USB HID mode +- 10 Channels implemented in ELRS mode (4x axis, 6x buttons) +- Low latency (1.6ms ELRS, 5ms USB) ## Build environment @@ -62,7 +68,7 @@ ELRS Layer - framework: arduino - Flashing via Teensy USB bootloader - Pressing boot button on teensy - - Pressing all four corners on the keyboard + - Press and hold "top lower right button" when powering the unit ## Hardware @@ -74,3 +80,15 @@ ELRS Layer - 1x Bottom case - 1x Top plate - 2x Gimbal spacers + +## Calibration + +_The button is from here reffered to "top lower left button"_ + +1 Turn off the unit +2 Press and hold the button while powering the unit +3 Release the button and center the two gimbals +4 Press the button again +5 Move the two gimbals to it maximux X and Y +6 Press the button one mo time +7 Done! From 1c539dc8c90467e775ce370e1b80abefb7e7967a Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 6 Jun 2023 20:38:20 +0200 Subject: [PATCH 29/29] Updated readme --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e552fc8..db5dedc 100644 --- a/README.md +++ b/README.md @@ -85,10 +85,10 @@ ELRS Layer _The button is from here reffered to "top lower left button"_ -1 Turn off the unit -2 Press and hold the button while powering the unit -3 Release the button and center the two gimbals -4 Press the button again -5 Move the two gimbals to it maximux X and Y -6 Press the button one mo time -7 Done! +1. Turn off the unit +2. Press and hold the button while powering the unit +3. Release the button and center the two gimbals +4. Press the button again +5. Move the two gimbals to it maximux X and Y +6. Press the button one mo time +7. Done!