mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 12:25:20 +03:00
Updating unit test to verify expected values with the new maximum
vbatscale value. See #104.
This commit is contained in:
parent
c2b1420c07
commit
107a3425cf
4 changed files with 20 additions and 10 deletions
|
@ -267,7 +267,7 @@ static void resetConf(void)
|
|||
masterConfig.yaw_control_direction = 1;
|
||||
masterConfig.gyroConfig.gyroMovementCalibrationThreshold = 32;
|
||||
|
||||
masterConfig.batteryConfig.vbatscale = 110;
|
||||
masterConfig.batteryConfig.vbatscale = VBAT_SCALE_DEFAULT;
|
||||
masterConfig.batteryConfig.vbatmaxcellvoltage = 43;
|
||||
masterConfig.batteryConfig.vbatmincellvoltage = 33;
|
||||
masterConfig.batteryConfig.currentMeterOffset = 0;
|
||||
|
|
|
@ -264,7 +264,7 @@ const clivalue_t valueTable[] = {
|
|||
{ "telemetry_switch", VAR_UINT8 | MASTER_VALUE, &masterConfig.telemetryConfig.telemetry_switch, 0, 1 },
|
||||
{ "frsky_inversion", VAR_UINT8 | MASTER_VALUE, &masterConfig.telemetryConfig.frsky_inversion, 0, 1 },
|
||||
|
||||
{ "vbat_scale", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatscale, 10, 250 },
|
||||
{ "vbat_scale", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatscale, VBAT_SCALE_MIN, VBAT_SCALE_MAX },
|
||||
{ "vbat_max_cell_voltage", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatmaxcellvoltage, 10, 50 },
|
||||
{ "vbat_min_cell_voltage", VAR_UINT8 | MASTER_VALUE, &masterConfig.batteryConfig.vbatmincellvoltage, 10, 50 },
|
||||
{ "current_meter_scale", VAR_UINT16 | MASTER_VALUE, &masterConfig.batteryConfig.currentMeterScale, 1, 10000 },
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define VBAT_SCALE_DEFAULT 110
|
||||
#define VBAT_SCALE_MIN 0
|
||||
#define VBAT_SCALE_MAX 255
|
||||
|
||||
typedef struct batteryConfig_s {
|
||||
uint8_t vbatscale; // adjust this to match battery voltage to reported value
|
||||
uint8_t vbatmaxcellvoltage; // maximum voltage per cell, used for auto-detecting battery voltage in 0.1V units, default is 43 (4.3V)
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
typedef struct batteryAdcToVoltageExpectation_s {
|
||||
uint16_t adcReading;
|
||||
uint16_t expectedVoltageInDeciVoltSteps;
|
||||
uint8_t scale;
|
||||
} batteryAdcToVoltageExpectation_t;
|
||||
|
||||
#define ELEVEN_TO_ONE_VOLTAGE_DIVIDER 110 // (10k:1k) * 10 for 0.1V
|
||||
|
@ -34,17 +35,18 @@ TEST(BatteryTest, BatteryADCToVoltage)
|
|||
// given
|
||||
|
||||
batteryConfig_t batteryConfig;
|
||||
batteryConfig.vbatscale = ELEVEN_TO_ONE_VOLTAGE_DIVIDER;
|
||||
|
||||
batteryInit(&batteryConfig);
|
||||
|
||||
batteryAdcToVoltageExpectation_t batteryAdcToVoltageExpectations[] = {
|
||||
{1420, 125},
|
||||
{1430, 126},
|
||||
{1440, 127},
|
||||
{1890, 167},
|
||||
{1900, 168},
|
||||
{1910, 169}
|
||||
{1420, 125, ELEVEN_TO_ONE_VOLTAGE_DIVIDER},
|
||||
{1430, 126, ELEVEN_TO_ONE_VOLTAGE_DIVIDER},
|
||||
{1440, 127, ELEVEN_TO_ONE_VOLTAGE_DIVIDER},
|
||||
{1890, 167, ELEVEN_TO_ONE_VOLTAGE_DIVIDER},
|
||||
{1900, 168, ELEVEN_TO_ONE_VOLTAGE_DIVIDER},
|
||||
{1910, 169, ELEVEN_TO_ONE_VOLTAGE_DIVIDER},
|
||||
{ 0, 0, VBAT_SCALE_MAX},
|
||||
{4096, 841, VBAT_SCALE_MAX}
|
||||
};
|
||||
uint8_t testIterationCount = sizeof(batteryAdcToVoltageExpectations) / sizeof(batteryAdcToVoltageExpectation_t);
|
||||
|
||||
|
@ -52,7 +54,11 @@ TEST(BatteryTest, BatteryADCToVoltage)
|
|||
|
||||
for (uint8_t index = 0; index < testIterationCount; index ++) {
|
||||
batteryAdcToVoltageExpectation_t *batteryAdcToVoltageExpectation = &batteryAdcToVoltageExpectations[index];
|
||||
printf("adcReading: %d\n", batteryAdcToVoltageExpectation->adcReading);
|
||||
batteryConfig.vbatscale = batteryAdcToVoltageExpectation->scale;
|
||||
printf("adcReading: %d, vbatscale: %d\n",
|
||||
batteryAdcToVoltageExpectation->adcReading,
|
||||
batteryAdcToVoltageExpectation->scale
|
||||
);
|
||||
|
||||
uint16_t pointOneVoltSteps = batteryAdcToVoltage(batteryAdcToVoltageExpectation->adcReading);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue