neo_rad 0.4.0

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 (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,162 @@
1
+ extern "C" {
2
+ #include <../Wire/Wire.h>
3
+ }
4
+ #include "DS1307.h"
5
+
6
+ DS1307::DS1307()
7
+ {
8
+ // Wire.begin(); // no no no no ..... do it explictly outside of library - multiple invocations is TROUBLE!!!!! BBR
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 the 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(byte *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
+ byte 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
+ byte 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
+ v=(10*((rtc_bcd[DS1307_YR] & DS1307_HI_YR)>>4))+(rtc_bcd[DS1307_YR] & DS1307_LO_BCD);
86
+ break;
87
+ } // end switch
88
+ return v;
89
+ }
90
+
91
+ void DS1307::set(int c, int v) // Update buffer, then update the chip
92
+ {
93
+ switch(c)
94
+ {
95
+ case DS1307_SEC:
96
+ if(v<60 && v>-1)
97
+ {
98
+ //preserve existing clock state (running/stopped)
99
+ int state=rtc_bcd[DS1307_SEC] & DS1307_CLOCKHALT;
100
+ rtc_bcd[DS1307_SEC]=state | ((v / 10)<<4) + (v % 10);
101
+ }
102
+ break;
103
+ case DS1307_MIN:
104
+ if(v<60 && v>-1)
105
+ {
106
+ rtc_bcd[DS1307_MIN]=((v / 10)<<4) + (v % 10);
107
+ }
108
+ break;
109
+ case DS1307_HR:
110
+ // TODO : AM/PM 12HR/24HR
111
+ if(v<24 && v>-1)
112
+ {
113
+ rtc_bcd[DS1307_HR]=((v / 10)<<4) + (v % 10);
114
+ }
115
+ break;
116
+ case DS1307_DOW:
117
+ if(v<8 && v>-1)
118
+ {
119
+ rtc_bcd[DS1307_DOW]=v;
120
+ }
121
+ break;
122
+ case DS1307_DATE:
123
+ if(v<31 && v>-1)
124
+ {
125
+ rtc_bcd[DS1307_DATE]=((v / 10)<<4) + (v % 10);
126
+ }
127
+ break;
128
+ case DS1307_MTH:
129
+ if(v<13 && v>-1)
130
+ {
131
+ rtc_bcd[DS1307_MTH]=((v / 10)<<4) + (v % 10);
132
+ }
133
+ break;
134
+ case DS1307_YR:
135
+ if(v<13 && v>-1)
136
+ {
137
+ rtc_bcd[DS1307_YR]=((v / 10)<<4) + (v % 10);
138
+ }
139
+ break;
140
+ } // end switch
141
+ save();
142
+ }
143
+
144
+ void DS1307::stop(void)
145
+ {
146
+ // set the ClockHalt bit high to stop the rtc
147
+ // this bit is part of the seconds byte
148
+ rtc_bcd[DS1307_SEC]=rtc_bcd[DS1307_SEC] | DS1307_CLOCKHALT;
149
+ save();
150
+ }
151
+
152
+ void DS1307::start(void)
153
+ {
154
+ // unset the ClockHalt bit to start the rtc
155
+ // TODO : preserve existing seconds
156
+ rtc_bcd[DS1307_SEC]=0;
157
+ save();
158
+ }
159
+
160
+
161
+
162
+
@@ -0,0 +1,66 @@
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 // with change of get() return from int to byte. this is no longer
25
+ // used, the user must add 2000 himself
26
+
27
+ #define DS1307_CTRL_ID B1101000 // DS1307
28
+
29
+ // Define register bit masks
30
+ #define DS1307_CLOCKHALT B10000000
31
+
32
+ #define DS1307_LO_BCD B00001111
33
+ #define DS1307_HI_BCD B11110000
34
+
35
+ #define DS1307_HI_SEC B01110000
36
+ #define DS1307_HI_MIN B01110000
37
+ #define DS1307_HI_HR B00110000
38
+ #define DS1307_LO_DOW B00000111
39
+ #define DS1307_HI_DATE B00110000
40
+ #define DS1307_HI_MTH B00110000
41
+ #define DS1307_HI_YR B11110000
42
+
43
+ // library interface description
44
+ class DS1307
45
+ {
46
+ // user-accessible "public" interface
47
+ public:
48
+ DS1307();
49
+ void get(byte*, boolean);
50
+ byte get(int, boolean);
51
+ void set(int, int);
52
+ void start(void);
53
+ void stop(void);
54
+
55
+ // library-accessible "private" interface
56
+ private:
57
+ byte rtc_bcd[7]; // used prior to read/set ds1307 registers;
58
+ void read(void);
59
+ void save(void);
60
+
61
+ };
62
+
63
+ extern DS1307 RTC;
64
+
65
+ #endif
66
+
@@ -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,144 @@
1
+
2
+
3
+
4
+ #include <FrequencyTimer2.h>
5
+
6
+ #include <avr/interrupt.h>
7
+
8
+ void (*FrequencyTimer2::onOverflow)() = 0;
9
+ uint8_t FrequencyTimer2::enabled = 0;
10
+
11
+ #if defined(__AVR_ATmega168__)
12
+ SIGNAL(SIG_OUTPUT_COMPARE2A)
13
+ #else
14
+ SIGNAL(SIG_OUTPUT_COMPARE2)
15
+ #endif
16
+ {
17
+ static uint8_t inHandler = 0; // protect us from recursion if our handler enables interrupts
18
+
19
+ if ( !inHandler && FrequencyTimer2::onOverflow) {
20
+ inHandler = 1;
21
+ (*FrequencyTimer2::onOverflow)();
22
+ inHandler = 0;
23
+ }
24
+ }
25
+
26
+ void FrequencyTimer2::setOnOverflow( void (*func)() )
27
+ {
28
+ FrequencyTimer2::onOverflow = func;
29
+ #if defined(__AVR_ATmega168__)
30
+ if ( func) TIMSK2 |= _BV(OCIE2A);
31
+ else TIMSK2 &= ~_BV(OCIE2A);
32
+ #else
33
+ if ( func) TIMSK |= _BV(OCIE2);
34
+ else TIMSK &= ~_BV(OCIE2);
35
+ #endif
36
+ }
37
+
38
+ void FrequencyTimer2::setPeriod(unsigned long period)
39
+ {
40
+ uint8_t pre, top;
41
+
42
+ if ( period == 0) period = 1;
43
+ period *= clockCyclesPerMicrosecond();
44
+
45
+ period /= 2; // we work with half-cycles before the toggle
46
+ if ( period <= 256) {
47
+ pre = 1;
48
+ top = period-1;
49
+ } else if ( period <= 256L*8) {
50
+ pre = 2;
51
+ top = period/8-1;
52
+ } else if ( period <= 256L*32) {
53
+ pre = 3;
54
+ top = period/32-1;
55
+ } else if ( period <= 256L*64) {
56
+ pre = 4;
57
+ top = period/64-1;
58
+ } else if ( period <= 256L*128) {
59
+ pre = 5;
60
+ top = period/128-1;
61
+ } else if ( period <= 256L*256) {
62
+ pre = 6;
63
+ top = period/256-1;
64
+ } else if ( period <= 256L*1024) {
65
+ pre = 7;
66
+ top = period/1024-1;
67
+ } else {
68
+ pre = 7;
69
+ top = 255;
70
+ }
71
+
72
+ #if defined(__AVR_ATmega168__)
73
+ TCCR2B = 0;
74
+ TCCR2A = 0;
75
+ TCNT2 = 0;
76
+ ASSR &= ~_BV(AS2); // use clock, not T2 pin
77
+ OCR2A = top;
78
+ TCCR2A = (_BV(WGM21) | ( FrequencyTimer2::enabled ? _BV(COM2A0) : 0));
79
+ TCCR2B = pre;
80
+ #else
81
+ TCCR2 = 0;
82
+ TCNT2 = 0;
83
+ ASSR &= ~_BV(AS2); // use clock, not T2 pin
84
+ OCR2 = top;
85
+ TCCR2 = (_BV(WGM21) | ( FrequencyTimer2::enabled ? _BV(COM20) : 0) | pre);
86
+ #endif
87
+ }
88
+
89
+ unsigned long FrequencyTimer2::getPeriod()
90
+ {
91
+ #if defined(__AVR_ATmega168__)
92
+ uint8_t p = (TCCR2B & 7);
93
+ unsigned long v = OCR2A;
94
+ #else
95
+ uint8_t p = (TCCR2 & 7);
96
+ unsigned long v = OCR2;
97
+ #endif
98
+ uint8_t shift;
99
+
100
+ switch(p) {
101
+ case 0 ... 1:
102
+ shift = 0;
103
+ break;
104
+ case 2:
105
+ shift = 3;
106
+ break;
107
+ case 3:
108
+ shift = 5;
109
+ break;
110
+ case 4:
111
+ shift = 6;
112
+ break;
113
+ case 5:
114
+ shift = 7;
115
+ break;
116
+ case 6:
117
+ shift = 8;
118
+ break;
119
+ case 7:
120
+ shift = 10;
121
+ break;
122
+ }
123
+ return (((v+1) << (shift+1)) + 1) / clockCyclesPerMicrosecond(); // shift+1 converts from half-period to period
124
+ }
125
+
126
+ void FrequencyTimer2::enable()
127
+ {
128
+ FrequencyTimer2::enabled = 1;
129
+ #if defined(__AVR_ATmega168__)
130
+ TCCR2A |= _BV(COM2A0);
131
+ #else
132
+ TCCR2 |= _BV(COM20);
133
+ #endif
134
+ }
135
+
136
+ void FrequencyTimer2::disable()
137
+ {
138
+ FrequencyTimer2::enabled = 0;
139
+ #if defined(__AVR_ATmega168__)
140
+ TCCR2A &= ~_BV(COM2A0);
141
+ #else
142
+ TCCR2 &= ~_BV(COM20);
143
+ #endif
144
+ }
@@ -0,0 +1,42 @@
1
+ #ifndef FREQUENCYTIMER2_IS_IN
2
+ #define FREQUENCYTIMER2_IS_IN
3
+
4
+ /*
5
+ FrequencyTimer2.h - A frequency generator and interrupt generator library
6
+ Author: Jim Studt, jim@federated.com
7
+ Copyright (c) 2007 David A. Mellis. All right reserved.
8
+
9
+ This library is free software; you can redistribute it and/or
10
+ modify it under the terms of the GNU Lesser General Public
11
+ License as published by the Free Software Foundation; either
12
+ version 2.1 of the License, or (at your option) any later version.
13
+
14
+ This library is distributed in the hope that it will be useful,
15
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ Lesser General Public License for more details.
18
+
19
+ You should have received a copy of the GNU Lesser General Public
20
+ License along with this library; if not, write to the Free Software
21
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
+ */
23
+
24
+
25
+ #include <wiring.h>
26
+
27
+ class FrequencyTimer2
28
+ {
29
+ private:
30
+ static uint8_t enabled;
31
+ public:
32
+ static void (*onOverflow)(); // not really public, but I can't work out the 'friend' for the SIGNAL
33
+
34
+ public:
35
+ static void setPeriod(unsigned long);
36
+ static unsigned long getPeriod();
37
+ static void setOnOverflow( void (*)() );
38
+ static void enable();
39
+ static void disable();
40
+ };
41
+
42
+ #endif
@@ -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
+