Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. /**
  2. * Copyright 2014 Nordic Semiconductor
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License
  15. */
  16.  
  17. #define LOG_LEVEL_INFO
  18. #include "Puck.h"
  19.  
  20. Puck* puck = &Puck::getPuck();
  21.  
  22. // Sample Gatt characteristic and service UUIDs
  23. const UUID SAMPLE_GATT_SERVICE = stringToUUID("bftj cube ");
  24. const UUID SAMPLE_GATT_CHARACTERISTIC = stringToUUID("bftj cube dirctn");
  25. const UUID Char_Id = stringToUUID("my other charact");
  26.  
  27. InterruptIn myButton(BUTTON1);
  28.  
  29. bool buttonPressed = false;
  30.  
  31. void onChange(const uint8_t* value, const uint8_t length) {
  32. printf("Stuff was written:\n");
  33. for (int i = 0; i < length; i++) {
  34. printf("%c\n", (char*)value);
  35. }
  36. }
  37.  
  38. void buttonCallback() {
  39. buttonPressed = true;
  40. }
  41.  
  42. int main(void) {
  43. // Add the Gatt characteristic
  44. int characteristicValueLength = 20;
  45.  
  46. puck->addCharacteristic(
  47. SAMPLE_GATT_SERVICE,
  48. SAMPLE_GATT_CHARACTERISTIC,
  49. 1,
  50. GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
  51. puck->addCharacteristic(
  52. SAMPLE_GATT_SERVICE,
  53. Char_Id,
  54. characteristicValueLength,
  55. GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE);
  56.  
  57. myButton.rise(&buttonCallback);
  58. myButton.enable_irq();
  59. // Initialize the puck
  60. puck->init(0xFAAD);
  61.  
  62. // Set the initial value of the characteristic
  63. uint8_t new_value = 0;
  64. puck->updateCharacteristicValue(SAMPLE_GATT_CHARACTERISTIC, &new_value, characteristicValueLength);
  65. puck->onCharacteristicWrite(&Char_Id, onChange);
  66. // Let the puck do its thing
  67. while(puck->drive()) {
  68. if (buttonPressed) {
  69. new_value = 1;
  70. puck->updateCharacteristicValue(SAMPLE_GATT_CHARACTERISTIC, &new_value, 1);
  71. LOG_INFO("BUTTON PRESSED\n");
  72. buttonPressed = false;
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement