subduino 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. data/.document +5 -0
  2. data/.gitignore +26 -0
  3. data/Rakefile +76 -0
  4. data/Readme.textile +46 -0
  5. data/VERSION +1 -0
  6. data/bin/subduino +34 -0
  7. data/bin/subduino-cli +65 -0
  8. data/duino/.gitignore +2 -0
  9. data/duino/Makefile +401 -0
  10. data/duino/duino.pde +17 -0
  11. data/duino/duino.rb +16 -0
  12. data/duino/methods.pde +5 -0
  13. data/lib/subduino/ard_io.rb +60 -0
  14. data/lib/subduino/ard_ps.rb +38 -0
  15. data/lib/subduino/arduino.rb +30 -0
  16. data/lib/subduino/parse.rb +61 -0
  17. data/lib/subduino/scaffold/Makefile +401 -0
  18. data/lib/subduino/scaffold/Makefile2 +247 -0
  19. data/lib/subduino/scaffold/generator.rb +29 -0
  20. data/lib/subduino/scaffold/scaffold.pde +17 -0
  21. data/lib/subduino/scaffold/scaffold.rb +16 -0
  22. data/lib/subduino/store.rb +65 -0
  23. data/lib/subduino.rb +48 -0
  24. data/node/arduinode.js +68 -0
  25. data/node/server.js +45 -0
  26. data/node/vendor/faye.js +1925 -0
  27. data/spec/spec_helper.rb +10 -0
  28. data/spec/subduino/ard_io_spec.rb +9 -0
  29. data/spec/subduino/parse_spec.rb +21 -0
  30. data/spec/subduino/store_spec.rb +17 -0
  31. data/spec/subduino_spec.rb +20 -0
  32. data/subduino.gemspec +239 -0
  33. data/webapp/Gemfile +8 -0
  34. data/webapp/Gemfile.lock +14 -0
  35. data/webapp/Rakefile +49 -0
  36. data/webapp/Readme.textile +45 -0
  37. data/webapp/VERSION +1 -0
  38. data/webapp/lib/app.rb +103 -0
  39. data/webapp/lib/duino.rb +213 -0
  40. data/webapp/lib/environment.rb +36 -0
  41. data/webapp/lib/messenger.rb +16 -0
  42. data/webapp/public/app.css +119 -0
  43. data/webapp/public/app.js +34 -0
  44. data/webapp/public/faye.js +1 -0
  45. data/webapp/public/icons/alarm-clock-blue.png +0 -0
  46. data/webapp/public/icons/alarm-clock.png +0 -0
  47. data/webapp/public/icons/balloon-left.png +0 -0
  48. data/webapp/public/icons/bandaid.png +0 -0
  49. data/webapp/public/icons/bell-disable.png +0 -0
  50. data/webapp/public/icons/bell.png +0 -0
  51. data/webapp/public/icons/big_icon.png +0 -0
  52. data/webapp/public/icons/bomb.png +0 -0
  53. data/webapp/public/icons/bookmark.png +0 -0
  54. data/webapp/public/icons/box-label.png +0 -0
  55. data/webapp/public/icons/brightness-control-up.png +0 -0
  56. data/webapp/public/icons/brightness-control.png +0 -0
  57. data/webapp/public/icons/brightness-small.png +0 -0
  58. data/webapp/public/icons/broom.png +0 -0
  59. data/webapp/public/icons/bug.png +0 -0
  60. data/webapp/public/icons/calculator.png +0 -0
  61. data/webapp/public/icons/calendar-day.png +0 -0
  62. data/webapp/public/icons/camera.png +0 -0
  63. data/webapp/public/icons/cards-address.png +0 -0
  64. data/webapp/public/icons/chart.png +0 -0
  65. data/webapp/public/icons/clock-select.png +0 -0
  66. data/webapp/public/icons/color.png +0 -0
  67. data/webapp/public/icons/compass.png +0 -0
  68. data/webapp/public/icons/control-power-small.png +0 -0
  69. data/webapp/public/icons/control-power.png +0 -0
  70. data/webapp/public/icons/control-record-small.png +0 -0
  71. data/webapp/public/icons/cpus.png +0 -0
  72. data/webapp/public/icons/credit-card.png +0 -0
  73. data/webapp/public/icons/cross-small.png +0 -0
  74. data/webapp/public/icons/dashboard.png +0 -0
  75. data/webapp/public/icons/database.png +0 -0
  76. data/webapp/public/icons/databases.png +0 -0
  77. data/webapp/public/icons/door-open-in.png +0 -0
  78. data/webapp/public/icons/door-open-out.png +0 -0
  79. data/webapp/public/icons/door-open.png +0 -0
  80. data/webapp/public/icons/door.png +0 -0
  81. data/webapp/public/icons/drive-globe.png +0 -0
  82. data/webapp/public/icons/equalizer.png +0 -0
  83. data/webapp/public/icons/exclamation-diamond.png +0 -0
  84. data/webapp/public/icons/exclamation.png +0 -0
  85. data/webapp/public/icons/eye-disable.png +0 -0
  86. data/webapp/public/icons/eye.png +0 -0
  87. data/webapp/public/icons/false.png +0 -0
  88. data/webapp/public/icons/gear-small.png +0 -0
  89. data/webapp/public/icons/gear.png +0 -0
  90. data/webapp/public/icons/groups.png +0 -0
  91. data/webapp/public/icons/heart.png +0 -0
  92. data/webapp/public/icons/heart_empty.png +0 -0
  93. data/webapp/public/icons/info.png +0 -0
  94. data/webapp/public/icons/key.png +0 -0
  95. data/webapp/public/icons/lightbulb.png +0 -0
  96. data/webapp/public/icons/lightbulb_off.png +0 -0
  97. data/webapp/public/icons/lightning-disable.png +0 -0
  98. data/webapp/public/icons/lightning-small.png +0 -0
  99. data/webapp/public/icons/lightning.png +0 -0
  100. data/webapp/public/icons/lock-unlock.png +0 -0
  101. data/webapp/public/icons/lock.png +0 -0
  102. data/webapp/public/icons/marker.png +0 -0
  103. data/webapp/public/icons/media-player-phone.png +0 -0
  104. data/webapp/public/icons/megaphone.png +0 -0
  105. data/webapp/public/icons/mem.png +0 -0
  106. data/webapp/public/icons/microphone.png +0 -0
  107. data/webapp/public/icons/monitor.png +0 -0
  108. data/webapp/public/icons/navigation.png +0 -0
  109. data/webapp/public/icons/off.png +0 -0
  110. data/webapp/public/icons/on.png +0 -0
  111. data/webapp/public/icons/pin.png +0 -0
  112. data/webapp/public/icons/plug--exclamation.png +0 -0
  113. data/webapp/public/icons/plug-disable.png +0 -0
  114. data/webapp/public/icons/plug.png +0 -0
  115. data/webapp/public/icons/restart.png +0 -0
  116. data/webapp/public/icons/ruby.png +0 -0
  117. data/webapp/public/icons/server.png +0 -0
  118. data/webapp/public/icons/shield-disable.png +0 -0
  119. data/webapp/public/icons/shield.png +0 -0
  120. data/webapp/public/icons/socket--exclamation.png +0 -0
  121. data/webapp/public/icons/socket-disable.png +0 -0
  122. data/webapp/public/icons/socket.png +0 -0
  123. data/webapp/public/icons/start.png +0 -0
  124. data/webapp/public/icons/stop.png +0 -0
  125. data/webapp/public/icons/switch--exclamation.png +0 -0
  126. data/webapp/public/icons/switch-disable.png +0 -0
  127. data/webapp/public/icons/switch-small.png +0 -0
  128. data/webapp/public/icons/switch.png +0 -0
  129. data/webapp/public/icons/target.png +0 -0
  130. data/webapp/public/icons/television-off.png +0 -0
  131. data/webapp/public/icons/television.png +0 -0
  132. data/webapp/public/icons/terminal.png +0 -0
  133. data/webapp/public/icons/tick-small.png +0 -0
  134. data/webapp/public/icons/traffic-light-off.png +0 -0
  135. data/webapp/public/icons/traffic-light.png +0 -0
  136. data/webapp/public/icons/traffic.png +0 -0
  137. data/webapp/public/icons/true.png +0 -0
  138. data/webapp/public/icons/umbrella.png +0 -0
  139. data/webapp/public/icons/unmonitor.png +0 -0
  140. data/webapp/public/icons/unmonitored.png +0 -0
  141. data/webapp/public/icons/users.png +0 -0
  142. data/webapp/public/icons/vcard.png +0 -0
  143. data/webapp/public/icons/wall.png +0 -0
  144. data/webapp/public/icons/wall_brick.png +0 -0
  145. data/webapp/public/icons/wall_disable.png +0 -0
  146. data/webapp/public/icons/wand-disable.png +0 -0
  147. data/webapp/public/icons/wand.png +0 -0
  148. data/webapp/public/icons/warn.png +0 -0
  149. data/webapp/public/icons/weather_clouds.png +0 -0
  150. data/webapp/public/icons/weather_cloudy.png +0 -0
  151. data/webapp/public/icons/weather_lightning.png +0 -0
  152. data/webapp/public/icons/weather_rain.png +0 -0
  153. data/webapp/public/icons/weather_snow.png +0 -0
  154. data/webapp/public/icons/weather_sun.png +0 -0
  155. data/webapp/public/icons/wrench-screwdriver.png +0 -0
  156. data/webapp/public/icons/wrench.png +0 -0
  157. data/webapp/public/iui/backButton.png +0 -0
  158. data/webapp/public/iui/blueButton.png +0 -0
  159. data/webapp/public/iui/cancel.png +0 -0
  160. data/webapp/public/iui/grayButton.png +0 -0
  161. data/webapp/public/iui/greenButton.png +0 -0
  162. data/webapp/public/iui/iui-logo-touch-icon.png +0 -0
  163. data/webapp/public/iui/iui.css +396 -0
  164. data/webapp/public/iui/iui.js +511 -0
  165. data/webapp/public/iui/iuix.css +1 -0
  166. data/webapp/public/iui/iuix.js +1 -0
  167. data/webapp/public/iui/listArrow.png +0 -0
  168. data/webapp/public/iui/listArrowSel.png +0 -0
  169. data/webapp/public/iui/listGroup.png +0 -0
  170. data/webapp/public/iui/loading.gif +0 -0
  171. data/webapp/public/iui/pinstripes.png +0 -0
  172. data/webapp/public/iui/redButton.png +0 -0
  173. data/webapp/public/iui/selection.png +0 -0
  174. data/webapp/public/iui/thumb.png +0 -0
  175. data/webapp/public/iui/toggle.png +0 -0
  176. data/webapp/public/iui/toggleOn.png +0 -0
  177. data/webapp/public/iui/toolButton.png +0 -0
  178. data/webapp/public/iui/toolbar.png +0 -0
  179. data/webapp/public/iui/whiteButton.png +0 -0
  180. data/webapp/public/iui/yellowButton.png +0 -0
  181. data/webapp/public/jquery.js +154 -0
  182. data/webapp/public/layout.css +33 -0
  183. data/webapp/public/right.js +9 -0
  184. data/webapp/public/rt.js +7 -0
  185. data/webapp/public/sparkline.js +85 -0
  186. data/webapp/spec/duino_spec.rb +8 -0
  187. data/webapp/spec/spec_helper.rb +10 -0
  188. data/webapp/views/command.haml +4 -0
  189. data/webapp/views/icon.haml +6 -0
  190. data/webapp/views/index.haml +51 -0
  191. data/webapp/views/layout.haml +17 -0
  192. data/webapp/views/mobile.haml +21 -0
  193. data/webapp/views/switch.haml +56 -0
  194. data/webapp/views/top.haml +4 -0
  195. data/webapp/views/watch.haml +26 -0
  196. metadata +277 -0
@@ -0,0 +1,60 @@
1
+ module Subduino
2
+
3
+ class ArdIO
4
+ class << self
5
+
6
+ def sp
7
+ @sp ||= SerialPort.new(Arduino.find_usb, BAUDS) #, DATA_BITS, DATA_STOP, parity)
8
+ # @sp.read_timeout = 10;# @sp.write_timeout = 10
9
+ end
10
+
11
+ def read(&proc)
12
+ Log.info "[USB] Starting USB Connect..." + sp.get_modem_params.map { |k,v| "#{k}: #{v}" }.join(" ")
13
+ Log.info "[USB] Read Timeout #{sp.read_timeout}" # {sp.write_timeout}"
14
+
15
+ #
16
+ # Read I/O
17
+ #
18
+ @iothread ||= Thread.new do
19
+ Thread.current.abort_on_exception = false
20
+ icache = []
21
+
22
+ loop do
23
+ begin
24
+ while char = sp.getc
25
+ if char !~ /\n|\r/
26
+ icache << char
27
+ else
28
+ data = icache.join(""); icache = []
29
+ if data =~ /:/
30
+ proc.call(data)
31
+ Log.info "[SENSOR] #{data}"
32
+ else
33
+ proc.call(data) unless data.empty?
34
+ # Log.info "[INPUT] Done."
35
+ end
36
+ end
37
+ end
38
+ sleep 1
39
+ rescue => e
40
+ Log.error "[USB] Error #{e}"
41
+ Log.error e.backtrace.join("\n")
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def write(msg)
48
+ Log.info "[IO TX] #{msg}"
49
+ txt = msg.gsub("\n", "\r")
50
+ txt += "\r" unless txt =~ /^\\r/
51
+ sp.write(txt)
52
+ end
53
+
54
+ def stop!
55
+ sp.close
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,38 @@
1
+ module Subduino
2
+ class ArdPS
3
+
4
+ def self.redis
5
+ @redis ||= Redis.new(:timeout => 0) rescue false
6
+ end
7
+
8
+ def self.read
9
+ return Log.warn "[PubSub] Not started..." unless @redis
10
+ Thread.new do
11
+ begin
12
+ redis.subscribe('subduin') do |on|
13
+ on.subscribe {|klass, num_subs| Log.info "[PubSub] Subscribed to #{klass} (#{num_subs} subscriptions)" }
14
+ on.message do |klass, msg|
15
+ Log.info "[PubSub] #{klass} - #{msg}"
16
+ ArdIO.write msg
17
+ # @redis.unsubscribe if msg == 'exit'
18
+ end
19
+ on.unsubscribe {|klass, num_subs| Log.info "[PubSub] Unsubscribed to #{klass} (#{num_subs} subscriptions)" }
20
+ end
21
+ rescue => e
22
+ Log.error "[PubSub] Error #{e}"
23
+ Log.error e.backtrace.join("\n")
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ def self.write(msg)
30
+ redis.publish('subdout', msg)
31
+ end
32
+
33
+ def self.stop!
34
+ redis.disconnect if @redis
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,30 @@
1
+ module Subduino
2
+
3
+
4
+
5
+ class Arduino
6
+
7
+ def self.find_usb
8
+ Dir['/dev/ttyUSB*'].first
9
+ end
10
+
11
+
12
+ def initialize
13
+ end
14
+
15
+ def send_to_arduino(string)
16
+ string.to_s.chomp.split("").each do |char|
17
+ @sp.putc char
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ # read << case comm
24
+ # when "Temp" then "%0.2f C" % (value.to_i * 0.04)
25
+ # when "Light" then "#{value.to_i * 2} Lux"
26
+ # else
27
+ # "#{comm}: #{value}"
28
+ # end
29
+
30
+ end
@@ -0,0 +1,61 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Subduino
3
+ module Parse
4
+
5
+ def self.work(klass, v)
6
+ const_get(klass).new(v)
7
+ end
8
+
9
+ class DigParser
10
+ def initialize(v); @v = v.to_i; end
11
+ def digital?; true; end
12
+ def to_s; @v.to_s; end
13
+ def raw; @v; end
14
+ end
15
+
16
+ class AnaParser < DigParser
17
+ def digital?; false; end
18
+ def parse; @v; end
19
+ def ratio
20
+ return 0 if @v.zero?
21
+ @v * 100 / 1023
22
+ end
23
+ end
24
+
25
+ class Bool < DigParser
26
+ def parse
27
+ @v.zero? ? false : true
28
+ end
29
+
30
+ def to_s
31
+ parse ? "ON" : "OFF"
32
+ end
33
+ end
34
+
35
+ class Knob < AnaParser
36
+ end
37
+
38
+ class Temp < AnaParser
39
+ def parse
40
+ @v * 0.035
41
+ end
42
+
43
+ def to_s
44
+ "%0.2f°C" % parse
45
+ end
46
+ end
47
+
48
+ class Lux < AnaParser
49
+ def parse
50
+ (@v * 0.5).to_i
51
+ end
52
+
53
+ def to_s
54
+ "#{parse} L"
55
+ end
56
+ end
57
+
58
+
59
+
60
+ end
61
+ end
@@ -0,0 +1,401 @@
1
+ ########################################################################
2
+ #
3
+ # Arduino command line tools Makefile
4
+ # System part (i.e. project independent)
5
+ #
6
+ # Copyright (C) 2010 Martin Oldfield <m@mjo.tc>, based on work that is
7
+ # Copyright Nicholas Zambetti, David A. Mellis & Hernando Barragan
8
+ #
9
+ # This file is free software; you can redistribute it and/or modify it
10
+ # under the terms of the GNU Lesser General Public License as
11
+ # published by the Free Software Foundation; either version 2.1 of the
12
+ # License, or (at your option) any later version.
13
+ #
14
+ # Adapted from Arduino 0011 Makefile by M J Oldfield
15
+ #
16
+ # Original Arduino adaptation by mellis, eighthave, oli.keller
17
+ #
18
+ # Version 0.1 17.ii.2009 M J Oldfield
19
+ #
20
+ # 0.2 22.ii.2009 M J Oldfield
21
+ # - fixes so that the Makefile actually works!
22
+ # - support for uploading via ISP
23
+ # - orthogonal choices of using the Arduino for
24
+ # tools, libraries and uploading
25
+ #
26
+ # 0.3 21.v.2010 M J Oldfield
27
+ # - added proper license statement
28
+ # - added code from Philip Hands to reset
29
+ # Arduino prior to upload
30
+ #
31
+ # 0.4 25.v.2010 M J Oldfield
32
+ # - tweaked reset target on Philip Hands' advice
33
+ #
34
+ ########################################################################
35
+ #
36
+ # STANDARD ARDUINO WORKFLOW
37
+ #
38
+ # Given a normal sketch directory, all you need to do is to create
39
+ # a small Makefile which defines a few things, and then includes this one.
40
+ #
41
+ # For example:
42
+ #
43
+ ARDUINO_DIR = /usr/share/arduino
44
+ #
45
+ TARGET = DUINO
46
+ ARDUINO_LIBS = Messenger
47
+
48
+ MCU = atmega328p
49
+ F_CPU = 16000000
50
+ ARDUINO_PORT = /dev/ttyUSB* #cu.usb*
51
+
52
+ # Linux
53
+ AVR_TOOLS_PATH = /usr/bin
54
+ AVRDUDE_CONF = /usr/share/arduino/hardware/tools/avrdude.conf
55
+
56
+ # INC_DIRS = ./vendor/Messenger
57
+
58
+ #
59
+ # include /usr/local/share/Arduino.mk
60
+ #
61
+ # Hopefully these will be self-explanatory but in case they're not:
62
+ #
63
+ # ARDUINO_DIR - Where the Arduino software has been unpacked
64
+ # TARGET - The basename used for the final files. Canonically
65
+ # this would match the .pde file, but it's not needed
66
+ # here: you could always set it to xx if you wanted!
67
+ # ARDUINO_LIBS - A list of any libraries used by the sketch (we assume
68
+ # these are in $(ARDUINO_DIR)/hardware/libraries
69
+ # MCU,F_CPU - The target processor description
70
+ # ARDUINO_PORT - The port where the Arduino can be found (only needed
71
+ # when uploading
72
+ #
73
+ # Once this file has been created the typical workflow is just
74
+ #
75
+ # $ make upload
76
+ #
77
+ # All of the object files are created in the build-cli subdirectory
78
+ # All sources should be in the current directory and can include:
79
+ # - at most one .pde file which will be treated as C++ after the standard
80
+ # Arduino header and footer have been affixed.
81
+ # - any number of .c, .cpp, .s and .h files
82
+ #
83
+ #
84
+ # Besides make upload you can also
85
+ # make - no upload
86
+ # make clean - remove all our dependencies
87
+ # make depends - update dependencies
88
+ # make reset - reset the Arduino by tickling DTR on the serial port
89
+ # make raw_upload - upload without first resetting
90
+ #
91
+ ########################################################################
92
+ #
93
+ # ARDUINO WITH OTHER TOOLS
94
+ #
95
+ # If the tools aren't in the Arduino distribution, then you need to
96
+ # specify their location:
97
+ #
98
+ # AVR_TOOLS_PATH = /usr/bin
99
+ # AVRDUDE_CONF = /etc/avrdude/avrdude.conf
100
+ #
101
+ ########################################################################
102
+ #
103
+ # ARDUINO WITH ISP
104
+ #
105
+ # You need to specify some details of your ISP programmer and might
106
+ # also need to specify the fuse values:
107
+ #
108
+ # ISP_PROG = -c stk500v2
109
+ # ISP_PORT = /dev/ttyACM0
110
+ #
111
+ # ISP_LOCK_FUSE_PRE = 0x3f
112
+ # ISP_LOCK_FUSE_POST = 0xcf
113
+ # ISP_HIGH_FUSE = 0xdf
114
+ # ISP_LOW_FUSE = 0xff
115
+ # ISP_EXT_FUSE = 0x01
116
+ #
117
+ # I think the fuses here are fine for uploading to the ATmega168
118
+ # without bootloader.
119
+ #
120
+ # To actually do this upload use the ispload target:
121
+ #
122
+ # make ispload
123
+ #
124
+ #
125
+ ########################################################################
126
+ # Some paths
127
+ #
128
+
129
+ ifneq (ARDUINO_DIR,)
130
+
131
+ ifndef AVR_TOOLS_PATH
132
+ AVR_TOOLS_PATH = $(ARDUINO_DIR)/hardware/tools/avr/bin
133
+ endif
134
+
135
+ ifndef ARDUINO_ETC_PATH
136
+ ARDUINO_ETC_PATH = $(ARDUINO_DIR)/hardware/tools/avr/etc
137
+ endif
138
+
139
+ ifndef AVRDUDE_CONF
140
+ AVRDUDE_CONF = $(ARDUINO_ETC_PATH)/avrdude.conf
141
+ endif
142
+
143
+ ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries
144
+ ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
145
+
146
+ endif
147
+
148
+ # Everything gets built in here
149
+ OBJDIR = build-cli
150
+
151
+ ########################################################################
152
+ # Local sources
153
+ #
154
+ LOCAL_C_SRCS = $(wildcard *.c)
155
+ LOCAL_CPP_SRCS = $(wildcard *.cpp)
156
+ LOCAL_CC_SRCS = $(wildcard *.cc)
157
+ LOCAL_PDE_SRCS = $(wildcard *.pde)
158
+ LOCAL_AS_SRCS = $(wildcard *.S)
159
+ LOCAL_OBJ_FILES = $(LOCAL_C_SRCS:.c=.o) $(LOCAL_CPP_SRCS:.cpp=.o) \
160
+ $(LOCAL_CC_SRCS:.cc=.o) $(LOCAL_PDE_SRCS:.pde=.o) \
161
+ $(LOCAL_AS_SRCS:.S=.o)
162
+ LOCAL_OBJS = $(patsubst %,$(OBJDIR)/%,$(LOCAL_OBJ_FILES))
163
+
164
+ # Dependency files
165
+ DEPS = $(LOCAL_OBJS:.o=.d)
166
+
167
+ # core sources
168
+ ifeq ($(strip $(NO_CORE)),)
169
+ ifdef ARDUINO_CORE_PATH
170
+ CORE_C_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.c)
171
+ CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp)
172
+ EXTRA_CPP_SRCS = $(wildcard $(ARDUINO_LIB_PATH)/Messenger/*.cpp)
173
+ CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o) $(EXTRA_CPP_SRCS:.cpp=.o)
174
+ CORE_OBJS = $(patsubst $(ARDUINO_CORE_PATH)/%, $(OBJDIR)/%,$(CORE_OBJ_FILES))
175
+ endif
176
+ endif
177
+
178
+ # all the objects!
179
+ OBJS = $(LOCAL_OBJS) $(CORE_OBJS)
180
+
181
+ ########################################################################
182
+ # Rules for making stuff
183
+ #
184
+
185
+ # The name of the main targets
186
+ TARGET_HEX = $(OBJDIR)/$(TARGET).hex
187
+ TARGET_ELF = $(OBJDIR)/$(TARGET).elf
188
+ TARGETS = $(OBJDIR)/$(TARGET).*
189
+
190
+ # A list of dependencies
191
+ DEP_FILE = $(OBJDIR)/depends.mk
192
+
193
+ # Names of executables
194
+ CC = $(AVR_TOOLS_PATH)/avr-gcc
195
+ CXX = $(AVR_TOOLS_PATH)/avr-g++
196
+ OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
197
+ OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
198
+ AR = $(AVR_TOOLS_PATH)/avr-ar
199
+ SIZE = $(AVR_TOOLS_PATH)/avr-size
200
+ NM = $(AVR_TOOLS_PATH)/avr-nm
201
+ REMOVE = rm -f
202
+ MV = mv -f
203
+ CAT = cat
204
+ ECHO = echo
205
+
206
+ # General arguments
207
+ SYS_LIBS = $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(ARDUINO_LIBS))
208
+ SYS_INCLUDES = $(patsubst %,-I%,$(SYS_LIBS))
209
+ SYS_OBJS = $(wildcard $(patsubst %,%/*.o,$(SYS_LIBS)))
210
+
211
+ CPPFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) \
212
+ -I. -I$(ARDUINO_CORE_PATH) \
213
+ $(SYS_INCLUDES) -g -Os -w -Wall \
214
+ -ffunction-sections -fdata-sections
215
+ CFLAGS = -std=gnu99
216
+ CXXFLAGS = -fno-exceptions
217
+ ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp
218
+ LDFLAGS = -mmcu=$(MCU) -lm -Wl,--gc-sections -Os
219
+
220
+ # Rules for making a CPP file from the main sketch (.cpe)
221
+ PDEHEADER = \\\#include \"WProgram.h\"
222
+
223
+ # Expand and pick the first port
224
+ ARD_PORT = $(firstword $(wildcard $(ARDUINO_PORT)))
225
+
226
+ # Implicit rules for building everything (needed to get everything in
227
+ # the right directory)
228
+ #
229
+ # Rather than mess around with VPATH there are quasi-duplicate rules
230
+ # here for building e.g. a system C++ file and a local C++
231
+ # file. Besides making things simpler now, this would also make it
232
+ # easy to change the build options in future
233
+
234
+ # normal local sources
235
+ # .o rules are for objects, .d for dependency tracking
236
+ # there seems to be an awful lot of duplication here!!!
237
+ $(OBJDIR)/%.o: %.c
238
+ $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
239
+
240
+ $(OBJDIR)/%.o: %.cc
241
+ $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
242
+
243
+ $(OBJDIR)/%.o: %.cpp
244
+ $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
245
+
246
+ $(OBJDIR)/%.o: %.S
247
+ $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
248
+
249
+ $(OBJDIR)/%.o: %.s
250
+ $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
251
+
252
+ $(OBJDIR)/%.d: %.c
253
+ $(CC) -MM $(CPPFLAGS) $(CFLAGS) $< -MF $@ -MT $(@:.d=.o)
254
+
255
+ $(OBJDIR)/%.d: %.cc
256
+ $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
257
+
258
+ $(OBJDIR)/%.d: %.cpp
259
+ $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
260
+
261
+ $(OBJDIR)/%.d: %.S
262
+ $(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o)
263
+
264
+ $(OBJDIR)/%.d: %.s
265
+ $(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o)
266
+
267
+ # the pde -> cpp -> o file
268
+ $(OBJDIR)/%.cpp: %.pde
269
+ $(ECHO) $(PDEHEADER) > $@
270
+ $(CAT) $< >> $@
271
+
272
+ $(OBJDIR)/%.o: $(OBJDIR)/%.cpp
273
+ $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
274
+
275
+ $(OBJDIR)/%.d: $(OBJDIR)/%.cpp
276
+ $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
277
+
278
+ # core files
279
+ $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.c
280
+ $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
281
+
282
+ $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp
283
+ $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
284
+
285
+ # various object conversions
286
+ $(OBJDIR)/%.hex: $(OBJDIR)/%.elf
287
+ $(OBJCOPY) -O ihex -R .eeprom $< $@
288
+
289
+ $(OBJDIR)/%.eep: $(OBJDIR)/%.elf
290
+ -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
291
+ --change-section-lma .eeprom=0 -O ihex $< $@
292
+
293
+ $(OBJDIR)/%.lss: $(OBJDIR)/%.elf
294
+ $(OBJDUMP) -h -S $< > $@
295
+
296
+ $(OBJDIR)/%.sym: $(OBJDIR)/%.elf
297
+ $(NM) -n $< > $@
298
+
299
+ ########################################################################
300
+ #
301
+ # Avrdude
302
+ #
303
+ ifndef AVRDUDE
304
+ AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
305
+ endif
306
+
307
+ AVRDUDE_COM_OPTS = -q -V -p $(MCU)
308
+ ifdef AVRDUDE_CONF
309
+ AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF)
310
+ endif
311
+
312
+ ifndef AVRDUDE_ARD_PROGRAMMER
313
+ AVRDUDE_ARD_PROGRAMMER = stk500v1
314
+ endif
315
+
316
+ ifndef AVRDUDE_ARD_BAUDRATE
317
+ AVRDUDE_ARD_BAUDRATE = 57600 # 19600
318
+ endif
319
+
320
+ AVRDUDE_ARD_OPTS = -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P $(ARD_PORT)
321
+
322
+ ifndef ISP_LOCK_FUSE_PRE
323
+ ISP_LOCK_FUSE_PRE = 0x3f
324
+ endif
325
+
326
+ ifndef ISP_LOCK_FUSE_POST
327
+ ISP_LOCK_FUSE_POST = 0xcf
328
+ endif
329
+
330
+ ifndef ISP_HIGH_FUSE
331
+ ISP_HIGH_FUSE = 0xdf
332
+ endif
333
+
334
+ ifndef ISP_LOW_FUSE
335
+ ISP_LOW_FUSE = 0xff
336
+ endif
337
+
338
+ ifndef ISP_EXT_FUSE
339
+ ISP_EXT_FUSE = 0x01
340
+ endif
341
+
342
+ ifndef ISP_PROG
343
+ ISP_PROG = -c stk500v2
344
+ endif
345
+
346
+ AVRDUDE_ISP_OPTS = -P $(ISP_PORT) $(ISP_PROG)
347
+
348
+
349
+ ########################################################################
350
+ #
351
+ # Explicit targets start here
352
+ #
353
+
354
+ all: $(OBJDIR) $(TARGET_HEX)
355
+
356
+ $(OBJDIR):
357
+ mkdir $(OBJDIR)
358
+
359
+ $(TARGET_ELF): $(OBJS)
360
+ $(CC) $(LDFLAGS) -o $@ $(OBJS) $(SYS_OBJS)
361
+
362
+ $(DEP_FILE): $(OBJDIR) $(DEPS)
363
+ cat $(DEPS) > $(DEP_FILE)
364
+
365
+ upload: reset raw_upload
366
+
367
+ raw_upload: $(TARGET_HEX)
368
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
369
+ -U flash:w:$(TARGET_HEX):i
370
+
371
+ # stty on MacOS likes -F, but on Debian it likes -f redirecting
372
+ # stdin/out appears to work but generates a spurious error on MacOS at
373
+ # least. Perhaps it would be better to just do it in perl ?
374
+ reset:
375
+ for STTYF in 'stty --file' 'stty -f' 'stty <' ; \
376
+ do $$STTYF /dev/tty >/dev/null 2>/dev/null && break ; \
377
+ done ;\
378
+ $$STTYF $(ARD_PORT) hupcl ;\
379
+ (sleep 0.1 || sleep 1) ;\
380
+ $$STTYF $(ARD_PORT) -hupcl
381
+
382
+ ispload: $(TARGET_HEX)
383
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e \
384
+ -U lock:w:$(ISP_LOCK_FUSE_PRE):m \
385
+ -U hfuse:w:$(ISP_HIGH_FUSE):m \
386
+ -U lfuse:w:$(ISP_LOW_FUSE):m \
387
+ -U efuse:w:$(ISP_EXT_FUSE):m
388
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -D \
389
+ -U flash:w:$(TARGET_HEX):i
390
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) \
391
+ -U lock:w:$(ISP_LOCK_FUSE_POST):m
392
+
393
+ clean:
394
+ $(REMOVE) $(OBJS) $(TARGETS) $(DEP_FILE) $(DEPS)
395
+
396
+ depends: $(DEPS)
397
+ cat $(DEPS) > $(DEP_FILE)
398
+
399
+ .PHONY: all clean depends upload raw_upload reset
400
+
401
+ include $(DEP_FILE)