Skip to content

Commit

Permalink
The init delay was broken as part of the refactoring in 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
pkendall64 committed Jan 28, 2023
1 parent 5eeab17 commit 34f7f60
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 49 deletions.
10 changes: 4 additions & 6 deletions src/Vrx_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -403,6 +400,7 @@ void setup()
#if defined(HDZERO_BACKPACK)
Serial.begin(VRX_UART_BAUD);
#endif
start_time = millis();
DBGLN("Setup completed");
}

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/fusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/fusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#include "module_base.h"
#include <Arduino.h>

#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] = {
Expand Down
8 changes: 4 additions & 4 deletions src/hdzero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -48,7 +48,7 @@ HDZero::GetChannelIndex()

void
HDZero::SetChannelIndex(uint8_t index)
{
{
MSP msp;
mspPacket_t packet;
packet.reset();
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/hdzero.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include "module_base.h"
#include <Arduino.h>

#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

Expand Down
4 changes: 2 additions & 2 deletions src/module_base.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/module_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

#include <Arduino.h>

#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);
Expand Down
5 changes: 5 additions & 0 deletions src/orqa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/orqa.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <crc.h>

#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);
Expand Down
10 changes: 5 additions & 5 deletions src/rapidfire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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; // '>'
Expand All @@ -59,7 +59,7 @@ Rapidfire::SendBuzzerCmd()

void
Rapidfire::SendIndexCmd(uint8_t index)
{
{
uint8_t newBand = index / 8 + 1;
uint8_t newChannel = index % 8;

Expand Down Expand Up @@ -194,7 +194,7 @@ Rapidfire::SendSPI(uint8_t* buf, uint8_t bufLen)
digitalWrite(PIN_CLK, HIGH);
delayMicroseconds(periodMicroSec / 2);

bufByte <<= 1;
bufByte <<= 1;
}
}
DBGLN("");
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/rapidfire.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#include "module_base.h"
#include <Arduino.h>

#undef VRX_BOOT_DELAY
#define VRX_BOOT_DELAY 2000

#define BIT_BANG_FREQ 1000
#define SPAM_COUNT 3

Expand Down
14 changes: 7 additions & 7 deletions src/rx5808.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
void
RX5808::Init()
{
ModuleBase::Init();
ModuleBase::Init(0);

pinMode(PIN_MOSI, INPUT);
pinMode(PIN_CLK, INPUT);
pinMode(PIN_CS, INPUT);
Expand Down Expand Up @@ -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);
Expand All @@ -62,7 +62,7 @@ RX5808::SendIndexCmd(uint8_t index)
void
RX5808::rtc6705WriteRegister(uint32_t buf)
{
if (!SPIModeEnabled)
if (!SPIModeEnabled)
{
EnableSPIMode();
}
Expand All @@ -84,7 +84,7 @@ RX5808::rtc6705WriteRegister(uint32_t buf)
digitalWrite(PIN_CLK, HIGH);
delayMicroseconds(periodMicroSec / 2);

buf >>= 1;
buf >>= 1;
}

digitalWrite(PIN_CLK, LOW);
Expand All @@ -100,7 +100,7 @@ RX5808::rtc6705WriteRegister(uint32_t buf)
uint32_t
RX5808::rtc6705readRegister(uint8_t readRegister)
{
if (!SPIModeEnabled)
if (!SPIModeEnabled)
{
EnableSPIMode();
}
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/skyzone_msp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -49,7 +49,7 @@ SkyzoneMSP::GetChannelIndex()

void
SkyzoneMSP::SetChannelIndex(uint8_t index)
{
{
MSP msp;
mspPacket_t packet;
packet.reset();
Expand Down Expand Up @@ -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();
Expand All @@ -101,7 +101,7 @@ void
SkyzoneMSP::SendRecordingState()
{
DBGLN("SendRecordingState = %d delay = %d", m_recordingState, m_delay);

MSP msp;
mspPacket_t packet;
packet.reset();
Expand Down
3 changes: 0 additions & 3 deletions src/skyzone_msp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include "module_base.h"
#include <Arduino.h>

#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

Expand Down
4 changes: 2 additions & 2 deletions src/steadyview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
void
SteadyView::Init()
{
ModuleBase::Init();
ModuleBase::Init(0);

pinMode(PIN_MOSI, OUTPUT);
pinMode(PIN_CLK, OUTPUT);
pinMode(PIN_CS, OUTPUT);
Expand Down

0 comments on commit 34f7f60

Please sign in to comment.