Demo Glucose Service

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate by Bluetooth Low Energy

BLE_Glucose_demo implements the Glucose Service which enables a collector device to connect and interact with.

There is a brief sample code edited with Android Studio for demo this BLE_Glucose_demo example, and it is public on github, everyone can clone it by this URL: https://github.com/Marcomissyou/BluetoothLeGlucose.git. It is convenient for you to development your BLE idea.

There is also provided apk file so you can download and install it directly then demo this code, but make sure your Android phone supports Bluetooth 4.0. /media/uploads/Marcomissyou/bleglucoseservice.apk

main.cpp

Committer:
Marcomissyou
Date:
2015-07-02
Revision:
66:72ca05b7a092
Parent:
65:e419508fefc4
Child:
67:aa3a1bbed328

File content as of revision 66:72ca05b7a092:

#include "mbed.h"
#include "BLE.h"
#include "BatteryService.h"
#include "DeviceInformationService.h"
#include "HIDService.h"
 
BLEDevice  ble;
DigitalOut led01(LED1);
Serial uart(p25,p23);

unsigned char keyData;
bool is_input = false; 
static const char     DEVICE_NAME[]        = "HID_Keyboard";
static const uint16_t uuid16_list[]        = {GattService::UUID_HUMAN_INTERFACE_DEVICE_SERVICE};
static volatile bool  triggerSensorPolling = false;

void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
{
    ble.startAdvertising(); // restart advertising
}


static uint8_t key_press_scan_buff[30];
static uint8_t modifyKey[30];
int main(void)
{   uart.baud(9600);
    uart.printf("Starting HID Service\n");
    //uart.attach(&uart_rx);
    led01 = 1;
    ble.init();
    bool enableBonding = false;
    bool requireMITM   = false;
    ble.initializeSecurity(enableBonding, requireMITM);
    ble.onDisconnection(disconnectionCallback);
 
    /* Setup primary service. */
    HIDService hidService(ble);
    /* Setup auxiliary service. */
    DeviceInformationService deviceInfo(ble, "ARM", "CYNTEC", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
    /* Setup advertising. */
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
    ble.accumulateAdvertisingPayload(GapAdvertisingData::KEYBOARD);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.setAdvertisingInterval(1000);
    ble.startAdvertising();
    uart.printf("Starting advertising\n");
    int index = 0;
    while (1) {
        if (uart.readable() == 1) {
            keyData = uart.getc();
            uart.putc(keyData);
            if(keyData <= 0x39 && keyData >= 0x30){             //number
                if(keyData == 0x30){
                    modifyKey[index] = 0x00;
                    key_press_scan_buff[index] = 0x27;
                    } else {
                    modifyKey[index] = 0x00;
                    key_press_scan_buff[index] = keyData-0x13;
                    }
                } else if(keyData <= 0x7a && keyData >= 0x61 ){ //lowercase letters
                    modifyKey[index] = 0x00;
                    key_press_scan_buff[index] = keyData-0x5d;
                } else if(keyData <= 0x5a && keyData >= 0x41){  //uppercase letters
                    modifyKey[index] = 0x02;
                    key_press_scan_buff[index] = keyData-0x3d;
                } else if (keyData == 0x20) {
                    modifyKey[index] = 0x00;
                    key_press_scan_buff[index] = 0x2c;
                } else {
                    modifyKey[index] = 0x00;
                    //key_press_scan_buff[index] = 0x28;
                    //key_press_scan_buff[index++] = 0x73;
                    key_press_scan_buff[index] = 0x73;
            }
            index++;
            if(keyData == 0x0a && ble.getGapState().connected){
                for(int i = 0; i < index; i++){
                //uart.putc(key_press_scan_buff[i]);
                hidService.updateReport(modifyKey[i], key_press_scan_buff[i]);
                wait(0.1);
                }
            index = 0;
            memset(modifyKey, 0, 30);
            memset(key_press_scan_buff, 0, 30);
            }
            
        }
    }
}