firmware: add current state query command

This commit is contained in:
Julian Daube 2019-10-22 09:21:27 +02:00
parent 6bf50707c4
commit aba0476bbe
3 changed files with 46 additions and 16 deletions

View File

@ -37,7 +37,20 @@ extern "C" {
/* Exported types ------------------------------------------------------------*/
/* 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 */
/* Exported constants --------------------------------------------------------*/
@ -54,6 +67,7 @@ extern "C" {
void Error_Handler(void);
void set_input(uint8_t channel);
int get_input();
void set_attenuation(uint8_t left, uint8_t right);
void set_mute(uint8_t mute); //< tries to switch to muted ui state
int is_muted(); //< returns whether the ui is muted

View File

@ -102,15 +102,7 @@ int test_button_pressed() {
#undef TEST_BUTTON
}
struct ui_state {
uint8_t oldchannel;
enum {
UI_STATE_NORMAL = 0,
UI_STATE_MUTE,
UI_STATE_SHORT,
} state;
} ui_state = {
struct ui_state ui_state = {
.oldchannel = -1,
.state = UI_STATE_NORMAL,
};
@ -131,6 +123,10 @@ void set_input(uint8_t channel) {
printf("C%d\n", channel);
}
int get_input() {
return ui_state.oldchannel;
}
// only mute if the ui allows to
void set_mute(uint8_t 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) {
bd_set_attenuation(&hi2c1, 0, left);
bd_set_attenuation(&hi2c1, 1, right);
ui_state.latt = bd_set_attenuation(&hi2c1, 0, left);
ui_state.ratt = bd_set_attenuation(&hi2c1, 1, right);
}

View File

@ -138,16 +138,24 @@ int parse_buffer() {
uint16_t gain;
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;
case 'L':
case 'R':
{
uint16_t att;
if (next_arg_unsigned(&att)) break;
uint8_t dir = 0;
uint8_t * save = &ui_state.latt;
printf("%c%d\n", temp, bd_set_attenuation(&hi2c1, temp == 'R', att&0xFF));
if (next_arg_unsigned(&att)) break;
if (temp == 'R') {
dir = 1;
save = &ui_state.ratt;
}
printf("%c%d\n", temp, (*save = bd_set_attenuation(&hi2c1, dir, att&0xFF)));
}
break;
case 'M':
@ -173,7 +181,7 @@ int parse_buffer() {
uint16_t boost;
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;
case 'T':
@ -181,7 +189,19 @@ int parse_buffer() {
uint16_t boost;
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;
default: