Skip to content

Commit

Permalink
Add a BLE Output class for PropertyPoint setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Xasin committed Aug 26, 2021
1 parent f114eb7 commit 1324be9
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
34 changes: 34 additions & 0 deletions ESP32/PropertyPoint/BLEOutput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

#include "include/xnm/property_point/BLEOutput.h"

namespace XNM {
namespace PropertyPoint {

BLEOutput::BLEOutput(Handler &handler, BLE::Server &ble_server)
:
BaseOutput(handler), ble(ble_server, ble_srv_uuid, ble_chr_uuid) {

}

void BLEOutput::send_upd_json(const cJSON * item, BaseProperty &prop) {
cJSON * out_obj = cJSON_CreateObject();

cJSON * upd_obj = cJSON_CreateObject();
cJSON_AddItemToObjectCS(out_obj, "upd", upd_obj);

cJSON_AddItemReferenceToObject(upd_obj, prop.key, const_cast<cJSON*>(item));

char * out = cJSON_Print(out_obj);

ble.send_str(out);

cJSON_free(out);
cJSON_Delete(out_obj);
}

void BLEOutput::init() {
ble.init();
}

}
}
6 changes: 4 additions & 2 deletions ESP32/PropertyPoint/BaseProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ BaseProperty::BaseProperty(Handler &handler, const char *key) :
key(key), readonly(false),
initialized(true),
on_update(nullptr) {

handler.insert_property(*this);
}

void BaseProperty::poke_update() {
Expand Down Expand Up @@ -66,5 +64,9 @@ BaseOutput * BaseProperty::get_truthholder() {
return truth_holder;
}

void BaseProperty::init() {
handler.insert_property(*this);
}

}
}
4 changes: 2 additions & 2 deletions ESP32/PropertyPoint/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

idf_component_register(SRCS "CustomProperty.cpp" "JSONProperty.cpp" "SingleProperty.cpp" "BaseHandler.cpp" "BaseOutput.cpp"
idf_component_register(SRCS "BLEOutput.cpp" "CustomProperty.cpp" "JSONProperty.cpp" "SingleProperty.cpp" "BaseHandler.cpp" "BaseOutput.cpp"
"BaseProperty.cpp" "MQTTOutput.cpp"
"SingleProperty.cpp" "JSONProperty.cpp"
"CustomProperty.cpp"
INCLUDE_DIRS "include"
REQUIRES json MQTT_SubHandler NeoController)
REQUIRES json MQTT_SubHandler NeoController xnm-ble)
32 changes: 32 additions & 0 deletions ESP32/PropertyPoint/include/xnm/property_point/BLEOutput.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

#pragma once

#include "BaseHandler.h"
#include "BaseOutput.h"
#include "BaseProperty.h"

#include <xnm/ble.h>

namespace XNM {
namespace PropertyPoint {

static const ble_uuid128_t ble_srv_uuid =
XNM_BLE_UUID(0x50, 0x50, 0, 0);
static const ble_uuid128_t ble_chr_uuid =
XNM_BLE_UUID(0x50, 0x50, 0, 1);

class BLEOutput : public BaseOutput {
private:
BLE::StringStream ble;

protected:
void send_upd_json(const cJSON * item, BaseProperty &prop);

public:
BLEOutput(Handler & handler, BLE::Server & ble);

void init();
};

}
}
5 changes: 5 additions & 0 deletions ESP32/PropertyPoint/include/xnm/property_point/BaseProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ friend Handler;
virtual void process_json_command(const cJSON * data);

BaseOutput * get_truthholder();

// Must be called to link this property up to the main
// property handler, to avoid initialization reorders issues.
// May also do other things, I suppose.
virtual void init();
};

}
Expand Down

0 comments on commit 1324be9

Please sign in to comment.