8000 Merge pull request #467 from jrickard/master · hasevr/esp32-snippets@eb25dac · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit eb25dac

Browse files
authored
Merge pull request nkolban#467 from jrickard/master
BLECharacterstic.setValue() overrides to allow additional data types
2 parents 6fa380b + bbec0b9 commit eb25dac

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

cpp_utils/BLECharacteristic.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,43 @@ void BLECharacteristic::setValue(std::string value) {
683683
setValue((uint8_t*)(value.data()), value.length());
684684
} // setValue
685685

686+
void BLECharacteristic::setValue(uint16_t& data16) {
687+
uint8_t temp[2];
688+
temp[0]=data16;
689+
temp[1]=data16>>8;
690+
setValue(temp, 2);
691+
} // setValue
692+
693+
void BLECharacteristic::setValue(uint32_t& data32) {
694+
uint8_t temp[4];
695+
temp[0]=data32;
696+
temp[1]=data32>>8;
697+
temp[2]=data32>>16;
698+
temp[3]=data32>>24;
699+
setValue(temp, 4);
700+
} // setValue
701+
702+
void BLECharacteristic::setValue(int& data32) {
703+
uint8_t temp[4];
704+
temp[0]=data32;
705+
temp[1]=data32>>8;
706+
temp[2]=data32>>16;
707+
temp[3]=data32>>24;
708+
setValue(temp, 4);
709+
} // setValue
710+
711+
void BLECharacteristic::setValue(float& data32) {
712+
uint8_t temp[4];
713+
*((float *)temp) = data32;
714+
setValue(temp, 4);
715+
} // setValue
716+
717+
void BLECharacteristic::setValue(double& data64) {
718+
uint8_t temp[8];
719+
*((double *)temp) = data64;
720+
setValue(temp, 8);
721+
} // setValue
722+
686723

687724
/**
688725
* @brief Set the Write No Response property value.

cpp_utils/BLECharacteristic.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class BLECharacteristic {
7575
void setReadProperty(bool value);
7676
void setValue(uint8_t* data, size_t size);
7777
void setValue(std::string value);
78+
void setValue(uint16_t& data16);
79+
void setValue(uint32_t& data32);
80+
void setValue(int& data32);
81+
void setValue(float& data32);
82+
void setValue(double& data64);
7883
void setWriteProperty(bool value);
7984
void setWriteNoResponseProperty(bool value);
8085
std::string toString();

0 commit comments

Comments
 (0)
0