-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathconv.comp.in
More file actions
28 lines (27 loc) · 806 Bytes
/
conv.comp.in
File metadata and controls
28 lines (27 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
component conv_@IN@_@OUT@ "Convert a value from @IN@ to @OUT@";
pin in @IN@ in;
pin out @OUT@ out;
@CC@pin out bit out_of_range "TRUE when 'in' is not in the range of @OUT@";
@CC@param rw bit clamp """If TRUE, then clamp to the range of @OUT@. If FALSE, then allow the value to "wrap around".""";
option period no;
function _ "Update 'out' based on 'in'";
license "GPL";
author "Jeff Epler";
;;
#include <rtapi_stdint.h>
FUNCTION(_) {
@TYPI@ val = in;
@CC@ if(clamp) {
#if @MAXEN@ == 0
@CC@ if(val > (@TYPI@)@MAX@) { out = @MAX@; out_of_range = 1; return; }
#endif
#if @MINEN@ == 0
@CC@ if(val < (@TYPI@)@MIN@) { out = @MIN@; out_of_range = 1; return; }
#endif
@CC@ out = (@TYPO@)val;
@CC@ out_of_range = 0;
@CC@ } else {
out = (@TYPO@)val;
@CC@ if((@TYPI@)out != val) out_of_range = 1;
@CC@ }
}