application: add basic monitor command
This commit is contained in:
parent
a4d881df29
commit
577e5511a2
100
application.c
100
application.c
|
@ -376,6 +376,98 @@ static void command_types(void* argument)
|
|||
mux_select(-1); // disable multiplexer
|
||||
}
|
||||
|
||||
/** monitor the channels for activity
|
||||
* @param[in] argument 0 to pull low, 1 to pull high
|
||||
*/
|
||||
static void command_monitor(void* argument)
|
||||
{
|
||||
(void)argument; // we won't use the argument
|
||||
|
||||
// set input pull
|
||||
if (NULL == argument) {
|
||||
puts("channels are left floating\n");
|
||||
for (uint8_t i = channel_start; i <= channel_stop; i++) {
|
||||
gpio_mode_setup(channel_ports[i], GPIO_MODE_INPUT, GPIO_PUPD_NONE, channel_pins[i]); // set to floating
|
||||
}
|
||||
} else {
|
||||
const uint32_t pull = *(uint32_t*)argument; // get pull argument
|
||||
if (0 == pull) {
|
||||
puts("channels are pulled low using internal 40 kOhm resistor\n");
|
||||
for (uint8_t i = channel_start; i <= channel_stop; i++) {
|
||||
gpio_mode_setup(channel_ports[i], GPIO_MODE_INPUT, GPIO_PUPD_PULLDOWN, channel_pins[i]); // set to pull down
|
||||
}
|
||||
} else if (1 == pull) {
|
||||
puts("channels are pulled high to 3.3V using internal 40 kOhm resistor\n");
|
||||
for (uint8_t i = channel_start; i <= channel_stop; i++) {
|
||||
gpio_mode_setup(channel_ports[i], GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, channel_pins[i]); // set to pull up
|
||||
}
|
||||
} else {
|
||||
puts("unknown pull parameter. use 0 for low and 3 for 3.3V high\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// collect pins we want to monitor
|
||||
uint16_t gpioa_mask = 0; // which pins on GPIOA we want to monitor
|
||||
uint16_t gpiob_mask = 0; // which pins on GPIOB we want to monitor
|
||||
for (uint8_t i = channel_start; i <= channel_stop; i++) {
|
||||
if (GPIOA == channel_ports[i]) {
|
||||
gpioa_mask |= channel_pins[i];
|
||||
} else if (GPIOB == channel_ports[i]) {
|
||||
gpiob_mask |= channel_pins[i];
|
||||
} else {
|
||||
printf("unknown port for CH%02u\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
// get initial state
|
||||
puts("press any key to stop monitoring\n");
|
||||
puts("time (s) ");
|
||||
for (uint8_t i = channel_start; i <= channel_stop; i++) {
|
||||
printf("%02u ", i);
|
||||
}
|
||||
puts("\n");
|
||||
|
||||
// start monitoring
|
||||
uint16_t gpioa_data = UINT16_MAX;
|
||||
uint16_t gpiob_data = UINT16_MAX;
|
||||
while (!user_input_available) { // run until user breaks it
|
||||
// time to do periodic checks
|
||||
if (wakeup_flag || second_flag) {
|
||||
iwdg_reset(); // kick the dog
|
||||
wakeup_flag = false; // clear flag
|
||||
second_flag = false; // clear flag
|
||||
}
|
||||
// check is there is a change on a channel
|
||||
const uint16_t gpioa_new = gpio_get(GPIOA, gpioa_mask);
|
||||
const uint16_t gpiob_new = gpio_get(GPIOB, gpioa_mask);
|
||||
if (gpioa_new != gpioa_data || gpiob_new != gpiob_data) {
|
||||
// print data
|
||||
puts("0000.000");
|
||||
for (uint8_t i = channel_start; i <= channel_stop; i++) {
|
||||
const uint16_t port = (GPIOA == channel_ports[i] ? gpioa_new : gpiob_new);
|
||||
const uint8_t high = ((port & channel_pins[i]) ? 1 : 0);
|
||||
if (high) {
|
||||
puts(" 1");
|
||||
} else {
|
||||
puts(" 0");
|
||||
}
|
||||
}
|
||||
puts("\n");
|
||||
// save change
|
||||
gpioa_data = gpioa_new;
|
||||
gpiob_data = gpiob_new;
|
||||
// do we need a rate limit?
|
||||
}
|
||||
}
|
||||
user_input_get(); // clean input
|
||||
|
||||
// set all back to input
|
||||
for (uint8_t i = channel_start; i <= channel_stop; i++) {
|
||||
gpio_mode_setup(channel_ports[i], GPIO_MODE_INPUT, GPIO_PUPD_NONE, channel_pins[i]); // ensure pin is floating input
|
||||
}
|
||||
}
|
||||
|
||||
/** set first channel of range to scan
|
||||
* @param[in] argument optional pointer to first channel number
|
||||
*/
|
||||
|
@ -554,6 +646,14 @@ static const struct menu_command_t menu_commands[] = {
|
|||
.argument_description = NULL,
|
||||
.command_handler = &command_types,
|
||||
},
|
||||
{
|
||||
.shortcut = 'm',
|
||||
.name = "monitor",
|
||||
.command_description = "monitor channel activity",
|
||||
.argument = MENU_ARGUMENT_UNSIGNED,
|
||||
.argument_description = "[0|3]",
|
||||
.command_handler = &command_monitor,
|
||||
},
|
||||
{
|
||||
.shortcut = 'c',
|
||||
.name = "start",
|
||||
|
|
Loading…
Reference in New Issue