neo_rad 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +7 -0
  2. data/History.txt +112 -0
  3. data/License.txt +282 -0
  4. data/Manifest.txt +144 -0
  5. data/README.rdoc +1 -0
  6. data/Rakefile +142 -0
  7. data/bin/rad +302 -0
  8. data/lib/examples/add_hysteresis.rb +13 -0
  9. data/lib/examples/basic_blink.rb +10 -0
  10. data/lib/examples/blink_m_address_assignment.rb +104 -0
  11. data/lib/examples/blink_m_hello.rb +14 -0
  12. data/lib/examples/blink_m_multi.rb +61 -0
  13. data/lib/examples/blink_with_serial.rb +16 -0
  14. data/lib/examples/configure_pa_lcd_boot.rb +91 -0
  15. data/lib/examples/debounce_methods.rb +49 -0
  16. data/lib/examples/external_variable_fu.rb +26 -0
  17. data/lib/examples/external_variables.rb +32 -0
  18. data/lib/examples/first_sound.rb +23 -0
  19. data/lib/examples/frequency_generator.rb +30 -0
  20. data/lib/examples/hello_array.rb +48 -0
  21. data/lib/examples/hello_array2.rb +112 -0
  22. data/lib/examples/hello_array_eeprom.rb +59 -0
  23. data/lib/examples/hello_clock.rb +84 -0
  24. data/lib/examples/hello_eeprom.rb +51 -0
  25. data/lib/examples/hello_eeprom_lcdpa.rb +81 -0
  26. data/lib/examples/hello_format_print.rb +94 -0
  27. data/lib/examples/hello_lcd_charset.rb +75 -0
  28. data/lib/examples/hello_pa_lcd.rb +59 -0
  29. data/lib/examples/hello_servos.rb +88 -0
  30. data/lib/examples/hello_spectra_sound.rb +38 -0
  31. data/lib/examples/hello_world.rb +11 -0
  32. data/lib/examples/hello_xbee.rb +12 -0
  33. data/lib/examples/hysteresis_duel.rb +39 -0
  34. data/lib/examples/i2c_with_clock_chip.rb +124 -0
  35. data/lib/examples/midi_beat_box.rb +86 -0
  36. data/lib/examples/midi_scales.rb +94 -0
  37. data/lib/examples/motor_knob.rb +30 -0
  38. data/lib/examples/servo_buttons.rb +23 -0
  39. data/lib/examples/servo_calibrate_continuous.rb +92 -0
  40. data/lib/examples/servo_throttle.rb +40 -0
  41. data/lib/examples/software_serial.rb +10 -0
  42. data/lib/examples/sparkfun_lcd.rb +48 -0
  43. data/lib/examples/spectra_soft_pot.rb +34 -0
  44. data/lib/examples/times_method.rb +8 -0
  45. data/lib/examples/toggle.rb +10 -0
  46. data/lib/examples/twitter.rb +57 -0
  47. data/lib/examples/two_wire.rb +14 -0
  48. data/lib/libraries/AFSoftSerial/AFSoftSerial.cpp +321 -0
  49. data/lib/libraries/AFSoftSerial/AFSoftSerial.h +61 -0
  50. data/lib/libraries/AFSoftSerial/keywords.txt +18 -0
  51. data/lib/libraries/AF_XPort/AF_XPort.cpp +166 -0
  52. data/lib/libraries/AF_XPort/AF_XPort.h +48 -0
  53. data/lib/libraries/DS1307/DS1307.cpp +162 -0
  54. data/lib/libraries/DS1307/DS1307.h +66 -0
  55. data/lib/libraries/DS1307/keywords.txt +18 -0
  56. data/lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp +144 -0
  57. data/lib/libraries/FrequencyTimer2/FrequencyTimer2.h +42 -0
  58. data/lib/libraries/FrequencyTimer2/keywords.txt +22 -0
  59. data/lib/libraries/I2CEEPROM/I2CEEPROM.cpp +120 -0
  60. data/lib/libraries/I2CEEPROM/I2CEEPROM.h +70 -0
  61. data/lib/libraries/I2CEEPROM/keywords.txt +21 -0
  62. data/lib/libraries/LoopTimer/LoopTimer.cpp +35 -0
  63. data/lib/libraries/LoopTimer/LoopTimer.h +34 -0
  64. data/lib/libraries/LoopTimer/keywords.txt +27 -0
  65. data/lib/libraries/OneWire/OneWire.cpp +194 -0
  66. data/lib/libraries/OneWire/OneWire.h +63 -0
  67. data/lib/libraries/OneWire/keywords.txt +35 -0
  68. data/lib/libraries/OneWire/readme.txt +13 -0
  69. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp +296 -0
  70. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +69 -0
  71. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +311 -0
  72. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +67 -0
  73. data/lib/libraries/Servo/Servo.cpp +192 -0
  74. data/lib/libraries/Servo/Servo.h +61 -0
  75. data/lib/libraries/Stepper/Stepper.cpp +220 -0
  76. data/lib/libraries/Stepper/Stepper.h +86 -0
  77. data/lib/libraries/Stepper/keywords.txt +28 -0
  78. data/lib/libraries/Wire/Wire.cpp +262 -0
  79. data/lib/libraries/Wire/Wire.h +67 -0
  80. data/lib/libraries/Wire/keywords.txt +31 -0
  81. data/lib/libraries/Wire/twi.h +57 -0
  82. data/lib/libraries/Wire/utility/twi.c +449 -0
  83. data/lib/libraries/Wire/utility/twi.h +57 -0
  84. data/lib/plugins/bitwise_ops.rb +54 -0
  85. data/lib/plugins/blink.rb +25 -0
  86. data/lib/plugins/blink_m.rb +356 -0
  87. data/lib/plugins/debounce.rb +138 -0
  88. data/lib/plugins/debug_output_to_lcd.rb +71 -0
  89. data/lib/plugins/hysteresis.rb +52 -0
  90. data/lib/plugins/input_output_state.rb +84 -0
  91. data/lib/plugins/lcd_padding.rb +58 -0
  92. data/lib/plugins/mem_test.rb +37 -0
  93. data/lib/plugins/midi.rb +60 -0
  94. data/lib/plugins/parallax_ping.rb +50 -0
  95. data/lib/plugins/servo_pulse.rb +31 -0
  96. data/lib/plugins/servo_setup.rb +86 -0
  97. data/lib/plugins/smoother.rb +54 -0
  98. data/lib/plugins/spark_fun_serial_lcd.rb +100 -0
  99. data/lib/plugins/spectra_symbol.rb +79 -0
  100. data/lib/plugins/twitter_connect.rb +145 -0
  101. data/lib/rad/README.rdoc +5 -0
  102. data/lib/rad/arduino_plugin.rb +246 -0
  103. data/lib/rad/arduino_sketch.rb +628 -0
  104. data/lib/rad/darwin_installer.rb +23 -0
  105. data/lib/rad/generators/makefile/makefile.erb +243 -0
  106. data/lib/rad/generators/makefile/makefile.rb +38 -0
  107. data/lib/rad/hardware_library.rb +813 -0
  108. data/lib/rad/init.rb +15 -0
  109. data/lib/rad/linux_installer.rb +132 -0
  110. data/lib/rad/progressbar.rb +236 -0
  111. data/lib/rad/rad_processor.rb +128 -0
  112. data/lib/rad/rad_rewriter.rb +94 -0
  113. data/lib/rad/rad_type_checker.rb +26 -0
  114. data/lib/rad/sim/arduino_sketch.rb +57 -0
  115. data/lib/rad/sketch_compiler.rb +47 -0
  116. data/lib/rad/tasks/build_and_make.rake +210 -0
  117. data/lib/rad/tasks/rad.rb +2 -0
  118. data/lib/rad/todo.txt +13 -0
  119. data/lib/rad/variable_processing.rb +153 -0
  120. data/lib/rad/version.rb +9 -0
  121. data/lib/rad.rb +5 -0
  122. data/scripts/txt2html +67 -0
  123. data/setup.rb +1585 -0
  124. data/spec/examples/hello_world.rb +11 -0
  125. data/spec/examples/serial_motor.rb +12 -0
  126. data/spec/models/arduino_sketch_spec.rb +82 -0
  127. data/spec/models/sketch_compiler_spec.rb +96 -0
  128. data/spec/models/spec_helper.rb +2 -0
  129. data/spec/sim/hello_world_spec.rb +42 -0
  130. data/spec/spec.opts +1 -0
  131. data/test/hello_world_test/Makefile +436 -0
  132. data/test/hello_world_test/hello_world.cpp +23 -0
  133. data/test/test_array_processing.rb +179 -0
  134. data/test/test_plugin_loading.rb +151 -0
  135. data/test/test_translation_post_processing.rb +185 -0
  136. data/test/test_variable_processing.rb +238 -0
  137. data/website/examples/assembler_test.rb.html +73 -0
  138. data/website/examples/gps_reader.rb.html +39 -0
  139. data/website/examples/hello_world.rb.html +38 -0
  140. data/website/examples/serial_motor.rb.html +41 -0
  141. data/website/index.html +178 -0
  142. data/website/index.txt +64 -0
  143. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  144. data/website/stylesheets/screen.css +169 -0
  145. data/website/template.rhtml +48 -0
  146. metadata +222 -0
@@ -0,0 +1,34 @@
1
+ /*
2
+ LoopTime.h - - Loop Timer library for Wiring/Arduino - Version 0.1
3
+
4
+ Original code by JD Banrhart
5
+ Original Arduino Library by BB Riley
6
+
7
+ */
8
+
9
+ // ensure this library description is only included once
10
+ #ifndef LoopTimer_h
11
+ #define LoopTimer_h
12
+
13
+ // include types & constants of Wiring core API
14
+ #include "WConstants.h"
15
+
16
+ // library interface description
17
+ class LoopTimer {
18
+ public:
19
+ // constructors:
20
+ LoopTimer();
21
+
22
+ // track method
23
+ void track(void);
24
+
25
+ // mover method:
26
+ unsigned long get_total(void);
27
+
28
+ private:
29
+ unsigned long start_loop_time;
30
+ unsigned long total_loop_time;
31
+ };
32
+
33
+ #endif
34
+
@@ -0,0 +1,27 @@
1
+ #######################################
2
+ # Syntax Coloring Map For Test
3
+ #######################################
4
+
5
+ #######################################
6
+ # Datatypes (KEYWORD1)
7
+ #######################################
8
+
9
+ LoopTimer KEYWORD1
10
+
11
+ #######################################
12
+ # Methods and Functions (KEYWORD2)
13
+ #######################################
14
+
15
+ track KEYWORD2
16
+ get_total KEYWORD2
17
+
18
+
19
+ ######################################
20
+ # Instances (KEYWORD2)
21
+ #######################################
22
+
23
+
24
+
25
+ #######################################
26
+ # Constants (LITERAL1)
27
+ #######################################
@@ -0,0 +1,194 @@
1
+ /*
2
+
3
+ // -----------------------------------------------------------
4
+ // This is an 'abbreviated' OneWire Library with functions
5
+ // only to handle a single device per line, no ROM-IDs will
6
+ // be read. It is a subset of the original fom the Arduino
7
+ // IDE - Brian Riley, Underhill Center, VT July 2008
8
+ // -----------------------------------------------------------
9
+ Copyright (c) 2007, Jim Studt
10
+
11
+ Updated to work with arduino-0008 and to include skip() as of
12
+ 2007/07/06. --RJL20
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining
15
+ a copy of this software and associated documentation files (the
16
+ "Software"), to deal in the Software without restriction, including
17
+ without limitation the rights to use, copy, modify, merge, publish,
18
+ distribute, sublicense, and/or sell copies of the Software, and to
19
+ permit persons to whom the Software is furnished to do so, subject to
20
+ the following conditions:
21
+
22
+ The above copyright notice and this permission notice shall be
23
+ included in all copies or substantial portions of the Software.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
+
33
+ Much of the code was inspired by Derek Yerger's code, though I don't
34
+ think much of that remains. In any event that was..
35
+ (copyleft) 2006 by Derek Yerger - Free to distribute freely.
36
+
37
+ The CRC code was excerpted and inspired by the Dallas Semiconductor
38
+ sample code bearing this copyright.
39
+ //---------------------------------------------------------------------------
40
+ // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
41
+ //
42
+ // Permission is hereby granted, free of charge, to any person obtaining a
43
+ // copy of this software and associated documentation files (the "Software"),
44
+ // to deal in the Software without restriction, including without limitation
45
+ // the rights to use, copy, modify, merge, publish, distribute, sublicense,
46
+ // and/or sell copies of the Software, and to permit persons to whom the
47
+ // Software is furnished to do so, subject to the following conditions:
48
+ //
49
+ // The above copyright notice and this permission notice shall be included
50
+ // in all copies or substantial portions of the Software.
51
+ //
52
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
53
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55
+ // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
56
+ // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
57
+ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
58
+ // OTHER DEALINGS IN THE SOFTWARE.
59
+ //
60
+ // Except as contained in this notice, the name of Dallas Semiconductor
61
+ // shall not be used except as stated in the Dallas Semiconductor
62
+ // Branding Policy.
63
+ //--------------------------------------------------------------------------
64
+ */
65
+
66
+ #include "OneWire.h"
67
+
68
+ extern "C" {
69
+ #include "WConstants.h"
70
+ #include <avr/io.h>
71
+ #include "pins_arduino.h"
72
+ }
73
+
74
+
75
+ OneWire::OneWire( uint8_t pinArg)
76
+ {
77
+ pin = pinArg;
78
+ port = digitalPinToPort(pin);
79
+ bitmask = digitalPinToBitMask(pin);
80
+ outputReg = portOutputRegister(port);
81
+ inputReg = portInputRegister(port);
82
+ modeReg = portModeRegister(port);
83
+ }
84
+
85
+ //
86
+ // Perform the onewire reset function. We will wait up to 250uS for
87
+ // the bus to come high, if it doesn't then it is broken or shorted
88
+ // and we return a 0;
89
+ //
90
+ // Returns 1 if a device asserted a presence pulse, 0 otherwise.
91
+ //
92
+ uint8_t OneWire::reset() {
93
+ uint8_t r;
94
+ uint8_t retries = 125;
95
+
96
+ // wait until the wire is high... just in case
97
+ pinMode(pin,INPUT);
98
+ do {
99
+ if ( retries-- == 0) return 0;
100
+ delayMicroseconds(2);
101
+ } while( !digitalRead( pin));
102
+
103
+ digitalWrite(pin,0); // pull low for 500uS
104
+ pinMode(pin,OUTPUT);
105
+ delayMicroseconds(500);
106
+ pinMode(pin,INPUT);
107
+ delayMicroseconds(65);
108
+ r = !digitalRead(pin);
109
+ delayMicroseconds(490);
110
+ return r;
111
+ }
112
+
113
+ //
114
+ // Write a bit. Port and bit is used to cut lookup time and provide
115
+ // more certain timing.
116
+ //
117
+ void OneWire::write_bit(uint8_t v) {
118
+ static uint8_t lowTime[] = { 55, 5 };
119
+ static uint8_t highTime[] = { 5, 55};
120
+
121
+ v = (v&1);
122
+ *modeReg |= bitmask; // make pin an output, do first since we
123
+ // expect to be at 1
124
+ *outputReg &= ~bitmask; // zero
125
+ delayMicroseconds(lowTime[v]);
126
+ *outputReg |= bitmask; // one, push pin up - important for
127
+ // parasites, they might start in here
128
+ delayMicroseconds(highTime[v]);
129
+ }
130
+
131
+ //
132
+ // Read a bit. Port and bit is used to cut lookup time and provide
133
+ // more certain timing.
134
+ //
135
+ uint8_t OneWire::read_bit() {
136
+ uint8_t r;
137
+
138
+ *modeReg |= bitmask; // make pin an output, do first since we expect to be at 1
139
+ *outputReg &= ~bitmask; // zero
140
+ delayMicroseconds(1);
141
+ *modeReg &= ~bitmask; // let pin float, pull up will raise
142
+ delayMicroseconds(5); // A "read slot" is when 1mcs > t > 2mcs
143
+ r = ( *inputReg & bitmask) ? 1 : 0; // check the bit
144
+ delayMicroseconds(50); // whole bit slot is 60-120uS, need to give some time
145
+
146
+ return r;
147
+ }
148
+
149
+ //
150
+ // Write a byte. The writing code uses the active drivers to raise the
151
+ // pin high, if you need power after the write (e.g. DS18S20 in
152
+ // parasite power mode) then set 'power' to 1, otherwise the pin will
153
+ // go tri-state at the end of the write to avoid heating in a short or
154
+ // other mishap.
155
+ //
156
+ void OneWire::write(uint8_t v, uint8_t power) {
157
+ uint8_t bitMask;
158
+
159
+ for (bitMask = 0x01; bitMask; bitMask <<= 1) {
160
+ OneWire::write_bit( (bitMask & v)?1:0);
161
+ }
162
+ if ( !power) {
163
+ pinMode(pin,INPUT);
164
+ digitalWrite(pin,0);
165
+ }
166
+ }
167
+
168
+ //
169
+ // Read a byte
170
+ //
171
+ uint8_t OneWire::read() {
172
+ uint8_t bitMask;
173
+ uint8_t r = 0;
174
+
175
+ for (bitMask = 0x01; bitMask; bitMask <<= 1) {
176
+ if ( OneWire::read_bit()) r |= bitMask;
177
+ }
178
+ return r;
179
+ }
180
+
181
+
182
+ //
183
+ // Do a ROM skip
184
+ //
185
+ void OneWire::skip()
186
+ {
187
+ write(0xCC,0); // Skip ROM
188
+ }
189
+
190
+ void OneWire::depower()
191
+ {
192
+ pinMode(pin,INPUT);
193
+ }
194
+
@@ -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
@@ -0,0 +1,296 @@
1
+ /*
2
+ SWSerLCDpa.cpp - Software serial to Peter Anderson 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 2007
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 "SWSerLCDpa.h"
27
+
28
+ /******************************************************************************
29
+ * Definitions
30
+ ******************************************************************************/
31
+
32
+ /******************************************************************************
33
+ * Constructors
34
+ ******************************************************************************/
35
+
36
+ SWSerLCDpa::SWSerLCDpa(uint8_t transmitPin)
37
+ {
38
+ _transmitPin = transmitPin;
39
+ _baudRate = 0;
40
+ pinMode(_transmitPin, OUTPUT);
41
+ _geometry = 0;
42
+ }
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
+
54
+ /******************************************************************************
55
+ * User API
56
+ ******************************************************************************/
57
+
58
+ void SWSerLCDpa::begin(long speed)
59
+ {
60
+ _baudRate = speed;
61
+ _bitPeriod = 1000000 / _baudRate;
62
+
63
+ digitalWrite(_transmitPin, HIGH);
64
+ delayMicroseconds( _bitPeriod); // if we were low this establishes the end
65
+ delay(50);
66
+ if (_geometry)
67
+ setgeo(_geometry);
68
+ }
69
+
70
+ void SWSerLCDpa::print(uint8_t b)
71
+ {
72
+ if (_baudRate == 0)
73
+ return;
74
+
75
+ int bitDelay = _bitPeriod - clockCyclesToMicroseconds(50); // a digitalWrite is about 50 cycles
76
+ byte mask;
77
+
78
+ digitalWrite(_transmitPin, LOW);
79
+ delayMicroseconds(bitDelay);
80
+
81
+ for (mask = 0x01; mask; mask <<= 1) {
82
+ if (b & mask){ // choose bit
83
+ digitalWrite(_transmitPin,HIGH); // send 1
84
+ }
85
+ else{
86
+ digitalWrite(_transmitPin,LOW); // send 1
87
+ }
88
+ delayMicroseconds(bitDelay);
89
+ }
90
+
91
+ digitalWrite(_transmitPin, HIGH);
92
+ delayMicroseconds(bitDelay);
93
+ }
94
+
95
+ void SWSerLCDpa::print(const char *s)
96
+ {
97
+ while (*s) {
98
+ print(*s++);
99
+ delay(2);
100
+ }
101
+ }
102
+
103
+ void SWSerLCDpa::print(char c)
104
+ {
105
+ print((uint8_t) c);
106
+ }
107
+
108
+ void SWSerLCDpa::print(int n)
109
+ {
110
+ print((long) n);
111
+ }
112
+
113
+ void SWSerLCDpa::print(unsigned int n)
114
+ {
115
+ print((unsigned long) n);
116
+ }
117
+
118
+ void SWSerLCDpa::print(long n)
119
+ {
120
+ if (n < 0) {
121
+ print('-');
122
+ n = -n;
123
+ }
124
+ printNumber(n, 10);
125
+ }
126
+
127
+ void SWSerLCDpa::print(unsigned long n)
128
+ {
129
+ printNumber(n, 10);
130
+ }
131
+
132
+ void SWSerLCDpa::print(long n, int base)
133
+ {
134
+ if (base == 0)
135
+ print((char) n);
136
+ else if (base == 10)
137
+ print(n);
138
+ else
139
+ printNumber(n, base);
140
+ }
141
+
142
+ // -------- PHA unique codes -------------------------
143
+
144
+
145
+ void SWSerLCDpa::clearscr(void)
146
+ {
147
+ print("?f");
148
+ delay(30);
149
+ }
150
+
151
+ void SWSerLCDpa::clearscr(const char *s)
152
+ {
153
+ clearscr();
154
+ print(s);
155
+ }
156
+
157
+ void SWSerLCDpa::clearscr(int n)
158
+ {
159
+ clearscr();
160
+ print(n);
161
+ }
162
+
163
+ void SWSerLCDpa::clearscr(long n, int base)
164
+ {
165
+ clearscr();
166
+ print(n, base);
167
+ }
168
+
169
+
170
+ void SWSerLCDpa::clearline(int line)
171
+ {
172
+ setxy(0,line);
173
+ print("?l");
174
+ delay(20);
175
+ }
176
+
177
+ void SWSerLCDpa::clearline(int line, const char *s)
178
+ {
179
+ clearline(line);
180
+ print(s);
181
+ }
182
+
183
+ void SWSerLCDpa::clearline(int line, int n)
184
+ {
185
+ clearline(line);
186
+ print(n);
187
+ }
188
+
189
+ void SWSerLCDpa::clearline(int line, long n, int base)
190
+ {
191
+ clearline(line);
192
+ print(n, base);
193
+ }
194
+
195
+ void SWSerLCDpa::setxy(int x, int y)
196
+ {
197
+ print("?y");
198
+ print(y);
199
+ print("?x");
200
+ if (x < 10)
201
+ print('0');
202
+ print(x);
203
+ delay(10);
204
+ }
205
+
206
+ void SWSerLCDpa::setxy(int x, int y, const char *s)
207
+ {
208
+ setxy(x,y);
209
+ print(s);
210
+ }
211
+
212
+ void SWSerLCDpa::setxy(int x, int y, int n)
213
+ {
214
+ setxy(x,y);
215
+ print(n);
216
+ }
217
+
218
+ void SWSerLCDpa::setxy(int x, int y, long n, int base)
219
+ {
220
+ setxy(x,y);
221
+ print(n, base);
222
+ }
223
+
224
+ void SWSerLCDpa::home(void)
225
+ {
226
+ print("?a");
227
+ delay(10);
228
+ }
229
+
230
+ void SWSerLCDpa::home(const char *s)
231
+ {
232
+ home();
233
+ print(s);
234
+ }
235
+
236
+ void SWSerLCDpa::home(int n)
237
+ {
238
+ home();
239
+ print(n);
240
+ }
241
+
242
+ void SWSerLCDpa::home(long n, int base)
243
+ {
244
+ home();
245
+ print(n, base);
246
+ }
247
+
248
+ void SWSerLCDpa::setgeo(int geometry)
249
+ {
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("?<");
272
+ }
273
+
274
+ // Private Methods /////////////////////////////////////////////////////////////
275
+
276
+ void SWSerLCDpa::printNumber(unsigned long n, uint8_t base)
277
+ {
278
+ unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
279
+ unsigned long i = 0;
280
+
281
+ if (n == 0) {
282
+ print('0');
283
+ return;
284
+ }
285
+
286
+ while (n > 0) {
287
+ buf[i++] = n % base;
288
+ n /= base;
289
+ }
290
+
291
+ for (; i > 0; i--) {
292
+ print((char) (buf[i - 1] < 10 ? '0' + buf[i - 1] : 'A' + buf[i - 1] - 10));
293
+ delay(2);
294
+ }
295
+
296
+ }