Skip to content

Commit

Permalink
"±" Signed conditional and "abs" post_procs (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiH authored Apr 1, 2024
1 parent c175005 commit f3cb71e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit f3cb71e

Please sign in to comment.