コード例 #1
0
ファイル: main.cpp プロジェクト: VanshKhanna/android-nrf-mbed
int main(){
    //pc.wait(1);
    gatt_characteristics[CHARACTERISTIC_LED] =
        new GattCharacteristic(
            nRF51_GATT_CHAR_LED,
            &gatt_char_value[CHARACTERISTIC_LED], 1, 1,
            GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ |
            GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE |
            GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);

    gatt_service = new GattService(nRF51_GATT_SERVICE, gatt_characteristics, CHARACTERISTIC_COUNT);
    //Initialize BLE Device
    ble.init();

    ble.setDeviceName((uint8_t *)DEVICE_NAME);

    // configure our advertising type, payload and interval00
    ble.accumulateAdvertisingPayload(
          GapAdvertisingData::BREDR_NOT_SUPPORTED |
          GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.accumulateAdvertisingPayload(
          GapAdvertisingData::COMPLETE_LOCAL_NAME,
          (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));

    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.setAdvertisingInterval(160); // 100ms

    /*
    led1.write(1);
    led3.write(1);
    led2.write(1);
    led4.write(1);
    */
    for(int i=0; i<10; i++)
        pc.printf("Hello World\n");
    ble.onConnection((Gap::ConnectionEventCallback_t)connectionCallback);
    ble.onDisconnection(disconnectionCallback);
    ble.gattServer().onDataWritten(onDataWritten);

    ble.addService(*gatt_service);

    ble.startAdvertising();

    /* Adding below for scanning */
        ble.setScanParams(500 /* scan interval */, 200 /* scan window */);
        ble.startScan(advertisementCallback);
    /**END OF PART FOR SCANNING**/

    for (;;)
    {
      ble.waitForEvent();
    }
}
コード例 #2
0
ファイル: main.cpp プロジェクト: sander/mbed-code
int main() {
  ble.init();
  ble.onConnection(onConnection);
  ble.onDisconnection(onDisconnection);
  ble.onDataWritten(onDataWritten);
 
  ble.accumulateAdvertisingPayload(
      GapAdvertisingData::BREDR_NOT_SUPPORTED);
  ble.setAdvertisingType(
      GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
  ble.accumulateAdvertisingPayload(
      GapAdvertisingData::SHORTENED_LOCAL_NAME,
      (const uint8_t *)NAME,
      sizeof(NAME) - 1);
  ble.accumulateAdvertisingPayload(
      GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
      (const uint8_t *)UARTServiceUUID_reversed,
      sizeof(UARTServiceUUID_reversed));
  ble.accumulateScanResponse(
      GapAdvertisingData::SHORTENED_LOCAL_NAME,
      (const uint8_t *)NAME,
      sizeof(NAME) - 1);
  ble.accumulateScanResponse(
      GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
      (const uint8_t *)UARTServiceUUID_reversed,
      sizeof(UARTServiceUUID_reversed));

  ble.setDeviceName((const uint8_t *)NAME);
 
  ble.setAdvertisingInterval(Gap::MSEC_TO_GAP_DURATION_UNITS(1000));
  ble.startAdvertising();
 
  UARTService uartService(ble);
  uartServicePtr = &uartService;

  while (true) {
    ble.waitForEvent();
  }
}
コード例 #3
0
ファイル: main.cpp プロジェクト: jxustlq/bleController
int main(void)
{
    int ret = 0;
    uint8_t *pTemp;
    int len;
    int ch;

//    led1 = new DigitalOut(P0_4);
    led1 = new DigitalOut(LED2);
     ticker = new Ticker();
    ticker->attach(periodicCallback, 0.4f); // blink LED
    serialPort = new Serial(USBTX, USBRX);
//    serialPort = new Serial(P0_0, P0_1);
    (*led1) = 1;
    serialPort->baud(115200);
    serialPort->attach(&rxInterrupt,SerialBase::RxIrq);

//    serialPort->printf("Yeth sport\r\n");
    wait_ms(100);
    ret = bicProcessInit();
    if (ret)
    {
        serialPort->printf("bic process init failed:%d\r\n", ret);
        while(1);
    }
//    serialPort->printf("%s\r\n", __TIME__);
    ble.init();
    ble.onDisconnection(disconnectionCallback);
    ble.onConnection(connectionEventCallback);

    uart = new UARTService(ble);

    recordInit();

    /* setup advertising */
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
                                     (const uint8_t *)"ysport", sizeof("ysport") - 1);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                     (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));

    ble.setAdvertisingInterval(50); /* 100ms; in multiples of 0.625ms. */
    ble.startAdvertising();

    while (true) {
        ble.waitForEvent();
        ch = EOF;
        if (ledToggle) {
            (*led1) = !(*led1);
            ledToggle = 0;
        }
        while(1)
        {
            ch = uart->_getc();
            if (ch == EOF)
                break;
            serialPort->putc(ch);
            bicReceiveChar((uint8_t)ch);
        }

        while(0 == bicProcessDispatchEvents()){
            wait_ms(20);
        }
    }
}
コード例 #4
0
ファイル: main.cpp プロジェクト: 2thetop/mbed_ble
int main(void)
{
    blue  = LED_ON;
    green = LED_OFF;

#if BUTTON_DOWN
    button.mode(PullDown);
    button.rise(button_wakeup);
#else
    button.mode(PullUp);
    button.fall(button_wakeup);
#endif

    DEBUG("Initialising the nRF51822\n\r");
    ble.init();
    ble.onConnection(connectionCallback);
    ble.onDisconnection(disconnectionCallback);
    ble.onDataWritten(onDataWritten);

    /* setup advertising */
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
                                    (const uint8_t *)BLE_NAME, sizeof(BLE_NAME));

    ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
    ble.startAdvertising();

    /* Enable over-the-air firmware updates. Instantiating DFUSservice introduces a
     * control characteristic which can be used to trigger the application to
     * handover control to a resident bootloader. */
    DFUService dfu(ble);

    UARTService uartService(ble);
    uartServicePtr = &uartService;

    blue_led_time_to_off = 3000 / TICK_PERIOD_MS;

    Ticker ticker;
    ticker.attach_us(tick, TICK_PERIOD_MS * 1000);

    while (true) {
        if (button_event) {
            int click;

            blue = LED_ON;
            click = button_detect();
            blue = LED_OFF;
            DEBUG("click type: %d\n\r", click);

            button_event = false;

            if (1 == click) {
                single_click_input = current_input;
            } else if (2 == click) {
                double_click_input = current_input;
                green = LED_ON;
                green_led_time_to_off = 1000 / TICK_PERIOD_MS;
            } else if (-1 == click) {
                while (BUTTON_DOWN == button.read()) {

                }
                nrf_delay_us(3000);

                power_down();
            } else {
                continue;
            }

            DEBUG("typical input: %f, %f\n\r", single_click_input, double_click_input);

            threshold_update = 1;
        } else {
            ble.waitForEvent();
        }
    }
}