Hi all,
I need a component which will output the difference between a latched value
(float) and the current value. I did not see anything fitting that bill, so
I wrote my own. Any suggestions on making the component more generic, more
widely applicable, or simply recommendations on such things as naming
conventions and use of pins vs. parameters for purposes of consistency with
other components is appreciated.
The source code is included at the end of this email. It compiles, but I
have not linked it into a configuration, so as simple as it is, it is
otherwise untested.
The component is intended to work as follows:
Inputs:
Name Type Description
in float Input to latch or perform difference
enable bit Enable the component
latch bit Latch "in" on selected transition
Outputs:
Name Type
out0 float Difference between latched value and "in"
out1 float Latched value
Parameters:
Name Type
absolute bit Generate absolute value of difference
rising bit When high, trigger on rising edge, else trigger on falling
edge.
If "enable" is low, then "out0" is set to 0.0 and "out1" is set to "in". If
"enable" is high, the component latches "in" on the specified transition. If
"absolute" is high, "out0" will be set to the absolute value of the
difference between the latched value and "in", otherwise it is set to the
signed difference between the latched value and "in". In either case, "out1"
is set to the latched value.
I see one potential problem from a usability stand point, in that when
"enable" goes high, "out1" will be set to zero (0.0) until the specified
transition is seen in "latch". If no value has been latched, but the
component is enabled, it would probably be more useful to set "out1" to in.
Regards,
Eric
--------- Source Code of latchdiff.comp ------------------
component latchdiff "output difference from latched value";
pin in float in "value to latch";
pin in bit enable "enable latching";
pin in bit latch "latch value on rising edge";
pin out float out0 "difference from latched value";
pin out float out1 "latched value";
param rw bit absolute=FALSE "Output absolute value of difference";
param rw bit rising=TRUE "Select latching on rising or falling edge";
option data internal;
option extra_setup yes;
function _ "Produce difference from a latched value";
license "GPL";
;;
typedef struct {
float oldIn;
char oldLatch;
float latchedVal;
} internal;
EXTRA_SETUP(){
data.oldIn = 0.0;
data.oldLatch = 0;
data.latchedVal = 0.0;
return 0;
}
FUNCTION(_){
int new, old, trigger;
float newIn;
if (!enable) {
out0 = 0.0;
out1 = in;
return;
}
new = latch;
old = data.oldLatch;
newIn = in;
trigger = 0;
/* detect edges */
if (new && (!old) && rising) trigger = 1;
if (old && (!new) && (!rising)) trigger = 1;
data.oldLatch = new;
if ( trigger ) {
/* Latch the value */
data.latchedVal = in;
}
/* drive outputs */
if (absolute) {
if (newIn >= data.latchedVal) out0 = newIn - data.latchedVal;
else out0 = data.latchedVal - newIn;
}
else out0 = newIn - data.latchedVal;
out1 = data.latchedVal;
}
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables
unlimited royalty-free distribution of the report engine
for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers