Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Nov 28, 2023
1 parent 38a7aaa commit 35193ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/config/RFConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OpenShock::Config {
struct RFConfig : public ConfigBase<Serialization::Configuration::RFConfig> {
std::uint8_t txPin;
bool keepAliveEnabled;

void ToDefault() override;

Expand Down
17 changes: 14 additions & 3 deletions src/config/RFConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const char* const TAG = "Config::RFConfig";
using namespace OpenShock::Config;

void RFConfig::ToDefault() {
txPin = 0U;
txPin = 0U;
keepAliveEnabled = true;
}

bool RFConfig::FromFlatbuffers(const Serialization::Configuration::RFConfig* config) {
Expand All @@ -16,13 +17,14 @@ bool RFConfig::FromFlatbuffers(const Serialization::Configuration::RFConfig* con
return false;
}

txPin = config->tx_pin();
txPin = config->tx_pin();
keepAliveEnabled = config->keepalive_enabled();

return true;
}

flatbuffers::Offset<OpenShock::Serialization::Configuration::RFConfig> RFConfig::ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder) const {
return Serialization::Configuration::CreateRFConfig(builder, txPin);
return Serialization::Configuration::CreateRFConfig(builder, txPin, keepAliveEnabled);
}

bool RFConfig::FromJSON(const cJSON* json) {
Expand All @@ -44,13 +46,22 @@ bool RFConfig::FromJSON(const cJSON* json) {

txPin = txPinJson->valueint;

const cJSON* keepAliveEnabledJson = cJSON_GetObjectItemCaseSensitive(json, "keepAliveEnabled");
if (!cJSON_IsBool(keepAliveEnabledJson)) {
ESP_LOGE(TAG, "value at 'keepAliveEnabled' is not a bool");
return false;
}

keepAliveEnabled = cJSON_IsTrue(keepAliveEnabledJson);

return true;
}

cJSON* RFConfig::ToJSON() const {
cJSON* root = cJSON_CreateObject();

cJSON_AddNumberToObject(root, "txPin", txPin);
cJSON_AddBoolToObject(root, "keepAliveEnabled", keepAliveEnabled);

return root;
}

0 comments on commit 35193ef

Please sign in to comment.