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,22 @@
|
|
|
1
|
+
#######################################
|
|
2
|
+
# Syntax Coloring Map FrequencyTimer2
|
|
3
|
+
#######################################
|
|
4
|
+
|
|
5
|
+
#######################################
|
|
6
|
+
# Datatypes (KEYWORD1)
|
|
7
|
+
#######################################
|
|
8
|
+
|
|
9
|
+
FrequencyTimer2 KEYWORD1
|
|
10
|
+
|
|
11
|
+
#######################################
|
|
12
|
+
# Methods and Functions (KEYWORD2)
|
|
13
|
+
#######################################
|
|
14
|
+
setPeriod KEYWORD2
|
|
15
|
+
getPeriod KEYWORD2
|
|
16
|
+
enable KEYWORD2
|
|
17
|
+
disable KEYWORD2
|
|
18
|
+
setOnOverflow KEYWORD2
|
|
19
|
+
|
|
20
|
+
#######################################
|
|
21
|
+
# Constants (LITERAL1)
|
|
22
|
+
#######################################
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/*************************************************************************************
|
|
2
|
+
* Arduino Library Program Code for Serial I2C EEPROMS - I2CEEPROM.cpp
|
|
3
|
+
* Adapted from an unsigned procedure on the Playground that had never been made
|
|
4
|
+
* into a library. Adaptation by Brian Riley, Underhill Center, VT, USA
|
|
5
|
+
* <brianbr@wulfden.org>
|
|
6
|
+
* ----------------------------------------------------------------------------------
|
|
7
|
+
* Simple read & write to a 24LCxxx EEPROM using the Wire library. The library will
|
|
8
|
+
* work with the 24LC16B (2KB), through and including 24LC512 (64KB). There is no way
|
|
9
|
+
* to tell what chip is there and consequently what the ending address is. So
|
|
10
|
+
* there is no address checking code, the programmer will have to keep track of his
|
|
11
|
+
* address count in his own program code. A read of a non-existant location will
|
|
12
|
+
* return the value 0xFF, but there is no way to tell if its an 0xFF or a read
|
|
13
|
+
* of non-existant memory
|
|
14
|
+
*
|
|
15
|
+
* Functions for R/W of single byte or a page of bytes. Block/Page reads are
|
|
16
|
+
* limited to 28 bytes due to the Wire library buffer being 32 bytes.
|
|
17
|
+
*
|
|
18
|
+
* Hardware Setup:
|
|
19
|
+
* _ _
|
|
20
|
+
* Arduino GND- A0-|oU |-Vcc to Arduino Vcc
|
|
21
|
+
* Arduino GND- A1-| |-WP to GND for now. Set to Vcc for write protection.
|
|
22
|
+
* Arduino GND- A2-| |-SCL to Arduino 5
|
|
23
|
+
* Arduino GND-Vss-| |-SDA to Arduino 4
|
|
24
|
+
* --- (A2, A1, A0 to GND for 1010000 (0x50) address.)
|
|
25
|
+
*
|
|
26
|
+
* Pulling any pin A2,A1,A0 to Vcc adds to base address 0x50, giving an address
|
|
27
|
+
* range for 8 devices 0x50 through 0x57, The code below assumes the 0x50, so
|
|
28
|
+
* when creating the instance one simply plugs in the relative address, a digit
|
|
29
|
+
* from 0 to 7. Now, the most common physical configuration is a single chip
|
|
30
|
+
* at device address 0, so instantiating with no device address assumes a '0'
|
|
31
|
+
* which becomes address 0x50 .
|
|
32
|
+
*
|
|
33
|
+
************************************************************************************/
|
|
34
|
+
|
|
35
|
+
extern "C" {
|
|
36
|
+
#include "WConstants.h"
|
|
37
|
+
#include <../Wire/Wire.h>
|
|
38
|
+
}
|
|
39
|
+
#include "I2CEEPROM.h"
|
|
40
|
+
|
|
41
|
+
/********************************
|
|
42
|
+
* I2CEEPROM() - constructors
|
|
43
|
+
********************************/
|
|
44
|
+
|
|
45
|
+
I2CEEPROM::I2CEEPROM() {
|
|
46
|
+
_device_address = 0x50;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
I2CEEPROM::I2CEEPROM(int addr) {
|
|
50
|
+
_device_address = addr + 0x50;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/********************************
|
|
54
|
+
* write_byte()
|
|
55
|
+
********************************/
|
|
56
|
+
|
|
57
|
+
void I2CEEPROM::write_byte( unsigned int eeaddress, byte data ) {
|
|
58
|
+
int rdata = data;
|
|
59
|
+
send_preamble(eeaddress);
|
|
60
|
+
Wire.send(rdata);
|
|
61
|
+
Wire.endTransmission();
|
|
62
|
+
delay(3); // needed to sllow tiem for the write
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/***************************************************************************
|
|
66
|
+
* write_page()
|
|
67
|
+
* Address is a page address, 6-bit (63). More and end will wrap
|
|
68
|
+
* around. But data can be maximum of 28 bytes, because the Wire library
|
|
69
|
+
* has a buffer of 32 bytes
|
|
70
|
+
***************************************************************************/
|
|
71
|
+
|
|
72
|
+
void I2CEEPROM::write_page( unsigned int eeaddresspage, byte* data, int length ) {
|
|
73
|
+
send_preamble(eeaddresspage);
|
|
74
|
+
for ( int c = 0; c < length; c++)
|
|
75
|
+
Wire.send(data[c]);
|
|
76
|
+
Wire.endTransmission();
|
|
77
|
+
delay(3*length); // need some delay
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/********************************
|
|
81
|
+
* read_byte()
|
|
82
|
+
********************************/
|
|
83
|
+
|
|
84
|
+
byte I2CEEPROM::read_byte( unsigned int eeaddress ) {
|
|
85
|
+
byte rdata = 0xFF;
|
|
86
|
+
send_preamble(eeaddress);
|
|
87
|
+
Wire.endTransmission();
|
|
88
|
+
Wire.requestFrom(_device_address,1);
|
|
89
|
+
if (Wire.available()) rdata = Wire.receive();
|
|
90
|
+
return rdata;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/************************************************
|
|
94
|
+
* write_byte()
|
|
95
|
+
* should not read more than 28 bytes at a time!
|
|
96
|
+
************************************************/
|
|
97
|
+
|
|
98
|
+
void I2CEEPROM::read_buffer( unsigned int eeaddress, byte *buffer, int length ) {
|
|
99
|
+
send_preamble(eeaddress);
|
|
100
|
+
Wire.endTransmission();
|
|
101
|
+
Wire.requestFrom(_device_address,length);
|
|
102
|
+
for ( int c = 0; c < length; c++ )
|
|
103
|
+
if (Wire.available()) buffer[c] = Wire.receive();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
/************************************************
|
|
108
|
+
* send_preamble()
|
|
109
|
+
* private function - group repetitive stuff
|
|
110
|
+
************************************************/
|
|
111
|
+
|
|
112
|
+
void I2CEEPROM::send_preamble( unsigned int eeaddress ) {
|
|
113
|
+
Wire.beginTransmission(_device_address);
|
|
114
|
+
Wire.send((int)(eeaddress >> 8)); // Address High Byte
|
|
115
|
+
Wire.send((int)(eeaddress & 0xFF)); // Address Low Byte
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
/*************************************************************************************
|
|
3
|
+
* Arduino Library Header File for Serial I2C EEPROMS - I2CEEPROM.h
|
|
4
|
+
* Adapted from an unsigned procedure on the Playground that had never been made
|
|
5
|
+
* into a library. Adaptation by Brian Riley, Underhill Center, VT, USA
|
|
6
|
+
* <brianbr@wulfden.org>
|
|
7
|
+
* ----------------------------------------------------------------------------------
|
|
8
|
+
* Simple read & write to a 24LCxxx EEPROM using the Wire library. The library will
|
|
9
|
+
* work with the 24LC16B (2KB), through and including 24LC512 (64KB). There is no way
|
|
10
|
+
* to tell what chip is there and consequently what the ending address is. So
|
|
11
|
+
* there is no address checking code, the programmer will have to keep track of his
|
|
12
|
+
* address count in his own program code. A read of a non-existant location will
|
|
13
|
+
* return the value 0xFF, but there is no way to tell if its an 0xFF or a read
|
|
14
|
+
* of non-existant memory
|
|
15
|
+
*
|
|
16
|
+
* Functions for R/W of single byte or a page of bytes. Block/Page reads are
|
|
17
|
+
* limited to 28 bytes due to the Wire library buffer being 32 bytes.
|
|
18
|
+
*
|
|
19
|
+
* Hardware Setup:
|
|
20
|
+
* _ _
|
|
21
|
+
* Arduino GND- A0-|oU |-Vcc to Arduino Vcc
|
|
22
|
+
* Arduino GND- A1-| |-WP to GND for now. Set to Vcc for write protection.
|
|
23
|
+
* Arduino GND- A2-| |-SCL to Arduino 5
|
|
24
|
+
* Arduino GND-Vss-| |-SDA to Arduino 4
|
|
25
|
+
* --- (A2, A1, A0 to GND for 1010000 (0x50) address.)
|
|
26
|
+
*
|
|
27
|
+
* Pulling any pin A2,A1,A0 to Vcc adds to base address 0x50, giving an address
|
|
28
|
+
* range for 8 devices 0x50 through 0x57, The code below assumes the 0x50, so
|
|
29
|
+
* when creating the instance one simply plugs in the relative address, a digit
|
|
30
|
+
* from 0 to 7. Now, the most common physical configuration is a single chip
|
|
31
|
+
* at device address 0, so instantiating with no device address assumes a '0'
|
|
32
|
+
* which becomes address 0x50 .
|
|
33
|
+
*
|
|
34
|
+
************************************************************************************/
|
|
35
|
+
|
|
36
|
+
// ensure this library description is only included once
|
|
37
|
+
#ifndef I2CEEPROM_h
|
|
38
|
+
#define I2CEEPROM_h
|
|
39
|
+
|
|
40
|
+
// include types & constants of Wiring core API
|
|
41
|
+
#include <WConstants.h>
|
|
42
|
+
|
|
43
|
+
// include types & constants of Wire i2c lib
|
|
44
|
+
#include <../Wire/Wire.h>
|
|
45
|
+
|
|
46
|
+
// library interface description
|
|
47
|
+
class I2CEEPROM
|
|
48
|
+
{
|
|
49
|
+
// user-accessible "public" interface
|
|
50
|
+
public:
|
|
51
|
+
I2CEEPROM();
|
|
52
|
+
I2CEEPROM(int);
|
|
53
|
+
|
|
54
|
+
void write_byte( unsigned int, byte );
|
|
55
|
+
|
|
56
|
+
void write_page( unsigned int, byte*, int );
|
|
57
|
+
|
|
58
|
+
byte read_byte( unsigned int );
|
|
59
|
+
|
|
60
|
+
void read_buffer( unsigned int, byte*, int );
|
|
61
|
+
|
|
62
|
+
// library-accessible "private" interface
|
|
63
|
+
private:
|
|
64
|
+
int _device_address;
|
|
65
|
+
void send_preamble(unsigned int);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
#endif
|
|
70
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#######################################
|
|
2
|
+
# Syntax Coloring Map For Ultrasound
|
|
3
|
+
#######################################
|
|
4
|
+
|
|
5
|
+
#######################################
|
|
6
|
+
# Datatypes (KEYWORD1)
|
|
7
|
+
#######################################
|
|
8
|
+
|
|
9
|
+
I2CEEPROM KEYWORD1
|
|
10
|
+
|
|
11
|
+
#######################################
|
|
12
|
+
# Methods and Functions (KEYWORD2)
|
|
13
|
+
#######################################
|
|
14
|
+
read_byte KEYWORD2
|
|
15
|
+
write_byte KEYWORD2
|
|
16
|
+
read_buffer KEYWORD2
|
|
17
|
+
write_page KEYWORD2
|
|
18
|
+
#######################################
|
|
19
|
+
# Constants (LITERAL1)
|
|
20
|
+
#######################################
|
|
21
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
LoopTime.cpp - - 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
|
+
|
|
10
|
+
// include types & constants of Wiring core API
|
|
11
|
+
#include "WProgram.h"
|
|
12
|
+
#include "LoopTimer.h"
|
|
13
|
+
|
|
14
|
+
LoopTimer::LoopTimer()
|
|
15
|
+
{
|
|
16
|
+
start_loop_time = 0;
|
|
17
|
+
total_loop_time = 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// track method
|
|
21
|
+
void LoopTimer::track(void)
|
|
22
|
+
{
|
|
23
|
+
total_loop_time = millis() - start_loop_time;
|
|
24
|
+
start_loop_time = millis();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// get total loop time:
|
|
28
|
+
unsigned long LoopTimer::get_total(void)
|
|
29
|
+
{
|
|
30
|
+
return total_loop_time;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
@@ -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
|
+
|