Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun roku-key-to-command (key)
- (cond ((eq key 'home) "Home")
- ((eq key 'reverse) "Rev")
- ((eq key 'forward) "Fwd")
- ((eq key 'play) "Play")
- ((eq key 'select) "Select")
- ((eq key 'left) "Left")
- ((eq key 'right) "Right")
- ((eq key 'down) "Down")
- ((eq key 'up) "Up")
- ((eq key 'back) "Back")
- ((eq key 'instant-replay) "InstantReplay")
- ((eq key 'info) "Info")
- ((eq key 'backspace) "Backspace")
- ((eq key 'search) "Search")
- ((eq key 'enter) "Enter")
- ((eq key 'power-on) "PowerOn")
- ((eq key 'power-off) "PowerOff")
- ((eq key 'volume-up) "VolumeUp")
- ((eq key 'volume-down) "VolumeDown")
- ((eq key 'volume-mute) "VolumeMute")
- (t (url-hexify-string (format "Lit_%c" key)))))
- (defun roku-make-keypress-url (host key)
- (concat "http://" host ":8060/keypress/" (roku-key-to-command key)))
- (defun roku-callback (x)
- (when x
- (message "%s" x)))
- (defun roku-send-keypress (host key)
- (let ((url-request-method "POST")
- (url-request-data ""))
- (url-retrieve (roku-make-keypress-url host key) #'roku-callback)))
- ;;; Tied to host
- (defvar roku-current-host nil)
- (defun roku-run (host)
- "Initiate transient state."
- (setq roku-current-host host)
- (hydra-roku/body))
- (defmacro roku-make-command (command)
- `(defun ,(intern (concat "roku-current-send-" (symbol-name command))) ()
- (interactive)
- (roku-send-keypress roku-current-host ',command)))
- (roku-make-command back)
- (roku-make-command home)
- (roku-make-command info)
- (roku-make-command instant-replay)
- (roku-make-command play)
- (roku-make-command search)
- (roku-make-command select)
- (roku-make-command backspace)
- (roku-make-command enter)
- (roku-make-command forward)
- (roku-make-command reverse)
- (roku-make-command up)
- (roku-make-command down)
- (roku-make-command left)
- (roku-make-command right)
- (roku-make-command power-on)
- (roku-make-command power-off)
- (roku-make-command volume-up)
- (roku-make-command volume-down)
- (roku-make-command volume-mute)
- (defun roku-send-text-sender (str-to-send pos)
- (let ((url-request-method "POST")
- (url-request-data ""))
- (cond ((< pos (length str-to-send))
- (let ((url (roku-make-keypress-url roku-current-host (elt str-to-send pos))))
- (url-retrieve url
- (lambda (_status)
- (run-at-time 1 nil (lambda ()
- (roku-send-text-sender str-to-send (1+ pos))))))))
- (t
- (roku-current-send-enter)))))
- (defun roku-send-text ()
- (interactive)
- (let ((s (read-string "Send text: ")))
- (when (stringp s)
- (message "%s" s)
- (roku-send-text-sender s 0))
- t))
- (defhydra hydra-roku (:hint nil)
- "
- [_h_] left [_j_] down [_k_] up [_l_] right
- [_<return>_] ok [_SPC_] play [_gh_] home [_<backspace>_] backspace
- [_H_] back [_i_] info [_m_] instant replay [_s_] search
- [_,_] reverse [_._] forward [_t_] enter text [_q_] quit
- [_p_] power off [_o_] power on [_0_] mute [_-_] vol down [_=_] vol up"
- ("q" nil)
- ("0" roku-current-send-volume-mute)
- ("-" roku-current-send-volume-down)
- ("=" roku-current-send-volume-up)
- ("p" roku-current-send-power-off)
- ("o" roku-current-send-power-on)
- ("h" roku-current-send-left)
- ("l" roku-current-send-right)
- ("j" roku-current-send-down)
- ("k" roku-current-send-up)
- ("<backspace>" roku-current-send-backspace)
- ("H" roku-current-send-back)
- ("<return>" roku-current-send-select)
- ("SPC" roku-current-send-play)
- ("gh" roku-current-send-home)
- ("i" roku-current-send-info)
- ("m" roku-current-send-instant-replay)
- ("s" roku-current-send-search)
- ("," roku-current-send-reverse)
- ("." roku-current-send-forward)
- ("t" roku-send-text))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement