Hi all,
I have a class that I have in mind to work as a high level interface to operate with buttons for embedded systems. I would like it to be reusable in different projects.
I want the programmer to be able to use the class with state machines and poll pressing events from the user.
I was thinking I could link a state machine event buffer to each class instance, and link events that could be application specific. The programmer could enum the possible events, and set them for each button. This would be an idea for the constructor:
|
button(int mcu_pin, uint8_t event_buffer, uint8_t short_press_event, uint8_t release_press_event, uint8_t long_press_event); // Constructor
|
As you can see, each button could trigger an event from being pressed, released, or pressed for a long period of time, and the event would be sent to the buffer belonging to a higher level state machine operating the buttons.
Does this design seem to hold water?
I am mostly concerned about the event variables, I think it looks sleek to pass the events as variables this way, but I am not sure it is a good coding practice. Another example of the in use:
1 2 3 4 5 6 7 8 9
|
#define CENTRAL_B_PIN (1)
#define STATE_M_BUFFER_SIZE (10)
uint8_t buffer[STATE_M_BUFFER_SIZE];
typedef enum {
S_EV_NOTHING, // no event
S_EV_ENTER, // enter data entry, ...
S_EV_SKIP // skip page, whatever, ...
} StateMachineEvents_t
button centralButton = button(CENTRAL_B_PIN, buffer, S_EV_ENTER, S_EV_NOTHING, S_EV_SKIP);
|
In that particular case, the central button would act as enter when pressed, and act as a skip (whatever that would mean in the specific app) when pressed long enough, and nothing would happen upon release.
What are your thoughts, any improvement or different idea you would have in mind?
Thanks a lot!!