2015-04-17 09:53:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 BlueKitchen GmbH
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the copyright holders nor the names of
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* 4. Any redistribution, use, or modification is done solely for
|
|
|
|
* personal benefit and not for any commercial purpose or for
|
|
|
|
* monetary gain.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
2021-11-02 08:31:00 +00:00
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
|
|
|
|
* GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
2015-04-17 09:53:41 +00:00
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Please inquire about commercial licensing options at
|
|
|
|
* contact@bluekitchen-gmbh.com
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-05-11 17:31:55 +00:00
|
|
|
#define BTSTACK_FILE__ "led_counter.c"
|
2017-03-24 22:39:20 +00:00
|
|
|
|
2014-11-15 23:07:12 +00:00
|
|
|
// *****************************************************************************
|
2020-10-23 07:54:54 +00:00
|
|
|
/* EXAMPLE_START(led_counter): Hello World - Blinking an LED without Bluetooth
|
2015-04-19 20:39:48 +00:00
|
|
|
*
|
2015-04-24 20:44:13 +00:00
|
|
|
* @text The example demonstrates how to provide a periodic timer to toggle an
|
|
|
|
* LED and send debug messages to the console as a minimal BTstack test.
|
2015-04-19 20:39:48 +00:00
|
|
|
*/
|
2014-11-15 23:07:12 +00:00
|
|
|
// *****************************************************************************
|
|
|
|
|
2015-04-19 20:39:48 +00:00
|
|
|
|
|
|
|
|
2014-11-15 23:07:12 +00:00
|
|
|
#include <stdio.h>
|
2023-09-07 08:18:43 +00:00
|
|
|
#include "btstack.h"
|
2015-10-15 14:33:34 +00:00
|
|
|
#include "hal_led.h"
|
2014-11-15 23:07:12 +00:00
|
|
|
|
|
|
|
#define HEARTBEAT_PERIOD_MS 1000
|
|
|
|
|
|
|
|
static int counter = 0;
|
2016-01-20 15:00:45 +00:00
|
|
|
static btstack_timer_source_t heartbeat;
|
2014-11-15 23:07:12 +00:00
|
|
|
|
2015-04-19 20:39:48 +00:00
|
|
|
/* @section Periodic Timer Setup
|
|
|
|
*
|
|
|
|
* @text As timers in BTstack are single shot,
|
|
|
|
* the periodic counter is implemented by re-registering the timer source in the
|
|
|
|
* heartbeat handler callback function. Listing LEDToggler shows heartbeat handler
|
|
|
|
* adapted to periodically toggle an LED and print number of toggles.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* LISTING_START(LEDToggler): Periodic counter */
|
2016-12-22 21:16:16 +00:00
|
|
|
static void heartbeat_handler(btstack_timer_source_t *ts){
|
|
|
|
UNUSED(ts);
|
|
|
|
|
2014-11-15 23:07:12 +00:00
|
|
|
// increment counter
|
2023-09-07 08:18:43 +00:00
|
|
|
counter++;
|
|
|
|
|
|
|
|
// print and log
|
|
|
|
log_info("BTstack Counter %u", counter);
|
|
|
|
printf("BTstack counter %04u\n\r", counter);
|
|
|
|
|
2014-11-15 23:07:12 +00:00
|
|
|
// toggle LED
|
2015-04-19 20:15:25 +00:00
|
|
|
hal_led_toggle();
|
2014-11-15 23:07:12 +00:00
|
|
|
|
|
|
|
// re-register timer
|
2016-01-20 14:58:46 +00:00
|
|
|
btstack_run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
|
|
|
|
btstack_run_loop_add_timer(&heartbeat);
|
2014-11-15 23:07:12 +00:00
|
|
|
}
|
2015-04-19 20:39:48 +00:00
|
|
|
/* LISTING_END */
|
2014-11-15 23:07:12 +00:00
|
|
|
|
2015-04-26 22:02:07 +00:00
|
|
|
/* @section Main Application Setup
|
2015-04-19 20:39:48 +00:00
|
|
|
*
|
|
|
|
* @text Listing MainConfiguration shows main application code.
|
2015-04-24 20:44:13 +00:00
|
|
|
* It configures the heartbeat tier and adds it to the run loop.
|
2015-04-25 20:12:40 +00:00
|
|
|
*/
|
|
|
|
|
2015-04-19 20:39:48 +00:00
|
|
|
/* LISTING_START(MainConfiguration): Setup heartbeat timer */
|
2014-11-15 23:07:12 +00:00
|
|
|
int btstack_main(int argc, const char * argv[]);
|
|
|
|
int btstack_main(int argc, const char * argv[]){
|
2016-12-22 21:16:16 +00:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
2015-04-23 21:21:56 +00:00
|
|
|
|
2015-04-19 20:39:48 +00:00
|
|
|
// set one-shot timer
|
|
|
|
heartbeat.process = &heartbeat_handler;
|
2016-01-20 14:58:46 +00:00
|
|
|
btstack_run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS);
|
|
|
|
btstack_run_loop_add_timer(&heartbeat);
|
2015-04-23 21:21:56 +00:00
|
|
|
|
|
|
|
printf("Running...\n\r");
|
2014-11-15 23:07:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-04-19 20:39:48 +00:00
|
|
|
/* LISTING_END */
|
2018-07-05 20:19:19 +00:00
|
|
|
/* EXAMPLE_END */
|