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

Merge pull request #3532 from basdelfos/battery-teb-msp-changes

MSP changes for the new Power & Battery tab in configurator
This commit is contained in:
Michael Keller 2017-07-19 08:46:46 +08:00 committed by GitHub
commit cd5e57e814
2 changed files with 25 additions and 10 deletions

View file

@ -704,9 +704,14 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
break;
}
case MSP_VOLTAGE_METERS:
case MSP_VOLTAGE_METERS: {
// write out id and voltage meter values, once for each meter we support
for (int i = 0; i < supportedVoltageMeterCount; i++) {
uint8_t count = supportedVoltageMeterCount;
#ifndef USE_OSD_SLAVE
count = supportedVoltageMeterCount - (VOLTAGE_METER_ID_ESC_COUNT - getMotorCount());
#endif
for (int i = 0; i < count; i++) {
voltageMeter_t meter;
uint8_t id = (uint8_t)voltageMeterIds[i];
@ -716,10 +721,15 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
sbufWriteU8(dst, (uint8_t)constrain(meter.filtered, 0, 255));
}
break;
}
case MSP_CURRENT_METERS:
case MSP_CURRENT_METERS: {
// write out id and current meter values, once for each meter we support
for (int i = 0; i < supportedCurrentMeterCount; i++) {
uint8_t count = supportedVoltageMeterCount;
#ifndef USE_OSD_SLAVE
count = supportedVoltageMeterCount - (VOLTAGE_METER_ID_ESC_COUNT - getMotorCount());
#endif
for (int i = 0; i < count; i++) {
currentMeter_t meter;
uint8_t id = (uint8_t)currentMeterIds[i];
@ -730,6 +740,7 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
sbufWriteU16(dst, (uint16_t)constrain(meter.amperage * 10, 0, 0xFFFF)); // send amperage in 0.001 A steps (mA). Negative range is truncated to zero
}
break;
}
case MSP_VOLTAGE_METER_CONFIG:
// by using a sensor type and a sub-frame length it's possible to configure any type of voltage meter,
@ -2131,12 +2142,12 @@ static mspResult_e mspCommonProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
#endif
case MSP_SET_VOLTAGE_METER_CONFIG: {
int id = sbufReadU8(src);
int8_t id = sbufReadU8(src);
//
// find and configure an ADC voltage sensor
//
int voltageSensorADCIndex;
int8_t voltageSensorADCIndex;
for (voltageSensorADCIndex = 0; voltageSensorADCIndex < MAX_VOLTAGE_SENSOR_ADC; voltageSensorADCIndex++) {
if (id == voltageMeterADCtoIDMap[voltageSensorADCIndex]) {
break;
@ -2149,7 +2160,9 @@ static mspResult_e mspCommonProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
voltageSensorADCConfigMutable(voltageSensorADCIndex)->vbatresdivmultiplier = sbufReadU8(src);
} else {
// if we had any other types of voltage sensor to configure, this is where we'd do it.
return -1;
sbufReadU8(src);
sbufReadU8(src);
sbufReadU8(src);
}
break;
}
@ -2168,11 +2181,11 @@ static mspResult_e mspCommonProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
currentSensorVirtualConfigMutable()->offset = sbufReadU16(src);
break;
#endif
default:
return -1;
sbufReadU16(src);
sbufReadU16(src);
break;
}
break;
}

View file

@ -60,6 +60,8 @@ typedef enum {
#define MAX_VOLTAGE_SENSOR_ADC 1 // VBAT - some boards have external, 12V, 9V and 5V meters.
#endif
#define VOLTAGE_METER_ID_ESC_COUNT 12
typedef enum {
VOLTAGE_SENSOR_ADC_VBAT = 0,
VOLTAGE_SENSOR_ADC_12V = 1,