Wirepas SDK
blink/app.c
/* Copyright 2017 Wirepas Ltd. All Rights Reserved.
*
* See file LICENSE.txt for full license details.
*
*/
/*
* \file app.c
* \brief A simple LED blink application
*/
#include <stdlib.h> // For NULL
#include "api.h"
#include "led.h"
#include "button.h"
#include "app_scheduler.h"
#define CALLBACK_PERIOD_S 1
#define CALLBACK_PERIOD_MS (CALLBACK_PERIOD_S * 1000)
#define EXECUTION_TIME_US 100
static uint32_t blink_holdoff;
static uint32_t blink_func(void)
{
static uint32_t counter = 0;
if (blink_holdoff > 0)
{
blink_holdoff--;
}
else
{
// Toggle all LEDs
uint32_t bits = counter;
uint_fast8_t num_leds = Led_getNumber();
for (uint_fast8_t led_id = 0; led_id < num_leds; led_id++)
{
Led_set(led_id, bits & 1);
bits >>= 1;
}
counter++;
}
return CALLBACK_PERIOD_MS;
}
static void button_press_func(uint8_t button_id, button_event_e event)
{
(void) event;
// Stop LED blinking for five seconds
blink_holdoff = 5;
// Turn LED on
Led_set(button_id, true);
}
static void button_release_func(uint8_t button_id, button_event_e event)
{
(void) event;
// Stop LED blinking for five seconds
blink_holdoff = 5;
// Turn LED off
Led_set(button_id, false);
}
void App_init(const app_global_functions_t * functions)
{
// Basic configuration of the node with a unique node address
{
// Could not configure the node
// It should not happen except if one of the config value is invalid
return;
}
// Set up LEDs
// Set up buttons
uint_fast8_t num_buttons = Button_get_number();
for (uint_fast8_t button_id = 0; button_id < num_buttons; button_id++)
{
button_press_func);
button_release_func);
}
// Set the blink callback to be called
// immediately after the stack is started
blink_holdoff = 0;
EXECUTION_TIME_US);
// Start the stack
lib_state->startStack();
}
Led_set
led_res_e Led_set(uint8_t led_id, bool state)
Turn the given LED on or off.
button.h
Board-independent button functions.
node_configuration.h
App_Scheduler_addTask_execTime
app_scheduler_res_e App_Scheduler_addTask_execTime(task_cb_f cb, uint32_t delay_ms, uint32_t exec_time_us)
Add a task.
APP_RES_OK
@ APP_RES_OK
Definition: wms_app.h:204
BUTTON_RELEASED
@ BUTTON_RELEASED
Definition: button.h:19
app_scheduler.h
app_global_functions_t
List of global functions, passed to App_entrypoint()
Definition: wms_app.h:157
Button_register_for_event
button_res_e Button_register_for_event(uint8_t button_id, button_event_e event, on_button_event_cb cb)
Register for a button event.
led.h
Board-independent LED functions.
configureNodeFromBuildParameters
__STATIC_INLINE app_res_e configureNodeFromBuildParameters()
Wrapper on top of configureNode to get parameters from build system and hardcoded values from chip (f...
Definition: node_configuration.h:233
Led_init
void Led_init(void)
Initialize Led module.
Led_getNumber
uint8_t Led_getNumber(void)
Get number of leds available.
Button_init
void Button_init(void)
Initialize Button module.
BUTTON_PRESSED
@ BUTTON_PRESSED
Definition: button.h:18
Button_get_number
uint8_t Button_get_number(void)
Get number of buttons.
APP_SCHEDULER_SCHEDULE_ASAP
#define APP_SCHEDULER_SCHEDULE_ASAP
Value to return from task or as initial time to be executed ASAP.
Definition: app_scheduler.h:42
api.h
button_event_e
button_event_e
Different events for a button.
Definition: button.h:17