void entry(void) { int8_t tag_angle; /* set advertisment packet */ radio_advertise(&g_beacon_pkt, sizeof(g_beacon_pkt)); /* run advertisement in background every 995ms */ radio_interval_ms(995); /* infinite foreground loop */ while(TRUE) { /* get tag angle from 3D accelerometer */ acc_magnitude(&tag_angle); /* only tx while beacon is worn (facing forward +/-45 degree) */ radio_enable(abs(tag_angle)<45); /* blink once every three seconds */ timer_wait_ms(3000); pin_set(CONFIG_LED_PIN); timer_wait_ms(1); pin_clear(CONFIG_LED_PIN); } }
void main_entry(void) { uint8_t blink; uint32_t tag_id; /* enabled LED output */ nrf_gpio_cfg_output(CONFIG_LED_PIN); nrf_gpio_pin_set(CONFIG_LED_PIN); /* enabled input pin */ nrf_gpio_cfg_input(CONFIG_SWITCH_PIN, NRF_GPIO_PIN_NOPULL); /* initialize UART */ uart_init(); /* start timer */ timer_init(); /* initialize flash */ if(flash_init()) halt(2); /* initialize accelerometer */ if(acc_init()) halt(3); /* calculate tag ID from NRF_FICR->DEVICEID */ tag_id = crc32(&NRF_FICR->DEVICEID, sizeof(NRF_FICR->DEVICEID)); #ifdef MARKER_TAG tag_id |= MARKER_TAG_BIT; #else /*MARKER_TAG*/ tag_id &= MARKER_TAG_BIT-1; #endif/*MARKER_TAG*/ /* start radio */ debug_printf("\n\rInitializing Tag[%08X] v" PROGRAM_VERSION " @24%02iMHz ...\n\r", tag_id, CONFIG_TRACKER_CHANNEL); radio_init(tag_id); /* enter main loop */ blink = 0; nrf_gpio_pin_clear(CONFIG_LED_PIN); while(TRUE) { /* get tag angle once per second */ acc_magnitude(&g_tag_angle); timer_wait(MILLISECONDS(1000)); /* blink every 5 seconds */ if(blink<5) blink++; else { blink = 0; nrf_gpio_pin_set(CONFIG_LED_PIN); timer_wait(MILLISECONDS(1)); nrf_gpio_pin_clear(CONFIG_LED_PIN); } } }