mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 05:15:25 +03:00
separate all telemetry code and add option to use softserial for telemetry.
to use, set softserial_baudrate=9600, softserial_inverted=1 and telemetry_softserial=1 then enable feature TELEMETRY. by disq git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@448 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
parent
47a4d30358
commit
779dfe8a92
8 changed files with 47 additions and 14 deletions
|
@ -90,6 +90,11 @@ typedef enum {
|
|||
GPS_MTK_BINARY,
|
||||
} GPSHardware;
|
||||
|
||||
typedef enum {
|
||||
TELEMETRY_UART = 0,
|
||||
TELEMETRY_SOFTSERIAL,
|
||||
} TelemetrySerial;
|
||||
|
||||
typedef enum {
|
||||
X = 0,
|
||||
Y,
|
||||
|
|
|
@ -120,6 +120,7 @@ const clivalue_t valueTable[] = {
|
|||
{ "gps_type", VAR_UINT8, &mcfg.gps_type, 0, 3 },
|
||||
{ "gps_baudrate", VAR_INT8, &mcfg.gps_baudrate, -1, 4 },
|
||||
{ "serialrx_type", VAR_UINT8, &mcfg.serialrx_type, 0, 2 },
|
||||
{ "telemetry_softserial", VAR_UINT8, &mcfg.telemetry_softserial, 0, 1 },
|
||||
{ "vbatscale", VAR_UINT8, &mcfg.vbatscale, 10, 200 },
|
||||
{ "vbatmaxcellvoltage", VAR_UINT8, &mcfg.vbatmaxcellvoltage, 10, 50 },
|
||||
{ "vbatmincellvoltage", VAR_UINT8, &mcfg.vbatmincellvoltage, 10, 50 },
|
||||
|
|
|
@ -13,7 +13,7 @@ master_t mcfg; // master config struct with data independent from profiles
|
|||
config_t cfg; // profile config struct
|
||||
const char rcChannelLetters[] = "AERT1234";
|
||||
|
||||
static const uint8_t EEPROM_CONF_VERSION = 54;
|
||||
static const uint8_t EEPROM_CONF_VERSION = 55;
|
||||
static uint32_t enabledSensors = 0;
|
||||
static void resetConf(void);
|
||||
|
||||
|
@ -192,6 +192,7 @@ static void resetConf(void)
|
|||
mcfg.vbatmincellvoltage = 33;
|
||||
mcfg.power_adc_channel = 0;
|
||||
mcfg.serialrx_type = 0;
|
||||
mcfg.telemetry_softserial = 0;
|
||||
mcfg.midrc = 1500;
|
||||
mcfg.mincheck = 1100;
|
||||
mcfg.maxcheck = 1900;
|
||||
|
|
|
@ -148,6 +148,9 @@ int main(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
if (feature(FEATURE_TELEMETRY))
|
||||
initTelemetry();
|
||||
|
||||
previousTime = micros();
|
||||
if (mcfg.mixerConfiguration == MULTITYPE_GIMBAL)
|
||||
calibratingA = CALIBRATING_ACC_CYCLES;
|
||||
|
|
4
src/mw.c
4
src/mw.c
|
@ -177,9 +177,9 @@ void annexCode(void)
|
|||
LED0_OFF;
|
||||
if (f.ARMED)
|
||||
LED0_ON;
|
||||
// This will switch to/from 9600 or 115200 baud depending on state. Of course, it should only do it on changes.
|
||||
// This will switch to/from 9600 or 115200 baud depending on state. Of course, it should only do it on changes. With telemetry_softserial>0 telemetry is always enabled, also see updateTelemetryState()
|
||||
if (feature(FEATURE_TELEMETRY))
|
||||
initTelemetry(f.ARMED);
|
||||
updateTelemetryState();
|
||||
}
|
||||
|
||||
#ifdef LEDRING
|
||||
|
|
5
src/mw.h
5
src/mw.h
|
@ -272,6 +272,8 @@ typedef struct master_t {
|
|||
uint32_t softserial_baudrate;
|
||||
uint8_t softserial_inverted; // use inverted softserial input and output signals
|
||||
|
||||
uint8_t telemetry_softserial; // Serial to use for Telemetry. 0:USART1, 1:SoftSerial1 (Enable FEATURE_SOFTSERIAL first)
|
||||
|
||||
config_t profile[3]; // 3 separate profiles
|
||||
uint8_t current_profile; // currently loaded profile
|
||||
|
||||
|
@ -456,5 +458,6 @@ void GPS_set_next_wp(int32_t* lat, int32_t* lon);
|
|||
int32_t wrap_18000(int32_t error);
|
||||
|
||||
// telemetry
|
||||
void initTelemetry(bool State);
|
||||
void initTelemetry(void);
|
||||
void updateTelemetryState(void);
|
||||
void sendTelemetry(void);
|
||||
|
|
|
@ -269,8 +269,7 @@ void serialInit(uint32_t baudrate)
|
|||
bool hfadded = false;
|
||||
|
||||
core.mainport = uartOpen(USART1, NULL, baudrate, MODE_RXTX);
|
||||
// TODO fix/hax
|
||||
core.telemport = core.mainport;
|
||||
|
||||
// calculate used boxes based on features and fill availableBoxes[] array
|
||||
memset(availableBoxes, 0xFF, sizeof(availableBoxes));
|
||||
|
||||
|
@ -764,8 +763,7 @@ void serialCom(void)
|
|||
c_state = IDLE;
|
||||
}
|
||||
}
|
||||
if (!cliMode && !serialTotalBytesWaiting(core.telemport) && feature(FEATURE_TELEMETRY) && f.ARMED) { // The first 2 conditions should never evaluate to true but I'm putting it here anyway - silpstream
|
||||
if (!cliMode && feature(FEATURE_TELEMETRY)) { // The first condition should never evaluate to true but I'm putting it here anyway - silpstream
|
||||
sendTelemetry();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,13 +202,29 @@ static void sendHeading(void)
|
|||
|
||||
static bool telemetryEnabled = false;
|
||||
|
||||
void initTelemetry(bool State)
|
||||
void initTelemetry(void)
|
||||
{
|
||||
// Sanity check for softserial vs. telemetry port
|
||||
if (!feature(FEATURE_SOFTSERIAL))
|
||||
mcfg.telemetry_softserial = TELEMETRY_UART;
|
||||
|
||||
if (mcfg.telemetry_softserial == TELEMETRY_SOFTSERIAL)
|
||||
core.telemport = &(softSerialPorts[0].port);
|
||||
else
|
||||
core.telemport = core.mainport;
|
||||
}
|
||||
|
||||
void updateTelemetryState(void)
|
||||
{
|
||||
bool State = mcfg.telemetry_softserial != TELEMETRY_UART ? true : f.ARMED;
|
||||
|
||||
if (State != telemetryEnabled) {
|
||||
if (mcfg.telemetry_softserial == TELEMETRY_UART) {
|
||||
if (State)
|
||||
serialInit(9600);
|
||||
else
|
||||
serialInit(mcfg.serial_baudrate);
|
||||
}
|
||||
telemetryEnabled = State;
|
||||
}
|
||||
}
|
||||
|
@ -218,6 +234,12 @@ static uint8_t cycleNum = 0;
|
|||
|
||||
void sendTelemetry(void)
|
||||
{
|
||||
if (mcfg.telemetry_softserial == TELEMETRY_UART && !f.ARMED)
|
||||
return;
|
||||
|
||||
if (serialTotalBytesWaiting(core.telemport) != 0)
|
||||
return;
|
||||
|
||||
if (millis() - lastCycleTime >= CYCLETIME) {
|
||||
lastCycleTime = millis();
|
||||
cycleNum++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue