From 93c0f8c304e4440018cbef48a5d0b7c02f017086 Mon Sep 17 00:00:00 2001 From: rearman Date: Thu, 20 Mar 2025 12:49:25 -0400 Subject: [PATCH] Factor various defuns to match use in forth image --- re/re-electronics-defuns.el | 16 +++--- re/re-packages.el | 32 ++++++------ re/re-plc-defuns.el | 30 +++++------ re/re-refrigeration-defuns.el | 89 +------------------------------- re/re-unit-conversions.el | 95 +++++++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+), 132 deletions(-) create mode 100644 re/re-unit-conversions.el diff --git a/re/re-electronics-defuns.el b/re/re-electronics-defuns.el index f3abfa6..d73948d 100644 --- a/re/re-electronics-defuns.el +++ b/re/re-electronics-defuns.el @@ -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 diff --git a/re/re-packages.el b/re/re-packages.el index 77bf61a..483795b 100644 --- a/re/re-packages.el +++ b/re/re-packages.el @@ -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 @@ -67,18 +67,18 @@ :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))) diff --git a/re/re-plc-defuns.el b/re/re-plc-defuns.el index 8a2fbc5..554bece 100644 --- a/re/re-plc-defuns.el +++ b/re/re-plc-defuns.el @@ -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." diff --git a/re/re-refrigeration-defuns.el b/re/re-refrigeration-defuns.el index 50cc14f..c9381aa 100644 --- a/re/re-refrigeration-defuns.el +++ b/re/re-refrigeration-defuns.el @@ -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 index 0000000..0e378c0 --- /dev/null +++ b/re/re-unit-conversions.el @@ -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 -- 2.39.5