Giter Site home page Giter Site logo

lwbtn's Introduction

Lightweight event manager

Read first: Documentation

Features

  • Written in C (C11)
  • Platform independent, requires user to provide millisecond timing source
  • No dynamic memory allocation
  • Callback driven event management
  • Easy to use and maintain
  • User friendly MIT license

Contribute

Fresh contributions are always welcome. Simple instructions to proceed:

  1. Fork Github repository
  2. Follow C style & coding rules already used in the project
  3. Create a pull request to develop branch with new features or bug fixes

Alternatively you may:

  1. Report a bug
  2. Ask for a feature request

lwbtn's People

Contributors

majerle 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lwbtn's Issues

Multi-Click event lost when the latest press/release time didn't fit into the time window.

Multi-Click event lost when the latest press/release time didn't fit into the time window.

Code Version: v1.0.0

Test Case:

Part of test.c :

/*
 * Simulate click event
 */
static const btn_test_time_t test_sequence[] = {
    BTN_STATE(1, LWBTN_CFG_TIME_DEBOUNCE_PRESS + LWBTN_CFG_TIME_CLICK_MIN),
    BTN_STATE(0, LWBTN_CFG_TIME_DEBOUNCE_RELEASE + LWBTN_CFG_TIME_CLICK_MAX),
    BTN_STATE(1, LWBTN_CFG_TIME_DEBOUNCE_PRESS + LWBTN_CFG_TIME_CLICK_MIN / 2), 
    BTN_STATE(0, LWBTN_CFG_TIME_DEBOUNCE_RELEASE + LWBTN_CFG_TIME_CLICK_MULTI_MAX + 1),
    BTN_STATE(0, 100)
};

/* List of expected test events during different input states and their timings */
static const btn_test_evt_t test_events[] = {
    BTN_EVENT_ONPRESS(),
    BTN_EVENT_ONRELEASE(),
    BTN_EVENT_ONPRESS(),
    BTN_EVENT_ONRELEASE(),
};

Part of lwbtn_opt.h :

#define LWBTN_CFG_TIME_CLICK_MIN 20
#define LWBTN_CFG_TIME_CLICK_MAX 300
#define LWBTN_CFG_TIME_CLICK_MULTI_MAX 400
#define LWBTN_CFG_CLICK_MAX_CONSECUTIVE 3
#define LWBTN_CFG_CLICK_MAX_CONSECUTIVE_SEND_IMMEDIATELY 1

Running result(On Win10):

Test running
[     20][    20] evt:   ONPRESS, keep-alive cnt:   0, click cnt:   0
[     42][    22] evt: ONRELEASE, keep-alive cnt:   0, click cnt:   0
[    361][   319] evt:   ONPRESS, keep-alive cnt:   0, click cnt:   1
[    372][    11] evt: ONRELEASE, keep-alive cnt:   0, click cnt:   1

No ONCLICK event is reported. Notice that the lasting time of active state in second click is LWBTN_CFG_TIME_CLICK_MIN / 2, which is smaller than LWBTN_CFG_TIME_CLICK_MIN .

I find it results from the following code in lwbtn.c:

 /* Check time validity for click event */
if ((mstime - btn->time_change) >= LWBTN_TIME_CLICK_GET_PRESSED_MIN(btn)
    && (mstime - btn->time_change) <= LWBTN_TIME_CLICK_GET_PRESSED_MAX(btn)) {
     /*  ... ...  */
     } else {
           /*
            * There was an on-release event, but timing
            * for click event detection is outside allowed window.
            * 
            * Reset clicks counter -> not valid sequence for click event.
            */
            btn->click.cnt = 0;      /* click.cnt is cleared here so no On-Click event will be triggered in our test case. */
}

Does this behaviour conform with the consideration of design and why?
Or to say, should we ignore the precedent valid clicks just because the latest press/release is invalid (beyond the window defined by LWBTN_CFG_TIME_CLICK_MIN and LWBTN_CFG_TIME_CLICK_MAX )?

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.