Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Race Timer Backpack #114

Merged
merged 10 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions hardware/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,5 +385,16 @@
"platform": "esp8285"
}
}
},
"timer": {
"name": "Generic backpack for any Race Timer",
"timer": {
"esp32": {
"product_name": "RotorHazard ESP32 (DIY)",
"firmware": "ESP_TIMER_Backpack",
"upload_methods": ["uart", "wifi"],
"platform": "esp32"
}
}
}
}
1 change: 1 addition & 0 deletions lib/MSP/msptypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define MSP_ELRS_SET_RX_LOAN_MODE 0x0F
#define MSP_ELRS_GET_BACKPACK_VERSION 0x10
#define MSP_ELRS_BACKPACK_CRSF_TLM 0x11
#define MSP_ELRS_SET_SEND_UID 0x00B5
#define MSP_ELRS_SET_OSD 0x00B6

// CRSF encapsulated msp defines
Expand Down
13 changes: 12 additions & 1 deletion lib/WIFI/devWIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@
#if defined(TARGET_VRX_BACKPACK)
extern VrxBackpackConfig config;
extern bool sendRTCChangesToVrx;
#else
#elif defined(TARGET_TX_BACKPACK)
extern TxBackpackConfig config;
#elif defined(TARGET_TIMER_BACKPACK)
extern TimerBackpackConfig config;
#else
#error Unknown target
#endif
extern unsigned long rebootTime;

Expand All @@ -44,6 +48,9 @@ static const char *wifi_ap_ssid = "ExpressLRS VRx Backpack";
#elif defined(TARGET_TX_BACKPACK)
static const char *myHostname = "elrs_txbp";
static const char *wifi_ap_ssid = "ExpressLRS TX Backpack";
#elif defined(TARGET_TIMER_BACKPACK)
static const char *myHostname = "elrs_timerbp";
static const char *wifi_ap_ssid = "ExpressLRS Timer Backpack";
#else
#error Unknown target
#endif
Expand Down Expand Up @@ -509,6 +516,8 @@ static void startMDNS()
MDNS.addServiceTxt(service, "type", "vrx");
#elif defined(TARGET_TX_BACKPACK)
MDNS.addServiceTxt(service, "type", "txbp");
#elif defined(TARGET_TIMER_BACKPACK)
MDNS.addServiceTxt(service, "type", "timer");
#endif
// If the probe result fails because there is another device on the network with the same name
// use our unique instance name as the hostname. A better way to do this would be to use
Expand All @@ -530,6 +539,8 @@ static void startMDNS()
MDNS.addServiceTxt("http", "tcp", "type", "vrx");
#elif defined(TARGET_TX_BACKPACK)
MDNS.addServiceTxt("http", "tcp", "type", "txbp");
#elif defined(TARGET_TIMER_BACKPACK)
MDNS.addServiceTxt("http", "tcp", "type", "timer");
#endif
#endif
}
Expand Down
96 changes: 96 additions & 0 deletions lib/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,99 @@ VrxBackpackConfig::SetStartWiFiOnBoot(bool startWifi)
}

#endif

/////////////////////////////////////////////////////

#if defined(TARGET_TIMER_BACKPACK)

void
TimerBackpackConfig::Load()
{
m_eeprom->Get(0, m_config);
m_modified = 0;

// Check if version number matches
if (m_config.version != (uint32_t)(TIMER_BACKPACK_CONFIG_VERSION | TIMER_BACKPACK_CONFIG_MAGIC))
{
// If not, revert to defaults for this version
DBGLN("EEPROM version mismatch! Resetting to defaults...");
SetDefaults();
}

m_modified = false;
}

void
TimerBackpackConfig::Commit()
{
if (!m_modified)
{
// No changes
return;
}
// Write the struct to eeprom
m_eeprom->Put(0, m_config);
m_eeprom->Commit();

m_modified = false;
}

// Setters
void
TimerBackpackConfig::SetStorageProvider(ELRS_EEPROM *eeprom)
{
if (eeprom)
{
m_eeprom = eeprom;
}
}

void
TimerBackpackConfig::SetDefaults()
{
m_config.version = TIMER_BACKPACK_CONFIG_VERSION | TIMER_BACKPACK_CONFIG_MAGIC;
m_config.bootCount = 0;
m_config.startWiFi = false;
m_config.ssid[0] = 0;
m_config.password[0] = 0;
memset(m_config.address, 0, 6);
m_modified = true;
Commit();
}

void
TimerBackpackConfig::SetStartWiFiOnBoot(bool startWifi)
{
m_config.startWiFi = startWifi;
m_modified = true;
}

void
TimerBackpackConfig::SetSSID(const char *ssid)
{
strcpy(m_config.ssid, ssid);
m_modified = true;
}

void
TimerBackpackConfig::SetPassword(const char *password)
{
strcpy(m_config.password, password);
m_modified = true;
}

void
TimerBackpackConfig::SetGroupAddress(const uint8_t address[6])
{
memcpy(m_config.address, address, 6);
m_modified = true;
}

void
TimerBackpackConfig::SetBootCount(uint8_t count)
{
m_config.bootCount = count;
m_modified = true;
}

#endif
47 changes: 47 additions & 0 deletions lib/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
// CONFIG_MAGIC is ORed with CONFIG_VERSION in the version field
#define TX_BACKPACK_CONFIG_MAGIC (0b01 << 30)
#define VRX_BACKPACK_CONFIG_MAGIC (0b10 << 30)
#define TIMER_BACKPACK_CONFIG_MAGIC (0b11 << 30)

#define TX_BACKPACK_CONFIG_VERSION 3
#define VRX_BACKPACK_CONFIG_VERSION 3
#define TIMER_BACKPACK_CONFIG_VERSION 3

#if defined(TARGET_TX_BACKPACK)
typedef struct {
Expand Down Expand Up @@ -93,3 +95,48 @@ class VrxBackpackConfig
extern VrxBackpackConfig config;

#endif

///////////////////////////////////////////////////

#if defined(TARGET_TIMER_BACKPACK)
typedef struct {
uint32_t version;
uint8_t bootCount;
bool startWiFi;
char ssid[33];
char password[65];
uint8_t address[6];
} timer_backpack_config_t;

class TimerBackpackConfig
{
public:
void Load();
void Commit();

// Getters
bool IsModified() const { return m_modified; }
uint8_t GetBootCount() { return m_config.bootCount; }
bool GetStartWiFiOnBoot() { return m_config.startWiFi; }
char *GetSSID() { return m_config.ssid; }
char *GetPassword() { return m_config.password; }
uint8_t *GetGroupAddress() { return m_config.address; }

// Setters
void SetStorageProvider(ELRS_EEPROM *eeprom);
void SetDefaults();
void SetBootCount(uint8_t count);
void SetStartWiFiOnBoot(bool startWifi);
void SetSSID(const char *ssid);
void SetPassword(const char *ssid);
void SetGroupAddress(const uint8_t address[6]);

private:
timer_backpack_config_t m_config;
ELRS_EEPROM *m_eeprom;
bool m_modified;
};

extern TimerBackpackConfig config;

#endif
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extra_configs =
targets/debug.ini
targets/txbp_esp.ini
targets/txbp_stm.ini
targets/timer_esp.ini
# defined one by one to maintain the order
targets/fusion.ini
targets/hdzero.ini
Expand Down
Loading
Loading