]> git.earman.xyz Git - emacsinit.git/commitdiff
Clean up defuns
authorrearman <rearman@r717.net>
Tue, 26 Aug 2025 20:29:30 +0000 (16:29 -0400)
committerrearman <rearman@r717.net>
Tue, 26 Aug 2025 20:29:30 +0000 (16:29 -0400)
Make args more clear, factor when possible

re/re-plc-defuns.el
re/re-refrigeration-defuns.el

index b55020e42e55d71134ddb6dd9d47e5e9f58ace2f..17bab1cb83dec6bbfac2f25365f360b7edd177ac 100644 (file)
@@ -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."
index c9381aaab053fbec6810bde0ddedfef66ee56753..5a0e4e7d6d6cf5e0f3b03db2ad28c6735eb533c9 100644 (file)
@@ -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