Skip to content

Commit

Permalink
Merge branch 'master' into more-baros
Browse files Browse the repository at this point in the history
  • Loading branch information
CapnBry committed Feb 12, 2024
2 parents fafef2d + 57df8fa commit 06ba9d3
Show file tree
Hide file tree
Showing 74 changed files with 1,213 additions and 798 deletions.
11 changes: 11 additions & 0 deletions src/html/elrs.css
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,24 @@ body, input, select, textarea {
}

/* Custom code for ExpressLRS PWM Output table */
.pwmpnl {
overflow-x: auto;
min-width: fit-content;
}
.pwmtbl table {
overflow-x: auto;
}
.pwmtbl th {
text-align: center;
font-weight: bold;
}
.pwmtbl td {
text-align: center;
}
.pwmitm {
min-width: 6em;
white-space: nowrap;
}

/*==========================*/

Expand Down
19 changes: 15 additions & 4 deletions src/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,22 @@ <h2>PWM Output</h2>
<li><b>Input:</b> Input channel from the handset</li>
<li><b>Invert:</b> Invert input channel position</li>
<li><b>750us:</b> Use half pulse width (494-1006us) with center 750us instead of 988-2012us</li>
<li><b>Failsafe:</b> Absolute position to set the servo on failsafe
<li><b>Failsafe</b>
<ul>
<li>Does not use "Invert" flag</li>
<li>Value will be halved if "750us" flag is set</li>
<li>Will be converted to binary for "On/Off" mode (>1500us = HIGH)</li>
<li>"Set Position" sets the servo to an absolute "Failsafe Pos"
<ul>
<li>Does not use "Invert" flag</li>
<li>Value will be halved if "750us" flag is set</li>
<li>Will be converted to binary for "On/Off" mode (>1500us = HIGH)</li>
</ul>
</li>
<li>"No Pulses" stops sending pulses
<ul>
<li>Unpowers servos</li>
<li>May disarm ESCs</li>
</ul>
</li>
<li>"Last Position" continues sending last received channel position</li>
</ul>
</li>
</ul>
Expand Down
33 changes: 28 additions & 5 deletions src/html/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ function getPwmFormData() {
const invert = _(`pwm_${ch}_inv`).checked ? 1 : 0;
const narrow = _(`pwm_${ch}_nar`).checked ? 1 : 0;
const failsafeField = _(`pwm_${ch}_fs`);
const failsafeModeField = _(`pwm_${ch}_fsmode`);
let failsafe = failsafeField.value;
if (failsafe > 2011) failsafe = 2011;
if (failsafe < 988) failsafe = 988;
failsafeField.value = failsafe;
let failsafeMode = failsafeModeField.value;

const raw = (narrow << 19) | (mode << 15) | (invert << 14) | (inChannel << 10) | (failsafe - 988);
// console.log(`PWM ${ch} mode=${mode} input=${inChannel} fs=${failsafe} inv=${invert} nar=${narrow} raw=${raw}`);
const raw = (narrow << 19) | (mode << 15) | (invert << 14) | (inChannel << 10) | (failsafeMode << 20) | (failsafe - 988);
// console.log(`PWM ${ch} mode=${mode} input=${inChannel} fs=${failsafe} fsmode=${failsafeMode} inv=${invert} nar=${narrow} raw=${raw}`);
outData.push(raw);
++ch;
}
Expand All @@ -41,7 +43,7 @@ function getPwmFormData() {

function enumSelectGenerate(id, val, arOptions) {
// Generate a <select> item with every option in arOptions, and select the val element (0-based)
const retVal = `<div class="mui-select compact"><select id="${id}">` +
const retVal = `<div class="mui-select compact"><select id="${id}" class="pwmitm">` +
arOptions.map((item, idx) => {
if (item) return `<option value="${idx}"${(idx === val) ? ' selected' : ''} ${item === 'Disabled' ? 'disabled' : ''}>${item}</option>`;
return '';
Expand Down Expand Up @@ -69,9 +71,10 @@ function updatePwmSettings(arPwm) {
var pinTxIndex = undefined;
var pinModes = []
// arPwm is an array of raw integers [49664,50688,51200]. 10 bits of failsafe position, 4 bits of input channel, 1 bit invert, 4 bits mode, 1 bit for narrow/750us
const htmlFields = ['<div class="mui-panel"><table class="pwmtbl mui-table"><tr><th class="fixed-column">Output</th><th class="mui--text-center fixed-column">Features</th><th>Mode</th><th>Input</th><th class="mui--text-center fixed-column">Invert?</th><th class="mui--text-center fixed-column">750us?</th><th>Failsafe</th></tr>'];
const htmlFields = ['<div class="mui-panel pwmpnl"><table class="pwmtbl mui-table"><tr><th class="fixed-column">Output</th><th class="mui--text-center fixed-column">Features</th><th>Mode</th><th>Input</th><th class="mui--text-center fixed-column">Invert?</th><th class="mui--text-center fixed-column">750us?</th><th class="mui--text-center fixed-column pwmitm">Failsafe Mode</th><th class="mui--text-center fixed-column pwmitm">Failsafe Pos</th></tr>'];
arPwm.forEach((item, index) => {
const failsafe = (item.config & 1023) + 988; // 10 bits
const failsafeMode = (item.config >> 20) & 3; // 2 bits
const ch = (item.config >> 10) & 15; // 4 bits
const inv = (item.config >> 14) & 1;
const mode = (item.config >> 15) & 15; // 4 bits
Expand Down Expand Up @@ -116,13 +119,16 @@ function updatePwmSettings(arPwm) {
'ch5 (AUX1)', 'ch6 (AUX2)', 'ch7 (AUX3)', 'ch8 (AUX4)',
'ch9 (AUX5)', 'ch10 (AUX6)', 'ch11 (AUX7)', 'ch12 (AUX8)',
'ch13 (AUX9)', 'ch14 (AUX10)', 'ch15 (AUX11)', 'ch16 (AUX12)']);
const failsafeModeSelect = enumSelectGenerate(`pwm_${index}_fsmode`, failsafeMode,
['Set Position', 'No Pulses', 'Last Position']); // match eServoOutputFailsafeMode
htmlFields.push(`<tr><td class="mui--text-center mui--text-title">${index + 1}</td>
<td>${generateFeatureBadges(features)}</td>
<td>${modeSelect}</td>
<td>${inputSelect}</td>
<td><div class="mui-checkbox mui--text-center"><input type="checkbox" id="pwm_${index}_inv"${(inv) ? ' checked' : ''}></div></td>
<td><div class="mui-checkbox mui--text-center"><input type="checkbox" id="pwm_${index}_nar"${(narrow) ? ' checked' : ''}></div></td>
<td><div class="mui-textfield compact"><input id="pwm_${index}_fs" value="${failsafe}" size="6"/></div></td></tr>`);
<td>${failsafeModeSelect}</td>
<td><div class="mui-textfield compact"><input id="pwm_${index}_fs" value="${failsafe}" size="6" class="pwmitm" /></div></td></tr>`);
pinModes[index] = mode;
});
htmlFields.push('</table></div>');
Expand All @@ -138,6 +144,7 @@ function updatePwmSettings(arPwm) {
_(`pwm_${index}_inv`).disabled = onoff;
_(`pwm_${index}_nar`).disabled = onoff;
_(`pwm_${index}_fs`).disabled = onoff;
_(`pwm_${index}_fsmode`).disabled = onoff;
}
arPwm.forEach((item,index)=>{
const pinMode = _(`pwm_${index}_mode`)
Expand All @@ -161,7 +168,23 @@ function updatePwmSettings(arPwm) {
pinModes[index] = pinMode.value;
}
pinMode.onchange();

// disable and hide the failsafe position field if not using the set-position failsafe mode
const failsafeMode = _(`pwm_${index}_fsmode`);
failsafeMode.onchange = () => {
const failsafeField = _(`pwm_${index}_fs`);
if (failsafeMode.value == 0) {
failsafeField.disabled = false;
failsafeField.style.display = 'block';
}
else {
failsafeField.disabled = true;
failsafeField.style.display = 'none';
}
};
failsafeMode.onchange();
});

// put some contraints on pinRx/Tx mode selects
if (pinRxIndex !== undefined && pinTxIndex !== undefined) {
const pinRxMode = _(`pwm_${pinRxIndex}_mode`);
Expand Down
7 changes: 7 additions & 0 deletions src/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ enum eServoOutputMode : uint8_t
somPwm, // True PWM mode (NOT SUPPORTED)
};

enum eServoOutputFailsafeMode : uint8_t
{
PWMFAILSAFE_SET_POSITION, // user customizable pulse value
PWMFAILSAFE_NO_PULSES, // stop pulsing
PWMFAILSAFE_LAST_POSITION, // continue to pulse last used value
};

enum eSerialProtocol : uint8_t
{
PROTOCOL_CRSF,
Expand Down
15 changes: 8 additions & 7 deletions src/lib/helpers/helpers.h → src/include/helpers.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "targets.h"

#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))

#ifndef UNUSED
Expand All @@ -9,33 +11,32 @@
class NullStream : public Stream
{
public:
int available(void)
int available() override
{
return 0;
}

void flush(void)
void flush() override
{
return;
}

int peek(void)
int peek() override
{
return -1;
}

int read(void)
int read() override
{
return -1;
}

size_t write(uint8_t u_Data)
size_t write(uint8_t u_Data) override
{
UNUSED(u_Data);
return 0x01;
}

size_t write(const uint8_t *buffer, size_t size)
size_t write(const uint8_t *buffer, size_t size) override
{
UNUSED(buffer);
return size;
Expand Down
4 changes: 2 additions & 2 deletions src/include/native.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Stream

// Print methods
virtual size_t write(uint8_t c) = 0;
virtual size_t write(uint8_t *s, int l) = 0;
virtual size_t write(const uint8_t *s, size_t l) = 0;

int print(const char *s) {return 0;}
int print(uint8_t s) {return 0;}
Expand All @@ -59,7 +59,7 @@ class HardwareSerial: public Stream {

// Print methods
size_t write(uint8_t c) {return 1;}
size_t write(uint8_t *s, int l) {return l;}
size_t write(const uint8_t *s, size_t l) {return l;}

int print(const char *s) {return 0;}
int print(uint8_t s) {return 0;}
Expand Down
1 change: 1 addition & 0 deletions src/include/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

#ifndef HAS_THERMAL
#define OPT_HAS_THERMAL false
#define OPT_HAS_THERMAL_LM75A false
#elif !defined(OPT_HAS_THERMAL)
#define OPT_HAS_THERMAL true
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/lib/BLE/devBLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#if defined(PLATFORM_ESP32)

#include "common.h"
#include "CRSF.h"
#include "crsf_protocol.h"
#include "handset.h"
#include "POWERMGNT.h"
#include "hwTimer.h"
#include "logging.h"
Expand Down Expand Up @@ -61,7 +62,7 @@ void BluetoothJoystickBegin()

POWERMGNT::setPower(MinPower);
Radio.End();
CRSF::RCdataCallback = BluetoothJoystickUpdateValues;
handset->setRCDataCallback(BluetoothJoystickUpdateValues);

BleGamepadConfiguration *gamepadConfig = new BleGamepadConfiguration();
gamepadConfig->setAutoReport(false);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/BUTTON/devButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "logging.h"
#include "button.h"
#include "config.h"
#include "CRSF.h"
#include "handset.h"

#ifndef GPIO_BUTTON_INVERTED
#define GPIO_BUTTON_INVERTED false
Expand Down Expand Up @@ -92,7 +92,7 @@ static int timeout()
return DURATION_NEVER;
}
#if defined(TARGET_TX)
if (CRSF::IsArmed())
if (handset->IsArmed())
return MS_IN_USE;
#else
if (connectionState == connected)
Expand Down
52 changes: 21 additions & 31 deletions src/lib/Backpack/devBackpack.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "targets.h"

#include "common.h"
#include "device.h"
#include "msp.h"
#include "msptypes.h"
#include "CRSF.h"
#include "CRSFHandset.h"
#include "config.h"
#include "logging.h"

Expand Down Expand Up @@ -34,9 +35,9 @@ bool lastRecordingState = false;
devicesStop();
Radio.End();
hwTimer::stop();
CRSF::End();
handset->End();

Stream *uplink = &CRSF::Port;
Stream *uplink = &CRSFHandset::Port;

uint32_t baud = PASSTHROUGH_BAUD == -1 ? BACKPACK_LOGGING_BAUD : PASSTHROUGH_BAUD;
// get ready for passthrough
Expand All @@ -52,25 +53,25 @@ bool lastRecordingState = false;
}
else
{
CRSF::Port.begin(baud, SERIAL_8N1, 44, 43); // pins are configured as 44 and 43
CRSF::Port.setTxBufferSize(1024);
CRSF::Port.setRxBufferSize(16384);
CRSFHandset::Port.begin(baud, SERIAL_8N1, 44, 43); // pins are configured as 44 and 43
CRSFHandset::Port.setTxBufferSize(1024);
CRSFHandset::Port.setRxBufferSize(16384);
}
#else
CRSF::Port.begin(baud, SERIAL_8N1, 3, 1); // default pin configuration 3 and 1
CRSF::Port.setTxBufferSize(1024);
CRSF::Port.setRxBufferSize(16384);
CRSFHandset::Port.begin(baud, SERIAL_8N1, 3, 1); // default pin configuration 3 and 1
CRSFHandset::Port.setTxBufferSize(1024);
CRSFHandset::Port.setRxBufferSize(16384);
#endif
}
else
{
CRSF::Port.begin(baud, SERIAL_8N1, GPIO_PIN_RCSIGNAL_RX, GPIO_PIN_RCSIGNAL_TX);
CRSF::Port.setTxBufferSize(1024);
CRSF::Port.setRxBufferSize(16384);
CRSFHandset::Port.begin(baud, SERIAL_8N1, GPIO_PIN_RCSIGNAL_RX, GPIO_PIN_RCSIGNAL_TX);
CRSFHandset::Port.setTxBufferSize(1024);
CRSFHandset::Port.setRxBufferSize(16384);
}
disableLoopWDT();

auto backpack = (HardwareSerial*)TxBackpack;
const auto backpack = (HardwareSerial*)TxBackpack;
if (baud != BACKPACK_LOGGING_BAUD)
{
backpack->begin(PASSTHROUGH_BAUD, SERIAL_8N1, GPIO_PIN_DEBUG_RX, GPIO_PIN_DEBUG_TX);
Expand Down Expand Up @@ -201,10 +202,10 @@ static void AuxStateToMSPOut()
return;
}

uint8_t auxNumber = (config.GetDvrAux() - 1) / 2 + 4;
uint8_t auxInverted = (config.GetDvrAux() + 1) % 2;
const uint8_t auxNumber = (config.GetDvrAux() - 1) / 2 + 4;
const uint8_t auxInverted = (config.GetDvrAux() + 1) % 2;

bool recordingState = CRSF_to_BIT(ChannelData[auxNumber]) ^ auxInverted;
const bool recordingState = CRSF_to_BIT(ChannelData[auxNumber]) ^ auxInverted;

if (recordingState == lastRecordingState)
{
Expand All @@ -213,17 +214,7 @@ static void AuxStateToMSPOut()
}
lastRecordingState = recordingState;

uint16_t delay = 0;

if (recordingState)
{
delay = GetDvrDelaySeconds(config.GetDvrStartDelay());
}

if (!recordingState)
{
delay = GetDvrDelaySeconds(config.GetDvrStopDelay());
}
const uint16_t delay = GetDvrDelaySeconds(recordingState ? config.GetDvrStartDelay() : config.GetDvrStopDelay());

mspPacket_t packet;
packet.reset();
Expand All @@ -244,7 +235,7 @@ void crsfTelemToMSPOut(uint8_t *data)
// Backpack telem is off
return;
}

mspPacket_t packet;
packet.reset();
packet.makeCommand();
Expand All @@ -256,7 +247,7 @@ void crsfTelemToMSPOut(uint8_t *data)
ERRLN("CRSF frame exceeds max length");
return;
}

for (uint8_t i = 0; i < size; ++i)
{
packet.addByte(data[i]);
Expand All @@ -280,8 +271,7 @@ static void initialize()
// Rely on event() to boot
}
#endif

CRSF::RCdataCallback = AuxStateToMSPOut;
handset->setRCDataCallback(AuxStateToMSPOut);
}

static int start()
Expand Down
1 change: 1 addition & 0 deletions src/lib/Baro/devBaro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#if defined(HAS_BARO)

#include "CRSF.h"
#include "logging.h"
#include "telemetry.h"
#include "baro_spl06.h"
Expand Down
Loading

0 comments on commit 06ba9d3

Please sign in to comment.