rfdsatt: Add 'interactive' mode with single-key modifications
This commit is contained in:
parent
e431886969
commit
73b514d793
|
@ -218,6 +218,64 @@ DEFUN(att_set, att_set_cmd, "set",
|
|||
printf("Error setting attenuator: %d\r\n", rc);
|
||||
}
|
||||
|
||||
|
||||
DEFUN(interact, interact_cmd, "interact", "Enter interactive single-key mode")
|
||||
{
|
||||
uint8_t g_chan = 0;
|
||||
uint8_t g_stage = 0;
|
||||
uint8_t g_val = 0;
|
||||
|
||||
printf("Entering interactive single-key mode. Press 'X' for exit\r\n");
|
||||
|
||||
while (1) {
|
||||
int ch, rc;
|
||||
/* read one blocking char */
|
||||
do {
|
||||
ch = getchar();
|
||||
} while (ch == EOF);
|
||||
|
||||
switch (ch) {
|
||||
case 'X': /* exit */
|
||||
return;
|
||||
case '1': case '2': case '3': case '4': /* channel number */
|
||||
g_chan = ch - '1';
|
||||
g_stage = 0;
|
||||
g_val = attenuator_get(g_chan, g_stage, ATT_VAL_CURRENT);
|
||||
break;
|
||||
case '0': /* set to 0dB */
|
||||
g_val = 0;
|
||||
break;
|
||||
case 'f': /* set to full attenuation */
|
||||
g_val = 31;
|
||||
break;
|
||||
case '+': /* increment by 1dB */
|
||||
if (g_val < 31)
|
||||
g_val++;
|
||||
break;
|
||||
case '-': /* decrement by 1dB */
|
||||
if (g_val > 0)
|
||||
g_val--;
|
||||
break;
|
||||
case 'a': /* stage 0 */
|
||||
if (g_stage != 0) {
|
||||
g_stage = 0;
|
||||
g_val = attenuator_get(g_chan, g_stage, ATT_VAL_CURRENT);
|
||||
}
|
||||
break;
|
||||
case 'b': /* stage 1 */
|
||||
if (g_stage != 1) {
|
||||
g_stage = 1;
|
||||
g_val = attenuator_get(g_chan, g_stage, ATT_VAL_CURRENT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
rc = attenuator_set(g_chan, g_stage, g_val*4);
|
||||
if (rc < 0)
|
||||
printf("Error setting attenuator: %d\r\n", rc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* main
|
||||
***********************************************************************/
|
||||
|
@ -282,6 +340,7 @@ int main(void)
|
|||
microvty_register(&version_cmd);
|
||||
microvty_register(&att_show_cmd);
|
||||
microvty_register(&att_set_cmd);
|
||||
microvty_register(&interact_cmd);
|
||||
|
||||
print_banner();
|
||||
microvty_print_prompt();
|
||||
|
|
Loading…
Reference in New Issue