GPS Device
Loading...
Searching...
No Matches
Button Command Handlers

Functions

static ERR_te button_getpushed_handler (uint32_t argc, char **argv)
 CLI handler for the "getpushed" command. Reports the debounced pushed state of a button.
static ERR_te button_getheld_handler (uint32_t argc, char **argv)
 CLI handler for the "getheld" command. Reports the held state of a button.
static ERR_te button_cmd_info_handler (uint32_t argc, char **argv)
 CLI handler for the "info" command. Logs the names of all registered buttons.

Detailed Description

Function Documentation

◆ button_getpushed_handler()

ERR_te button_getpushed_handler ( uint32_t argc,
char ** argv )
static

CLI handler for the "getpushed" command. Reports the debounced pushed state of a button.

Expected invocation: button getpushed <name>

Searches the registered button pool for a handle whose name matches argv[2], then calls button_get_pushed_state and logs the result.

Parameters
[in]argcArgument count. Must be exactly 3.
[in]argvArgument list: argv[0] = "button", argv[1] = "getpushed", argv[2] = button name.
Returns
  • ERR_OK on success
  • ERR_INVALID_ARGUMENT if argc != 3 or no button with the given name exists
  • Propagated error from button_get_pushed_state on failure

Definition at line 574 of file button.c.

574 {
575 if(argc != 3) {
576 LOG_ERROR(
577 internal_state.subsys,
578 internal_state.log_level,
579 "button_getpushed_handler: invalid arguments"
580 );
582 }
583
584 for(uint32_t i = 0; i < CONFIG_BUTTON_MAX_OBJECTS; i++) {
585 if(str_cmp(argv[2], internal_state.buttons[i].name) == true) {
586 bool pushed_state;
587 ERR_te err = button_get_pushed_state(&internal_state.buttons[i], &pushed_state);
588 if(err != ERR_OK) {
589 return err;
590 }
591
592 LOG_INFO(
593 internal_state.subsys,
594 internal_state.log_level,
595 "button_getpushed_handler: %s pushed state: %d",
596 internal_state.buttons[i].name,
597 pushed_state
598 );
599
600 return ERR_OK;
601 }
602
603 if(i == internal_state.button_num - 1) {
604 LOG_ERROR(
605 internal_state.subsys,
606 internal_state.log_level,
607 "button_getpushed_handler: invalid arguments"
608 );
610 }
611 }
612
613 return ERR_OK;
614}
static struct internal_state_s internal_state
Singleton instance of the SysTick driver internal state.
ERR_te button_get_pushed_state(BUTTON_HANDLE_ts const *button_handle, bool *pushed_state_o)
Retrieves the pushed state of a button.
Definition button.c:516
bool str_cmp(const char *str1, const char *str2)
Compares two null-terminated strings for equality.
Definition common.c:248
ERR_te
Standard return type used by all public API functions.
Definition err.h:35
@ ERR_OK
Definition err.h:36
@ ERR_INVALID_ARGUMENT
Definition err.h:38
#define LOG_ERROR(subsys, lvl, fmt,...)
Definition log.h:258
#define LOG_INFO(subsys, lvl, fmt,...)
Definition log.h:255
Here is the call graph for this function:

◆ button_getheld_handler()

ERR_te button_getheld_handler ( uint32_t argc,
char ** argv )
static

CLI handler for the "getheld" command. Reports the held state of a button.

Expected invocation: button getheld <name>

Searches the registered button pool for a handle whose name matches argv[2], then calls button_get_held_state and logs the result.

Parameters
[in]argcArgument count. Must be exactly 3.
[in]argvArgument list: argv[0] = "button", argv[1] = "getheld", argv[2] = button name.
Returns
  • ERR_OK on success
  • ERR_INVALID_ARGUMENT if argc != 3 or no button with the given name exists
  • Propagated error from button_get_held_state on failure

Definition at line 634 of file button.c.

634 {
635 if(argc != 3) {
636 LOG_ERROR(
637 internal_state.subsys,
638 internal_state.log_level,
639 "button_getheld_handler: invalid arguments"
640 );
642 }
643
644 for(uint32_t i = 0; i < CONFIG_BUTTON_MAX_OBJECTS; i++) {
645 if(str_cmp(argv[2], internal_state.buttons[i].name) == true) {
646 bool held_state;
647 ERR_te err = button_get_held_state(&internal_state.buttons[i], &held_state);
648 if(err != ERR_OK) {
649 return err;
650 }
651
652 LOG_INFO(
653 internal_state.subsys,
654 internal_state.log_level,
655 "button_getheld_handler: %s held state: %d",
656 internal_state.buttons[i].name,
657 held_state
658 );
659
660 return ERR_OK;
661 }
662
663 if(i == internal_state.button_num - 1) {
664 LOG_ERROR(
665 internal_state.subsys,
666 internal_state.log_level,
667 "button_getheld_handler: invalid arguments"
668 );
670 }
671 }
672
673 return ERR_OK;
674}
ERR_te button_get_held_state(BUTTON_HANDLE_ts const *button_handle, bool *held_state_o)
Retrieves the held state of a button.
Definition button.c:533
Here is the call graph for this function:

◆ button_cmd_info_handler()

ERR_te button_cmd_info_handler ( uint32_t argc,
char ** argv )
static

CLI handler for the "info" command. Logs the names of all registered buttons.

Expected invocation: button info

Iterates over the internal button pool and logs the name of every slot that is currently in use.

Parameters
[in]argcArgument count. Must be exactly 2.
[in]argvArgument list: argv[0] = "button", argv[1] = "info".
Returns
  • ERR_OK on success
  • ERR_INVALID_ARGUMENT if argc != 2

Definition at line 692 of file button.c.

692 {
693 if(argc != 2) {
694 LOG_ERROR(
695 internal_state.subsys,
696 internal_state.log_level,
697 "button_cmd_info_handler: invalid arguments"
698 );
699 return ERR_INVALID_ARGUMENT;
700 }
701
702 LOG_INFO(internal_state.subsys, internal_state.log_level, "Printing button information:");
703
704 for(uint32_t i = 0; i < CONFIG_BUTTON_MAX_OBJECTS; i++) {
705 if(internal_state.buttons[i].in_use == true) {
706 LOG_INFO(
707 internal_state.subsys,
708 internal_state.log_level,
709 "name: %s",
710 internal_state.buttons[i].name
711 );
712 }
713 }
714
715 return ERR_OK;
716}