* WiP: new module interface * WiP: softserial timer DMA * WiP: setup() and send() in one step and remove methods specific to internal or external module * fixes and extra port config * horus targets * module ports have moved * T8 support (only internal module) * fix nv14 * stupid GCC.... * disable BT * remove nv14 telem driver * remove old aux serial driver * Move module buffers out of pulses.h * Soft serial fixes and PXX1 support * Fixed PPM module output * Fixed CLI * compilation fixes * Ported bluetooth and flysky gimbal to new serial driver * Re-enable soft-serial RX * fixes and cleanup * nv14 fixes * Fix flysky gimbals * Ghost module * 16 bytes of RAM * Remove getByte from module API * Ghost cleanup * fix: _half_duplex_input() must be called after usart init * WiP * more cleanup * Remove board specific settings from PXX1 / PXX2 drivers * A bit of PXX2 header cleanup * Add support for OVER8 and ONEBIT * Add some support for inverters (NV14 / EL18) * Support NV14 power fixes in generic board * Fix polarity handling * Fix RX DMA * Fix mixer not running * Add soft-serial polarity control * Quick fix for telemetry polling while module port is changed * Fix bootloader DEBUG * Fix MPM telemetry * Fix pulse start * DSM2 soft-serial fallback * DSMP async module restart * Fix CRSF LUA upstream * Remove global variable telemetryProtocol * Use HAL/LL constants * Fix various issue with AFHDS3 and NV14/EL18 internal module * Fixed S.PORT unit tests * fix: update widx after writing at current index * fix: init error condition * Fix: possible infinite loop in _find_port() * Add support for bidir S.PORT init * Add support for "getLastByte" in HW serial driver * PXX1: Add support for S.PORT based on IDLE callback * Fix rebase error * Fix softserial _rx_fifo_push() * Add softserial support for waitForTxCompleted() * Fix MPM flashing (internal / external) * Fixed external MPM * Activate RX DMA on internal module Seems to work with serial passthrough without issues, at least on the L3R PRO. * Fix softserial DMA on stdlcd F4 targets * Add softserial support for 32bit timers (mostly TIM2) * More precise soft-serial * Fix MPM update using inverters & HW uart * Raise S.PORT DMA/USART IRQ prio to achieve faster switching to input * Remove useless delays * Fix flashing external ELRS module * Added a retry mechanism for FrSky S.PORT update * Remove useless enableRx() * External FrSky modules are all flashed via S.PORT * Remove power management unit update This was only used on the first batch of X-lite.
325 lines
13 KiB
C++
325 lines
13 KiB
C++
/*
|
|
* Copyright (C) EdgeTX
|
|
*
|
|
* Based on code named
|
|
* opentx - https://github.com/opentx/opentx
|
|
* th9x - http://code.google.com/p/th9x
|
|
* er9x - http://code.google.com/p/er9x
|
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
|
*
|
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#include "opentx.h"
|
|
|
|
enum SensorFields {
|
|
SENSOR_FIELD_NAME,
|
|
SENSOR_FIELD_TYPE,
|
|
SENSOR_FIELD_ID,
|
|
SENSOR_FIELD_FORMULA=SENSOR_FIELD_ID,
|
|
// SENSOR_FIELD_RECEIVER_NAME,
|
|
SENSOR_FIELD_UNIT,
|
|
SENSOR_FIELD_PRECISION,
|
|
SENSOR_FIELD_PARAM1,
|
|
SENSOR_FIELD_PARAM2,
|
|
SENSOR_FIELD_PARAM3,
|
|
SENSOR_FIELD_PARAM4,
|
|
SENSOR_FIELD_AUTOOFFSET,
|
|
SENSOR_FIELD_ONLYPOSITIVE,
|
|
SENSOR_FIELD_FILTER,
|
|
SENSOR_FIELD_PERSISTENT,
|
|
SENSOR_FIELD_LOGS,
|
|
SENSOR_FIELD_MAX
|
|
};
|
|
|
|
#define SENSOR_2ND_COLUMN (12*FW)
|
|
#define SENSOR_3RD_COLUMN (18*FW)
|
|
|
|
#define SENSOR_UNIT_ROWS ((sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_DIST)) || sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
|
|
#define SENSOR_PREC_ROWS (sensor->isPrecConfigurable() && sensor->unit != UNIT_FAHRENHEIT ? (uint8_t)0 : HIDDEN_ROW)
|
|
#define SENSOR_PARAM1_ROWS (sensor->unit >= UNIT_FIRST_VIRTUAL ? HIDDEN_ROW : (uint8_t)0)
|
|
#define SENSOR_PARAM2_ROWS (sensor->unit == UNIT_GPS || sensor->unit == UNIT_DATETIME || sensor->unit == UNIT_CELLS || (sensor->type==TELEM_TYPE_CALCULATED && (sensor->formula==TELEM_FORMULA_CONSUMPTION || sensor->formula==TELEM_FORMULA_TOTALIZE)) ? HIDDEN_ROW : (uint8_t)0)
|
|
#define SENSOR_PARAM3_ROWS (sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY) ? (uint8_t)0 : HIDDEN_ROW
|
|
#define SENSOR_PARAM4_ROWS (sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY) ? (uint8_t)0 : HIDDEN_ROW
|
|
#define SENSOR_AUTOOFFSET_ROWS (sensor->unit != UNIT_RPMS && sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
|
|
#define SENSOR_ONLYPOS_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
|
|
#define SENSOR_FILTER_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
|
|
#define SENSOR_PERSISTENT_ROWS (sensor->type == TELEM_TYPE_CALCULATED ? (uint8_t)0 : HIDDEN_ROW)
|
|
|
|
void menuModelSensor(event_t event)
|
|
{
|
|
TelemetrySensor * sensor = &g_model.telemetrySensors[s_currIdx];
|
|
|
|
drawStringWithIndex(PSIZE(TR_MENUSENSOR)*FW+FW, 0, STR_SENSOR, s_currIdx+1);
|
|
drawSensorCustomValue(25*FW, 0, s_currIdx, getValue(MIXSRC_FIRST_TELEM+3*s_currIdx));
|
|
lcdDrawFilledRect(0, 0, LCD_W, FH, SOLID, FILL_WHITE|GREY_DEFAULT);
|
|
|
|
uint8_t old_editMode = s_editMode;
|
|
|
|
SUBMENU(STR_MENUSENSOR, SENSOR_FIELD_MAX, {
|
|
0, //Name
|
|
0, // Type
|
|
sensor->type == TELEM_TYPE_CALCULATED ? (uint8_t)0 : (uint8_t)1, // ID / Formula
|
|
// sensor->type == TELEM_TYPE_CALCULATED ? HIDDEN_ROW : READONLY_ROW, // Receiver name
|
|
SENSOR_UNIT_ROWS,
|
|
SENSOR_PREC_ROWS,
|
|
SENSOR_PARAM1_ROWS,
|
|
SENSOR_PARAM2_ROWS,
|
|
SENSOR_PARAM3_ROWS,
|
|
SENSOR_PARAM4_ROWS,
|
|
SENSOR_AUTOOFFSET_ROWS,
|
|
SENSOR_ONLYPOS_ROWS,
|
|
SENSOR_FILTER_ROWS,
|
|
SENSOR_PERSISTENT_ROWS,
|
|
0 // Logs
|
|
});
|
|
|
|
for (uint8_t i=0; i<NUM_BODY_LINES; i++) {
|
|
coord_t y = MENU_HEADER_HEIGHT + 1 + i*FH;
|
|
int k = i + menuVerticalOffset;
|
|
|
|
for (int j=0; j<k; j++) {
|
|
if (mstate_tab[j+1] == HIDDEN_ROW) {
|
|
if (++k >= (int)DIM(mstate_tab)) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
LcdFlags attr = (menuVerticalPosition==k ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0);
|
|
|
|
switch (k) {
|
|
case SENSOR_FIELD_NAME:
|
|
editSingleName(SENSOR_2ND_COLUMN, y, STR_NAME, sensor->label,
|
|
TELEM_LABEL_LEN, event, attr, old_editMode);
|
|
break;
|
|
case SENSOR_FIELD_TYPE:
|
|
sensor->type = editChoice(SENSOR_2ND_COLUMN, y, NO_INDENT(STR_TYPE), STR_VSENSORTYPES, sensor->type, 0, 1, attr, event);
|
|
if (attr && checkIncDec_Ret) {
|
|
sensor->instance = 0;
|
|
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
|
sensor->param = 0;
|
|
sensor->filter = 0;
|
|
sensor->autoOffset = 0;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case SENSOR_FIELD_ID:
|
|
if (sensor->type == TELEM_TYPE_CUSTOM) {
|
|
lcdDrawTextAlignedLeft(y, STR_ID);
|
|
lcdDrawHexNumber(SENSOR_2ND_COLUMN, y, sensor->id, LEFT|(menuHorizontalPosition==0 ? attr : 0));
|
|
lcdDrawNumber(SENSOR_3RD_COLUMN, y, (sensor->instance & 0x1F) + 1, LEFT|(menuHorizontalPosition==1 ? attr : 0));
|
|
if (attr) {
|
|
switch (menuHorizontalPosition) {
|
|
case 0:
|
|
sensor->id = checkIncDec(event, sensor->id, 0x0000, 0xffff, INCDEC_REP10|NO_INCDEC_MARKS);
|
|
break;
|
|
|
|
case 1:
|
|
CHECK_INCDEC_MODELVAR_ZERO(event, sensor->instance, 0xff);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
sensor->formula = editChoice(SENSOR_2ND_COLUMN, y, STR_FORMULA, STR_VFORMULAS, sensor->formula, 0, TELEM_FORMULA_LAST, attr, event);
|
|
if (attr && checkIncDec_Ret) {
|
|
sensor->param = 0;
|
|
if (sensor->formula == TELEM_FORMULA_CELL) {
|
|
sensor->unit = UNIT_VOLTS;
|
|
sensor->prec = 2;
|
|
}
|
|
else if (sensor->formula == TELEM_FORMULA_DIST) {
|
|
sensor->unit = UNIT_DIST;
|
|
sensor->prec = 0;
|
|
}
|
|
else if (sensor->formula == TELEM_FORMULA_CONSUMPTION) {
|
|
sensor->unit = UNIT_MAH;
|
|
sensor->prec = 0;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
|
|
// case SENSOR_FIELD_RECEIVER_NAME:
|
|
// lcdDrawTextAlignedLeft(y, STR_SOURCE);
|
|
// // TODO: this needs to be known from the sensor data alone!
|
|
// if (telemetryProtocol == PROTOCOL_TELEMETRY_FRSKY_SPORT &&
|
|
// sensor->frskyInstance.rxIndex != TELEMETRY_ENDPOINT_SPORT) {
|
|
// drawReceiverName(SENSOR_2ND_COLUMN, y, sensor->frskyInstance.rxIndex >> 2,
|
|
// sensor->frskyInstance.rxIndex & 0x03, 0);
|
|
// }
|
|
// else if (isModuleUsingSport(INTERNAL_MODULE, g_model.moduleData[INTERNAL_MODULE].type)) {
|
|
// // far from perfect
|
|
// lcdDrawText(SENSOR_2ND_COLUMN, y, STR_INTERNAL_MODULE);
|
|
// }
|
|
// else {
|
|
// lcdDrawText(SENSOR_2ND_COLUMN, y, STR_EXTERNAL_MODULE);
|
|
// }
|
|
// break;
|
|
|
|
case SENSOR_FIELD_UNIT:
|
|
lcdDrawTextAlignedLeft(y, STR_UNIT);
|
|
lcdDrawTextAtIndex(SENSOR_2ND_COLUMN, y, STR_VTELEMUNIT, sensor->unit, attr);
|
|
if (attr) {
|
|
CHECK_INCDEC_MODELVAR_ZERO(event, sensor->unit, UNIT_MAX);
|
|
if (checkIncDec_Ret) {
|
|
if (sensor->unit == UNIT_FAHRENHEIT) {
|
|
sensor->prec = 0;
|
|
}
|
|
telemetryItems[s_currIdx].clear();
|
|
}
|
|
}
|
|
break;
|
|
|
|
case SENSOR_FIELD_PRECISION:
|
|
sensor->prec = editChoice(SENSOR_2ND_COLUMN, y, STR_PRECISION, STR_VPREC, sensor->prec, 0, 2, attr, event);
|
|
if (attr && checkIncDec_Ret) {
|
|
telemetryItems[s_currIdx].clear();
|
|
}
|
|
break;
|
|
|
|
case SENSOR_FIELD_PARAM1:
|
|
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
|
if (sensor->formula == TELEM_FORMULA_CELL) {
|
|
lcdDrawTextAlignedLeft(y, STR_CELLSENSOR);
|
|
drawSource(SENSOR_2ND_COLUMN, y, sensor->cell.source ? MIXSRC_FIRST_TELEM+3*(sensor->cell.source-1) : 0, attr);
|
|
if (attr) {
|
|
sensor->cell.source = checkIncDec(event, sensor->cell.source, 0, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isCellsSensor);
|
|
}
|
|
break;
|
|
}
|
|
else if (sensor->formula == TELEM_FORMULA_DIST) {
|
|
lcdDrawTextAlignedLeft(y, STR_GPSSENSOR);
|
|
drawSource(SENSOR_2ND_COLUMN, y, sensor->dist.gps ? MIXSRC_FIRST_TELEM+3*(sensor->dist.gps-1) : 0, attr);
|
|
if (attr) {
|
|
sensor->dist.gps = checkIncDec(event, sensor->dist.gps, 0, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isGPSSensor);
|
|
}
|
|
break;
|
|
}
|
|
else if (sensor->formula == TELEM_FORMULA_CONSUMPTION) {
|
|
lcdDrawTextAlignedLeft(y, STR_CURRENTSENSOR);
|
|
drawSource(SENSOR_2ND_COLUMN, y, sensor->consumption.source ? MIXSRC_FIRST_TELEM+3*(sensor->consumption.source-1) : 0, attr);
|
|
if (attr) {
|
|
sensor->consumption.source = checkIncDec(event, sensor->consumption.source, 0, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isSensorAvailable);
|
|
}
|
|
break;
|
|
}
|
|
else if (sensor->formula == TELEM_FORMULA_TOTALIZE) {
|
|
lcdDrawTextAlignedLeft(y, STR_SOURCE);
|
|
drawSource(SENSOR_2ND_COLUMN, y, sensor->consumption.source ? MIXSRC_FIRST_TELEM+3*(sensor->consumption.source-1) : 0, attr);
|
|
if (attr) {
|
|
sensor->consumption.source = checkIncDec(event, sensor->consumption.source, 0, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isSensorAvailable);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
else {
|
|
if (sensor->unit == UNIT_RPMS) {
|
|
lcdDrawTextAlignedLeft(y, STR_BLADES);
|
|
if (attr) sensor->custom.ratio = checkIncDec(event, sensor->custom.ratio, 1, 30000, EE_MODEL|NO_INCDEC_MARKS|INCDEC_REP10);
|
|
lcdDrawNumber(SENSOR_2ND_COLUMN, y, sensor->custom.ratio, LEFT|attr);
|
|
break;
|
|
}
|
|
else {
|
|
lcdDrawTextAlignedLeft(y, STR_RATIO);
|
|
if (attr) sensor->custom.ratio = checkIncDec(event, sensor->custom.ratio, 0, 30000, EE_MODEL|NO_INCDEC_MARKS|INCDEC_REP10);
|
|
if (sensor->custom.ratio == 0)
|
|
lcdDrawChar(SENSOR_2ND_COLUMN, y, '-', attr);
|
|
else
|
|
lcdDrawNumber(SENSOR_2ND_COLUMN, y, sensor->custom.ratio, LEFT|attr|PREC1);
|
|
break;
|
|
}
|
|
}
|
|
// no break
|
|
|
|
case SENSOR_FIELD_PARAM2:
|
|
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
|
if (sensor->formula == TELEM_FORMULA_CELL) {
|
|
sensor->cell.index = editChoice(SENSOR_2ND_COLUMN, y, STR_CELLINDEX, STR_VCELLINDEX, sensor->cell.index, TELEM_CELL_INDEX_LOWEST, TELEM_CELL_INDEX_LAST, attr, event);
|
|
break;
|
|
}
|
|
else if (sensor->formula == TELEM_FORMULA_DIST) {
|
|
lcdDrawTextAlignedLeft(y, STR_ALTSENSOR);
|
|
drawSource(SENSOR_2ND_COLUMN, y, sensor->dist.alt ? MIXSRC_FIRST_TELEM+3*(sensor->dist.alt-1) : 0, attr);
|
|
if (attr) {
|
|
sensor->dist.alt = checkIncDec(event, sensor->dist.alt, 0, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isAltSensor);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
else if (sensor->unit == UNIT_RPMS) {
|
|
lcdDrawTextAlignedLeft(y, STR_MULTIPLIER);
|
|
if (attr) sensor->custom.offset = checkIncDec(event, sensor->custom.offset, 1, 30000, EE_MODEL|NO_INCDEC_MARKS|INCDEC_REP10);
|
|
lcdDrawNumber(SENSOR_2ND_COLUMN, y, sensor->custom.offset, LEFT|attr);
|
|
break;
|
|
}
|
|
else {
|
|
lcdDrawTextAlignedLeft(y, STR_OFFSET);
|
|
if (attr) sensor->custom.offset = checkIncDec(event, sensor->custom.offset, -30000, +30000, EE_MODEL|NO_INCDEC_MARKS|INCDEC_REP10);
|
|
if (sensor->prec > 0) attr |= (sensor->prec == 2 ? PREC2 : PREC1);
|
|
lcdDrawNumber(SENSOR_2ND_COLUMN, y, sensor->custom.offset, LEFT|attr);
|
|
break;
|
|
}
|
|
// no break
|
|
|
|
case SENSOR_FIELD_PARAM3:
|
|
// no break
|
|
|
|
case SENSOR_FIELD_PARAM4:
|
|
{
|
|
drawStringWithIndex(0, y, STR_SOURCE, k-SENSOR_FIELD_PARAM1+1);
|
|
int8_t * source = &sensor->calc.sources[k-SENSOR_FIELD_PARAM1];
|
|
if (attr) {
|
|
*source = checkIncDec(event, *source, -MAX_TELEMETRY_SENSORS, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isSensorAvailable);
|
|
}
|
|
if (*source < 0) {
|
|
lcdDrawChar(SENSOR_2ND_COLUMN, y, '-', attr);
|
|
drawSource(lcdNextPos, y, MIXSRC_FIRST_TELEM+3*(-1-*source), attr);
|
|
}
|
|
else {
|
|
drawSource(SENSOR_2ND_COLUMN, y, *source ? MIXSRC_FIRST_TELEM+3*(*source-1) : 0, attr);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case SENSOR_FIELD_AUTOOFFSET:
|
|
sensor->autoOffset = editCheckBox(sensor->autoOffset, SENSOR_2ND_COLUMN, y, STR_AUTOOFFSET, attr, event);
|
|
break;
|
|
|
|
case SENSOR_FIELD_ONLYPOSITIVE:
|
|
sensor->onlyPositive = editCheckBox(sensor->onlyPositive, SENSOR_2ND_COLUMN, y, STR_ONLYPOSITIVE, attr, event);
|
|
break;
|
|
|
|
case SENSOR_FIELD_FILTER:
|
|
sensor->filter = editCheckBox(sensor->filter, SENSOR_2ND_COLUMN, y, STR_FILTER, attr, event);
|
|
break;
|
|
|
|
case SENSOR_FIELD_PERSISTENT:
|
|
sensor->persistent = editCheckBox(sensor->persistent, SENSOR_2ND_COLUMN, y, NO_INDENT(STR_PERSISTENT), attr, event);
|
|
if (checkIncDec_Ret && !sensor->persistent) {
|
|
sensor->persistentValue = 0;
|
|
}
|
|
break;
|
|
|
|
case SENSOR_FIELD_LOGS:
|
|
sensor->logs = editCheckBox(sensor->logs, SENSOR_2ND_COLUMN, y, STR_LOGS, attr, event);
|
|
if (attr && checkIncDec_Ret) {
|
|
logsClose();
|
|
}
|
|
break;
|
|
|
|
}
|
|
}
|
|
}
|