madrona-rad 0.2.4 → 0.2.5

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 (37) hide show
  1. data/History.txt +10 -0
  2. data/Manifest.txt +26 -0
  3. data/bin/rad +28 -36
  4. data/lib/examples/blink_m_hello.rb +14 -0
  5. data/lib/examples/debounce_methods.rb +49 -0
  6. data/lib/examples/external_variable_fu.rb +24 -0
  7. data/lib/examples/external_variables.rb +31 -0
  8. data/lib/examples/hello_eeprom.rb +54 -0
  9. data/lib/examples/i2c_with_clock_chip.rb +124 -0
  10. data/lib/examples/two_wire.rb +14 -0
  11. data/lib/libraries/DS1307/DS1307.cpp +161 -0
  12. data/lib/libraries/DS1307/DS1307.h +64 -0
  13. data/lib/libraries/DS1307/keywords.txt +18 -0
  14. data/lib/libraries/OneWire/OneWire.cpp +194 -0
  15. data/lib/libraries/OneWire/OneWire.h +63 -0
  16. data/lib/libraries/OneWire/keywords.txt +35 -0
  17. data/lib/libraries/OneWire/readme.txt +13 -0
  18. data/lib/libraries/Wire/Wire.cpp +262 -0
  19. data/lib/libraries/Wire/Wire.h +67 -0
  20. data/lib/libraries/Wire/keywords.txt +31 -0
  21. data/lib/libraries/Wire/twi.h +57 -0
  22. data/lib/plugins/bitwise_ops.rb +54 -0
  23. data/lib/plugins/blink_m.rb +304 -6
  24. data/lib/plugins/debounce.rb +46 -24
  25. data/lib/plugins/i2c_eeprom.rb +70 -0
  26. data/lib/rad/arduino_plugin.rb +27 -4
  27. data/lib/rad/arduino_sketch.rb +354 -115
  28. data/lib/rad/generators/makefile/makefile.erb +2 -2
  29. data/lib/rad/generators/makefile/makefile.rb +5 -9
  30. data/lib/rad/init.rb +3 -1
  31. data/lib/rad/rad_processor.rb +11 -0
  32. data/lib/rad/rad_rewriter.rb +1 -1
  33. data/lib/rad/tasks/build_and_make.rake +25 -12
  34. data/lib/rad/variable_processing.rb +116 -0
  35. data/lib/test/test_array_processing.rb +78 -0
  36. data/lib/test/test_variable_processing.rb +188 -0
  37. metadata +29 -3
@@ -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,262 @@
1
+ /*
2
+ TwoWire.cpp - TWI/I2C library for Wiring & Arduino
3
+ Copyright (c) 2006 Nicholas Zambetti. 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
+ extern "C" {
21
+ #include <stdlib.h>
22
+ #include <string.h>
23
+ #include <inttypes.h>
24
+ #include "twi.h"
25
+ }
26
+
27
+ #include "Wire.h"
28
+
29
+ // Initialize Class Variables //////////////////////////////////////////////////
30
+
31
+ uint8_t* TwoWire::rxBuffer = 0;
32
+ uint8_t TwoWire::rxBufferIndex = 0;
33
+ uint8_t TwoWire::rxBufferLength = 0;
34
+
35
+ uint8_t TwoWire::txAddress = 0;
36
+ uint8_t* TwoWire::txBuffer = 0;
37
+ uint8_t TwoWire::txBufferIndex = 0;
38
+ uint8_t TwoWire::txBufferLength = 0;
39
+
40
+ uint8_t TwoWire::transmitting = 0;
41
+ void (*TwoWire::user_onRequest)(void);
42
+ void (*TwoWire::user_onReceive)(int);
43
+
44
+ // Constructors ////////////////////////////////////////////////////////////////
45
+
46
+ TwoWire::TwoWire()
47
+ {
48
+ }
49
+
50
+ // Public Methods //////////////////////////////////////////////////////////////
51
+
52
+ void TwoWire::begin(void)
53
+ {
54
+ // init buffer for reads
55
+ rxBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t));
56
+ rxBufferIndex = 0;
57
+ rxBufferLength = 0;
58
+
59
+ // init buffer for writes
60
+ txBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t));
61
+ txBufferIndex = 0;
62
+ txBufferLength = 0;
63
+
64
+ twi_init();
65
+ }
66
+
67
+ void TwoWire::begin(uint8_t address)
68
+ {
69
+ twi_setAddress(address);
70
+ twi_attachSlaveTxEvent(onRequestService);
71
+ twi_attachSlaveRxEvent(onReceiveService);
72
+ begin();
73
+ }
74
+
75
+ void TwoWire::begin(int address)
76
+ {
77
+ begin((uint8_t)address);
78
+ }
79
+
80
+ void TwoWire::requestFrom(uint8_t address, uint8_t quantity)
81
+ {
82
+ // clamp to buffer length
83
+ if(quantity > BUFFER_LENGTH){
84
+ quantity = BUFFER_LENGTH;
85
+ }
86
+ // perform blocking read into buffer
87
+ twi_readFrom(address, rxBuffer, quantity);
88
+ // set rx buffer iterator vars
89
+ rxBufferIndex = 0;
90
+ rxBufferLength = quantity;
91
+ }
92
+
93
+ void TwoWire::requestFrom(int address, int quantity)
94
+ {
95
+ requestFrom((uint8_t)address, (uint8_t)quantity);
96
+ }
97
+
98
+ void TwoWire::beginTransmission(uint8_t address)
99
+ {
100
+ // indicate that we are transmitting
101
+ transmitting = 1;
102
+ // set address of targeted slave
103
+ txAddress = address;
104
+ // reset tx buffer iterator vars
105
+ txBufferIndex = 0;
106
+ txBufferLength = 0;
107
+ }
108
+
109
+ void TwoWire::beginTransmission(int address)
110
+ {
111
+ beginTransmission((uint8_t)address);
112
+ }
113
+
114
+ void TwoWire::endTransmission(void)
115
+ {
116
+ // transmit buffer (blocking)
117
+ twi_writeTo(txAddress, txBuffer, txBufferLength, 1);
118
+ // reset tx buffer iterator vars
119
+ txBufferIndex = 0;
120
+ txBufferLength = 0;
121
+ // indicate that we are done transmitting
122
+ transmitting = 0;
123
+ }
124
+
125
+ // must be called in:
126
+ // slave tx event callback
127
+ // or after beginTransmission(address)
128
+ void TwoWire::send(uint8_t data)
129
+ {
130
+ if(transmitting){
131
+ // in master transmitter mode
132
+ // don't bother if buffer is full
133
+ if(txBufferLength >= BUFFER_LENGTH){
134
+ return;
135
+ }
136
+ // put byte in tx buffer
137
+ txBuffer[txBufferIndex] = data;
138
+ ++txBufferIndex;
139
+ // update amount in buffer
140
+ txBufferLength = txBufferIndex;
141
+ }else{
142
+ // in slave send mode
143
+ // reply to master
144
+ twi_transmit(&data, 1);
145
+ }
146
+ }
147
+
148
+ // must be called in:
149
+ // slave tx event callback
150
+ // or after beginTransmission(address)
151
+ void TwoWire::send(uint8_t* data, uint8_t quantity)
152
+ {
153
+ if(transmitting){
154
+ // in master transmitter mode
155
+ for(uint8_t i = 0; i < quantity; ++i){
156
+ send(data[i]);
157
+ }
158
+ }else{
159
+ // in slave send mode
160
+ // reply to master
161
+ twi_transmit(data, quantity);
162
+ }
163
+ }
164
+
165
+ // must be called in:
166
+ // slave tx event callback
167
+ // or after beginTransmission(address)
168
+ void TwoWire::send(char* data)
169
+ {
170
+ send((uint8_t*)data, strlen(data));
171
+ }
172
+
173
+ // must be called in:
174
+ // slave tx event callback
175
+ // or after beginTransmission(address)
176
+ void TwoWire::send(int data)
177
+ {
178
+ send((uint8_t)data);
179
+ }
180
+
181
+ // must be called in:
182
+ // slave rx event callback
183
+ // or after requestFrom(address, numBytes)
184
+ uint8_t TwoWire::available(void)
185
+ {
186
+ return rxBufferLength - rxBufferIndex;
187
+ }
188
+
189
+ // must be called in:
190
+ // slave rx event callback
191
+ // or after requestFrom(address, numBytes)
192
+ uint8_t TwoWire::receive(void)
193
+ {
194
+ // default to returning null char
195
+ // for people using with char strings
196
+ uint8_t value = '\0';
197
+
198
+ // get each successive byte on each call
199
+ if(rxBufferIndex < rxBufferLength){
200
+ value = rxBuffer[rxBufferIndex];
201
+ ++rxBufferIndex;
202
+ }
203
+
204
+ return value;
205
+ }
206
+
207
+ // behind the scenes function that is called when data is received
208
+ void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
209
+ {
210
+ // don't bother if user hasn't registered a callback
211
+ if(!user_onReceive){
212
+ return;
213
+ }
214
+ // don't bother if rx buffer is in use by a master requestFrom() op
215
+ // i know this drops data, but it allows for slight stupidity
216
+ // meaning, they may not have read all the master requestFrom() data yet
217
+ if(rxBufferIndex < rxBufferLength){
218
+ return;
219
+ }
220
+ // copy twi rx buffer into local read buffer
221
+ // this enables new reads to happen in parallel
222
+ for(uint8_t i = 0; i < numBytes; ++i){
223
+ rxBuffer[i] = inBytes[i];
224
+ }
225
+ // set rx iterator vars
226
+ rxBufferIndex = 0;
227
+ rxBufferLength = numBytes;
228
+ // alert user program
229
+ user_onReceive(numBytes);
230
+ }
231
+
232
+ // behind the scenes function that is called when data is requested
233
+ void TwoWire::onRequestService(void)
234
+ {
235
+ // don't bother if user hasn't registered a callback
236
+ if(!user_onRequest){
237
+ return;
238
+ }
239
+ // reset tx buffer iterator vars
240
+ // !!! this will kill any pending pre-master sendTo() activity
241
+ txBufferIndex = 0;
242
+ txBufferLength = 0;
243
+ // alert user program
244
+ user_onRequest();
245
+ }
246
+
247
+ // sets function called on slave write
248
+ void TwoWire::onReceive( void (*function)(int) )
249
+ {
250
+ user_onReceive = function;
251
+ }
252
+
253
+ // sets function called on slave read
254
+ void TwoWire::onRequest( void (*function)(void) )
255
+ {
256
+ user_onRequest = function;
257
+ }
258
+
259
+ // Preinstantiate Objects //////////////////////////////////////////////////////
260
+
261
+ TwoWire Wire = TwoWire();
262
+
@@ -0,0 +1,67 @@
1
+ /*
2
+ TwoWire.h - TWI/I2C library for Arduino & Wiring
3
+ Copyright (c) 2006 Nicholas Zambetti. 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 TwoWire_h
21
+ #define TwoWire_h
22
+
23
+ #include <inttypes.h>
24
+
25
+ #define BUFFER_LENGTH 32
26
+
27
+ class TwoWire
28
+ {
29
+ private:
30
+ static uint8_t* rxBuffer;
31
+ static uint8_t rxBufferIndex;
32
+ static uint8_t rxBufferLength;
33
+
34
+ static uint8_t txAddress;
35
+ static uint8_t* txBuffer;
36
+ static uint8_t txBufferIndex;
37
+ static uint8_t txBufferLength;
38
+
39
+ static uint8_t transmitting;
40
+ static void (*user_onRequest)(void);
41
+ static void (*user_onReceive)(int);
42
+ static void onRequestService(void);
43
+ static void onReceiveService(uint8_t*, int);
44
+ public:
45
+ TwoWire();
46
+ void begin();
47
+ void begin(uint8_t);
48
+ void begin(int);
49
+ void beginTransmission(uint8_t);
50
+ void beginTransmission(int);
51
+ void endTransmission(void);
52
+ void requestFrom(uint8_t, uint8_t);
53
+ void requestFrom(int, int);
54
+ void send(uint8_t);
55
+ void send(uint8_t*, uint8_t);
56
+ void send(int);
57
+ void send(char*);
58
+ uint8_t available(void);
59
+ uint8_t receive(void);
60
+ void onReceive( void (*)(int) );
61
+ void onRequest( void (*)(void) );
62
+ };
63
+
64
+ extern TwoWire Wire;
65
+
66
+ #endif
67
+
@@ -0,0 +1,31 @@
1
+ #######################################
2
+ # Syntax Coloring Map For Wire
3
+ #######################################
4
+
5
+ #######################################
6
+ # Datatypes (KEYWORD1)
7
+ #######################################
8
+
9
+ #######################################
10
+ # Methods and Functions (KEYWORD2)
11
+ #######################################
12
+
13
+ begin KEYWORD2
14
+ beginTransmission KEYWORD2
15
+ endTransmission KEYWORD2
16
+ requestFrom KEYWORD2
17
+ send KEYWORD2
18
+ receive KEYWORD2
19
+ onReceive KEYWORD2
20
+ onRequest KEYWORD2
21
+
22
+ #######################################
23
+ # Instances (KEYWORD2)
24
+ #######################################
25
+
26
+ Wire KEYWORD2
27
+
28
+ #######################################
29
+ # Constants (LITERAL1)
30
+ #######################################
31
+