madrona-rad 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +14 -0
- data/Manifest.txt +41 -18
- data/Rakefile +5 -0
- data/bin/rad +16 -6
- data/lib/examples/blink_m_address_assignment.rb +104 -0
- data/lib/examples/blink_m_multi.rb +61 -0
- data/lib/examples/configure_pa_lcd_boot.rb +91 -0
- data/lib/examples/external_variables.rb +5 -1
- data/lib/examples/hello_array.rb +48 -0
- data/lib/examples/hello_array2.rb +79 -0
- data/lib/examples/hello_array_eeprom.rb +61 -0
- data/lib/examples/hello_eeprom.rb +4 -7
- data/lib/examples/hello_eeprom_lcdpa.rb +81 -0
- data/lib/examples/hello_lcd_charset.rb +75 -0
- data/lib/examples/hello_pa_lcd.rb +59 -0
- data/lib/examples/hysteresis_duel.rb +39 -0
- data/lib/examples/motor_knob.rb +30 -0
- data/lib/examples/orig_servo_throttle.rb +1 -1
- data/lib/examples/servo_calibrate_continuous.rb +92 -0
- data/lib/examples/servo_throttle.rb +1 -1
- data/lib/examples/sparkfun_lcd.rb +2 -2
- data/lib/examples/spectra_soft_pot.rb +34 -0
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp +60 -25
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +8 -2
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +46 -27
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +5 -2
- data/lib/libraries/Stepper/Stepper.cpp +220 -0
- data/lib/libraries/Stepper/Stepper.h +86 -0
- data/lib/libraries/Stepper/keywords.txt +28 -0
- data/lib/libraries/Wire/utility/twi.c +449 -0
- data/lib/libraries/Wire/utility/twi.h +57 -0
- data/lib/plugins/blink_m.rb +79 -46
- data/lib/plugins/hysteresis.rb +52 -0
- data/lib/plugins/lcd_padding.rb +39 -0
- data/lib/plugins/spectra_symbol.rb +79 -0
- data/lib/rad/arduino_plugin.rb +21 -0
- data/lib/rad/arduino_sketch.rb +231 -53
- data/lib/rad/init.rb +2 -2
- data/lib/rad/rad_processor.rb +42 -1
- data/lib/rad/rad_type_checker.rb +26 -0
- data/lib/rad/sim/arduino_sketch.rb +57 -0
- data/lib/rad/tasks/build_and_make.rake +4 -4
- data/lib/rad/variable_processing.rb +49 -12
- data/lib/rad/version.rb +1 -1
- data/test/test_array_processing.rb +179 -0
- data/test/test_plugin_loading.rb +151 -0
- data/test/test_translation_post_processing.rb +185 -0
- data/{lib/test → test}/test_variable_processing.rb +63 -13
- data/website/index.html +8 -7
- metadata +66 -30
- data/lib/test/test_array_processing.rb +0 -78
data/lib/rad/arduino_plugin.rb
CHANGED
@@ -173,6 +173,27 @@ end
|
|
173
173
|
STR
|
174
174
|
end
|
175
175
|
|
176
|
+
def self.add_sensor_struct
|
177
|
+
$plugin_structs[:sensor] = <<-STR
|
178
|
+
struct hysteresis {
|
179
|
+
int pin;
|
180
|
+
int state;
|
181
|
+
};
|
182
|
+
STR
|
183
|
+
end
|
184
|
+
|
185
|
+
def self.add_spectra_struct
|
186
|
+
$plugin_structs[:spectra] = <<-STR
|
187
|
+
struct spectra {
|
188
|
+
int pin;
|
189
|
+
int state;
|
190
|
+
int r1;
|
191
|
+
int r2;
|
192
|
+
int r3;
|
193
|
+
};
|
194
|
+
STR
|
195
|
+
end
|
196
|
+
|
176
197
|
|
177
198
|
def self.check_for_plugin_use(sketch_string, plugin_string, file_name) # rename klass to filename
|
178
199
|
$plugin_structs = $plugin_structs || {}
|
data/lib/rad/arduino_sketch.rb
CHANGED
@@ -163,14 +163,21 @@ class ArduinoSketch
|
|
163
163
|
def initialize #:nodoc:
|
164
164
|
@servo_settings = [] # need modular way to add this
|
165
165
|
@debounce_settings = [] # need modular way to add this
|
166
|
+
@hysteresis_settings = []
|
167
|
+
@spectra_settings = []
|
166
168
|
@servo_pins = []
|
167
169
|
@debounce_pins = []
|
170
|
+
@hysteresis_pins = []
|
171
|
+
@spectra_pins = []
|
168
172
|
$external_array_vars = []
|
169
173
|
$external_vars =[]
|
170
174
|
$external_var_identifiers = []
|
171
175
|
$sketch_methods = []
|
172
176
|
$load_libraries ||= []
|
173
177
|
$defines ||= []
|
178
|
+
$define_types = {}
|
179
|
+
$array_types = {}
|
180
|
+
$array_index_helpers = ('a'..'zz').to_a
|
174
181
|
|
175
182
|
@declarations = []
|
176
183
|
@pin_modes = {:output => [], :input => []}
|
@@ -295,20 +302,36 @@ class ArduinoSketch
|
|
295
302
|
# array "char buffer[32]"
|
296
303
|
# result: char buffer[32];
|
297
304
|
# todo
|
298
|
-
# need to feed array external array identifiers to rtc if they are in plugins or libraries
|
305
|
+
# need to feed array external array identifiers to rtc if they are in plugins or libraries, (not so sure about this will do more testing)
|
299
306
|
def array(arg)
|
300
307
|
if arg
|
301
308
|
arg = arg.chomp.rstrip.lstrip
|
302
309
|
name = arg.scan(/\s*(\w*)\[\d*\]?/).first.first
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
310
|
+
|
311
|
+
# following 10 lines seem to be unnecessary
|
312
|
+
# and are left over from early array work
|
313
|
+
# but they are still here for a bit
|
314
|
+
# determine if there is an array assignement, and how many
|
315
|
+
# then eliminate the assignment and update the array size
|
316
|
+
# if /\w*\[\d*\]\s*\=\s*\{(.*)\}/ =~ arg
|
317
|
+
# assignment = arg.scan(/\w*\[\d*\]\s*\=\s*\{(.*)\}/).first.first
|
318
|
+
# array_size = assignment.split(",").length
|
319
|
+
# if /\[(\s*)\]/ =~ arg
|
320
|
+
# arg.gsub!(/(\[\d*\])/, "[#{array_size}]")
|
321
|
+
# end
|
322
|
+
# end
|
323
|
+
# arg = arg.scan(/^((\s*|\w*)*\s*\w*\[\d*\])?/).first.first
|
324
|
+
|
325
|
+
# help rad_processor do a better job with array types
|
326
|
+
types = ["int", "long", "char*", "unsigned int", "unsigned long", "byte", "bool", "float" ]
|
327
|
+
types.each_with_index do |type, i|
|
328
|
+
@type = types[i] if /#{type}/ =~ arg
|
309
329
|
end
|
310
|
-
|
330
|
+
raise ArgumentError, "type not currently supported.. got: #{arg}. Currently supporting #{types.join(", ")}" unless @type
|
331
|
+
|
311
332
|
arg = "#{arg};" unless arg[-1,1] == ";"
|
333
|
+
$array_types[name] = @type
|
334
|
+
@type = nil
|
312
335
|
$external_var_identifiers << name unless $external_var_identifiers.include?(name)
|
313
336
|
# add array_name declaration
|
314
337
|
$external_array_vars << arg unless $external_array_vars.include?(arg)
|
@@ -317,31 +340,39 @@ class ArduinoSketch
|
|
317
340
|
|
318
341
|
# define "DS1307_SEC 0"
|
319
342
|
# result: #define DS1307_SEC 0
|
343
|
+
# note we send the constant identifiers and type to our rad_type_checker
|
344
|
+
# however, it only knows about long, float, str....
|
345
|
+
# so we don't send ints ...yet..
|
346
|
+
# need more testing
|
320
347
|
def define(arg)
|
321
348
|
if arg
|
322
349
|
arg = arg.chomp.rstrip.lstrip
|
323
|
-
|
350
|
+
name = arg.split(" ").first
|
351
|
+
value = arg.gsub!("#{name} ","")
|
352
|
+
# negative
|
353
|
+
if value =~ /^-(\d|x)*$/
|
354
|
+
type = "long"
|
355
|
+
# negative float
|
356
|
+
elsif value =~ /^-(\d|\.|x)*$/
|
357
|
+
type = "float"
|
358
|
+
elsif value =~ /[a-zA-Z]/
|
359
|
+
type = "str"
|
360
|
+
value = "\"#{value}\""
|
361
|
+
elsif value !~ /(\.|x)/
|
362
|
+
type = "long"
|
363
|
+
elsif value =~ /(\d*\.\d*)/ # and no
|
364
|
+
type = "float"
|
365
|
+
elsif value =~ /0x\d\d/
|
366
|
+
type = "byte"
|
367
|
+
else
|
368
|
+
raise ArgumentError, "opps, could not determine the define type, got #{value}"
|
369
|
+
end
|
370
|
+
$define_types[name] = type
|
371
|
+
arg = "#define #{name} #{value}"
|
324
372
|
$defines << arg
|
373
|
+
dummy_for_testing = arg, type
|
325
374
|
end
|
326
375
|
end
|
327
|
-
|
328
|
-
# need better location.. module?
|
329
|
-
def self.add_to_setup(meth)
|
330
|
-
meth = meth.gsub("setup", "additional_setup")
|
331
|
-
post_process_ruby_to_c_methods(meth)
|
332
|
-
end
|
333
|
-
|
334
|
-
def self.post_process_ruby_to_c_methods(e)
|
335
|
-
clean_c_methods = []
|
336
|
-
# need to take a look at the \(unsigned in the line below not sure if we are really trying to catch something like that
|
337
|
-
if e !~ /^\s*(#{C_VAR_TYPES})(\W{1,6}|\(unsigned\()(#{$external_var_identifiers.join("|")})/ || $external_var_identifiers.empty?
|
338
|
-
# use the list of identifers the external_vars method of the sketch and remove the parens the ruby2c sometime adds to variables
|
339
|
-
# keep an eye on the gsub!.. are we getting nil errors
|
340
|
-
e.gsub!(/((#{$external_var_identifiers.join("|")})\(\))/, '\2') unless $external_var_identifiers.empty?
|
341
|
-
clean_c_methods << e
|
342
|
-
end
|
343
|
-
return clean_c_methods.join( "\n" )
|
344
|
-
end
|
345
376
|
|
346
377
|
# Configure a single pin for output and setup a method to refer to that pin, i.e.:
|
347
378
|
#
|
@@ -376,7 +407,7 @@ class ArduinoSketch
|
|
376
407
|
return
|
377
408
|
when :freq_out || :freq_gen || :frequency_generator
|
378
409
|
frequency_timer(num, opts)
|
379
|
-
|
410
|
+
return
|
380
411
|
when :i2c
|
381
412
|
two_wire(num, opts) unless @@twowire_inc
|
382
413
|
return #
|
@@ -463,13 +494,17 @@ class ArduinoSketch
|
|
463
494
|
servo(num, opts)
|
464
495
|
# move this to better place ...
|
465
496
|
# should probably go along with servo code into plugin
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
497
|
+
@@servo_dh ||= FALSE
|
498
|
+
if (@@servo_dh == FALSE) # on second instance this stuff can't be repeated - BBR
|
499
|
+
@@servo_dh = TRUE
|
500
|
+
@declarations << "void servo_refresh(void);"
|
501
|
+
helper_methods = []
|
502
|
+
helper_methods << "void servo_refresh(void)"
|
503
|
+
helper_methods << "{"
|
504
|
+
helper_methods << "\tServo::refresh();"
|
505
|
+
helper_methods << "}"
|
506
|
+
@helper_methods += "\n#{helper_methods.join("\n")}"
|
507
|
+
end
|
473
508
|
end
|
474
509
|
|
475
510
|
## this won't work at all... no pins
|
@@ -535,6 +570,18 @@ class ArduinoSketch
|
|
535
570
|
adjust = opts[:adjust] ? opts[:adjust] : 200
|
536
571
|
@debounce_settings << "dbce[#{num}].state = #{state}, dbce[#{num}].read = 0, dbce[#{num}].prev = #{prev}, dbce[#{num}].time = 0, dbce[#{num}].adjust = #{adjust}"
|
537
572
|
end
|
573
|
+
if opts[:device] == :sensor
|
574
|
+
ArduinoPlugin.add_sensor_struct
|
575
|
+
count = @hysteresis_pins.length
|
576
|
+
@hysteresis_pins << num
|
577
|
+
@hysteresis_settings << "hyst[#{count}].pin = #{num}, hyst[#{count}].state = 0"
|
578
|
+
end
|
579
|
+
if opts[:device] == :spectra
|
580
|
+
ArduinoPlugin.add_spectra_struct
|
581
|
+
count = @spectra_pins.length
|
582
|
+
@spectra_pins << num
|
583
|
+
@spectra_settings << "spec[#{count}].pin = #{num}, spec[#{count}].state = 10, spec[#{count}].r1 = 0, spec[#{count}].r2 = 0, spec[#{count}].r3 = 0"
|
584
|
+
end
|
538
585
|
@declarations << "int _#{opts[ :as ]} = #{num};"
|
539
586
|
|
540
587
|
accessor = []
|
@@ -660,15 +707,36 @@ class ArduinoSketch
|
|
660
707
|
accessor << "void println(SWSerLCDpa& s) {"
|
661
708
|
accessor << "\treturn s.println();"
|
662
709
|
accessor << "}"
|
663
|
-
|
710
|
+
accessor << "void clearscr(SWSerLCDpa& s) {"
|
664
711
|
accessor << "\treturn s.clearscr();"
|
665
712
|
accessor << "}"
|
666
|
-
|
667
|
-
|
713
|
+
accessor << "void clearline(SWSerLCDpa& s, int line) {"
|
714
|
+
accessor << "\treturn s.clearline( line );"
|
715
|
+
accessor << "}"
|
716
|
+
accessor << "void setxy( SWSerLCDpa& s, int x, int y) {"
|
717
|
+
accessor << "\treturn s.setxy( x, y );"
|
718
|
+
accessor << "}"
|
719
|
+
accessor << "void clearscr(SWSerLCDpa& s, const char *str) {"
|
720
|
+
accessor << "\treturn s.clearscr(str);"
|
721
|
+
accessor << "}"
|
722
|
+
accessor << "void clearline(SWSerLCDpa& s, int line, const char *str) {"
|
723
|
+
accessor << "\treturn s.clearline( line, str );"
|
724
|
+
accessor << "}"
|
725
|
+
accessor << "void setxy( SWSerLCDpa& s, int x, int y, const char *str) {"
|
726
|
+
accessor << "\treturn s.setxy( x, y, str );"
|
727
|
+
accessor << "}"
|
728
|
+
accessor << "void clearscr(SWSerLCDpa& s, int n) {"
|
729
|
+
accessor << "\treturn s.clearscr(n);"
|
730
|
+
accessor << "}"
|
731
|
+
accessor << "void clearline(SWSerLCDpa& s, int line, int n) {"
|
732
|
+
accessor << "\treturn s.clearline( line, n );"
|
733
|
+
accessor << "}"
|
734
|
+
accessor << "void setxy( SWSerLCDpa& s, int x, int y, int n) {"
|
735
|
+
accessor << "\treturn s.setxy( x, y, n );"
|
736
|
+
accessor << "}"
|
737
|
+
accessor << "void setgeo( SWSerLCDpa& s, int g) {"
|
738
|
+
accessor << "\treturn s.setgeo( g );"
|
668
739
|
accessor << "}"
|
669
|
-
accessor << "void setgeo( SWSerLCDpa& s, int i ) {"
|
670
|
-
accessor << "\treturn s.setgeo( i );"
|
671
|
-
accessor << "}"
|
672
740
|
accessor << "void setintensity( SWSerLCDpa& s, int i ) {"
|
673
741
|
accessor << "\treturn s.setintensity( i );"
|
674
742
|
accessor << "}"
|
@@ -677,9 +745,6 @@ class ArduinoSketch
|
|
677
745
|
accessor << "}"
|
678
746
|
accessor << "void outofBignum(SWSerLCDpa& s) {"
|
679
747
|
accessor << "\treturn s.outofBignum();"
|
680
|
-
accessor << "}"
|
681
|
-
accessor << "void setxy( SWSerLCDpa& s, int x, int y) {"
|
682
|
-
accessor << "\treturn s.setxy( x, y );"
|
683
748
|
accessor << "}"
|
684
749
|
accessor << "void println( SWSerLCDpa& s, char c ) {"
|
685
750
|
accessor << "\treturn s.println( c );"
|
@@ -757,21 +822,30 @@ class ArduinoSketch
|
|
757
822
|
accessor << "void print( SWSerLCDsf& s, char* str ) {"
|
758
823
|
accessor << "\treturn s.print( str );"
|
759
824
|
accessor << "}"
|
760
|
-
|
825
|
+
accessor << "void clearscr(SWSerLCDsf& s) {"
|
761
826
|
accessor << "\treturn s.clearscr();"
|
762
827
|
accessor << "}"
|
763
|
-
accessor << "void
|
764
|
-
accessor << "\treturn s.
|
828
|
+
accessor << "void setxy( SWSerLCDsf& s, int x, int y) {"
|
829
|
+
accessor << "\treturn s.setxy( x, y );"
|
830
|
+
accessor << "}"
|
831
|
+
accessor << "void clearscr(SWSerLCDsf& s, const char *str) {"
|
832
|
+
accessor << "\treturn s.clearscr(str);"
|
833
|
+
accessor << "}"
|
834
|
+
accessor << "void clearscr(SWSerLCDsf& s, int n) {"
|
835
|
+
accessor << "\treturn s.clearscr(n);"
|
836
|
+
accessor << "}"
|
837
|
+
accessor << "void setxy( SWSerLCDsf& s, int x, int y, const char *str) {"
|
838
|
+
accessor << "\treturn s.setxy( x, y, str );"
|
839
|
+
accessor << "}"
|
840
|
+
accessor << "void setxy( SWSerLCDsf& s, int x, int y, int n) {"
|
841
|
+
accessor << "\treturn s.setxy( x, y, n );"
|
842
|
+
accessor << "}"
|
843
|
+
accessor << "void setgeo( SWSerLCDsf& s, int g) {"
|
844
|
+
accessor << "\treturn s.setgeo( g );"
|
765
845
|
accessor << "}"
|
766
|
-
accessor << "void setgeo( SWSerLCDsf& s, int i ) {"
|
767
|
-
accessor << "\treturn s.setgeo( i );"
|
768
|
-
accessor << "}"
|
769
846
|
accessor << "void setintensity( SWSerLCDsf& s, int i ) {"
|
770
847
|
accessor << "\treturn s.setintensity( i );"
|
771
848
|
accessor << "}"
|
772
|
-
accessor << "void setxy( SWSerLCDsf& s, int x, int y) {"
|
773
|
-
accessor << "\treturn s.setxy( x, y );"
|
774
|
-
accessor << "}"
|
775
849
|
accessor << "void setcmd( SWSerLCDsf& s, uint8_t a, uint8_t b) {"
|
776
850
|
accessor << "\treturn s.setcmd( a, b );"
|
777
851
|
accessor << "}"
|
@@ -785,6 +859,83 @@ class ArduinoSketch
|
|
785
859
|
end
|
786
860
|
|
787
861
|
|
862
|
+
def twowire_stepper(pin1, pin2, opts={}) # servo motor routines #
|
863
|
+
raise ArgumentError, "can only define pin1 from Fixnum, got #{pin1.class}" unless pin1.is_a?(Fixnum)
|
864
|
+
raise ArgumentError, "can only define pin2 from Fixnum, got #{pin2.class}" unless pin2.is_a?(Fixnum)
|
865
|
+
|
866
|
+
st_speed = opts[:speed] ? opts[:speed] : 30
|
867
|
+
st_steps = opts[:steps] ? opts[:steps] : 100
|
868
|
+
|
869
|
+
if opts[:as]
|
870
|
+
@declarations << "Stepper _#{opts[ :as ]} = Stepper(#{st_steps},#{pin1},#{pin2});"
|
871
|
+
accessor = []
|
872
|
+
$load_libraries << "Stepper"
|
873
|
+
accessor << "Stepper& #{opts[ :as ]}() {"
|
874
|
+
accessor << "\treturn _#{opts[ :as ]};"
|
875
|
+
accessor << "}"
|
876
|
+
@@stepr_inc ||= FALSE
|
877
|
+
if (@@stepr_inc == FALSE) # on second instance this stuff can't be repeated - BBR
|
878
|
+
@@stepr_inc = TRUE
|
879
|
+
accessor << "void set_speed( Stepper& s, long sp ) {"
|
880
|
+
accessor << "\treturn s.set_speed( sp );"
|
881
|
+
accessor << "}"
|
882
|
+
accessor << "void set_steps( Stepper& s, int b ) {"
|
883
|
+
accessor << "\treturn s.set_steps( b );"
|
884
|
+
accessor << "}"
|
885
|
+
accessor << "int version( Stepper& s ) {"
|
886
|
+
accessor << "\treturn s.version();"
|
887
|
+
accessor << "}"
|
888
|
+
end
|
889
|
+
|
890
|
+
@accessors << accessor.join( "\n" )
|
891
|
+
|
892
|
+
@signatures << "Stepper& #{opts[ :as ]}();"
|
893
|
+
|
894
|
+
@other_setup << "\t_#{opts[ :as ]}.set_speed(#{st_speed});" if opts[:speed]
|
895
|
+
|
896
|
+
end
|
897
|
+
end
|
898
|
+
|
899
|
+
|
900
|
+
def fourwire_stepper( pin1, pin2, pin3, pin4, opts={}) # servo motor routines #
|
901
|
+
raise ArgumentError, "can only define pin1 from Fixnum, got #{pin1.class}" unless pin1.is_a?(Fixnum)
|
902
|
+
raise ArgumentError, "can only define pin2 from Fixnum, got #{pin2.class}" unless pin2.is_a?(Fixnum)
|
903
|
+
raise ArgumentError, "can only define pin3 from Fixnum, got #{pin3.class}" unless pin3.is_a?(Fixnum)
|
904
|
+
raise ArgumentError, "can only define pin4 from Fixnum, got #{pin4.class}" unless pin4.is_a?(Fixnum)
|
905
|
+
|
906
|
+
st_speed = opts[:speed] ? opts[:speed] : 30
|
907
|
+
st_steps = opts[:steps] ? opts[:steps] : 100
|
908
|
+
|
909
|
+
if opts[:as]
|
910
|
+
@declarations << "Stepper _#{opts[ :as ]} = Stepper(#{st_steps},#{pin1},#{pin2},#{pin3},#{pin4});"
|
911
|
+
accessor = []
|
912
|
+
$load_libraries << "Stepper"
|
913
|
+
accessor << "Stepper& #{opts[ :as ]}() {"
|
914
|
+
accessor << "\treturn _#{opts[ :as ]};"
|
915
|
+
accessor << "}"
|
916
|
+
@@stepr_inc ||= FALSE
|
917
|
+
if (@@stepr_inc == FALSE) # on second instance this stuff can't be repeated - BBR
|
918
|
+
@@stepr_inc = TRUE
|
919
|
+
accessor << "void set_speed( Stepper& s, long sp ) {"
|
920
|
+
accessor << "\treturn s.set_speed( sp );"
|
921
|
+
accessor << "}"
|
922
|
+
accessor << "void set_steps( Stepper& s, int b ) {"
|
923
|
+
accessor << "\treturn s.set_steps( b );"
|
924
|
+
accessor << "}"
|
925
|
+
accessor << "int version( Stepper& s ) {"
|
926
|
+
accessor << "\treturn s.version();"
|
927
|
+
accessor << "}"
|
928
|
+
end
|
929
|
+
|
930
|
+
@accessors << accessor.join( "\n" )
|
931
|
+
|
932
|
+
@signatures << "Stepper& #{opts[ :as ]}();"
|
933
|
+
|
934
|
+
@other_setup << "\t_#{opts[ :as ]}.set_speed(#{st_speed});" if opts[:speed]
|
935
|
+
|
936
|
+
end
|
937
|
+
end
|
938
|
+
|
788
939
|
|
789
940
|
def servo(pin, opts={}) # servo motor routines #
|
790
941
|
raise ArgumentError, "can only define pin from Fixnum, got #{pin.class}" unless pin.is_a?(Fixnum)
|
@@ -1090,6 +1241,16 @@ class ArduinoSketch
|
|
1090
1241
|
external_vars << "struct debounce dbce[#{array_size}] = { #{@debounce_settings.join(", ")} };" if $plugin_structs[:debounce]
|
1091
1242
|
external_vars << ""
|
1092
1243
|
|
1244
|
+
external_vars << "// hysteresis array"
|
1245
|
+
h_array_size = @hysteresis_settings.empty? ? 1 : @hysteresis_pins.length + 1 # conserve space if no variables needed
|
1246
|
+
external_vars << "struct hysteresis hyst[#{h_array_size}] = { #{@hysteresis_settings.join(", ")} };" if $plugin_structs[:sensor]
|
1247
|
+
external_vars << ""
|
1248
|
+
|
1249
|
+
external_vars << "// spectrasymbol soft pot array"
|
1250
|
+
sp_array_size = @spectra_settings.empty? ? 1 : @spectra_pins.length + 1 # conserve space if no variables needed
|
1251
|
+
external_vars << "struct spectra spec[#{sp_array_size}] = { #{@spectra_settings.join(", ")} };" if $plugin_structs[:spectra]
|
1252
|
+
external_vars << ""
|
1253
|
+
|
1093
1254
|
$external_array_vars.each { |var| external_vars << var } if $external_array_vars
|
1094
1255
|
|
1095
1256
|
external_vars << "\n" + comment_box( "variable and accessors" )
|
@@ -1194,6 +1355,23 @@ class ArduinoSketch
|
|
1194
1355
|
result
|
1195
1356
|
end
|
1196
1357
|
|
1358
|
+
def self.add_to_setup(meth)
|
1359
|
+
meth = meth.gsub("setup", "additional_setup")
|
1360
|
+
post_process_ruby_to_c_methods(meth)
|
1361
|
+
end
|
1362
|
+
|
1363
|
+
def self.post_process_ruby_to_c_methods(e)
|
1364
|
+
clean_c_methods = []
|
1365
|
+
# need to take a look at the \(unsigned in the line below not sure if we are really trying to catch something like that
|
1366
|
+
if e !~ /^\s*(#{C_VAR_TYPES})(\W{1,6}|\(unsigned\()(#{$external_var_identifiers.join("|")})/ || $external_var_identifiers.empty?
|
1367
|
+
# use the list of identifers the external_vars method of the sketch and remove the parens the ruby2c sometime adds to variables
|
1368
|
+
# keep an eye on the gsub!.. are we getting nil errors
|
1369
|
+
e.gsub!(/((#{$external_var_identifiers.join("|")})\(\))/, '\2') unless $external_var_identifiers.empty?
|
1370
|
+
clean_c_methods << e
|
1371
|
+
end
|
1372
|
+
return clean_c_methods.join( "\n" )
|
1373
|
+
end
|
1374
|
+
|
1197
1375
|
private
|
1198
1376
|
|
1199
1377
|
def serial_boilerplate #:nodoc:
|
data/lib/rad/init.rb
CHANGED
@@ -5,10 +5,10 @@ unless defined?(PROJECT_DIR_NAME)
|
|
5
5
|
PROJECT_DIR_NAME = a[a.length-1]
|
6
6
|
end
|
7
7
|
|
8
|
-
PLUGIN_C_VAR_TYPES = "int|void|unsigned|long|short|uint8_t|static|byte"
|
8
|
+
PLUGIN_C_VAR_TYPES = "int|void|unsigned|long|short|uint8_t|static|byte|char\\*"
|
9
9
|
|
10
10
|
|
11
|
-
%w(generators/makefile/makefile.rb rad_processor.rb rad_rewriter.rb variable_processing.rb arduino_sketch.rb arduino_plugin.rb tasks/rad.rb).each do |path|
|
11
|
+
%w(generators/makefile/makefile.rb rad_processor.rb rad_rewriter.rb rad_type_checker.rb variable_processing.rb arduino_sketch.rb arduino_plugin.rb tasks/rad.rb).each do |path|
|
12
12
|
require File.expand_path("#{RAD_ROOT}/vendor/rad/#{path}")
|
13
13
|
end
|
14
14
|
|
data/lib/rad/rad_processor.rb
CHANGED
@@ -6,7 +6,7 @@ class RADProcessor < RubyToAnsiC
|
|
6
6
|
unless defined? @translator then
|
7
7
|
@translator = CompositeSexpProcessor.new
|
8
8
|
@translator << RADRewriter.new
|
9
|
-
@translator <<
|
9
|
+
@translator << RADTypeChecker.new
|
10
10
|
@translator << R2CRewriter.new
|
11
11
|
@translator << self.new
|
12
12
|
@translator.on_error_in(:defn) do |processor, exp, err|
|
@@ -35,6 +35,47 @@ class RADProcessor < RubyToAnsiC
|
|
35
35
|
name = exp.shift
|
36
36
|
"__#{name.to_s.sub(/^@/, '')}"
|
37
37
|
end
|
38
|
+
|
39
|
+
def process_iter(exp)
|
40
|
+
# the array identifer may be in one of two locations
|
41
|
+
# when using the instance variable (ivar) style it is located at exp[0][1][1]
|
42
|
+
if exp[0][1][1]
|
43
|
+
enum = exp[0][1][1]
|
44
|
+
enum = "__#{enum.to_s.sub(/^@/, '')}" if enum.to_s =~ /^@/
|
45
|
+
# for local variables it is located at exp[0][1][2]
|
46
|
+
elsif exp[0][1][2]
|
47
|
+
enum = exp[0][1][2]
|
48
|
+
end
|
49
|
+
|
50
|
+
out = []
|
51
|
+
# Only support enums in C-land # not sure if this comment if valid anymore
|
52
|
+
raise UnsupportedNodeError if exp[0][1].nil? # HACK ugly
|
53
|
+
@env.scope do
|
54
|
+
|
55
|
+
call = process exp.shift
|
56
|
+
var = process(exp.shift).intern # semi-HACK-y
|
57
|
+
body = process exp.shift
|
58
|
+
|
59
|
+
# array types from varible_processing>post_process_arrays and arduino_sketch>array
|
60
|
+
$array_types.each do |k,v|
|
61
|
+
@array_type = v if k == enum.to_s.sub(/^__/,"")
|
62
|
+
end
|
63
|
+
|
64
|
+
index_helper = $array_index_helpers.shift
|
65
|
+
index = "index_#{index_helper}" # solves redeclaration issue
|
66
|
+
|
67
|
+
body += ";" unless body =~ /[;}]\Z/
|
68
|
+
body.gsub!(/\n\n+/, "\n")
|
69
|
+
|
70
|
+
out << "unsigned int #{index};" # shouldn't need more than int
|
71
|
+
out << "for (#{index} = 0; #{index} < (int) (sizeof(#{enum}) / sizeof(#{enum}[0])); #{index}++) {"
|
72
|
+
out << "#{@array_type} #{var} = #{enum}[#{index}];"
|
73
|
+
out << body
|
74
|
+
out << "}"
|
75
|
+
end
|
76
|
+
|
77
|
+
return out.join("\n")
|
78
|
+
end
|
38
79
|
|
39
80
|
def process_lasgn(exp)
|
40
81
|
out = ""
|