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