rad 0.2.2 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +34 -0
- data/Manifest.txt +113 -7
- data/{README.txt → README.rdoc} +17 -5
- data/Rakefile +3 -0
- data/bin/rad +106 -1
- data/lib/examples/add_hysteresis.rb +13 -0
- data/lib/examples/basic_blink.rb +10 -0
- data/lib/examples/blink_m_address_assignment.rb +104 -0
- data/lib/examples/blink_m_hello.rb +14 -0
- data/lib/examples/blink_m_multi.rb +61 -0
- data/lib/examples/blink_with_serial.rb +16 -0
- data/lib/examples/configure_pa_lcd_boot.rb +91 -0
- data/lib/examples/debounce_methods.rb +49 -0
- data/lib/examples/external_variable_fu.rb +26 -0
- data/lib/examples/external_variables.rb +32 -0
- data/lib/examples/first_sound.rb +23 -0
- data/lib/examples/frequency_generator.rb +30 -0
- data/lib/examples/hello_array.rb +48 -0
- data/lib/examples/hello_array2.rb +79 -0
- data/lib/examples/hello_array_eeprom.rb +59 -0
- data/lib/examples/hello_clock.rb +84 -0
- data/lib/examples/hello_eeprom.rb +51 -0
- data/lib/examples/hello_eeprom_lcdpa.rb +81 -0
- data/lib/examples/hello_format_print.rb +94 -0
- data/lib/examples/hello_lcd_charset.rb +75 -0
- data/lib/examples/hello_pa_lcd.rb +59 -0
- data/lib/examples/hello_servos.rb +88 -0
- data/lib/examples/hello_spectra_sound.rb +38 -0
- data/lib/examples/hello_world.rb +11 -0
- data/lib/examples/hello_xbee.rb +12 -0
- data/lib/examples/hysteresis_duel.rb +39 -0
- data/lib/examples/i2c_with_clock_chip.rb +124 -0
- data/lib/examples/midi_beat_box.rb +86 -0
- data/lib/examples/midi_scales.rb +94 -0
- data/lib/examples/motor_knob.rb +30 -0
- data/lib/examples/servo_buttons.rb +23 -0
- data/lib/examples/servo_calibrate_continuous.rb +92 -0
- data/lib/examples/servo_throttle.rb +40 -0
- data/lib/examples/sparkfun_lcd.rb +48 -0
- data/lib/examples/spectra_soft_pot.rb +34 -0
- data/lib/examples/times_method.rb +8 -0
- data/lib/examples/toggle.rb +10 -0
- data/lib/examples/twitter.rb +57 -0
- data/lib/examples/two_wire.rb +14 -0
- data/lib/libraries/AFSoftSerial/AFSoftSerial.cpp +321 -0
- data/lib/libraries/AFSoftSerial/AFSoftSerial.h +61 -0
- data/lib/libraries/AFSoftSerial/keywords.txt +18 -0
- data/lib/libraries/AF_XPort/AF_XPort.cpp +166 -0
- data/lib/libraries/AF_XPort/AF_XPort.h +48 -0
- data/lib/libraries/DS1307/DS1307.cpp +162 -0
- data/lib/libraries/DS1307/DS1307.h +66 -0
- data/lib/libraries/{SWSerLCDpa → DS1307}/keywords.txt +1 -1
- data/lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp +144 -0
- data/lib/libraries/FrequencyTimer2/FrequencyTimer2.h +42 -0
- data/lib/libraries/FrequencyTimer2/keywords.txt +22 -0
- data/lib/libraries/I2CEEPROM/I2CEEPROM.cpp +120 -0
- data/lib/libraries/I2CEEPROM/I2CEEPROM.h +70 -0
- data/lib/libraries/I2CEEPROM/keywords.txt +21 -0
- data/lib/libraries/LoopTimer/LoopTimer.cpp +35 -0
- data/lib/libraries/LoopTimer/LoopTimer.h +34 -0
- data/lib/libraries/LoopTimer/keywords.txt +27 -0
- data/lib/libraries/OneWire/OneWire.cpp +194 -0
- data/lib/libraries/OneWire/OneWire.h +63 -0
- data/lib/libraries/OneWire/keywords.txt +35 -0
- data/lib/libraries/OneWire/readme.txt +13 -0
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp +93 -47
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +16 -9
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +311 -0
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +67 -0
- data/lib/libraries/Servo/Servo.cpp +192 -0
- data/lib/libraries/Servo/Servo.h +61 -0
- 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/Wire.cpp +262 -0
- data/lib/libraries/Wire/Wire.h +67 -0
- data/lib/libraries/Wire/keywords.txt +31 -0
- data/lib/libraries/Wire/twi.h +57 -0
- data/lib/libraries/Wire/utility/twi.c +449 -0
- data/lib/libraries/Wire/utility/twi.h +57 -0
- data/lib/plugins/bitwise_ops.rb +54 -0
- data/lib/plugins/blink.rb +25 -0
- data/lib/plugins/blink_m.rb +356 -0
- data/lib/plugins/debounce.rb +138 -0
- data/lib/plugins/debug_output_to_lcd.rb +71 -0
- data/lib/plugins/hysteresis.rb +52 -0
- data/lib/plugins/input_output_state.rb +84 -0
- data/lib/plugins/lcd_padding.rb +58 -0
- data/lib/plugins/mem_test.rb +37 -0
- data/lib/plugins/midi.rb +60 -0
- data/lib/plugins/parallax_ping.rb +50 -0
- data/lib/plugins/servo_pulse.rb +31 -0
- data/lib/plugins/servo_setup.rb +86 -0
- data/lib/plugins/smoother.rb +54 -0
- data/lib/plugins/spark_fun_serial_lcd.rb +100 -0
- data/lib/plugins/spectra_symbol.rb +79 -0
- data/lib/plugins/twitter_connect.rb +145 -0
- data/lib/rad/README.rdoc +5 -0
- data/lib/rad/arduino_plugin.rb +246 -0
- data/lib/rad/arduino_sketch.rb +351 -257
- data/lib/rad/generators/makefile/makefile.erb +1 -1
- data/lib/rad/generators/makefile/makefile.rb +9 -10
- data/lib/rad/hardware_library.rb +813 -0
- data/lib/rad/init.rb +3 -1
- data/lib/rad/rad_processor.rb +128 -0
- data/lib/rad/rad_rewriter.rb +94 -0
- data/lib/rad/rad_type_checker.rb +26 -0
- data/lib/rad/sim/arduino_sketch.rb +57 -0
- data/lib/rad/sketch_compiler.rb +47 -0
- data/lib/rad/tasks/build_and_make.rake +146 -24
- data/lib/rad/variable_processing.rb +153 -0
- data/lib/rad/version.rb +1 -1
- data/spec/examples/hello_world.rb +11 -0
- data/spec/examples/serial_motor.rb +12 -0
- data/spec/models/sketch_compiler_spec.rb +96 -0
- data/spec/sim/hello_world_spec.rb +42 -0
- 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/test/test_variable_processing.rb +238 -0
- data/website/index.html +22 -7
- data/website/stylesheets/screen.css +32 -1
- metadata +130 -13
@@ -0,0 +1,63 @@
|
|
1
|
+
#ifndef OneWire_h
|
2
|
+
#define OneWire_h
|
3
|
+
|
4
|
+
#include <inttypes.h>
|
5
|
+
|
6
|
+
// you can exclude onewire_search by defining that to 0
|
7
|
+
#ifndef ONEWIRE_SEARCH
|
8
|
+
#define ONEWIRE_SEARCH 0
|
9
|
+
#endif
|
10
|
+
|
11
|
+
// You can exclude onewire_crc16 by defining that to 0
|
12
|
+
#ifndef ONEWIRE_CRC16
|
13
|
+
#define ONEWIRE_CRC16 0
|
14
|
+
#endif
|
15
|
+
|
16
|
+
class OneWire
|
17
|
+
{
|
18
|
+
private:
|
19
|
+
uint8_t pin;
|
20
|
+
uint8_t port;
|
21
|
+
uint8_t bitmask;
|
22
|
+
volatile uint8_t *outputReg;
|
23
|
+
volatile uint8_t *inputReg;
|
24
|
+
volatile uint8_t *modeReg;
|
25
|
+
|
26
|
+
public:
|
27
|
+
OneWire( uint8_t pin);
|
28
|
+
|
29
|
+
// Perform a 1-Wire reset cycle. Returns 1 if a device responds
|
30
|
+
// with a presence pulse. Returns 0 if there is no device or the
|
31
|
+
// bus is shorted or otherwise held low for more than 250uS
|
32
|
+
uint8_t reset();
|
33
|
+
|
34
|
+
// Issue a 1-Wire rom skip command, to address all on bus.
|
35
|
+
void skip();
|
36
|
+
|
37
|
+
// Write a byte. If 'power' is one then the wire is held high at
|
38
|
+
// the end for parasitically powered devices. You are responsible
|
39
|
+
// for eventually depowering it by calling depower() or doing
|
40
|
+
// another read or write.
|
41
|
+
void write( uint8_t v, uint8_t power = 0);
|
42
|
+
|
43
|
+
// Read a byte.
|
44
|
+
uint8_t read();
|
45
|
+
|
46
|
+
// Write a bit. The bus is always left powered at the end, see
|
47
|
+
// note in write() about that.
|
48
|
+
void write_bit( uint8_t v);
|
49
|
+
|
50
|
+
// Read a bit.
|
51
|
+
uint8_t read_bit();
|
52
|
+
|
53
|
+
// Stop forcing power onto the bus. You only need to do this if
|
54
|
+
// you used the 'power' flag to write() or used a write_bit() call
|
55
|
+
// and aren't about to do another read or write. You would rather
|
56
|
+
// not leave this powered if you don't have to, just in case
|
57
|
+
// someone shorts your bus.
|
58
|
+
void depower();
|
59
|
+
|
60
|
+
|
61
|
+
};
|
62
|
+
|
63
|
+
#endif
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#######################################
|
2
|
+
# Syntax Coloring Map For OneWire
|
3
|
+
#######################################
|
4
|
+
|
5
|
+
#######################################
|
6
|
+
# Datatypes (KEYWORD1)
|
7
|
+
#######################################
|
8
|
+
|
9
|
+
OneWire KEYWORD1
|
10
|
+
|
11
|
+
#######################################
|
12
|
+
# Methods and Functions (KEYWORD2)
|
13
|
+
#######################################
|
14
|
+
|
15
|
+
reset KEYWORD2
|
16
|
+
write_bit KEYWORD2
|
17
|
+
read_bit KEYWORD2
|
18
|
+
write KEYWORD2
|
19
|
+
read KEYWORD2
|
20
|
+
select KEYWORD2
|
21
|
+
skip KEYWORD2
|
22
|
+
depower KEYWORD2
|
23
|
+
reset_search KEYWORD2
|
24
|
+
search KEYWORD2
|
25
|
+
crc8 KEYWORD2
|
26
|
+
crc16 KEYWORD2
|
27
|
+
|
28
|
+
#######################################
|
29
|
+
# Instances (KEYWORD2)
|
30
|
+
#######################################
|
31
|
+
|
32
|
+
|
33
|
+
#######################################
|
34
|
+
# Constants (LITERAL1)
|
35
|
+
#######################################
|
@@ -0,0 +1,13 @@
|
|
1
|
+
See:
|
2
|
+
http://www.arduino.cc/playground/Learning/OneWire
|
3
|
+
http://www.federated.com/~jim/onewire/
|
4
|
+
|
5
|
+
The version of the OneWire library at federated.com works with arduino-0007.
|
6
|
+
The version here works with arduino-0008, thanks to the very helpful Jim Studt.
|
7
|
+
|
8
|
+
To use, make a new directory: arduino-0008/lib/targets/libraries/OneWire/
|
9
|
+
and put OneWire.cpp, OneWire.h and keywords.txt in it.
|
10
|
+
|
11
|
+
--Josh Larios
|
12
|
+
hades (at) elsewhere (dot) org
|
13
|
+
2007/07/06
|
@@ -37,8 +37,20 @@ SWSerLCDpa::SWSerLCDpa(uint8_t transmitPin)
|
|
37
37
|
{
|
38
38
|
_transmitPin = transmitPin;
|
39
39
|
_baudRate = 0;
|
40
|
+
pinMode(_transmitPin, OUTPUT);
|
41
|
+
_geometry = 0;
|
40
42
|
}
|
41
43
|
|
44
|
+
SWSerLCDpa::SWSerLCDpa(uint8_t transmitPin, int geometry)
|
45
|
+
{
|
46
|
+
_transmitPin = transmitPin;
|
47
|
+
_baudRate = 0;
|
48
|
+
pinMode(_transmitPin, OUTPUT);
|
49
|
+
_geometry = geometry;
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
|
42
54
|
/******************************************************************************
|
43
55
|
* User API
|
44
56
|
******************************************************************************/
|
@@ -50,6 +62,9 @@ void SWSerLCDpa::begin(long speed)
|
|
50
62
|
|
51
63
|
digitalWrite(_transmitPin, HIGH);
|
52
64
|
delayMicroseconds( _bitPeriod); // if we were low this establishes the end
|
65
|
+
delay(50);
|
66
|
+
if (_geometry)
|
67
|
+
setgeo(_geometry);
|
53
68
|
}
|
54
69
|
|
55
70
|
void SWSerLCDpa::print(uint8_t b)
|
@@ -81,7 +96,7 @@ void SWSerLCDpa::print(const char *s)
|
|
81
96
|
{
|
82
97
|
while (*s) {
|
83
98
|
print(*s++);
|
84
|
-
delay(
|
99
|
+
delay(2);
|
85
100
|
}
|
86
101
|
}
|
87
102
|
|
@@ -125,51 +140,57 @@ void SWSerLCDpa::print(long n, int base)
|
|
125
140
|
}
|
126
141
|
|
127
142
|
// -------- PHA unique codes -------------------------
|
128
|
-
|
129
|
-
{
|
130
|
-
print("?n");
|
131
|
-
delay(10);
|
132
|
-
}
|
143
|
+
|
133
144
|
|
134
145
|
void SWSerLCDpa::clearscr(void)
|
135
146
|
{
|
136
147
|
print("?f");
|
137
|
-
delay(
|
148
|
+
delay(30);
|
138
149
|
}
|
139
150
|
|
140
|
-
void SWSerLCDpa::
|
151
|
+
void SWSerLCDpa::clearscr(const char *s)
|
141
152
|
{
|
142
|
-
|
143
|
-
|
153
|
+
clearscr();
|
154
|
+
print(s);
|
144
155
|
}
|
145
156
|
|
157
|
+
void SWSerLCDpa::clearscr(int n)
|
158
|
+
{
|
159
|
+
clearscr();
|
160
|
+
print(n);
|
161
|
+
}
|
146
162
|
|
147
|
-
void SWSerLCDpa::
|
163
|
+
void SWSerLCDpa::clearscr(long n, int base)
|
148
164
|
{
|
149
|
-
|
150
|
-
|
151
|
-
delay(200);
|
165
|
+
clearscr();
|
166
|
+
print(n, base);
|
152
167
|
}
|
153
168
|
|
154
|
-
|
169
|
+
|
170
|
+
void SWSerLCDpa::clearline(int line)
|
155
171
|
{
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
print(intensity, 16);
|
160
|
-
delay(200);
|
172
|
+
setxy(0,line);
|
173
|
+
print("?l");
|
174
|
+
delay(20);
|
161
175
|
}
|
162
176
|
|
163
|
-
void SWSerLCDpa::
|
177
|
+
void SWSerLCDpa::clearline(int line, const char *s)
|
164
178
|
{
|
165
|
-
|
179
|
+
clearline(line);
|
180
|
+
print(s);
|
166
181
|
}
|
167
182
|
|
168
|
-
void SWSerLCDpa::
|
183
|
+
void SWSerLCDpa::clearline(int line, int n)
|
169
184
|
{
|
170
|
-
|
185
|
+
clearline(line);
|
186
|
+
print(n);
|
171
187
|
}
|
172
188
|
|
189
|
+
void SWSerLCDpa::clearline(int line, long n, int base)
|
190
|
+
{
|
191
|
+
clearline(line);
|
192
|
+
print(n, base);
|
193
|
+
}
|
173
194
|
|
174
195
|
void SWSerLCDpa::setxy(int x, int y)
|
175
196
|
{
|
@@ -182,47 +203,72 @@ void SWSerLCDpa::setxy(int x, int y)
|
|
182
203
|
delay(10);
|
183
204
|
}
|
184
205
|
|
206
|
+
void SWSerLCDpa::setxy(int x, int y, const char *s)
|
207
|
+
{
|
208
|
+
setxy(x,y);
|
209
|
+
print(s);
|
210
|
+
}
|
185
211
|
|
186
|
-
void SWSerLCDpa::
|
212
|
+
void SWSerLCDpa::setxy(int x, int y, int n)
|
187
213
|
{
|
188
|
-
|
189
|
-
|
214
|
+
setxy(x,y);
|
215
|
+
print(n);
|
190
216
|
}
|
191
217
|
|
192
|
-
void SWSerLCDpa::
|
218
|
+
void SWSerLCDpa::setxy(int x, int y, long n, int base)
|
193
219
|
{
|
194
|
-
|
195
|
-
|
220
|
+
setxy(x,y);
|
221
|
+
print(n, base);
|
196
222
|
}
|
197
223
|
|
198
|
-
void SWSerLCDpa::
|
224
|
+
void SWSerLCDpa::home(void)
|
199
225
|
{
|
200
|
-
print(
|
201
|
-
|
226
|
+
print("?a");
|
227
|
+
delay(10);
|
202
228
|
}
|
203
229
|
|
204
|
-
void SWSerLCDpa::
|
230
|
+
void SWSerLCDpa::home(const char *s)
|
205
231
|
{
|
206
|
-
|
207
|
-
|
232
|
+
home();
|
233
|
+
print(s);
|
208
234
|
}
|
209
235
|
|
210
|
-
void SWSerLCDpa::
|
236
|
+
void SWSerLCDpa::home(int n)
|
211
237
|
{
|
238
|
+
home();
|
212
239
|
print(n);
|
213
|
-
println();
|
214
240
|
}
|
215
241
|
|
216
|
-
void SWSerLCDpa::
|
242
|
+
void SWSerLCDpa::home(long n, int base)
|
217
243
|
{
|
218
|
-
|
219
|
-
|
244
|
+
home();
|
245
|
+
print(n, base);
|
220
246
|
}
|
221
247
|
|
222
|
-
void SWSerLCDpa::
|
248
|
+
void SWSerLCDpa::setgeo(int geometry)
|
223
249
|
{
|
224
|
-
|
225
|
-
|
250
|
+
print("?G");
|
251
|
+
print(geometry);
|
252
|
+
delay(200);
|
253
|
+
}
|
254
|
+
|
255
|
+
void SWSerLCDpa::setintensity(int intensity)
|
256
|
+
{
|
257
|
+
print("?B");
|
258
|
+
if (intensity < 16)
|
259
|
+
print('0');
|
260
|
+
print(intensity, 16);
|
261
|
+
delay(200);
|
262
|
+
}
|
263
|
+
|
264
|
+
void SWSerLCDpa::intoBignum(void)
|
265
|
+
{
|
266
|
+
print("?>3");
|
267
|
+
}
|
268
|
+
|
269
|
+
void SWSerLCDpa::outofBignum(void)
|
270
|
+
{
|
271
|
+
print("?<");
|
226
272
|
}
|
227
273
|
|
228
274
|
// Private Methods /////////////////////////////////////////////////////////////
|
@@ -242,9 +288,9 @@ void SWSerLCDpa::printNumber(unsigned long n, uint8_t base)
|
|
242
288
|
n /= base;
|
243
289
|
}
|
244
290
|
|
245
|
-
for (; i > 0; i--)
|
291
|
+
for (; i > 0; i--) {
|
246
292
|
print((char) (buf[i - 1] < 10 ? '0' + buf[i - 1] : 'A' + buf[i - 1] - 10));
|
247
|
-
|
248
|
-
|
293
|
+
delay(2);
|
294
|
+
}
|
249
295
|
|
250
296
|
}
|
@@ -29,8 +29,10 @@ class SWSerLCDpa
|
|
29
29
|
uint8_t _transmitPin;
|
30
30
|
long _baudRate;
|
31
31
|
int _bitPeriod;
|
32
|
+
int _geometry;
|
32
33
|
void printNumber(unsigned long, uint8_t);
|
33
34
|
public:
|
35
|
+
SWSerLCDpa(uint8_t, int);
|
34
36
|
SWSerLCDpa(uint8_t);
|
35
37
|
void begin(long);
|
36
38
|
void print(char);
|
@@ -41,21 +43,26 @@ class SWSerLCDpa
|
|
41
43
|
void print(long);
|
42
44
|
void print(unsigned long);
|
43
45
|
void print(long, int);
|
44
|
-
void println(void);
|
45
46
|
void clearscr(void);
|
47
|
+
void clearscr(const char[]);
|
48
|
+
void clearscr(int);
|
49
|
+
void clearscr(long, int);
|
50
|
+
void clearline(int);
|
51
|
+
void clearline(int, const char[]);
|
52
|
+
void clearline(int, int);
|
53
|
+
void clearline(int, long, int);
|
46
54
|
void home(void);
|
55
|
+
void home(const char[]);
|
56
|
+
void home(int);
|
57
|
+
void home(long, int);
|
58
|
+
void setxy(int, int);
|
59
|
+
void setxy(int, int, const char[]);
|
60
|
+
void setxy(int, int, int);
|
61
|
+
void setxy(int, int, long, int);
|
47
62
|
void setgeo(int);
|
48
63
|
void setintensity(int);
|
49
64
|
void intoBignum(void);
|
50
65
|
void outofBignum(void);
|
51
|
-
void setxy(int, int);
|
52
|
-
void println(char);
|
53
|
-
void println(const char[]);
|
54
|
-
void println(uint8_t);
|
55
|
-
void println(int);
|
56
|
-
void println(long);
|
57
|
-
void println(unsigned long);
|
58
|
-
void println(long, int);
|
59
66
|
};
|
60
67
|
|
61
68
|
#endif
|
@@ -0,0 +1,311 @@
|
|
1
|
+
/*
|
2
|
+
SWSerLCDsf.cpp - Software serial to SparkFun controller chip based
|
3
|
+
LCD display library Adapted from SoftwareSerial.cpp (c) 2006 David A. Mellis
|
4
|
+
by Brian B. Riley, Underhill Center, Vermont, USA, July 2008
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
/******************************************************************************
|
22
|
+
* Includes
|
23
|
+
******************************************************************************/
|
24
|
+
|
25
|
+
#include "WConstants.h"
|
26
|
+
#include "SWSerLCDsf.h"
|
27
|
+
|
28
|
+
/******************************************************************************
|
29
|
+
* Definitions
|
30
|
+
******************************************************************************/
|
31
|
+
|
32
|
+
/******************************************************************************
|
33
|
+
* Constructors
|
34
|
+
******************************************************************************/
|
35
|
+
|
36
|
+
SWSerLCDsf::SWSerLCDsf(uint8_t transmitPin)
|
37
|
+
{
|
38
|
+
_transmitPin = transmitPin;
|
39
|
+
_baudRate = 0;
|
40
|
+
_rows = 2;
|
41
|
+
_cols = 16;
|
42
|
+
_geometry = 0;
|
43
|
+
}
|
44
|
+
|
45
|
+
SWSerLCDsf::SWSerLCDsf(uint8_t transmitPin, int geometry)
|
46
|
+
{
|
47
|
+
_transmitPin = transmitPin;
|
48
|
+
_baudRate = 0;
|
49
|
+
pinMode(_transmitPin, OUTPUT);
|
50
|
+
_rows = 2;
|
51
|
+
_cols = 16;
|
52
|
+
_geometry = geometry;
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
/******************************************************************************
|
57
|
+
* User API
|
58
|
+
******************************************************************************/
|
59
|
+
|
60
|
+
void SWSerLCDsf::begin(long speed)
|
61
|
+
{
|
62
|
+
_baudRate = speed;
|
63
|
+
_bitPeriod = 1000000 / _baudRate;
|
64
|
+
|
65
|
+
digitalWrite(_transmitPin, HIGH);
|
66
|
+
delayMicroseconds( _bitPeriod); // if we were low this establishes the end
|
67
|
+
delay(50);
|
68
|
+
if (_geometry)
|
69
|
+
setgeo(_geometry);
|
70
|
+
}
|
71
|
+
|
72
|
+
void SWSerLCDsf::print(uint8_t b)
|
73
|
+
{
|
74
|
+
if (_baudRate == 0)
|
75
|
+
return;
|
76
|
+
|
77
|
+
int bitDelay = _bitPeriod - clockCyclesToMicroseconds(50); // a digitalWrite is about 50 cycles
|
78
|
+
byte mask;
|
79
|
+
|
80
|
+
digitalWrite(_transmitPin, LOW);
|
81
|
+
delayMicroseconds(bitDelay);
|
82
|
+
|
83
|
+
for (mask = 0x01; mask; mask <<= 1) {
|
84
|
+
if (b & mask){ // choose bit
|
85
|
+
digitalWrite(_transmitPin,HIGH); // send 1
|
86
|
+
}
|
87
|
+
else{
|
88
|
+
digitalWrite(_transmitPin,LOW); // send 1
|
89
|
+
}
|
90
|
+
delayMicroseconds(bitDelay);
|
91
|
+
}
|
92
|
+
|
93
|
+
digitalWrite(_transmitPin, HIGH);
|
94
|
+
delayMicroseconds(bitDelay);
|
95
|
+
}
|
96
|
+
|
97
|
+
void SWSerLCDsf::print(const char *s)
|
98
|
+
{
|
99
|
+
while (*s) {
|
100
|
+
print(*s++);
|
101
|
+
delay(1);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
void SWSerLCDsf::print(char c)
|
106
|
+
{
|
107
|
+
print((uint8_t) c);
|
108
|
+
}
|
109
|
+
|
110
|
+
void SWSerLCDsf::print(int n)
|
111
|
+
{
|
112
|
+
print((long) n);
|
113
|
+
}
|
114
|
+
|
115
|
+
void SWSerLCDsf::print(unsigned int n)
|
116
|
+
{
|
117
|
+
print((unsigned long) n);
|
118
|
+
}
|
119
|
+
|
120
|
+
void SWSerLCDsf::print(long n)
|
121
|
+
{
|
122
|
+
if (n < 0) {
|
123
|
+
print('-');
|
124
|
+
n = -n;
|
125
|
+
}
|
126
|
+
printNumber(n, 10);
|
127
|
+
}
|
128
|
+
|
129
|
+
void SWSerLCDsf::print(unsigned long n)
|
130
|
+
{
|
131
|
+
printNumber(n, 10);
|
132
|
+
}
|
133
|
+
|
134
|
+
void SWSerLCDsf::print(long n, int base)
|
135
|
+
{
|
136
|
+
if (base == 0)
|
137
|
+
print((char) n);
|
138
|
+
else if (base == 10)
|
139
|
+
print(n);
|
140
|
+
else
|
141
|
+
printNumber(n, base);
|
142
|
+
}
|
143
|
+
|
144
|
+
// -------- Spark Fun unique codes -------------------------
|
145
|
+
|
146
|
+
void SWSerLCDsf::clearscr(void)
|
147
|
+
{
|
148
|
+
print((uint8_t) 0xFE);
|
149
|
+
print((uint8_t) 0x01);
|
150
|
+
delay(100);
|
151
|
+
}
|
152
|
+
|
153
|
+
void SWSerLCDsf::clearscr(const char *s)
|
154
|
+
{
|
155
|
+
clearscr();
|
156
|
+
print(s);
|
157
|
+
}
|
158
|
+
|
159
|
+
void SWSerLCDsf::clearscr(int n)
|
160
|
+
{
|
161
|
+
clearscr();
|
162
|
+
print(n);
|
163
|
+
}
|
164
|
+
|
165
|
+
void SWSerLCDsf::clearscr(long n, int b)
|
166
|
+
{
|
167
|
+
clearscr();
|
168
|
+
print(n,b);
|
169
|
+
}
|
170
|
+
|
171
|
+
void SWSerLCDsf::home(void)
|
172
|
+
{
|
173
|
+
setxy(0, 0);
|
174
|
+
}
|
175
|
+
|
176
|
+
void SWSerLCDsf::home(const char *s)
|
177
|
+
{
|
178
|
+
home();
|
179
|
+
print(s);
|
180
|
+
}
|
181
|
+
|
182
|
+
void SWSerLCDsf::home(int n)
|
183
|
+
{
|
184
|
+
home();
|
185
|
+
print(n);
|
186
|
+
}
|
187
|
+
|
188
|
+
void SWSerLCDsf::home(long n, int b)
|
189
|
+
{
|
190
|
+
home();
|
191
|
+
print(n,b);
|
192
|
+
}
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
void SWSerLCDsf::setxy(byte x, byte y)
|
197
|
+
{
|
198
|
+
byte posvar;
|
199
|
+
|
200
|
+
switch (y) {
|
201
|
+
case 0:
|
202
|
+
posvar = 128 + x;
|
203
|
+
break;
|
204
|
+
case 1:
|
205
|
+
posvar = 192+ x;
|
206
|
+
break;
|
207
|
+
case 2:
|
208
|
+
posvar = ((_cols == 16) ? 144 : 148) + x;
|
209
|
+
break;
|
210
|
+
case 3:
|
211
|
+
posvar = ((_cols == 16) ? 208 : 212) + x;
|
212
|
+
break;
|
213
|
+
}
|
214
|
+
print((uint8_t) 0xFE);
|
215
|
+
print((uint8_t) posvar);
|
216
|
+
}
|
217
|
+
|
218
|
+
void SWSerLCDsf::setxy(byte x, byte y, const char *s)
|
219
|
+
{
|
220
|
+
setxy(x,y);
|
221
|
+
print(s);
|
222
|
+
}
|
223
|
+
|
224
|
+
void SWSerLCDsf::setxy(byte x, byte y, int n)
|
225
|
+
{
|
226
|
+
setxy(x,y);
|
227
|
+
print(n);
|
228
|
+
}
|
229
|
+
|
230
|
+
void SWSerLCDsf::setxy(byte x, byte y, long n, int b)
|
231
|
+
{
|
232
|
+
setxy(x,y);
|
233
|
+
print(n,b);
|
234
|
+
}
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
void SWSerLCDsf::setcmd(byte code, byte cmd)
|
239
|
+
{
|
240
|
+
print((uint8_t) code);
|
241
|
+
print((uint8_t) cmd);
|
242
|
+
}
|
243
|
+
|
244
|
+
|
245
|
+
void SWSerLCDsf::setgeo(int geometry)
|
246
|
+
{
|
247
|
+
byte rows=6, cols=4;
|
248
|
+
switch (geometry) {
|
249
|
+
case 216:
|
250
|
+
break;
|
251
|
+
case 220:
|
252
|
+
_cols = 20;
|
253
|
+
cols = 3;
|
254
|
+
break;
|
255
|
+
case 416:
|
256
|
+
rows = 5;
|
257
|
+
_rows = 4;
|
258
|
+
break;
|
259
|
+
case 420:
|
260
|
+
_rows = 4;
|
261
|
+
_cols = 20;
|
262
|
+
cols = 3;
|
263
|
+
rows = 5;
|
264
|
+
break;
|
265
|
+
default:
|
266
|
+
return;
|
267
|
+
break;
|
268
|
+
}
|
269
|
+
print((uint8_t) 0x7C);
|
270
|
+
print((uint8_t) rows);
|
271
|
+
print((uint8_t) 0x7C);
|
272
|
+
print((uint8_t) cols);
|
273
|
+
delay(200);
|
274
|
+
}
|
275
|
+
|
276
|
+
void SWSerLCDsf::setintensity(int intensity)
|
277
|
+
{
|
278
|
+
if (intensity > 29)
|
279
|
+
intensity = 29;
|
280
|
+
print((uint8_t) 0x7C);
|
281
|
+
print((uint8_t) (0x80 + intensity));
|
282
|
+
delay(100);
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
// Private Methods /////////////////////////////////////////////////////////////
|
290
|
+
|
291
|
+
void SWSerLCDsf::printNumber(unsigned long n, uint8_t base)
|
292
|
+
{
|
293
|
+
unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
|
294
|
+
unsigned long i = 0;
|
295
|
+
|
296
|
+
if (n == 0) {
|
297
|
+
print('0');
|
298
|
+
return;
|
299
|
+
}
|
300
|
+
|
301
|
+
while (n > 0) {
|
302
|
+
buf[i++] = n % base;
|
303
|
+
n /= base;
|
304
|
+
}
|
305
|
+
|
306
|
+
for (; i > 0; i--)
|
307
|
+
print((char) (buf[i - 1] < 10 ? '0' + buf[i - 1] : 'A' + buf[i - 1] - 10));
|
308
|
+
|
309
|
+
delay(8);
|
310
|
+
|
311
|
+
}
|