;;; -*- Mode: Emacs-Lisp; coding:shift_jis -*- ;;; Logitec K-505 Kanji tablet (漢字入力装置) interface for XEmacs. (provide 'k505) ;;; I feel I must be missing something about events. Why can't Lisp ;;; code enqueue events? (defun enqueue-event (event) (enqueue-eval-event 'dispatch-event event)) (defvar k505-serial-port "/dev/ttyS0" "Serial port to which Kanji table is attached.") (defvar k505-process nil "Kanji table inferior process") (defvar k505-pending nil "List of input from Kanji table to be processed") (defun k505-filter (proc str) (setq k505-pending (nconc k505-pending (mapcar 'char-to-int str))) (if (>= (length k505-pending) 2) (let ((event (k505-event (pop k505-pending) (pop k505-pending)))) (if event (enqueue-event event) (beep))))) (defun start-k505 () "Start an inferior process talking to the Kanji tablet." (interactive) (stop-k505) (shell-command-to-string (concat "stty -F " k505-serial-port " speed 1200 raw")) (setq k505-process (let ((process-connection-type nil)) (start-process-shell-command "k505" nil "cat" k505-serial-port))) (set-process-filter k505-process 'k505-filter)) (defun stop-k505 () "Stop the Kanji table process." (interactive) (if k505-process (kill-process (prog1 k505-process (setq k505-process nil))))) (defun k505-event (b1 b2) (if (>= b1 #x80) (decf b1 #x80)) (if (>= b2 #x80) (decf b2 #x80)) (cond ((= b1 0x00) ;; Command. These are in this order in the manual. I am not ;; 100% sure what all of these are supposed to do. (let ((key (case b2 (#x60 ) ;実行 (#x61 ) ;解除 (#x62 ) ;登録 (#x63 ) ;呼出 (#x64 ) ;印字 (#x65 ) ;印字停止 (#x7F 'delete) ;1字抹消 DEL (#x18 'cancel) ;入カ訂正 CAN (#x12 'insert) ;挿入 INS (#x05 'end) ;後部消去 EL (#x0B 'home) ;ホーム HOME (#x1D 'left) (#x1C 'right) (#x1E 'up) (#x1F 'down) (#x66 'next) (#x67 'prior) (#x08 'backspace) ;後退 BS (#x0A 'linefeed) ;改行 LF (#x09 'tab) ;タブ HT (#x5C ) ;外字 EXC (#x68 ) ;リスト LIST (#x69 ) ;右づめ (#x31 ) ;領域指定 AS (#x2B ) ;揃え JF (#x4A ) ;縦書 VWF (#x4B ) ;横書 HWF (#x6A ) ;改頁 (#x6B ) ;倍角 (#x6C ) ;全角 (#x5E ) ;半角 HSS (#x28 ) ;書式設定 KGS (#x23 ) ;タブ 設定 (#x6D ) ;ア ンダーラインモ ード (#x6E ) ;ア ンダーライン付 (#x6F ) ;ア ンダーライン消 (#x2A ) ;強調 HL (#x0E ) ;拡大 SO (#x0F ) ;縮小 SI (#x5D ) ;戻わ RBS (#x11 ) ;コピー DUP (#x34 ) ;画面消去 KED ))) (if key (make-event 'key-press (list 'key key))))) ((> b1 #x20) ;; Ordinary graphic character. (character-to-event (make-char 'japanese-jisx0208 b1 b2)))))