madrona-rad 0.2.2 → 0.2.3

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 CHANGED
@@ -1,3 +1,14 @@
1
+ == 0.2.3 2008-07-10
2
+ * Manyish updates:
3
+ - updated servo library to support position parameter
4
+ - plus:
5
+ - addition of plugins
6
+ - latest and greatest lcd libraries for pa and sf
7
+ - multiple methods
8
+ - addition of rad_process and rad_rewrite methods methods
9
+ - options for :device => servo, button, lcd,
10
+ - and many more
11
+
1
12
  == 0.2.2 2008-04-27
2
13
  * 2ish updates:
3
14
  - updated makefile template and cli to expect arduino-0011
data/Manifest.txt CHANGED
@@ -4,6 +4,9 @@ Manifest.txt
4
4
  README.rdoc
5
5
  Rakefile
6
6
  bin/rad
7
+ lib/libraries/FrequencyTimer2/keywords.txt
8
+ lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp
9
+ lib/libraries/FrequencyTimer2/FrequencyTimer2.h
7
10
  lib/libraries/Servo/keywords.txt
8
11
  lib/libraries/Servo/Servo.cpp
9
12
  lib/libraries/Servo/Servo.h
data/bin/rad CHANGED
@@ -104,6 +104,10 @@ FileUtils.mkdir_p "#{sketch_name}/vendor/libraries"
104
104
  puts "Successfully created your libraries directory."
105
105
 
106
106
 
107
+ FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/FrequencyTimer2/.", "#{sketch_name}/vendor/libraries/FrequencyTimer2"
108
+ puts "Installed Servo into #{sketch_name}/vendor/libraries"
109
+ puts
110
+
107
111
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/Servo/.", "#{sketch_name}/vendor/libraries/Servo"
108
112
  puts "Installed Servo into #{sketch_name}/vendor/libraries"
109
113
  puts
@@ -0,0 +1,144 @@
1
+
2
+
3
+
4
+ #include <FrequencyTimer2.h>
5
+
6
+ #include <avr/interrupt.h>
7
+
8
+ void (*FrequencyTimer2::onOverflow)() = 0;
9
+ uint8_t FrequencyTimer2::enabled = 0;
10
+
11
+ #if defined(__AVR_ATmega168__)
12
+ SIGNAL(SIG_OUTPUT_COMPARE2A)
13
+ #else
14
+ SIGNAL(SIG_OUTPUT_COMPARE2)
15
+ #endif
16
+ {
17
+ static uint8_t inHandler = 0; // protect us from recursion if our handler enables interrupts
18
+
19
+ if ( !inHandler && FrequencyTimer2::onOverflow) {
20
+ inHandler = 1;
21
+ (*FrequencyTimer2::onOverflow)();
22
+ inHandler = 0;
23
+ }
24
+ }
25
+
26
+ void FrequencyTimer2::setOnOverflow( void (*func)() )
27
+ {
28
+ FrequencyTimer2::onOverflow = func;
29
+ #if defined(__AVR_ATmega168__)
30
+ if ( func) TIMSK2 |= _BV(OCIE2A);
31
+ else TIMSK2 &= ~_BV(OCIE2A);
32
+ #else
33
+ if ( func) TIMSK |= _BV(OCIE2);
34
+ else TIMSK &= ~_BV(OCIE2);
35
+ #endif
36
+ }
37
+
38
+ void FrequencyTimer2::setPeriod(unsigned long period)
39
+ {
40
+ uint8_t pre, top;
41
+
42
+ if ( period == 0) period = 1;
43
+ period *= clockCyclesPerMicrosecond();
44
+
45
+ period /= 2; // we work with half-cycles before the toggle
46
+ if ( period <= 256) {
47
+ pre = 1;
48
+ top = period-1;
49
+ } else if ( period <= 256L*8) {
50
+ pre = 2;
51
+ top = period/8-1;
52
+ } else if ( period <= 256L*32) {
53
+ pre = 3;
54
+ top = period/32-1;
55
+ } else if ( period <= 256L*64) {
56
+ pre = 4;
57
+ top = period/64-1;
58
+ } else if ( period <= 256L*128) {
59
+ pre = 5;
60
+ top = period/128-1;
61
+ } else if ( period <= 256L*256) {
62
+ pre = 6;
63
+ top = period/256-1;
64
+ } else if ( period <= 256L*1024) {
65
+ pre = 7;
66
+ top = period/1024-1;
67
+ } else {
68
+ pre = 7;
69
+ top = 255;
70
+ }
71
+
72
+ #if defined(__AVR_ATmega168__)
73
+ TCCR2B = 0;
74
+ TCCR2A = 0;
75
+ TCNT2 = 0;
76
+ ASSR &= ~_BV(AS2); // use clock, not T2 pin
77
+ OCR2A = top;
78
+ TCCR2A = (_BV(WGM21) | ( FrequencyTimer2::enabled ? _BV(COM2A0) : 0));
79
+ TCCR2B = pre;
80
+ #else
81
+ TCCR2 = 0;
82
+ TCNT2 = 0;
83
+ ASSR &= ~_BV(AS2); // use clock, not T2 pin
84
+ OCR2 = top;
85
+ TCCR2 = (_BV(WGM21) | ( FrequencyTimer2::enabled ? _BV(COM20) : 0) | pre);
86
+ #endif
87
+ }
88
+
89
+ unsigned long FrequencyTimer2::getPeriod()
90
+ {
91
+ #if defined(__AVR_ATmega168__)
92
+ uint8_t p = (TCCR2B & 7);
93
+ unsigned long v = OCR2A;
94
+ #else
95
+ uint8_t p = (TCCR2 & 7);
96
+ unsigned long v = OCR2;
97
+ #endif
98
+ uint8_t shift;
99
+
100
+ switch(p) {
101
+ case 0 ... 1:
102
+ shift = 0;
103
+ break;
104
+ case 2:
105
+ shift = 3;
106
+ break;
107
+ case 3:
108
+ shift = 5;
109
+ break;
110
+ case 4:
111
+ shift = 6;
112
+ break;
113
+ case 5:
114
+ shift = 7;
115
+ break;
116
+ case 6:
117
+ shift = 8;
118
+ break;
119
+ case 7:
120
+ shift = 10;
121
+ break;
122
+ }
123
+ return (((v+1) << (shift+1)) + 1) / clockCyclesPerMicrosecond(); // shift+1 converts from half-period to period
124
+ }
125
+
126
+ void FrequencyTimer2::enable()
127
+ {
128
+ FrequencyTimer2::enabled = 1;
129
+ #if defined(__AVR_ATmega168__)
130
+ TCCR2A |= _BV(COM2A0);
131
+ #else
132
+ TCCR2 |= _BV(COM20);
133
+ #endif
134
+ }
135
+
136
+ void FrequencyTimer2::disable()
137
+ {
138
+ FrequencyTimer2::enabled = 0;
139
+ #if defined(__AVR_ATmega168__)
140
+ TCCR2A &= ~_BV(COM2A0);
141
+ #else
142
+ TCCR2 &= ~_BV(COM20);
143
+ #endif
144
+ }
@@ -0,0 +1,42 @@
1
+ #ifndef FREQUENCYTIMER2_IS_IN
2
+ #define FREQUENCYTIMER2_IS_IN
3
+
4
+ /*
5
+ FrequencyTimer2.h - A frequency generator and interrupt generator library
6
+ Author: Jim Studt, jim@federated.com
7
+ Copyright (c) 2007 David A. Mellis. All right reserved.
8
+
9
+ This library is free software; you can redistribute it and/or
10
+ modify it under the terms of the GNU Lesser General Public
11
+ License as published by the Free Software Foundation; either
12
+ version 2.1 of the License, or (at your option) any later version.
13
+
14
+ This library is distributed in the hope that it will be useful,
15
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ Lesser General Public License for more details.
18
+
19
+ You should have received a copy of the GNU Lesser General Public
20
+ License along with this library; if not, write to the Free Software
21
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
+ */
23
+
24
+
25
+ #include <wiring.h>
26
+
27
+ class FrequencyTimer2
28
+ {
29
+ private:
30
+ static uint8_t enabled;
31
+ public:
32
+ static void (*onOverflow)(); // not really public, but I can't work out the 'friend' for the SIGNAL
33
+
34
+ public:
35
+ static void setPeriod(unsigned long);
36
+ static unsigned long getPeriod();
37
+ static void setOnOverflow( void (*)() );
38
+ static void enable();
39
+ static void disable();
40
+ };
41
+
42
+ #endif
@@ -0,0 +1,22 @@
1
+ #######################################
2
+ # Syntax Coloring Map FrequencyTimer2
3
+ #######################################
4
+
5
+ #######################################
6
+ # Datatypes (KEYWORD1)
7
+ #######################################
8
+
9
+ FrequencyTimer2 KEYWORD1
10
+
11
+ #######################################
12
+ # Methods and Functions (KEYWORD2)
13
+ #######################################
14
+ setPeriod KEYWORD2
15
+ getPeriod KEYWORD2
16
+ enable KEYWORD2
17
+ disable KEYWORD2
18
+ setOnOverflow KEYWORD2
19
+
20
+ #######################################
21
+ # Constants (LITERAL1)
22
+ #######################################
@@ -1,3 +1,24 @@
1
+ /*
2
+ Servo.h - Arduino Software Servo Library
3
+ Author: ????
4
+ Modified: Brian Riley <brianbr@wulfden.org> Jun/Jul 2008
5
+ Copyright (c) 2007 David A. Mellis. All right reserved.
6
+
7
+ This library is free software; you can redistribute it and/or
8
+ modify it under the terms of the GNU Lesser General Public
9
+ License as published by the Free Software Foundation; either
10
+ version 2.1 of the License, or (at your option) any later version.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General Public
18
+ License along with this library; if not, write to the Free Software
19
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
1
22
  #include "WConstants.h"
2
23
  #include <Servo.h>
3
24
 
@@ -5,7 +26,7 @@ Servo *Servo::first;
5
26
 
6
27
  #define NO_ANGLE (0xff)
7
28
 
8
- Servo::Servo() : pin(0),angle(NO_ANGLE),pulse0(0),next(0)
29
+ Servo::Servo() : pin(0),angle(NO_ANGLE),pulse0(0),min16(DEFLT_MINP),max16(DEFLT_MAXP),next(0)
9
30
  {}
10
31
 
11
32
 
@@ -18,26 +39,34 @@ uint8_t Servo::attach(int pinArg)
18
39
  first = this;
19
40
  digitalWrite(pin,0);
20
41
  pinMode(pin,OUTPUT);
21
- min16 = 34;
22
- max16 = 150;
42
+ return 1;
43
+ }
44
+
45
+ uint8_t Servo::attach(int pinArg, int angleArg)
46
+ {
47
+ attach(pinArg);
48
+ write(angleArg);
23
49
  return 1;
24
50
  }
25
51
 
26
52
 
27
53
  uint8_t Servo::attach(int pinArg, uint16_t minp, uint16_t maxp)
28
54
  {
29
- pin = pinArg;
30
- angle = NO_ANGLE;
31
- pulse0 = 0;
32
- next = first;
33
- first = this;
34
- digitalWrite(pin,0);
35
- pinMode(pin,OUTPUT);
55
+ attach(pinArg);
36
56
  min16 = minp/16;
37
57
  max16 = maxp/16;
38
58
  return 1;
39
59
  }
40
60
 
61
+ uint8_t Servo::attach(int pinArg, int angleArg, uint16_t minp, uint16_t maxp)
62
+ {
63
+ attach(pinArg);
64
+ min16 = minp/16;
65
+ max16 = maxp/16;
66
+ write(angleArg);
67
+ return 1;
68
+ }
69
+
41
70
  void Servo::detach()
42
71
  {
43
72
  for ( Servo **p = &first; *p != 0; p = &((*p)->next) ) {
@@ -96,37 +125,46 @@ void Servo::refresh()
96
125
  static unsigned long lastRefresh = 0;
97
126
  unsigned long m = millis();
98
127
 
99
- // if we haven't wrapped millis, and 20ms have not passed, then don't do anything
128
+ // if we haven't wrapped millis, and 20ms have not passed,
129
+ // then don't do anything
130
+
100
131
  if ( m >= lastRefresh && m < lastRefresh + 20) return;
101
132
  lastRefresh = m;
102
133
 
103
134
  for ( p = first; p != 0; p = p->next ) if ( p->pulse0) count++;
135
+
104
136
  if ( count == 0) return;
105
137
 
106
138
  // gather all the servos in an array
139
+
107
140
  Servo *s[count];
108
- for ( p = first; p != 0; p = p->next ) if ( p->pulse0) s[i++] = p;
141
+
142
+ for ( p = first; p != 0; p = p->next ) if ( p->pulse0) s[i++] = p;
109
143
 
110
144
  // bubblesort the servos by pulse time, ascending order
145
+
111
146
  for(;;) {
112
- uint8_t moved = 0;
113
- for ( i = 1; i < count; i++) {
114
- if ( s[i]->pulse0 < s[i-1]->pulse0) {
115
- Servo *t = s[i];
116
- s[i] = s[i-1];
117
- s[i-1] = t;
118
- moved = 1;
119
- }
120
- }
121
- if ( !moved) break;
147
+ uint8_t moved = 0;
148
+ for ( i = 1; i < count; i++) {
149
+ if ( s[i]->pulse0 < s[i-1]->pulse0) {
150
+ Servo *t = s[i];
151
+ s[i] = s[i-1];
152
+ s[i-1] = t;
153
+ moved = 1;
154
+ }
155
+ }
156
+ if ( !moved) break;
122
157
  }
123
158
 
124
- // turn on all the pins
125
- // Note the timing error here... when you have many servos going, the
126
- // ones at the front will get a pulse that is a few microseconds too long.
127
- // Figure about 4uS/servo after them. This could be compensated, but I feel
128
- // it is within the margin of error of software servos that could catch
129
- // an extra interrupt handler at any time.
159
+ /*********************************************************************
160
+ * Turn on all the pins
161
+ * Note the timing error here... when you have many servos going, the
162
+ * ones at the front will get a pulse that is a few microseconds too long.
163
+ * Figure about 4uS/servo after them. This could be compensated, but I feel
164
+ * it is within the margin of error of software servos that could catch
165
+ * an extra interrupt handler at any time.
166
+ ********************************************************************/
167
+
130
168
  for ( i = 0; i < count; i++) digitalWrite( s[i]->pin, 1);
131
169
 
132
170
  uint8_t start = TCNT0;
@@ -134,19 +172,21 @@ void Servo::refresh()
134
172
  uint8_t last = now;
135
173
 
136
174
  // Now wait for each pin's time in turn..
175
+
137
176
  for ( i = 0; i < count; i++) {
138
- uint16_t go = start + s[i]->pulse0;
177
+ uint16_t go = start + s[i]->pulse0;
139
178
 
140
- // loop until we reach or pass 'go' time
141
- for (;;) {
142
- now = TCNT0;
143
- if ( now < last) base += 256;
144
- last = now;
179
+ // loop until we reach or pass 'go' time
180
+
181
+ for (;;) {
182
+ now = TCNT0;
183
+ if ( now < last) base += 256;
184
+ last = now;
145
185
 
146
- if ( base+now > go) {
147
- digitalWrite( s[i]->pin,0);
148
- break;
149
- }
150
- }
186
+ if ( base+now > go) {
187
+ digitalWrite( s[i]->pin,0);
188
+ break;
189
+ }
190
+ }
151
191
  }
152
192
  }
@@ -1,17 +1,40 @@
1
+ /*
2
+ Servo.h - Arduino Software Servo Library
3
+ Author: ????
4
+ Modified: Brian Riley <brianbr@wulfden.org> Jun/Jul 2008
5
+ Copyright (c) 2007 David A. Mellis. All right reserved.
6
+
7
+ This library is free software; you can redistribute it and/or
8
+ modify it under the terms of the GNU Lesser General Public
9
+ License as published by the Free Software Foundation; either
10
+ version 2.1 of the License, or (at your option) any later version.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General Public
18
+ License along with this library; if not, write to the Free Software
19
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
1
21
  #ifndef SERVO_IS_IN
2
22
  #define SERVO_IS_IN
3
23
 
4
24
  #include <inttypes.h>
5
25
  #include <wiring.h>
6
26
 
27
+ #define DEFLT_MINP 34
28
+ #define DEFLT_MAXP 150
29
+
7
30
  class Servo
8
31
  {
9
32
  private:
10
33
  uint8_t pin;
11
34
  uint8_t angle; // in degrees
12
35
  uint16_t pulse0; // pulse width in TCNT0 counts
13
- uint8_t min16; // minimum pulse, 16uS units (default is 34)
14
- uint8_t max16; // maximum pulse, 16uS units, 0-4ms range (default is 150)
36
+ uint8_t min16; // minimum pulse, 16uS units (default is DEFLT_MINP)
37
+ uint8_t max16; // maximum pulse, 16uS units, 0-4ms range (default is DEFLT_MAXP)
15
38
  class Servo *next;
16
39
  static Servo* first;
17
40
  void write(int); // specify the angle in degrees, 0 to 180
@@ -19,15 +42,20 @@ class Servo
19
42
  Servo();
20
43
  uint8_t attach(int); // attach to a pin, sets pinMode, returns 0 on failure, won't
21
44
  // position the servo until a subsequent write() happens
45
+ uint8_t attach(int,int);
46
+ // same, except position is also is specified
22
47
  uint8_t attach(int,uint16_t,uint16_t);
23
48
  // same, except min/max pulse is specified
49
+ uint8_t attach(int,int,uint16_t,uint16_t);
50
+ // same, except position and min/max pulse is specified
24
51
  void detach();
25
- void position(int); // enter an angle from 0 to 180
26
- void speed(int); // enter a speed from -100 to +100
52
+ void position(int); // enter an angle from 0 to 180
53
+ void speed(int); // enter a speed from -90 to +90
27
54
  uint8_t read();
28
55
  uint8_t attached();
29
- static void refresh(); // must be called at least every 50ms or so to keep servo alive
30
- // you can call more often, it won't happen more than once every 20ms
56
+ static void refresh(); // must be called at least every 50ms or so to keep servo alive
57
+ // you can call more often, it won't happen more than once
58
+ // every 20ms
31
59
  };
32
60
 
33
61
  #endif
@@ -79,7 +79,7 @@ void set_splash(){
79
79
  selectLineOne();
80
80
  Serial.print(" Ruby + Auduino");
81
81
  selectLineTwo();
82
- Serial.print(" RAD 0.2.2+ ");
82
+ Serial.print(" RAD 0.2.3+ ");
83
83
  Serial.print(0x7C, BYTE); // decimal 124, command flag for backlight stuff
84
84
  Serial.print(10, BYTE);
85
85
  }
@@ -157,6 +157,7 @@ class ArduinoSketch
157
157
  @@slcdpa_inc = FALSE # same
158
158
  @@slcdsf_inc = FALSE # same
159
159
  @@swser_inc = FALSE # same
160
+ @@frequency_inc = FALSE # same
160
161
 
161
162
  def initialize #:nodoc:
162
163
  @servo_settings = [] # need modular way to add this
@@ -167,7 +168,8 @@ class ArduinoSketch
167
168
  @@external_vars =[]
168
169
  $external_var_identifiers = []
169
170
  $sketch_methods = []
170
-
171
+ $load_libraries = []
172
+
171
173
  @declarations = []
172
174
  @pin_modes = {:output => [], :input => []}
173
175
  @pullups = []
@@ -304,6 +306,7 @@ class ArduinoSketch
304
306
  if opts[:device]
305
307
  case opts[:device]
306
308
  when :servo
309
+ puts "line 309"
307
310
  new_servo_setup(num, opts)
308
311
  return # don't use declarations, accessor, signatures below
309
312
  when :orig_servo
@@ -316,7 +319,12 @@ class ArduinoSketch
316
319
  return
317
320
  when :sf_lcd || :sf_LCD
318
321
  sf_lcd_setup(num, opts)
319
- return
322
+ return
323
+ when :freq_out || :freq_gen || :frequency_generator
324
+ frequency_timer(num, opts)
325
+ return
326
+ else
327
+ raise ArgumentError, "today's device choices are: :servo, :original_servo_setup, :pa_lcd, :sf_lcd, and :freq_out, got #{opts[:device]}"
320
328
  end
321
329
  end
322
330
 
@@ -377,9 +385,11 @@ class ArduinoSketch
377
385
 
378
386
  # use the servo library
379
387
  def new_servo_setup(num, opts)
380
- opts[:minp] = opts[:min] ? opts[:min] : 544
381
- opts[:maxp] = opts[:max] ? opts[:max] : 2400
382
- servo(num, opts)
388
+ if opts[:position]
389
+ raise ArgumentError, "position must be an integer from 0 to 360, got #{opts[:position].class}" unless opts[:position].is_a?(Fixnum)
390
+ raise ArgumentError, "position must be an integer from 0 to 360---, got #{opts[:position]}" if opts[:position] < 0 || opts[:position] > 360
391
+ end
392
+ servo(num, opts)
383
393
  # move this to better place ...
384
394
  # should probably go along with servo code into plugin
385
395
  @declarations << "void servo_refresh(void);"
@@ -403,6 +413,10 @@ class ArduinoSketch
403
413
 
404
414
  # use the pa lcd library
405
415
  def pa_lcd_setup(num, opts)
416
+ if opts[:geometry]
417
+ raise ArgumentError, "can only define pin from Fixnum, got #{opts[:geometry]}" unless opts[:geometry].is_a?(Fixnum)
418
+ raise ArgumentError, "pa_lcd geometry must be 216, 220, 224, 240, 416, 420, got #{opts[:geometry]}" unless opts[:geometry].to_s =~ /(216|220|224|240|416|420)/
419
+ end
406
420
  # move to plugin and load plugin
407
421
  # what's the default?
408
422
  opts[:rate] ||= 9600
@@ -412,12 +426,15 @@ class ArduinoSketch
412
426
 
413
427
  # use the sf (sparkfun) library
414
428
  def sf_lcd_setup(num, opts)
429
+ if opts[:geometry]
430
+ raise ArgumentError, "can only define pin from Fixnum, got #{opts[:geometry]}" unless opts[:geometry].is_a?(Fixnum)
431
+ raise ArgumentError, "sf_lcd geometry must be 216, 220, 416, 420, got #{opts[:geometry]}" unless opts[:geometry].to_s =~ /(216|220|416|420)/
432
+ end
415
433
  # move to plugin and load plugin
416
434
  opts[:rate] ||= 9600
417
435
  rate = opts[:rate] ? opts[:rate] : 9600
418
436
  swser_LCDsf(num, opts)
419
437
  end
420
-
421
438
 
422
439
  # Confiugre a single pin for input and setup a method to refer to that pin, i.e.:
423
440
  #
@@ -531,6 +548,7 @@ class ArduinoSketch
531
548
  if opts[:as]
532
549
  @declarations << "SWSerLCDpa _#{opts[ :as ]} = SWSerLCDpa(#{tx}, #{geometry});"
533
550
  accessor = []
551
+ $load_libraries << "SWSerLCDpa"
534
552
  accessor << "SWSerLCDpa& #{opts[ :as ]}() {"
535
553
  accessor << "\treturn _#{opts[ :as ]};"
536
554
  accessor << "}"
@@ -632,6 +650,7 @@ class ArduinoSketch
632
650
  if opts[:as]
633
651
  @declarations << "SWSerLCDsf _#{opts[ :as ]} = SWSerLCDsf(#{tx}, #{geometry});"
634
652
  accessor = []
653
+ $load_libraries << "SWSerLCDsf"
635
654
  accessor << "SWSerLCDsf& #{opts[ :as ]}() {"
636
655
  accessor << "\treturn _#{opts[ :as ]};"
637
656
  accessor << "}"
@@ -698,12 +717,13 @@ class ArduinoSketch
698
717
  def servo(spin, opts={}) # servo motor routines # how about pin instead of spin
699
718
  raise ArgumentError, "can only define spin from Fixnum, got #{spin.class}" unless spin.is_a?(Fixnum)
700
719
 
701
- minp = opts[:minp] ? opts[:minp] : 544
702
- maxp = opts[:maxp] ? opts[:maxp] : 2400
720
+ minp = opts[:min] ? opts[:min] : 544
721
+ maxp = opts[:max] ? opts[:max] : 2400
703
722
 
704
723
  if opts[:as]
705
724
  @declarations << "Servo _#{opts[ :as ]} = Servo();"
706
725
  accessor = []
726
+ $load_libraries << "Servo"
707
727
  accessor << "Servo& #{opts[ :as ]}() {"
708
728
  accessor << "\treturn _#{opts[ :as ]};"
709
729
  accessor << "}"
@@ -733,11 +753,61 @@ class ArduinoSketch
733
753
  @accessors << accessor.join( "\n" )
734
754
 
735
755
  @signatures << "Servo& #{opts[ :as ]}();"
736
-
737
- @other_setup << "_#{opts[ :as ]}.attach(#{spin}, #{minp}, #{maxp});"
756
+
757
+ @other_setup << "\t_#{opts[ :as ]}.attach(#{spin}, #{opts[:position]}, #{minp}, #{maxp});" if opts[:position]
758
+ @other_setup << "\t_#{opts[ :as ]}.attach(#{spin}, #{minp}, #{maxp});" unless opts[:position]
738
759
 
739
760
  end
740
- end
761
+ end
762
+
763
+ def frequency_timer(pin, opts={}) # frequency timer routines
764
+
765
+ raise ArgumentError, "can only define pin from Fixnum, got #{pin.class}" unless pin.is_a?(Fixnum)
766
+ raise ArgumentError, "only pin 11 may be used for freq_out, got #{pin}" unless pin == 11
767
+ raise ArgumentError, "the frequency or period option must be included. Example: :frequecy => 700" unless opts[:frequency] || opts[:period]
768
+ if opts[:frequency]
769
+ raise ArgumentError, "the frequency option must be an integer, got #{opts[:frequency].class}" unless opts[:frequency].is_a?(Fixnum)
770
+ end
771
+ if opts[:period]
772
+ raise ArgumentError, "the frequency option must be an integer, got #{opts[:period].class}" unless opts[:period].is_a?(Fixnum)
773
+ end
774
+ # refer to: http://www.arduino.cc/playground/Code/FrequencyTimer2
775
+
776
+ if opts[:as]
777
+
778
+ @declarations << "FrequencyTimer2 _#{opts[ :as ]} = FrequencyTimer2();"
779
+ accessor = []
780
+ $load_libraries << "FrequencyTimer2"
781
+ accessor << "FrequencyTimer2& #{opts[ :as ]}() {"
782
+ accessor << "\treturn _#{opts[ :as ]};"
783
+ accessor << "}"
784
+
785
+ if (@@frequency_inc == FALSE) # on second instance this stuff can't be repeated - BBR
786
+ @@frequency_inc = TRUE
787
+ accessor << "void set_frequency( FrequencyTimer2& s, int b ) {"
788
+ accessor << "\treturn s.setPeriod( 1000000L/b );"
789
+ accessor << "}"
790
+ accessor << "void set_period( FrequencyTimer2& s, int b ) {"
791
+ accessor << "\treturn s.setPeriod( b );"
792
+ accessor << "}"
793
+ accessor << "void enable( FrequencyTimer2& s ) {"
794
+ accessor << "\treturn s.enable();"
795
+ accessor << "}"
796
+ accessor << "void disable( FrequencyTimer2& s ) {"
797
+ accessor << "\treturn s.disable();"
798
+ accessor << "}"
799
+ end
800
+
801
+ @accessors << accessor.join( "\n" )
802
+
803
+ @signatures << "FrequencyTimer2& #{opts[ :as ]}();"
804
+
805
+ @other_setup << "\tFrequencyTimer2::setPeriod(1000000L/#{opts[:frequency]});" if opts[:frequency]
806
+ @other_setup << "\tFrequencyTimer2::setPeriod(#{opts[:period]});" if opts[:period]
807
+ @other_setup << "\tFrequencyTimer2::enable();" if opts[:enable] == :true
808
+ end
809
+ end
810
+
741
811
 
742
812
 
743
813
 
@@ -748,9 +818,7 @@ class ArduinoSketch
748
818
 
749
819
  result << "#include <WProgram.h>\n"
750
820
  result << "#include <SoftwareSerial.h>\n"
751
- result << "#include <SWSerLCDpa.h>"
752
- result << "#include <SWSerLCDsf.h>"
753
- result << "#include <Servo.h>"
821
+ $load_libraries.each { |lib| result << "#include <#{lib}.h>" } unless $load_libraries.nil?
754
822
 
755
823
  result << comment_box( 'plugin directives' )
756
824
  $plugin_directives.each {|dir| result << dir } unless $plugin_directives.nil? || $plugin_directives.empty?
@@ -10,7 +10,7 @@ class Makefile
10
10
  params['target'] = sketch_name
11
11
 
12
12
  params['libraries_root'] = "#{File.expand_path(RAD_ROOT)}/vendor/libraries"
13
- params['libraries'] = libraries
13
+ params['libraries'] = $load_libraries # load only libraries used
14
14
 
15
15
  params['asm_files'] = Dir.entries( File.expand_path(RAD_ROOT) + "/" + PROJECT_DIR_NAME ).select{|e| e =~ /\.S/}
16
16
 
@@ -21,9 +21,9 @@ class Makefile
21
21
  end
22
22
  end
23
23
 
24
- def libraries
25
- Dir.entries("#{RAD_ROOT}/vendor/libraries").select{|e| !(e =~ /\./)}
26
- end
24
+ # def libraries
25
+ # Dir.entries("#{RAD_ROOT}/vendor/libraries").select{|e| !(e =~ /\./)}
26
+ # end
27
27
 
28
28
  def hardware_params
29
29
  return @hardware_params if @hardware_params
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madrona-rad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Borenstein
@@ -48,6 +48,9 @@ files:
48
48
  - README.rdoc
49
49
  - Rakefile
50
50
  - bin/rad
51
+ - lib/libraries/FrequencyTimer2/keywords.txt
52
+ - lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp
53
+ - lib/libraries/FrequencyTimer2/FrequencyTimer2.h
51
54
  - lib/libraries/Servo/keywords.txt
52
55
  - lib/libraries/Servo/Servo.cpp
53
56
  - lib/libraries/Servo/Servo.h
@@ -115,6 +118,6 @@ rubyforge_project: rad
115
118
  rubygems_version: 1.2.0
116
119
  signing_key:
117
120
  specification_version: 2
118
- summary: Fork of the Ruby Arduino Development - 0.2.4.4.7
121
+ summary: Fork of the Ruby Arduino Development - 0.2.4.5.3
119
122
  test_files: []
120
123