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.
- data/History.txt +10 -0
- data/Manifest.txt +26 -0
- data/bin/rad +28 -36
- data/lib/examples/blink_m_hello.rb +14 -0
- data/lib/examples/debounce_methods.rb +49 -0
- data/lib/examples/external_variable_fu.rb +24 -0
- data/lib/examples/external_variables.rb +31 -0
- data/lib/examples/hello_eeprom.rb +54 -0
- data/lib/examples/i2c_with_clock_chip.rb +124 -0
- data/lib/examples/two_wire.rb +14 -0
- data/lib/libraries/DS1307/DS1307.cpp +161 -0
- data/lib/libraries/DS1307/DS1307.h +64 -0
- data/lib/libraries/DS1307/keywords.txt +18 -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/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/plugins/bitwise_ops.rb +54 -0
- data/lib/plugins/blink_m.rb +304 -6
- data/lib/plugins/debounce.rb +46 -24
- data/lib/plugins/i2c_eeprom.rb +70 -0
- data/lib/rad/arduino_plugin.rb +27 -4
- data/lib/rad/arduino_sketch.rb +354 -115
- data/lib/rad/generators/makefile/makefile.erb +2 -2
- data/lib/rad/generators/makefile/makefile.rb +5 -9
- data/lib/rad/init.rb +3 -1
- data/lib/rad/rad_processor.rb +11 -0
- data/lib/rad/rad_rewriter.rb +1 -1
- data/lib/rad/tasks/build_and_make.rake +25 -12
- data/lib/rad/variable_processing.rb +116 -0
- data/lib/test/test_array_processing.rb +78 -0
- data/lib/test/test_variable_processing.rb +188 -0
- metadata +29 -3
@@ -0,0 +1,161 @@
|
|
1
|
+
extern "C" {
|
2
|
+
#include <../Wire/Wire.h>
|
3
|
+
}
|
4
|
+
#include "DS1307.h"
|
5
|
+
|
6
|
+
DS1307::DS1307()
|
7
|
+
{
|
8
|
+
// Wire.begin();
|
9
|
+
}
|
10
|
+
|
11
|
+
DS1307 RTC=DS1307();
|
12
|
+
|
13
|
+
// PRIVATE FUNCTIONS
|
14
|
+
|
15
|
+
// Aquire data from the RTC chip in BCD format
|
16
|
+
// refresh the buffer
|
17
|
+
void DS1307::read(void)
|
18
|
+
{
|
19
|
+
// use the Wire lib to connect to tho rtc
|
20
|
+
// reset the register pointer to zero
|
21
|
+
Wire.beginTransmission(DS1307_CTRL_ID);
|
22
|
+
Wire.send(0x00);
|
23
|
+
Wire.endTransmission();
|
24
|
+
|
25
|
+
// request the 7 bytes of data (secs, min, hr, dow, date, mth, yr)
|
26
|
+
Wire.requestFrom(DS1307_CTRL_ID, 7);
|
27
|
+
for(int i=0; i<7; i++)
|
28
|
+
{
|
29
|
+
// store data in raw bcd format
|
30
|
+
rtc_bcd[i]=Wire.receive();
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
// update the data on the IC from the bcd formatted data in the buffer
|
35
|
+
void DS1307::save(void)
|
36
|
+
{
|
37
|
+
Wire.beginTransmission(DS1307_CTRL_ID);
|
38
|
+
Wire.send(0x00); // reset register pointer
|
39
|
+
for(int i=0; i<7; i++)
|
40
|
+
{
|
41
|
+
Wire.send(rtc_bcd[i]);
|
42
|
+
}
|
43
|
+
Wire.endTransmission();
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
// PUBLIC FUNCTIONS
|
48
|
+
/*
|
49
|
+
void DS1307::get(int *rtc, boolean refresh) // Aquire data from buffer and convert to int, refresh buffer if required
|
50
|
+
{
|
51
|
+
if(refresh) read();
|
52
|
+
for(int i=0;i<7;i++) // cycle through each component, create array of data
|
53
|
+
{
|
54
|
+
rtc[i]=get(i, 0);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
*/
|
58
|
+
|
59
|
+
int DS1307::get(int c, boolean refresh) // aquire individual RTC item from buffer, return as int, refresh buffer if required
|
60
|
+
{
|
61
|
+
if(refresh) read();
|
62
|
+
int v=-1;
|
63
|
+
switch(c)
|
64
|
+
{
|
65
|
+
case DS1307_SEC:
|
66
|
+
v=(10*((rtc_bcd[DS1307_SEC] & DS1307_HI_SEC)>>4))+(rtc_bcd[DS1307_SEC] & DS1307_LO_BCD);
|
67
|
+
break;
|
68
|
+
case DS1307_MIN:
|
69
|
+
v=(10*((rtc_bcd[DS1307_MIN] & DS1307_HI_MIN)>>4))+(rtc_bcd[DS1307_MIN] & DS1307_LO_BCD);
|
70
|
+
break;
|
71
|
+
case DS1307_HR:
|
72
|
+
v=(10*((rtc_bcd[DS1307_HR] & DS1307_HI_HR)>>4))+(rtc_bcd[DS1307_HR] & DS1307_LO_BCD);
|
73
|
+
break;
|
74
|
+
case DS1307_DOW:
|
75
|
+
v=rtc_bcd[DS1307_DOW] & DS1307_LO_DOW;
|
76
|
+
break;
|
77
|
+
case DS1307_DATE:
|
78
|
+
v=(10*((rtc_bcd[DS1307_DATE] & DS1307_HI_DATE)>>4))+(rtc_bcd[DS1307_DATE] & DS1307_LO_BCD);
|
79
|
+
break;
|
80
|
+
case DS1307_MTH:
|
81
|
+
v=(10*((rtc_bcd[DS1307_MTH] & DS1307_HI_MTH)>>4))+(rtc_bcd[DS1307_MTH] & DS1307_LO_BCD);
|
82
|
+
break;
|
83
|
+
case DS1307_YR:
|
84
|
+
v=(10*((rtc_bcd[DS1307_YR] & DS1307_HI_YR)>>4))+(rtc_bcd[DS1307_YR] & DS1307_LO_BCD)+DS1307_BASE_YR;
|
85
|
+
break;
|
86
|
+
} // end switch
|
87
|
+
return v;
|
88
|
+
}
|
89
|
+
|
90
|
+
void DS1307::set(int c, int v) // Update buffer, then update the chip
|
91
|
+
{
|
92
|
+
switch(c)
|
93
|
+
{
|
94
|
+
case DS1307_SEC:
|
95
|
+
if(v<60 && v>-1)
|
96
|
+
{
|
97
|
+
//preserve existing clock state (running/stopped)
|
98
|
+
int state=rtc_bcd[DS1307_SEC] & DS1307_CLOCKHALT;
|
99
|
+
rtc_bcd[DS1307_SEC]=state | ((v / 10)<<4) + (v % 10);
|
100
|
+
}
|
101
|
+
break;
|
102
|
+
case DS1307_MIN:
|
103
|
+
if(v<60 && v>-1)
|
104
|
+
{
|
105
|
+
rtc_bcd[DS1307_MIN]=((v / 10)<<4) + (v % 10);
|
106
|
+
}
|
107
|
+
break;
|
108
|
+
case DS1307_HR:
|
109
|
+
// TODO : AM/PM 12HR/24HR
|
110
|
+
if(v<24 && v>-1)
|
111
|
+
{
|
112
|
+
rtc_bcd[DS1307_HR]=((v / 10)<<4) + (v % 10);
|
113
|
+
}
|
114
|
+
break;
|
115
|
+
case DS1307_DOW:
|
116
|
+
if(v<8 && v>-1)
|
117
|
+
{
|
118
|
+
rtc_bcd[DS1307_DOW]=v;
|
119
|
+
}
|
120
|
+
break;
|
121
|
+
case DS1307_DATE:
|
122
|
+
if(v<31 && v>-1)
|
123
|
+
{
|
124
|
+
rtc_bcd[DS1307_DATE]=((v / 10)<<4) + (v % 10);
|
125
|
+
}
|
126
|
+
break;
|
127
|
+
case DS1307_MTH:
|
128
|
+
if(v<13 && v>-1)
|
129
|
+
{
|
130
|
+
rtc_bcd[DS1307_MTH]=((v / 10)<<4) + (v % 10);
|
131
|
+
}
|
132
|
+
break;
|
133
|
+
case DS1307_YR:
|
134
|
+
if(v<13 && v>-1)
|
135
|
+
{
|
136
|
+
rtc_bcd[DS1307_YR]=((v / 10)<<4) + (v % 10);
|
137
|
+
}
|
138
|
+
break;
|
139
|
+
} // end switch
|
140
|
+
save();
|
141
|
+
}
|
142
|
+
|
143
|
+
void DS1307::stop(void)
|
144
|
+
{
|
145
|
+
// set the ClockHalt bit high to stop the rtc
|
146
|
+
// this bit is part of the seconds byte
|
147
|
+
rtc_bcd[DS1307_SEC]=rtc_bcd[DS1307_SEC] | DS1307_CLOCKHALT;
|
148
|
+
save();
|
149
|
+
}
|
150
|
+
|
151
|
+
void DS1307::start(void)
|
152
|
+
{
|
153
|
+
// unset the ClockHalt bit to start the rtc
|
154
|
+
// TODO : preserve existing seconds
|
155
|
+
rtc_bcd[DS1307_SEC]=0;
|
156
|
+
save();
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
/*
|
2
|
+
DS1307.h - library for DS1307 rtc
|
3
|
+
*/
|
4
|
+
|
5
|
+
// ensure this library description is only included once
|
6
|
+
#ifndef DS1307_h
|
7
|
+
#define DS1307_h
|
8
|
+
|
9
|
+
// include types & constants of Wiring core API
|
10
|
+
#include <WConstants.h>
|
11
|
+
|
12
|
+
// include types & constants of Wire ic2 lib
|
13
|
+
#include <../Wire/Wire.h>
|
14
|
+
|
15
|
+
#define DS1307_SEC 0
|
16
|
+
#define DS1307_MIN 1
|
17
|
+
#define DS1307_HR 2
|
18
|
+
#define DS1307_DOW 3
|
19
|
+
#define DS1307_DATE 4
|
20
|
+
#define DS1307_MTH 5
|
21
|
+
#define DS1307_YR 6
|
22
|
+
#define DS1307_CTRL 7
|
23
|
+
|
24
|
+
#define DS1307_BASE_YR 2000
|
25
|
+
|
26
|
+
#define DS1307_CTRL_ID B1101000 //DS1307
|
27
|
+
|
28
|
+
// Define register bit masks
|
29
|
+
#define DS1307_CLOCKHALT B10000000
|
30
|
+
|
31
|
+
#define DS1307_LO_BCD B00001111
|
32
|
+
#define DS1307_HI_BCD B11110000
|
33
|
+
|
34
|
+
#define DS1307_HI_SEC B01110000
|
35
|
+
#define DS1307_HI_MIN B01110000
|
36
|
+
#define DS1307_HI_HR B00110000
|
37
|
+
#define DS1307_LO_DOW B00000111
|
38
|
+
#define DS1307_HI_DATE B00110000
|
39
|
+
#define DS1307_HI_MTH B00110000
|
40
|
+
#define DS1307_HI_YR B11110000
|
41
|
+
|
42
|
+
// library interface description
|
43
|
+
class DS1307
|
44
|
+
{
|
45
|
+
// user-accessible "public" interface
|
46
|
+
public:
|
47
|
+
DS1307();
|
48
|
+
// void get(int *, boolean);
|
49
|
+
int get(int, boolean);
|
50
|
+
void set(int, int);
|
51
|
+
void start(void);
|
52
|
+
void stop(void);
|
53
|
+
|
54
|
+
// library-accessible "private" interface
|
55
|
+
private:
|
56
|
+
byte rtc_bcd[7]; // used prior to read/set ds1307 registers;
|
57
|
+
void read(void);
|
58
|
+
void save(void);
|
59
|
+
};
|
60
|
+
|
61
|
+
extern DS1307 RTC;
|
62
|
+
|
63
|
+
#endif
|
64
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#######################################
|
2
|
+
# Syntax Coloring Map For Ultrasound
|
3
|
+
#######################################
|
4
|
+
|
5
|
+
#######################################
|
6
|
+
# Datatypes (KEYWORD1)
|
7
|
+
#######################################
|
8
|
+
|
9
|
+
DS1307 KEYWORD1
|
10
|
+
|
11
|
+
#######################################
|
12
|
+
# Methods and Functions (KEYWORD2)
|
13
|
+
#######################################
|
14
|
+
|
15
|
+
#######################################
|
16
|
+
# Constants (LITERAL1)
|
17
|
+
#######################################
|
18
|
+
|
@@ -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
|
+
|