mirror of
https://github.com/opentx/opentx.git
synced 2025-07-24 00:35:18 +03:00
Remarks from Damjan in e8aaa67450
taken into account
This commit is contained in:
parent
d85ee61cb3
commit
efb37a4419
5 changed files with 50 additions and 62 deletions
|
@ -57,16 +57,16 @@ PLAY_FUNCTION(playValue, source_t idx)
|
||||||
if (telemetrySensor.prec > 0) {
|
if (telemetrySensor.prec > 0) {
|
||||||
if (telemetrySensor.prec == 2) {
|
if (telemetrySensor.prec == 2) {
|
||||||
if (val >= 5000) {
|
if (val >= 5000) {
|
||||||
val = div100_and_round(val);
|
val = div_and_round<100>(val);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val = div10_and_round(val);
|
val = div_and_round<10>(val);
|
||||||
attr = PREC1;
|
attr = PREC1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (val >= 500) {
|
if (val >= 500) {
|
||||||
val = div10_and_round(val);
|
val = div_and_round<10>(val);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
attr = PREC1;
|
attr = PREC1;
|
||||||
|
@ -113,7 +113,7 @@ PLAY_FUNCTION(playValue, source_t idx)
|
||||||
if (TELEMETRY_STREAMING()) {
|
if (TELEMETRY_STREAMING()) {
|
||||||
idx -= (MIXSRC_FIRST_TELEM+TELEM_A1-1);
|
idx -= (MIXSRC_FIRST_TELEM+TELEM_A1-1);
|
||||||
uint8_t att = 0;
|
uint8_t att = 0;
|
||||||
int16_t converted_value = div10_and_round(applyChannelRatio(idx, val));;
|
int16_t converted_value = div_and_round<10>(applyChannelRatio(idx, val));;
|
||||||
if (ANA_CHANNEL_UNIT(idx) < UNIT_RAW) {
|
if (ANA_CHANNEL_UNIT(idx) < UNIT_RAW) {
|
||||||
att = PREC1;
|
att = PREC1;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ PLAY_FUNCTION(playValue, source_t idx)
|
||||||
break;
|
break;
|
||||||
case MIXSRC_FIRST_TELEM+TELEM_CELL-1:
|
case MIXSRC_FIRST_TELEM+TELEM_CELL-1:
|
||||||
case MIXSRC_FIRST_TELEM+TELEM_MIN_CELL-1:
|
case MIXSRC_FIRST_TELEM+TELEM_MIN_CELL-1:
|
||||||
PLAY_NUMBER(div10_and_round(val), 1+UNIT_VOLTS, PREC1);
|
PLAY_NUMBER(div_and_round<10>(val), 1+UNIT_VOLTS, PREC1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MIXSRC_FIRST_TELEM+TELEM_VFAS-1:
|
case MIXSRC_FIRST_TELEM+TELEM_VFAS-1:
|
||||||
|
@ -140,11 +140,11 @@ PLAY_FUNCTION(playValue, source_t idx)
|
||||||
case MIXSRC_FIRST_TELEM+TELEM_ACCx-1:
|
case MIXSRC_FIRST_TELEM+TELEM_ACCx-1:
|
||||||
case MIXSRC_FIRST_TELEM+TELEM_ACCy-1:
|
case MIXSRC_FIRST_TELEM+TELEM_ACCy-1:
|
||||||
case MIXSRC_FIRST_TELEM+TELEM_ACCz-1:
|
case MIXSRC_FIRST_TELEM+TELEM_ACCz-1:
|
||||||
PLAY_NUMBER(div10_and_round(val), 1+UNIT_G, PREC1);
|
PLAY_NUMBER(div_and_round<10>(val), 1+UNIT_G, PREC1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MIXSRC_FIRST_TELEM+TELEM_VSPEED-1:
|
case MIXSRC_FIRST_TELEM+TELEM_VSPEED-1:
|
||||||
PLAY_NUMBER(div10_and_round(val), 1+UNIT_METERS_PER_SECOND, PREC1);
|
PLAY_NUMBER(div_and_round<10>(val), 1+UNIT_METERS_PER_SECOND, PREC1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MIXSRC_FIRST_TELEM+TELEM_ASPEED-1:
|
case MIXSRC_FIRST_TELEM+TELEM_ASPEED-1:
|
||||||
|
@ -176,9 +176,9 @@ PLAY_FUNCTION(playValue, source_t idx)
|
||||||
{
|
{
|
||||||
getvalue_t rpm = val;
|
getvalue_t rpm = val;
|
||||||
if (rpm > 100)
|
if (rpm > 100)
|
||||||
rpm = 10 * div10_and_round(rpm);
|
rpm = 10 * div_and_round<10>(rpm);
|
||||||
if (rpm > 1000)
|
if (rpm > 1000)
|
||||||
rpm = 10 * div10_and_round(rpm);
|
rpm = 10 * div_and_round<10>(rpm);
|
||||||
PLAY_NUMBER(rpm, 1+UNIT_RPMS, 0);
|
PLAY_NUMBER(rpm, 1+UNIT_RPMS, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -969,14 +969,14 @@ void putsTelemetryChannelValue(coord_t x, coord_t y, uint8_t channel, lcdint_t v
|
||||||
{
|
{
|
||||||
lcdint_t converted_value = applyChannelRatio(channel, val);
|
lcdint_t converted_value = applyChannelRatio(channel, val);
|
||||||
if (ANA_CHANNEL_UNIT(channel) >= UNIT_RAW) {
|
if (ANA_CHANNEL_UNIT(channel) >= UNIT_RAW) {
|
||||||
converted_value = div10_and_round(converted_value);
|
converted_value = div_and_round<10>(converted_value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (abs(converted_value) < 1000) {
|
if (abs(converted_value) < 1000) {
|
||||||
att |= PREC2;
|
att |= PREC2;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
converted_value = div10_and_round(converted_value);
|
converted_value = div_and_round<10>(converted_value);
|
||||||
att |= PREC1;
|
att |= PREC1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1019,7 +1019,7 @@ void putsTelemetryChannelValue(coord_t x, coord_t y, uint8_t channel, lcdint_t v
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TELEM_VSPEED-1:
|
case TELEM_VSPEED-1:
|
||||||
putsValueWithUnit(x, y, div10_and_round(val), UNIT_RAW, att|PREC1);
|
putsValueWithUnit(x, y, div_and_round<10>(val), UNIT_RAW, att|PREC1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TELEM_ASPEED-1:
|
case TELEM_ASPEED-1:
|
||||||
|
@ -1041,7 +1041,7 @@ void putsTelemetryChannelValue(coord_t x, coord_t y, uint8_t channel, lcdint_t v
|
||||||
|
|
||||||
#if defined(FRSKY_SPORT)
|
#if defined(FRSKY_SPORT)
|
||||||
case TELEM_ALT-1:
|
case TELEM_ALT-1:
|
||||||
putsValueWithUnit(x, y, div10_and_round(val), UNIT_DIST, att|PREC1);
|
putsValueWithUnit(x, y, div_and_round<10>(val), UNIT_DIST, att|PREC1);
|
||||||
break;
|
break;
|
||||||
#elif defined(WS_HOW_HIGH)
|
#elif defined(WS_HOW_HIGH)
|
||||||
case TELEM_ALT-1:
|
case TELEM_ALT-1:
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) OpenTX
|
* Copyright (C) OpenTX
|
||||||
*
|
*
|
||||||
* Based on code named
|
* Based on code named
|
||||||
* th9x - http://code.google.com/p/th9x
|
* th9x - http://code.google.com/p/th9x
|
||||||
* er9x - http://code.google.com/p/er9x
|
* er9x - http://code.google.com/p/er9x
|
||||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
*
|
*
|
||||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
* published by the Free Software Foundation.
|
* published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
|
|
||||||
#if !defined(CPUARM)
|
#if !defined(CPUARM)
|
||||||
|
@ -127,27 +127,6 @@ uint16_t isqrt32(uint32_t n)
|
||||||
-205 -> -21
|
-205 -> -21
|
||||||
-204 -> -20
|
-204 -> -20
|
||||||
*/
|
*/
|
||||||
getvalue_t div10_and_round(getvalue_t value)
|
|
||||||
{
|
|
||||||
if (value >= 0 ) {
|
|
||||||
value += 5;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
value -= 5;
|
|
||||||
}
|
|
||||||
return value/10;
|
|
||||||
}
|
|
||||||
|
|
||||||
getvalue_t div100_and_round(getvalue_t value)
|
|
||||||
{
|
|
||||||
if (value >= 0 ) {
|
|
||||||
value += 50;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
value -= 50;
|
|
||||||
}
|
|
||||||
return value/100;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(PCBTARANIS)
|
#if defined(PCBTARANIS)
|
||||||
double gpsToDouble(bool neg, int16_t bp, int16_t ap)
|
double gpsToDouble(bool neg, int16_t bp, int16_t ap)
|
||||||
|
|
|
@ -49,7 +49,7 @@ int16_t ex_chans[NUM_CHNOUT] = {0}; // Outputs (before LIMITS) of the last perMa
|
||||||
int16_t cyc_anas[3] = {0};
|
int16_t cyc_anas[3] = {0};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void applyExpos(int16_t *anas, uint8_t mode APPLY_EXPOS_EXTRA_PARAMS)
|
void applyExpos(int16_t * anas, uint8_t mode APPLY_EXPOS_EXTRA_PARAMS)
|
||||||
{
|
{
|
||||||
#if !defined(VIRTUALINPUTS)
|
#if !defined(VIRTUALINPUTS)
|
||||||
int16_t anas2[NUM_INPUTS]; // values before expo, to ensure same expo base when multiple expo lines are used
|
int16_t anas2[NUM_INPUTS]; // values before expo, to ensure same expo base when multiple expo lines are used
|
||||||
|
@ -70,7 +70,7 @@ void applyExpos(int16_t *anas, uint8_t mode APPLY_EXPOS_EXTRA_PARAMS)
|
||||||
continue;
|
continue;
|
||||||
if (getSwitch(ed->swtch)) {
|
if (getSwitch(ed->swtch)) {
|
||||||
#if defined(VIRTUALINPUTS)
|
#if defined(VIRTUALINPUTS)
|
||||||
int v;
|
int32_t v;
|
||||||
if (ed->srcRaw == ovwrIdx) {
|
if (ed->srcRaw == ovwrIdx) {
|
||||||
v = ovwrValue;
|
v = ovwrValue;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ void applyExpos(int16_t *anas, uint8_t mode APPLY_EXPOS_EXTRA_PARAMS)
|
||||||
//========== WEIGHT ===============
|
//========== WEIGHT ===============
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
int32_t weight = GET_GVAR_PREC1(ed->weight, MIN_EXPO_WEIGHT, 100, mixerCurrentFlightMode);
|
int32_t weight = GET_GVAR_PREC1(ed->weight, MIN_EXPO_WEIGHT, 100, mixerCurrentFlightMode);
|
||||||
v = ((int32_t)v * weight) / 1000;
|
v = div_and_round<1000>((int32_t)v * weight);
|
||||||
#else
|
#else
|
||||||
int16_t weight = GET_GVAR(ed->weight, MIN_EXPO_WEIGHT, 100, mixerCurrentFlightMode);
|
int16_t weight = GET_GVAR(ed->weight, MIN_EXPO_WEIGHT, 100, mixerCurrentFlightMode);
|
||||||
weight = calc100to256(weight);
|
weight = calc100to256(weight);
|
||||||
|
@ -118,7 +118,7 @@ void applyExpos(int16_t *anas, uint8_t mode APPLY_EXPOS_EXTRA_PARAMS)
|
||||||
#if defined(VIRTUALINPUTS)
|
#if defined(VIRTUALINPUTS)
|
||||||
//========== OFFSET ===============
|
//========== OFFSET ===============
|
||||||
int32_t offset = GET_GVAR_PREC1(ed->offset, -100, 100, mixerCurrentFlightMode);
|
int32_t offset = GET_GVAR_PREC1(ed->offset, -100, 100, mixerCurrentFlightMode);
|
||||||
if (offset) v += calc100toRESX(offset) / 10;
|
if (offset) v += div_and_round<10>(calc100toRESX(offset));
|
||||||
|
|
||||||
//========== TRIMS ================
|
//========== TRIMS ================
|
||||||
if (ed->carryTrim < TRIM_ON)
|
if (ed->carryTrim < TRIM_ON)
|
||||||
|
@ -856,14 +856,14 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms)
|
||||||
//========== WEIGHT ===============
|
//========== WEIGHT ===============
|
||||||
int32_t dv = (int32_t)v * weight;
|
int32_t dv = (int32_t)v * weight;
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
dv /= 10;
|
dv = div_and_round<10>(dv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//========== OFFSET / AFTER ===============
|
//========== OFFSET / AFTER ===============
|
||||||
if (apply_offset_and_curve) {
|
if (apply_offset_and_curve) {
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
int32_t offset = GET_GVAR_PREC1(MD_OFFSET(md), GV_RANGELARGE_NEG, GV_RANGELARGE, mixerCurrentFlightMode);
|
int32_t offset = GET_GVAR_PREC1(MD_OFFSET(md), GV_RANGELARGE_NEG, GV_RANGELARGE, mixerCurrentFlightMode);
|
||||||
if (offset) dv += int32_t(calc100toRESX_16Bits(offset) / 10) << 8;
|
if (offset) dv += div_and_round<10>(calc100toRESX_16Bits(offset)) << 8;
|
||||||
#else
|
#else
|
||||||
int16_t offset = GET_GVAR(MD_OFFSET(md), GV_RANGELARGE_NEG, GV_RANGELARGE, mixerCurrentFlightMode);
|
int16_t offset = GET_GVAR(MD_OFFSET(md), GV_RANGELARGE_NEG, GV_RANGELARGE, mixerCurrentFlightMode);
|
||||||
if (offset) dv += int32_t(calc100toRESX_16Bits(offset)) << 8;
|
if (offset) dv += int32_t(calc100toRESX_16Bits(offset)) << 8;
|
||||||
|
|
|
@ -1634,8 +1634,17 @@ lcdint_t applyChannelRatio(source_t channel, lcdint_t val);
|
||||||
#define ANA_CHANNEL_UNIT(channel) g_model.frsky.channels[channel].type
|
#define ANA_CHANNEL_UNIT(channel) g_model.frsky.channels[channel].type
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
getvalue_t div10_and_round(getvalue_t value);
|
template<int I>
|
||||||
getvalue_t div100_and_round(getvalue_t value);
|
getvalue_t div_and_round(getvalue_t value)
|
||||||
|
{
|
||||||
|
if (value >= 0 ) {
|
||||||
|
value += I / 2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
value -= I / 2;
|
||||||
|
}
|
||||||
|
return value / I;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(FRSKY)
|
#if defined(FRSKY)
|
||||||
NOINLINE uint8_t getRssiAlarmValue(uint8_t alarm);
|
NOINLINE uint8_t getRssiAlarmValue(uint8_t alarm);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue