bleman.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2019 Koen Zandberg <koen@bergzand.net>
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser
  5. * General Public License v2.1. See the file LICENSE in the top level
  6. * directory for more details.
  7. */
  8. #ifndef APP_BLEMAN_H
  9. #define APP_BLEMAN_H
  10. #include "host/ble_gap.h"
  11. #include <stdint.h>
  12. #include "event.h"
  13. #include "thread.h"
  14. #include "xtimer.h"
  15. #include "bleman/bas.h"
  16. #include "bleman/hrs.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #ifndef CONFIG_BLEMAN_DEVICE_NAME
  21. #define CONFIG_BLEMAN_DEVICE_NAME "ROOMBAHAHACKED"
  22. #endif
  23. #ifndef CONFIG_BLEMAN_MANUF_NAME
  24. #define CONFIG_BLEMAN_MANUF_NAME "danielinux"
  25. #endif
  26. #ifndef CONFIG_BLEMAN_MODEL_NUM
  27. #define CONFIG_BLEMAN_MODEL_NUM "1"
  28. #endif
  29. #ifndef CONFIG_BLEMAN_FW_VERSION
  30. #define CONFIG_BLEMAN_FW_VERSION "1.0.0"
  31. #endif
  32. #ifndef CONFIG_BLEMAN_HW_VERSION
  33. #define CONFIG_BLEMAN_HW_VERSION "1"
  34. #endif
  35. #ifndef CONFIG_BLEMAN_SERIAL_LEN
  36. #define CONFIG_BLEMAN_SERIAL_LEN 24
  37. #endif
  38. #ifndef CONFIG_BLEMAN_ROOMBA_UUID
  39. #define CONFIG_BLEMAN_ROOMBA_UUID 0xc5, 0xb1, 0x8c, 0x78, 0x38, 0x3b, 0x46, 0x56, 0x99, 0x13, 0x4a, 0xb0, 0x0a, 0xdc, 0x51, 0x98
  40. #endif
  41. typedef struct _bleman bleman_t;
  42. typedef struct _bleman_event_handler bleman_event_handler_t;
  43. /**
  44. * @brief event notification handler
  45. *
  46. * @param event NimBLE gap event
  47. * @param bleman bleman context
  48. * @param arg Extra argument passed to the call
  49. */
  50. typedef void (*bleman_event_cb_t)(bleman_t *bleman, struct ble_gap_event *event,
  51. void *arg);
  52. typedef enum {
  53. BLEMAN_BLE_STATE_INACTIVE,
  54. BLEMAN_BLE_STATE_ADVERTISING,
  55. BLEMAN_BLE_STATE_DISCONNECTED,
  56. BLEMAN_BLE_STATE_CONNECTED,
  57. } bleman_ble_state_t;
  58. struct _bleman_event_handler {
  59. struct _bleman_event_handler *next; /**< linked list iterator */
  60. bleman_event_cb_t handler; /**< Handler function pointer */
  61. void *arg; /**< Argument passed to the handler function call */
  62. };
  63. struct _bleman {
  64. char serial[CONFIG_BLEMAN_SERIAL_LEN];
  65. event_queue_t eq;
  66. uint16_t conn_handle;
  67. bleman_event_handler_t *handlers;
  68. bleman_ble_state_t state;
  69. bleman_bas_t bas;
  70. bleman_hrs_t hrs;
  71. };
  72. int bleman_thread_create(void);
  73. bleman_t *bleman_get(void);
  74. bleman_ble_state_t bleman_get_conn_state(bleman_t *bleman, struct ble_gap_conn_desc *state);
  75. /**
  76. * @brief Add a notification handler to the bleman thread
  77. *
  78. * @param bleman bleman context
  79. * @param event event handler context to add
  80. * @param cb callback function
  81. * @param arg argument to add to the handler
  82. */
  83. void bleman_add_event_handler(bleman_t *bleman, bleman_event_handler_t *event,
  84. bleman_event_cb_t cb, void *arg);
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif /* APP_BLEMAN_H */