Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void update() {
- if(!initialize()) {
- return;
- }
- if(!use_interrupt) {
- process_change(this);
- }
- if(m_pressed==1) {
- return;
- }
- if(m_last_change_ms!=0 && !m_events.empty() && millis()-m_last_change_ms>= double_click_ms) {
- event_entry_t ev;
- event_entry_t ev_next;
- uint32_t press_ms=0;
- int state = 0;
- int clicks = 0;
- int longp = 0;
- int done = 0;
- while(!done) {
- switch(state) {
- case 0:
- if(!m_events.get(&ev)) {
- done = true;
- break;
- }
- if(ev.state==1) {
- // pressed
- state = 1;
- break;
- } else {
- // released
- if(m_on_boot_click!=nullptr) {
- m_on_boot_click(m_on_boot_click_state);
- }
- m_events.get(&ev);
- // pressed
- state = 1;
- break;
- }
- case 1: // press state
- ++clicks;
- press_ms = ev.ms;
- if(!m_events.get(&ev)) {
- done = true;
- break;
- }
- state = 2;
- break;
- case 2: // release state
- longp = !!(m_on_long_click && ev.ms-press_ms>=long_click_ms);
- if(!m_events.get(&ev)) {
- // flush the clicks
- if(m_on_click) {
- if(clicks>longp) {
- m_on_click(clicks-longp,m_on_click_state);
- }
- }
- if(longp) {
- m_on_long_click(m_on_long_click_state);
- }
- done = true;
- break;
- }
- state = 1;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement