Page 1 of 1

Btn.addButton() with interrupt

Posted: 29 Feb 2024 12:00
by KGBEl
Hi out there.

I have copied the example from https://z-uno.z-wave.me/Reference/ZUNO_ ... addButton/
and it works well.
In the text there is a hint of BtnButtonModeExtInt wich you can use instead of BtnButtonModeTimer
in the example.

My question is, how do I set up an ISR and let the interrupt find its way to that ISR.

I found out that attachInterrupt() is not working in this case.

Z-Uno v2, 3.0.10, Razberry 7 Pro, RaspBerry 4
SDK Version: 7.15.00
Serial API Version: 07.05

Very thankful in advance.

Re: Btn.addButton() with interrupt

Posted: 14 Mar 2024 10:25
by amatilda
KGBEl wrote:
29 Feb 2024 12:00
Hi out there.

I have copied the example from https://z-uno.z-wave.me/Reference/ZUNO_ ... addButton/
and it works well.
In the text there is a hint of BtnButtonModeExtInt wich you can use instead of BtnButtonModeTimer
in the example.

My question is, how do I set up an ISR and let the interrupt find its way to that ISR.

I found out that attachInterrupt() is not working in this case.

Z-Uno v2, 3.0.10, Razberry 7 Pro, RaspBerry 4
SDK Version: 7.15.00
Serial API Version: 07.05

Very thankful in advance.
Hello.
Replace

Code: Select all

init.mode = BtnButtonModeTimer;
on

Code: Select all

init.mode = BtnButtonModeExtInt;

Re: Btn.addButton() with interrupt

Posted: 14 Mar 2024 21:11
by KGBEl
Thank you for answering, I did that but I haven't found out how to catch the button press.

How do I set up an isr so I can catch the interrupt?

Re: Btn.addButton() with interrupt

Posted: 15 Mar 2024 17:29
by amatilda
KGBEl wrote:
14 Mar 2024 21:11
Thank you for answering, I did that but I haven't found out how to catch the button press.

How do I set up an isr so I can catch the interrupt?
If you check button presses, then as in the example:

Code: Select all

void process_buttons() {
	if(Btn.isSingleClick(BUTTON)) {
		Serial0.println("isSingleClick");
		if (dimmerValue == 5)
			dimmerValue = 100;
		else
			dimmerValue = 5;
	}
	if(Btn.isTripleClick(BUTTON)) {
		Serial0.println("isTripleClick");
		if (dimmerValue == 5)
			dimmerValue = 100;
		else
			dimmerValue = 5;
	}
	if(Btn.isLongClick(BUTTON)) {
		Serial0.println("isLongClick");
		if (dimmerValue == 5)
			dimmerValue = 100;
		else
			dimmerValue = 5;
	}
	if(Btn.isDoubleClick(BUTTON)) {
		Serial0.println("isDoubleClick");
		if (dimmerValue == 5)
			dimmerValue = 100;
		else
			dimmerValue = 5;
	}
}
If you need an interrupt callback, this class does not currently provide this.
You need to use attachInterrupt https://z-uno.z-wave.me/Reference/Inter ... Interrupt/ instead of this class.

Re: Btn.addButton() with interrupt

Posted: 15 Mar 2024 19:07
by KGBEl
Thank you for answering.

If I understand you right, there is no way to use BtnButtonModeExtInt and get an
answer to pushed button without polling the Btn.xxxx for events.

Best is to use attachInterrupt() an work around?

Re: Btn.addButton() with interrupt

Posted: 15 Mar 2024 19:09
by KGBEl
One more question, is there a plan for getting an callback on BtnButtonModeExtInt?

Re: Btn.addButton() with interrupt

Posted: 17 Mar 2024 00:00
by amatilda
KGBEl wrote:
15 Mar 2024 19:07
If I understand you right, there is no way to use BtnButtonModeExtInt and get an
answer to pushed button without polling the Btn.xxxx for events.

Best is to use attachInterrupt() an work around?
Yes that's right.

Re: Btn.addButton() with interrupt

Posted: 17 Mar 2024 00:01
by amatilda
KGBEl wrote:
15 Mar 2024 19:09
One more question, is there a plan for getting an callback on BtnButtonModeExtInt?
At the moment there are no plans for this.

Re: Btn.addButton() with interrupt

Posted: 17 Mar 2024 13:42
by KGBEl
Thank you very much for your answers, appreciated.