bluerange-io / bluerange-mesh

BlueRange Mesh (formerly FruityMesh) - The first completely connection-based open source mesh on top of Bluetooth Low Energy (4.1/5.0 or higher)
https://bluerange.io/
Other
287 stars 109 forks source link

How to use a button with interrupt? #123

Closed NilsMinor closed 3 years ago

NilsMinor commented 4 years ago

Hi,

what is the correct way to use button interrupts? I've seen that there is a callback "button_interrupt_handler". My Target is to register a callback function and to configure my button to call the routine. Should I do this inside my custom module?

My target is to add a PIR sensor to trigger functionality of my module.

Thanks, Nils

mariusheil commented 4 years ago

Hi,

look in Module.h and you will find a virtual ButtonHandler that you can override. This will be called once a button has been pressed and release for a certain time. If you need more functionality like e.g. starting as soon as the press occurs, you would have to implement this functionality yourself using the nordic methods. Otherwise, using our handler is the best approach. You can do this in your module.

NilsMinor commented 4 years ago

Hi, thanks for your response :) I used the virtual Buttonhandler but it is only called when I release the button and gives me the pressed time (I don't know the unit). I need to trigger my interrupt from low to high as well as from high to low changes. Should I therefore implement my own button handler or should I change the setup of the button configuration? Thanks, Nils

mariusheil commented 4 years ago

Hi,

what you could do to make it generic is to extend the functionality and call the ButtonHandler on Press and on Release events. Then, you need to pass the type of the event (pressed / released) and also the time (it is in deciseconds, like most other timeunits in fruitymesh, which is 1/10 second). For the pressed event, you could e.g. pass the time since the last released event. Not sure if somebody would be using that, but maybe better than just passing 0. If you do that, you could open a pull request and we would probably accept that.

Thanks