From 446f00e554313273a7885e14aa5c1b5c72bd73b9 Mon Sep 17 00:00:00 2001 From: rearman Date: Tue, 26 Aug 2025 16:29:30 -0400 Subject: [PATCH] Clean up defuns Make args more clear, factor when possible --- re/re-plc-defuns.el | 25 +++++++++++++------------ re/re-refrigeration-defuns.el | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/re/re-plc-defuns.el b/re/re-plc-defuns.el index b55020e..17bab1c 100644 --- a/re/re-plc-defuns.el +++ b/re/re-plc-defuns.el @@ -47,18 +47,19 @@ Converts the amperage to a voltage using `amps->volts',then applies "Given an upper and lower PLC count, return the list of upper and lower voltage." (list (counts->volts upper) (counts->volts lower))) -(defun divisor (raw-max raw-min scaled-max scaled-min) +(defun divisor (counts-max counts-min engineering-max engineering-min) "Calculate 1/slope given PLC Max/Min and Eng. Max/Min." - (/ (float (- raw-max raw-min)) (- scaled-max scaled-min))) + (/ (float (- counts-max counts-min)) (- engineering-max engineering-min))) -(defun offset (divisor scaled-min raw-min) +(defun offset (divisor engineering-min counts-min) "Calculate offset given Divisor and both minimums." - (- scaled-min (/ raw-min divisor))) + (- engineering-min (/ counts-min divisor))) -(defun count-scale (raw-max raw-min scaled-max scaled-min) +(defun count-scale (counts-max counts-min engineering-max engineering-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)))) + (let* ((div (divisor counts-max counts-min engineering-max engineering-min)) + (ofst (offset div engineering-min counts-min))) + (list div ofst))) (defun scale (signal-max signal-min engineering-max engineering-min &optional impedance) "Calculate the divisor and offset, from signal and eng values. @@ -69,13 +70,13 @@ variables." (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))) + (counts-max (car rng)) + (counts-min (cadr rng))) + (count-scale counts-max counts-min engineering-max engineering-min))) -(defun final (analog-input divisor offset) +(defun final (counts divisor offset) "Calculate the scaled value of an input." - (+ (/ analog-input divisor) offset)) + (+ (/ counts divisor) offset)) (defun input (scaled-value divisor offset) "Calculate the input counts from a scaled value." diff --git a/re/re-refrigeration-defuns.el b/re/re-refrigeration-defuns.el index c9381aa..5a0e4e7 100644 --- a/re/re-refrigeration-defuns.el +++ b/re/re-refrigeration-defuns.el @@ -19,25 +19,28 @@ Inputs are feet/minute, width (ft) and height (ft)." (defun sat-water-press (temp) "Calculate the saturated water pressure at a temp (F)." - (+ 0.0182795 - (* temp 0.001029904) - (* (square temp) (E 2.579408 -5) - (* (cube temp) (E 2.400493 -7)) + (+ (E 1.82795 -2) + (* temp (E 1.029904 -3)) + (* (^ temp 2) (E 2.579408 -5)) + (* (^ temp 3) (E 2.400493 -7)) (* (^ temp 4) (E 8.100939 -10)) (* (^ temp 5) (E 3.256805 -11)) (* (^ temp 6) (E -1.001922 -13)) - (* (^ temp 7) (E 2.44161 -16))))) + (* (^ temp 7) (E 2.44161 -16)))) -(defun hum-ratio (humidity swp) +(defun hum-press (humidity swp) + "Calculate the Humidity-Pressure." + (* (/ humidity 100.0) swp)) + +(defun hum-ratio (humidity-pressure) "Calulate the humidity ratio. -Takes humidity in %RH, and a Saturated Water Pressure." - (let ((hum-press (* (/ humidity 100.0) swp))) - (/ (* hum-press 0.62198) (- 14.7 hum-press)))) +Takes humidity-pressure." + (/ (* humidity-pressure 0.62198) (- 14.7 humidity-pressure))) (defun gn-water-per-lb (humidity temp) "Calculate the grains of water per lb of air. Takes humidity in %RH, and temp in F." - (* 7000 (hum-ratio humidity (sat-water-press temp)))) + (* 7000 (hum-ratio (hum-press humidity (sat-water-press temp))))) (provide 're-refrigeration-defuns) ;;; re-refrigeration-defuns.el ends here -- 2.39.5