]> git.earman.xyz Git - emacsinit.git/commitdiff
Factor various defuns to match use in forth image
authorrearman <rearman@r717.net>
Thu, 20 Mar 2025 16:49:25 +0000 (12:49 -0400)
committerrearman <rearman@r717.net>
Thu, 20 Mar 2025 16:49:25 +0000 (12:49 -0400)
re/re-electronics-defuns.el
re/re-packages.el
re/re-plc-defuns.el
re/re-refrigeration-defuns.el
re/re-unit-conversions.el [new file with mode: 0644]

index f3abfa6b950d6b88cfac7f552349e4445693034d..d73948d98cd00e8d401fcc5c9efb031131515bbc 100644 (file)
@@ -7,24 +7,20 @@
 
 (defun eff-imp (r1 &optional r2)
   "Calculate the effective input impedance, given two resistances.
-For use in `amps->volts' and related.  The handling of only one
-resistance given is done here, instead of doing it in every
-function that uses this."
-  (if (eq nil r2)
-      r1
-    (inv (+ (inv r1) (inv r2)))))
+For use in `amps->volts' and related."
+  (inv (+ (inv r1) (inv r2))))
 
-(defun amps->volts (amps r1 &optional r2)
+(defun amps->volts (amps imp)
   "Calculate the voltage, given amperage and impedance.
 Multiplies the amperage by the effective impedance calculated
 with `eff-imp'."
-  (* amps (eff-imp r1 r2)))
+  (* amps imp))
 
-(defun volts->amps (volts r1 &optional r2)
+(defun volts->amps (volts imp)
   "Calculate the amperage, given voltage and impedance.
 Divides the voltage by the effective impedance calculated with
 `eff-imp'."
-  (/ volts (eff-imp r1 r2)))
+  (/ volts imp))
 
 (provide 're-electronics-defuns)
 ;;; re-electronics-defuns.el ends here
index 77bf61af7f3e5be26e56b3a37869bad3681efbc3..483795b9baa3cbc113c7c6ca7a540e22cd502239 100644 (file)
@@ -24,9 +24,9 @@
   (visual-fill-column-enable-sensible-window-split t))
 
 (keymap-global-set "C-c v"
-                   (lambda nil
-                     (interactive)
-                     (visual-fill-column-mode 'toggle)))
+                  (lambda nil
+                    (interactive)
+                    (visual-fill-column-mode 'toggle)))
 
 (use-package corfu
   :ensure
   :config
   (openwith-mode t)
   (setq openwith-associations
-        (list (list (openwith-make-extension-regexp
-                     '("xls" "xlsx" "doc" "docx" "ppt" "pptx" "odt" "ods" "odg" "odp"))
-                    "libreoffice"
-                    '(file))  ; Windows falls back to system default
-              (list (openwith-make-extension-regexp
-                     '("adpro"))
-                    "ProductivitySuite"
-                    '(file))
-              (list (openwith-make-extension-regexp
-                     '("pdf"))
-                    "zathura"
-                    '(file)))))  ; Windows falls back to ms-office
+       (list (list (openwith-make-extension-regexp
+                    '("xls" "xlsx" "doc" "docx" "ppt" "pptx" "odt" "ods" "odg" "odp"))
+                   "libreoffice"
+                   '(file))  ; Windows falls back to system default
+             (list (openwith-make-extension-regexp
+                    '("adpro"))
+                   "ProductivitySuite"
+                   '(file))
+             (list (openwith-make-extension-regexp
+                    '("pdf"))
+                   "zathura"
+                   '(file)))))  ; Windows falls back to ms-office
 
 (use-package auctex :ensure t :defer t)
 
@@ -97,7 +97,7 @@
   (slime-net-coding-system 'utf-8-unix))
 
 (add-hook 'slime-mode-hook
-          (lambda nil (unless (slime-connected-p) (save-excursion (slime)))))
+         (lambda nil (unless (slime-connected-p) (save-excursion (slime)))))
 
 (use-package paredit :ensure t :bind (("C-c p" quote paredit-mode)))
 
index 8a2fbc521b793cfbbe83649db7929e84e6982524..554beceae345b422ea72878771eeeb833e701273 100644 (file)
@@ -8,21 +8,16 @@
 (defvar *plc-resolution* 16)
 (defvar *plc-max-voltage* 10.0)
 
-(defun P3K ()
-  (setq *plc-resolution* 16
-       *plc-max-voltage* 10.0))
+(defun 16B () (setq *plc-resolution* 16
+                   *plc-max-voltage* 10.0))
 
-(defun SLC ()
-  (setq *plc-resolution* 16
-       *plc-max-voltage* 10.0))
+(defun 13B () (setq *plc-resolution* 13
+                   *plc-max-voltage* 10.0))
 
-(defun P1K ()
-  (setq *plc-resolution* 16
-       *plc-max-voltage* 10.0))
-
-(defun DL4 ()
-  (setq *plc-resolution* 13
-       *plc-max-voltage* 10.0))
+(defalias 'P3K '16B)
+(defalias 'SLC '16B)
+(defalias 'P1K '13B)
+(defalias 'DL4 '13B)
 
 (defun max-counts (resolution)
   "Calculate the max count for a PLC analog, given card's bit-resolution."
@@ -38,12 +33,11 @@ Calculates a ratio of vin/vmax, then scales by `max-counts'."
 Calculates a ratio of cin/`max-counts', then multiplies by vmax."
   (* (/ cin (max-counts *plc-resolution*)) *plc-max-voltage*))
 
-(defun amps->counts (amps r1 &optional r2)
+(defun amps->counts (amps imp)
   "Convert a current signal to PLC Counts.
-Converts the amperage to a voltage using `amps->volts' (with r1
-and optional r2), then applies `volts->counts' to the resulting
-voltage, vmax, and resolution."
-  (volts->counts *plc-max-voltage* (amps->volts amps r1 r2) *plc-resolution*))
+Converts the amperage to a voltage using `amps->volts',then applies
+ `volts->counts' to the resulting voltage,vmax, and resolution."
+  (volts->counts *plc-max-voltage* (amps->volts amps imp) *plc-resolution*))
 
 (defun count-range (upper lower)
   "Given an upper and lower voltage, return the list of upper and lower PLC counts."
index 50cc14fca6abbd0e305cc7f332afc8e605e4784e..c9381aaab053fbec6810bde0ddedfef66ee56753 100644 (file)
@@ -4,94 +4,7 @@
 ;;; Code:
 
 (require 're-math-defuns)
-
-;; Unit wendings
-
-;;; Leŋþ
-(defun mm->in (mm)
-  "Convert milimeters to inches."
-  (/ mm 25.4))
-
-(defun in->mm (in)
-  "Convert inches to milimeters."
-  (* in 25.4))
-
-;;; Heat
-(defun k->c (tempk)
-  "Convert degrees Kelvin to degrees Celsius."
-  (- tempk 273.15))
-
-(defun c->k (tempc)
-  "Convert degrees Celsius to degrees Kelvin."
-  (+ tempc 273.15))
-
-(defun c->f (tempc)
-  "Convert degrees Celsius to degrees Fahrenheit."
-  (+ (* tempc 1.8) 32.0))
-
-(defun f->c (tempf)
-  "Convert degrees Fahrenheit to degrees Celsius."
-  (/ (- tempf 32.0) 1.8))
-
-(defun k->f (tempk)
-  "Convert degrees Kelvin to degrees Fahrenheit.
-Applies `c->f' to `k->c'."
-  (c->f (k->c tempk)))
-
-(defun f->k (tempf)
-  "Convert degrees Fahrenheit to degrees Kelvin.
-Applies `c->k' to `f->c'."
-  (c->k (f->c tempf)))
-
-;;; Pressure
-(defun bar->psi (bar)
-  "Convert bar to psi."
-  (* 14.5 bar))
-
-(defun psi->bar (psi)
-  "Convert psi to bar."
-  (/ psi 14.5))
-
-(defun kpa->psi (kpa)
-  "Convert kpa to psi."
-  (* 6.89 kpa))
-
-(defun psi->kpa (psi)
-  "Convert psi to kpa."
-  (/ psi 6.89))
-
-(defun mmhg->psi (mmhg)
-  "Convert mmhg to psi."
-  (/ mmhg 51.71))
-
-(defun psi->mmhg (psi)
-  "Convert psi to mmhg."
-  (* 51.71 psi))
-
-(defun inhg->psi (inhg)
-  "Convert inhg to psi."
-  (mmhg->psi (in->mm inhg)))
-
-(defun psi->inhg (psi)
-  "Convert psi to inhg."
-  (mm->in (psi->mmhg psi)))
-
-;;; Weight
-(defun g->oz (grams)
-  "Convert grams to ounces."
-  (/ grams 28.34))
-
-(defun oz->g (ounces)
-  "Convert ounces to grams."
-  (* ounces 28.34))
-
-(defun kg->lb (kilograms)
-  "Convert kilograms to pounds."
-  (* kilograms 2.2))
-
-(defun lb->kg (pounds)
-  "Convert pounds to kilograms."
-  (/ pounds 2.2))
+(require 're-unit-conversions)
 
 ;; Cooling
 (defun cfm-circ (fpm radius)
diff --git a/re/re-unit-conversions.el b/re/re-unit-conversions.el
new file mode 100644 (file)
index 0000000..0e378c0
--- /dev/null
@@ -0,0 +1,95 @@
+;;; re-unit-conversions.el -*- lexical-binding: t; -*-
+;; This file is not part of GNU Emacs
+
+;;; Code:
+
+(require 're-math-defuns)
+
+;; Leŋþ
+(defun mm->in (mm)
+  "Convert milimeters to inches."
+  (/ mm 25.4))
+
+(defun in->mm (in)
+  "Convert inches to milimeters."
+  (* in 25.4))
+
+;; Heat
+(defun k->c (tempk)
+  "Convert degrees Kelvin to degrees Celsius."
+  (- tempk 273.15))
+
+(defun c->k (tempc)
+  "Convert degrees Celsius to degrees Kelvin."
+  (+ tempc 273.15))
+
+(defun c->f (tempc)
+  "Convert degrees Celsius to degrees Fahrenheit."
+  (+ (* tempc 1.8) 32.0))
+
+(defun f->c (tempf)
+  "Convert degrees Fahrenheit to degrees Celsius."
+  (/ (- tempf 32.0) 1.8))
+
+(defun k->f (tempk)
+  "Convert degrees Kelvin to degrees Fahrenheit.
+Applies `c->f' to `k->c'."
+  (c->f (k->c tempk)))
+
+(defun f->k (tempf)
+  "Convert degrees Fahrenheit to degrees Kelvin.
+Applies `c->k' to `f->c'."
+  (c->k (f->c tempf)))
+
+;; Pressure
+(defun bar->psi (bar)
+  "Convert bar to psi."
+  (* 14.5 bar))
+
+(defun psi->bar (psi)
+  "Convert psi to bar."
+  (/ psi 14.5))
+
+(defun kpa->psi (kpa)
+  "Convert kpa to psi."
+  (* 6.89 kpa))
+
+(defun psi->kpa (psi)
+  "Convert psi to kpa."
+  (/ psi 6.89))
+
+(defun mmhg->psi (mmhg)
+  "Convert mmhg to psi."
+  (/ mmhg 51.71))
+
+(defun psi->mmhg (psi)
+  "Convert psi to mmhg."
+  (* 51.71 psi))
+
+(defun inhg->psi (inhg)
+  "Convert inhg to psi."
+  (mmhg->psi (in->mm inhg)))
+
+(defun psi->inhg (psi)
+  "Convert psi to inhg."
+  (mm->in (psi->mmhg psi)))
+
+;; Weight
+(defun g->oz (grams)
+  "Convert grams to ounces."
+  (/ grams 28.34))
+
+(defun oz->g (ounces)
+  "Convert ounces to grams."
+  (* ounces 28.34))
+
+(defun kg->lb (kilograms)
+  "Convert kilograms to pounds."
+  (* kilograms 2.2))
+
+(defun lb->kg (pounds)
+  "Convert pounds to kilograms."
+  (/ pounds 2.2))
+
+(provide 're-unit-conversions)
+;;; re-unit-conversions.el ends here