Commit d5396d75 authored by Mathieu Maret's avatar Mathieu Maret

First Draft with only one GPIO usable

parent 6e509e9c
#include "HIB.h"
static uint8_t pin;
static uint8_t initialState;
static int state;
static volatile bool debouncing;
static ETSTimer timer;
static unsigned long previousMillis;
static unsigned int longPressMsec;
void timerCallback(void *);
void IRQ_handler();
void onButtonPressed();
void onButtonReleased();
void onLongButtonPressed();
void setConfig(uint8_t p, uint8_t initState, int longPress );
HIB::HIB(uint8_t pin, uint8_t initialState, int longPressMsec)
setConfig(pin, initialState, longPressMsec);
void HIB::configure(uint8_t pin, uint8_t initState, int longPressMsec){
setConfig(pin, initState, longPressMsec);
void setConfig(uint8_t p, uint8_t initState, int longPress ){
pin = p;
initialState = initState;
state = initialState;
debouncing = false;
previousMillis = 0;
longPressMsec = longPress;
pinMode(pin, INPUT);
attachInterrupt(digitalPinToInterrupt(pin), IRQ_handler, CHANGE);
os_timer_setfn(&timer, timerCallback, NULL);
void IRQ_handler(){
debouncing = true;
os_timer_arm(&timer, 50, 0);
void timerCallback(void *){
debouncing = false;
state = !state;
if (state != digitalRead(pin)){
Serial.println("Debounce failed");
state = !state;
if(state != initialState)
void onButtonPressed(){
Serial.println("Button Pressed");
previousMillis = millis();
void onLongButtonPressed(){
Serial.println("Long Button Pressed");
void onButtonReleased(){
Serial.println("Button Released");
if(millis() - previousMillis >= longPressMsec){
HIB Hib;
#pragma once
#include "Arduino.h"
extern "C" {
#include "osapi.h"
// Human Interface Button
class HIB {
HIB(uint8_t pin, uint8_t initialState, int longPressMsec = 5000);
void configure(uint8_t pin, uint8_t initialState, int longPressMsec = 5000);
extern HIB Hib;
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