BitsButtonXR is a high-performance button detection module designed specifically for embedded systems.
It inherits the classic binary sequence state machine technology from BitsButton framework and has been adapted according to the design concept of XRobot. Through integration with LibXR middleware, BitsButtonXR achieves automated runtime management and standardized event distribution, eliminating the need for manual polling sequence maintenance and greatly simplifying system integration logic.
For detailed usage tutorials and API documentation, please refer to the Project Wiki.
-
Based on
LibXR::GPIOandLibXR::Timerinterfaces for hardware abstraction, decoupling underlying platform differences and unifying timing scheduling. -
Follows
Applicationframework specifications, supporting dependency injection and automated lifecycle management through MANIFEST. -
Uses
LibXR::Eventsignals andLibXR::LockFreeQueuedata separation architecture to build a thread-safe single-producer multi-consumer model. -
Applies a hybrid scheduling mechanism combining interrupt wake-up and timer polling to achieve low-power response and physical isolation from mechanical bounce.
- GPIO device nodes matching the
key_aliasin thesingle_buttonsconfiguration must be provided.
-
single_buttons- Single button configuration list (
SingleButtonConfig). Contains GPIO alias, active level (high/low), and timing constraint parameters (short press/long press thresholds, etc.).
- Single button configuration list (
-
combined_buttons- Combined button configuration list (
CombinedButtonConfig). Contains combination alias, whether to suppress single button events, and array of button indices that form the combination.
- Combined button configuration list (
/** Timing parameter constraints */
struct ButtonConstraints {
uint16_t short_press_time_ms; ///< Time threshold for short press
uint16_t long_press_start_time_ms; ///< Time when long press starts
uint16_t long_press_period_triger_ms; ///< Period for long press hold events
uint16_t time_window_time_ms; ///< Window for double click detection
};
/** Combined button configuration */
struct CombinedButtonConfig {
const char *combined_alias; ///< Name identifier for the combination
bool suppress_single_keys; ///< Whether to suppress individual button events
std::initializer_list<const char *> constituent_aliases; ///< List of button aliases in combination
ButtonConstraints constraints; ///< Timing constraints for this combination
};
/** Single button configuration */
struct SingleButtonConfig {
const char *key_alias; ///< GPIO name identifier for the button
bool active_level; ///< GPIO level that indicates button press
ButtonConstraints constraints; ///< Timing constraints for this button
};- No dependencies (except for the LibXR basic framework).