T1000eBoard.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <Arduino.h>
  2. #include "T1000eBoard.h"
  3. #include <Wire.h>
  4. #include <bluefruit.h>
  5. void T1000eBoard::begin() {
  6. // for future use, sub-classes SHOULD call this from their begin()
  7. startup_reason = BD_STARTUP_NORMAL;
  8. btn_prev_state = HIGH;
  9. sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
  10. // Enable DC/DC converter for improved power efficiency
  11. NRF_POWER->DCDCEN = 1;
  12. #ifdef BUTTON_PIN
  13. pinMode(BATTERY_PIN, INPUT);
  14. pinMode(BUTTON_PIN, INPUT);
  15. pinMode(LED_PIN, OUTPUT);
  16. #endif
  17. #if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
  18. Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
  19. #endif
  20. Wire.begin();
  21. delay(10); // give sx1262 some time to power up
  22. }
  23. #if 0
  24. static BLEDfu bledfu;
  25. static void connect_callback(uint16_t conn_handle) {
  26. (void)conn_handle;
  27. MESH_DEBUG_PRINTLN("BLE client connected");
  28. }
  29. static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
  30. (void)conn_handle;
  31. (void)reason;
  32. MESH_DEBUG_PRINTLN("BLE client disconnected");
  33. }
  34. bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) {
  35. // Config the peripheral connection with maximum bandwidth
  36. // more SRAM required by SoftDevice
  37. // Note: All config***() function must be called before begin()
  38. Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
  39. Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16);
  40. Bluefruit.begin(1, 0);
  41. // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
  42. Bluefruit.setTxPower(4);
  43. // Set the BLE device name
  44. Bluefruit.setName("T1000E_OTA");
  45. Bluefruit.Periph.setConnectCallback(connect_callback);
  46. Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
  47. // To be consistent OTA DFU should be added first if it exists
  48. bledfu.begin();
  49. // Set up and start advertising
  50. // Advertising packet
  51. Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
  52. Bluefruit.Advertising.addTxPower();
  53. Bluefruit.Advertising.addName();
  54. /* Start Advertising
  55. - Enable auto advertising if disconnected
  56. - Interval: fast mode = 20 ms, slow mode = 152.5 ms
  57. - Timeout for fast mode is 30 seconds
  58. - Start(timeout) with timeout = 0 will advertise forever (until connected)
  59. For recommended advertising interval
  60. https://developer.apple.com/library/content/qa/qa1931/_index.html
  61. */
  62. Bluefruit.Advertising.restartOnDisconnect(true);
  63. Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
  64. Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
  65. Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
  66. strcpy(reply, "OK - started");
  67. return true;
  68. }
  69. #endif