@@ -9,13 +9,15 @@ bool BleSerial::connected()
9
9
void BleSerial::onConnect (BLEServer *pServer)
10
10
{
11
11
bleConnected = true ;
12
- if (enableLed) digitalWrite (ledPin, HIGH);
12
+ if (enableLed)
13
+ digitalWrite (ledPin, HIGH);
13
14
}
14
15
15
16
void BleSerial::onDisconnect (BLEServer *pServer)
16
17
{
17
18
bleConnected = false ;
18
- if (enableLed) digitalWrite (ledPin, LOW);
19
+ if (enableLed)
20
+ digitalWrite (ledPin, LOW);
19
21
Server->startAdvertising ();
20
22
}
21
23
@@ -87,11 +89,11 @@ size_t BleSerial::write(const uint8_t *buffer, size_t bufferSize)
87
89
}
88
90
}
89
91
90
- if (maxTransferSize < MIN_MTU){
92
+ if (maxTransferSize < MIN_MTU)
93
+ {
91
94
return 0 ;
92
95
}
93
96
94
-
95
97
size_t written = 0 ;
96
98
for (int i = 0 ; i < bufferSize; i++)
97
99
{
@@ -109,7 +111,7 @@ size_t BleSerial::write(uint8_t byte)
109
111
}
110
112
this ->transmitBuffer [this ->transmitBufferLength ] = byte;
111
113
this ->transmitBufferLength ++;
112
- if (this ->transmitBufferLength == sizeof ( this -> transmitBuffer ) )
114
+ if (this ->transmitBufferLength == maxTransferSize )
113
115
{
114
116
flush ();
115
117
}
@@ -127,19 +129,18 @@ void BleSerial::flush()
127
129
TxCharacteristic->notify (true );
128
130
}
129
131
130
- void BleSerial::begin (const char *name,bool enable_led, int led_pin)
132
+ void BleSerial::begin (const char *name, bool enable_led, int led_pin)
131
133
{
132
134
enableLed = enable_led;
133
135
ledPin = led_pin;
134
136
135
- if (enableLed){
136
- pinMode (ledPin,OUTPUT);
137
+ if (enableLed)
138
+ {
139
+ pinMode (ledPin, OUTPUT);
137
140
}
138
- // characteristic property is what the other device does.
139
141
140
142
ConnectedDeviceCount = 0 ;
141
143
BLEDevice::init (name);
142
- // BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT);
143
144
144
145
Server = BLEDevice::createServer ();
145
146
Server->setCallbacks (this );
@@ -149,16 +150,9 @@ void BleSerial::begin(const char *name,bool enable_led, int led_pin)
149
150
pAdvertising = BLEDevice::getAdvertising ();
150
151
pAdvertising->addServiceUUID (BLE_SERIAL_SERVICE_UUID);
151
152
pAdvertising->setScanResponse (true );
152
- pAdvertising->setMinPreferred (0x06 ); // functions that help with iPhone connections issue
153
+ pAdvertising->setMinPreferred (0x06 );
153
154
pAdvertising->setMinPreferred (0x12 );
154
155
pAdvertising->start ();
155
-
156
- // pSecurity = new BLESecurity();
157
-
158
- // Set static pin
159
- // uint32_t passkey = 123456;
160
- // esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));
161
- // pSecurity->setCapability(ESP_IO_CAP_OUT);
162
156
}
163
157
164
158
void BleSerial::end ()
@@ -172,16 +166,15 @@ void BleSerial::onWrite(BLECharacteristic *pCharacteristic)
172
166
{
173
167
std::string value = pCharacteristic->getValue ();
174
168
175
- if (value.length () > 0 )
176
- {
177
- for (int i = 0 ; i < value.length (); i++)
178
- receiveBuffer.add (value[i]);
179
- }
169
+ for (int i = 0 ; i < value.length (); i++)
170
+ receiveBuffer.add (value[i]);
180
171
}
181
172
}
182
173
183
174
void BleSerial::SetupSerialService ()
184
175
{
176
+ // characteristic property is what the other device does.
177
+
185
178
SerialService = Server->createService (BLE_SERIAL_SERVICE_UUID);
186
179
187
180
RxCharacteristic = SerialService->createCharacteristic (
0 commit comments