diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96766c3..fad8ca8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,38 +32,38 @@ jobs: pio run - format: - name: Formatting - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 + # format: + # name: Formatting + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v2 - - name: Run clang-format - shell: bash - run: | - make format + # - name: Run clang-format + # shell: bash + # run: | + # make format - static_analysis: - name: Static Analysis - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 + # static_analysis: + # name: Static Analysis + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v2 - - name: Static Code Analysis - shell: bash - run: | - # Exit immediately if a command exits with a non-zero status. - set -e - # Enable the globstar shell option - shopt -s globstar + # - name: Static Code Analysis + # shell: bash + # run: | + # # Exit immediately if a command exits with a non-zero status. + # set -e + # # Enable the globstar shell option + # shopt -s globstar - # Make sure we are inside the github workspace - cd $GITHUB_WORKSPACE - export PATH=$PATH:~/.platformio/penv/bin - wget https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py -O get-platformio.py - python3 get-platformio.py - pio platform install "platformio/teensy" + # # Make sure we are inside the github workspace + # cd $GITHUB_WORKSPACE + # export PATH=$PATH:~/.platformio/penv/bin + # wget https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py -O get-platformio.py + # python3 get-platformio.py + # pio platform install "platformio/teensy" - pio check \ No newline at end of file + # pio check \ No newline at end of file diff --git a/lib/DebugLight/include/DebugLight.hpp b/lib/DebugLight/include/DebugLight.hpp deleted file mode 100644 index 912ce58..0000000 --- a/lib/DebugLight/include/DebugLight.hpp +++ /dev/null @@ -1,170 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace debug_light { - -const double DEFAULT_UPDATE_INTERVAL_MS = 300; -const double MIN_UPDATE_INTERVAL_MS = 100; - -const std::string morse[] = { - ".-", // A - "-...", // B - "-.-.", // C - "-..", // D - ".", // E - "..-.", // F - "--.", // G - "....", // H - "..", // I - ".---", // J - "-.-" // K - ".-..", // L - "--", // M - "-.", // N - "---", // O - ".--.", // P - "--.-", // Q - ".-.", // R - "...", // S - "-", // T - "..-", // U - "...-", // V - ".--", // W - "-..-", // X - "-.--", // Y - "--.." // Z -}; - -static const std::string& toMorse(char c) { - int ord = static_cast(toupper(c)) - static_cast('A'); - if (ord >= 0 && ord < 26) { - return morse[ord]; - } else { - return morse[0]; - } -} - - -class DebugLight { -public: - - DebugLight() { - updateInterval = DEFAULT_UPDATE_INTERVAL_MS; - pin = LED_BUILTIN; - patternActive = false; - } - - DebugLight(uint8_t _pin) { - updateInterval = DEFAULT_UPDATE_INTERVAL_MS; - pin = _pin; - patternActive = false; - } - - DebugLight(uint8_t _pin, double _updateInterval) { - if (_updateInterval >= MIN_UPDATE_INTERVAL_MS) { - updateInterval = _updateInterval; - } else { - updateInterval = DEFAULT_UPDATE_INTERVAL_MS; - } - - pin = _pin; - patternActive = false; - } - - void update() { - if (patternActive) { - if (timer >= updateInterval) { - timer -= updateInterval; - digitalWrite(pin, updatePattern(currentPattern)); - } - } else { - if (timer >= updateInterval * 3) { - timer -= updateInterval * 3; - digitalToggle(pin); - } - } - } - - void setPattern(const std::string code) { - currentPattern = (struct Pattern){.str = code}; - patternActive = true; - } - - void disablePattern() { - patternActive = false; - } - -private: - static elapsedMillis timer; - double updateInterval; - uint8_t pin; - - // Patterns (for error codes) - struct Pattern { - std::string str; - int strIdx; - int morseIdx; - int count; - }; - - struct Pattern currentPattern; - bool patternActive; - - uint8_t updatePattern(struct Pattern& pattern) { - - // end of string - if (pattern.strIdx >= pattern.str.length()) { - // wait 3 counts at end of pattern before resetting - if (pattern.count >= 2) { - resetPattern(pattern); - } else { - pattern.count += 1; - } - return LOW; - } - - // get morse code string for char at strIdx - char curr = pattern.str[pattern.strIdx]; - const std::string& code = debug_light::toMorse(curr); - - // end of character - if (pattern.morseIdx >= code.length()) { - advancePattern(pattern); - return LOW; - } - - if (code[pattern.morseIdx] == '.') { - // dot is 1 count - pattern.morseIdx += 1; - return HIGH; - } else if (code[pattern.morseIdx] == '-') { - // dash is 3 counts - if (pattern.count >= 2) { - pattern.morseIdx += 1; - pattern.count = 0; - } else { - pattern.count += 1; - } - return HIGH; - } else { - // unknown character - pattern.morseIdx += 1; - return LOW; - } - } - void resetPattern(struct Pattern& pattern) { - pattern.strIdx = 0; - pattern.morseIdx = 0; - pattern.count = 0; - } - void advancePattern(struct Pattern& pattern) { - pattern.strIdx += 1; - pattern.morseIdx = 0; - pattern.count = 0; - } -}; - -} \ No newline at end of file diff --git a/lib/DebugLight/src/DebugLight.cpp b/lib/DebugLight/src/DebugLight.cpp deleted file mode 100644 index 945f96d..0000000 --- a/lib/DebugLight/src/DebugLight.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "DebugLight.hpp" - -elapsedMillis debug_light::DebugLight::timer; \ No newline at end of file diff --git a/lib/StatusLight/include/StatusLight.hpp b/lib/StatusLight/include/StatusLight.hpp deleted file mode 100644 index 10651b3..0000000 --- a/lib/StatusLight/include/StatusLight.hpp +++ /dev/null @@ -1,84 +0,0 @@ -#pragma once - -#include -#include - -namespace status_light { - -const double DEFAULT_PERIOD = 1.0; - -class StatusLight { -public: - StatusLight(std::unordered_map pin_map) { - - blinkPeriod = DEFAULT_PERIOD; - for (auto& pair : pin_map) { - led[pair.first] = (struct Led){.pin=pair.second, .state=0, .blink=0}; - } - } - - void setPeriod(double period) { period > 0 ? blinkPeriod = period: blinkPeriod = DEFAULT_PERIOD; } - bool setLedState(const std::string& name, uint8_t state) { - if (led.find(name) != led.end()) { - led[name].state = state; - return true; - } else { - return false; - } - } - bool setLedBlink(const std::string& name, uint8_t blink) { - if (led.find(name) != led.end()) { - led[name].blink = blink; - return true; - } else { - return false; - } - } - void resetLeds() { - for (auto& pair : led) { - pair.second.state = 0; - pair.second.blink = 0; - } - } - void update() { - if (blinkPeriod >= blinkPeriod) { - // LOW - blinkPeriod -= blinkPeriod; - for (const auto& pair : led) { - if (!pair.second.state) { - pinMode(pair.second.pin, LOW); - } else if (pair.second.blink) { - pinMode(pair.second.pin, LOW); - } else { - pinMode(pair.second.pin, HIGH); - } - } - - } else if (blinkPeriod >= blinkPeriod / 2.0) { - // HIGH - for (const auto& pair : led) { - if (!pair.second.state) { - pinMode(pair.second.pin, LOW); - } else if (pair.second.blink) { - pinMode(pair.second.pin, HIGH); - } else { - pinMode(pair.second.pin, HIGH); - } - } - } - } - -private: - - struct Led { - uint8_t pin; - uint8_t state; - uint8_t blink; - }; - - std::unordered_map led; - double blinkPeriod; - static elapsedMillis blinkTimer; -}; - -} \ No newline at end of file diff --git a/src/Main/main.cpp b/src/Main/main.cpp index 5d77f43..84f80df 100644 --- a/src/Main/main.cpp +++ b/src/Main/main.cpp @@ -4,7 +4,6 @@ #include #include "urc.pb.h" #include "Messages.hpp" -#include "StatusLight.hpp" #include "SoloCAN.hpp" #include "pb_encode.h" diff --git a/src/StatusLight/main.cpp b/src/StatusLight/main.cpp index 7d5f98f..e8d1134 100644 --- a/src/StatusLight/main.cpp +++ b/src/StatusLight/main.cpp @@ -2,7 +2,6 @@ #include #include "urc.pb.h" #include -#include "StatusLight.hpp" // v1.0 PCB pins // const int GREEN_PIN = 30;