1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 22:35:23 +03:00

Changed CLI variables to use a union. Some build fixes.

This commit is contained in:
Michael Keller 2017-04-10 13:42:55 +12:00 committed by mikeller
parent 9c29475ba4
commit e66b74579b
4 changed files with 33 additions and 19 deletions

View file

@ -119,7 +119,7 @@ static OSD_Entry menuMiscEntries[]=
{ "-- MISC --", OME_Label, NULL, NULL, 0 }, { "-- MISC --", OME_Label, NULL, NULL, 0 },
{ "MIN THR", OME_UINT16, NULL, &(OSD_UINT16_t){ &motorConfig_minthrottle, 1000, 2000, 1 }, 0 }, { "MIN THR", OME_UINT16, NULL, &(OSD_UINT16_t){ &motorConfig_minthrottle, 1000, 2000, 1 }, 0 },
{ "DIGITAL IDLE", OME_UINT16, NULL, &(OSD_UINT16_t) { &motorConfig_digitalIdleOffsetValue, 0, 2000, 1 }, 0 }, { "DIGITAL IDLE", OME_UINT8, NULL, &(OSD_UINT8_t) { &motorConfig_digitalIdleOffsetValue, 0, 200, 1 }, 0 },
{ "VBAT SCALE", OME_UINT8, NULL, &(OSD_UINT8_t) { &voltageSensorADCConfig_vbatscale, 1, 250, 1 }, 0 }, { "VBAT SCALE", OME_UINT8, NULL, &(OSD_UINT8_t) { &voltageSensorADCConfig_vbatscale, 1, 250, 1 }, 0 },
{ "VBAT CLMAX", OME_UINT8, NULL, &(OSD_UINT8_t) { &batteryConfig_vbatmaxcellvoltage, 10, 50, 1 }, 0 }, { "VBAT CLMAX", OME_UINT8, NULL, &(OSD_UINT8_t) { &batteryConfig_vbatmaxcellvoltage, 10, 50, 1 }, 0 },
{ "RC PREV", OME_Submenu, cmsMenuChange, &cmsx_menuRcPreview, 0}, { "RC PREV", OME_Submenu, cmsMenuChange, &cmsx_menuRcPreview, 0},

View file

@ -479,6 +479,13 @@ typedef enum {
#define VALUE_SECTION_MASK (0x30) #define VALUE_SECTION_MASK (0x30)
#define VALUE_MODE_MASK (0xC0) #define VALUE_MODE_MASK (0xC0)
typedef union {
int8_t int8;
uint8_t uint8;
int16_t int16;
uint16_t uint16;
} cliVar_t;
typedef struct cliMinMaxConfig_s { typedef struct cliMinMaxConfig_s {
const int16_t min; const int16_t min;
const int16_t max; const int16_t max;
@ -1053,25 +1060,25 @@ static void cliPrintf(const char *format, ...)
bufWriterFlush(cliWriter); bufWriterFlush(cliWriter);
} }
static void printValuePointer(const clivalue_t *var, const void *valuePointer, uint32_t full) static void printValuePointer(const clivalue_t *var, const void *valuePointer, bool full)
{ {
int32_t value = 0; cliVar_t value = { .uint16 = 0 };
switch (var->type & VALUE_TYPE_MASK) { switch (var->type & VALUE_TYPE_MASK) {
case VAR_UINT8: case VAR_UINT8:
value = *(uint8_t *)valuePointer; value.uint8 = *(uint8_t *)valuePointer;
break; break;
case VAR_INT8: case VAR_INT8:
value = *(int8_t *)valuePointer; value.int8 = *(int8_t *)valuePointer;
break; break;
case VAR_UINT16: case VAR_UINT16:
value = *(uint16_t *)valuePointer; value.uint16 = *(uint16_t *)valuePointer;
break; break;
case VAR_INT16: case VAR_INT16:
value = *(int16_t *)valuePointer; value.int16 = *(int16_t *)valuePointer;
break; break;
} }
@ -1083,7 +1090,7 @@ static void printValuePointer(const clivalue_t *var, const void *valuePointer, u
} }
break; break;
case MODE_LOOKUP: case MODE_LOOKUP:
cliPrint(lookupTables[var->config.lookup.tableIndex].values[value]); cliPrint(lookupTables[var->config.lookup.tableIndex].values[value.uint16]);
break; break;
} }
} }
@ -1419,7 +1426,7 @@ static void dumpAllValues(uint16_t valueSection, uint8_t dumpMask)
} }
} }
static void cliPrintVar(const clivalue_t *var, uint32_t full) static void cliPrintVar(const clivalue_t *var, bool full)
{ {
const void *ptr = getValuePointer(var); const void *ptr = getValuePointer(var);
@ -1447,19 +1454,25 @@ static void cliPrintVarRange(const clivalue_t *var)
} }
} }
static void cliSetVar(const clivalue_t *var, const int32_t value) static void cliSetVar(const clivalue_t *var, const cliVar_t value)
{ {
void *ptr = getValuePointer(var); void *ptr = getValuePointer(var);
switch (var->type & VALUE_TYPE_MASK) { switch (var->type & VALUE_TYPE_MASK) {
case VAR_UINT8: case VAR_UINT8:
*(uint8_t *)ptr = value.uint8;
break;
case VAR_INT8: case VAR_INT8:
*(int8_t *)ptr = value; *(int8_t *)ptr = value.int8;
break; break;
case VAR_UINT16: case VAR_UINT16:
*(uint16_t *)ptr = value.uint16;
break;
case VAR_INT16: case VAR_INT16:
*(int16_t *)ptr = value; *(int16_t *)ptr = value.int16;
break; break;
} }
} }
@ -3561,12 +3574,12 @@ static void cliSet(char *cmdline)
if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0 && variableNameLength == strlen(valueTable[i].name)) { if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0 && variableNameLength == strlen(valueTable[i].name)) {
bool changeValue = false; bool changeValue = false;
int32_t value = 0; cliVar_t value = { .uint16 = 0 };
switch (valueTable[i].type & VALUE_MODE_MASK) { switch (valueTable[i].type & VALUE_MODE_MASK) {
case MODE_DIRECT: { case MODE_DIRECT: {
value = atoi(eqptr); value.uint16 = atoi(eqptr);
if (value >= valueTable[i].config.minmax.min && value <= valueTable[i].config.minmax.max) { if (value.uint16 >= valueTable[i].config.minmax.min && value.uint16 <= valueTable[i].config.minmax.max) {
changeValue = true; changeValue = true;
} }
} }
@ -3578,7 +3591,7 @@ static void cliSet(char *cmdline)
matched = strcasecmp(tableEntry->values[tableValueIndex], eqptr) == 0; matched = strcasecmp(tableEntry->values[tableValueIndex], eqptr) == 0;
if (matched) { if (matched) {
value = tableValueIndex; value.uint16 = tableValueIndex;
changeValue = true; changeValue = true;
} }
} }

View file

@ -350,11 +350,11 @@ void initEscEndpoints(void) {
if (isMotorProtocolDshot()) { if (isMotorProtocolDshot()) {
disarmMotorOutput = DSHOT_DISARM_COMMAND; disarmMotorOutput = DSHOT_DISARM_COMMAND;
if (feature(FEATURE_3D)) if (feature(FEATURE_3D))
motorOutputLow = DSHOT_MIN_THROTTLE + lrintf(((DSHOT_3D_DEADBAND_LOW - DSHOT_MIN_THROTTLE) / 100.0f) * CONVERT_PARAM_TO_PERCENT(motorConfig()->digitalIdleOffsetValue)); motorOutputLow = DSHOT_MIN_THROTTLE + lrintf(((DSHOT_3D_DEADBAND_LOW - DSHOT_MIN_THROTTLE) / 100.0f) * CONVERT_PARAMETER_TO_PERCENT(motorConfig()->digitalIdleOffsetValue));
else else
motorOutputLow = DSHOT_MIN_THROTTLE + lrintf(((DSHOT_MAX_THROTTLE - DSHOT_MIN_THROTTLE) / 100.0f) * CONVERT_PARAM_TO_PERCENT(motorConfig()->digitalIdleOffsetValue)); motorOutputLow = DSHOT_MIN_THROTTLE + lrintf(((DSHOT_MAX_THROTTLE - DSHOT_MIN_THROTTLE) / 100.0f) * CONVERT_PARAMETER_TO_PERCENT(motorConfig()->digitalIdleOffsetValue));
motorOutputHigh = DSHOT_MAX_THROTTLE; motorOutputHigh = DSHOT_MAX_THROTTLE;
deadbandMotor3dHigh = DSHOT_3D_DEADBAND_HIGH + lrintf(((DSHOT_MAX_THROTTLE - DSHOT_3D_DEADBAND_HIGH) / 100.0f) * CONVERT_PARAM_TO_PERCENT(motorConfig()->digitalIdleOffsetValue)); // TODO - Not working yet !! Mixer requires some throttle rescaling changes deadbandMotor3dHigh = DSHOT_3D_DEADBAND_HIGH + lrintf(((DSHOT_MAX_THROTTLE - DSHOT_3D_DEADBAND_HIGH) / 100.0f) * CONVERT_PARAMETER_TO_PERCENT(motorConfig()->digitalIdleOffsetValue)); // TODO - Not working yet !! Mixer requires some throttle rescaling changes
deadbandMotor3dLow = DSHOT_3D_DEADBAND_LOW; deadbandMotor3dLow = DSHOT_3D_DEADBAND_LOW;
} else } else
#endif #endif

View file

@ -75,6 +75,7 @@
#include "fc/runtime_config.h" #include "fc/runtime_config.h"
#include "flight/imu.h" #include "flight/imu.h"
#include "flight/altitude.h"
#include "rx/rx.h" #include "rx/rx.h"