Call function with parameter by Timer API

On RUI3 Timer API, How do I call function by Timer API with an Integer value as a parameter?

I am using parameters in my RUI3-Signal-Meter-P2P-LPWAN

Start timer with parameter:

	display_reason = 1;
	api.system.timer.start(RAK_TIMER_1, 250, &display_reason);

Timer callback with parameter usage:

void handle_display(void *reason)
{
	// Get the wakeup reason
	uint8_t *disp_reason = (uint8_t *)reason;

	// Check if we have a reason
	if (disp_reason == NULL)
	{
		Serial.println("Bug in code!");
	}
	else if (disp_reason[0] == 1)
	{
		// RX event display
	}
	else if (disp_reason[0] == 2)
	{
	}
	else if (disp_reason[0] == 3)
	{
	}
	else if (disp_reason[0] == 5)
	{
	}
}

Thank you for your support.

I can start Timer API with parameter as you show me, but I wonder if it posible to start Timer API with a local variable as parameter? If yes, how can I do that?
I’ve try with this code, but it not work.

// uint8_t testValue = 1;

void testing(void *ch){
    uint8_t *channel = (uint8_t*)ch;
    if (channel[0] == NULL)
    {   
        Serial.println("Testing");
    } else {
        Serial.printf("Testing with parameter: %d\r\n", channel[0]);
    } 
}

void setup()
{
    Serial.begin(115200);
    Serial.println("Starting...");
    api.system.timer.create(RAK_TIMER_0,(RAK_TIMER_HANDLER)testing, RAK_TIMER_PERIODIC);
    uint8_t testValue = 1;
    testing(&testValue);
    api.system.timer.start(RAK_TIMER_0, 1000, &testValue);
}

void loop()
{
    api.system.sleep.all();
}

No it is not possible.
As you can see the parameter is given as a pointer to the parameter.
If you define the parameter local, it will be on the stack and destroyed when the function returns.

Many thanks for the clear explanation.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.