firmware: add current state query command
This commit is contained in:
		
							parent
							
								
									6bf50707c4
								
							
						
					
					
						commit
						aba0476bbe
					
				@ -37,7 +37,20 @@ extern "C" {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* Exported types ------------------------------------------------------------*/
 | 
					/* Exported types ------------------------------------------------------------*/
 | 
				
			||||||
/* USER CODE BEGIN ET */
 | 
					/* USER CODE BEGIN ET */
 | 
				
			||||||
 | 
					struct ui_state {
 | 
				
			||||||
 | 
					  uint8_t oldchannel;
 | 
				
			||||||
 | 
					  enum {
 | 
				
			||||||
 | 
					    UI_STATE_NORMAL = 0, 
 | 
				
			||||||
 | 
					    UI_STATE_MUTE,
 | 
				
			||||||
 | 
					    UI_STATE_SHORT,
 | 
				
			||||||
 | 
					  } state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  uint8_t gain;
 | 
				
			||||||
 | 
					  uint8_t bboost, tboost;
 | 
				
			||||||
 | 
					  uint8_t latt, ratt;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern struct ui_state ui_state; // global ui state
 | 
				
			||||||
/* USER CODE END ET */
 | 
					/* USER CODE END ET */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Exported constants --------------------------------------------------------*/
 | 
					/* Exported constants --------------------------------------------------------*/
 | 
				
			||||||
@ -54,6 +67,7 @@ extern "C" {
 | 
				
			|||||||
void Error_Handler(void);
 | 
					void Error_Handler(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void set_input(uint8_t channel);
 | 
					void set_input(uint8_t channel);
 | 
				
			||||||
 | 
					int get_input();
 | 
				
			||||||
void set_attenuation(uint8_t left, uint8_t right);
 | 
					void set_attenuation(uint8_t left, uint8_t right);
 | 
				
			||||||
void set_mute(uint8_t mute); //< tries to switch to muted ui state
 | 
					void set_mute(uint8_t mute); //< tries to switch to muted ui state
 | 
				
			||||||
int is_muted(); //< returns whether the ui is muted
 | 
					int is_muted(); //< returns whether the ui is muted
 | 
				
			||||||
 | 
				
			|||||||
@ -102,15 +102,7 @@ int test_button_pressed() {
 | 
				
			|||||||
#undef TEST_BUTTON
 | 
					#undef TEST_BUTTON
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct ui_state {
 | 
					struct ui_state ui_state = {
 | 
				
			||||||
  uint8_t oldchannel;
 | 
					 | 
				
			||||||
  enum {
 | 
					 | 
				
			||||||
    UI_STATE_NORMAL = 0, 
 | 
					 | 
				
			||||||
    UI_STATE_MUTE,
 | 
					 | 
				
			||||||
    UI_STATE_SHORT,
 | 
					 | 
				
			||||||
  } state;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
} ui_state = {
 | 
					 | 
				
			||||||
  .oldchannel = -1,
 | 
					  .oldchannel = -1,
 | 
				
			||||||
  .state = UI_STATE_NORMAL,
 | 
					  .state = UI_STATE_NORMAL,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@ -131,6 +123,10 @@ void set_input(uint8_t channel) {
 | 
				
			|||||||
	printf("C%d\n", channel);
 | 
						printf("C%d\n", channel);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int get_input() {
 | 
				
			||||||
 | 
					  return ui_state.oldchannel;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// only mute if the ui allows to 
 | 
					// only mute if the ui allows to 
 | 
				
			||||||
void set_mute(uint8_t mute) {
 | 
					void set_mute(uint8_t mute) {
 | 
				
			||||||
  if(UI_STATE_MUTE == ui_state.state && mute)
 | 
					  if(UI_STATE_MUTE == ui_state.state && mute)
 | 
				
			||||||
@ -190,8 +186,8 @@ int is_shorted() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void set_attenuation(uint8_t left, uint8_t right) {
 | 
					void set_attenuation(uint8_t left, uint8_t right) {
 | 
				
			||||||
	bd_set_attenuation(&hi2c1, 0, left);
 | 
						ui_state.latt = bd_set_attenuation(&hi2c1, 0, left);
 | 
				
			||||||
	bd_set_attenuation(&hi2c1, 1, right);
 | 
					  ui_state.ratt = bd_set_attenuation(&hi2c1, 1, right);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -138,16 +138,24 @@ int parse_buffer() {
 | 
				
			|||||||
			uint16_t gain;
 | 
								uint16_t gain;
 | 
				
			||||||
			if (next_arg_unsigned(&gain)) break;
 | 
								if (next_arg_unsigned(&gain)) break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			printf("G%d\n", bd_set_gain(&hi2c1, gain));
 | 
								printf("G%d\n", (ui_state.gain = bd_set_gain(&hi2c1, gain)));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case 'L':
 | 
						case 'L':
 | 
				
			||||||
	case 'R':
 | 
						case 'R':
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		uint16_t att;
 | 
							uint16_t att;
 | 
				
			||||||
 | 
							uint8_t dir = 0;
 | 
				
			||||||
 | 
							uint8_t * save = &ui_state.latt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (next_arg_unsigned(&att)) break;
 | 
							if (next_arg_unsigned(&att)) break;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		printf("%c%d\n", temp, bd_set_attenuation(&hi2c1, temp == 'R', att&0xFF));
 | 
							if (temp == 'R') {
 | 
				
			||||||
 | 
								dir = 1;
 | 
				
			||||||
 | 
								save = &ui_state.ratt;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							printf("%c%d\n", temp, (*save = bd_set_attenuation(&hi2c1, dir, att&0xFF)));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case 'M':
 | 
						case 'M':
 | 
				
			||||||
@ -173,7 +181,7 @@ int parse_buffer() {
 | 
				
			|||||||
		uint16_t boost;
 | 
							uint16_t boost;
 | 
				
			||||||
		if (next_arg_unsigned(&boost)) break;
 | 
							if (next_arg_unsigned(&boost)) break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		printf("B%d\n", bd_set_bass_boost(&hi2c1, boost));
 | 
							printf("B%d\n", (ui_state.bboost = bd_set_bass_boost(&hi2c1, boost)));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case 'T':
 | 
						case 'T':
 | 
				
			||||||
@ -181,7 +189,19 @@ int parse_buffer() {
 | 
				
			|||||||
		uint16_t boost;
 | 
							uint16_t boost;
 | 
				
			||||||
		if (next_arg_unsigned(&boost)) break;
 | 
							if (next_arg_unsigned(&boost)) break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		printf("T%d\n", bd_set_treble_boost(&hi2c1, boost));
 | 
							printf("T%d\n", (ui_state.tboost = bd_set_treble_boost(&hi2c1, boost)));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case '?':
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// return the system state
 | 
				
			||||||
 | 
							printf("M%d\n", is_muted());
 | 
				
			||||||
 | 
							printf("S%d\n", is_shorted());
 | 
				
			||||||
 | 
							printf("C%d\n", get_input());
 | 
				
			||||||
 | 
							printf("B%d\n", ui_state.bboost);
 | 
				
			||||||
 | 
							printf("T%d\n", ui_state.tboost);
 | 
				
			||||||
 | 
							printf("L%d\n", ui_state.latt);
 | 
				
			||||||
 | 
							printf("R%d\n", ui_state.ratt);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user