Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new BLEStringCharacateristic type #5

Merged
merged 1 commit into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BLELongCharacteristic KEYWORD1
BLEUnsignedLongCharacteristic KEYWORD1
BLEFloatCharacteristic KEYWORD1
BLEDoubleCharacteristic KEYWORD1
BLEStringCharacteristic KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
Expand Down
1 change: 1 addition & 0 deletions src/ArduinoBLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "local/BLELocalDevice.h"
#include "BLEProperty.h"
#include "BLEStringCharacteristic.h"
#include "BLETypedCharacteristics.h"

#endif
45 changes: 45 additions & 0 deletions src/BLEStringCharacteristic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
This file is part of the ArduinoBLE library.
Copyright (c) 2018 Arduino SA. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "BLEStringCharacteristic.h"

BLEStringCharacteristic::BLEStringCharacteristic(const char* uuid, unsigned char properties, int valueSize) :
BLECharacteristic(uuid, properties, valueSize)
{
}

int BLEStringCharacteristic::writeValue(const String& value)
{
return BLECharacteristic::writeValue(value.c_str());
}

String BLEStringCharacteristic::value(void)
{
String str;
int length = BLECharacteristic::valueLength();
const uint8_t* val = BLECharacteristic::value();

str.reserve(length);

for (int i = 0; i < length; i++) {
str += (char)val[i];
}

return str;
}
39 changes: 39 additions & 0 deletions src/BLEStringCharacteristic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
This file is part of the ArduinoBLE library.
Copyright (c) 2018 Arduino SA. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef _BLE_STRING_CHARACTERISTIC_H_
#define _BLE_STRING_CHARACTERISTIC_H_

#include <Arduino.h>

#include "BLECharacteristic.h"

class BLEStringCharacteristic : public BLECharacteristic
{
public:
BLEStringCharacteristic(const char* uuid, unsigned char properties, int valueSize);

int writeValue(const String& value);
int setValue(const String& value) { return writeValue(value); }
String value(void);

private:
};

#endif