@@ -150,21 +150,20 @@ void NimBLEHIDDevice::setBatteryLevel(uint8_t level, bool notify) {
150
150
} // setBatteryLevel
151
151
152
152
/* *
153
- * @brief Locate the characteristic for a report ID.
153
+ * @brief Locate the characteristic for a report ID and a report type .
154
154
*
155
155
* @param [in] reportId Report identifier to locate.
156
- * @param [out ] reportType Type of report (input/output/feature). Not meaningful if the return value is nullptr .
156
+ * @param [in ] reportType Type of report (input/output/feature).
157
157
* @return NimBLECharacteristic* The characteristic.
158
158
* @return nullptr If the characteristic does not exist.
159
159
*/
160
- NimBLECharacteristic* NimBLEHIDDevice::locateReportCharacteristicById (uint8_t reportId, uint8_t & reportType) {
160
+ NimBLECharacteristic* NimBLEHIDDevice::locateReportCharacteristicByIdAndType (uint8_t reportId, uint8_t reportType) {
161
161
NimBLECharacteristic* candidate = m_hidSvc->getCharacteristic (inputReportChrUuid, 0 );
162
162
for (uint16_t i = 1 ; (candidate != nullptr ) && (i != 0 ); i++) {
163
163
NimBLEDescriptor* dsc = candidate->getDescriptorByUUID (featureReportDscUuid);
164
164
NimBLEAttValue desc1_val_att = dsc->getValue ();
165
165
const uint8_t * desc1_val = desc1_val_att.data ();
166
- reportType = desc1_val[1 ];
167
- if (desc1_val[0 ] == reportId) return candidate;
166
+ if ((desc1_val[0 ] == reportId) && (desc1_val[1 ] == reportType)) return candidate;
168
167
candidate = m_hidSvc->getCharacteristic (inputReportChrUuid, i);
169
168
}
170
169
return nullptr ;
@@ -175,15 +174,10 @@ NimBLECharacteristic* NimBLEHIDDevice::locateReportCharacteristicById(uint8_t re
175
174
* @param [in] reportId Input report ID, the same as in report map for input object related to the characteristic.
176
175
* @return NimBLECharacteristic* A pointer to the input report characteristic.
177
176
* Store this value to avoid computational overhead.
178
- * @return nullptr If the report is already created as an output or feature report.
179
177
* @details This will create the characteristic if not already created.
180
178
*/
181
179
NimBLECharacteristic* NimBLEHIDDevice::getInputReport (uint8_t reportId) {
182
- uint8_t reportType;
183
- NimBLECharacteristic* inputReportChr = locateReportCharacteristicById (reportId, reportType);
184
- if ((inputReportChr != nullptr ) && (reportType != 0x01 ))
185
- // ERROR: this reportId exists, but it is not an input report
186
- return nullptr ;
180
+ NimBLECharacteristic* inputReportChr = locateReportCharacteristicByIdAndType (reportId, 0x01 );
187
181
if (inputReportChr == nullptr ) {
188
182
inputReportChr =
189
183
m_hidSvc->createCharacteristic (inputReportChrUuid,
@@ -203,15 +197,10 @@ NimBLECharacteristic* NimBLEHIDDevice::getInputReport(uint8_t reportId) {
203
197
* @param [in] reportId Output report ID, the same as in report map for output object related to the characteristic.
204
198
* @return NimBLECharacteristic* A pointer to the output report characteristic.
205
199
* Store this value to avoid computational overhead.
206
- * @return nullptr If the report is already created as an input or feature report.
207
200
* @details This will create the characteristic if not already created.
208
201
*/
209
202
NimBLECharacteristic* NimBLEHIDDevice::getOutputReport (uint8_t reportId) {
210
- uint8_t reportType;
211
- NimBLECharacteristic* outputReportChr = locateReportCharacteristicById (reportId, reportType);
212
- if ((outputReportChr != nullptr ) && (reportType != 0x02 ))
213
- // ERROR: this reportId exists, but it is not an output report
214
- return nullptr ;
203
+ NimBLECharacteristic* outputReportChr = locateReportCharacteristicByIdAndType (reportId, 0x02 );
215
204
if (outputReportChr == nullptr ) {
216
205
outputReportChr =
217
206
m_hidSvc->createCharacteristic (inputReportChrUuid,
@@ -232,15 +221,10 @@ NimBLECharacteristic* NimBLEHIDDevice::getOutputReport(uint8_t reportId) {
232
221
* @param [in] reportId Feature report ID, the same as in report map for feature object related to the characteristic.
233
222
* @return NimBLECharacteristic* A pointer to feature report characteristic.
234
223
* Store this value to avoid computational overhead.
235
- * @return nullptr If the report is already created as an input or output report.
236
224
* @details This will create the characteristic if not already created.
237
225
*/
238
226
NimBLECharacteristic* NimBLEHIDDevice::getFeatureReport (uint8_t reportId) {
239
- uint8_t reportType;
240
- NimBLECharacteristic* featureReportChr = locateReportCharacteristicById (reportId, reportType);
241
- if ((featureReportChr != nullptr ) && (reportType != 0x03 ))
242
- // ERROR: this reportId exists, but it is not a feature report
243
- return nullptr ;
227
+ NimBLECharacteristic* featureReportChr = locateReportCharacteristicByIdAndType (reportId, 0x03 );
244
228
if (featureReportChr == nullptr ) {
245
229
featureReportChr = m_hidSvc->createCharacteristic (
246
230
inputReportChrUuid,
0 commit comments