MeshCore/variants/t1000-e/T1000eBoard.cpp

90 lines
2.6 KiB
C++
Raw Normal View History

2025-02-14 09:54:06 +01:00
#include <Arduino.h>
#include "T1000eBoard.h"
#include <Wire.h>
2025-02-14 09:54:06 +01:00
#include <bluefruit.h>
void T1000eBoard::begin() {
// for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL;
btn_prev_state = HIGH;
2025-03-21 15:08:13 +01:00
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
// Enable DC/DC converter for improved power efficiency
NRF_POWER->DCDCEN = 1;
2025-02-26 18:19:38 +11:00
#ifdef BUTTON_PIN
pinMode(BATTERY_PIN, INPUT);
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
2025-02-26 18:19:38 +11:00
#endif
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
2025-04-09 18:19:13 +10:00
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
#endif
Wire.begin();
delay(10); // give sx1262 some time to power up
}
2025-02-14 09:54:06 +01:00
#if 0
static BLEDfu bledfu;
static void connect_callback(uint16_t conn_handle) {
(void)conn_handle;
MESH_DEBUG_PRINTLN("BLE client connected");
2025-02-14 09:54:06 +01:00
}
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
(void)conn_handle;
(void)reason;
2025-02-14 09:54:06 +01:00
MESH_DEBUG_PRINTLN("BLE client disconnected");
2025-02-14 09:54:06 +01:00
}
2025-03-22 23:51:44 +11:00
bool TrackerT1000eBoard::startOTAUpdate(const char* id, char reply[]) {
// Config the peripheral connection with maximum bandwidth
// more SRAM required by SoftDevice
// Note: All config***() function must be called before begin()
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16);
Bluefruit.begin(1, 0);
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
Bluefruit.setTxPower(4);
// Set the BLE device name
Bluefruit.setName("T1000E_OTA");
Bluefruit.Periph.setConnectCallback(connect_callback);
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
// To be consistent OTA DFU should be added first if it exists
bledfu.begin();
// Set up and start advertising
// Advertising packet
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();
Bluefruit.Advertising.addName();
/* Start Advertising
- Enable auto advertising if disconnected
- Interval: fast mode = 20 ms, slow mode = 152.5 ms
- Timeout for fast mode is 30 seconds
- Start(timeout) with timeout = 0 will advertise forever (until connected)
For recommended advertising interval
https://developer.apple.com/library/content/qa/qa1931/_index.html
*/
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
2025-02-14 09:54:06 +01:00
2025-03-22 23:51:44 +11:00
strcpy(reply, "OK - started");
2025-02-14 09:54:06 +01:00
return true;
}
#endif