NCS CAF leds modules can not receive power down event?

Hi,

    I use CAF leds modules in NCS. After click the button and led lights for 3.6 seconds, I submit power down event when double click button. As show in the following figure, led modules can receive power down event and set leds state to off.

case CLICK_SHORT:
    send_led_event(LED_ID_BLUE, &m_led_effect[LED_EFFECT_ID_DEVICE_ON]);
    break;

case CLICK_DOUBLE: {
    struct power_down_event *event = new_power_down_event();

    event->error = false;
    EVENT_SUBMIT(event);
}
break;

    Another situation, I submit led event and power dowen event after long press the button, I find led modules can't receive power down event.

case CLICK_LONG: {
    send_led_event(LED_ID_RED, &m_led_effect[LED_EFFECT_ID_DEVICE_ON]);

    struct power_down_event *event = new_power_down_event();
    event->error = false;
    EVENT_SUBMIT(event);
}
break;

  • Under the same conditions, button modules can receive normally. In addition, led use GPIO mode.

  • Hi Magdalena, 

    Could you check if CONFIG_CAF_LEDS_PM_EVENTS is set to 1. 

    Could you send us the project so we can test on a DK here ? 

  • Yeah, CONFIG_CAF_LEDS_PM_EVENTS is set to 1. My project only enable LEDs、BUTTON and CLICK,you can see it work normally when short click or double click. It doesn't seem to have anything to do with leds, because this kind of problem can happen if I submit power down event in click long event.

  • My project is based on sample/caf : https://github.com/nrfconnect/sdk-nrf/tree/v1.8.0/samples/caf

    It will also appear on 52840 DK. I add click event in sample/caf, this is the modified led_state.c file and prj.conf. You can replace them in sample/caf.

    #include <zephyr.h>
    
    #define MODULE led_state
    #include <caf/events/module_state_event.h>
    #include <caf/events/led_event.h>
    #include <caf/events/button_event.h>
    #include <caf/events/click_event.h>
    #include <caf/events/power_event.h>
    
    #include <logging/log.h>
    LOG_MODULE_REGISTER(MODULE, CONFIG_CAF_SAMPLE_LED_STATE_LOG_LEVEL);
    
    #include "led_state_def.h"
    
    
    enum button_id {
    	BUTTON_ID_NEXT_EFFECT,
    	BUTTON_ID_NEXT_LED,
    
    	BUTTON_ID_COUNT
    };
    
    static enum led_effect_id curr_led_effect_id[LED_ID_COUNT];
    static enum led_id curr_led_id;
    
    
    static void send_led_event(enum led_id led_id, const struct led_effect *led_effect)
    {
    	__ASSERT_NO_MSG(led_effect);
    	__ASSERT_NO_MSG(led_id < LED_ID_COUNT);
    
    	struct led_event *event = new_led_event();
    
    	event->led_id = led_id;
    	event->led_effect = led_effect;
    	EVENT_SUBMIT(event);
    }
    
    static bool handle_click_event(const struct click_event *evt) {
        if (evt->key_id == 0) {
            if (evt->click == CLICK_LONG) {
                struct power_down_event *event = new_power_down_event();
    
                event->error = false;
                EVENT_SUBMIT(event);
            } else if (evt->click == CLICK_SHORT) {
                struct power_down_event *event = new_power_down_event();
    
                event->error = false;
                EVENT_SUBMIT(event);
            }
        }
    
        return false;
    }
    
    static bool event_handler(const struct event_header *eh)
    {
        if (is_click_event(eh)) {
            return handle_click_event(cast_click_event(eh));
        }
    
    	if (is_module_state_event(eh)) {
    		const struct module_state_event *event = cast_module_state_event(eh);
    
    		if (check_state(event, MODULE_ID(leds), MODULE_STATE_READY)) {
    			/* Turn on the first LED */
    			send_led_event(LED_ID_0, &led_effect_on);
    		}
    
    		return false;
    	}
    
    	/* Event not handled but subscribed. */
    	__ASSERT_NO_MSG(false);
    
    	return false;
    }
    
    EVENT_LISTENER(MODULE, event_handler);
    EVENT_SUBSCRIBE(MODULE, module_state_event);
    EVENT_SUBSCRIBE(MODULE, click_event);

    # Dependencies for EVENT_MANAGER and CAF
    CONFIG_LINKER_ORPHAN_SECTION_PLACE=y
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    # Enable CAF_BUTTONS
    CONFIG_CAF=y
    CONFIG_CAF_BUTTONS=y
    CONFIG_CAF_BUTTONS_POLARITY_INVERSED=y
    
    # Dependencies for CAF_LEDS
    CONFIG_LED=y
    CONFIG_PWM=y
    CONFIG_LED_PWM=y
    
    # Enable CAF_LEDS
    CONFIG_CAF_LEDS=y
    CONFIG_CAF_LEDS_PWM=y
    
    CONFIG_CAF_CLICK_DETECTOR=y
    CONFIG_CAF_PM_EVENTS=y
    
    # Enable logging
    CONFIG_LOG=y
    # Increase number of internal logging buffers
    CONFIG_LOG_STRDUP_BUF_COUNT=32
    
    # Application specific options
    CONFIG_CAF_SAMPLE_LED_STATE=y

  • These are log information of short click and long click respectively.

Related