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

"±" Signed conditional and "abs" post_procs #533

Merged
merged 1 commit into from
Apr 1, 2024
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
2 changes: 2 additions & 0 deletions docs/participate/adding-decoders.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ Valid operations are:
- "*" multiply
- "+" add
- "-" subtract
- "±" signed conditional add or subtract
- "%" modulo
- "<" shift left
- ">" shift right
Expand All @@ -323,6 +324,7 @@ Valid operations are:
- "^" Logical XOR the values
- "min" the minimum allowed value
- "max" the maximum allowed value
- "abs" absolute value

`lookup` This specifies a lookup table for any decoded "string_from_hex_data" string. If the string is defined in the table its related string will be assigned to the property. If no matching hex string is present the property is defined as not decoded.

Expand Down
10 changes: 9 additions & 1 deletion src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,15 @@ int TheengsDecoder::decodeBLEJson(JsonObject& jsondata) {
if (temp_val < post_proc[i + 1].as<double>()) {
temp_val = post_proc[i + 1].as<double>();
}
}
} else if (strncmp(post_proc[i].as<const char*>(), "±", 1) == 0) {
if (temp_val < 0) {
temp_val += post_proc[i + 1].as<double>();
} else {
temp_val -= post_proc[i + 1].as<double>();
}
} else if (strncmp(post_proc[i].as<const char*>(), "abs", 3) == 0) {
temp_val = abs(temp_val);
}
}
}
}
Expand Down
Loading