rad 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +7 -0
- data/License.txt +282 -0
- data/Manifest.txt +25 -0
- data/README.txt +3 -0
- data/Rakefile +139 -0
- data/bin/rad +68 -0
- data/lib/rad.rb +5 -0
- data/lib/rad/arduino_sketch.rb +95 -0
- data/lib/rad/generators/makefile/makefile.erb +219 -0
- data/lib/rad/generators/makefile/makefile.rb +46 -0
- data/lib/rad/init.rb +7 -0
- data/lib/rad/tasks/build_and_make.rake +86 -0
- data/lib/rad/tasks/rad.rb +2 -0
- data/lib/rad/todo.txt +18 -0
- data/lib/rad/version.rb +9 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- data/spec/models/arduino_sketch_spec.rb +63 -0
- data/spec/models/spec_helper.rb +2 -0
- data/spec/spec.opts +1 -0
- data/website/index.html +131 -0
- data/website/index.txt +68 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +84 -0
data/bin/rad
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
rescue LoadError
|
6
|
+
# no rubygems to load, so we fail silently
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
require 'fileutils'
|
11
|
+
|
12
|
+
parser = OptionParser.new do |opts|
|
13
|
+
opts.banner = <<BANNER
|
14
|
+
Build a directory for your RAD Sketch and install RAD in its vendor sub-directory.
|
15
|
+
|
16
|
+
Usage: #{File.basename($0)} <sketch_dir_name>
|
17
|
+
BANNER
|
18
|
+
|
19
|
+
opts.on("-h", "--help",
|
20
|
+
"Show this help message.") { puts opts; exit }
|
21
|
+
opts.parse!(ARGV)
|
22
|
+
end
|
23
|
+
|
24
|
+
sketch_name = ARGV[0]
|
25
|
+
parser.parse!(["-h"]) unless sketch_name
|
26
|
+
|
27
|
+
FileUtils.mkdir_p "#{sketch_name}/vendor/rad"
|
28
|
+
puts "Successfully created your sketch directory."
|
29
|
+
|
30
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/rad/.", "#{sketch_name}/vendor/rad"
|
31
|
+
puts "Installed RAD library into #{sketch_name}/vendor/rad"
|
32
|
+
puts
|
33
|
+
|
34
|
+
FileUtils.touch "#{sketch_name}/#{sketch_name}.rb"
|
35
|
+
File.open("#{sketch_name}/#{sketch_name}.rb", "w") do |file|
|
36
|
+
file << <<-EOS
|
37
|
+
class #{sketch_name.split("_").collect{|c| c.capitalize}.join("")} < ArduinoSketch
|
38
|
+
end
|
39
|
+
EOS
|
40
|
+
end
|
41
|
+
puts "Added #{sketch_name}/#{sketch_name}.rb"
|
42
|
+
|
43
|
+
File.open("#{sketch_name}/Rakefile", 'w') do |file|
|
44
|
+
file << <<-EOS
|
45
|
+
require 'vendor/rad/init.rb'
|
46
|
+
EOS
|
47
|
+
end
|
48
|
+
puts "Added #{sketch_name}/Rakefile"
|
49
|
+
|
50
|
+
FileUtils.mkdir_p "#{sketch_name}/config"
|
51
|
+
puts "Added #{sketch_name}/config"
|
52
|
+
|
53
|
+
File.open("#{sketch_name}/config/hardware.yml", 'w') do |file|
|
54
|
+
file << <<-EOS
|
55
|
+
rserial_port: /dev/tty.usbserial-A3000WS0
|
56
|
+
EOS
|
57
|
+
end
|
58
|
+
puts "Added #{sketch_name}/config/hardware.yml"
|
59
|
+
|
60
|
+
File.open("#{sketch_name}/config/software.yml", 'w') do |file|
|
61
|
+
file << <<-EOS
|
62
|
+
arduino_root: /Applications/arduino/arduino-0007
|
63
|
+
EOS
|
64
|
+
end
|
65
|
+
puts "Added #{sketch_name}/config/software.yml"
|
66
|
+
|
67
|
+
puts
|
68
|
+
puts "Run 'rake -T' inside your sketch dir to learn how to compile and upload it."
|
data/lib/rad.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# TOOD:
|
2
|
+
# ON and OFF
|
3
|
+
# HIGH and LOW
|
4
|
+
|
5
|
+
class ArduinoSketch
|
6
|
+
def initialize
|
7
|
+
@declarations = []
|
8
|
+
@pin_modes = {:output => [], :input => []}
|
9
|
+
@accessors = []
|
10
|
+
@signatures = []
|
11
|
+
@helper_methods = ""
|
12
|
+
end
|
13
|
+
|
14
|
+
def output_pin(num, opts={})
|
15
|
+
raise ArgumentError, "can only define pin from Fixnum, got #{num.class}" unless num.is_a?(Fixnum)
|
16
|
+
@pin_modes[:output] << num
|
17
|
+
if opts[:as]
|
18
|
+
@declarations << "int _#{opts[:as]} = #{num};"
|
19
|
+
@accessors << "int #{opts[:as]}(){\nreturn _#{opts[:as]};\n}"
|
20
|
+
@signatures << "int #{opts[:as]}();"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def output_pins(nums)
|
25
|
+
ar = Array(nums)
|
26
|
+
ar.each {|n| output_pin(n)}
|
27
|
+
end
|
28
|
+
|
29
|
+
def input_pin(num, opts={})
|
30
|
+
raise ArgumentError, "can only define pin from Fixnum, got #{num.class}" unless num.is_a?(Fixnum)
|
31
|
+
@pin_modes[:input] << num
|
32
|
+
if opts[:as]
|
33
|
+
@declarations << "int _#{opts[:as]} = #{num};"
|
34
|
+
@accessors << "int #{opts[:as]}(){\nreturn _#{opts[:as]};\n}"
|
35
|
+
@signatures << "int #{opts[:as]}();"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def input_pins(nums)
|
40
|
+
ar = Array(nums)
|
41
|
+
ar.each {|n| input_pin(n)}
|
42
|
+
end
|
43
|
+
|
44
|
+
def add(st)
|
45
|
+
@helper_methods << "\n#{st}\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
def compose_setup # also composes headers and signatures
|
49
|
+
result = "#include <WProgram.h>\nvoid loop();\nvoid setup();"
|
50
|
+
@signatures.each do |dec|
|
51
|
+
result << "#{dec}\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
@declarations.each do |dec|
|
55
|
+
result << "#{dec}\n"
|
56
|
+
end
|
57
|
+
@accessors.each do |ac|
|
58
|
+
result << "#{ac}\n"
|
59
|
+
end
|
60
|
+
result << "void setup(){\n"
|
61
|
+
@pin_modes.each do |k,v|
|
62
|
+
v.each do |value|
|
63
|
+
result << "pinMode(#{value}, #{k.to_s.upcase});\n"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
result<<"}\n#{@helper_methods}"
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def serial_boilerplate
|
72
|
+
# TODO:
|
73
|
+
# take away serial_begin and write a real class method
|
74
|
+
# serial_print and serial_println need signatures for every combination of argument options
|
75
|
+
<<-CODE
|
76
|
+
void serial_begin(int speed){
|
77
|
+
Serial.begin(speed)
|
78
|
+
}
|
79
|
+
int serial_available(){
|
80
|
+
Serial.available() > 0
|
81
|
+
}
|
82
|
+
int serial_read(){
|
83
|
+
Serial.read()
|
84
|
+
}
|
85
|
+
void serial_flush(){
|
86
|
+
Serial.flush()
|
87
|
+
}
|
88
|
+
void serial_print()
|
89
|
+
void serial_println()
|
90
|
+
Serial.print(data)
|
91
|
+
Serial.println(data)
|
92
|
+
CODE
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
# Arduino makefile
|
2
|
+
#
|
3
|
+
# This makefile allows you to build sketches from the command line
|
4
|
+
# without the Arduino environment (or Java).
|
5
|
+
#
|
6
|
+
# The Arduino environment does preliminary processing on a sketch before
|
7
|
+
# compiling it. If you're using this makefile instead, you'll need to do
|
8
|
+
# a few things differently:
|
9
|
+
#
|
10
|
+
# - Give your program's file a .cpp extension (e.g. foo.cpp).
|
11
|
+
#
|
12
|
+
# - Put this line at top of your code: #include <WProgram.h>
|
13
|
+
#
|
14
|
+
# - Write prototypes for all your functions (or define them before you
|
15
|
+
# call them). A prototype declares the types of parameters a
|
16
|
+
# function will take and what type of value it will return. This
|
17
|
+
# means that you can have a call to a function before the definition
|
18
|
+
# of the function. A function prototype looks like the first line of
|
19
|
+
# the function, with a semi-colon at the end. For example:
|
20
|
+
# int digitalRead(int pin);
|
21
|
+
#
|
22
|
+
# Instructions for using the makefile:
|
23
|
+
#
|
24
|
+
# 1. Copy this file into the folder with your sketch.
|
25
|
+
#
|
26
|
+
# 2. Below, modify the line containing "TARGET" to refer to the name of
|
27
|
+
# of your program's file without an extension (e.g. TARGET = foo).
|
28
|
+
#
|
29
|
+
# 3. Modify the line containg "ARDUINO" to point the directory that
|
30
|
+
# contains the Arduino core (for normal Arduino installations, this
|
31
|
+
# is the lib/targets/arduino sub-directory).
|
32
|
+
#
|
33
|
+
# 4. Modify the line containing "PORT" to refer to the filename
|
34
|
+
# representing the USB or serial connection to your Arduino board
|
35
|
+
# (e.g. PORT = /dev/tty.USB0). If the exact name of this file
|
36
|
+
# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*).
|
37
|
+
#
|
38
|
+
# 5. At the command line, change to the directory containing your
|
39
|
+
# program's file and the makefile.
|
40
|
+
#
|
41
|
+
# 6. Type "make" and press enter to compile/verify your program.
|
42
|
+
#
|
43
|
+
# 7. Type "make upload", reset your Arduino board, and press enter to
|
44
|
+
# upload your program to the Arduino board.
|
45
|
+
#
|
46
|
+
# $Id$
|
47
|
+
|
48
|
+
PORT = <%= params[:serial_port] %>
|
49
|
+
TARGET = <%= params[:target] %>
|
50
|
+
ARDUINO = <%= params[:arduino_root] %>/lib/targets/arduino
|
51
|
+
SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c $(ARDUINO)/WInterrupts.c
|
52
|
+
CXXSRC = $(TARGET).cpp $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WRandom.cpp
|
53
|
+
MCU = atmega8
|
54
|
+
F_CPU = 16000000
|
55
|
+
FORMAT = ihex
|
56
|
+
UPLOAD_RATE = 19200
|
57
|
+
|
58
|
+
# Name of this Makefile (used for "make depend").
|
59
|
+
MAKEFILE = Makefile
|
60
|
+
|
61
|
+
# Debugging format.
|
62
|
+
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
|
63
|
+
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
|
64
|
+
DEBUG = stabs
|
65
|
+
|
66
|
+
OPT = s
|
67
|
+
|
68
|
+
# Place -D or -U options here
|
69
|
+
CDEFS = -DF_CPU=$(F_CPU)
|
70
|
+
CXXDEFS = -DF_CPU=$(F_CPU)
|
71
|
+
|
72
|
+
# Place -I options here
|
73
|
+
CINCS = -I$(ARDUINO)
|
74
|
+
CXXINCS = -I$(ARDUINO)
|
75
|
+
|
76
|
+
# Compiler flag to set the C Standard level.
|
77
|
+
# c89 - "ANSI" C
|
78
|
+
# gnu89 - c89 plus GCC extensions
|
79
|
+
# c99 - ISO C99 standard (not yet fully implemented)
|
80
|
+
# gnu99 - c99 plus GCC extensions
|
81
|
+
CSTANDARD = -std=gnu99
|
82
|
+
CDEBUG = -g$(DEBUG)
|
83
|
+
CWARN = -Wall -Wstrict-prototypes
|
84
|
+
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
|
85
|
+
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
|
86
|
+
|
87
|
+
CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
|
88
|
+
CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT)
|
89
|
+
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
|
90
|
+
LDFLAGS =
|
91
|
+
|
92
|
+
|
93
|
+
# Programming support using avrdude. Settings and variables.
|
94
|
+
AVRDUDE_PROGRAMMER = stk500
|
95
|
+
AVRDUDE_PORT = $(PORT)
|
96
|
+
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
|
97
|
+
AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -C <%= params[:arduino_root] %>/tools/avr/etc/avrdude.conf -c $(AVRDUDE_PROGRAMMER) \
|
98
|
+
-b $(UPLOAD_RATE)
|
99
|
+
|
100
|
+
# Program settings
|
101
|
+
CC = avr-gcc
|
102
|
+
CXX = avr-g++
|
103
|
+
OBJCOPY = avr-objcopy
|
104
|
+
OBJDUMP = avr-objdump
|
105
|
+
SIZE = avr-size
|
106
|
+
NM = avr-nm
|
107
|
+
AVRDUDE = avrdude
|
108
|
+
REMOVE = rm -f
|
109
|
+
MV = mv -f
|
110
|
+
|
111
|
+
# Define all object files.
|
112
|
+
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
|
113
|
+
|
114
|
+
# Define all listing files.
|
115
|
+
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
|
116
|
+
|
117
|
+
# Combine all necessary flags and optional flags.
|
118
|
+
# Add target processor to flags.
|
119
|
+
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
|
120
|
+
ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
|
121
|
+
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
|
122
|
+
|
123
|
+
|
124
|
+
# Default target.
|
125
|
+
all: build
|
126
|
+
|
127
|
+
build: elf hex
|
128
|
+
|
129
|
+
elf: $(TARGET).elf
|
130
|
+
hex: $(TARGET).hex
|
131
|
+
eep: $(TARGET).eep
|
132
|
+
lss: $(TARGET).lss
|
133
|
+
sym: $(TARGET).sym
|
134
|
+
|
135
|
+
# Program the device.
|
136
|
+
upload: $(TARGET).hex
|
137
|
+
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
|
143
|
+
COFFCONVERT=$(OBJCOPY) --debugging \
|
144
|
+
--change-section-address .data-0x800000 \
|
145
|
+
--change-section-address .bss-0x800000 \
|
146
|
+
--change-section-address .noinit-0x800000 \
|
147
|
+
--change-section-address .eeprom-0x810000
|
148
|
+
|
149
|
+
|
150
|
+
coff: $(TARGET).elf
|
151
|
+
$(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
|
152
|
+
|
153
|
+
|
154
|
+
extcoff: $(TARGET).elf
|
155
|
+
$(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
|
156
|
+
|
157
|
+
|
158
|
+
.SUFFIXES: .elf .hex .eep .lss .sym
|
159
|
+
|
160
|
+
.elf.hex:
|
161
|
+
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
|
162
|
+
|
163
|
+
.elf.eep:
|
164
|
+
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
165
|
+
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
|
166
|
+
|
167
|
+
# Create extended listing file from ELF output file.
|
168
|
+
.elf.lss:
|
169
|
+
$(OBJDUMP) -h -S $< > $@
|
170
|
+
|
171
|
+
# Create a symbol table from ELF output file.
|
172
|
+
.elf.sym:
|
173
|
+
$(NM) -n $< > $@
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
# Link: create ELF output file from object files.
|
178
|
+
$(TARGET).elf: $(OBJ)
|
179
|
+
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
|
180
|
+
|
181
|
+
|
182
|
+
# Compile: create object files from C++ source files.
|
183
|
+
.cpp.o:
|
184
|
+
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
|
185
|
+
|
186
|
+
# Compile: create object files from C source files.
|
187
|
+
.c.o:
|
188
|
+
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
189
|
+
|
190
|
+
|
191
|
+
# Compile: create assembler files from C source files.
|
192
|
+
.c.s:
|
193
|
+
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
194
|
+
|
195
|
+
|
196
|
+
# Assemble: create object files from assembler source files.
|
197
|
+
.S.o:
|
198
|
+
$(CC) -c $(ALL_ASFLAGS) $< -o $@
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
# Target: clean project.
|
203
|
+
clean:
|
204
|
+
$(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
|
205
|
+
$(TARGET).map $(TARGET).sym $(TARGET).lss \
|
206
|
+
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
|
207
|
+
|
208
|
+
depend:
|
209
|
+
if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
|
210
|
+
then \
|
211
|
+
sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
|
212
|
+
$(MAKEFILE).$$$$ && \
|
213
|
+
$(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
|
214
|
+
fi
|
215
|
+
echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
|
216
|
+
>> $(MAKEFILE); \
|
217
|
+
$(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
|
218
|
+
|
219
|
+
.PHONY: all build elf hex eep lss sym program coff extcoff clean depend
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
class Makefile
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# build the sketch Makefile for the given template based on the values in its software and hardware config files
|
7
|
+
def compose_for_sketch(sketch_name)
|
8
|
+
params = hardware_params.merge software_params
|
9
|
+
|
10
|
+
params[:target] = sketch_name
|
11
|
+
|
12
|
+
e = ERB.new File.open("#{File.dirname(__FILE__)}/makefile.erb").read
|
13
|
+
|
14
|
+
File.open("#{RAD_ROOT}/#{sketch_name}/Makefile", "w") do |f|
|
15
|
+
f << e.result(binding)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def hardware_params
|
20
|
+
return @hardware_params if @hardware_params
|
21
|
+
@hardware_params = {}
|
22
|
+
|
23
|
+
File.open( "#{RAD_ROOT}/config/hardware.yml" ) do |yf|
|
24
|
+
YAML.load_documents( yf ) do |ydoc|
|
25
|
+
@hardware_params[:serial_port] = ydoc["serial_port"]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
@hardware_params
|
30
|
+
end
|
31
|
+
|
32
|
+
def software_params
|
33
|
+
return @software_params if @software_params
|
34
|
+
@software_params = {}
|
35
|
+
|
36
|
+
File.open( "#{RAD_ROOT}/config/software.yml" ) do |yf|
|
37
|
+
YAML.load_documents( yf ) do |ydoc|
|
38
|
+
@software_params[:arduino_root] = ydoc["arduino_root"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
@software_params
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|