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);