Added volume level to device state data structure.

Added filtered volume level to device state. Value is updated at 10Hz and
filtering is done by averaging the current value with the new sample.
This commit is contained in:
Silvano Seva 2024-10-15 17:33:58 +02:00
parent a310a0a2d1
commit 847750e233
4 changed files with 14 additions and 5 deletions

View File

@ -40,6 +40,7 @@ typedef struct
uint16_t v_bat;
uint8_t charge;
rssi_t rssi;
uint8_t volume;
uint8_t ui_screen;
uint8_t tuner_mode;

View File

@ -72,6 +72,7 @@ void state_init()
state.v_bat = platform_getVbat();
state.charge = battery_getCharge(state.v_bat);
state.rssi = -127.0f;
state.volume = platform_getVolumeLevel();
state.channel_index = 0; // Set default channel index (it is 0-based)
state.bank_enabled = false;
@ -126,6 +127,14 @@ void state_task()
state.v_bat += (vbat * 2) / 100;
#endif
/*
* Update volume level, as a 50% average between previous value and a new
* read of the knob position. This gives a good reactivity while preventing
* the volume level to jitter when the knob is not being moved.
*/
uint16_t vol = platform_getVolumeLevel() + state.volume;
state.volume = vol / 2;
state.charge = battery_getCharge(state.v_bat);
state.rssi = rtx_getRssi();

View File

@ -260,7 +260,7 @@ void _ui_drawMainBottom()
// Squelch bar
rssi_t rssi = last_state.rssi;
uint8_t squelch = last_state.settings.sqlLevel;
uint8_t volume = platform_getVolumeLevel();
uint8_t volume = last_state.volume;
uint16_t meter_width = CONFIG_SCREEN_WIDTH - 2 * layout.horizontal_pad;
uint16_t meter_height = layout.bottom_h;
point_t meter_pos = { layout.horizontal_pad,

View File

@ -87,14 +87,13 @@ static void *audio_thread(void *arg)
{
Cx000dac_task();
uint8_t volume = platform_getVolumeLevel();
if(volume != oldVolume)
if(state.volume != oldVolume)
{
// Apply new volume level, map 0 - 255 range into -31 to 31
int8_t gain = ((int8_t) (volume / 4)) - 31;
int8_t gain = ((int8_t) (state.volume / 4)) - 31;
C6000.setDacGain(gain);
oldVolume = volume;
oldVolume = state.volume;
}
now += 4;