1 ;;; ob-arduino.el --- Org-mode Babel support for Arduino. -*- lexical-binding: t; -*-
3 ;; Authors: stardiviner <numbchild@gmail.com>
4 ;; Package-Requires: ((emacs "24.4") (org "24.1"))
5 ;; Package-Version: 1.0
6 ;; Keywords: arduino org babel
7 ;; homepage: https://repo.or.cz/arduino-mode.git
9 ;; You should have received a copy of the GNU General Public License
10 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
14 ;; Like the following src block, press =[C-c C-c]= to upload to Arduino board.
16 ;; #+begin_src arduino
17 ;; // the setup function runs once when you press reset or power the board
19 ;; // initialize digital pin LED_BUILTIN as an output.
20 ;; pinMode(LED_BUILTIN, OUTPUT);
23 ;; // the loop function runs over and over again forever
25 ;; digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
26 ;; delay(100); // wait for 0.1 second
27 ;; digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
28 ;; delay(100); // wait for 0.1 second
36 (defgroup ob-arduino nil
37 "org-mode blocks for Arduino."
40 (defcustom ob-arduino
:program
"arduino"
41 "Default Arduino program name."
44 (defcustom ob-arduino
:port
"/dev/ttyACM0"
45 "Default Arduino port."
48 (defcustom ob-arduino
:board
"arduino:avr:uno"
49 "Default Arduino board."
53 (defvar org-babel-default-header-args
:sclang nil
) ;;FIXME: What's this for??
54 (defvar org-babel-temporary-directory
)
57 (defun org-babel-execute:arduino
(body params
)
58 "org-babel arduino hook."
59 (let* ((port (cdr (assoc :port params
)))
60 (board (cdr (assoc :board params
)))
61 ;; (cmd (mapconcat #'identity (list
62 ;; ob-arduino:program "--upload"
63 ;; (if port (concat "--port " port))
64 ;; (if board (concat "--board " board))
67 (code (org-babel-expand-body:generic body params
))
68 (src-file (org-babel-temp-file "ob-arduino-" ".ino")))
69 ;; delete all `ob-arduino' temp files, otherwise arduino will compile all
70 ;; ob-arduino temp files, and report error.
73 (unless (file-directory-p f
)
74 (delete-file (expand-file-name f org-babel-temporary-directory
))))
76 (file-name-directory (org-babel-temp-file "ob-arduino-" ".ino"))
78 ;; specify file for arduino command.
79 (with-temp-file src-file
82 (concat ob-arduino
:program
84 " " (if port
(concat "--port " port
))
85 " " (if board
(concat "--board " board
))
87 "" ; pass empty string "" as `BODY' to `org-babel--shell-command-on-region'
88 ;; to fix command `arduino' don't accept string issue.
94 (with-eval-after-load 'org
95 (add-to-list 'org-src-lang-modes
'("arduino" . arduino
))
96 (add-to-list 'org-babel-tangle-lang-exts
'("arduino" .
"ino")))
100 (provide 'ob-arduino
)
102 ;;; ob-arduino.el ends here