firmware: implement muting of inputs

This commit is contained in:
Julian Daube 2019-10-21 23:34:51 +02:00
parent d28508f7bf
commit cc6e747b3f
3 changed files with 71 additions and 11 deletions

View File

@ -55,6 +55,7 @@ void Error_Handler(void);
void set_input(uint8_t channel); void set_input(uint8_t channel);
void set_attenuation(uint8_t left, uint8_t right); void set_attenuation(uint8_t left, uint8_t right);
void set_mute(uint8_t mute);
/* USER CODE BEGIN EFP */ /* USER CODE BEGIN EFP */

View File

@ -102,23 +102,55 @@ int test_button_pressed() {
#undef TEST_BUTTON #undef TEST_BUTTON
} }
struct ui_state {
uint8_t oldchannel;
uint8_t mute;
} ui_state = {
.oldchannel = -1,
.mute = 0,
};
void set_input(uint8_t channel) { void set_input(uint8_t channel) {
static uint8_t oldchannel = -1; if (ui_state.oldchannel == channel || channel >= 6)
if (channel == oldchannel || channel >= 6)
return; return;
channel = channel; set_input_led(ui_state.oldchannel, 0);
set_input_led(oldchannel, 0);
// do not disturb the mute mode
if (!ui_state.mute)
{
set_input_led(channel, 1); set_input_led(channel, 1);
// invert bd inputs to match the numbers on the case // invert bd inputs to match the numbers on the case
bd_set_input(&hi2c1, 5-channel); bd_set_input(&hi2c1, 5-channel);
oldchannel = channel; }
ui_state.oldchannel = channel;
printf("C%d\n", channel); printf("C%d\n", channel);
} }
void set_mute(uint8_t mute) {
if(ui_state.mute == mute)
return;
if (0 == (ui_state.mute = mute)) {
// hack to make reactivation of the last channel easier
uint8_t old_input = ui_state.oldchannel;
ui_state.oldchannel = -1;
set_input(old_input);
HAL_GPIO_WritePin(USER_LED_GPIO_Port, USER_LED_Pin, 0);
}
else {
HAL_GPIO_WritePin(USER_LED_GPIO_Port, USER_LED_Pin, 1);
set_input_led(ui_state.oldchannel, 0);
bd_set_input(&hi2c1, BD_INPUT_MUTE);
}
printf("M%d\n", ui_state.mute?1:0);
}
void set_attenuation(uint8_t left, uint8_t right) { void set_attenuation(uint8_t left, uint8_t right) {
bd_set_attenuation(&hi2c1, 0, left); bd_set_attenuation(&hi2c1, 0, left);
bd_set_attenuation(&hi2c1, 1, right); bd_set_attenuation(&hi2c1, 1, right);
@ -168,6 +200,8 @@ int main(void)
// reset set input // reset set input
set_input(input); set_input(input);
set_attenuation(0,0); set_attenuation(0,0);
int count = 0;
int button_timeout = 0;
/* USER CODE END 2 */ /* USER CODE END 2 */
/* Infinite loop */ /* Infinite loop */
@ -180,8 +214,25 @@ int main(void)
// handle button inputs // handle button inputs
input = test_button_pressed(); input = test_button_pressed();
if (0 <= input) { if (6 > input) {
set_input(input); set_input(input);
if (100 < ++count) {
count = 0;
button_timeout++;
}
//printf("%d\n", count);
if (1000 < button_timeout) {
// long press, toggle mute
set_mute(!ui_state.mute);
button_timeout = 0;
}
} else {
count = 0;
button_timeout = 0;
} }
// parse serial commands // parse serial commands

View File

@ -150,6 +150,14 @@ int parse_buffer() {
printf("%c%d\n", temp, bd_set_attenuation(&hi2c1, temp == 'R', att&0xFF)); printf("%c%d\n", temp, bd_set_attenuation(&hi2c1, temp == 'R', att&0xFF));
} }
break; break;
case 'M':
{
uint16_t mute;
if (next_arg_unsigned(&mute)) break;
set_mute(mute);
}
break;
case 'B': case 'B':
case 'T': case 'T':