ban4jp -
/
BTstack_test
https://mbed.org/forum/ja/topic/4890/
Fork of BTstack by
led_counter.cpp@0:1ed23ab1345f, 2012-06-26 (annotated)
- Committer:
- va009039
- Date:
- Tue Jun 26 14:27:45 2012 +0000
- Revision:
- 0:1ed23ab1345f
fix overflow spp_service_buffer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:1ed23ab1345f | 1 | #if 0 |
va009039 | 0:1ed23ab1345f | 2 | //***************************************************************************** |
va009039 | 0:1ed23ab1345f | 3 | // |
va009039 | 0:1ed23ab1345f | 4 | // led_counter demo - uses the BTstack run loop to blink an LED |
va009039 | 0:1ed23ab1345f | 5 | // |
va009039 | 0:1ed23ab1345f | 6 | //***************************************************************************** |
va009039 | 0:1ed23ab1345f | 7 | #include "mbed.h" |
va009039 | 0:1ed23ab1345f | 8 | #include <btstack/run_loop.h> |
va009039 | 0:1ed23ab1345f | 9 | |
va009039 | 0:1ed23ab1345f | 10 | Serial pc(USBTX, USBRX); |
va009039 | 0:1ed23ab1345f | 11 | DigitalOut led1(LED1), led2(LED2); |
va009039 | 0:1ed23ab1345f | 12 | |
va009039 | 0:1ed23ab1345f | 13 | #define HEARTBEAT_PERIOD_MS 1000 |
va009039 | 0:1ed23ab1345f | 14 | |
va009039 | 0:1ed23ab1345f | 15 | static void heartbeat_handler(struct timer *ts){ |
va009039 | 0:1ed23ab1345f | 16 | |
va009039 | 0:1ed23ab1345f | 17 | // increment counter |
va009039 | 0:1ed23ab1345f | 18 | static int counter = 0; |
va009039 | 0:1ed23ab1345f | 19 | char lineBuffer[30]; |
va009039 | 0:1ed23ab1345f | 20 | sprintf(lineBuffer, "BTstack counter %04u\n\r", ++counter); |
va009039 | 0:1ed23ab1345f | 21 | printf(lineBuffer); |
va009039 | 0:1ed23ab1345f | 22 | |
va009039 | 0:1ed23ab1345f | 23 | // toggle LED |
va009039 | 0:1ed23ab1345f | 24 | led2 = !led2; |
va009039 | 0:1ed23ab1345f | 25 | |
va009039 | 0:1ed23ab1345f | 26 | run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS); |
va009039 | 0:1ed23ab1345f | 27 | run_loop_add_timer(ts); |
va009039 | 0:1ed23ab1345f | 28 | } |
va009039 | 0:1ed23ab1345f | 29 | |
va009039 | 0:1ed23ab1345f | 30 | // main |
va009039 | 0:1ed23ab1345f | 31 | int main(void) |
va009039 | 0:1ed23ab1345f | 32 | { |
va009039 | 0:1ed23ab1345f | 33 | pc.baud(921600); |
va009039 | 0:1ed23ab1345f | 34 | printf("%s\n", __FILE__); |
va009039 | 0:1ed23ab1345f | 35 | |
va009039 | 0:1ed23ab1345f | 36 | // init LEDs |
va009039 | 0:1ed23ab1345f | 37 | led1 = led2 = 1; |
va009039 | 0:1ed23ab1345f | 38 | |
va009039 | 0:1ed23ab1345f | 39 | /// GET STARTED with BTstack /// |
va009039 | 0:1ed23ab1345f | 40 | run_loop_init(RUN_LOOP_EMBEDDED); |
va009039 | 0:1ed23ab1345f | 41 | |
va009039 | 0:1ed23ab1345f | 42 | // set one-shot timer |
va009039 | 0:1ed23ab1345f | 43 | timer_source_t heartbeat; |
va009039 | 0:1ed23ab1345f | 44 | heartbeat.process = &heartbeat_handler; |
va009039 | 0:1ed23ab1345f | 45 | run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS); |
va009039 | 0:1ed23ab1345f | 46 | run_loop_add_timer(&heartbeat); |
va009039 | 0:1ed23ab1345f | 47 | |
va009039 | 0:1ed23ab1345f | 48 | printf("Run...\n\r"); |
va009039 | 0:1ed23ab1345f | 49 | |
va009039 | 0:1ed23ab1345f | 50 | // go! |
va009039 | 0:1ed23ab1345f | 51 | run_loop_execute(); |
va009039 | 0:1ed23ab1345f | 52 | |
va009039 | 0:1ed23ab1345f | 53 | // happy compiler! |
va009039 | 0:1ed23ab1345f | 54 | return 0; |
va009039 | 0:1ed23ab1345f | 55 | } |
va009039 | 0:1ed23ab1345f | 56 | #endif |