T1000eBoard.cpp 2.4 KB

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