Skip to content

Commit

Permalink
Merge pull request #114 from i-am-grub/master
Browse files Browse the repository at this point in the history
Generic Race Timer Backpack
  • Loading branch information
pkendall64 committed Apr 28, 2024
2 parents a7458e0 + d5a6e2f commit 5d7da05
Show file tree
Hide file tree
Showing 14 changed files with 1,004 additions and 18 deletions.
46 changes: 46 additions & 0 deletions hardware/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,5 +438,51 @@
"platform": "esp8285"
}
}
},
"timer": {
"name": "Generic backpack for any Race Timer",
"timer": {
"esp32": {
"product_name": "Backpack for Race Timer with ESP32",
"firmware": "TIMER_ESP32_Backpack",
"upload_methods": ["uart", "wifi"],
"platform": "esp32"
},
"esp82": {
"product_name": "Backpack for Race Timer with ESP82",
"firmware": "TIMER_ESP82_Backpack",
"upload_methods": ["uart", "wifi"],
"platform": "esp8285"
},
"esp12f": {
"product_name": "Backpack for Race Timer with ESP12F",
"firmware": "TIMER_ESP12F_Backpack",
"upload_methods": ["uart", "wifi"],
"platform": "esp8285"
}
}
},
"rotorhazard": {
"name": "RotorHazard",
"timer": {
"esp32": {
"product_name": "ESP32 Module (DIY)",
"firmware": "TIMER_ESP32_Backpack",
"upload_methods": ["uart", "wifi"],
"platform": "esp32"
},
"esp82": {
"product_name": "EP82 Module (DIY)",
"firmware": "TIMER_ESP82_Backpack",
"upload_methods": ["uart", "wifi"],
"platform": "esp8285"
},
"NuclearHazard": {
"product_name": "NuclearHazard",
"firmware": "TIMER_ESP32_Backpack",
"upload_methods": ["wifi"],
"platform": "esp32"
}
}
}
}
121 changes: 121 additions & 0 deletions html/timer_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<!DOCTYPE HTML>
<html>

<head>
<title>Welcome to your ExpressLRS System</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="mui.css" />
<link rel="stylesheet" href="elrs.css" />
</head>

<body>
<header class="mui-appbar mui--z1 mui--text-center elrs-header">
<img src="logo.svg" height="250" width="250" style="padding:20px;"></a>
<h1>Welcome to your <b>ExpressLRS</b> update page<br />
</h1>
<p>From here you can update your <b>Race Timer Backpack</b> module with <b>@PLATFORM@</b> firmware<br />
<p>
<b>Firmware Rev. </b><var>@VERSION@</var>
</header>

<br>
<div class="mui-container-fluid">
<div class="mui-panel mui-col-sm-10 mui-col-sm-offset-1">

<ul class="mui-tabs__bar mui-tabs__bar--justified">
<li><a data-mui-toggle="tab" data-mui-controls="pane-justified-1">Backpack</a></li>
<li><a data-mui-toggle="tab" data-mui-controls="pane-justified-2">Network</a></li>
</ul>

<div class="mui-tabs__pane" id="pane-justified-1">
<h2>Backpack Firmware Update</h2>
Here you can update your backpack firmware,
be careful to upload the correct file otherwise a bad flash may occur. If this happens you will need
to reflash via USB/Serial.
<br/>
<br/>
<form id='upload_form_bp' method='POST' enctype='multipart/form-data'>
<div class="group">
<input id='firmware_file_bp' type='file' name='update'>
<input type='submit' value='Update' class='mui-btn mui-btn--primary'>
</div>
<br/>
<h3 id="status_bp"></h3>
<progress id="progressBar_bp" value="0" max="100" style="width:100%;"></progress>
</form>
</div>

<div class="mui-tabs__pane" id="pane-justified-2">
<div id="apmode" style="display:none;">
<div class="mui-panel">
<h2>Join Network</h2>
Here you can join a network and it will be saved as your &quot;home&quot; network.
When you are in range of your &quot;home&quot; network and start WiFi update the backpack will automatically connect.
<form action="/sethome" id="sethome" method="POST" autocomplete="off" class="mui-form">
<div class="autocomplete mui-textfield" style="width: 80%;">
<input id="network" type="text" name="network" placeholder="SSID"/>
</div>
<div id="loader" style="float:right" class="loader"></div>
<div class="mui-textfield" style="width: 80%;">
<input type="password" id="password" name="password" placeholder="Password" />
</div>
<input type="submit" value="Join" class="mui-btn mui-btn--primary">
</form>
</div>
<div class="mui-panel">
<a id="connect" href="#">Connect to &quot;home&quot; network: <span id="homenet"></span></a>
</div>
</div>

<div id="stamode" style="display:none;">
<h2>Home Network: <span id="ssid"></span></h2>
<br>
Forget &quot;home&quot; network and start access point
<br>
<a id="forget" href="#" class="mui-btn mui-btn--primary">Forget</a>
<br><br>
Disconnect from &quot;home&quot; network start access point
<br>
<a id="access" href="#" class="mui-btn mui-btn--primary">Disconnect</a>
</div>
</div>
</div>
</div>
<footer>
<div class="mui-container-fluid">
<div class="mui-row">
<div class="mui--text-center mui-col-xs-4">
<a href="https://github.com/ExpressLRS/Backpack">
<svg width="24" xmlns="http://www.w3.org/2000/svg" aria-label="GitHub" role="img" viewBox="0 0 512 512">
<rect width="512" height="512" rx="15%" fill="#181717"/>
<path fill="#fff" d="M335 499c14 0 12 17 12 17H165s-2-17 12-17c13 0 16-6 16-12l-1-44c-71 16-86-34-86-34-12-30-28-37-28-37-24-16 1-16 1-16 26 2 40 26 40 26 22 39 59 28 74 22 2-17 9-28 16-35-57-6-116-28-116-126 0-28 10-51 26-69-3-6-11-32 3-67 0 0 21-7 70 26 42-12 86-12 128 0 49-33 70-26 70-26 14 35 6 61 3 67 16 18 26 41 26 69 0 98-60 120-117 126 10 8 18 24 18 48l-1 70c0 6 3 12 16 12z"/>
</svg>
GitHub
</a>
</div>
<div class="mui--text-center mui-col-xs-4">
<a href="https://discord.gg/dS6ReFY">
<svg width="24" fill="#5865f2" aria-label="Discord" role="img" version="1.1" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
<rect width="512" height="512" rx="15%" fill="#fff"/>
<path d="m386 137c-24-11-49.5-19-76.3-23.7c-.5 0-1 0-1.2.6c-3.3 5.9-7 13.5-9.5 19.5c-29-4.3-57.5-4.3-85.7 0c-2.6-6.2-6.3-13.7-10-19.5c-.3-.4-.7-.7-1.2-.6c-23 4.6-52.4 13-76 23.7c-.2 0-.4.2-.5.4c-49 73-62 143-55 213c0 .3.2.7.5 1c32 23.6 63 38 93.6 47.3c.5 0 1 0 1.3-.4c7.2-9.8 13.6-20.2 19.2-31.2c.3-.6 0-1.4-.7-1.6c-10-4-20-8.6-29.3-14c-.7-.4-.8-1.5 0-2c2-1.5 4-3 5.8-4.5c.3-.3.8-.3 1.2-.2c61.4 28 128 28 188 0c.4-.2.9-.1 1.2.1c1.9 1.6 3.8 3.1 5.8 4.6c.7.5.6 1.6 0 2c-9.3 5.5-19 10-29.3 14c-.7.3-1 1-.6 1.7c5.6 11 12.1 21.3 19 31c.3.4.8.6 1.3.4c30.6-9.5 61.7-23.8 93.8-47.3c.3-.2.5-.5.5-1c7.8-80.9-13.1-151-55.4-213c0-.2-.3-.4-.5-.4Zm-192 171c-19 0-34-17-34-38c0-21 15-38 34-38c19 0 34 17 34 38c0 21-15 38-34 38zm125 0c-19 0-34-17-34-38c0-21 15-38 34-38c19 0 34 17 34 38c0 21-15 38-34 38z" fill="#5865f2"/>
</svg>
Discord
</a>
</div>
<div class="mui--text-center mui-col-xs-4">
<a href="https://www.facebook.com/groups/636441730280366">
<svg width="24" xmlns="http://www.w3.org/2000/svg" aria-label="Facebook" role="img" viewBox="0 0 512 512">
<rect width="512" height="512" rx="15%" fill="#1877f2"/>
<path d="M355.6 330l11.4-74h-71v-48c0-20.2 9.9-40 41.7-40H370v-63s-29.3-5-57.3-5c-58.5 0-96.7 35.4-96.7 99.6V256h-65v74h65v182h80V330h59.6z" fill="#fff"/>
</svg>
Facebook
</a>
</div>
</div>
</div>
</footer>
</body>
<script src="mui.js"></script>
<script src="scan.js"></script>
</html>
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_timer";
static const char *wifi_ap_ssid = "ExpressLRS Timer Backpack";
#else
#error Unknown target
#endif
Expand Down Expand Up @@ -501,6 +508,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 @@ -522,6 +531,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.ini
# defined one by one to maintain the order
targets/fusion.ini
targets/hdzero.ini
Expand Down
Loading

0 comments on commit 5d7da05

Please sign in to comment.