Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

Button Any Edge trigger not working

It seems since the update that registering a button callback with the MGOS_GPIO_INT_EDGE_ANY trigger no longer works.

Comments


  • Please, repeat the following exercise as it is written below:

    /mos.yml (excerpt):
    #...
    config_schema:
    - ["pins", "o", {title: "Object pins"}]
    - ["pins.led", "i", 2, {title: "GPIO2:D4"}]
    - ["pins.btn_switch", "i", 12, {title: "GPIO12:D6"}]

    #...
    
    libs:
      - origin: https://github.com/mongoose-os-libs/mjs
      - origin: https://github.com/mongoose-os-libs/ca-bundle 
      - origin: https://github.com/mongoose-os-libs/wifi
      - origin: https://github.com/mongoose-os-libs/rpc-common
      - origin: https://github.com/mongoose-os-libs/rpc-service-config
      - origin: https://github.com/mongoose-os-libs/rpc-service-fs
      - origin: https://github.com/mongoose-os-libs/rpc-uart
    
    #...
    

    /fs/init.js:

    load('api_rpc.js');
    load('api_config.js');
    load('api_events.js');
    load('api_gpio.js');
    
    let pinButton = Cfg.get('pins.btn_switch');
    GPIO.set_mode(pinButton, GPIO.MODE_INPUT);
    GPIO.set_pull(pinButton, GPIO.PULL_DOWN); 
    
    let pinLed = Cfg.get('pins.led');
    GPIO.set_mode(pinLed, GPIO.MODE_OUTPUT); 
    
    function switchCallback(){
        let isSwitchOn = GPIO.read(pinButton);
        GPIO.write(pinLed, isSwitchOn);
        print("read(", pinButton, ") --> The statement 'The switch is on' currently is " , isSwitchOn ? "TRUE" : "FALSE");   
        return GPIO.read(pinButton);
    }
    
    //Init during first start to accuire current SwitchState
    switchCallback();
    
    let StateResponse = {
      callback: switchCallback 
    };
    
    GPIO.set_int_handler(pinButton, GPIO.INT_EDGE_ANY, StateResponse.callback, null);
    GPIO.enable_int(pinButton);
    
  • jonwjonw USA
    edited July 2018

    @shockich It is a problem with the newer releases of the mos SDK. Look at these 2 lines:
    https://github.com/cesanta/mongoose-os/blob/master/fw/src/mgos_gpio.c#L139-L140

    By adding this restriction to the mgos_gpio_set_button_handler, they have removed the ability to use the MGOS_GPIO_INT_EDGE_ANY trigger:
    !(int_mode == MGOS_GPIO_INT_EDGE_POS || int_mode == MGOS_GPIO_INT_EDGE_NEG)

    I tried modifying the code to allow for the MGOS_GPIO_INT_EDGE_ANY trigger, but when I did I noticed it was no longer reliable and my button releases were only detected 10% of the time. Therefore, I am assuming, something in the update broke the MGOS_GPIO_INT_EDGE_ANY trigger and mongoose decided to restrict the button handler registration to positive or negative edges only.

    I have since registered a timer to check the button status every 200ms until it is released as a (somewhat messy) workaround.

  • @shockich
    I am working on a project using esp8266, leds, 3 buttons( 1 flash on the chip, and 2 more created on diff chips)

    I would like to have 3 buttons for up, down, set respectively and have 2 leds attached to the esp board.
    Press button 1-- led 1 turns on (also should have an option to tell the time at which it turns on ), Button 2 for set menu(so just displays the time for now), button 3 pressed makes led 2 on

    Any suggestions regarding the function for the flash press button or outline or if someone has worked with something similar in C ?

    many thanks!

Sign In or Register to comment.