Skip to content

Commit

Permalink
Merge pull request #21 from pkendall64/use-externalised-targets
Browse files Browse the repository at this point in the history
Use the externalised targets
  • Loading branch information
pkendall64 authored Sep 17, 2023
2 parents 7e5c920 + fac3342 commit 42b8715
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
28 changes: 27 additions & 1 deletion get_artifacts.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash

# Download main ELRS firmware, for each tagged version
mkdir -p firmware
cd firmware
curl -L -o index.json https://artifactory.expresslrs.org/ExpressLRS/index.json
Expand All @@ -9,7 +11,31 @@ for i in `cat index.json | jq '.tags | keys[]' | sed 's/"//g' | sort -r` ; do
cd $HASH
unzip -q ../firmware.zip
mv firmware/* .
rmdir firmware
rm -rf firmware
cd ..
rm firmware.zip
done

# Download the published hardware targets into the `firmware` directory
mkdir hardware
cd hardware
curl -L -o hardware.zip https://artifactory.expresslrs.org/ExpressLRS/hardware.zip
unzip -q hardware.zip
rm hardware.zip

# Download backpack firmware, for each tagged version
cd ../..
mkdir -p backpack
cd backpack
curl -L -o index.json https://artifactory.expresslrs.org/Backpack/index.json
for i in `cat index.json | jq '.tags | keys[]' | sed 's/"//g' | sort -r` ; do
HASH=`grep \"$i\" index.json | sed 's/.* "//' | sed 's/".*//'`
curl -L -o firmware.zip "https://artifactory.expresslrs.org/Backpack/$HASH/firmware.zip"
mkdir $HASH
cd $HASH
unzip -q ../firmware.zip
mv firmware/* .
rm -rf firmware
cd ..
rm firmware.zip
done
14 changes: 9 additions & 5 deletions src/js/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class Configure {
}

static #appendArray = (...args) => {
const totalLength = args.reduce((acc, value) => acc + value.length, 0);
const totalLength = args.reduce((acc, value) => acc + value.length, 0)
const c = new Uint8Array(totalLength)
args.reduce((acc, value) => {
c.set(value, acc)
Expand Down Expand Up @@ -182,7 +182,7 @@ export class Configure {
this.#bstrToUi8(config.product_name.padEnd(128, '\x00')),
this.#bstrToUi8(config.lua_name.padEnd(16, '\x00')),
this.#bstrToUi8(JSON.stringify(options).padEnd(512, '\x00'))
)
)
}

static download = async (deviceType, radioType, config, firmwareUrl, options) => {
Expand All @@ -194,11 +194,13 @@ export class Configure {
const version = document.getElementById('version').value
const folder = `firmware/${version}`

var hardwareLayoutData
let hardwareLayoutData
if (config.custom_layout) {
hardwareLayoutData = this.#bstrToUi8(JSON.stringify(config.custom_layout))
} else {
// 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 {
Expand All @@ -219,14 +221,16 @@ export class Configure {
}

const files = await Promise.all(list)
var logoFile = { data: new Uint8Array(0), address: 0 }
let logoFile = { data: new Uint8Array(0), address: 0 }
if (config.logo_file !== undefined) {
// get logo from version specific folder OR fall back to global folder
logoFile = await this.#fetch_file(`${folder}/hardware/logo/${config.logo_file}`, 0)
.catch(() => this.#fetch_file(`firmware/hardware/logo/${config.logo_file}`, 0))
}
files[files.length - 1].data = this.#appendArray(
files[files.length - 1].data,
hardwareLayoutData,
(new Uint8Array(2048-hardwareLayoutData.length)).fill(0),
(new Uint8Array(2048 - hardwareLayoutData.length)).fill(0),
logoFile.data
)
return files
Expand Down
21 changes: 13 additions & 8 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ const compareSemanticVersions = (a, b) => {
return b1.length - a1.length
}

const compareSemanticVersionsRC = (a, b) => {
return compareSemanticVersions(a.replace(/-.*/, ''), b.replace(/-.*/, ''))
}

async function initialise () {
checkProxy()
setInterval(() => { checkProxy() }, 30000)
Expand Down Expand Up @@ -281,25 +285,24 @@ versionSelect.onchange = async () => {
typeSelect.disabled = true
typeSelect.value = ''

const version = versionSelect.value
const json = await checkStatus(await fetch(`firmware/${version}/hardware/targets.json`)).json()
hardware = json
for (const k in json) {
hardware = await checkStatus(await fetch('firmware/hardware/targets.json')).json()
for (const k in hardware) {
const opt = document.createElement('option')
opt.value = k
opt.innerHTML = json[k].name === undefined ? k : json[k].name
opt.innerHTML = hardware[k].name === undefined ? k : hardware[k].name
vendorSelect.appendChild(opt)
}
vendorSelect.disabled = false
setDisplay('.uart', false)
setDisplay('.stlink', false)
setDisplay('.wifi', false)

const version = versionSelect.options[versionSelect.selectedIndex].text
const models = []
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 !== undefined) {
if (hardware[v][t][m].product_name !== undefined && compareSemanticVersionsRC(version, hardware[v][t][m].min_version) >= 0) {
models.push(hardware[v][t][m].product_name)
}
}
Expand Down Expand Up @@ -377,10 +380,11 @@ vendorSelect.onchange = () => {
modelSelect.value = ''
deviceNext.disabled = true
const models = []
const version = versionSelect.options[versionSelect.selectedIndex].text
const v = vendorSelect.value
for (const t in hardware[v]) {
for (const m in hardware[v][t]) {
if (hardware[v][t][m].product_name !== undefined) {
if (hardware[v][t][m].product_name !== undefined && compareSemanticVersionsRC(version, hardware[v][t][m].min_version) >= 0) {
models.push(hardware[v][t][m].product_name)
}
}
Expand All @@ -392,10 +396,11 @@ typeSelect.onchange = () => {
modelSelect.value = ''
deviceNext.disabled = true
const models = []
const version = versionSelect.options[versionSelect.selectedIndex].text
const v = vendorSelect.value
const t = typeSelect.value
for (const m in hardware[v][t]) {
if (hardware[v][t][m].product_name !== undefined) {
if (hardware[v][t][m].product_name !== undefined && compareSemanticVersionsRC(version, hardware[v][t][m].min_version) >= 0) {
models.push(hardware[v][t][m].product_name)
}
}
Expand Down

0 comments on commit 42b8715

Please sign in to comment.