オムロンのOKAO Vision HVC-C1BとBLE通信します。
Dependencies: BLE_API mbed nRF51822
Fork of BLE_ButtonSense by
オムロン OKAO Vision(ヒューマンビジョンコンポ)HVC-C1BとRedBearLab nRF51822 mbedでBLE通信を行うサンプルです。
HVC-C1Bは、人、手、顔、性別、年齢、表情、顔の向き、視線、目の閉じを推定し、値を返してくれます。 http://plus-sensing.omron.co.jp/egg-project/
main.cppの最初の定義の部分(IDや欲しい項目)を変更すると使えます。 欲しい項目を1に要らない項目は0にしてください。
タイムアウトの処理が入っていませんが、もし入れたい場合は、LEDのHartBeatの処理に追加すれば簡単に出来ると思います。
下記のような感じでメッセージが帰ってきます。
#Look at HVC-C1B peerAddr[d5 32 26 3b 47 3d] rssi -76, isScanResponse 0, AdvertisementType 0 # St#HVC-C1B Connect #SCAN Stop ate 1 Wait for Caracteristic Found #short: # C UUID-2a00 valueAttr[3] props[0] #short: # C UUID-2a01 valueAttr[5] props[0] #short: # C UUID-2a04 valueAttr[7] props[0] #short: # C UUID-2a05 valueAttr[10] props[0] #long: # C UUID-35100003d13a4f398ab3bf64d4fbb4b4 valueAttr[14] props[0] #HVCNotifyCharacteristic Found #long: # C UUID-35100002d13a4f398ab3bf64d4fbb4b4 valueAttr[17] props[0] #HVCWriteCharacteristic Found #long: # C UUID-35100004d13a4f398ab3bf64d4fbb4b4 valueAttr[19] props[0] #HVCDeviceCharacteristic Found # discovery terminated CallBack 0 # State 2 Notify Enable #send data 1 #State=2 Wited # State3 kidoukakunin #send data 1 #received HVX callback for handle 14; type notification #received HVX callback for handle 14; type notification # State3 HVC-C1B 1 1 0 96090000 # State4 DataSending #send data 1 #received HVX callback for handle 14; type notification #received HVX callback for handle 14; type notification #received HVX callback for handle 14; type notification HumanDetect:1 Human(0):x=199,y=251,size=330,depend=774 HandDetect:0 FaceDetect:1 Face(0):x=227,y=230,size=158,depend=670 FaceDirection(0):holizon=20,vertical=0,angle=15,depend=120 FaceOld(0):old=64,depend=333 FaceSex(0):Sex=0,depend=111 FaceLook(0):holizon=-2,vertical=-2 FaceEyeClose(0):xleft=229,right=326 FaceExpression(0):TopExpression=5,TopScore=46,look=-74 # State4 DataSending #send data 1
main.cpp
- Committer:
- rgrover1
- Date:
- 2015-07-06
- Revision:
- 0:2dec89c76f68
- Child:
- 1:e4ee755844de
File content as of revision 0:2dec89c76f68:
/* mbed Microcontroller Library * Copyright (c) 2006-2015 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "mbed.h" #include "ble/BLE.h" #include "ble/DiscoveredCharacteristic.h" #include "ble/DiscoveredService.h" #include "ble_gatt.h" BLE ble; Gap::Handle_t connectionHandle = 0xFFFF; DigitalOut alivenessLED(LED1, 1); bool foundButtonCharacteristic = false; DiscoveredCharacteristic buttonCharacteristic; void periodicCallback(void) { alivenessLED = !alivenessLED; /* Do blinky on LED1 while we're waiting for BLE events */ } void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) { if (params->peerAddr[0] != 0x29) { /* !ALERT! Update this filter to suit your device. */ return; } printf("adv peerAddr[%02x %02x %02x %02x %02x %02x] rssi %d, isScanResponse %u, AdvertisementType %u\r\n", params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0], params->rssi, params->isScanResponse, params->type); ble.gap().connect(params->peerAddr, Gap::ADDR_TYPE_RANDOM_STATIC, NULL, NULL); } void serviceDiscoveryCallback(const DiscoveredService *service) { if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) { printf("S UUID-%x attrs[%u %u]\r\n", service->getUUID().getShortUUID(), service->getStartHandle(), service->getEndHandle()); } else { printf("S UUID-"); const uint8_t *longUUIDBytes = service->getUUID().getBaseUUID(); for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) { printf("%02x", longUUIDBytes[i]); } printf(" attrs[%u %u]\r\n", service->getStartHandle(), service->getEndHandle()); } } void characteristicDiscoveryCallback(const DiscoveredCharacteristic *characteristicP) { printf(" C UUID-%x valueAttr[%u] props[%x]\r\n", characteristicP->getShortUUID(), characteristicP->getValueHandle(), (uint8_t)characteristicP->getProperties().broadcast()); if (characteristicP->getShortUUID() == 0xa001) { /* !ALERT! Update this filter to suit your device. */ buttonCharacteristic = *characteristicP; foundButtonCharacteristic = true; } } void discoveryTerminationCallback(Gap::Handle_t connectionHandle) { printf("terminated SD for handle %u\r\n", connectionHandle); } void connectionCallback(const Gap::ConnectionCallbackParams_t *params) { if (params->role == Gap::CENTRAL) { connectionHandle = params->handle; ble.gattClient().onServiceDiscoveryTermination(discoveryTerminationCallback); ble.gattClient().launchServiceDiscovery(params->handle, serviceDiscoveryCallback, characteristicDiscoveryCallback/*, 0xa000, 0xa001*/); } } void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { printf("disconnected\r\n"); } void hvxCallback(const GattHVXCallbackParams *params) { printf("received HVX callback for handle %u; type %s\r\n", params->handle, (params->type == BLE_HVX_NOTIFICATION) ? "notification" : "indication"); for (unsigned index = 0; index < params->len; index++) { printf(" %02x", params->data[index]); } printf("\r\n"); } int main(void) { Ticker ticker; ticker.attach(periodicCallback, 1); ble.init(); ble.gap().onConnection(connectionCallback); ble.gap().onDisconnection(disconnectionCallback); ble.gap().setScanParams(500, 400); ble.gap().startScan(advertisementCallback); ble.gattClient().onHVX(hvxCallback); while (true) { if (foundButtonCharacteristic && !ble.gattClient().isServiceDiscoveryActive()) { foundButtonCharacteristic = false; /* need to do the following only once */ /* Note: Yuckiness alert! The following needs to be encapsulated in a neat API. * It isn't clear whether we should provide a DiscoveredCharacteristic::enableNoticiation() or * DiscoveredCharacteristic::discoverDescriptors() followed by DiscoveredDescriptor::write(...). */ uint16_t value = BLE_HVX_NOTIFICATION; ble.gattClient().write(GattClient::GATT_OP_WRITE_REQ, connectionHandle, buttonCharacteristic.getValueHandle() + 1, /* HACK Alert. We're assuming that CCCD descriptor immediately follows the value attribute. */ sizeof(uint16_t), /* HACK Alert! size should be made into a BLE_API constant. */ reinterpret_cast<const uint8_t *>(&value)); } ble.waitForEvent(); } }