mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 08:15:30 +03:00
CF/BF - refactor voltage refresh/read api. update voltage/current msp code
msp code is still unfinished, but the plan is clearer now. move some defaults from battery.h and allow targets to override them. define ID's for all voltage and current sensors, the idea being a list of ids wil lbe created for each build which will allow all the voltage and current meters to be exposed via MSP.
This commit is contained in:
parent
089042e136
commit
f3e740c598
6 changed files with 234 additions and 43 deletions
|
@ -909,6 +909,36 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn
|
|||
sbufWriteU16(dst, boardAlignment()->yawDegrees);
|
||||
break;
|
||||
|
||||
case MSP_BATTERY_STATE: {
|
||||
sbufWriteU8(dst, (uint8_t)constrain(getBatteryCellCount(), 0, 255)); // 0 indicates battery not detected.
|
||||
sbufWriteU8(dst, (uint8_t)constrain(getBatteryVoltage(), 0, 255)); // in 0.1V steps
|
||||
sbufWriteU16(dst, (uint16_t)constrain(getMAhDrawn(), 0, 0xFFFF)); // milliamp hours drawn from battery
|
||||
// should we add batteryAmperage?
|
||||
// should we add batteryPercentageRemaining?
|
||||
// should we add batteryState (which is really a combined voltage AND consumption alert state)?
|
||||
// should we add batteryVoltageState and batteryConsumptionState?
|
||||
break;
|
||||
}
|
||||
/*
|
||||
case MSP_VOLTAGE_METERS:
|
||||
// TODO write out voltage, once for each meter id we support
|
||||
for (int i = 0; i < MAX_VOLTAGE_METERS; i++) {
|
||||
|
||||
uint16_t voltage = getVoltageMeter(i)->vbat;
|
||||
sbufWriteU8(dst, (uint8_t)constrain(voltage, 0, 255));
|
||||
}
|
||||
break;
|
||||
|
||||
case MSP_CURRENT_METERS:
|
||||
// TODO write out amperage meter for each meter id we support
|
||||
for (int i = 0; i < MAX_AMPERAGE_METERS; i++) {
|
||||
amperageMeter_t *meter = getAmperageMeter(i);
|
||||
// write out amperage, once for each current meter.
|
||||
sbufWriteU16(dst, (uint16_t)constrain(meter->amperage * 10, 0, 0xFFFF)); // send amperage in 0.001 A steps. Negative range is truncated to zero
|
||||
sbufWriteU32(dst, meter->mAhDrawn);
|
||||
}
|
||||
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,
|
||||
// e.g. an i2c/spi/can sensor or any sensor not built directly into the FC such as ESC/RX/SPort/SBus that has
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue