mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 00:35:39 +03:00
CF/BF - First cut of MSP current sensor.
How it works: 1. Current Meter Source on FC is set to MSP/OSD Slave by user. 2. On reboot FC sends MSP_ANALOG to OSD Slave. 3. OSD Slave listens for incoming MSP as usual. 4. OSD responds to MSP as usual. 6. The FC recevies the data from the OSD Slave and updates the MSP Current Meter.
This commit is contained in:
parent
3e56bb75cf
commit
22147105fb
17 changed files with 166 additions and 15 deletions
|
@ -56,12 +56,15 @@ const uint8_t currentMeterIds[] = {
|
|||
CURRENT_METER_ID_ESC_MOTOR_11,
|
||||
CURRENT_METER_ID_ESC_MOTOR_12,
|
||||
#endif
|
||||
#ifdef USE_MSP_CURRENT_METER
|
||||
CURRENT_METER_ID_MSP_1,
|
||||
#endif
|
||||
};
|
||||
|
||||
const uint8_t supportedCurrentMeterCount = ARRAYLEN(currentMeterIds);
|
||||
|
||||
//
|
||||
// ADC/Virtual/ESC shared
|
||||
// ADC/Virtual/ESC/MSP shared
|
||||
//
|
||||
|
||||
void currentMeterReset(currentMeter_t *meter)
|
||||
|
@ -225,6 +228,45 @@ void currentMeterESCReadMotor(uint8_t motorNumber, currentMeter_t *meter)
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef USE_MSP_CURRENT_METER
|
||||
#include "common/streambuf.h"
|
||||
#include "msp/msp_protocol.h"
|
||||
#include "msp/msp_serial.h"
|
||||
|
||||
currentMeterMSPState_t currentMeterMSPState;
|
||||
|
||||
void currentMeterMSPSet(uint16_t amperage, uint16_t mAhDrawn)
|
||||
{
|
||||
// We expect the FC's MSP_ANALOG response handler to call this function
|
||||
currentMeterMSPState.amperage = amperage;
|
||||
currentMeterMSPState.mAhDrawn = mAhDrawn;
|
||||
}
|
||||
|
||||
void currentMeterMSPInit(void)
|
||||
{
|
||||
memset(¤tMeterMSPState, 0, sizeof(currentMeterMSPState_t));
|
||||
}
|
||||
|
||||
void currentMeterMSPRefresh(timeUs_t currentTimeUs)
|
||||
{
|
||||
// periodically request MSP_ANALOG
|
||||
static timeUs_t streamRequestAt = 0;
|
||||
if (cmp32(currentTimeUs, streamRequestAt) > 0) {
|
||||
streamRequestAt = currentTimeUs + ((1000 * 1000) / 10); // 10hz
|
||||
|
||||
mspSerialPush(MSP_ANALOG, NULL, 0, MSP_DIRECTION_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
void currentMeterMSPRead(currentMeter_t *meter)
|
||||
{
|
||||
meter->amperageLatest = currentMeterMSPState.amperage;
|
||||
meter->amperage = currentMeterMSPState.amperage;
|
||||
meter->mAhDrawn = currentMeterMSPState.mAhDrawn;
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// API for current meters using IDs
|
||||
//
|
||||
|
@ -241,6 +283,11 @@ void currentMeterRead(currentMeterId_e id, currentMeter_t *meter)
|
|||
currentMeterVirtualRead(meter);
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_MSP_CURRENT_METER
|
||||
else if (id == CURRENT_METER_ID_MSP_1) {
|
||||
currentMeterMSPRead(meter);
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ESC_SENSOR
|
||||
else if (id == CURRENT_METER_ID_ESC_COMBINED_1) {
|
||||
currentMeterESCReadCombined(meter);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue