Commit 2f6764df authored by Adrien Oliva's avatar Adrien Oliva

Add doxygen documentation.

parent 921d4905
Pipeline #125 passed with stage
in 0 seconds
5 Adrien Oliva <olivaa+gitlab@yapbreak.fr>
9 Adrien Oliva <olivaa+gitlab@yapbreak.fr>
/**
* @file simple.cpp
* @brief Simple click with a button connected to PIN 4.
*/
/// [Click]
#include <Arduino.h>
#include "button.h"
......@@ -5,16 +11,29 @@
// Create a button connected to pin 4.
button_t my_button(4);
/**
* @brief Callback for a single click.
*
* @param arg (UNUSED)
*/
void click(void *arg)
{
Serial.println("Click");
}
/**
* @brief Callback for a double click.
*
* @param arg (UNUSED)
*/
void doubleclick(void *arg)
{
Serial.println("Double click");
}
/**
* @brief Arduino function to setup and initialize everything.
*/
void setup() {
Serial.begin(115200);
......@@ -25,11 +44,23 @@ void setup() {
}, NULL);
}
/**
* @brief Arduino function called in the main loop.
*/
void loop() {
my_button.loop();
}
/// [Click]
#ifndef ARDUINO
/**
* @brief Stub of Arduino main.
*
* @param argc (UNUSED)
* @param argv (UNUSED)
*
* @return Exit code
*/
int main(int argc, char *argv)
{
(void) argc;
......
/**
* @file button.cpp
* @brief Button interface implementation using Arduino framework.
*/
#include <Arduino.h>
#include "button.h"
/**
* @brief Double click latency in ms
*/
#define DOUBLECLICK_TIMER 250
/**
* @brief Long click duration in ms
*/
#define LONGCLICK_TIMER 2000
button_t::button_t(const uint8_t pin)
......
/**
* @file button.h
* @author Adrien Oliva <olivaa+gitlab@yapbreak.fr>
* @date 2018-03-27
* @brief Main classes definitions.
*
* @section main API description and purpose
*
* @subsection ex_simple Simple Button Click Sample
* @snippet simple.cpp Click
*/
/* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* Version 2, December 2004
*
......@@ -13,39 +24,130 @@
* 0. You just DO WHAT THE FUCK YOU WANT TO.
*
*/
/**
* @mainpage LibButton
*
* This is a small IOT library to easily handle buttons.
*/
#ifndef __BUTTON_H__
#define __BUTTON_H__
#include <functional>
/**
* @brief Generic click callback function.
*
* User defined callback called on every click (single, double or long).
*/
typedef std::function<void(void *)> button_callback_t;
/**
* @brief Abstract a button.
*
* This is the main button interface. Given a GPIO pin, you can set callbacks
* that react on single click, double click or long click.
*/
class button_t {
private:
/**
* @brief A PIN identifier where button is connected.
*/
const uint8_t m_pin;
/**
* @brief Store last button state seen.
*/
bool m_last_down = false;
/**
* @brief Store time for next relevent event.
*/
unsigned long m_next_event_time = 0;
/**
* @brief Store keypress time.
*/
unsigned long m_keypress_time = 0;
/**
* @brief Number of event appears within given time.
*/
char m_event_count = 0;
/**
* @brief Long press flag.
*/
bool m_long_enable = false;
/**
* @brief Single click callback registration slot.
*/
button_callback_t m_single_click_callback = NULL;
/**
* @brief Double click callback registration slot.
*/
button_callback_t m_double_click_callback = NULL;
/**
* @brief Long click callback registration slot.
*/
button_callback_t m_long_click_callback = NULL;
/**
* @brief User defined argument for single click callback
*/
void *m_single_arg = NULL;
/**
* @brief User defined argument for double click callback
*/
void *m_double_arg = NULL;
/**
* @brief User defined argument for long click callback
*/
void *m_long_arg = NULL;
public:
/**
* @brief Main button constructor.
*
* @param pin GPIO connected to the button controlled by this interface.
*/
explicit button_t(const uint8_t pin);
/**
* @brief Default destructor.
*/
~button_t();
/**
* @brief Set single click callback.
*
* @param callback Function called upon single click.
* @param arg Argument passed to callback function.
*
* A single click is caracterized by a press shorter than 2 seconds,
* followed by a release for more than 250 ms.
*/
void on_single_click(const button_callback_t &callback, void *arg);
/**
* @brief Set double click callback.
*
* @param callback Function called upon double click.
* @param arg Argument passed to callback function.
*
* A double click is characterized by a press shorter than 2 seconds,
* followed by another press shorter than 2 seconds in less than
* 250 ms interval.
*/
void on_double_click(const button_callback_t &callback, void *arg);
/**
* @brief Set long click callback.
*
* @param callback Function called upon single click.
* @param arg Argument passed to callback function.
*
* A long click is characterized by a press longer than 2 seconds.
*/
void on_long_click(const button_callback_t &callback, void *arg);
/**
* @brief Main loop function, to be called in Arduino's loop function.
*/
void loop();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment