Skip to content

Commit

Permalink
Revert "Better checking for shocker types, fix rmt sending causing cr…
Browse files Browse the repository at this point in the history
…ashes (#149)"

This reverts commit 4fb17d1.
  • Loading branch information
LucHeart authored Jan 22, 2024
1 parent 072fa59 commit 62b2615
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
20 changes: 0 additions & 20 deletions include/ShockerModelType.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,7 @@
#include "serialization/_fbs/ShockerModelType_generated.h"

#include <cstdint>
#include <cstring>

namespace OpenShock {
typedef OpenShock::Serialization::Types::ShockerModelType ShockerModelType;

inline bool ShockerModelTypeFromString(const char* str, ShockerModelType& out, bool allowTypo = false) {
if (strcasecmp(str, "caixianlin") == 0 || strcasecmp(str, "cai-xianlin") == 0) {
out = ShockerModelType::CaiXianlin;
return true;
}

if (strcasecmp(str, "petrainer") == 0) {
out = ShockerModelType::Petrainer;
return true;
}

if (allowTypo && strcasecmp(str, "pettrainer") == 0) {
out = ShockerModelType::Petrainer;
return true;
}

return false;
}
} // namespace OpenShock
2 changes: 1 addition & 1 deletion include/radio/rmt/internal/Shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace OpenShock::Rmt::Internal {
static_assert(N > 0, "N must be greater than 0");
static_assert(N < std::numeric_limits<T>::digits, "N must be less or equal to the number of bits in T");

for (std::int64_t bit_pos = N - 1; bit_pos >= 0; --bit_pos) {
for (std::size_t bit_pos = N - 1; bit_pos >= 0; --bit_pos) {
pulses.push_back((data >> bit_pos) & 1 ? rmtOne : rmtZero);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/serialization/JsonAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ bool JsonAPI::ParseDeviceInfoJsonResponse(int code, const cJSON* root, JsonAPI::
}

OpenShock::ShockerModelType shockerModelType;
if (!OpenShock::ShockerModelTypeFromString(shockerModelStr, shockerModelType, true)) { // PetTrainer is a typo in the API, we pass true to allow it
if (strcmp(shockerModelStr, "caixianlin") == 0 || strcmp(shockerModelStr, "cai-xianlin") == 0 || strcmp(shockerModelStr, "CaiXianlin") == 0) {
shockerModelType = OpenShock::ShockerModelType::CaiXianlin;
} else if (strcmp(shockerModelStr, "petrainer") == 0 || strcmp(shockerModelStr, "Petrainer") == 0) {
shockerModelType = OpenShock::ShockerModelType::Petrainer;
} else {
ESP_LOGJSONE("value at 'shocker.model' is not a valid shocker model", shocker);
return false;
}
Expand Down
6 changes: 5 additions & 1 deletion src/serialization/JsonSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ bool JsonSerial::ParseShockerCommand(const cJSON* root, JsonSerial::ShockerComma
return false;
}
ShockerModelType modelType;
if (!ShockerModelTypeFromString(model->valuestring, modelType)) {
if (strcmp(model->valuestring, "caixianlin") == 0) {
modelType = ShockerModelType::CaiXianlin;
} else if (strcmp(model->valuestring, "petrainer") == 0) {
modelType = ShockerModelType::Petrainer;
} else {
ESP_LOGE(TAG, "value at 'model' is not a valid shocker model (caixianlin, petrainer)");
return false;
}
Expand Down

0 comments on commit 62b2615

Please sign in to comment.