1 ;;; ob-arduino.el --- Org-mode Babel support for Arduino.
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://github.com/stardiviner/arduino-mode
9 ;; You should have received a copy of the GNU General Public License
10 ;; along with GNU Emacs. If not, see <http://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 (require 'arduino-mode
)
38 (defgroup ob-arduino nil
39 "org-mode blocks for Arduino."
42 (defcustom ob-arduino
:program
"arduino"
43 "Default Arduino program name."
47 (defcustom ob-arduino
:port
"/dev/ttyACM0"
48 "Default Arduino port."
52 (defcustom ob-arduino
:board
"arduino:avr:uno"
53 "Default Arduino board."
58 (defvar org-babel-default-header-args
:sclang nil
)
61 (defun org-babel-execute:arduino
(body params
)
62 "org-babel arduino hook."
63 (let* ((port (cdr (assoc :port params
)))
64 (board (cdr (assoc :board params
)))
65 (cmd (mapconcat 'identity
(list
66 ob-arduino
:program
"--upload"
67 (if port
(concat "--port " port
))
68 (if board
(concat "--board " board
))
70 (code (org-babel-expand-body:generic body params
))
71 (src-file (org-babel-temp-file "ob-arduino-" ".ino")))
72 ;; delete all `ob-arduino' temp files, otherwise arduino will compile all
73 ;; ob-arduino temp files, and report error.
76 (unless (file-directory-p f
)
77 (delete-file (expand-file-name f org-babel-temporary-directory
))))
79 (file-name-directory (org-babel-temp-file "ob-arduino-" ".ino"))
81 ;; specify file for arduino command.
82 (with-temp-file src-file
85 (concat ob-arduino
:program
87 " " (if port
(concat "--port " port
))
88 " " (if board
(concat "--board " board
))
90 "" ; pass empty string "" as `BODY' to `org-babel--shell-command-on-region'
91 ;; to fix command `arduino' don't accept string issue.
98 '(add-to-list 'org-src-lang-modes
'("arduino" . arduino
)))
103 (provide 'ob-arduino
)
105 ;;; ob-arduino.el ends here