Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Scheduler advanced example | ||
|
||
This example explains how to use scheduler to handle more tasks | ||
The application_task() Task is created automatically by SDK. | ||
If you need more tasks then call the bc_scheduler_register() | ||
|
||
This example demonstrates scheduling the task to blink a LED. The right and more | ||
efficient way would be use just the bc_led_set_mode(&led, BC_LED_MODE_BLINK) function | ||
to set the blinking speed and the toggling will be handled in the background. | ||
|
||
For more information please see http://sdk.bigclown.com/group__bc__scheduler.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
This example explains how to use scheduler to handle more tasks | ||
*/ | ||
|
||
#include <application.h> | ||
|
||
// LED instance | ||
bc_led_t led; | ||
|
||
// To control the tasks we need to save task IDs | ||
bc_scheduler_task_id_t id_task_turn_on; | ||
bc_scheduler_task_id_t id_task_turn_off; | ||
|
||
void task_turn_on(void *param) | ||
{ | ||
// Convert param from void* type to bc_led_t | ||
bc_led_t *param_led = (bc_led_t*)param; | ||
bc_led_set_mode(param_led, BC_LED_MODE_ON); | ||
// Schedule the start of the LED turn off task in 500 ms | ||
bc_scheduler_plan_relative(id_task_turn_off, 500); | ||
} | ||
|
||
void task_turn_off(void *param) | ||
{ | ||
bc_led_t *param_led = (bc_led_t*)param; | ||
bc_led_set_mode(param_led, BC_LED_MODE_OFF); | ||
} | ||
|
||
// Setup the LED and register two tasks | ||
void application_init(void) | ||
{ | ||
bc_led_init(&led, BC_GPIO_LED, false, false); | ||
|
||
// Register two tasks | ||
// We pass the &led pointer as a parameter to the task functions | ||
// Also register function returns the task ID which we use later. | ||
// BC_TICK_INFINITY means that the task is not run automatically | ||
id_task_turn_on = bc_scheduler_register(task_turn_on, &led, BC_TICK_INFINITY); | ||
id_task_turn_off = bc_scheduler_register(task_turn_off, &led, BC_TICK_INFINITY); | ||
} | ||
|
||
void application_task(void) | ||
{ | ||
// Start the task to turn LED on | ||
bc_scheduler_plan_now(id_task_turn_on); | ||
// Schedule calling this function again in 1000 ms | ||
bc_scheduler_plan_current_relative(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef _APPLICATION_H | ||
#define _APPLICATION_H | ||
|
||
#include <bcl.h> | ||
|
||
#endif // _APPLICATION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Scheduler basic example | ||
|
||
This example explains how the sheduler plans the tasks. | ||
The application_task() Task is created automatically by SDK. | ||
If you need more tasks then call the bc_scheduler_register() | ||
|
||
This example demonstrates scheduling the task to blink a LED. The right and more | ||
efficient way would be use just the bc_led_set_mode(&led, BC_LED_MODE_BLINK) function | ||
to set the blinking speed and the toggling will be handled in the background. | ||
|
||
For more information please see http://sdk.bigclown.com/group__bc__scheduler.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
This example explains how the sheduler plans the tasks. | ||
The application_task() Task is created automatically by SDK. | ||
If you need more tasks then call the bc_scheduler_register() | ||
This example demonstrates scheduling the task to blink a LED. The right and more | ||
efficient way would be use just the bc_led_set_mode(&led, BC_LED_MODE_BLINK) function | ||
to set the blinking speed and the toggling will be handled in the background. | ||
For more information please see http://sdk.bigclown.com/group__bc__scheduler.html | ||
*/ | ||
|
||
#include <application.h> | ||
|
||
// LED instance | ||
bc_led_t led; | ||
|
||
// Setup the LED | ||
void application_init(void) | ||
{ | ||
bc_led_init(&led, BC_GPIO_LED, false, false); | ||
} | ||
|
||
// application_task() is like the Arduino loop() but more power efficient. | ||
// At the end of the function you have to specify when | ||
// the function will be called next. Otherwise it won't be called again. | ||
void application_task(void) | ||
{ | ||
bc_led_set_mode(&led, BC_LED_MODE_TOGGLE); | ||
|
||
// Shedule this function to be called 500 ms later | ||
// during the 500 ms the MCU will sleep and conserve power | ||
bc_scheduler_plan_current_relative(500); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef _APPLICATION_H | ||
#define _APPLICATION_H | ||
|
||
#include <bcl.h> | ||
|
||
#endif // _APPLICATION_H |