From cefd0601b91fa642163c82021d454b3c17d8adf4 Mon Sep 17 00:00:00 2001 From: Jan Sucan Date: Sun, 22 Sep 2019 21:17:50 +0200 Subject: Initial commit --- FanController/fan_controller/hw/button.c | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 FanController/fan_controller/hw/button.c (limited to 'FanController/fan_controller/hw/button.c') diff --git a/FanController/fan_controller/hw/button.c b/FanController/fan_controller/hw/button.c new file mode 100644 index 0000000..90edf03 --- /dev/null +++ b/FanController/fan_controller/hw/button.c @@ -0,0 +1,48 @@ +/* Autor: Ján Sučan + * + * Zdrojove kody, ich casti a subory z nich vzniknute priamo alebo nepriamo + * (objektove subory, Intel Hex, ...) prosim nepouzivajte komercne, ani ako + * sucast komercnych diel. Vsetky ostatne pripady pouzitia su dovolene. + * + * Please don't use the source codes, their parts and files created from them + * directly or indirectly, (object files, Intel Hex files, ...) for commercial + * purposes, not even as a part of commercial products. All other use cases + * are allowed. + */ + +#include +#include +#include + +/** + * @brief Zisti, ci je tlacitko stlacene. + * + * @retval true Tlacitko je stlacene. + * @retval false Tlacitko nie je stlacene. + */ +bool +button_is_pressed(void) +{ + bool a, b; + + a = io_is_button_pressed(); + // Minimalna hodnota pre cakanie funkciou delay_ms() je 16 ms. + delay_ms(20); + b = io_is_button_pressed(); + // Stavy oboch vzoriek sa musia rovnat + // a musia byt rovne stlacenemu tlacitku. + // Ak by sa nerovnali, islo by o zakmit. + return (!a == !b) && !a && !b; +} + +/** + * @brief Zisti, ci je tlacitko pustene (nestlacene). + * + * @retval true Tlacitko je pustene. + * @retval false Tlacitko nie je pustene. + */ +bool +button_is_released(void) +{ + return !button_is_pressed(); +} -- cgit v1.2.3