mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 06:45:16 +03:00
Changed float parameters to int16 in 'cli.c'.
Fixed buffer length used for 'ftoa'. Got rid of magic numbers, replaced 'digitalIdlePercent' with 'digitalIdleValue'.
This commit is contained in:
parent
ce8c5fbd79
commit
9c29475ba4
16 changed files with 77 additions and 120 deletions
|
@ -465,8 +465,6 @@ typedef enum {
|
|||
VAR_INT8 = (1 << VALUE_TYPE_OFFSET),
|
||||
VAR_UINT16 = (2 << VALUE_TYPE_OFFSET),
|
||||
VAR_INT16 = (3 << VALUE_TYPE_OFFSET),
|
||||
//VAR_UINT32 = (4 << VALUE_TYPE_OFFSET),
|
||||
VAR_FLOAT = (5 << VALUE_TYPE_OFFSET), // 0x05
|
||||
|
||||
// value section, bits 4-5
|
||||
MASTER_VALUE = (0 << VALUE_SECTION_OFFSET),
|
||||
|
@ -549,9 +547,9 @@ static const clivalue_t valueTable[] = {
|
|||
#ifdef BARO
|
||||
{ "baro_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_BARO_HARDWARE }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_hardware) },
|
||||
{ "baro_tab_size", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, BARO_SAMPLE_COUNT_MAX }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_sample_count) },
|
||||
{ "baro_noise_lpf", VAR_FLOAT | MASTER_VALUE, .config.minmax = { 0 , 1 }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_noise_lpf) },
|
||||
{ "baro_cf_vel", VAR_FLOAT | MASTER_VALUE, .config.minmax = { 0 , 1 }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_cf_vel) },
|
||||
{ "baro_cf_alt", VAR_FLOAT | MASTER_VALUE, .config.minmax = { 0 , 1 }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_cf_alt) },
|
||||
{ "baro_noise_lpf", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, 1000 }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_noise_lpf) },
|
||||
{ "baro_cf_vel", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, 1000 }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_cf_vel) },
|
||||
{ "baro_cf_alt", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, 1000 }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_cf_alt) },
|
||||
#endif
|
||||
|
||||
// PG_RX_CONFIG
|
||||
|
@ -599,7 +597,7 @@ static const clivalue_t valueTable[] = {
|
|||
{ "max_throttle", VAR_UINT16 | MASTER_VALUE, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, maxthrottle) },
|
||||
{ "min_command", VAR_UINT16 | MASTER_VALUE, .config.minmax = { PWM_RANGE_ZERO, PWM_RANGE_MAX }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, mincommand) },
|
||||
#ifdef USE_DSHOT
|
||||
{ "digital_idle_percent", VAR_FLOAT | MASTER_VALUE, .config.minmax = { 0, 20 }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, digitalIdleOffsetPercent) },
|
||||
{ "digital_idle_value", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, 2000 }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, digitalIdleOffsetValue) },
|
||||
#endif
|
||||
{ "use_unsynced_pwm", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.useUnsyncedPwm) },
|
||||
{ "motor_pwm_protocol", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_MOTOR_PWM_PROTOCOL }, PG_MOTOR_CONFIG, offsetof(motorConfig_t, dev.motorPwmProtocol) },
|
||||
|
@ -745,16 +743,16 @@ static const clivalue_t valueTable[] = {
|
|||
{ "vbat_pid_gain", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_PID_PROFILE, offsetof(pidProfile_t, vbatPidCompensation) },
|
||||
{ "pid_at_min_throttle", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_PID_PROFILE, offsetof(pidProfile_t, pidAtMinThrottle) },
|
||||
{ "anti_gravity_thresh", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 20, 1000 }, PG_PID_PROFILE, offsetof(pidProfile_t, itermThrottleThreshold) },
|
||||
{ "anti_gravity_gain", VAR_FLOAT | PROFILE_VALUE, .config.minmax = { 1, 30 }, PG_PID_PROFILE, offsetof(pidProfile_t, itermAcceleratorGain) },
|
||||
{ "anti_gravity_gain", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 1, 30000 }, PG_PID_PROFILE, offsetof(pidProfile_t, itermAcceleratorGain) },
|
||||
{ "setpoint_relax_ratio", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 100 }, PG_PID_PROFILE, offsetof(pidProfile_t, setpointRelaxRatio) },
|
||||
{ "d_setpoint_weight", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 254 }, PG_PID_PROFILE, offsetof(pidProfile_t, dtermSetpointWeight) },
|
||||
{ "yaw_accel_limit", VAR_FLOAT | PROFILE_VALUE, .config.minmax = { 0.1f, 50.0f }, PG_PID_PROFILE, offsetof(pidProfile_t, yawRateAccelLimit) },
|
||||
{ "accel_limit", VAR_FLOAT | PROFILE_VALUE, .config.minmax = { 0.1f, 50.0f }, PG_PID_PROFILE, offsetof(pidProfile_t, rateAccelLimit) },
|
||||
{ "yaw_accel_limit", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 1, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, yawRateAccelLimit) },
|
||||
{ "accel_limit", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 1, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, rateAccelLimit) },
|
||||
|
||||
{ "iterm_windup", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 30, 100 }, PG_PID_PROFILE, offsetof(pidProfile_t, itermWindupPointPercent) },
|
||||
{ "yaw_lowpass", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 0, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, yaw_lpf_hz) },
|
||||
{ "pidsum_limit", VAR_FLOAT | PROFILE_VALUE, .config.minmax = { 0.1, 1.0 }, PG_PID_PROFILE, offsetof(pidProfile_t, pidSumLimit) },
|
||||
{ "pidsum_limit_yaw", VAR_FLOAT | PROFILE_VALUE, .config.minmax = { 0.1, 1.0 }, PG_PID_PROFILE, offsetof(pidProfile_t, pidSumLimitYaw) },
|
||||
{ "pidsum_limit", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 100, 1000 }, PG_PID_PROFILE, offsetof(pidProfile_t, pidSumLimit) },
|
||||
{ "pidsum_limit_yaw", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 100, 1000 }, PG_PID_PROFILE, offsetof(pidProfile_t, pidSumLimitYaw) },
|
||||
|
||||
{ "p_pitch", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, P8[PITCH]) },
|
||||
{ "i_pitch", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 200 }, PG_PID_PROFILE, offsetof(pidProfile_t, I8[PITCH]) },
|
||||
|
@ -797,8 +795,8 @@ static const clivalue_t valueTable[] = {
|
|||
{ "tlm_switch", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, telemetry_switch) },
|
||||
{ "tlm_inversion", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, telemetry_inversion) },
|
||||
{ "sport_halfduplex", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, sportHalfDuplex) },
|
||||
{ "frsky_default_lat", VAR_FLOAT | MASTER_VALUE, .config.minmax = { -90.0, 90.0 }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, gpsNoFixLatitude) },
|
||||
{ "frsky_default_long", VAR_FLOAT | MASTER_VALUE, .config.minmax = { -180.0, 180.0 }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, gpsNoFixLongitude) },
|
||||
{ "frsky_default_lat", VAR_INT16 | MASTER_VALUE, .config.minmax = { -9000, 9000 }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, gpsNoFixLatitude) },
|
||||
{ "frsky_default_long", VAR_INT16 | MASTER_VALUE, .config.minmax = { -18000, 18000 }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, gpsNoFixLongitude) },
|
||||
{ "frsky_gps_format", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, FRSKY_FORMAT_NMEA }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, frsky_coordinate_format) },
|
||||
{ "frsky_unit", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_UNIT }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, frsky_unit) },
|
||||
{ "frsky_vfas_precision", VAR_UINT8 | MASTER_VALUE, .config.minmax = { FRSKY_VFAS_PRECISION_LOW, FRSKY_VFAS_PRECISION_HIGH }, PG_TELEMETRY_CONFIG, offsetof(telemetryConfig_t, frsky_vfas_precision) },
|
||||
|
@ -1058,7 +1056,6 @@ static void cliPrintf(const char *format, ...)
|
|||
static void printValuePointer(const clivalue_t *var, const void *valuePointer, uint32_t full)
|
||||
{
|
||||
int32_t value = 0;
|
||||
char buf[8];
|
||||
|
||||
switch (var->type & VALUE_TYPE_MASK) {
|
||||
case VAR_UINT8:
|
||||
|
@ -1076,19 +1073,6 @@ static void printValuePointer(const clivalue_t *var, const void *valuePointer, u
|
|||
case VAR_INT16:
|
||||
value = *(int16_t *)valuePointer;
|
||||
break;
|
||||
|
||||
/* not currently used
|
||||
case VAR_UINT32:
|
||||
value = *(uint32_t *)valuePointer;
|
||||
break; */
|
||||
|
||||
case VAR_FLOAT:
|
||||
cliPrintf("%s", ftoa(*(float *)valuePointer, buf));
|
||||
if (full && (var->type & VALUE_MODE_MASK) == MODE_DIRECT) {
|
||||
cliPrintf(" %s", ftoa((float)var->config.minmax.min, buf));
|
||||
cliPrintf(" %s", ftoa((float)var->config.minmax.max, buf));
|
||||
}
|
||||
return; // return from case for float only
|
||||
}
|
||||
|
||||
switch(var->type & VALUE_MODE_MASK) {
|
||||
|
@ -1123,16 +1107,8 @@ static bool valuePtrEqualsDefault(uint8_t type, const void *ptr, const void *ptr
|
|||
case VAR_INT16:
|
||||
result = *(int16_t *)ptr == *(int16_t *)ptrDefault;
|
||||
break;
|
||||
|
||||
/* not currently used
|
||||
case VAR_UINT32:
|
||||
result = *(uint32_t *)ptr == *(uint32_t *)ptrDefault;
|
||||
break;*/
|
||||
|
||||
case VAR_FLOAT:
|
||||
result = *(float *)ptr == *(float *)ptrDefault;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1471,33 +1447,19 @@ static void cliPrintVarRange(const clivalue_t *var)
|
|||
}
|
||||
}
|
||||
|
||||
typedef union {
|
||||
int32_t int_value;
|
||||
float float_value;
|
||||
} int_float_value_t;
|
||||
|
||||
static void cliSetVar(const clivalue_t *var, const int_float_value_t value)
|
||||
static void cliSetVar(const clivalue_t *var, const int32_t value)
|
||||
{
|
||||
void *ptr = getValuePointer(var);
|
||||
|
||||
switch (var->type & VALUE_TYPE_MASK) {
|
||||
case VAR_UINT8:
|
||||
case VAR_INT8:
|
||||
*(int8_t *)ptr = value.int_value;
|
||||
*(int8_t *)ptr = value;
|
||||
break;
|
||||
|
||||
case VAR_UINT16:
|
||||
case VAR_INT16:
|
||||
*(int16_t *)ptr = value.int_value;
|
||||
break;
|
||||
|
||||
/* not currently used
|
||||
case VAR_UINT32:
|
||||
*(uint32_t *)ptr = value.int_value;
|
||||
break; */
|
||||
|
||||
case VAR_FLOAT:
|
||||
*(float *)ptr = (float)value.float_value;
|
||||
*(int16_t *)ptr = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2052,9 +2014,9 @@ static void printMotorMix(uint8_t dumpMask, const motorMixer_t *customMotorMixer
|
|||
{
|
||||
const char *format = "mmix %d %s %s %s %s\r\n";
|
||||
char buf0[8];
|
||||
char buf1[8];
|
||||
char buf2[8];
|
||||
char buf3[8];
|
||||
char buf1[FTOA_BUFFER_LENGTH];
|
||||
char buf2[FTOA_BUFFER_LENGTH];
|
||||
char buf3[FTOA_BUFFER_LENGTH];
|
||||
for (uint32_t i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
|
||||
if (customMotorMixer[i].throttle == 0.0f)
|
||||
break;
|
||||
|
@ -3599,22 +3561,12 @@ static void cliSet(char *cmdline)
|
|||
if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0 && variableNameLength == strlen(valueTable[i].name)) {
|
||||
|
||||
bool changeValue = false;
|
||||
int_float_value_t tmp = { 0 };
|
||||
int32_t value = 0;
|
||||
switch (valueTable[i].type & VALUE_MODE_MASK) {
|
||||
case MODE_DIRECT: {
|
||||
int32_t value = 0;
|
||||
float valuef = 0;
|
||||
|
||||
value = atoi(eqptr);
|
||||
valuef = fastA2F(eqptr);
|
||||
|
||||
if (valuef >= valueTable[i].config.minmax.min && valuef <= valueTable[i].config.minmax.max) { // note: compare float value
|
||||
|
||||
if ((valueTable[i].type & VALUE_TYPE_MASK) == VAR_FLOAT)
|
||||
tmp.float_value = valuef;
|
||||
else
|
||||
tmp.int_value = value;
|
||||
|
||||
if (value >= valueTable[i].config.minmax.min && value <= valueTable[i].config.minmax.max) {
|
||||
changeValue = true;
|
||||
}
|
||||
}
|
||||
|
@ -3626,7 +3578,7 @@ static void cliSet(char *cmdline)
|
|||
matched = strcasecmp(tableEntry->values[tableValueIndex], eqptr) == 0;
|
||||
|
||||
if (matched) {
|
||||
tmp.int_value = tableValueIndex;
|
||||
value = tableValueIndex;
|
||||
changeValue = true;
|
||||
}
|
||||
}
|
||||
|
@ -3635,7 +3587,7 @@ static void cliSet(char *cmdline)
|
|||
}
|
||||
|
||||
if (changeValue) {
|
||||
cliSetVar(val, tmp);
|
||||
cliSetVar(val, value);
|
||||
|
||||
cliPrintf("%s set to ", valueTable[i].name);
|
||||
cliPrintVar(val, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue