@@ -346,7 +346,7 @@ void BLECharacteristic::setReadProperty(bool value) {
346
346
* @param [in] data The data to set for the characteristic.
347
347
* @param [in] length The length of the data in bytes.
348
348
*/
349
- void BLECharacteristic::setValue (uint8_t *data, size_t length) {
349
+ void BLECharacteristic::setValue (const uint8_t *data, size_t length) {
350
350
// The call to BLEUtils::buildHexData() doesn't output anything if the log level is not
351
351
// "VERBOSE". As it is quite CPU intensive, it is much better to not call it if not needed.
352
352
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
@@ -371,43 +371,28 @@ void BLECharacteristic::setValue(uint8_t *data, size_t length) {
371
371
* @param [in] Set the value of the characteristic.
372
372
* @return N/A.
373
373
*/
374
- void BLECharacteristic::setValue (String value) {
375
- setValue (( uint8_t *) (value.c_str ()), value.length ());
374
+ void BLECharacteristic::setValue (const String & value) {
375
+ setValue (reinterpret_cast < const uint8_t *> (value.c_str ()), value.length ());
376
376
} // setValue
377
377
378
- void BLECharacteristic::setValue (uint16_t &data16) {
379
- uint8_t temp[2 ];
380
- temp[0 ] = data16;
381
- temp[1 ] = data16 >> 8 ;
382
- setValue (temp, 2 );
378
+ void BLECharacteristic::setValue (uint16_t data16) {
379
+ setValue (reinterpret_cast <const uint8_t *>(&data16), sizeof (data16));
383
380
} // setValue
384
381
385
- void BLECharacteristic::setValue (uint32_t &data32) {
386
- uint8_t temp[4 ];
387
- temp[0 ] = data32;
388
- temp[1 ] = data32 >> 8 ;
389
- temp[2 ] = data32 >> 16 ;
390
- temp[3 ] = data32 >> 24 ;
391
- setValue (temp, 4 );
382
+ void BLECharacteristic::setValue (uint32_t data32) {
383
+ setValue (reinterpret_cast <const uint8_t *>(&data32), sizeof (data32));
392
384
} // setValue
393
385
394
- void BLECharacteristic::setValue (int &data32) {
395
- uint8_t temp[4 ];
396
- temp[0 ] = data32;
397
- temp[1 ] = data32 >> 8 ;
398
- temp[2 ] = data32 >> 16 ;
399
- temp[3 ] = data32 >> 24 ;
400
- setValue (temp, 4 );
386
+ void BLECharacteristic::setValue (int data32) {
387
+ setValue (reinterpret_cast <const uint8_t *>(&data32), sizeof (data32));
401
388
} // setValue
402
389
403
- void BLECharacteristic::setValue (float &data32) {
404
- float temp = data32;
405
- setValue ((uint8_t *)&temp, 4 );
390
+ void BLECharacteristic::setValue (float data32) {
391
+ setValue (reinterpret_cast <const uint8_t *>(&data32), sizeof (data32));
406
392
} // setValue
407
393
408
- void BLECharacteristic::setValue (double &data64) {
409
- double temp = data64;
410
- setValue ((uint8_t *)&temp, 8 );
394
+ void BLECharacteristic::setValue (double data64) {
395
+ setValue (reinterpret_cast <const uint8_t *>(&data64), sizeof (data64));
411
396
} // setValue
412
397
413
398
/* *
0 commit comments