T1000eBoard.cpp 2.7 KB

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