1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Updating unit test to verify expected values with the new maximum

vbatscale value. See #104.
This commit is contained in:
Dominic Clifton 2014-10-07 21:10:29 +01:00
parent c2b1420c07
commit 107a3425cf
4 changed files with 20 additions and 10 deletions

View file

@ -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);