Nordic library control of switch inputs (buttons)

We have project using the common Matter Code base from SDK 1.6.1 and using a variation of the code to act as a switch sensor device time. This seems to work pretty well; however we notice that between the button states of closed and not closed.
With the provided code snippet:

void AppTask::ButtonEventHandler(Nrf::ButtonState state, Nrf::ButtonMask hasChanged)
{
	if ((APPLICATION_BUTTON_MASK & state & hasChanged)) {
		// button is signaling true
		Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Set(false); 
		app::Clusters::BooleanState::Attributes::StateValue::Set(1, false);
		// Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Set(true); 
		// app::Clusters::BooleanState::Attributes::StateValue::Set(1, true);
	} else if ((APPLICATION_BUTTON_MASK & hasChanged)) {
		// button is signaling false
		Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Set(true); 
		app::Clusters::BooleanState::Attributes::StateValue::Set(1, true);
		// Nrf::GetBoard().GetLED(Nrf::DeviceLeds::LED2).Set(false); 
		// app::Clusters::BooleanState::Attributes::StateValue::Set(1, false);
	}
}

We get the open and close state, however the one state seems to continuously transmit 

I was looking at the following in dk_buttons_and_leds.c and in the function dk_buttons_init(): I see the comment:

            /* Module starts in scanning mode and will switch to
             * callback mode if no button is pressed.
             */
Does this imply anything about the operation of the button scanning? Will holding a button (closing a switch) cause the unit to stay in active mode but releasing the button allows it to fall back to inactive (low power?) mode?


PS Still not 'Matter' Tag I can select before posting?

Parents
  • Hi,

    Just added "Matter" tag to this case.

    however the one state seems to continuously transmit 

    Did you add printout in ButtonEventHandler to see this really happens?

    Does this imply anything about the operation of the button scanning?

    After reading the source codes, I feel it is not related to button scanning. The comments claim "Module starts in scanning mode and will switch to callback mode if no button is pressed.", but the callback will reschedule

    buttons_scan task to check and forward has_changed and button_sacn value to ButtonEventHandler handler. ButtonEventHandler only get update when button state has_changed.

    Will holding a button (closing a switch) cause the unit to stay in active mode but releasing the button allows it to fall back to inactive (low power?) mode?

    You can easily test it on your device. The mode change will only happen when have a action(either relase or press button). When you keep releasing or pressing one button after power reset, you even do not know the actual state since ButtonEventHandler will not be trigger before you have an action, but you can read GPIO to set initial active/inactive mode.

    Best regards,

    Charlie

Reply
  • Hi,

    Just added "Matter" tag to this case.

    however the one state seems to continuously transmit 

    Did you add printout in ButtonEventHandler to see this really happens?

    Does this imply anything about the operation of the button scanning?

    After reading the source codes, I feel it is not related to button scanning. The comments claim "Module starts in scanning mode and will switch to callback mode if no button is pressed.", but the callback will reschedule

    buttons_scan task to check and forward has_changed and button_sacn value to ButtonEventHandler handler. ButtonEventHandler only get update when button state has_changed.

    Will holding a button (closing a switch) cause the unit to stay in active mode but releasing the button allows it to fall back to inactive (low power?) mode?

    You can easily test it on your device. The mode change will only happen when have a action(either relase or press button). When you keep releasing or pressing one button after power reset, you even do not know the actual state since ButtonEventHandler will not be trigger before you have an action, but you can read GPIO to set initial active/inactive mode.

    Best regards,

    Charlie

Children
No Data
Related