Skip to content

Commit

Permalink
Merge branch 'develop' into wifi-scanning-qol
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc authored Dec 5, 2023
2 parents 7b9513c + 91c17fe commit bab0ccd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
18 changes: 18 additions & 0 deletions include/ShockerCommandType.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,22 @@

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

inline bool ShockerCommandTypeFromString(const char* str, ShockerCommandType& out) {
if (strcasecmp(str, "stop") == 0) {
out = ShockerCommandType::Stop;
return true;
} else if (strcasecmp(str, "shock") == 0) {
out = ShockerCommandType::Shock;
return true;
} else if (strcasecmp(str, "vibrate") == 0) {
out = ShockerCommandType::Vibrate;
return true;
} else if (strcasecmp(str, "sound") == 0) {
out = ShockerCommandType::Sound;
return true;
} else {
return false;
}
}
} // namespace OpenShock
10 changes: 1 addition & 9 deletions src/serialization/JsonSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,7 @@ bool JsonSerial::ParseShockerCommand(const cJSON* root, JsonSerial::ShockerComma
return false;
}
ShockerCommandType commandType;
if (strcmp(command->valuestring, "stop") == 0) {
commandType = ShockerCommandType::Stop;
} else if (strcmp(command->valuestring, "shock") == 0) {
commandType = ShockerCommandType::Shock;
} else if (strcmp(command->valuestring, "vibrate") == 0) {
commandType = ShockerCommandType::Vibrate;
} else if (strcmp(command->valuestring, "sound") == 0) {
commandType = ShockerCommandType::Sound;
} else {
if (!ShockerCommandTypeFromString(command->valuestring, commandType)) {
ESP_LOGE(TAG, "value at 'type' is not a valid shocker command (stop, shock, vibrate, sound)");
return false;
}
Expand Down

0 comments on commit bab0ccd

Please sign in to comment.