tile_tdt_module.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * NOTICE
  3. *
  4. * Copyright 2017 Tile Inc. All Rights Reserved.
  5. * All code or other information included in the accompanying files ("Tile Source Material")
  6. * is PROPRIETARY information of Tile Inc. ("Tile") and access and use of the Tile Source Material
  7. * is subject to these terms. The Tile Source Material may only be used for demonstration purposes,
  8. * and may not be otherwise distributed or made available to others, including for commercial purposes.
  9. * Without limiting the foregoing , you understand and agree that no production use
  10. * of the Tile Source Material is allowed without a Tile ID properly obtained under a separate
  11. * agreement with Tile.
  12. * You also understand and agree that Tile may terminate the limited rights granted under these terms
  13. * at any time in its discretion.
  14. * All Tile Source Material is provided AS-IS without warranty of any kind.
  15. * Tile does not warrant that the Tile Source Material will be error-free or fit for your purposes.
  16. * Tile will not be liable for any damages resulting from your use of or inability to use
  17. * the Tile Source Material.
  18. *
  19. * Support: firmware_support@tile.com
  20. */
  21. /** @file tile_tdt_module.h
  22. ** @brief Tile Double Tap module
  23. */
  24. #ifndef TILE_TDT_MODULE_H_
  25. #define TILE_TDT_MODULE_H_
  26. #include <stdint.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #define TDT_HDC_IBEACON_DURATION 200 ///< in tens of miliseconds
  31. #define TDT_HDC_ADVERTISING_STEP_DURATION 200 ///< Advertising step in tens of miliseconds
  32. #define TDT_HDC_ADVERTISING_LAST_STEP_DURATION 100 ///< Advertising last step in tens of miliseconds
  33. #define TDT_HDC_IBEACON_INTERVAL 40 ///< in 0.625 milisecond increments
  34. #define TDT_HDC_ADVERTISING_INTERVAL 160 ///< in 0.625 milisecond increments
  35. /**
  36. * @brief TDT Local Config Struct
  37. */
  38. typedef struct
  39. {
  40. uint16_t SE_LTF:1; ///< [0] Song Enable: LongTap Failure
  41. uint16_t SE_LTS:1; ///< [1] Song Enable: LongTap Success
  42. uint16_t SE_DTF:1; ///< [2] Song Enable: DoubleTap Failure
  43. uint16_t SE_DTS:1; ///< [3] Song Enable: DoubleTap Success
  44. uint16_t SE_STIF:1; ///< [4] Song Enable: SingleTapImmediate Failure
  45. uint16_t SE_STIS:1; ///< [5] Song Enable: SingleTapImmediate Success
  46. uint16_t SE_STDF:1; ///< [6] Song Enable: SingleTapDelayed Failure
  47. uint16_t SE_STDS:1; ///< [7] Song Enable: SingleTapDelayed Success
  48. uint16_t EN_DT:1; ///< [8] Enable: DoubleTap
  49. uint16_t EN_LT:1; ///< [9] Enable: LongTap
  50. uint16_t EN_STI:1; ///< [10] Enable: SingleTapImmediate
  51. uint16_t EN_STD:1; ///< [11] Enable: SingleTapDelayed
  52. uint16_t SS_Strength:2; ///< [12:13] Success Song Strength (0/1: Low; 2: Med; 3: High)
  53. uint16_t FS_Strength:2; ///< [14:15] Fail Song Strength (0/1: Low; 2: Med; 3: High)
  54. uint8_t Delay; ///< DoubleTap and LongTap detection delay: in units of 20 ms, plus an offset of 10ms.
  55. uint8_t NotifDebounceDelay; ///< DoubleTap Notification Debouncing Delay: in units of 100ms. 0 means no debouncing.
  56. } tdt_config_t;
  57. /**
  58. * Tile DoubleTap module.
  59. *
  60. * This module is used by Tile Lib to detect various types of button press.
  61. * Furthermore, this module also supports the "TDT HDC" feature, which is used
  62. * to advertise with a high duty cycle when a double tap is detected.
  63. */
  64. struct tile_tdt_module
  65. {
  66. /**
  67. * Configuration for TDT. Used internally by Tile Lib.
  68. */
  69. tdt_config_t config;
  70. /**
  71. * Variables to support optional TDT HDC feature.
  72. */
  73. uint8_t hdc_status;
  74. /*** Diagnostic information ***/
  75. uint16_t *single_tap;
  76. uint8_t *long_tap;
  77. uint16_t *double_tap_detect;
  78. uint16_t *double_tap_notify;
  79. uint16_t *double_tap_failure2;
  80. /**
  81. * Configuration was written by the app. Should be stored to NVM.
  82. */
  83. int (*config_written)(tdt_config_t *config);
  84. /**
  85. * Called when a double tap is detected and the Tile should move into
  86. * high duty cycle advertising.
  87. */
  88. void (*hdc_cb)(void);
  89. };
  90. /**
  91. * TDT_HDC_STATUS.
  92. *
  93. * Used by the TDT HDC optional feature (see @ref tile_tdt_module).
  94. */
  95. enum TDT_HDC_STATUS
  96. {
  97. TDT_HDC_STATUS_NORMAL = 0x00, // Default state, Nothing special
  98. TDT_HDC_STATUS_IBEACON = 0x01, // Advertise iBeacon
  99. TDT_HDC_STATUS_FAST_ADV = 0x02, // Advertise fast
  100. TDT_HDC_STATUS_FAST_ADV2 = 0x03, // Advertise fast
  101. TDT_HDC_STATUS_FAST_ADV3 = 0x04, // Advertise fast
  102. TDT_HDC_STATUS_FAST_ADV4 = 0x05, // Advertise fast
  103. TDT_HDC_STATUS_FAST_ADV5 = 0x06, // Advertise fast
  104. TDT_HDC_STATUS_NOTIFY = 0x07, // Send a TDT notification
  105. };
  106. /**
  107. * Register TDT module
  108. */
  109. int tile_tdt_register(struct tile_tdt_module *module);
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif // TILE_TDT_MODULE_H_