firmware: add capability to short all inputs (via serial command)
This commit is contained in:
		
							parent
							
								
									5364d92c1c
								
							
						
					
					
						commit
						a60a0fa459
					
				@ -55,7 +55,10 @@ void Error_Handler(void);
 | 
			
		||||
 | 
			
		||||
void set_input(uint8_t channel);
 | 
			
		||||
void set_attenuation(uint8_t left, uint8_t right);
 | 
			
		||||
void set_mute(uint8_t mute);
 | 
			
		||||
void set_mute(uint8_t mute); //< tries to switch to muted ui state
 | 
			
		||||
int is_muted(); //< returns whether the ui is muted
 | 
			
		||||
void set_short(uint8_t shorted); //< tries to switch to shorted ui state
 | 
			
		||||
int is_shorted();
 | 
			
		||||
 | 
			
		||||
/* USER CODE BEGIN EFP */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -104,37 +104,49 @@ int test_button_pressed() {
 | 
			
		||||
 | 
			
		||||
struct ui_state {
 | 
			
		||||
  uint8_t oldchannel;
 | 
			
		||||
  uint8_t mute;
 | 
			
		||||
  enum {
 | 
			
		||||
    UI_STATE_NORMAL = 0, 
 | 
			
		||||
    UI_STATE_MUTE,
 | 
			
		||||
    UI_STATE_SHORT,
 | 
			
		||||
  } state;
 | 
			
		||||
 | 
			
		||||
} ui_state = {
 | 
			
		||||
  .oldchannel = -1,
 | 
			
		||||
  .mute = 0,
 | 
			
		||||
  .state = UI_STATE_NORMAL,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void set_input(uint8_t channel) {
 | 
			
		||||
	if (ui_state.oldchannel == channel || channel >= 6)
 | 
			
		||||
	if (ui_state.state != UI_STATE_NORMAL || ui_state.oldchannel == channel || channel >= 6)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
  set_input_led(ui_state.oldchannel, 0);	
 | 
			
		||||
  
 | 
			
		||||
  // do not disturb the mute mode
 | 
			
		||||
  if (!ui_state.mute)
 | 
			
		||||
  {
 | 
			
		||||
  set_input_led(channel, 1);
 | 
			
		||||
 | 
			
		||||
  // invert bd inputs to match the numbers on the case
 | 
			
		||||
  bd_set_input(&hi2c1, 5-channel);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
	ui_state.oldchannel = channel;
 | 
			
		||||
 | 
			
		||||
	printf("C%d\n", channel);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// only mute if the ui allows to 
 | 
			
		||||
void set_mute(uint8_t mute) {
 | 
			
		||||
  if(ui_state.mute == mute)
 | 
			
		||||
  if(UI_STATE_MUTE == ui_state.state && mute)
 | 
			
		||||
    // no state change required
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  if (0 == (ui_state.mute = mute)) {
 | 
			
		||||
  // figure out the state transition  
 | 
			
		||||
  if (UI_STATE_NORMAL == ui_state.state && mute) {
 | 
			
		||||
    ui_state.state = UI_STATE_MUTE;
 | 
			
		||||
    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);
 | 
			
		||||
  } 
 | 
			
		||||
  else if (UI_STATE_MUTE == ui_state.state && !mute) 
 | 
			
		||||
  {
 | 
			
		||||
    ui_state.state = UI_STATE_NORMAL;
 | 
			
		||||
    // hack to make reactivation of the last channel easier
 | 
			
		||||
    uint8_t old_input = ui_state.oldchannel;
 | 
			
		||||
    ui_state.oldchannel = -1;
 | 
			
		||||
@ -142,13 +154,39 @@ void set_mute(uint8_t mute) {
 | 
			
		||||
    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);
 | 
			
		||||
int is_muted() {
 | 
			
		||||
  return ui_state.state == UI_STATE_MUTE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void set_short(uint8_t do_short) {
 | 
			
		||||
  // test for possible state changes
 | 
			
		||||
  if (UI_STATE_NORMAL == ui_state.state && do_short) 
 | 
			
		||||
  {
 | 
			
		||||
    ui_state.state = UI_STATE_SHORT;
 | 
			
		||||
    bd_set_input(&hi2c1, BD_INPUT_ALL);
 | 
			
		||||
 | 
			
		||||
    // visualize that all inputs are shorted
 | 
			
		||||
    for (int i = 0; i < 6; ++i) 
 | 
			
		||||
      set_input_led(i, 1);
 | 
			
		||||
  } 
 | 
			
		||||
  else if (UI_STATE_SHORT == ui_state.state && !do_short) 
 | 
			
		||||
  {
 | 
			
		||||
    ui_state.state = UI_STATE_NORMAL;
 | 
			
		||||
    
 | 
			
		||||
    for (int i = 0; i < 6; ++i) 
 | 
			
		||||
      set_input_led(i, 0);
 | 
			
		||||
 | 
			
		||||
    // reactivate currently selected input
 | 
			
		||||
    uint8_t old_input = ui_state.oldchannel;
 | 
			
		||||
    ui_state.oldchannel = -1;
 | 
			
		||||
    set_input(old_input);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int is_shorted() {
 | 
			
		||||
  return ui_state.state == UI_STATE_SHORT;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void set_attenuation(uint8_t left, uint8_t right) {
 | 
			
		||||
@ -202,6 +240,7 @@ int main(void)
 | 
			
		||||
  set_attenuation(0,0);
 | 
			
		||||
  int count = 0;
 | 
			
		||||
  int button_timeout = 0;
 | 
			
		||||
  
 | 
			
		||||
  /* USER CODE END 2 */
 | 
			
		||||
 | 
			
		||||
  /* Infinite loop */
 | 
			
		||||
@ -226,7 +265,8 @@ int main(void)
 | 
			
		||||
 | 
			
		||||
      if (1000 < button_timeout) {
 | 
			
		||||
        // long press, toggle mute
 | 
			
		||||
        set_mute(!ui_state.mute);
 | 
			
		||||
        set_mute(!is_muted());
 | 
			
		||||
        printf("M%d\n", is_muted());
 | 
			
		||||
        button_timeout = 0;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -156,6 +156,16 @@ int parse_buffer() {
 | 
			
		||||
		if (next_arg_unsigned(&mute)) break;
 | 
			
		||||
		
 | 
			
		||||
		set_mute(mute);
 | 
			
		||||
		printf("M%d\n", is_muted());
 | 
			
		||||
	}
 | 
			
		||||
		break;
 | 
			
		||||
	case 'S':
 | 
			
		||||
	{
 | 
			
		||||
		uint16_t shorted;
 | 
			
		||||
		if (next_arg_unsigned(&shorted)) break;
 | 
			
		||||
		
 | 
			
		||||
		set_short(shorted);
 | 
			
		||||
		printf("S%d\n", is_shorted());
 | 
			
		||||
	}
 | 
			
		||||
		break;
 | 
			
		||||
	case 'B':
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user