Files
rpi4b-temp-humidity/src/button.h
T

44 lines
1015 B
C

/*
* button.h - Call functions if GPIO pins are high
* Copyright (C) 2024 Alexander Rosenberg
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version. See the LICENSE file for more information.
*/
#ifndef INCLUDED_BUTTON_H
#define INCLUDED_BUTTON_H
#include <sys/types.h>
#include <libgpio.h>
#include <stdbool.h>
typedef struct {
gpio_handle_t handle;
gpio_pin_t pin;
struct timespec last_detect;
bool is_down;
} Button;
/*
* Create a Button object with the given HANDLE, PIN and ACTION. USER_DATA will
* be passed to ACTION every time it is run.
* Return: the created Button.
*/
Button *button_new(gpio_handle_t handle, gpio_pin_t pin);
/*
* Delete BUTTON.
*/
void button_delete(Button *button);
/*
* Return: true if BUTTON is down
*/
bool button_pressed(Button *button);
#endif