Skip to content

Commit

Permalink
Merge branch 'master' into loan-back-baby
Browse files Browse the repository at this point in the history
  • Loading branch information
pkendall64 authored Jul 1, 2024
2 parents b8f894b + 5ecd7b3 commit 35bf3ec
Show file tree
Hide file tree
Showing 40 changed files with 1,398 additions and 353 deletions.
1 change: 1 addition & 0 deletions src/html/hardware.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function fileDragHover(e) {
function fileSelectHandler(e) {
fileDragHover(e);
const files = e.target.files || e.dataTransfer.files;
_('upload_hardware').reset();
for (const f of files) {
parseFile(f);
}
Expand Down
14 changes: 7 additions & 7 deletions src/html/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@@require(PLATFORM, VERSION, isTX, hasSubGHz)
@@require(PLATFORM, VERSION, isTX, hasSubGHz, is8285)
<!DOCTYPE HTML>
<html lang="en">

Expand Down Expand Up @@ -138,12 +138,11 @@ <h2>Import/Export</h2>
<div class="mui-tabs__pane" id="pane-justified-2">
<div class="mui-panel">
<h2>Firmware Update</h2>
Choose a file to update module firmware. Select the correct .bin file for @@{PLATFORM} otherwise a bad flash may occur.
If this happens you will need to recover via USB/Serial. You may also download the
<a href="firmware.bin" title="Click to download firmware">currently running firmware</a>.
Select the correct <strong>firmware.bin@@{ ".gz" if (is8285 and not isTX) else "" }</strong> for @@{PLATFORM} otherwise a bad flash may occur.
If this happens you will need to recover via USB/Serial. You may also download the <a href="firmware.bin" title="Click to download firmware">currently running firmware</a>.
<br/><br/>
@@if (PLATFORM.find('8285')>=0):
<div class="mui-panel" style="background-color: #fcecae;text-align:center;">Do NOT decompress/unzip/extract the firmware.bin.gz file, upload the file as it is.</div>
@@if (is8285 and not isTX):
<div class="mui-panel" style="background-color: #fcecae;text-align:center;">Do NOT decompress/unzip/extract the firmware.bin.gz file. Upload the file as it is.</div>
<br/>
@@end
<button id="upload_btn" class="mui-btn mui-btn--primary upload" style="margin: 0 auto; display:block;">
Expand Down Expand Up @@ -258,6 +257,7 @@ <h2>Serial Protocol</h2>
<option value='4'>SUMD</option>
<option value='5'>DJI RS Pro</option>
<option value='6'>HoTT Telemetry</option>
<option value='7'>MAVLINK</option>
</select>
<label for='serial-protocol'>Serial Protocol</label>
</div>
Expand Down Expand Up @@ -302,7 +302,7 @@ <h2>Model Match</h2>
<input id='model-match' name='model-match' type='checkbox'/>
<label for="model-match">Enable Model Match</label>
</div>
<div class="mui-textfield">
<div class="mui-textfield" id="modelNum">
<input id='modelid' type='text' name='modelid' value="255" required/>
<label for="modelid">Model ID</label>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/html/logo-template.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 32 additions & 15 deletions src/html/scan.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@@require(PLATFORM, isTX)
@@require(PLATFORM, isTX, is8285)

/* eslint-disable comma-dangle */
/* eslint-disable max-len */
Expand Down Expand Up @@ -59,7 +59,7 @@ function generateFeatureBadges(features) {
if ((features & 12) === 12) str += `<span style="color: #696969; background-color: #fab4a8" class="badge">I2C</span>`;
else if (!!(features & 4)) str += `<span style="color: #696969; background-color: #fab4a8" class="badge">SCL</span>`;
else if (!!(features & 8)) str += `<span style="color: #696969; background-color: #fab4a8" class="badge">SDA</span>`;

// Serial2
if ((features & 96) === 96) str += `<span style="color: #696969; background-color: #36b5ff" class="badge">Serial2</span>`;
else if (!!(features & 32)) str += `<span style="color: #696969; background-color: #36b5ff" class="badge">RX2</span>`;
Expand Down Expand Up @@ -119,7 +119,7 @@ function updatePwmSettings(arPwm) {
}
modes.push(undefined); // true PWM
}

if (features & 32) {
modes.push('Serial2 RX');
} else {
Expand Down Expand Up @@ -187,7 +187,7 @@ function updatePwmSettings(arPwm) {
updateOthers(pinMode.value, true); // disable others
updateOthers(pinModes[index], false); // enable others
pinModes[index] = pinMode.value;

// show Serial2 protocol selection only if Serial2 TX is assigned
_('serial1-config').style.display = 'none';
if (pinMode.value == 14) // Serial2 TX
Expand Down Expand Up @@ -247,7 +247,7 @@ function updatePwmSettings(arPwm) {
}
const pinTx = pinTxMode.value;
pinRxMode.onchange();
if(pinRxMode.value != 9) pinTxMode.value = pinTx;
if (pinRxMode.value != 9) pinTxMode.value = pinTx;
}
}
@@end
Expand All @@ -262,14 +262,14 @@ function init() {
// setup model match checkbox handler
_('model-match').onclick = () => {
if (_('model-match').checked) {
_('modelid').style.display = 'block';
_('modelNum').style.display = 'block';
if (storedModelId === 255) {
_('modelid').value = '';
} else {
_('modelid').value = storedModelId;
}
} else {
_('modelid').style.display = 'none';
_('modelNum').style.display = 'none';
_('modelid').value = '255';
}
};
Expand Down Expand Up @@ -360,11 +360,11 @@ function updateConfig(data, options) {
}
@@if not isTX:
if (data.hasOwnProperty('modelid') && data.modelid !== 255) {
_('modelid').style.display = 'block';
_('modelNum').style.display = 'block';
_('model-match').checked = true;
storedModelId = data.modelid;
} else {
_('modelid').style.display = 'none';
_('modelNum').style.display = 'none';
_('model-match').checked = false;
storedModelId = 255;
}
Expand Down Expand Up @@ -421,7 +421,7 @@ function updateConfig(data, options) {
_('is-airport').onchange = () => {
_('serial-protocol').onchange();
_('serial1-protocol').onchange();
}
}
_('is-airport').onchange;
_('vbind').value = data.vbind;
_('vbind').onchange = () => {
Expand All @@ -431,7 +431,7 @@ function updateConfig(data, options) {

// set initial visibility status of Serial2 protocol selection
_('serial1-config').style.display = 'none';
data.pwm.forEach((item,index) => {
data.pwm?.forEach((item,index) => {
const _pinMode = _(`pwm_${index}_mode`)
if (_pinMode.value == 14) // Serial2 TX
_('serial1-config').style.display = 'block';
Expand Down Expand Up @@ -518,8 +518,25 @@ function fileDragHover(e) {

function fileSelectHandler(e) {
fileDragHover(e);
// ESP32 expects .bin, ESP8285 RX expect .bin.gz
const files = e.target.files || e.dataTransfer.files;
uploadFile(files[0]);
const fileExt = files[0].name.split('.').pop();
@@if (is8285 and not isTX):
const expectedFileExt = 'gz';
const expectedFileExtDesc = '.bin.gz file. <br />Do NOT decompress/unzip/extract the file!';
@@else:
const expectedFileExt = 'bin';
const expectedFileExtDesc = '.bin file.';
@@endif
if (fileExt === expectedFileExt) {
uploadFile(files[0]);
} else {
cuteAlert({
type: 'error',
title: 'Incorrect File Format',
message: 'You selected the file &quot;' + files[0].name.toString() + '&quot;.<br />The firmware file must be a ' + expectedFileExtDesc
});
}
}

function uploadFile(file) {
Expand Down Expand Up @@ -564,11 +581,11 @@ function completeHandler(event) {
// This is basically a delayed display of the success dialog with a fake progress
let percent = 0;
const interval = setInterval(()=>{
@@if (PLATFORM.find('8285')>=0):
@@if (is8285):
percent = percent + 1;
@@else:
percent = percent + 2;
@@end
@@end
_('progressBar').value = percent;
_('status').innerHTML = percent + '% flashed... please wait';
if (percent === 100) {
Expand Down Expand Up @@ -872,7 +889,7 @@ function updateOptions(data) {
if (Array.isArray(value)) _(key).value = value.toString();
else _(key).value = value;
}
if(_(key).onchange) _(key).onchange();
if (_(key).onchange) _(key).onchange();
}
}
if (data['wifi-ssid']) _('homenet').textContent = data['wifi-ssid'];
Expand Down
9 changes: 8 additions & 1 deletion src/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ typedef enum : uint8_t
TX_RADIO_MODE_SWITCH = 3
} tx_radio_mode_e;

typedef enum : uint8_t
{
TX_NORMAL_MODE = 0,
TX_MAVLINK_MODE = 1,
} tx_transmission_mode_e;

// Value used for expresslrs_rf_pref_params_s.DynpowerUpThresholdSnr if SNR should not be used
#define DYNPOWER_SNR_THRESH_NONE -127
#define SNR_SCALE(snr) ((int8_t)((float)snr * RADIO_SNR_SCALE))
Expand Down Expand Up @@ -207,7 +213,8 @@ enum eSerialProtocol : uint8_t
PROTOCOL_INVERTED_SBUS,
PROTOCOL_SUMD,
PROTOCOL_DJI_RS_PRO,
PROTOCOL_HOTT_TLM
PROTOCOL_HOTT_TLM,
PROTOCOL_MAVLINK
};

enum eSerial1Protocol : uint8_t
Expand Down
13 changes: 13 additions & 0 deletions src/include/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,16 @@ class NullStream : public Stream
return size;
}
};

#if defined(PLATFORM_STM32)
inline const char *strchrnul(const char *pos, const char find)
{
const char *semi = strchr(pos, find);
if (semi == nullptr)
{
semi = pos + strlen(pos);
}
return semi;
}
#endif

4 changes: 3 additions & 1 deletion src/include/target/Unified_ESP_RX.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,6 @@
#define VPD_VALUES_100MW hardware_u16_array(HARDWARE_vtx_amp_vpd_100mW)
#define PWM_VALUES_25MW hardware_u16_array(HARDWARE_vtx_amp_pwm_25mW)
#define PWM_VALUES_100MW hardware_u16_array(HARDWARE_vtx_amp_pwm_100mW)
#endif
#endif

#define GPIO_PIN_FAN_EN hardware_pin(HARDWARE_misc_fan_en)
64 changes: 64 additions & 0 deletions src/lib/CONFIG/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,23 @@ TxConfig::SetAntennaMode(uint8_t txAntenna)
}
}

void
TxConfig::SetLinkMode(uint8_t linkMode)
{
if (GetLinkMode() != linkMode)
{
m_model->linkMode = linkMode;

if (linkMode == TX_MAVLINK_MODE)
{
m_model->tlm = TLM_RATIO_1_2;
m_model->switchMode = smHybridOr16ch; // Force Hybrid / 16ch/2 switch modes for mavlink
m_config.backpackTlmEnabled = false; // Disable backpack telemetry since it'd be MSP mixed with MAVLink
}
m_modified |= MODEL_CHANGED | MAIN_CHANGED;
}
}

void
TxConfig::SetModelMatch(bool modelMatch)
{
Expand Down Expand Up @@ -689,6 +706,10 @@ TxConfig::SetModelId(uint8_t modelId)

#if defined(TARGET_RX)

#if defined(PLATFORM_ESP8266)
#include "flash_hal.h"
#endif

RxConfig::RxConfig()
{
}
Expand Down Expand Up @@ -929,9 +950,38 @@ bool RxConfig::IsOnLoan() const
return GetIsBound() && memcmp(m_config.uid, firmwareOptions.uid, UID_LEN) != 0;
}

#if defined(PLATFORM_ESP8266)
#define EMPTY_SECTOR ((FS_start - 0x1000 - 0x40200000) / SPI_FLASH_SEC_SIZE) // empty sector before FS area start
static bool erase_power_on_count = false;
static int realPowerOnCounter = -1;
uint8_t
RxConfig::GetPowerOnCounter() const
{
if (realPowerOnCounter == -1) {
byte zeros[16];
ESP.flashRead(EMPTY_SECTOR * SPI_FLASH_SEC_SIZE, zeros, sizeof(zeros));
realPowerOnCounter = sizeof(zeros);
for (int i=0 ; i<sizeof(zeros) ; i++) {
if (zeros[i] != 0) {
realPowerOnCounter = i;
break;
}
}
}
return realPowerOnCounter;
}
#endif

void
RxConfig::Commit()
{
#if defined(PLATFORM_ESP8266)
if (erase_power_on_count)
{
ESP.flashEraseSector(EMPTY_SECTOR);
erase_power_on_count = false;
}
#endif
if (!m_modified)
{
// No changes
Expand Down Expand Up @@ -959,11 +1009,25 @@ RxConfig::SetUID(uint8_t* uid)
void
RxConfig::SetPowerOnCounter(uint8_t powerOnCounter)
{
#if defined(PLATFORM_ESP8266)
realPowerOnCounter = powerOnCounter;
if (powerOnCounter == 0)
{
erase_power_on_count = true;
m_modified = true;
}
else
{
byte zeros[16] = {0};
ESP.flashWrite(EMPTY_SECTOR * SPI_FLASH_SEC_SIZE, zeros, std::min((size_t)powerOnCounter, sizeof(zeros)));
}
#else
if (m_config.powerOnCounter != powerOnCounter)
{
m_config.powerOnCounter = powerOnCounter;
m_modified = true;
}
#endif
}

void
Expand Down
8 changes: 7 additions & 1 deletion src/lib/CONFIG/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ typedef struct {
txAntenna:2, // FUTURE: Which TX antenna to use, 0=Auto
ptrStartChannel:4,
ptrEnableChannel:5,
_unused:3;
linkMode:3;
} model_config_t;

typedef struct {
Expand Down Expand Up @@ -109,6 +109,7 @@ class TxConfig
uint8_t GetBoostChannel() const { return m_model->boostChannel; }
uint8_t GetSwitchMode() const { return m_model->switchMode; }
uint8_t GetAntennaMode() const { return m_model->txAntenna; }
uint8_t GetLinkMode() const { return m_model->linkMode; }
bool GetModelMatch() const { return m_model->modelMatch; }
bool IsModified() const { return m_modified; }
uint8_t GetVtxBand() const { return m_config.vtxBand; }
Expand Down Expand Up @@ -136,6 +137,7 @@ class TxConfig
void SetBoostChannel(uint8_t boostChannel);
void SetSwitchMode(uint8_t switchMode);
void SetAntennaMode(uint8_t txAntenna);
void SetLinkMode(uint8_t linkMode);
void SetModelMatch(bool modelMatch);
void SetDefaults(bool commit);
void SetStorageProvider(ELRS_EEPROM *eeprom);
Expand Down Expand Up @@ -240,7 +242,11 @@ class RxConfig
// Getters
bool GetIsBound() const;
const uint8_t* GetUID() const { return m_config.uid; }
#if defined(PLATFORM_ESP8266)
uint8_t GetPowerOnCounter() const;
#else
uint8_t GetPowerOnCounter() const { return m_config.powerOnCounter; }
#endif
uint8_t GetModelId() const { return m_config.modelId; }
uint8_t GetPower() const { return m_config.power; }
uint8_t GetAntennaMode() const { return m_config.antennaMode; }
Expand Down
Loading

0 comments on commit 35bf3ec

Please sign in to comment.