rad 0.2.2 → 0.2.9

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.
Files changed (123) hide show
  1. data/History.txt +34 -0
  2. data/Manifest.txt +113 -7
  3. data/{README.txt → README.rdoc} +17 -5
  4. data/Rakefile +3 -0
  5. data/bin/rad +106 -1
  6. data/lib/examples/add_hysteresis.rb +13 -0
  7. data/lib/examples/basic_blink.rb +10 -0
  8. data/lib/examples/blink_m_address_assignment.rb +104 -0
  9. data/lib/examples/blink_m_hello.rb +14 -0
  10. data/lib/examples/blink_m_multi.rb +61 -0
  11. data/lib/examples/blink_with_serial.rb +16 -0
  12. data/lib/examples/configure_pa_lcd_boot.rb +91 -0
  13. data/lib/examples/debounce_methods.rb +49 -0
  14. data/lib/examples/external_variable_fu.rb +26 -0
  15. data/lib/examples/external_variables.rb +32 -0
  16. data/lib/examples/first_sound.rb +23 -0
  17. data/lib/examples/frequency_generator.rb +30 -0
  18. data/lib/examples/hello_array.rb +48 -0
  19. data/lib/examples/hello_array2.rb +79 -0
  20. data/lib/examples/hello_array_eeprom.rb +59 -0
  21. data/lib/examples/hello_clock.rb +84 -0
  22. data/lib/examples/hello_eeprom.rb +51 -0
  23. data/lib/examples/hello_eeprom_lcdpa.rb +81 -0
  24. data/lib/examples/hello_format_print.rb +94 -0
  25. data/lib/examples/hello_lcd_charset.rb +75 -0
  26. data/lib/examples/hello_pa_lcd.rb +59 -0
  27. data/lib/examples/hello_servos.rb +88 -0
  28. data/lib/examples/hello_spectra_sound.rb +38 -0
  29. data/lib/examples/hello_world.rb +11 -0
  30. data/lib/examples/hello_xbee.rb +12 -0
  31. data/lib/examples/hysteresis_duel.rb +39 -0
  32. data/lib/examples/i2c_with_clock_chip.rb +124 -0
  33. data/lib/examples/midi_beat_box.rb +86 -0
  34. data/lib/examples/midi_scales.rb +94 -0
  35. data/lib/examples/motor_knob.rb +30 -0
  36. data/lib/examples/servo_buttons.rb +23 -0
  37. data/lib/examples/servo_calibrate_continuous.rb +92 -0
  38. data/lib/examples/servo_throttle.rb +40 -0
  39. data/lib/examples/sparkfun_lcd.rb +48 -0
  40. data/lib/examples/spectra_soft_pot.rb +34 -0
  41. data/lib/examples/times_method.rb +8 -0
  42. data/lib/examples/toggle.rb +10 -0
  43. data/lib/examples/twitter.rb +57 -0
  44. data/lib/examples/two_wire.rb +14 -0
  45. data/lib/libraries/AFSoftSerial/AFSoftSerial.cpp +321 -0
  46. data/lib/libraries/AFSoftSerial/AFSoftSerial.h +61 -0
  47. data/lib/libraries/AFSoftSerial/keywords.txt +18 -0
  48. data/lib/libraries/AF_XPort/AF_XPort.cpp +166 -0
  49. data/lib/libraries/AF_XPort/AF_XPort.h +48 -0
  50. data/lib/libraries/DS1307/DS1307.cpp +162 -0
  51. data/lib/libraries/DS1307/DS1307.h +66 -0
  52. data/lib/libraries/{SWSerLCDpa → DS1307}/keywords.txt +1 -1
  53. data/lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp +144 -0
  54. data/lib/libraries/FrequencyTimer2/FrequencyTimer2.h +42 -0
  55. data/lib/libraries/FrequencyTimer2/keywords.txt +22 -0
  56. data/lib/libraries/I2CEEPROM/I2CEEPROM.cpp +120 -0
  57. data/lib/libraries/I2CEEPROM/I2CEEPROM.h +70 -0
  58. data/lib/libraries/I2CEEPROM/keywords.txt +21 -0
  59. data/lib/libraries/LoopTimer/LoopTimer.cpp +35 -0
  60. data/lib/libraries/LoopTimer/LoopTimer.h +34 -0
  61. data/lib/libraries/LoopTimer/keywords.txt +27 -0
  62. data/lib/libraries/OneWire/OneWire.cpp +194 -0
  63. data/lib/libraries/OneWire/OneWire.h +63 -0
  64. data/lib/libraries/OneWire/keywords.txt +35 -0
  65. data/lib/libraries/OneWire/readme.txt +13 -0
  66. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp +93 -47
  67. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +16 -9
  68. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +311 -0
  69. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +67 -0
  70. data/lib/libraries/Servo/Servo.cpp +192 -0
  71. data/lib/libraries/Servo/Servo.h +61 -0
  72. data/lib/libraries/Stepper/Stepper.cpp +220 -0
  73. data/lib/libraries/Stepper/Stepper.h +86 -0
  74. data/lib/libraries/Stepper/keywords.txt +28 -0
  75. data/lib/libraries/Wire/Wire.cpp +262 -0
  76. data/lib/libraries/Wire/Wire.h +67 -0
  77. data/lib/libraries/Wire/keywords.txt +31 -0
  78. data/lib/libraries/Wire/twi.h +57 -0
  79. data/lib/libraries/Wire/utility/twi.c +449 -0
  80. data/lib/libraries/Wire/utility/twi.h +57 -0
  81. data/lib/plugins/bitwise_ops.rb +54 -0
  82. data/lib/plugins/blink.rb +25 -0
  83. data/lib/plugins/blink_m.rb +356 -0
  84. data/lib/plugins/debounce.rb +138 -0
  85. data/lib/plugins/debug_output_to_lcd.rb +71 -0
  86. data/lib/plugins/hysteresis.rb +52 -0
  87. data/lib/plugins/input_output_state.rb +84 -0
  88. data/lib/plugins/lcd_padding.rb +58 -0
  89. data/lib/plugins/mem_test.rb +37 -0
  90. data/lib/plugins/midi.rb +60 -0
  91. data/lib/plugins/parallax_ping.rb +50 -0
  92. data/lib/plugins/servo_pulse.rb +31 -0
  93. data/lib/plugins/servo_setup.rb +86 -0
  94. data/lib/plugins/smoother.rb +54 -0
  95. data/lib/plugins/spark_fun_serial_lcd.rb +100 -0
  96. data/lib/plugins/spectra_symbol.rb +79 -0
  97. data/lib/plugins/twitter_connect.rb +145 -0
  98. data/lib/rad/README.rdoc +5 -0
  99. data/lib/rad/arduino_plugin.rb +246 -0
  100. data/lib/rad/arduino_sketch.rb +351 -257
  101. data/lib/rad/generators/makefile/makefile.erb +1 -1
  102. data/lib/rad/generators/makefile/makefile.rb +9 -10
  103. data/lib/rad/hardware_library.rb +813 -0
  104. data/lib/rad/init.rb +3 -1
  105. data/lib/rad/rad_processor.rb +128 -0
  106. data/lib/rad/rad_rewriter.rb +94 -0
  107. data/lib/rad/rad_type_checker.rb +26 -0
  108. data/lib/rad/sim/arduino_sketch.rb +57 -0
  109. data/lib/rad/sketch_compiler.rb +47 -0
  110. data/lib/rad/tasks/build_and_make.rake +146 -24
  111. data/lib/rad/variable_processing.rb +153 -0
  112. data/lib/rad/version.rb +1 -1
  113. data/spec/examples/hello_world.rb +11 -0
  114. data/spec/examples/serial_motor.rb +12 -0
  115. data/spec/models/sketch_compiler_spec.rb +96 -0
  116. data/spec/sim/hello_world_spec.rb +42 -0
  117. data/test/test_array_processing.rb +179 -0
  118. data/test/test_plugin_loading.rb +151 -0
  119. data/test/test_translation_post_processing.rb +185 -0
  120. data/test/test_variable_processing.rb +238 -0
  121. data/website/index.html +22 -7
  122. data/website/stylesheets/screen.css +32 -1
  123. metadata +130 -13
@@ -0,0 +1,14 @@
1
+ class TwoWire < ArduinoSketch
2
+
3
+ # just a demo that two_wire loads
4
+
5
+ output_pin 19, :as => :wire, :device => :i2c, :enable => :true
6
+
7
+ def loop
8
+
9
+ x = 4
10
+
11
+ end
12
+
13
+
14
+ end
@@ -0,0 +1,321 @@
1
+ /*
2
+ SoftwareSerial.cpp - Software serial library
3
+ Copyright (c) 2006 David A. Mellis. All right reserved. - hacked by ladyada
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License as published by the Free Software Foundation; either
8
+ version 2.1 of the License, or (at your option) any later version.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+ /******************************************************************************
21
+ * Includes
22
+ ******************************************************************************/
23
+ #include <avr/interrupt.h>
24
+ #include "WConstants.h"
25
+ #include "AFSoftSerial.h"
26
+
27
+ /******************************************************************************
28
+ * Definitions
29
+ ******************************************************************************/
30
+
31
+ #define AFSS_MAX_RX_BUFF 64
32
+
33
+ /******************************************************************************
34
+ * Statics
35
+ ******************************************************************************/
36
+ static uint8_t _receivePin;
37
+ static uint8_t _transmitPin;
38
+ static int _bitDelay;
39
+
40
+ static char _receive_buffer[AFSS_MAX_RX_BUFF];
41
+ static uint8_t _receive_buffer_index;
42
+
43
+ #if (F_CPU == 16000000)
44
+ void whackDelay(uint16_t delay) {
45
+ uint8_t tmp=0;
46
+
47
+ asm volatile("sbiw %0, 0x01 \n\t"
48
+ "ldi %1, 0xFF \n\t"
49
+ "cpi %A0, 0xFF \n\t"
50
+ "cpc %B0, %1 \n\t"
51
+ "brne .-10 \n\t"
52
+ : "+r" (delay), "+a" (tmp)
53
+ : "0" (delay)
54
+ );
55
+ }
56
+ #endif
57
+
58
+ /******************************************************************************
59
+ * Interrupts
60
+ ******************************************************************************/
61
+
62
+ SIGNAL(SIG_PIN_CHANGE0) {
63
+ if ((_receivePin >=8) && (_receivePin <= 13)) {
64
+ recv();
65
+ }
66
+ }
67
+ SIGNAL(SIG_PIN_CHANGE2)
68
+ {
69
+ if (_receivePin <8) {
70
+ recv();
71
+ }
72
+ }
73
+
74
+
75
+ void recv(void) {
76
+ char i, d = 0;
77
+ if (digitalRead(_receivePin))
78
+ return; // not ready!
79
+ whackDelay(_bitDelay - 8);
80
+ for (i=0; i<8; i++) {
81
+ //PORTB |= _BV(5);
82
+ whackDelay(_bitDelay*2 - 6); // digitalread takes some time
83
+ //PORTB &= ~_BV(5);
84
+ if (digitalRead(_receivePin))
85
+ d |= (1 << i);
86
+ }
87
+ whackDelay(_bitDelay*2);
88
+ if (_receive_buffer_index >= AFSS_MAX_RX_BUFF)
89
+ return;
90
+ _receive_buffer[_receive_buffer_index] = d; // save data
91
+ _receive_buffer_index++; // got a byte
92
+ }
93
+
94
+
95
+
96
+ /******************************************************************************
97
+ * Constructors
98
+ ******************************************************************************/
99
+
100
+ AFSoftSerial::AFSoftSerial(uint8_t receivePin, uint8_t transmitPin)
101
+ {
102
+ _receivePin = receivePin;
103
+ _transmitPin = transmitPin;
104
+ _baudRate = 0;
105
+ }
106
+
107
+ void AFSoftSerial::setTX(uint8_t tx) {
108
+ _transmitPin = tx;
109
+ }
110
+ void AFSoftSerial::setRX(uint8_t rx) {
111
+ _receivePin = rx;
112
+ }
113
+
114
+ /******************************************************************************
115
+ * User API
116
+ ******************************************************************************/
117
+
118
+ void AFSoftSerial::begin(long speed)
119
+ {
120
+ pinMode(_transmitPin, OUTPUT);
121
+ digitalWrite(_transmitPin, HIGH);
122
+
123
+ pinMode(_receivePin, INPUT);
124
+ digitalWrite(_receivePin, HIGH); // pullup!
125
+
126
+ _baudRate = speed;
127
+ switch (_baudRate) {
128
+ case 115200: // For xmit -only-!
129
+ _bitDelay = 4; break;
130
+ case 57600:
131
+ _bitDelay = 14; break;
132
+ case 38400:
133
+ _bitDelay = 24; break;
134
+ case 31250:
135
+ _bitDelay = 31; break;
136
+ case 19200:
137
+ _bitDelay = 54; break;
138
+ case 9600:
139
+ _bitDelay = 113; break;
140
+ case 4800:
141
+ _bitDelay = 232; break;
142
+ case 2400:
143
+ _bitDelay = 470; break;
144
+ default:
145
+ _bitDelay = 0;
146
+ }
147
+
148
+ if (_receivePin < 8) {
149
+ // a PIND pin, PCINT16-23
150
+ PCMSK2 |= _BV(_receivePin);
151
+ PCICR |= _BV(2);
152
+ } else if (_receivePin <= 13) {
153
+ // a PINB pin, PCINT0-5
154
+ PCICR |= _BV(0);
155
+ PCMSK0 |= _BV(_receivePin-8);
156
+ }
157
+
158
+ whackDelay(_bitDelay*2); // if we were low this establishes the end
159
+ }
160
+
161
+ int AFSoftSerial::read(void)
162
+ {
163
+ uint8_t d,i;
164
+
165
+ if (! _receive_buffer_index)
166
+ return -1;
167
+
168
+ d = _receive_buffer[0]; // grab first byte
169
+ // if we were awesome we would do some nifty queue action
170
+ // sadly, i dont care
171
+ for (i=0; i<_receive_buffer_index; i++) {
172
+ _receive_buffer[i] = _receive_buffer[i+1];
173
+ }
174
+ _receive_buffer_index--;
175
+ return d;
176
+ }
177
+
178
+ uint8_t AFSoftSerial::available(void)
179
+ {
180
+ return _receive_buffer_index;
181
+ }
182
+
183
+ void AFSoftSerial::print(uint8_t b)
184
+ {
185
+ if (_baudRate == 0)
186
+ return;
187
+ byte mask;
188
+
189
+ cli(); // turn off interrupts for a clean txmit
190
+
191
+ digitalWrite(_transmitPin, LOW); // startbit
192
+ whackDelay(_bitDelay*2);
193
+
194
+ for (mask = 0x01; mask; mask <<= 1) {
195
+ if (b & mask){ // choose bit
196
+ digitalWrite(_transmitPin,HIGH); // send 1
197
+ }
198
+ else{
199
+ digitalWrite(_transmitPin,LOW); // send 1
200
+ }
201
+ whackDelay(_bitDelay*2);
202
+ }
203
+
204
+ digitalWrite(_transmitPin, HIGH);
205
+ sei(); // turn interrupts back on. hooray!
206
+ whackDelay(_bitDelay*2);
207
+ }
208
+
209
+ void AFSoftSerial::print(const char *s)
210
+ {
211
+ while (*s)
212
+ print(*s++);
213
+ }
214
+
215
+ void AFSoftSerial::print(char c)
216
+ {
217
+ print((uint8_t) c);
218
+ }
219
+
220
+ void AFSoftSerial::print(int n)
221
+ {
222
+ print((long) n);
223
+ }
224
+
225
+ void AFSoftSerial::print(unsigned int n)
226
+ {
227
+ print((unsigned long) n);
228
+ }
229
+
230
+ void AFSoftSerial::print(long n)
231
+ {
232
+ if (n < 0) {
233
+ print('-');
234
+ n = -n;
235
+ }
236
+ printNumber(n, 10);
237
+ }
238
+
239
+ void AFSoftSerial::print(unsigned long n)
240
+ {
241
+ printNumber(n, 10);
242
+ }
243
+
244
+ void AFSoftSerial::print(long n, int base)
245
+ {
246
+ if (base == 0)
247
+ print((char) n);
248
+ else if (base == 10)
249
+ print(n);
250
+ else
251
+ printNumber(n, base);
252
+ }
253
+
254
+ void AFSoftSerial::println(void)
255
+ {
256
+ print('\r');
257
+ print('\n');
258
+ }
259
+
260
+ void AFSoftSerial::println(char c)
261
+ {
262
+ print(c);
263
+ println();
264
+ }
265
+
266
+ void AFSoftSerial::println(const char c[])
267
+ {
268
+ print(c);
269
+ println();
270
+ }
271
+
272
+ void AFSoftSerial::println(uint8_t b)
273
+ {
274
+ print(b);
275
+ println();
276
+ }
277
+
278
+ void AFSoftSerial::println(int n)
279
+ {
280
+ print(n);
281
+ println();
282
+ }
283
+
284
+ void AFSoftSerial::println(long n)
285
+ {
286
+ print(n);
287
+ println();
288
+ }
289
+
290
+ void AFSoftSerial::println(unsigned long n)
291
+ {
292
+ print(n);
293
+ println();
294
+ }
295
+
296
+ void AFSoftSerial::println(long n, int base)
297
+ {
298
+ print(n, base);
299
+ println();
300
+ }
301
+
302
+ // Private Methods /////////////////////////////////////////////////////////////
303
+
304
+ void AFSoftSerial::printNumber(unsigned long n, uint8_t base)
305
+ {
306
+ unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
307
+ unsigned long i = 0;
308
+
309
+ if (n == 0) {
310
+ print('0');
311
+ return;
312
+ }
313
+
314
+ while (n > 0) {
315
+ buf[i++] = n % base;
316
+ n /= base;
317
+ }
318
+
319
+ for (; i > 0; i--)
320
+ print((char) (buf[i - 1] < 10 ? '0' + buf[i - 1] : 'A' + buf[i - 1] - 10));
321
+ }
@@ -0,0 +1,61 @@
1
+ /*
2
+ SoftwareSerial.h - Software serial library
3
+ Copyright (c) 2006 David A. Mellis. All right reserved.
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License as published by the Free Software Foundation; either
8
+ version 2.1 of the License, or (at your option) any later version.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+ #ifndef AFSoftSerial_h
21
+ #define AFSoftSerial_h
22
+
23
+ #include <inttypes.h>
24
+
25
+ uint16_t whackDelay2(uint16_t delay);
26
+
27
+ static void recv(void);
28
+
29
+ class AFSoftSerial
30
+ {
31
+ private:
32
+ long _baudRate;
33
+ void printNumber(unsigned long, uint8_t);
34
+
35
+ public:
36
+ AFSoftSerial(uint8_t, uint8_t);
37
+ void setTX(uint8_t tx);
38
+ void setRX(uint8_t rx);
39
+ void begin(long);
40
+ int read();
41
+ uint8_t available(void);
42
+ void print(char);
43
+ void print(const char[]);
44
+ void print(uint8_t);
45
+ void print(int);
46
+ void print(unsigned int);
47
+ void print(long);
48
+ void print(unsigned long);
49
+ void print(long, int);
50
+ void println(void);
51
+ void println(char);
52
+ void println(const char[]);
53
+ void println(uint8_t);
54
+ void println(int);
55
+ void println(long);
56
+ void println(unsigned long);
57
+ void println(long, int);
58
+ };
59
+
60
+ #endif
61
+
@@ -0,0 +1,18 @@
1
+ #######################################
2
+ # Syntax Coloring Map For Ultrasound
3
+ #######################################
4
+
5
+ #######################################
6
+ # Datatypes (KEYWORD1)
7
+ #######################################
8
+
9
+ AFSoftSerial KEYWORD1
10
+
11
+ #######################################
12
+ # Methods and Functions (KEYWORD2)
13
+ #######################################
14
+
15
+ #######################################
16
+ # Constants (LITERAL1)
17
+ #######################################
18
+
@@ -0,0 +1,166 @@
1
+ #include <avr/io.h>
2
+ #include "WProgram.h"
3
+ #include "AFSoftSerial.h"
4
+ #include "AF_XPort.h"
5
+
6
+ static AFSoftSerial xportserial = AFSoftSerial(0,0); // we dont know the pins yet
7
+
8
+ AF_XPort::AF_XPort(uint8_t rx, uint8_t tx, uint8_t reset, uint8_t dtr, uint8_t rts, uint8_t cts) {
9
+ rxpin = rx;
10
+ txpin = tx;
11
+ resetpin = reset;
12
+ if (resetpin) {
13
+ pinMode(resetpin, OUTPUT);
14
+ digitalWrite(resetpin, HIGH);
15
+ }
16
+
17
+ dtrpin = dtr;
18
+ rtspin = rts;
19
+ ctspin = cts;
20
+ if (ctspin) {
21
+ digitalWrite(ctspin, HIGH);
22
+ pinMode(ctspin, OUTPUT);
23
+ }
24
+ }
25
+
26
+ void AF_XPort::begin(uint16_t b) {
27
+ xportserial.setTX(rxpin);
28
+ xportserial.setRX(txpin);
29
+ xportserial.begin(b);
30
+ }
31
+
32
+ uint8_t AF_XPort::reset(void) {
33
+ char d;
34
+
35
+ if (resetpin) {
36
+ digitalWrite(resetpin, LOW);
37
+ delay(50);
38
+ digitalWrite(resetpin, HIGH);
39
+ }
40
+
41
+ // wait for 'D' for disconnected
42
+ if (serialavail_timeout(5000)) { // 3 second timeout
43
+ d = xportserial.read();
44
+ //Serial.print("Read: "); Serial.print(d, HEX);
45
+ if (d != 'D'){
46
+ return ERROR_BADRESP;
47
+ } else {
48
+ return 0;
49
+ }
50
+ }
51
+ return ERROR_TIMEDOUT;
52
+ }
53
+
54
+ uint8_t AF_XPort::disconnected(void) {
55
+ if (dtrpin != 0) {
56
+ return digitalRead(dtrpin);
57
+ }
58
+ return 0;
59
+ }
60
+
61
+
62
+ uint8_t AF_XPort::connect(char *ipaddr, long port) {
63
+ char ret;
64
+
65
+ xportserial.print('C');
66
+ xportserial.print(ipaddr);
67
+ xportserial.print('/');
68
+ xportserial.println(port);
69
+ // wait for 'C'
70
+ if (serialavail_timeout(3000)) { // 3 second timeout
71
+ ret = xportserial.read();
72
+ //Serial.print("Read: "); Serial.print(d, HEX);
73
+ if (ret != 'C') {
74
+ return ERROR_BADRESP;
75
+ }
76
+ } else {
77
+ return ERROR_TIMEDOUT;
78
+ }
79
+ return 0;
80
+ }
81
+
82
+
83
+ // check to see what data is available from the xport
84
+ uint8_t AF_XPort::serialavail_timeout(int timeout) { // in ms
85
+ while (timeout) {
86
+ if (xportserial.available()) {
87
+ if (ctspin) { // we read some stuff, time to stop!
88
+ digitalWrite(ctspin, HIGH);
89
+ }
90
+ return 1;
91
+ }
92
+ // nothing in the queue, tell it to send something
93
+ if (ctspin) {
94
+ digitalWrite(ctspin, LOW);
95
+ }
96
+ timeout -= 1;
97
+ delay(1);
98
+ }
99
+ if (ctspin) { // we may need to process some stuff, so stop now
100
+ digitalWrite(ctspin, HIGH);
101
+ }
102
+ return 0;
103
+ }
104
+
105
+
106
+
107
+ uint8_t AF_XPort::readline_timeout(char *buff, uint8_t maxlen, int timeout) {
108
+ uint8_t idx;
109
+ char c;
110
+
111
+ for (idx=0; idx < maxlen; idx++) {
112
+ buff[idx] = 0;
113
+ if (serialavail_timeout(timeout)) {
114
+ c = xportserial.read();
115
+ //Serial.print(c); // debugging
116
+ if (c == '\n') {
117
+ return idx;
118
+ } else {
119
+ buff[idx] = c;
120
+ }
121
+ } else {
122
+ // timedout!
123
+ break;
124
+ }
125
+ }
126
+ return idx;
127
+ }
128
+
129
+
130
+ // clear out any extra data
131
+ void AF_XPort::flush(int timeout) {
132
+ while (serialavail_timeout(timeout)) {
133
+ xportserial.read();
134
+ }
135
+ }
136
+
137
+ // on direct+ and xport's we can toggle a line to disconnect
138
+ void AF_XPort::disconnect() {
139
+ /* digitalWrite(XPORT_DISCONN, LOW);
140
+ delay(20);
141
+ digitalWrite(XPORT_DISCONN, HIGH);*/
142
+ }
143
+
144
+ // print a string from Flash, saves lots of RAM space!
145
+ void AF_XPort::ROM_print(const char *pSTR) {
146
+ uint16_t i;
147
+ for (i = 0; pgm_read_byte(&pSTR[i]); i++) {
148
+ xportserial.print(pgm_read_byte(&pSTR[i]));
149
+ }
150
+ }
151
+
152
+ // all the prints
153
+ void AF_XPort::print(uint8_t b) { xportserial.print(b); }
154
+ void AF_XPort::print(const char *b) { xportserial.print(b); }
155
+ void AF_XPort::print(char b) { xportserial.print(b); }
156
+ void AF_XPort::print(unsigned int b) { xportserial.print(b); }
157
+ void AF_XPort::print(long b) { xportserial.print(b); }
158
+ void AF_XPort::print(long b, int base) { xportserial.print(b, base); }
159
+ void AF_XPort::println(void) { xportserial.println(); }
160
+ void AF_XPort::println(const char c[]) { xportserial.println(c); }
161
+ void AF_XPort::println(uint8_t b) { xportserial.println(b); }
162
+ void AF_XPort::println(int b) { xportserial.println(b); }
163
+ void AF_XPort::println(long b) { xportserial.println(b); }
164
+ void AF_XPort::println(unsigned long b) { xportserial.println(b); }
165
+ void AF_XPort::println(long n, int base) { xportserial.println(n, base); }
166
+