Closed mcarosh closed 3 years ago
@mcarosh A common misconception is that I have anything to do with the API. I'm just a member of the community like you (perhaps the most vocal one!) except that I wrote the Builder for myself and thought maybe someone else would find it useful so i packed it up and sent to Calvin. Given my 19 stars after a few years maybe I was wrong. :) Calvin deserves all the credit for the API. Its also the reason you generally should ask API questions in the GUIslice API repository.
Now as for a long duration button, Its not something GUIslice API supports easily but I think it can be done.
I helped another user (I don't remember who) that wanted a power button where someone would first press the power button than it would tell them to now hold down the button for three seconds and the state would change. press the power button again and you repeat. So modified the code he posted and came up with this demo. power_btn.zip
The idea is to put all of the logic inside the button's callback, in this case with a timer.
The various button state changes should be all you need. The demo also changes the color of the button from blue to red during the state changes and the background colors for when you are holding the button down. This gives users some feedback as to what is happening. Which I think is very important.
Hopefully you will be able to use modify the code for continuous operation. I don't think it should be necessary to start the whole process off with a single press like my demo but hopefully it will give you some ideas. If you modify it and need further help just post your new version and give me some details of your issues.
Of course its also possible Calvin has a better way to do this. He generally monitors postings here so he might speak up with a simpler solution.
Paul--
Hi @mcarosh --
I believe you had asked a similar question in the Arduino Forum, but I'm not sure if you saw my reply. Just in case, I'm copying my reply here, in case it is helpful. You may note that it was similar in concept to the code that Paul attached above, but perhaps simplified a bit.
It is relatively easy to detect a "long press" to support continuous increment of your counter since the button callback functions are triggered when you first start touching a button, while still holding and when releasing it. You can use these other events to help you detect a continued hold.
For example, starting with the basic ex02_ard_btn_txt example, replace the callback with the following:
int16_t m_nCount = 0; // Simple counter
uint32_t m_tmLastPress = 0; // Time of last press interval
// Button callbacks
bool CbBtnQuit(void* pvGui,void *pvElemRef,gslc_teTouch eTouch,int16_t nX,int16_t nY)
{
if (eTouch == GSLC_TOUCH_DOWN_IN) { // Started press (inside button)
m_tmLastPress = millis();
} else if (eTouch == GSLC_TOUCH_UP_IN) { // Released (inside button)
m_nCount += 1;
GSLC_DEBUG_PRINT("Count = %d\n",m_nCount);
} else if (eTouch == GSLC_TOUCH_MOVE_IN) { // Continued press (inside button)
if ((millis() - m_tmLastPress) > 500) {
m_nCount += 10;
m_tmLastPress = millis();
GSLC_DEBUG_PRINT("Count = %d\n",m_nCount);
}
}
return true;
}
Hello both (ImpulseAdventure, Pconti31) A really big THANKS!!! You made my day :) Now my sketch is finished :) I´ve made a little example program for long-press button. If you want to you can maybe put it to the examples (but please have a look at it before 8) In my case everything works like a charm. So again big "thank you" for your great support and the program itself. And sorry for asking the same question at two forums. I couldn´t remember my github password when I was with a friend, who also wanted to help me, but also failed. In the end you are the men ;) Stay brave mcarosh Longpress-Btn.zip
@mcarosh Nice Job! I'm going to add Calvin's Callback to the FAQ.pdf so it can help other people. Paul--
Is it possible to create an example for long-press button??? Especially if I hold the button down. In my case I want to set a Temp. If I short-press the button I want to add 1°C (this already works) and if I hold the button down I want to continuously add 10°C until the button is released. I don´t know if this is even possible but if so I would be very happy to see an example because the "continuous-add" while button is hold down, keeps me always struggling :/
Thanks for any help Furthermore I want to mention this (GUISlice) is a wonderful library/program. it saved me a lot of time. really thank you for your great work ;)