Made 'platform_getVolumeLevel' and 'platform_getMicLevel' API functions return a normalised 8 bit value ranging from 0 to 255 (TG-293 #closed)

replace/a722ec2a6c00378d1566244d8968a947aec39362
Silvano Seva 2021-08-13 21:57:32 +02:00 zatwierdzone przez Federico Amedeo Izzo
rodzic 379f5aa71b
commit 8e0a5d1c0f
8 zmienionych plików z 97 dodań i 59 usunięć

Wyświetl plik

@ -58,11 +58,11 @@ typedef struct
{
char name[10]; /* Manufacturer-assigned hardware name. */
uint16_t uhf_maxFreq; /* Upper bound for UHF band, in MHz. */
uint16_t uhf_minFreq; /* Lower bound for UHF band, in MHz. */
uint16_t uhf_maxFreq; /* Upper bound for UHF band, in MHz. */
uint16_t uhf_minFreq; /* Lower bound for UHF band, in MHz. */
uint16_t vhf_maxFreq; /* Upper bound for VHF band, in MHz. */
uint16_t vhf_minFreq; /* Lower bound for VHF band, in MHz. */
uint16_t vhf_maxFreq; /* Upper bound for VHF band, in MHz. */
uint16_t vhf_minFreq; /* Lower bound for VHF band, in MHz. */
uint8_t _unused : 4,
uhf_band : 1, /* Device allows UHF band operation. */
@ -89,14 +89,16 @@ void platform_terminate();
float platform_getVbat();
/**
* This function reads and returns the current microphone input level.
* This function reads and returns the current microphone input level as a
* normalised value between 0 and 255.
*/
float platform_getMicLevel();
uint8_t platform_getMicLevel();
/**
* This function reads and returns the current volume selector level.
* This function reads and returns the current volume selector level as a
* normalised value between 0 and 255.
*/
float platform_getVolumeLevel();
uint8_t platform_getVolumeLevel();
/**
* This function reads and returns the current channel selector level.

Wyświetl plik

@ -36,14 +36,14 @@
* digital value to be fed into the HR_C6000 lineout DAC gain. We thus have to
* provide the helper function below to keep the real volume level consistent
* with the knob position.
* Current knob position corresponds to an analog signal in the range 0 - 1500mV,
* which has to be mapped in a range between 1 and 31.
*/
#ifdef PLATFORM_MDUV3x0
void _setVolume()
{
float level = (platform_getVolumeLevel() / 1560.0f) * 30.0f;
uint8_t volume = ((uint8_t) (level + 0.5f));
// Volume level range is 0 - 255, by right shifting by 3 we get a value in
// range 0 - 31.
uint8_t volume = platform_getVolumeLevel();
volume >>= 3;
// Mute volume when knob is set below 10%
if(volume < 1)

Wyświetl plik

@ -69,12 +69,12 @@ void platform_init()
memset(&calibration, 0x00, sizeof(gdxCalibration_t));
/* Initialise hardware information structure */
hwInfo.vhf_maxFreq = 174;
hwInfo.vhf_minFreq = 136;
hwInfo.vhf_band = 1;
hwInfo.uhf_maxFreq = 470;
hwInfo.uhf_minFreq = 400;
hwInfo.uhf_band = 1;
hwInfo.vhf_maxFreq = 174;
hwInfo.vhf_minFreq = 136;
hwInfo.vhf_band = 1;
hwInfo.uhf_maxFreq = 470;
hwInfo.uhf_minFreq = 400;
hwInfo.uhf_band = 1;
hwInfo.lcd_type = 0;
memcpy(hwInfo.name, "DM-1801", 7);
hwInfo.name[7] = '\0';
@ -100,28 +100,27 @@ void platform_terminate()
float platform_getVbat()
{
float value = 0.0f;
pthread_mutex_lock(&adc_mutex);
value = adc0_getMeasurement(1);
uint16_t value = adc0_getMeasurement(1);
pthread_mutex_unlock(&adc_mutex);
return (value * 3.0f)/1000.0f;
return (((float) value) * 3.0f)/1000.0f;
}
float platform_getMicLevel()
uint8_t platform_getMicLevel()
{
float value = 0.0f;
pthread_mutex_lock(&adc_mutex);
value = adc0_getMeasurement(3);
uint16_t value = adc0_getRawSample(3);
pthread_mutex_unlock(&adc_mutex);
return value;
/* Value from ADC is 12 bit wide: shift right by four to get 0 - 255 */
return value >> 4;
}
float platform_getVolumeLevel()
uint8_t platform_getVolumeLevel()
{
/* TODO */
return 0.0f;
return 0;
}
int8_t platform_getChSelector()

Wyświetl plik

@ -99,28 +99,27 @@ void platform_terminate()
float platform_getVbat()
{
float value = 0.0f;
pthread_mutex_lock(&adc_mutex);
value = adc0_getMeasurement(1);
uint16_t value = adc0_getMeasurement(1);
pthread_mutex_unlock(&adc_mutex);
return (value * 3.0f)/1000.0f;
return (((float) value) * 3.0f)/1000.0f;
}
float platform_getMicLevel()
uint8_t platform_getMicLevel()
{
float value = 0.0f;
pthread_mutex_lock(&adc_mutex);
value = adc0_getMeasurement(3);
uint16_t value = adc0_getRawSample(3);
pthread_mutex_unlock(&adc_mutex);
return value;
/* Value from ADC is 12 bit wide: shift right by four to get 0 - 255 */
return value >> 4;
}
float platform_getVolumeLevel()
uint8_t platform_getVolumeLevel()
{
/* TODO */
return 0.0f;
return 0;
}
int8_t platform_getChSelector()

Wyświetl plik

@ -99,14 +99,24 @@ float platform_getVbat()
return adc1_getMeasurement(ADC_VBAT_CH)*3.0f/1000.0f;
}
float platform_getMicLevel()
uint8_t platform_getMicLevel()
{
return adc1_getMeasurement(ADC_VOX_CH);
/* Value from ADC is 12 bit wide: shift right by four to get 0 - 255 */
return (adc1_getRawSample(ADC_VOX_CH) >> 4);
}
float platform_getVolumeLevel()
uint8_t platform_getVolumeLevel()
{
return adc1_getMeasurement(ADC_VOL_CH);
/*
* Knob position corresponds to an analog signal in the range 0 - 1600mV,
* converted to a value in range 0 - 255 using fixed point math: divide by
* 1600 and then multiply by 256.
*/
uint16_t value = adc1_getMeasurement(ADC_VOL_CH);
if(value > 1599) value = 1599;
uint32_t level = value << 16;
level /= 1600;
return ((uint8_t) (level >> 8));
}
int8_t platform_getChSelector()

Wyświetl plik

@ -114,14 +114,24 @@ float platform_getVbat()
return (adc1_getMeasurement(ADC_VBAT_CH)*5.7f)/1000.0f;
}
float platform_getMicLevel()
uint8_t platform_getMicLevel()
{
return 0.0f;
/* Value from ADC is 12 bit wide: shift right by four to get 0 - 255 */
return (adc1_getRawSample(ADC_VOX_CH) >> 4);
}
float platform_getVolumeLevel()
uint8_t platform_getVolumeLevel()
{
return 0.0f;
/*
* Knob position corresponds to an analog signal in the range 0 - 1600mV,
* converted to a value in range 0 - 255 using fixed point math: divide by
* 1600 and then multiply by 256.
*/
uint16_t value = adc1_getMeasurement(ADC_VOL_CH);
if(value > 1599) value = 1599;
uint32_t level = value << 16;
level /= 1600;
return ((uint8_t) (level >> 8));
}
bool platform_getPttStatus()

Wyświetl plik

@ -102,14 +102,24 @@ float platform_getVbat()
return adc1_getMeasurement(ADC_VBAT_CH)*3.0f/1000.0f;
}
float platform_getMicLevel()
uint8_t platform_getMicLevel()
{
return 0.0f;
/* Value from ADC is 12 bit wide: shift right by four to get 0 - 255 */
return (adc1_getRawSample(ADC_VOX_CH) >> 4);
}
float platform_getVolumeLevel()
uint8_t platform_getVolumeLevel()
{
return adc1_getMeasurement(ADC_VOL_CH);
/*
* Knob position corresponds to an analog signal in the range 0 - 1600mV,
* converted to a value in range 0 - 255 using fixed point math: divide by
* 1600 and then multiply by 256.
*/
uint16_t value = adc1_getMeasurement(ADC_VOL_CH);
if(value > 1599) value = 1599;
uint32_t level = value << 16;
level /= 1600;
return ((uint8_t) (level >> 8));
}
bool platform_getPttStatus()

Wyświetl plik

@ -29,13 +29,13 @@ void platform_init()
// Fill hwinfo struct
memset(&hwInfo, 0x00, sizeof(hwInfo));
snprintf(hwInfo.name, 10, "Linux");
// Frequencies are in MHz
hwInfo.vhf_maxFreq = 174;
hwInfo.vhf_minFreq = 136;
hwInfo.vhf_band = 1;
hwInfo.uhf_maxFreq = 480;
hwInfo.uhf_minFreq = 400;
hwInfo.uhf_band = 1;
// Frequencies are in MHz
hwInfo.vhf_maxFreq = 174;
hwInfo.vhf_minFreq = 136;
hwInfo.vhf_band = 1;
hwInfo.uhf_maxFreq = 480;
hwInfo.uhf_minFreq = 400;
hwInfo.uhf_band = 1;
emulator_start();
}
@ -57,15 +57,23 @@ float platform_getVbat()
}
float platform_getMicLevel()
uint8_t platform_getMicLevel()
{
return Radio_State.micLevel;
float level = Radio_State.micLevel;
if(level < 0.0f) level = 0.0f;
if(level > 255.0f) level = 255.0f;
return ((uint8_t) level);
}
float platform_getVolumeLevel()
uint8_t platform_getVolumeLevel()
{
return Radio_State.volumeLevel;
float level = Radio_State.volumeLevel;
if(level < 0.0f) level = 0.0f;
if(level > 255.0f) level = 255.0f;
return ((uint8_t) level);
}