;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/terror-3/ev3-control-cli.el (require 'cl-lib) (require 'ev3-motor-rotate) (require 'ev3-motor-stop) (defun str-to-int (str) (if (string= str "0") 0 (let ((res (string-to-number str))) (unless (zerop res) ; this is so "" will return nil, not 0 (round res)) ))) (defun ev3-display-help () (find-file (concat default-directory "README")) ) (defun ev3-cmd-loop () (interactive) (cl-loop (let*((ps "[terror-3] ") (cmd (read-from-minibuffer ps)) (speed (str-to-int cmd)) ) (if speed (set-motor-both speed) (pcase cmd ((or "" "help" "h") (progn (ev3-display-help) (cl-return) )) ((or "quit" "q") (cl-return)) ((or "rotate left" "rl") (ev3-rotate-left)) ((or "rotate right" "rr") (ev3-rotate-right)) ((or "stop" "s") (ev3-stop)) (_ (message "DNC (hit `h' for help)") )))))) (provide 'ev3-control-cli)