diff --git a/src/Vrx_main.cpp b/src/Vrx_main.cpp index b95f72d..40b4742 100644 --- a/src/Vrx_main.cpp +++ b/src/Vrx_main.cpp @@ -44,10 +44,6 @@ #define NO_BINDING_TIMEOUT 120000 #define BINDING_LED_PAUSE 1000 -#if !defined(VRX_BOOT_DELAY) - #define VRX_BOOT_DELAY 0 -#endif - #if !defined(VRX_UART_BAUD) #define VRX_UART_BAUD 460800 #endif @@ -67,6 +63,7 @@ uint8_t cachedIndex = 0; bool sendChangesToVrx = false; bool gotInitialPacket = false; uint32_t lastSentRequest = 0; +uint32_t start_time = 0; device_t *ui_devices[] = { #ifdef PIN_LED @@ -403,6 +400,7 @@ void setup() #if defined(HDZERO_BACKPACK) Serial.begin(VRX_UART_BAUD); #endif + start_time = millis(); DBGLN("Setup completed"); } @@ -436,9 +434,9 @@ void loop() sendChangesToVrx = false; vrxModule.SendIndexCmd(cachedIndex); } - + // spam out a bunch of requests for the desired band/channel for the first 5s - if (!gotInitialPacket && now - VRX_BOOT_DELAY < 5000 && now - lastSentRequest > 1000 && connectionState != binding) + if (!gotInitialPacket && now - start_time < 5000 && now - lastSentRequest > 1000 && connectionState != binding) { DBGLN("RequestVTXPacket..."); RequestVTXPacket(); diff --git a/src/fusion.cpp b/src/fusion.cpp index 48f8a78..72d234c 100644 --- a/src/fusion.cpp +++ b/src/fusion.cpp @@ -9,13 +9,13 @@ GENERIC_CRC8 crsf_crc(CRSF_CRC_POLY); void Fusion::Init() { - ModuleBase::Init(); + ModuleBase::Init(1000); DBGLN("Fusion backpack init complete"); } void Fusion::SendIndexCmd(uint8_t index) -{ +{ uint16_t f = frequencyTable[index]; uint8_t buf[12]; uint8_t pos = 0; diff --git a/src/fusion.h b/src/fusion.h index 74858a8..c8a967f 100644 --- a/src/fusion.h +++ b/src/fusion.h @@ -3,9 +3,6 @@ #include "module_base.h" #include -#undef VRX_BOOT_DELAY -#define VRX_BOOT_DELAY 1000 - #define VRX_UART_BAUD 500000 // fusion uses 500k baud between the ESP8266 and the STM32 const uint16_t frequencyTable[48] = { diff --git a/src/hdzero.cpp b/src/hdzero.cpp index d18a70b..f1077fd 100644 --- a/src/hdzero.cpp +++ b/src/hdzero.cpp @@ -10,12 +10,12 @@ HDZero::HDZero(Stream *port) void HDZero::Init() { - ModuleBase::Init(); + ModuleBase::Init(7000); } void HDZero::SendIndexCmd(uint8_t index) -{ +{ uint8_t retries = 3; while (GetChannelIndex() != index && retries > 0) { @@ -48,7 +48,7 @@ HDZero::GetChannelIndex() void HDZero::SetChannelIndex(uint8_t index) -{ +{ MSP msp; mspPacket_t packet; packet.reset(); @@ -85,7 +85,7 @@ void HDZero::SetRecordingState(uint8_t recordingState, uint16_t delay) { DBGLN("SetRecordingState = %d delay = %d", recordingState, delay); - + MSP msp; mspPacket_t packet; packet.reset(); diff --git a/src/hdzero.h b/src/hdzero.h index 0403f3d..eb4ec37 100644 --- a/src/hdzero.h +++ b/src/hdzero.h @@ -5,9 +5,6 @@ #include "module_base.h" #include -#undef VRX_BOOT_DELAY -#define VRX_BOOT_DELAY 7000 - #define VRX_RESPONSE_TIMEOUT 500 #define VRX_UART_BAUD 115200 // hdzero uses 115k baud between the ESP8285 and the STM32 diff --git a/src/module_base.cpp b/src/module_base.cpp index a03af49..88c5fbc 100644 --- a/src/module_base.cpp +++ b/src/module_base.cpp @@ -1,9 +1,9 @@ #include "module_base.h" void -ModuleBase::Init() +ModuleBase::Init(uint32_t delay_ms) { - delay(VRX_BOOT_DELAY); + delay(delay_ms); } void diff --git a/src/module_base.h b/src/module_base.h index 283ffb5..6187271 100644 --- a/src/module_base.h +++ b/src/module_base.h @@ -2,12 +2,10 @@ #include -#define VRX_BOOT_DELAY 0 - class ModuleBase { public: - void Init(); + void Init(uint32_t delay_ms); void SendIndexCmd(uint8_t index); void SetRecordingState(uint8_t recordingState, uint16_t delay); void Loop(uint32_t now); diff --git a/src/orqa.cpp b/src/orqa.cpp index afd4e0d..a62b2d6 100644 --- a/src/orqa.cpp +++ b/src/orqa.cpp @@ -2,6 +2,11 @@ GENERIC_CRC8 ghst_crc(GHST_CRC_POLY); +void Orqa::Init() +{ + ModuleBase::Init(7000); +} + void Orqa::SendIndexCmd(uint8_t index) { uint8_t band = GetBand(index); diff --git a/src/orqa.h b/src/orqa.h index 71e1fc7..1a9f430 100644 --- a/src/orqa.h +++ b/src/orqa.h @@ -5,12 +5,12 @@ #include #define VRX_UART_BAUD 100000 -#define VRX_BOOT_DELAY 7000 #define GHST_CRC_POLY 0xD5 class Orqa : public ModuleBase { public: + void Init(); void SendIndexCmd(uint8_t index); private: uint8_t GHSTChannel(uint8_t band, uint8_t channel); diff --git a/src/rapidfire.cpp b/src/rapidfire.cpp index d36fbd3..f7a58e9 100644 --- a/src/rapidfire.cpp +++ b/src/rapidfire.cpp @@ -5,7 +5,7 @@ void Rapidfire::Init() { - ModuleBase::Init(); + ModuleBase::Init(2000); EnableSPIMode(); // https://github.com/ExpressLRS/ExpressLRS/pull/1489 & https://github.com/ExpressLRS/Backpack/pull/65 @@ -44,7 +44,7 @@ void Rapidfire::SendBuzzerCmd() { DBGLN("Beep!"); - + uint8_t cmd[4]; cmd[0] = RF_API_BEEP_CMD; // 'S' cmd[1] = RF_API_DIR_GRTHAN; // '>' @@ -59,7 +59,7 @@ Rapidfire::SendBuzzerCmd() void Rapidfire::SendIndexCmd(uint8_t index) -{ +{ uint8_t newBand = index / 8 + 1; uint8_t newChannel = index % 8; @@ -194,7 +194,7 @@ Rapidfire::SendSPI(uint8_t* buf, uint8_t bufLen) digitalWrite(PIN_CLK, HIGH); delayMicroseconds(periodMicroSec / 2); - bufByte <<= 1; + bufByte <<= 1; } } DBGLN(""); @@ -203,7 +203,7 @@ Rapidfire::SendSPI(uint8_t* buf, uint8_t bufLen) digitalWrite(PIN_CLK, LOW); digitalWrite(PIN_CS, HIGH); delay(100); - + pinMode(PIN_MOSI, INPUT); pinMode(PIN_CLK, INPUT); pinMode(PIN_CS, INPUT); diff --git a/src/rapidfire.h b/src/rapidfire.h index 370486c..937041c 100644 --- a/src/rapidfire.h +++ b/src/rapidfire.h @@ -3,9 +3,6 @@ #include "module_base.h" #include -#undef VRX_BOOT_DELAY -#define VRX_BOOT_DELAY 2000 - #define BIT_BANG_FREQ 1000 #define SPAM_COUNT 3 diff --git a/src/rx5808.cpp b/src/rx5808.cpp index 00f4d40..6713ee4 100644 --- a/src/rx5808.cpp +++ b/src/rx5808.cpp @@ -5,8 +5,8 @@ void RX5808::Init() { - ModuleBase::Init(); - + ModuleBase::Init(0); + pinMode(PIN_MOSI, INPUT); pinMode(PIN_CLK, INPUT); pinMode(PIN_CS, INPUT); @@ -46,7 +46,7 @@ RX5808::SendIndexCmd(uint8_t index) DBGLN("%x", index); uint16_t f = frequencyTable[index]; - + uint32_t data = ((((f - 479) / 2) / 32) << 7) | (((f - 479) / 2) % 32); uint32_t newRegisterData = SYNTHESIZER_REG_B | (RX5808_WRITE_CTRL_BIT << 4) | (data << 5); @@ -62,7 +62,7 @@ RX5808::SendIndexCmd(uint8_t index) void RX5808::rtc6705WriteRegister(uint32_t buf) { - if (!SPIModeEnabled) + if (!SPIModeEnabled) { EnableSPIMode(); } @@ -84,7 +84,7 @@ RX5808::rtc6705WriteRegister(uint32_t buf) digitalWrite(PIN_CLK, HIGH); delayMicroseconds(periodMicroSec / 2); - buf >>= 1; + buf >>= 1; } digitalWrite(PIN_CLK, LOW); @@ -100,7 +100,7 @@ RX5808::rtc6705WriteRegister(uint32_t buf) uint32_t RX5808::rtc6705readRegister(uint8_t readRegister) { - if (!SPIModeEnabled) + if (!SPIModeEnabled) { EnableSPIMode(); } @@ -123,7 +123,7 @@ RX5808::rtc6705readRegister(uint8_t readRegister) digitalWrite(PIN_CLK, HIGH); delayMicroseconds(periodMicroSec / 2); - buf >>= 1; + buf >>= 1; } // Change pin from output to input diff --git a/src/skyzone_msp.cpp b/src/skyzone_msp.cpp index c7d98b9..ca77935 100644 --- a/src/skyzone_msp.cpp +++ b/src/skyzone_msp.cpp @@ -10,13 +10,13 @@ SkyzoneMSP::SkyzoneMSP(Stream *port) void SkyzoneMSP::Init() { - ModuleBase::Init(); + ModuleBase::Init(2000); m_delay = 0; } void SkyzoneMSP::SendIndexCmd(uint8_t index) -{ +{ uint8_t retries = 3; while (GetChannelIndex() != index && retries > 0) { @@ -49,7 +49,7 @@ SkyzoneMSP::GetChannelIndex() void SkyzoneMSP::SetChannelIndex(uint8_t index) -{ +{ MSP msp; mspPacket_t packet; packet.reset(); @@ -86,7 +86,7 @@ void SkyzoneMSP::SetRecordingState(uint8_t recordingState, uint16_t delay) { DBGLN("SetRecordingState = %d delay = %d", recordingState, delay); - + m_recordingState = recordingState; m_delay = delay * 1000; // delay is in seconds, convert to milliseconds m_delayStartMillis = millis(); @@ -101,7 +101,7 @@ void SkyzoneMSP::SendRecordingState() { DBGLN("SendRecordingState = %d delay = %d", m_recordingState, m_delay); - + MSP msp; mspPacket_t packet; packet.reset(); diff --git a/src/skyzone_msp.h b/src/skyzone_msp.h index 4c41db9..d815cc3 100644 --- a/src/skyzone_msp.h +++ b/src/skyzone_msp.h @@ -5,9 +5,6 @@ #include "module_base.h" #include -#undef VRX_BOOT_DELAY -#define VRX_BOOT_DELAY 2000 - #define VRX_RESPONSE_TIMEOUT 500 #define VRX_UART_BAUD 115200 // skyzone uses 115k baud between the ESP32-PICO and their MCU diff --git a/src/steadyview.cpp b/src/steadyview.cpp index eaf9cde..9609b02 100644 --- a/src/steadyview.cpp +++ b/src/steadyview.cpp @@ -5,8 +5,8 @@ void SteadyView::Init() { - ModuleBase::Init(); - + ModuleBase::Init(0); + pinMode(PIN_MOSI, OUTPUT); pinMode(PIN_CLK, OUTPUT); pinMode(PIN_CS, OUTPUT);