Modified 'platform_getVbat' API: now it returns an uint16_t value containing the battery voltage in millivolt

replace/eca75ed5f509647d855b8a4aa87cf70e1a24357e
Silvano Seva 2021-08-14 12:47:21 +02:00
rodzic 8e0a5d1c0f
commit a7acc3301b
7 zmienionych plików z 34 dodań i 18 usunięć

Wyświetl plik

@ -84,9 +84,9 @@ void platform_init();
void platform_terminate();
/**
* This function reads and returns the current battery voltage in volt.
* This function reads and returns the current battery voltage in millivolt.
*/
float platform_getVbat();
uint16_t platform_getVbat();
/**
* This function reads and returns the current microphone input level as a

Wyświetl plik

@ -98,13 +98,18 @@ void platform_terminate()
gpio_clearPin(PWR_SW);
}
float platform_getVbat()
uint16_t platform_getVbat()
{
pthread_mutex_lock(&adc_mutex);
uint16_t value = adc0_getMeasurement(1);
pthread_mutex_unlock(&adc_mutex);
return (((float) value) * 3.0f)/1000.0f;
/*
* Battery voltage is measured through an 1:3 voltage divider and
* adc1_getMeasurement returns a value in mV. Thus, to have effective
* battery voltage, multiply by three.
*/
return value * 3;
}
uint8_t platform_getMicLevel()

Wyświetl plik

@ -97,13 +97,18 @@ void platform_terminate()
gpio_clearPin(PWR_SW);
}
float platform_getVbat()
uint16_t platform_getVbat()
{
pthread_mutex_lock(&adc_mutex);
uint16_t value = adc0_getMeasurement(1);
pthread_mutex_unlock(&adc_mutex);
return (((float) value) * 3.0f)/1000.0f;
/*
* Battery voltage is measured through an 1:3 voltage divider and
* adc1_getMeasurement returns a value in mV. Thus, to have effective
* battery voltage, multiply by three.
*/
return value * 3;
}
uint8_t platform_getMicLevel()

Wyświetl plik

@ -89,14 +89,14 @@ void platform_terminate()
gpio_clearPin(PWR_SW);
}
float platform_getVbat()
uint16_t platform_getVbat()
{
/*
* Battery voltage is measured through an 1:3 voltage divider and
* adc1_getMeasurement returns a value in mV. Thus, to have effective
* battery voltage multiply by three and divide by 1000
* battery voltage, multiply by three.
*/
return adc1_getMeasurement(ADC_VBAT_CH)*3.0f/1000.0f;
return adc1_getMeasurement(ADC_VBAT_CH) * 3;
}
uint8_t platform_getMicLevel()

Wyświetl plik

@ -104,14 +104,17 @@ void platform_terminate()
while(1) ;
}
float platform_getVbat()
uint16_t platform_getVbat()
{
/*
* Battery voltage is measured through an 1:5.7 voltage divider and
* adc1_getMeasurement returns a value in mV. Thus, to have effective
* battery voltage multiply by the ratio and divide by 1000
* adc1_getMeasurement returns a value in mV. To have effective battery
* voltage we have to multiply by the ratio: with a simple trick we can do
* it also without using floats and with a maximum error of -1mV.
*/
return (adc1_getMeasurement(ADC_VBAT_CH)*5.7f)/1000.0f;
uint16_t vbat = adc1_getMeasurement(ADC_VBAT_CH);
return (vbat * 6) - ((vbat * 3) / 10);
}
uint8_t platform_getMicLevel()

Wyświetl plik

@ -92,14 +92,14 @@ void platform_terminate()
gpio_clearPin(PWR_SW);
}
float platform_getVbat()
uint16_t platform_getVbat()
{
/*
* Battery voltage is measured through an 1:3 voltage divider and
* adc1_getMeasurement returns a value in mV. Thus, to have effective
* battery voltage multiply by three and divide by 1000
* battery voltage, multiply by three.
*/
return adc1_getMeasurement(ADC_VBAT_CH)*3.0f/1000.0f;
return adc1_getMeasurement(ADC_VBAT_CH) * 3;
}
uint8_t platform_getMicLevel()

Wyświetl plik

@ -51,9 +51,12 @@ void platform_setBacklightLevel(__attribute__((unused)) uint8_t level)
}
// Simulate a fully charged lithium battery
float platform_getVbat()
uint16_t platform_getVbat()
{
return Radio_State.Vbat;
float voltage = Radio_State.Vbat;
if(voltage < 0.0f) voltage = 0.0f;
if(voltage > 65.0f) voltage = 65.0f;
return ((uint16_t) voltage);
}