Skip to content

Commit 6098414

Browse files
committed
Add LED blink by 'Alert Level' characteristic value
1 parent 90b258c commit 6098414

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

zzz_temporary-ble-build-out/nus_api.h

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424

2525
#include "wsf_os.h"
2626

27+
extern void debug_print(const char* f, const char* F, uint16_t L);
28+
extern void debug_printf(char* fmt, ...);
29+
extern void set_led_high( void );
30+
extern void set_led_low( void );
31+
2732
#ifdef __cplusplus
2833
extern "C" {
2934
#endif

zzz_temporary-ble-build-out/nus_main.c

+61
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* to any use, copying or further distribution of this software.
2323
*/
2424
/*************************************************************************************************/
25+
#define DEBUG
26+
2527

2628
#include <string.h>
2729
#include "wsf_types.h"
@@ -278,17 +280,24 @@ static const attsCccSet_t tagCccSet[TAG_NUM_CCC_IDX] =
278280
/*************************************************************************************************/
279281
static void tagAlert(uint8_t alert)
280282
{
283+
#ifdef DEBUG
284+
debug_print(__func__, __FILE__, __LINE__);
285+
debug_printf("alert: 0x%02X\n", alert);
286+
#endif
281287
/* perform alert according to setting of alert alert */
282288
if (alert == CH_ALERT_LVL_NONE)
283289
{
290+
set_led_low();
284291
AppUiAction(APP_UI_ALERT_CANCEL);
285292
}
286293
else if (alert == CH_ALERT_LVL_MILD)
287294
{
295+
set_led_high();
288296
AppUiAction(APP_UI_ALERT_LOW);
289297
}
290298
else if (alert == CH_ALERT_LVL_HIGH)
291299
{
300+
set_led_high();
292301
AppUiAction(APP_UI_ALERT_HIGH);
293302
}
294303
}
@@ -308,6 +317,9 @@ static void tagSetup(dmEvt_t *pMsg);
308317
/*************************************************************************************************/
309318
static void tagDmCback(dmEvt_t *pDmEvt)
310319
{
320+
#ifdef DEBUG
321+
debug_print(__func__, __FILE__, __LINE__);
322+
#endif
311323
dmEvt_t *pMsg;
312324
uint16_t len;
313325

@@ -341,6 +353,9 @@ static void tagDmCback(dmEvt_t *pDmEvt)
341353
/*************************************************************************************************/
342354
static void tagAttCback(attEvt_t *pEvt)
343355
{
356+
#ifdef DEBUG
357+
debug_print(__func__, __FILE__, __LINE__);
358+
#endif
344359
attEvt_t *pMsg;
345360

346361
if ((pMsg = WsfMsgAlloc(sizeof(attEvt_t) + pEvt->valueLen)) != NULL)
@@ -367,6 +382,9 @@ static void tagAttCback(attEvt_t *pEvt)
367382
/*************************************************************************************************/
368383
static void tagCccCback(attsCccEvt_t *pEvt)
369384
{
385+
#ifdef DEBUG
386+
debug_print(__func__, __FILE__, __LINE__);
387+
#endif
370388
attsCccEvt_t *pMsg;
371389
appDbHdl_t dbHdl;
372390

@@ -398,6 +416,9 @@ static uint8_t tagIasWriteCback(dmConnId_t connId, uint16_t handle, uint8_t oper
398416
uint16_t offset, uint16_t len, uint8_t *pValue,
399417
attsAttr_t *pAttr)
400418
{
419+
#ifdef DEBUG
420+
debug_print(__func__, __FILE__, __LINE__);
421+
#endif
401422
ATT_TRACE_INFO3("tagIasWriteCback connId:%d handle:0x%04x op:0x%02x",
402423
connId, handle, operation);
403424
ATT_TRACE_INFO2(" offset:0x%04x len:0x%04x", offset, len);
@@ -420,6 +441,9 @@ static uint8_t tagIasWriteCback(dmConnId_t connId, uint16_t handle, uint8_t oper
420441
/*************************************************************************************************/
421442
static void tagOpen(dmEvt_t *pMsg)
422443
{
444+
#ifdef DEBUG
445+
debug_print(__func__, __FILE__, __LINE__);
446+
#endif
423447
/* Update peer address info */
424448
tagCb.addrType = pMsg->connOpen.addrType;
425449
BdaCpy(tagCb.peerAddr, pMsg->connOpen.peerAddr);
@@ -438,6 +462,9 @@ static void tagOpen(dmEvt_t *pMsg)
438462
/*************************************************************************************************/
439463
static void tagClose(dmEvt_t *pMsg)
440464
{
465+
#ifdef DEBUG
466+
debug_print(__func__, __FILE__, __LINE__);
467+
#endif
441468
uint8_t *pVal;
442469
uint16_t len;
443470

@@ -473,6 +500,9 @@ static void tagClose(dmEvt_t *pMsg)
473500
/*************************************************************************************************/
474501
static void tagSecPairCmpl(dmEvt_t *pMsg)
475502
{
503+
#ifdef DEBUG
504+
debug_print(__func__, __FILE__, __LINE__);
505+
#endif
476506
appConnCb_t *pCb;
477507
dmSecKey_t *pPeerKey;
478508

@@ -506,6 +536,9 @@ static void tagSecPairCmpl(dmEvt_t *pMsg)
506536
/*************************************************************************************************/
507537
static void tagSetup(dmEvt_t *pMsg)
508538
{
539+
#ifdef DEBUG
540+
debug_print(__func__, __FILE__, __LINE__);
541+
#endif
509542
/* set advertising and scan response data for discoverable mode */
510543
AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(tagAdvDataDisc), (uint8_t *) tagAdvDataDisc);
511544
AppAdvSetData(APP_SCAN_DATA_DISCOVERABLE, sizeof(tagScanData), (uint8_t *) tagScanData);
@@ -531,6 +564,9 @@ static void tagSetup(dmEvt_t *pMsg)
531564
/*************************************************************************************************/
532565
static void tagValueUpdate(attEvt_t *pMsg)
533566
{
567+
#ifdef DEBUG
568+
debug_print(__func__, __FILE__, __LINE__);
569+
#endif
534570
if (pMsg->hdr.status == ATT_SUCCESS)
535571
{
536572
// todo: add debugging statement here to see what's happening!
@@ -564,6 +600,9 @@ static void tagValueUpdate(attEvt_t *pMsg)
564600
/*************************************************************************************************/
565601
static void tagDiscGapCmpl(dmConnId_t connId)
566602
{
603+
#ifdef DEBUG
604+
debug_print(__func__, __FILE__, __LINE__);
605+
#endif
567606
appDbHdl_t dbHdl;
568607

569608
/* if RPA Only attribute found on peer device */
@@ -588,6 +627,9 @@ static void tagDiscGapCmpl(dmConnId_t connId)
588627
/*************************************************************************************************/
589628
static void tagProcRssiTimer(dmEvt_t *pMsg)
590629
{
630+
#ifdef DEBUG
631+
debug_print(__func__, __FILE__, __LINE__);
632+
#endif
591633
dmConnId_t connId;
592634

593635
/* if still connected */
@@ -614,6 +656,9 @@ static void tagProcRssiTimer(dmEvt_t *pMsg)
614656
/*************************************************************************************************/
615657
static void tagBtnCback(uint8_t btn)
616658
{
659+
#ifdef DEBUG
660+
debug_print(__func__, __FILE__, __LINE__);
661+
#endif
617662
dmConnId_t connId;
618663

619664
/* button actions when connected */
@@ -763,6 +808,9 @@ static void tagBtnCback(uint8_t btn)
763808
/*************************************************************************************************/
764809
static void tagDiscCback(dmConnId_t connId, uint8_t status)
765810
{
811+
#ifdef DEBUG
812+
debug_print(__func__, __FILE__, __LINE__);
813+
#endif
766814
switch(status)
767815
{
768816
case APP_DISC_INIT:
@@ -856,6 +904,10 @@ static void tagDiscCback(dmConnId_t connId, uint8_t status)
856904
/*************************************************************************************************/
857905
static void tagProcMsg(dmEvt_t *pMsg)
858906
{
907+
#ifdef DEBUG
908+
debug_print(__func__, __FILE__, __LINE__);
909+
debug_printf("pMsg->hdr.event: 0x%04X\n", (uint32_t)pMsg->hdr.event);
910+
#endif
859911
uint8_t uiEvent = APP_UI_NONE;
860912

861913
switch(pMsg->hdr.event)
@@ -987,6 +1039,9 @@ static void tagProcMsg(dmEvt_t *pMsg)
9871039
/*************************************************************************************************/
9881040
void NusHandlerInit(wsfHandlerId_t handlerId)
9891041
{
1042+
#ifdef DEBUG
1043+
debug_print(__func__, __FILE__, __LINE__);
1044+
#endif
9901045
APP_TRACE_INFO0("NusHandlerInit");
9911046

9921047
/* store handler ID */
@@ -1030,6 +1085,9 @@ void NusHandlerInit(wsfHandlerId_t handlerId)
10301085
/*************************************************************************************************/
10311086
void NusHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
10321087
{
1088+
#ifdef DEBUG
1089+
debug_print(__func__, __FILE__, __LINE__);
1090+
#endif
10331091
if (pMsg != NULL)
10341092
{
10351093
APP_TRACE_INFO1("Tag got evt %d", pMsg->event);
@@ -1069,6 +1127,9 @@ void NusHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
10691127
/*************************************************************************************************/
10701128
void NusStart(void)
10711129
{
1130+
#ifdef DEBUG
1131+
debug_print(__func__, __FILE__, __LINE__);
1132+
#endif
10721133
/* Register for stack callbacks */
10731134
DmRegister(tagDmCback);
10741135
DmConnRegister(DM_CLIENT_ID_APP, tagDmCback);

zzz_temporary-ble-build-out/zzz_temporary-ble-build-out.ino

+50
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,45 @@ extern "C"
3636
}
3737
#endif
3838

39+
#define DEBUG
40+
#define SERIAL_PORT Serial
41+
#define DEBUG_UART_BUF_LEN 256
42+
43+
// ****************************************
44+
//
45+
// Debug print functions
46+
//
47+
// ****************************************
48+
extern "C" void debug_print(const char* f, const char* F, uint16_t L){
49+
SERIAL_PORT.printf("fm: %s, file: %s, line: %d\n", f, F, L);
50+
}
51+
52+
extern "C" void debug_printf(char* fmt, ...){
53+
#ifdef DEBUG
54+
char debug_buffer [DEBUG_UART_BUF_LEN];
55+
va_list args;
56+
va_start (args, fmt);
57+
vsnprintf(debug_buffer, DEBUG_UART_BUF_LEN, (const char*)fmt, args);
58+
va_end (args);
59+
60+
SERIAL_PORT.print(debug_buffer);
61+
#endif //DEBUG
62+
}
63+
64+
65+
// ****************************************
66+
//
67+
// C-callable led functions
68+
//
69+
// ****************************************
70+
extern void set_led_high( void ){
71+
digitalWrite(LED_BUILTIN, HIGH);
72+
}
73+
74+
extern void set_led_low( void ){
75+
digitalWrite(LED_BUILTIN, LOW);
76+
}
77+
3978
//*****************************************************************************
4079
//
4180
// Forward declarations.
@@ -405,6 +444,15 @@ extern "C" void am_ble_isr(void){
405444
void setup() {
406445
// put your setup code here, to run once:
407446

447+
#ifdef DEBUG
448+
SERIAL_PORT.begin(115200);
449+
delay(1000);
450+
SERIAL_PORT.printf("Apollo3 Arduino BLE Example. Compiled: %s\n", __TIME__);
451+
#endif
452+
453+
pinMode(LED_BUILTIN, OUTPUT);
454+
set_led_low();
455+
408456
//
409457
// Boot the radio.
410458
//
@@ -422,6 +470,8 @@ void setup() {
422470

423471
while (TRUE)
424472
{
473+
// debug_print(__func__, __FILE__, __LINE__);
474+
425475
//
426476
// Calculate the elapsed time from our free-running timer, and update
427477
// the software timers in the WSF scheduler.

0 commit comments

Comments
 (0)