@@ -991,6 +991,67 @@ When MAIL-MODE-P is non-nil, treat INFILE as a mail."
991
991
992
992
993
993
994
+ ; ;; Serial port
995
+
996
+ (autoload 'term-send-string " term" )
997
+ (defcustom +serial-port " /dev/ttyUSB0"
998
+ " The default port (device) to use."
999
+ :group 'minemacs-serial
1000
+ :type 'file )
1001
+
1002
+ (defcustom +serial-baudrate 115200
1003
+ " The default baudrate to use."
1004
+ :group 'minemacs-serial
1005
+ :type 'natnum )
1006
+
1007
+ (defcustom +serial-first-commands nil
1008
+ " A list of commands to run in the serial terminal after creation."
1009
+ :group 'minemacs-serial
1010
+ :type '(repeat string))
1011
+
1012
+ (defvar +serial-buffer nil )
1013
+ (defvar +serial-process nil )
1014
+
1015
+ (defun +serial-running-p ()
1016
+ " Is there a serial port terminal running?"
1017
+ (buffer-live-p +serial-buffer) (process-live-p +serial-process))
1018
+
1019
+ (defun +serial--run-commands (port baud &rest commands)
1020
+ " Run COMMANDS on a device via serial communication.
1021
+
1022
+ Connect at PORT with baudrate BAUD."
1023
+ (let ((commands (ensure-list commands)))
1024
+ (unless (+serial-running-p)
1025
+ (setq +serial-buffer (serial-term port baud)
1026
+ +serial-process (get-buffer-process +serial-buffer)
1027
+ commands (append +serial-first-commands commands)))
1028
+ (if (+serial-running-p)
1029
+ (term-send-string +serial-process (string-join (append commands '(" \n " )) " \n " ))
1030
+ (user-error " Unable to communicate with the serial terminal process" ))))
1031
+
1032
+ (defun +serial-run-commands (commands &optional port baud)
1033
+ " Run COMMANDS on a device via serial communication.
1034
+
1035
+ If PORT or BAUD are nil, use values from `+serial-port' and `+serial-baudrate' ."
1036
+ (interactive (list (read-shell-command (format " Run command via serial port: " ))))
1037
+ (let ((port (or port +serial-port))
1038
+ (baud (or baud +serial-baudrate)))
1039
+ (+log! " Dev %s@%d: running commands %S" port baud commands)
1040
+ (apply #'+serial--run-commands (append (list port baud) (ensure-list commands)))))
1041
+
1042
+
1043
+
1044
+ ; ;; Networking
1045
+
1046
+ (defvar +net-default-device " wlan0" )
1047
+
1048
+ (defun +net-get-ip-address (&optional dev)
1049
+ " Get the IP-address for device DEV (default: eth0) of the current machine."
1050
+ (let ((dev (or dev +net-default-device)))
1051
+ (format-network-address (car (network-interface-info dev)) t )))
1052
+
1053
+
1054
+
994
1055
; ;; Github
995
1056
996
1057
(defun +github-latest-release (repo &optional fallback-release)
0 commit comments