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.
- 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,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Stepper.h - - Stepper library for Wiring/Arduino - Version 0.4
|
|
3
|
+
|
|
4
|
+
Original library (0.1) by Tom Igoe.
|
|
5
|
+
Two-wire modifications (0.2) by Sebastian Gassner
|
|
6
|
+
Combination version (0.3) by Tom Igoe and David Mellis
|
|
7
|
+
Bug fix for four-wire (0.4) by Tom Igoe, bug fix from Noah Shibley
|
|
8
|
+
|
|
9
|
+
Drives a unipolar or bipolar stepper motor using 2 wires or 4 wires
|
|
10
|
+
|
|
11
|
+
When wiring multiple stepper motors to a microcontroller,
|
|
12
|
+
you quickly run out of output pins, with each motor requiring 4 connections.
|
|
13
|
+
|
|
14
|
+
By making use of the fact that at any time two of the four motor
|
|
15
|
+
coils are the inverse of the other two, the number of
|
|
16
|
+
control connections can be reduced from 4 to 2.
|
|
17
|
+
|
|
18
|
+
A slightly modified circuit around a Darlington transistor array or an L293 H-bridge
|
|
19
|
+
connects to only 2 microcontroler pins, inverts the signals received,
|
|
20
|
+
and delivers the 4 (2 plus 2 inverted ones) output signals required
|
|
21
|
+
for driving a stepper motor.
|
|
22
|
+
|
|
23
|
+
The sequence of control signals for 4 control wires is as follows:
|
|
24
|
+
|
|
25
|
+
Step C0 C1 C2 C3
|
|
26
|
+
1 1 0 1 0
|
|
27
|
+
2 0 1 1 0
|
|
28
|
+
3 0 1 0 1
|
|
29
|
+
4 1 0 0 1
|
|
30
|
+
|
|
31
|
+
The sequence of controls signals for 2 control wires is as follows
|
|
32
|
+
(columns C1 and C2 from above):
|
|
33
|
+
|
|
34
|
+
Step C0 C1
|
|
35
|
+
1 0 1
|
|
36
|
+
2 1 1
|
|
37
|
+
3 1 0
|
|
38
|
+
4 0 0
|
|
39
|
+
|
|
40
|
+
The circuits can be found at
|
|
41
|
+
http://www.arduino.cc/en/Tutorial/Stepper
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
// ensure this library description is only included once
|
|
45
|
+
#ifndef Stepper_h
|
|
46
|
+
#define Stepper_h
|
|
47
|
+
|
|
48
|
+
// include types & constants of Wiring core API
|
|
49
|
+
#include "WConstants.h"
|
|
50
|
+
|
|
51
|
+
// library interface description
|
|
52
|
+
class Stepper {
|
|
53
|
+
public:
|
|
54
|
+
// constructors:
|
|
55
|
+
Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2);
|
|
56
|
+
Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4);
|
|
57
|
+
|
|
58
|
+
// speed setter method:
|
|
59
|
+
void set_speed(long whatSpeed);
|
|
60
|
+
|
|
61
|
+
// mover method:
|
|
62
|
+
void set_steps(int number_of_steps);
|
|
63
|
+
|
|
64
|
+
int version(void);
|
|
65
|
+
|
|
66
|
+
private:
|
|
67
|
+
void stepMotor(int this_step);
|
|
68
|
+
|
|
69
|
+
int direction; // Direction of rotation
|
|
70
|
+
int speed; // Speed in RPMs
|
|
71
|
+
unsigned long step_delay; // delay between steps, in ms, based on speed
|
|
72
|
+
int number_of_steps; // total number of steps this motor can take
|
|
73
|
+
int pin_count; // whether you're driving the motor with 2 or 4 pins
|
|
74
|
+
int step_number; // which step the motor is on
|
|
75
|
+
|
|
76
|
+
// motor pin numbers:
|
|
77
|
+
int motor_pin_1;
|
|
78
|
+
int motor_pin_2;
|
|
79
|
+
int motor_pin_3;
|
|
80
|
+
int motor_pin_4;
|
|
81
|
+
|
|
82
|
+
long last_step_time; // time stamp in ms of when the last step was taken
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
#endif
|
|
86
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#######################################
|
|
2
|
+
# Syntax Coloring Map For Test
|
|
3
|
+
#######################################
|
|
4
|
+
|
|
5
|
+
#######################################
|
|
6
|
+
# Datatypes (KEYWORD1)
|
|
7
|
+
#######################################
|
|
8
|
+
|
|
9
|
+
Stepper KEYWORD1
|
|
10
|
+
|
|
11
|
+
#######################################
|
|
12
|
+
# Methods and Functions (KEYWORD2)
|
|
13
|
+
#######################################
|
|
14
|
+
|
|
15
|
+
step KEYWORD2
|
|
16
|
+
setSpeed KEYWORD2
|
|
17
|
+
version KEYWORD2
|
|
18
|
+
|
|
19
|
+
######################################
|
|
20
|
+
# Instances (KEYWORD2)
|
|
21
|
+
#######################################
|
|
22
|
+
direction KEYWORD2
|
|
23
|
+
speed KEYWORD2
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
#######################################
|
|
27
|
+
# Constants (LITERAL1)
|
|
28
|
+
#######################################
|
|
@@ -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
|
+
|