diff --git a/.github/workflows/duo_build.yml b/.github/workflows/duo_build.yml index 0a5635170c..2f1221d0b3 100644 --- a/.github/workflows/duo_build.yml +++ b/.github/workflows/duo_build.yml @@ -7,6 +7,9 @@ on: branches: [ "duo" ] workflow_dispatch: # manual trigger +env: + EMSDK_VERSION: "3.1.74" + jobs: setup: runs-on: ubuntu-latest @@ -116,11 +119,12 @@ jobs: run: sudo apt-get update - name: Install Emscripten run: | - sudo apt install -y cmake python3 git clone https://github.com/emscripten-core/emsdk.git cd emsdk - ./emsdk install latest - ./emsdk activate latest + git fetch --tags + git checkout "${EMSDK_VERSION}" + ./emsdk install "${EMSDK_VERSION}" + ./emsdk activate "${EMSDK_VERSION}" working-directory: VortexEngine/VortexLib - name: Build Webassembly run: | diff --git a/Makefile b/Makefile index 1c279a53ef..a003c667f3 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ OSCCFG = 0x02 #FUSE3 = 0x00 # TCD0CFG { CMPA=CLEAR, CMPB=CLEAR, CMPC=CLEAR, CMPD=CLEAR, CMPAEN=CLEAR, CPMCEN=CLEAR, CMPDEN=CLEAR } TCD0CFG = 0x00 -# SYSCFG0 +# SYSCFG0 { CRCSRC=NOCRC, RESERVED=0, TOUTDIS=0, RSTPINCFG=UPDI, EESAVE=$(SAVE_EEPROM) (usually 1) } SYSCFG0 = 0b1100010$(SAVE_EEPROM) # SYSCFG1 { SUT=64ms } SYSCFG1 = 0x07 diff --git a/VortexEngine/src/Memory/Memory.cpp b/VortexEngine/src/Memory/Memory.cpp index 9172488167..c44abd97c9 100644 --- a/VortexEngine/src/Memory/Memory.cpp +++ b/VortexEngine/src/Memory/Memory.cpp @@ -117,7 +117,7 @@ uint32_t cur_memory_usage_total() #endif // DEBUG_ALLOCATIONS == 1 -#ifndef VORTEX_LIB +#if CPP_MEMORY_OPERATORS == 1 // for C++11 need the following: void *operator new (size_t size) { return vmalloc(size); } diff --git a/VortexEngine/src/Memory/Memory.h b/VortexEngine/src/Memory/Memory.h index b851d781ec..275a19aaf4 100644 --- a/VortexEngine/src/Memory/Memory.h +++ b/VortexEngine/src/Memory/Memory.h @@ -36,7 +36,8 @@ uint32_t cur_memory_usage_total(); #endif -#ifndef VORTEX_LIB +#if CPP_MEMORY_OPERATORS == 1 + void *operator new (size_t size); void *operator new[](size_t size); void operator delete (void *ptr); @@ -51,6 +52,7 @@ void operator delete[](void *ptr, size_t size) noexcept; //void operator delete[](void *ptr, std::align_val_t al) noexcept; //void operator delete (void *ptr, size_t size, std::align_val_t al) noexcept; //void operator delete[](void *ptr, size_t size, std::align_val_t al) noexcept; + #endif #endif diff --git a/VortexEngine/src/Menus/MenuList/EditorConnection.cpp b/VortexEngine/src/Menus/MenuList/EditorConnection.cpp index c1fc1d5927..8810871837 100644 --- a/VortexEngine/src/Menus/MenuList/EditorConnection.cpp +++ b/VortexEngine/src/Menus/MenuList/EditorConnection.cpp @@ -5,7 +5,9 @@ #include "../../Serial/Serial.h" #include "../../Storage/Storage.h" #include "../../Wireless/VLSender.h" +#include "../../Wireless/VLReceiver.h" #include "../../Time/TimeControl.h" +#include "../../Time/Timings.h" #include "../../Colors/Colorset.h" #include "../../Modes/Modes.h" #include "../../Modes/Mode.h" @@ -17,6 +19,7 @@ EditorConnection::EditorConnection(const RGBColor &col, bool advanced) : Menu(col, advanced), m_state(STATE_DISCONNECTED), + m_timeOutStartTime(0), m_allowReset(true), m_previousModeIndex(0), m_numModesToReceive(0), @@ -78,7 +81,7 @@ void EditorConnection::onLongClick() void EditorConnection::leaveMenu(bool doSave) { - SerialComs::write(EDITOR_VERB_GOODBYE); + writeData(EDITOR_VERB_GOODBYE); Menu::leaveMenu(true); } @@ -109,6 +112,7 @@ const EditorConnection::CommandState EditorConnection::commands[] = { { EDITOR_VERB_PULL_EACH_MODE, STATE_PULL_EACH_MODE }, { EDITOR_VERB_PUSH_EACH_MODE, STATE_PUSH_EACH_MODE }, { EDITOR_VERB_TRANSMIT_VL, STATE_TRANSMIT_MODE_VL }, + { EDITOR_VERB_LISTEN_VL, STATE_LISTEN_MODE_VL }, { EDITOR_VERB_SET_GLOBAL_BRIGHTNESS, STATE_SET_GLOBAL_BRIGHTNESS }, { EDITOR_VERB_GET_GLOBAL_BRIGHTNESS, STATE_GET_GLOBAL_BRIGHTNESS }, }; @@ -146,11 +150,8 @@ void EditorConnection::handleState() case STATE_DISCONNECTED: default: // not connected yet so check for connections - if (!SerialComs::isConnected()) { - if (!SerialComs::checkSerial()) { - // no connection found just continue waiting - break; - } + if (!detectConnection()) { + break; } // a connection was found, say hello m_state = STATE_GREETING; @@ -160,7 +161,7 @@ void EditorConnection::handleState() // Send Greeting case STATE_GREETING: // send the hello greeting with our version number and build time - SerialComs::write(EDITOR_VERB_GREETING); + writeData(EDITOR_VERB_GREETING); m_state = STATE_IDLE; break; @@ -172,7 +173,7 @@ void EditorConnection::handleState() // parse the receive buffer for any commands from the editor handleCommand(); // watch for disconnects - if (!SerialComs::isConnected()) { + if (!isConnected()) { Leds::holdAll(RGB_RED); leaveMenu(true); } @@ -195,7 +196,7 @@ void EditorConnection::handleState() break; case STATE_PULL_MODES_DONE: // send our acknowledgement that the modes were sent - SerialComs::write(EDITOR_VERB_PULL_MODES_ACK); + writeData(EDITOR_VERB_PULL_MODES_ACK); // go idle m_state = STATE_IDLE; break; @@ -204,7 +205,7 @@ void EditorConnection::handleState() // Receive Modes from PC case STATE_PUSH_MODES: // now say we are ready - SerialComs::write(EDITOR_VERB_READY); + writeData(EDITOR_VERB_READY); // move to receiving m_state = STATE_PUSH_MODES_RECEIVE; break; @@ -218,7 +219,7 @@ void EditorConnection::handleState() m_state = STATE_PUSH_MODES_DONE; break; case STATE_PUSH_MODES_DONE: - SerialComs::write(EDITOR_VERB_PUSH_MODES_ACK); + writeData(EDITOR_VERB_PUSH_MODES_ACK); m_state = STATE_IDLE; break; @@ -226,7 +227,7 @@ void EditorConnection::handleState() // Demo Mode from PC case STATE_DEMO_MODE: // now say we are ready - SerialComs::write(EDITOR_VERB_READY); + writeData(EDITOR_VERB_READY); // move to receiving m_state = STATE_DEMO_MODE_RECEIVE; break; @@ -241,7 +242,7 @@ void EditorConnection::handleState() break; case STATE_DEMO_MODE_DONE: // say we are done - SerialComs::write(EDITOR_VERB_DEMO_MODE_ACK); + writeData(EDITOR_VERB_DEMO_MODE_ACK); m_state = STATE_IDLE; break; @@ -249,7 +250,7 @@ void EditorConnection::handleState() // Reset Demo to Nothing case STATE_CLEAR_DEMO: clearDemo(); - SerialComs::write(EDITOR_VERB_CLEAR_DEMO_ACK); + writeData(EDITOR_VERB_CLEAR_DEMO_ACK); m_state = STATE_IDLE; break; @@ -264,7 +265,29 @@ void EditorConnection::handleState() break; case STATE_TRANSMIT_MODE_VL_DONE: // done transmitting - SerialComs::write(EDITOR_VERB_TRANSMIT_VL_ACK); + writeData(EDITOR_VERB_TRANSMIT_VL_ACK); + m_state = STATE_IDLE; + break; + + // ------------------------------- + // Receive Mode from Duo + case STATE_LISTEN_MODE_VL: +#if VL_ENABLE_RECEIVER == 1 + // immediately load the mode and send it now + VLReceiver::beginReceiving(); +#endif + m_state = STATE_LISTEN_MODE_VL_LISTEN; + break; + case STATE_LISTEN_MODE_VL_LISTEN: + // immediately load the mode and send it now + showReceiveModeVL(); + if (receiveModeVL() == RV_WAIT) { + break; + } + m_state = STATE_LISTEN_MODE_VL_DONE; + break; + case STATE_LISTEN_MODE_VL_DONE: + // done transmitting m_state = STATE_IDLE; break; @@ -283,7 +306,10 @@ void EditorConnection::handleState() if (Modes::numModes() == 0) { m_state = STATE_PULL_EACH_MODE_DONE; } else { + // backup the old mode index so we can return to it m_previousModeIndex = Modes::curModeIndex(); + // switch to mode 0 to ensure we start at the beginning + Modes::setCurMode(0); m_state = STATE_PULL_EACH_MODE_SEND; } break; @@ -311,7 +337,7 @@ void EditorConnection::handleState() break; case STATE_PULL_EACH_MODE_DONE: // send our acknowledgement that the modes were sent - SerialComs::write(EDITOR_VERB_PULL_EACH_MODE_DONE); + writeData(EDITOR_VERB_PULL_EACH_MODE_DONE); // switch back to the previous mode Modes::setCurMode(m_previousModeIndex); // go idle @@ -323,7 +349,7 @@ void EditorConnection::handleState() case STATE_PUSH_EACH_MODE: // editor requested to push modes, find out how many // ack the command and wait for the amount of modes - SerialComs::write(EDITOR_VERB_PUSH_EACH_MODE_ACK); + writeData(EDITOR_VERB_PUSH_EACH_MODE_ACK); m_state = STATE_PUSH_EACH_MODE_COUNT; break; case STATE_PUSH_EACH_MODE_COUNT: @@ -334,7 +360,7 @@ void EditorConnection::handleState() // clear modes and start receiving Modes::clearModes(); // write out an ack - SerialComs::write(EDITOR_VERB_PUSH_EACH_MODE_ACK); + writeData(EDITOR_VERB_PUSH_EACH_MODE_ACK); // ready to receive a mode m_state = STATE_PUSH_EACH_MODE_RECEIVE; break; @@ -344,7 +370,7 @@ void EditorConnection::handleState() // just wait break; } - SerialComs::write(EDITOR_VERB_PUSH_EACH_MODE_ACK); + writeData(EDITOR_VERB_PUSH_EACH_MODE_ACK); if (m_numModesToReceive > 0) { m_numModesToReceive--; } @@ -364,7 +390,7 @@ void EditorConnection::handleState() // ------------------------------- // Set Global Brightness case STATE_SET_GLOBAL_BRIGHTNESS: - SerialComs::write(EDITOR_VERB_READY); + writeData(EDITOR_VERB_READY); m_state = STATE_SET_GLOBAL_BRIGHTNESS_RECEIVE; break; case STATE_SET_GLOBAL_BRIGHTNESS_RECEIVE: @@ -405,22 +431,25 @@ void EditorConnection::showEditor() void EditorConnection::receiveData() { - // read more data into the receive buffer - SerialComs::read(m_receiveBuffer); + if (m_receiveBuffer.size() >= 512) { + return; + } + // Otherwise, read more from Serial + readData(m_receiveBuffer); } void EditorConnection::sendModes() { ByteStream modesBuffer; Modes::saveToBuffer(modesBuffer); - SerialComs::write(modesBuffer); + writeData(modesBuffer); } void EditorConnection::sendModeCount() { ByteStream buffer; buffer.serialize8(Modes::numModes()); - SerialComs::write(buffer); + writeData(buffer); } void EditorConnection::sendCurMode() @@ -435,7 +464,7 @@ void EditorConnection::sendCurMode() // ?? return; } - SerialComs::write(modeBuffer); + writeData(modeBuffer); } void EditorConnection::sendCurModeVL() @@ -445,13 +474,20 @@ void EditorConnection::sendCurModeVL() #endif } +void EditorConnection::listenModeVL() +{ +#if VL_ENABLE_RECEIVER == 1 + m_state = STATE_LISTEN_MODE_VL; +#endif +} + ReturnCode EditorConnection::sendBrightness() { ByteStream brightnessBuf; if (!brightnessBuf.serialize8(Leds::getBrightness())) { return RV_FAIL; } - SerialComs::write(brightnessBuf); + writeData(brightnessBuf); return RV_OK; } @@ -558,7 +594,6 @@ ReturnCode EditorConnection::receiveDemoMode() ReturnCode EditorConnection::receiveMessage(const char *message) { size_t len = strlen(message); - uint8_t byte = 0; // wait for the editor to ack the idle if (m_receiveBuffer.size() < len) { return RV_WAIT; @@ -566,10 +601,8 @@ ReturnCode EditorConnection::receiveMessage(const char *message) if (memcmp(m_receiveBuffer.data(), message, len) != 0) { return RV_FAIL; } - for (size_t i = 0; i < len; ++i) { - if (!m_receiveBuffer.consume8(&byte)) { - return RV_FAIL; - } + if (!m_receiveBuffer.consume((uint32_t)len)) { + return RV_FAIL; } // we have now received at least one command, do not allow resetting m_allowReset = false; @@ -600,3 +633,80 @@ ReturnCode EditorConnection::receiveBrightness() } return RV_OK; } + +ReturnCode EditorConnection::receiveModeVL() +{ +#if VL_ENABLE_RECEIVER == 1 + // if reveiving new data set our last data time + if (VLReceiver::onNewData()) { + m_timeOutStartTime = Time::getCurtime(); + // if our last data was more than time out duration reset the recveiver + } else if (m_timeOutStartTime > 0 && (m_timeOutStartTime + MAX_TIMEOUT_DURATION) < Time::getCurtime()) { + VLReceiver::resetVLState(); + m_timeOutStartTime = 0; + return RV_WAIT; + } + // check if the VLReceiver has a full packet available + if (!VLReceiver::dataReady()) { + // nothing available yet + return RV_WAIT; + } + DEBUG_LOG("Mode ready to receive! Receiving..."); + // receive the VL mode into the current mode + if (!VLReceiver::receiveMode(&m_previewMode)) { + ERROR_LOG("Failed to receive mode"); + return RV_FAIL; + } + DEBUG_LOGF("Success receiving mode: %u", m_previewMode.getPatternID()); + if (!Modes::updateCurMode(&m_previewMode)) { + return RV_FAIL; + } +#endif + ByteStream modeBuffer; + if (!m_previewMode.saveToBuffer(modeBuffer)) { + return RV_FAIL; + } + writeData(modeBuffer); + return RV_OK; +} + +void EditorConnection::showReceiveModeVL() +{ +#if VL_ENABLE_RECEIVER == 1 + if (VLReceiver::isReceiving()) { + // using uint32_t to avoid overflow, the result should be within 10 to 255 + //Leds::setAll(RGBColor(0, VLReceiver::percentReceived(), 0)); + Leds::setRange(LED_0, (LedPos)(((uint32_t)VLReceiver::percentReceived() * LED_COUNT) / 100), RGB_GREEN6); + } else { + Leds::setAll(RGB_WHITE0); + } +#endif +} + +bool EditorConnection::detectConnection() +{ + if (SerialComs::isConnected() || SerialComs::checkSerial()) { + return true; + } + return false; +} + +bool EditorConnection::isConnected() +{ + return SerialComs::isConnected(); +} + +void EditorConnection::readData(ByteStream &buffer) +{ + SerialComs::read(buffer); +} + +void EditorConnection::writeData(ByteStream &buffer) +{ + SerialComs::write(buffer); +} + +void EditorConnection::writeData(const char *message) +{ + SerialComs::write(message); +} diff --git a/VortexEngine/src/Menus/MenuList/EditorConnection.h b/VortexEngine/src/Menus/MenuList/EditorConnection.h index fa499db7fe..df4b539a82 100644 --- a/VortexEngine/src/Menus/MenuList/EditorConnection.h +++ b/VortexEngine/src/Menus/MenuList/EditorConnection.h @@ -40,6 +40,7 @@ class EditorConnection : public Menu void sendModeCount(); void sendCurMode(); void sendCurModeVL(); + void listenModeVL(); ReturnCode sendBrightness(); ReturnCode receiveBuffer(ByteStream &buffer); ReturnCode receiveModes(); @@ -48,6 +49,13 @@ class EditorConnection : public Menu ReturnCode receiveDemoMode(); ReturnCode receiveMessage(const char *message); ReturnCode receiveBrightness(); + ReturnCode receiveModeVL(); + void showReceiveModeVL(); + bool detectConnection(); + void readData(ByteStream &buffer); + void writeData(ByteStream &buffer); + void writeData(const char *message); + bool isConnected(); enum EditorConnectionState { // the editor is not connected @@ -81,6 +89,11 @@ class EditorConnection : public Menu STATE_TRANSMIT_MODE_VL, STATE_TRANSMIT_MODE_VL_DONE, + // receive a mode over VL + STATE_LISTEN_MODE_VL, + STATE_LISTEN_MODE_VL_LISTEN, + STATE_LISTEN_MODE_VL_DONE, + // editor pulls the modes from device (safer version) STATE_PULL_EACH_MODE, STATE_PULL_EACH_MODE_COUNT, @@ -114,6 +127,8 @@ class EditorConnection : public Menu EditorConnectionState m_state; // the data that is received ByteStream m_receiveBuffer; + // receiver timeout + uint32_t m_timeOutStartTime; // Whether at least one command has been received yet bool m_allowReset; // the mode index to return to after iterating the modes to send them diff --git a/VortexEngine/src/Modes/DefaultModes.cpp b/VortexEngine/src/Modes/DefaultModes.cpp index a2f0e7b7e4..5b482d97a5 100644 --- a/VortexEngine/src/Modes/DefaultModes.cpp +++ b/VortexEngine/src/Modes/DefaultModes.cpp @@ -19,7 +19,7 @@ const uint32_t pat9Cols[] = { 0xFFF600, 0x000880 }; // Here is the array of 'default modes' that are assigned to // the gloveset upon factory reset -const DefaultModeEntry defaultModes[MAX_MODES] = { +const DefaultModeEntry defaultModes[] = { // mode 1 {{ { PATTERN_STROBEGAP, 3, rgbCols }, // tip @@ -66,3 +66,8 @@ const DefaultModeEntry defaultModes[MAX_MODES] = { { PATTERN_HYPERSTROBE, 2, pat9Cols } }}, }; + +// compile time assert for max modes count check +static_assert(MAX_MODES == (sizeof(defaultModes) / sizeof(defaultModes[0])), + "Incorrect number of default modes! Ensure default_modes array has " + EXPAND_AND_QUOTE(MAX_MODES) " enties"); diff --git a/VortexEngine/src/Modes/DefaultModes.h b/VortexEngine/src/Modes/DefaultModes.h index 6c685a0d81..ad42d3ed0f 100644 --- a/VortexEngine/src/Modes/DefaultModes.h +++ b/VortexEngine/src/Modes/DefaultModes.h @@ -19,6 +19,6 @@ struct DefaultModeEntry }; // exposed global array of default modes -extern const DefaultModeEntry defaultModes[MAX_MODES]; +extern const DefaultModeEntry defaultModes[]; #endif diff --git a/VortexEngine/src/Modes/Mode.cpp b/VortexEngine/src/Modes/Mode.cpp index 9a0447e228..284bd24f28 100644 --- a/VortexEngine/src/Modes/Mode.cpp +++ b/VortexEngine/src/Modes/Mode.cpp @@ -607,7 +607,6 @@ void Mode::copyPatternFrom(const Mode *other, LedPos to, LedPos from) m_singlePats[to] = PatternBuilder::dupe(other->m_singlePats[from]); } - void Mode::swapPatterns(LedPos a, LedPos b) { if (a >= LED_COUNT || b >= LED_COUNT) { diff --git a/VortexEngine/src/Time/Timings.h b/VortexEngine/src/Time/Timings.h index c3391b41f1..ae27636d50 100644 --- a/VortexEngine/src/Time/Timings.h +++ b/VortexEngine/src/Time/Timings.h @@ -13,7 +13,6 @@ #define SHORT_CLICK_THRESHOLD_TICKS MS_TO_TICKS(CLICK_THRESHOLD) #define CONSECUTIVE_WINDOW_TICKS MS_TO_TICKS(CONSECUTIVE_WINDOW) #define AUTO_RANDOM_DELAY_TICKS MS_TO_TICKS(AUTO_RANDOM_DELAY) -#define UNLOCK_WAKE_WINDOW_TICKS MS_TO_TICKS(UNLOCK_WAKE_WINDOW) #define SLEEP_ENTER_THRESHOLD_TICKS MS_TO_TICKS(SLEEP_TRIGGER_TIME) #define SLEEP_WINDOW_THRESHOLD_TICKS MS_TO_TICKS(SLEEP_WINDOW_TIME) #define FORCE_SLEEP_THRESHOLD_TICKS MS_TO_TICKS(FORCE_SLEEP_TIME) diff --git a/VortexEngine/src/VortexConfig.h b/VortexEngine/src/VortexConfig.h index b04345cb0a..a446593813 100644 --- a/VortexEngine/src/VortexConfig.h +++ b/VortexEngine/src/VortexConfig.h @@ -340,6 +340,20 @@ // =================================================================== // Boolean Configurations (0 or 1) +// Infrared Enable +// +// Whether to enable the Infrared system as a whole. This is for mode +// transferring with IR peripherals +#define IR_ENABLE_SENDER 0 +#define IR_ENABLE_RECEIVER 0 + +// Visible Light Enable +// +// Whether to enable the Visible Light system as a whole. This is for mode +// transferring with the Leds and a light sensor +#define VL_ENABLE_SENDER 1 +#define VL_ENABLE_RECEIVER 1 + // Debug Allocations // // Tracks all memory allocations and logs them, useful for finding leaks @@ -351,6 +365,14 @@ // it will allocate space permanently for the new brush and never free it #define DEBUG_ALLOCATIONS 0 +// CPP Memory Operators +// +// Uses custom/drop-in replacements for new/delete to support C++ memory +// operators in embedded environments where they aren't normally available. +// Turn this off if the framework/hardware being targetted offers new/delete +// and enable it if new/delete are unavailable. +#define CPP_MEMORY_OPERATORS 1 + // Variable Tickrate // // This controls whether the setTickrate function is available and @@ -562,6 +584,9 @@ // get the global brightness of the device #define EDITOR_VERB_GET_GLOBAL_BRIGHTNESS "M" +// set the global brightness of the chromalinked duo +#define EDITOR_VERB_SET_CHROMA_BRIGHTNESS "N" + // =================================================================== // Manually Configured Sizes // @@ -618,6 +643,10 @@ #define RGB_MENU_BRIGHTNESS_SELECT RGB_YELLOW4 #define RGB_MENU_FACTORY_RESET RGB_RED4 +// vortex lib doesn't need custom memory operators for cpp +#undef CPP_MEMORY_OPERATORS +#define CPP_MEMORY_OPERATORS 0 + #endif // ifdef VORTEX_LIB // This will be defined if the project is being built inside the test framework diff --git a/VortexEngine/src/VortexEngine.cpp b/VortexEngine/src/VortexEngine.cpp index 8afc4f4165..3781018763 100644 --- a/VortexEngine/src/VortexEngine.cpp +++ b/VortexEngine/src/VortexEngine.cpp @@ -41,12 +41,12 @@ bool VortexEngine::init() #endif // all of the global controllers - if (!SerialComs::init()) { - DEBUG_LOG("Serial failed to initialize"); + if (!Time::init()) { + // time must init first but can't log failures till serialcomms inits return false; } - if (!Time::init()) { - DEBUG_LOG("Time failed to initialize"); + if (!SerialComs::init()) { + DEBUG_LOG("Serial failed to initialize"); return false; } if (!Storage::init()) { diff --git a/VortexEngine/src/Wireless/IRConfig.h b/VortexEngine/src/Wireless/IRConfig.h index a80afee022..2b2a023b32 100644 --- a/VortexEngine/src/Wireless/IRConfig.h +++ b/VortexEngine/src/Wireless/IRConfig.h @@ -1,12 +1,7 @@ #ifndef IR_CONFIG_H #define IR_CONFIG_H -// Infrared Enable -// -// Whether to enable the Infrared system as a whole -// -#define IR_ENABLE_SENDER 0 -#define IR_ENABLE_RECEIVER 0 +#include "../VortexConfig.h" // the size of IR blocks in bits #define IR_DEFAULT_BLOCK_SIZE 32 diff --git a/VortexEngine/src/Wireless/IRReceiver.cpp b/VortexEngine/src/Wireless/IRReceiver.cpp index 47ec50ef4d..1f467a8995 100644 --- a/VortexEngine/src/Wireless/IRReceiver.cpp +++ b/VortexEngine/src/Wireless/IRReceiver.cpp @@ -178,7 +178,7 @@ void IRReceiver::handleIRTiming(uint32_t diff) break; case READING_DATA_MARK: // classify mark/space based on the timing and write into buffer - m_irData.write1Bit((diff > (IR_TIMING * 2)) ? 1 : 0); + m_irData.write1Bit(diff > (IR_TIMING * 2)); m_recvState = READING_DATA_SPACE; break; case READING_DATA_SPACE: diff --git a/VortexEngine/src/Wireless/IRSender.cpp b/VortexEngine/src/Wireless/IRSender.cpp index a4119926dc..e64ba95c8e 100644 --- a/VortexEngine/src/Wireless/IRSender.cpp +++ b/VortexEngine/src/Wireless/IRSender.cpp @@ -25,8 +25,6 @@ uint32_t IRSender::m_size = 0; uint8_t IRSender::m_numBlocks = 0; // the amount in the final block uint8_t IRSender::m_remainder = 0; -// configuration options for the sender -uint32_t IRSender::m_blockSize = 0; // write total uint32_t IRSender::m_writeCounter = 0; @@ -116,8 +114,8 @@ bool IRSender::send() void IRSender::beginSend() { m_isSending = true; - DEBUG_LOGF("[%zu] Beginning send size %u (blocks: %u remainder: %u blocksize: %u)", - Time::microseconds(), m_size, m_numBlocks, m_remainder, m_blockSize); + DEBUG_LOGF("[%zu] Beginning send size %u (blocks: %u remainder: %u)", + Time::microseconds(), m_size, m_numBlocks, m_remainder); // init sender before writing, is this necessary here? I think so initPWM(); // wakeup the other receiver with a very quick mark/space diff --git a/VortexEngine/src/Wireless/IRSender.h b/VortexEngine/src/Wireless/IRSender.h index d8e9df30eb..61c90902c8 100644 --- a/VortexEngine/src/Wireless/IRSender.h +++ b/VortexEngine/src/Wireless/IRSender.h @@ -23,6 +23,7 @@ class IRSender static bool send(); static bool isSending() { return m_isSending; } + static void stopSending() { m_isSending = false; } static uint32_t percentDone() { return (uint32_t)(((float)m_writeCounter / (float)m_size) * 100.0); } @@ -54,9 +55,6 @@ class IRSender // the amount in the final block static uint8_t m_remainder; - // configuration options for the sender - static uint32_t m_blockSize; - // write total static uint32_t m_writeCounter; }; diff --git a/VortexEngine/src/Wireless/VLConfig.h b/VortexEngine/src/Wireless/VLConfig.h index f10896810c..7dccd0bce1 100644 --- a/VortexEngine/src/Wireless/VLConfig.h +++ b/VortexEngine/src/Wireless/VLConfig.h @@ -3,13 +3,6 @@ #include "../VortexConfig.h" -// Visible Light Enable -// -// Whether to enable the Visible Light system as a whole -// -#define VL_ENABLE_SENDER 1 -#define VL_ENABLE_RECEIVER 1 - // the size of IR blocks in bits #define VL_DEFAULT_BLOCK_SIZE 256 #define VL_DEFAULT_BLOCK_SPACING MS_TO_TICKS(5) @@ -28,7 +21,12 @@ // These are the modern constants for new sender/receiver in modesharing // new one is faster, more reliable, and better at error detection #define VL_TIMING (uint16_t)(2230) +// NOTE! Only the chromadeck uses this 'fast' timing to send, because it's cpu +// is running so much faster it can handle it in the sender code. The Duo +// receiver has no issue with the faster speed but the Duo sender cannot do it +#define VL_TIMING_FAST (uint16_t)(1230) +// despite the faster VL_TIMING the header mark and space must remain the same #define VL_HEADER_MARK (uint16_t)(VL_TIMING * 16) #define VL_HEADER_SPACE (uint16_t)(VL_TIMING * 8) diff --git a/VortexEngine/src/Wireless/VLReceiver.cpp b/VortexEngine/src/Wireless/VLReceiver.cpp index 96e1d9972d..ea5d6cf500 100644 --- a/VortexEngine/src/Wireless/VLReceiver.cpp +++ b/VortexEngine/src/Wireless/VLReceiver.cpp @@ -1,5 +1,5 @@ #include "VLReceiver.h" -#include "IRConfig.h" +#include "VLConfig.h" #if VL_ENABLE_RECEIVER == 1 diff --git a/VortexEngine/src/Wireless/VLSender.cpp b/VortexEngine/src/Wireless/VLSender.cpp index 9abdb9d0f8..56c52a65f0 100644 --- a/VortexEngine/src/Wireless/VLSender.cpp +++ b/VortexEngine/src/Wireless/VLSender.cpp @@ -1,5 +1,4 @@ #include "VLSender.h" -#include "IRConfig.h" #if VL_ENABLE_SENDER == 1