Git Product home page Git Product logo

rwmingis / interruptbutton Goto Github PK

View Code? Open in Web Editor NEW
30.0 3.0 8.0 3.83 MB

This is an interrupt based button event library for the ESP32. It enables binding user defined actions to button events including 'Key Down', Key Up' , 'Key Press', 'Long Key Press' 'AutoRepeat Press' and 'Double-Click'. The actions associated it these events may be executed Asynchronously, Synchronously, or a Hybrid between the two.

License: MIT License

C++ 98.88% CMake 1.12%
button interrupts events arduino-library esp32 esp32-arduino debounce synchronous asynchronous rtos

interruptbutton's People

Contributors

mathieucarbou avatar rwmingis avatar vortigont avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

interruptbutton's Issues

Program crashes

Hi I often encounter this issue and my ESp32 will reboot:

assert failed: xQueueGenericSend queue.c:832 (pxQueue->pcHead != ((void *)0) || pxQueue->u.xSemaphore.xMutexHolder == ((void *)0) || pxQueue->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle())

Why?

RTOS API

I need to use RTOS API in the event fucntion. For example, sending some data to a queue, should I use regular API, or API with _FromISR?
xQueueOverwrite(QueueHandle_t xQueue, const void * pvItemToQueue);
xQueueOverwriteFromISR(QueueHandle_t xQueue, const void * pvItemToQueue,BaseType_t *pxHigherPriorityTaskWoken);
Thanks.

ESP crashes if using dynamicaly created objects

Using dynamically created button objects leads to a crash on ISR

int pin = 4;
InterruptButton *btn1 = nullptr;

setup(){
      btn1 = new InterruptButton(pin, INPUT_PULLUP, LOW);
      btn1.syncKeyPress[0] =  [](){ Serial.println("Button 1 press");};

}

It makes impossible to use run-time assigned pins for buttons.

Unable to attach to INPUT-only pins

esp32 has 4 INPUT-only pins 34,35,36,39 that can't be set with PULLUP or PULLDOWN
due to this condition those pins are not working for this lib.

void InterruptButton::begin(void){
  if(m_pinMode == INPUT_PULLUP || m_pinMode == INPUT_PULLDOWN) {}

if(m_pinMode == INPUT_PULLUP || m_pinMode == INPUT_PULLDOWN) {

might be possible to add || m_pinMode == INPUT here to use those pins also?

CRLF

There's a mix of CRLF in the source files which is not good... Source files usually by convention us LF, and CRLF only locally on Windows machine if git is configured correctly. Regardless, any IDE supports LF so no reason for CR.

image

interruptbutton stops working after some time

Hi,

I'm using your library (thank you for making it!) as a component with esp-idf 4.4.2 on a TTGO T-Display (dual-core ESP32 V3).

I noticed that after some amount of time, the buttons become unresponsive - trying to figure out why.

Setting up the modules as such:

InterruptButton button_bottom(BUTTON_1, LOW);
InterruptButton button_top(BUTTON_2, LOW);

void buttonSetup()
{
  InterruptButton::setMenuCount(0);
  InterruptButton::setMenuLevel(0);               // Use the functions bound to the first menu associated with the button
  //InterruptButton::m_RTOSservicerStackDepth = 4096; // Use larger values for more memory intensive functions if using Asynchronous mode.
  InterruptButton::setMode(Mode_Asynchronous);    // Defaults to Asynchronous (immediate like an ISR and not actioned in main loop)
  buttonPressActions();
}
void buttonPressActions() {
  button_top.bind(Event_LongKeyPress, 0, []() {   // LONG PRESS ON BUTTON 2
      displayLCD(LCD_Something);
  });

  button_top.bind(Event_KeyPress, 0, []() {   // PRESS ON BUTTON 2
      displayLCD(LCD_Something);
  });

  button_top.bind(Event_DoubleClick, 0, []() {   // DOUBLE-CLICK ON BUTTON 2
      displayLCD(LCD_Something);
  });

  button_bottom.bind(Event_KeyPress, 0, []() {  // PRESS ON BUTTON 1
      displayLCD(LCD_Something);
  });

  button_bottom.bind(Event_DoubleClick, 0, []() {  // DOUBLE-CLICK ON BUTTON 1
      displayLCD(LCD_Something);
  });
}

Behavior- after some unknown amount of time, the button events stop being triggered. No errors. No stack overflows. It appears the rest of program execution keeps chugging along.

High Heap memory consumption ? Is it normal ?

@rwmingis : I am following with interest issue #17: I am using your library which is pretty cool. I found that when I activate it in my project, the heap memory usage bumps a lot (I don't know the reason). I am using Event_KeyPress and Event_LongKeyPress with no special configuration.

Should I also disable some events like shown in issue #17 to get some memory back ?

Here is the heap consumption of my ESP, when the button option is activated, I am creating a button like this:

  button = new InterruptButton(pin, LOW);
  button->setLongPressInterval(8000);
  button->bind(events::Event_KeyPress, [this]()
               { _callback(ButtonConfig.getPressAction()); });
  button->bind(events::Event_LongKeyPress, [this]()
               { _callback(ButtonConfig.getLongPressAction()); });
  InterruptButton::setMode(Mode_Asynchronous);

image

Thanks!

Cant disable AutoRepeatPress

Hello, I have the following code:

prevButton.disableEvent(Event_AutoRepeatPress);
prevButton.disableEvent(Event_DoubleClick);
prevButton.disableEvent(Event_KeyDown);
prevButton.disableEvent(Event_KeyUp);

prevButton.bind(Event_KeyPress, 0, &prevEventHandler);
prevButton.bind(Event_LongKeyPress, 0, &longPrevEventHandler);


void prevEventHandler(void)
{

  Serial.println("prev pressed");
}

void longPrevEventHandler(void)
{

  Serial.println("long prev pressed");
}

But whenever I longpress a button, the Autorepeatpress also triggers(When i set the Autorepeatpress Interval to a high value, it "works")

This is the response from my ESP32, when i only press and hold the button for a few seconds:

long prev pressed
prev pressed
prev pressed
prev pressed
prev pressed
prev pressed
prev pressed

Problem with ArduinoIDE 2.0.0 on Windows11

I get warnings( errors) from the compiler from tag totalPolls and can not download to the ESP32-WROOM-DA Module
In Win10 this is just Warnings. If I use Arduino program 1.8.19 (not IDE) with Win11 then I can download the file.
I used the example InterruptButtonExample.ino. The problem seems to were Win11 with ArduinoIDE.

cc1plus.exe: some warnings being treated as errors in Win11

e:_Arduino_2024\Heima\libraries\InterruptButton\InterruptButton.cpp: In static member function 'static void InterruptButton::readButton(void*)':
e:_Arduino_2024\Heima\libraries\InterruptButton\InterruptButton.cpp:130:12: warning: '++' expression of 'volatile'-qualified type is deprecated [-Wvolatile]
130 | btn->m_totalPolls++; // Count the number of total reads
| ~~~~~^~~~~~~~~~~~
e:_Arduino_2024\Heima\libraries\InterruptButton\InterruptButton.cpp:131:66: warning: '++' expression of 'volatile'-qualified type is deprecated [-Wvolatile]
131 | if(gpio_get_level(btn->m_pin) == btn->m_pressedState) btn->m_validPolls++; // Count the number of valid 'PRESSED' reads
| ~~~~~^~~~~~~~~~~~
e:_Arduino_2024\Heima\libraries\InterruptButton\InterruptButton.cpp:164:12: warning: '++' expression of 'volatile'-qualified type is deprecated [-Wvolatile]
164 | btn->m_totalPolls++;
| ~~~~~^~~~~~~~~~~~
e:_Arduino_2024\Heima\libraries\InterruptButton\InterruptButton.cpp:166:14: warning: '++' expression of 'volatile'-qualified type is deprecated [-Wvolatile]
166 | btn->m_validPolls++;
| ~~~~~^~~~~~~~~~~~
e:_Arduino_2024\Heima\libraries\InterruptButton\InterruptButton.cpp:173:16: warning: '--' expression of 'volatile'-qualified type is deprecated [-Wvolatile]
173 | btn->m_validPolls--;
| ~~~~~^~~~~~~~~~~~
e:_Arduino_2024\Heima\libraries\InterruptButton\InterruptButton.cpp: At global scope:
e:_Arduino_2024\Heima\libraries\InterruptButton\InterruptButton.cpp:17:20: error: 'TAG' defined but not used [-Werror=unused-variable]
17 | static const char* TAG = "IBTN"; // IDF log tag
| ^~~
cc1plus.exe: some warnings being treated as errors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.