"Calculate offset given Divisor and both minimums."
(- scaled-min (/ raw-min divisor)))
-(defun scale (raw-max raw-min scaled-max scaled-min)
- "Calculate the divisor and offset, given the parameters."
+(defun count-scale (raw-max raw-min scaled-max scaled-min)
+ "Calculate the divisor and offset, from counts and eng values."
(let* ((div (divisor raw-max raw-min scaled-max scaled-min)))
(list div (offset div scaled-min raw-min))))
+(defun scale (signal-max signal-min engineering-max engineering-min &optional impedance)
+ "Calculate the divisor and offset, from signal and eng values.
+Current signal if `impedance' is not nil, otherwise voltage signal.
+Uses `count-range', which uses `*plc-resolution*' and `*plc-max-voltage*'
+variables."
+ (let* ((rng (if impedance
+ (count-range (amps->volts signal-max impedance)
+ (amps->volts signal-min impedance))
+ (count-range signal-max signal-min)))
+ (pmax (car rng))
+ (pmin (cadr rng)))
+ (count-scale pmax pmin engineering-max engineering-min)))
+
(defun final (analog-input divisor offset)
"Calculate the scaled value of an input."
(+ (/ analog-input divisor) offset))