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:
parent
a310a0a2d1
commit
847750e233
|
|
@ -40,6 +40,7 @@ typedef struct
|
||||||
uint16_t v_bat;
|
uint16_t v_bat;
|
||||||
uint8_t charge;
|
uint8_t charge;
|
||||||
rssi_t rssi;
|
rssi_t rssi;
|
||||||
|
uint8_t volume;
|
||||||
|
|
||||||
uint8_t ui_screen;
|
uint8_t ui_screen;
|
||||||
uint8_t tuner_mode;
|
uint8_t tuner_mode;
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ void state_init()
|
||||||
state.v_bat = platform_getVbat();
|
state.v_bat = platform_getVbat();
|
||||||
state.charge = battery_getCharge(state.v_bat);
|
state.charge = battery_getCharge(state.v_bat);
|
||||||
state.rssi = -127.0f;
|
state.rssi = -127.0f;
|
||||||
|
state.volume = platform_getVolumeLevel();
|
||||||
|
|
||||||
state.channel_index = 0; // Set default channel index (it is 0-based)
|
state.channel_index = 0; // Set default channel index (it is 0-based)
|
||||||
state.bank_enabled = false;
|
state.bank_enabled = false;
|
||||||
|
|
@ -126,6 +127,14 @@ void state_task()
|
||||||
state.v_bat += (vbat * 2) / 100;
|
state.v_bat += (vbat * 2) / 100;
|
||||||
#endif
|
#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.charge = battery_getCharge(state.v_bat);
|
||||||
state.rssi = rtx_getRssi();
|
state.rssi = rtx_getRssi();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ void _ui_drawMainBottom()
|
||||||
// Squelch bar
|
// Squelch bar
|
||||||
rssi_t rssi = last_state.rssi;
|
rssi_t rssi = last_state.rssi;
|
||||||
uint8_t squelch = last_state.settings.sqlLevel;
|
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_width = CONFIG_SCREEN_WIDTH - 2 * layout.horizontal_pad;
|
||||||
uint16_t meter_height = layout.bottom_h;
|
uint16_t meter_height = layout.bottom_h;
|
||||||
point_t meter_pos = { layout.horizontal_pad,
|
point_t meter_pos = { layout.horizontal_pad,
|
||||||
|
|
|
||||||
|
|
@ -87,14 +87,13 @@ static void *audio_thread(void *arg)
|
||||||
{
|
{
|
||||||
Cx000dac_task();
|
Cx000dac_task();
|
||||||
|
|
||||||
uint8_t volume = platform_getVolumeLevel();
|
if(state.volume != oldVolume)
|
||||||
if(volume != oldVolume)
|
|
||||||
{
|
{
|
||||||
// Apply new volume level, map 0 - 255 range into -31 to 31
|
// 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);
|
C6000.setDacGain(gain);
|
||||||
|
|
||||||
oldVolume = volume;
|
oldVolume = state.volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
now += 4;
|
now += 4;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue