Skip to content

Commit

Permalink
Allow flashing an RX as TX when passing the expert query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
pkendall64 committed Jul 6, 2024
1 parent 56dbbb8 commit 6786fc5
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 34 deletions.
55 changes: 33 additions & 22 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@
<div class="mui-select">
<select name="version" id="version">
</select>
<label>Version</label>
<label for="version">Version</label>
</div>
<div class="mui-select">
<select name="vendor" id="vendor" disabled>
<option value="" disabled selected></option>
</select>
<label>Vendor</label>
<label for="vendor">Vendor</label>
</div>
<div class="mui-select">
<select name="type" id="type" disabled>
Expand All @@ -88,11 +88,22 @@
<option value="tx_dual" id="tx_dual" disabled>Dual Frequency 2.4GHz/900Mhz Transmitter</option>
<option value="rx_dual" id="rx_dual" disabled>Dual Frequency 2.4GHz/900Mhz Receiver</option>
</select>
<label>Device Type</label>
<label for="type">Device Type</label>
</div>
<div class="mui-textfield">
<input name="model" id="model" type="text" autocomplete="off" placeholder="Start typing for auto-complete..."/>
<label>Device Model</label>
<label for="model">Device Model</label>
</div>
<div class="mui-checkbox rx-as-tx display--none" >
<input name="rx-as-tx" id="rx-as-tx" type="checkbox">
<label for="rx-as-tx">Flash Recevier as a Transmitter</label>
</div>
<div class="mui-select rx-as-tx-connection display--none">
<select name="connection" id="connection">
<option value="internal" id="internal" selected>Internal (Full duplex)</option>
<option value="external" id="external">External (Half duplex)</option>
</select>
<label for="connection">Connection Type</label>
</div>
<div class="mui--pull-left">
<a class="mui-btn" href="" download="elrsV3.lua" id="download-lua">Download ELRS Lua Script</a>
Expand All @@ -115,15 +126,15 @@
</div>
<div class="mui-textfield">
<input size='40' id='uid' name='uid' type='text' class='array' readonly />
<label>UID (Auto updated by changing the bind-phrase above)</label>
<label for="uid">UID (Auto updated by changing the bind-phrase above)</label>
</div>

<div class="mui-select tx_2400 rx_2400 display--none">
<select id='fcclbt' name='fcclbt'>
<option value='FCC' selected>FCC</option>
<option value='LBT'>LBT</option>
</select>
<label>Region</label>
<label for="fcclbt">Region</label>
</div>
<div class="mui-select tx_900 rx_900 tx_dual rx_dual display--none">
<select id='domain' name='domain'>
Expand All @@ -134,40 +145,40 @@
<option value='4'>AU433</option>
<option value='5'>EU433</option>
</select>
<label>Regulatory domain</label>
<label for="domain">Regulatory domain</label>
</div>

<div class="esp8285 esp32 display--none">
<div class="mui-textfield mui-textfield--float-label">
<input size='32' id='wifi-ssid' name='wifi-ssid' type='text' value="" />
<label>WiFi SSID</label>
<label for="wifi-ssid">WiFi SSID</label>
</div>
<div class="mui-textfield mui-textfield--float-label">
<input size='64' id='wifi-password' name='wifi-password' type='password' value="" />
<label>WiFi Password</label>
<label for="wifi-password">WiFi Password</label>
</div>
<div class="mui-textfield mui-textfield--float-label">
<input size='3' id='wifi-on-interval' name='wifi-on-interval' type='text' value="60" />
<label>WiFi "auto on" interval (s)</label>
<label for="wifi-on-interval">WiFi "auto on" interval (s)</label>
</div>
</div>

<div class="tx_2400 tx_900 display--none">
<div class="mui-textfield mui-textfield--float-label">
<input size='5' id='tlm-interval' name='tlm-interval' type='text' value="240" />
<label>TLM report interval (ms)</label>
<label for="tlm-interval">TLM report interval (ms)</label>
</div>
<div class="mui-checkbox esp32">
<input id='uart-inverted' name='uart-inverted' type='checkbox' checked />
<label>UART inverted</label>
<label for="uart-inverted">UART inverted</label>
</div>
<div class="mui-textfield mui-textfield--float-label feature-fan">
<input size='3' id='fan-runtime' name='fan-runtime' type='text' value="30" />
<label>Fan runtime (s)</label>
<label for="fan-runtime">Fan runtime (s)</label>
</div>
<div class="mui-checkbox feature-unlock-higher-power">
<input id='unlock-higher-power' name='unlock-higher-power' type='checkbox' />
<label>Unlock higher power</label>
<label for="unlock-higher-power">Unlock higher power</label>
</div>
<div class="feature-buzzer">
<div class="mui-select">
Expand All @@ -182,27 +193,27 @@
</div>
<div class="mui-textfield mui-textfield--float-label">
<input id='melody' name='melody' type='text' value="" />
<label>Melody</label>
<label for="melody">Melody</label>
</div>
</div>
</div>

<div class="rx_900 rx_2400 display--none">
<div class="mui-textfield mui-textfield--float-label">
<input size='7' id='rcvr-uart-baud' name='rcvr-uart-baud' type='text' value="420000" />
<label>UART baud</label>
<label for="rcvr-uart-baud">UART baud</label>
</div>
<div class="mui-checkbox feature-sbus-uart">
<input id='r9mm-mini-sbus' name='r9mm-mini-sbus' type='checkbox' />
<label>Use SBUS Pins as UART</label>
<label for="r9mm-mini-sbus">Use SBUS Pins as UART</label>
</div>
<div class="mui-checkbox esp8285 esp32">
<input id='rcvr-invert-tx' name='rcvr-invert-tx' type='checkbox' />
<label>Invert TX pin</label>
<label for="rcvr-invert-tx">Invert TX pin</label>
</div>
<div class="mui-checkbox">
<input id='lock-on-first-connection' name='lock-on-first-connection' type='checkbox' checked />
<label>Lock on first connection</label>
<label for="lock-on-first-connection">Lock on first connection</label>
</div>
</div>

Expand All @@ -216,7 +227,7 @@
<option value="wifi" id="wifi">WiFi</option>
<option value="stlink" id="stlink">STLink</option>
</select>
<label>Flashing Method</label>
<label for="method">Flashing Method</label>
</div>

<div class="mui--pull-right">
Expand All @@ -238,11 +249,11 @@
<div class="uart betaflight etx stlink display--none">
<div class="mui-checkbox esp8285 esp32 display--none">
<input id='erase-flash' type='checkbox' />
<label>Erase flash first?</label>
<label for="erase-flash">Erase flash first?</label>
</div>
<div class="mui-checkbox stlink display--none">
<input id='flash-bootloader' type='checkbox' />
<label>Also flash bootloader?</label>
<label for="flash-bootloader">Also flash bootloader?</label>
</div>
</div>
<button class="mui-btn mui-btn--primary" id="flashButton">Flash</button>
Expand Down
16 changes: 9 additions & 7 deletions src/js/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ export class Configure {
)
}

static download = async (deviceType, radioType, config, firmwareUrl, options) => {
static download = async (deviceType, rxAsTxType, radioType, config, firmwareUrl, options) => {
if (rxAsTxType !== undefined) firmwareUrl = firmwareUrl.replace('_RX', '_TX')
if (config.platform === 'stm32') {
const entry = await this.#fetch_file(firmwareUrl, 0, (bin) => this.#configureSTM32(bin, deviceType, radioType, options))
return [entry]
Expand All @@ -201,14 +202,15 @@ export class Configure {
// get layout from version specific folder OR fall back to global folder
const hardwareLayoutFile = await this.#fetch_file(`${folder}/hardware/${deviceType}/${config.layout_file}`, 0)
.catch(() => this.#fetch_file(`firmware/hardware/${deviceType}/${config.layout_file}`, 0))
if (config.overlay === undefined) {
hardwareLayoutData = hardwareLayoutFile.data
} else {
hardwareLayoutData = this.#bstrToUi8(JSON.stringify({
...JSON.parse(this.#ui8ToBstr(hardwareLayoutFile.data)),
let layout = JSON.parse(this.#ui8ToBstr(hardwareLayoutFile.data))
if (config.overlay !== undefined) {
layout = {
...layout,
...config.overlay
}))
}
}
if (rxAsTxType === 'external') layout['serial_rx'] = layout['serial_tx']
hardwareLayoutData = this.#bstrToUi8(JSON.stringify(layout))
}

if (config.platform.startsWith('esp32')) {
Expand Down
56 changes: 51 additions & 5 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let binary = null
let term = null
let stlink = null
let uploadURL = null
let expertMode = false

document.addEventListener('DOMContentLoaded', initialise, false)

Expand Down Expand Up @@ -238,6 +239,8 @@ const compareSemanticVersionsRC = (a, b) => {
}

async function initialise () {
expertMode = new URLSearchParams(location.search).has("expert")
console.log("Expert mode: %s", expertMode)
checkProxy()
setInterval(() => { checkProxy() }, 30000)
term = new Terminal()
Expand Down Expand Up @@ -396,6 +399,8 @@ typeSelect.onchange = () => {
models.push(hardware[v][t][m].product_name)
}
}
if (t.startsWith('rx_')) setDisplay('.rx-as-tx', expertMode)
else setDisplay('.rx-as-tx', false)
autocomplete(modelSelect, models, true)
}

Expand All @@ -406,6 +411,12 @@ modelSelect.onchange = () => {
if (hardware[v][t][m].product_name === modelSelect.value) {
vendorSelect.value = v
typeSelect.value = t
if (t.startsWith('rx_')) {
setDisplay('.rx-as-tx', expertMode)
}
else {
setDisplay('.rx-as-tx', false)
}
selectedModel = hardware[v][t][m]
typeSelect.disabled = false
deviceNext.disabled = false
Expand All @@ -418,6 +429,33 @@ modelSelect.onchange = () => {
modelSelect.value = ''
}

_('rx-as-tx').onchange = (e) => {
if (e.target.checked) {
for (const v in hardware) {
for (const t in hardware[v]) {
for (const m in hardware[v][t]) {
if (hardware[v][t][m].product_name === modelSelect.value) {
if (hardware[v][t][m].platform === 'esp8285') {
setDisplay('.rx-as-tx-connection', false)
_('connection').value = 'internal'
} else {
setDisplay('.rx-as-tx-connection', true)
_('connection').value = 'internal'
}
}
}
}
}
}
else {
setDisplay('.rx-as-tx-connection', false)
}
}

function adjustedType() {
return _('rx-as-tx').checked ? typeSelect.value.replace('rx_', 'tx_') : typeSelect.value
}

deviceNext.onclick = (e) => {
e.preventDefault()
setDisplay('.tx_2400', false)
Expand All @@ -438,15 +476,21 @@ deviceNext.onclick = (e) => {
if (features) features.forEach(f => setDisplay(`.feature-${f}`))

_('fcclbt').value = 'FCC'
setDisplay(`.${typeSelect.value}`)
setDisplay(`.${adjustedType()}`)
setDisplay(`.${selectedModel.platform}`)

_('uart').disabled = true
_('betaflight').disabled = true
_('etx').disabled = true
_('wifi').disabled = true
_('stlink').disabled = true
selectedModel.upload_methods.forEach((k) => { if (_(k)) _(k).disabled = false })
if (_('rx-as-tx').checked) {
_('uart').disabled = false
_('wifi').disabled = false
}
else {
selectedModel.upload_methods.forEach((k) => { if (_(k)) _(k).disabled = false })
}

setDisplay('#step-device', false)
setClass('#step-2', 'active')
Expand Down Expand Up @@ -484,7 +528,7 @@ const getSettings = async (deviceType) => {
options['wifi-password'] = _('wifi-password').value
}
}
if (deviceType === 'RX') {
if (deviceType === 'RX' && !_('rx-as-tx').checked) {
options['rcvr-uart-baud'] = +_('rcvr-uart-baud').value
options['rcvr-invert-tx'] = _('rcvr-invert-tx').checked
options['lock-on-first-connection'] = _('lock-on-first-connection').checked
Expand Down Expand Up @@ -542,7 +586,8 @@ const connectUART = async (e) => {
})
setDisplay(connectButton, false)

binary = await Configure.download(deviceType, radioType, config, firmwareUrl, options)
const txType = _('rx-as-tx').checked ? _('connection').value : undefined
binary = await Configure.download(deviceType, txType, radioType, config, firmwareUrl, options)

const method = methodSelect.value

Expand Down Expand Up @@ -580,7 +625,8 @@ const generateFirmware = async () => {
const deviceType = typeSelect.value.startsWith('tx_') ? 'TX' : 'RX'
const radioType = typeSelect.value.endsWith('_900') ? 'sx127x' : (typeSelect.value.endsWith('_2400') ? 'sx128x' : 'lr1121')
const { config, firmwareUrl, options } = await getSettings(deviceType)
const firmwareFiles = await Configure.download(deviceType, radioType, config, firmwareUrl, options)
const txType = _('rx-as-tx').checked ? _('connection').value : undefined
const firmwareFiles = await Configure.download(deviceType, txType, radioType, config, firmwareUrl, options)
return [
firmwareFiles,
{ config, firmwareUrl, options }
Expand Down

0 comments on commit 6786fc5

Please sign in to comment.