mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 01:34:18 +01:00
Adapt to new bytebuffer
This commit is contained in:
parent
e4bef0c2a3
commit
7e82aadbb7
2 changed files with 8 additions and 2 deletions
|
@ -112,7 +112,7 @@ bool BLEServer::create_device_characteristics_() {
|
||||||
if (this->model_.has_value()) {
|
if (this->model_.has_value()) {
|
||||||
BLECharacteristic *model =
|
BLECharacteristic *model =
|
||||||
this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ);
|
this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ);
|
||||||
model->set_value(ByteBuffer::wrap(this->model_.value()));
|
model->set_value(ByteBuffer::wrap(std::vector<uint8_t>(this->model_.value().begin(), this->model_.value().end())));
|
||||||
} else {
|
} else {
|
||||||
BLECharacteristic *model =
|
BLECharacteristic *model =
|
||||||
this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ);
|
this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ);
|
||||||
|
@ -125,7 +125,7 @@ bool BLEServer::create_device_characteristics_() {
|
||||||
|
|
||||||
BLECharacteristic *manufacturer =
|
BLECharacteristic *manufacturer =
|
||||||
this->device_information_service_->create_characteristic(MANUFACTURER_UUID, BLECharacteristic::PROPERTY_READ);
|
this->device_information_service_->create_characteristic(MANUFACTURER_UUID, BLECharacteristic::PROPERTY_READ);
|
||||||
manufacturer->set_value(ByteBuffer::wrap(this->manufacturer_));
|
manufacturer->set_value(ByteBuffer::wrap(std::vector<uint8_t>(this->manufacturer_.begin(), this->manufacturer_.end())));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,36 +27,42 @@ ByteBuffer ByteBuffer::wrap(std::vector<uint8_t> data, Endian endianness) {
|
||||||
ByteBuffer ByteBuffer::wrap(uint8_t value) {
|
ByteBuffer ByteBuffer::wrap(uint8_t value) {
|
||||||
ByteBuffer buffer = ByteBuffer::create(1);
|
ByteBuffer buffer = ByteBuffer::create(1);
|
||||||
buffer.put_uint8(value);
|
buffer.put_uint8(value);
|
||||||
|
buffer.flip();
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer ByteBuffer::wrap(uint16_t value, Endian endianness) {
|
ByteBuffer ByteBuffer::wrap(uint16_t value, Endian endianness) {
|
||||||
ByteBuffer buffer = ByteBuffer::create(2, endianness);
|
ByteBuffer buffer = ByteBuffer::create(2, endianness);
|
||||||
buffer.put_uint16(value);
|
buffer.put_uint16(value);
|
||||||
|
buffer.flip();
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer ByteBuffer::wrap(uint32_t value, Endian endianness) {
|
ByteBuffer ByteBuffer::wrap(uint32_t value, Endian endianness) {
|
||||||
ByteBuffer buffer = ByteBuffer::create(4, endianness);
|
ByteBuffer buffer = ByteBuffer::create(4, endianness);
|
||||||
buffer.put_uint32(value);
|
buffer.put_uint32(value);
|
||||||
|
buffer.flip();
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer ByteBuffer::wrap(uint64_t value, Endian endianness) {
|
ByteBuffer ByteBuffer::wrap(uint64_t value, Endian endianness) {
|
||||||
ByteBuffer buffer = ByteBuffer::create(8, endianness);
|
ByteBuffer buffer = ByteBuffer::create(8, endianness);
|
||||||
buffer.put_uint64(value);
|
buffer.put_uint64(value);
|
||||||
|
buffer.flip();
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer ByteBuffer::wrap(float value, Endian endianness) {
|
ByteBuffer ByteBuffer::wrap(float value, Endian endianness) {
|
||||||
ByteBuffer buffer = ByteBuffer::create(sizeof(float), endianness);
|
ByteBuffer buffer = ByteBuffer::create(sizeof(float), endianness);
|
||||||
buffer.put_float(value);
|
buffer.put_float(value);
|
||||||
|
buffer.flip();
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer ByteBuffer::wrap(double value, Endian endianness) {
|
ByteBuffer ByteBuffer::wrap(double value, Endian endianness) {
|
||||||
ByteBuffer buffer = ByteBuffer::create(sizeof(double), endianness);
|
ByteBuffer buffer = ByteBuffer::create(sizeof(double), endianness);
|
||||||
buffer.put_double(value);
|
buffer.put_double(value);
|
||||||
|
buffer.flip();
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue