Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Copyright 2014 Nordic Semiconductor
- *
- * 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
- */
- #define LOG_LEVEL_INFO
- #include "Puck.h"
- Puck* puck = &Puck::getPuck();
- // Sample Gatt characteristic and service UUIDs
- const UUID SAMPLE_GATT_SERVICE = stringToUUID("bftj cube ");
- const UUID SAMPLE_GATT_CHARACTERISTIC = stringToUUID("bftj cube dirctn");
- const UUID Char_Id = stringToUUID("my other charact");
- InterruptIn myButton(BUTTON1);
- bool buttonPressed = false;
- void onChange(const uint8_t* value, const uint8_t length) {
- printf("Stuff was written:\n");
- for (int i = 0; i < length; i++) {
- printf("%c\n", (char*)value);
- }
- }
- void buttonCallback() {
- buttonPressed = true;
- }
- int main(void) {
- // Add the Gatt characteristic
- int characteristicValueLength = 20;
- puck->addCharacteristic(
- SAMPLE_GATT_SERVICE,
- SAMPLE_GATT_CHARACTERISTIC,
- 1,
- GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
- puck->addCharacteristic(
- SAMPLE_GATT_SERVICE,
- Char_Id,
- characteristicValueLength,
- GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE);
- myButton.rise(&buttonCallback);
- myButton.enable_irq();
- // Initialize the puck
- puck->init(0xFAAD);
- // Set the initial value of the characteristic
- uint8_t new_value = 0;
- puck->updateCharacteristicValue(SAMPLE_GATT_CHARACTERISTIC, &new_value, characteristicValueLength);
- puck->onCharacteristicWrite(&Char_Id, onChange);
- // Let the puck do its thing
- while(puck->drive()) {
- if (buttonPressed) {
- new_value = 1;
- puck->updateCharacteristicValue(SAMPLE_GATT_CHARACTERISTIC, &new_value, 1);
- LOG_INFO("BUTTON PRESSED\n");
- buttonPressed = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement