RUI3 (RAK Unified Interface 3) - RAK4631
timer

Functions

bool create (RAK_TIMER_ID id, RAK_TIMER_HANDLER handler, RAK_TIMER_MODE mode)
 
bool start (RAK_TIMER_ID id, uint32_t ms, void *data)
 
bool stop (RAK_TIMER_ID id)
 

Detailed Description

Function Documentation

◆ create()

bool create ( RAK_TIMER_ID  id,
RAK_TIMER_HANDLER  handler,
RAK_TIMER_MODE  mode 
)
Description
Create a timer.
Syntax
api.system.timer.create(id, handler, mode)
Parameters
idthe timer ID
handlerthe handler function for this timer
modethe mode of this timer
Returns
bool
Return values
TRUEfor creating timer successfully
FALSEfor creating timer failure
Example
     void handler(void *data)
     {
       Serial.printf("[%lu]This is the handler\r\n", millis());
     }
     void setup()
     {
       Serial.begin(115200);

       if (api.system.timer.create(RAK_TIMER_0, (RAK_TIMER_HANDLER)handler, RAK_TIMER_PERIODIC) != true) {
         Serial.printf("Creating timer failed.\r\n");
       } else if (api.system.timer.start(RAK_TIMER_0, 1000, NULL) != true) {
         Serial.printf("Starting timer failed.\r\n");
       }
     }
     void loop()
     {
     }

◆ start()

bool start ( RAK_TIMER_ID  id,
uint32_t  ms,
void *  data 
)
Description
Start a timer.
Syntax
api.system.timer.start(id, ms, data)
Parameters
idthe timer ID
msthe period of timer
datathe data passed to timer handler function
Returns
bool
Return values
TRUEfor starting timer successfully
FALSEfor starting timer failure
Example
     void handler(void *data)
     {
       Serial.printf("[%lu]This is the handler\r\n", millis());
     }
     void setup()
     {
       Serial.begin(115200);

       if (api.system.timer.create(RAK_TIMER_0, (RAK_TIMER_HANDLER)handler, RAK_TIMER_PERIODIC) != true) {
         Serial.printf("Creating timer failed.\r\n");
       } else if (api.system.timer.start(RAK_TIMER_0, 1000, NULL) != true) {
         Serial.printf("Starting timer failed.\r\n");
       }
     }
     void loop()
     {
     }

◆ stop()

bool stop ( RAK_TIMER_ID  id)
Description
Stop a timer.
Syntax
api.system.timer.stop(id)
Parameters
idthe timer ID
Returns
bool
Return values
TRUEfor stoping timer successfully
FALSEfor stoping timer failure
Example
     void handler(void *data)
     {
       Serial.printf("[%lu]This is the handler\r\n", millis());
     }
     void setup()
     {
       Serial.begin(115200);

       if (api.system.timer.create(RAK_TIMER_0, (RAK_TIMER_HANDLER)handler, RAK_TIMER_PERIODIC) != true) {
         Serial.printf("Creating timer failed.\r\n");
       } else if (api.system.timer.start(RAK_TIMER_0, 1000, NULL) != true) {
         Serial.printf("Starting timer failed.\r\n");
       }
     }
     void loop()
     {
       if (millis() > 60000) {
         if (api.system.timer.stop(RAK_TIMER_0) != true) {
           Serial.printf("Stoping timer failed.\r\n");
         }
       }
     }