You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
804 B
33 lines
804 B
// Copyright (c) 2020 Lukasz Chodyla |
|
// Distributed under the MIT License. |
|
// See accompanying file LICENSE.txt for the full license. |
|
|
|
#ifndef COMPONENTS_FIRMWARE_NXBUTTONS_H_ |
|
#define COMPONENTS_FIRMWARE_NXBUTTONS_H_ |
|
|
|
#include <stdint.h> |
|
#include <stdbool.h> |
|
#include <stddef.h> |
|
|
|
typedef void (*ButtonEventHandler)(uint8_t btn); |
|
|
|
typedef struct Button |
|
{ |
|
uint8_t id; |
|
uint8_t btnGpio; |
|
uint8_t pullGpio; // disabled when 0 |
|
bool inverted; // triggered by gnd by default |
|
bool isPressed; |
|
bool isBouncing; |
|
uint32_t debounceMs; |
|
} Button; |
|
|
|
void nxInitButtons(Button buttons[], size_t buttonCount); |
|
|
|
void nxSetOnPressHandler(ButtonEventHandler handler); |
|
|
|
void nxSetOnReleaseHandler(ButtonEventHandler handler); |
|
|
|
bool nxIsButtonPressed(uint8_t btn); |
|
|
|
#endif /* COMPONENTS_FIRMWARE_NXBUTTONS_H_ */
|
|
|