subduino 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/Readme.textile +48 -2
  2. data/VERSION +1 -1
  3. data/bin/subduino +21 -5
  4. data/duino/Makefile +53 -50
  5. data/duino/duino.pde +271 -5
  6. data/lib/subduino.rb +1 -1
  7. data/lib/subduino/parse.rb +23 -34
  8. data/lib/subduino/parse/bool.rb +13 -0
  9. data/lib/subduino/parse/lux.rb +13 -0
  10. data/lib/subduino/parse/temp.rb +17 -0
  11. data/lib/subduino/scaffold/Makefile +59 -51
  12. data/lib/subduino/store.rb +21 -12
  13. data/subduino.gemspec +88 -2
  14. data/webapp/config.yml +20 -0
  15. data/webapp/lib/app.rb +2 -2
  16. data/webapp/lib/duino.rb +9 -16
  17. data/webapp/public/custom.js +187 -0
  18. data/webapp/public/date_input.css +149 -0
  19. data/webapp/public/facebox.css +83 -0
  20. data/webapp/public/facebox.js +319 -0
  21. data/webapp/public/favicon.ico +0 -0
  22. data/webapp/public/icons/current.png +0 -0
  23. data/webapp/public/icons/day.png +0 -0
  24. data/webapp/public/icons/door-big.png +0 -0
  25. data/webapp/public/icons/favicon.png +0 -0
  26. data/webapp/public/icons/irrigation.png +0 -0
  27. data/webapp/public/icons/lamp-big.png +0 -0
  28. data/webapp/public/icons/lightbulb_off.png +0 -0
  29. data/webapp/public/icons/locked.png +0 -0
  30. data/webapp/public/icons/lux.png +0 -0
  31. data/webapp/public/icons/night.png +0 -0
  32. data/webapp/public/icons/noise.png +0 -0
  33. data/webapp/public/icons/onoff.png +0 -0
  34. data/webapp/public/icons/rain.png +0 -0
  35. data/webapp/public/icons/refrigeration.png +0 -0
  36. data/webapp/public/icons/temp.png +0 -0
  37. data/webapp/public/icons/unlocked.png +0 -0
  38. data/webapp/public/images/ajax-loader.gif +0 -0
  39. data/webapp/public/images/b.png +0 -0
  40. data/webapp/public/images/bendl.gif +0 -0
  41. data/webapp/public/images/bendr.gif +0 -0
  42. data/webapp/public/images/bendsb.gif +0 -0
  43. data/webapp/public/images/bg.jpg +0 -0
  44. data/webapp/public/images/bhead.gif +0 -0
  45. data/webapp/public/images/bheadl.gif +0 -0
  46. data/webapp/public/images/bheadr.gif +0 -0
  47. data/webapp/public/images/bl.png +0 -0
  48. data/webapp/public/images/bnd.gif +0 -0
  49. data/webapp/public/images/br.png +0 -0
  50. data/webapp/public/images/bread.gif +0 -0
  51. data/webapp/public/images/btnb.gif +0 -0
  52. data/webapp/public/images/btnb_.gif +0 -0
  53. data/webapp/public/images/btnm.gif +0 -0
  54. data/webapp/public/images/btnm_.gif +0 -0
  55. data/webapp/public/images/btns.gif +0 -0
  56. data/webapp/public/images/btns_.gif +0 -0
  57. data/webapp/public/images/cal.jpg +0 -0
  58. data/webapp/public/images/close.png +0 -0
  59. data/webapp/public/images/closelabel.gif +0 -0
  60. data/webapp/public/images/error.gif +0 -0
  61. data/webapp/public/images/ft.gif +0 -0
  62. data/webapp/public/images/hdr.gif +0 -0
  63. data/webapp/public/images/hdrl.gif +0 -0
  64. data/webapp/public/images/hdrr.gif +0 -0
  65. data/webapp/public/images/hld.jpg +0 -0
  66. data/webapp/public/images/imgb.gif +0 -0
  67. data/webapp/public/images/imgo.gif +0 -0
  68. data/webapp/public/images/imgt.gif +0 -0
  69. data/webapp/public/images/info.gif +0 -0
  70. data/webapp/public/images/jquery.wysiwyg.gif +0 -0
  71. data/webapp/public/images/li.gif +0 -0
  72. data/webapp/public/images/mbg.png +0 -0
  73. data/webapp/public/images/nsp.gif +0 -0
  74. data/webapp/public/images/phs.gif +0 -0
  75. data/webapp/public/images/sdd.jpg +0 -0
  76. data/webapp/public/images/sdd_.jpg +0 -0
  77. data/webapp/public/images/sidebar.gif +0 -0
  78. data/webapp/public/images/sorta.gif +0 -0
  79. data/webapp/public/images/sortd.gif +0 -0
  80. data/webapp/public/images/srch.gif +0 -0
  81. data/webapp/public/images/srch_.gif +0 -0
  82. data/webapp/public/images/success.gif +0 -0
  83. data/webapp/public/images/thumb1.jpg +0 -0
  84. data/webapp/public/images/thumb2.jpg +0 -0
  85. data/webapp/public/images/thumb3.jpg +0 -0
  86. data/webapp/public/images/tiny.gif +0 -0
  87. data/webapp/public/images/tiny_.gif +0 -0
  88. data/webapp/public/images/tl.png +0 -0
  89. data/webapp/public/images/tr.png +0 -0
  90. data/webapp/public/images/upload.gif +0 -0
  91. data/webapp/public/images/warning.gif +0 -0
  92. data/webapp/public/jquery.img.preload.js +152 -0
  93. data/webapp/public/jquery.sparkline.js +85 -0
  94. data/webapp/public/jquery.tablesorter.min.js +2 -0
  95. data/webapp/public/jquery.visualize.js +452 -0
  96. data/webapp/public/jquery.wysiwyg.css +56 -0
  97. data/webapp/public/style.css +881 -0
  98. data/webapp/public/visualize.css +32 -0
  99. data/webapp/views/index.haml +365 -49
  100. data/webapp/views/layout.haml +78 -7
  101. data/webapp/views/template.haml +676 -0
  102. metadata +89 -3
data/Readme.textile CHANGED
@@ -1,9 +1,10 @@
1
1
  h1. Subduino
2
2
 
3
- Talks to arduino using cool stuff.
3
+ Arduino Tools on Ruby
4
4
 
5
5
  http://github.com/nofxx/subduino
6
6
 
7
+
7
8
  h2. Install
8
9
 
9
10
  gem install subduino
@@ -12,11 +13,51 @@ h2. Install
12
13
  h3. Requirements
13
14
 
14
15
  * "Arduino":http://arduino.cc
16
+
17
+ PubSub (gems):
18
+
15
19
  * "serialport":http://github.com/hparra/ruby-serialport
16
20
  * "redis":http://github.com/ezmobius/redis-rb
17
21
 
22
+ Compile/Upload to arduino (archlinux pkgs):
23
+
24
+ * "arduino" or "arduino64"
25
+ * "gcc-avr"
26
+ * "avrdude"
27
+
28
+ WebApp (gems):
29
+
30
+ * sinatra
31
+ * haml
18
32
 
19
- h2. Use
33
+
34
+ h2. Create a project
35
+
36
+ <pre><code>
37
+ subduino some/dir/bot
38
+ ...creates folder and some sketch files...
39
+
40
+ </pre></code>
41
+
42
+ h3. bot.rb
43
+
44
+ Simple example that monitors arduinos on the USB.
45
+
46
+ h3. bot.pde
47
+
48
+ Common arduino source, can be compiled/uploaded via the IDE or:
49
+
50
+ h3. Makefile
51
+
52
+ Nice makefile so you don't need the IDE ;)
53
+ Use 'make' or 'make upload'.
54
+
55
+ It's being tested (works) on archlinux with arduino 0019.
56
+ It's just a matter of setting the first lines of the Makefile correct for your OS.
57
+ Please let me know so I can detect the OS and write a correct makefile for other distros.
58
+
59
+
60
+ h2. PubSub
20
61
 
21
62
  <pre><code>
22
63
 
@@ -31,6 +72,11 @@ h2. Use
31
72
  </pre></code>
32
73
 
33
74
 
75
+ h2. Webapp
76
+
77
+ Need some heavy work...
78
+
79
+
34
80
  h2. Contributing
35
81
 
36
82
  Fork/work/push.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/bin/subduino CHANGED
@@ -12,23 +12,39 @@ OptionParser.new { |op|
12
12
  }.parse!(ARGV.dup)
13
13
 
14
14
  # set :run, true
15
- if ARGV.empty?
15
+
16
+
17
+ if ARGV.empty? || ARGV.join =~ /yml/
18
+ LastRun = {:all => 0}
19
+ if File.exists?(f = ARGV.join)
20
+ puts "Using config file #{f}"
21
+ AppConfig = YAML.load(File.read(f))["opts"]
22
+ else
23
+ AppConfig = { "log_interval" => 30, "bauds" => 57600 }
24
+ end
16
25
 
17
26
  client = Faye::Client.new('http://localhost:8000/faye')
18
27
 
19
28
  EM.run do
20
29
 
21
30
  Subduino.start do |read|
22
- client.publish('/stats', 'data' => read)
23
31
  puts "[IO] #{read}"
32
+ if LastRun[:all] < (Time.now.to_i - AppConfig["log_interval"])
33
+ p "Syncing...."
34
+ LastRun[:all] = Time.now.to_i
35
+ client.publish('/stats', 'data' => read)
36
+ Subduino::Store.add_csv_to_store(read, true)
37
+ else
38
+ Subduino::Store.add_csv_to_store(read)
39
+ end
24
40
  end
25
41
 
26
42
  end
27
- end
28
-
43
+ else
29
44
  require "subduino/scaffold/generator"
30
45
  dir = ARGV[0]
31
46
  puts "Subduing dir #{dir}"
32
47
  `mkdir #{dir}` unless File.exists?(dir)
48
+ Subduino::Generator.copy_files(dir)
49
+ end
33
50
 
34
- Subduino::Generator.copy_files(dir)
data/duino/Makefile CHANGED
@@ -1,53 +1,25 @@
1
- ########################################################################
2
1
  #
3
- # Arduino command line tools Makefile
4
- # System part (i.e. project independent)
5
2
  #
6
- # Copyright (C) 2010 Martin Oldfield <m@mjo.tc>, based on work that is
7
- # Copyright Nicholas Zambetti, David A. Mellis & Hernando Barragan
3
+ # duino Arduino command line tools Makefile
8
4
  #
9
- # This file is free software; you can redistribute it and/or modify it
10
- # under the terms of the GNU Lesser General Public License as
11
- # published by the Free Software Foundation; either version 2.1 of the
12
- # License, or (at your option) any later version.
13
- #
14
- # Adapted from Arduino 0011 Makefile by M J Oldfield
15
- #
16
- # Original Arduino adaptation by mellis, eighthave, oli.keller
17
- #
18
- # Version 0.1 17.ii.2009 M J Oldfield
19
- #
20
- # 0.2 22.ii.2009 M J Oldfield
21
- # - fixes so that the Makefile actually works!
22
- # - support for uploading via ISP
23
- # - orthogonal choices of using the Arduino for
24
- # tools, libraries and uploading
25
- #
26
- # 0.3 21.v.2010 M J Oldfield
27
- # - added proper license statement
28
- # - added code from Philip Hands to reset
29
- # Arduino prior to upload
30
- #
31
- # 0.4 25.v.2010 M J Oldfield
32
- # - tweaked reset target on Philip Hands' advice
33
5
  #
34
- ########################################################################
6
+ # Copyright (C) 2010 Martin Oldfield <m@mjo.tc>, based on work that is
7
+ # Copyright Nicholas Zambetti, David A. Mellis & Hernando Barragan
35
8
  #
36
- # STANDARD ARDUINO WORKFLOW
37
9
  #
38
- # Given a normal sketch directory, all you need to do is to create
39
- # a small Makefile which defines a few things, and then includes this one.
10
+ # See footer for copyright/changelog....
11
+ #
12
+
40
13
  #
41
- # For example:
14
+ # CONFIGURATION
42
15
  #
16
+ TARGET = duino
43
17
  ARDUINO_DIR = /usr/share/arduino
44
- #
45
- TARGET = DUINO
46
18
  ARDUINO_LIBS = Messenger
47
19
 
48
20
  MCU = atmega328p
49
21
  F_CPU = 16000000
50
- ARDUINO_PORT = /dev/ttyUSB* #cu.usb*
22
+ ARDUINO_PORT = /dev/ttyUSB*
51
23
 
52
24
  # Linux
53
25
  AVR_TOOLS_PATH = /usr/bin
@@ -55,9 +27,6 @@ AVRDUDE_CONF = /usr/share/arduino/hardware/tools/avrdude.conf
55
27
 
56
28
  # INC_DIRS = ./vendor/Messenger
57
29
 
58
- #
59
- # include /usr/local/share/Arduino.mk
60
- #
61
30
  # Hopefully these will be self-explanatory but in case they're not:
62
31
  #
63
32
  # ARDUINO_DIR - Where the Arduino software has been unpacked
@@ -70,6 +39,14 @@ AVRDUDE_CONF = /usr/share/arduino/hardware/tools/avrdude.conf
70
39
  # ARDUINO_PORT - The port where the Arduino can be found (only needed
71
40
  # when uploading
72
41
  #
42
+ # ARDUINO WITH OTHER TOOLS
43
+ #
44
+ # If the tools aren't in the Arduino distribution, then you need to
45
+ # specify their location:
46
+ #
47
+ # AVR_TOOLS_PATH = /usr/bin
48
+ # AVRDUDE_CONF = /etc/avrdude/avrdude.conf
49
+
73
50
  # Once this file has been created the typical workflow is just
74
51
  #
75
52
  # $ make upload
@@ -90,16 +67,6 @@ AVRDUDE_CONF = /usr/share/arduino/hardware/tools/avrdude.conf
90
67
  #
91
68
  ########################################################################
92
69
  #
93
- # ARDUINO WITH OTHER TOOLS
94
- #
95
- # If the tools aren't in the Arduino distribution, then you need to
96
- # specify their location:
97
- #
98
- # AVR_TOOLS_PATH = /usr/bin
99
- # AVRDUDE_CONF = /etc/avrdude/avrdude.conf
100
- #
101
- ########################################################################
102
- #
103
70
  # ARDUINO WITH ISP
104
71
  #
105
72
  # You need to specify some details of your ISP programmer and might
@@ -399,3 +366,39 @@ depends: $(DEPS)
399
366
  .PHONY: all clean depends upload raw_upload reset
400
367
 
401
368
  include $(DEP_FILE)
369
+
370
+ #
371
+ # This makefile is from:
372
+ # http://mjo.tc/atelier/2009/02/arduino-cli.html
373
+ #
374
+ # With some help:
375
+ #
376
+ # http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1265576847
377
+ # http://johanneshoff.com/arduino-command-line/Makefile
378
+ #
379
+ # This file is free software; you can redistribute it and/or modify it
380
+ # under the terms of the GNU Lesser General Public License as
381
+ # published by the Free Software Foundation; either version 2.1 of the
382
+ # License, or (at your option) any later version.
383
+ #
384
+ # Adapted from Arduino 0011 Makefile by M J Oldfield
385
+ #
386
+ # Original Arduino adaptation by mellis, eighthave, oli.keller
387
+ #
388
+ # Version 0.1 17.ii.2009 M J Oldfield
389
+ #
390
+ # 0.2 22.ii.2009 M J Oldfield
391
+ # - fixes so that the Makefile actually works!
392
+ # - support for uploading via ISP
393
+ # - orthogonal choices of using the Arduino for
394
+ # tools, libraries and uploading
395
+ #
396
+ # 0.3 21.v.2010 M J Oldfield
397
+ # - added proper license statement
398
+ # - added code from Philip Hands to reset
399
+ # Arduino prior to upload
400
+ #
401
+ # 0.4 25.v.2010 M J Oldfield
402
+ # - tweaked reset target on Philip Hands' advice
403
+ #
404
+ ########################################################################
data/duino/duino.pde CHANGED
@@ -1,17 +1,283 @@
1
1
  /*
2
+ * Arduin
2
3
  *
3
- * SCAFFOLD
4
4
  *
5
+ * /home/nofxx/projects/ardo/control
5
6
  *
6
- * #{Time.now}
7
- */
7
+ *
8
+ */
8
9
 
9
10
  #include <Messenger.h>
10
11
 
11
- void setup() {
12
+ #define sec 1000
13
+ #define min 60000
14
+ #define hour 3600000
15
+ #define day 86400000
16
+
17
+ // Output
18
+ const int rxPin = 0;
19
+ const int txPin = 1;
20
+ const int d2 = 2;
21
+ const int d3 = 3;
22
+ const int d4 = 4;
23
+ const int d5 = 5;
24
+ const int d6 = 6;
25
+ const int d7 = 7;
26
+ const int d8 = 8;
27
+ const int d9 = 9;
28
+ //const int d10 = 10;
29
+ //const int d11 = 11;
30
+ //const int d12 = 12;
31
+ const int infoPin = 13;
32
+
33
+ // Input
34
+ const int i0 = A0;
35
+ const int i1 = A1;
36
+ const int i2 = A2;
37
+ const int i3 = A3;
38
+ const int i4 = A4;
39
+ const int i5 = A5;
40
+ // Digital
41
+ const int d10 = 10;
42
+ const int d11 = 11;
43
+ const int d12 = 12;
44
+
45
+ // Intervals (s)
46
+ unsigned long shoot = 1;
47
+ unsigned long sync = 5 * sec;
48
+ unsigned long time_now, last_shoot, last_sync;
49
+
50
+ int btnState = 0;
51
+ int touchState = 0;
52
+ int motorState = 0;
53
+
54
+ char buffer [50];
55
+
56
+ volatile int rx_state = LOW;
57
+ volatile int tx_state = LOW;
58
+
59
+ Messenger message = Messenger();
60
+
61
+ // Create the callback function
62
+
63
+ unsigned long mintomilli(unsigned long m) {
64
+ return(m * 60000);
65
+ }
66
+
67
+ void btnLed() {
68
+ if(digitalRead(d2) == 1) {
69
+ Serial.println("BUTTON");
70
+ digitalWrite(infoPin, HIGH);
71
+ analogWrite(d3, 250);
72
+ if (motorState != 0) {
73
+ motorState = 0;
74
+ } else {
75
+ motorState = 1;
76
+ }
77
+ } else {
78
+ digitalWrite(infoPin, LOW);
79
+ analogWrite(d3, LOW);
80
+ }
81
+
82
+ }
83
+
84
+ void messageReady() {
85
+ int pin = 2;
86
+ int val = 0;
87
+ // Loop through all the available elements of the message
88
+ while ( message.available() && pin <= infoPin ) {
89
+ val = message.readInt();
90
+ // Set the pin as determined by the message
91
+ analogWrite(pin, val);
92
+ pin = pin + 1;
93
+ }
94
+
95
+ }
96
+
97
+ void setup() {
98
+ // Atmega defaults INPUT
99
+ pinMode(infoPin, OUTPUT);
100
+ pinMode(d2, OUTPUT);
101
+ pinMode(d3, OUTPUT);
102
+ pinMode(d6, OUTPUT);
103
+ pinMode(d10, OUTPUT);
104
+
105
+ // testFalse();
106
+ shoot = mintomilli(shoot);
107
+
108
+ attachInterrupt(0, btnLed, CHANGE);
109
+ Serial.begin(115200);
110
+ //Serial.begin(9600);
111
+ message.attach(messageReady);
112
+ }
113
+
114
+
115
+ void loop() {
116
+
117
+ time_now = millis();
118
+
119
+ // Sync over wire
120
+ if ( abs(time_now - last_sync) >= sync) {
121
+ last_sync = time_now;
122
+ sprintf(buffer, "i0:%d,i1:%d,i2:%d,i3:%d,i4:%d,i5:%d,d11:%d,d12:%d",
123
+ analogRead(i0),
124
+ analogRead(i1),
125
+ analogRead(i2),
126
+ analogRead(i3),
127
+ analogRead(i4),
128
+ analogRead(i5),
129
+ digitalRead(d11),
130
+ digitalRead(d12));
131
+ Serial.println(buffer);
132
+ }
133
+
134
+
135
+ // if (motorState != 0) {
136
+ // analogWrite(d10, (analogRead(i1)/5));
137
+ // } else {
138
+ // analogWrite(d10, 0);
139
+ // }
140
+
141
+ // noInterrupts();
142
+ // interrupts();
143
+
144
+ // if ( abs(time_now - last_shoot) >= shoot) {
145
+ // last_shoot = time_now;
146
+ // // Serial.println("SHOOTING");
147
+ // digitalWrite(d6, HIGH); // turn the d6 on
148
+ // delay(400); // stop the program for some time
149
+ // digitalWrite(d6, LOW); // turn the d6 off
150
+ // }
151
+
152
+ // Terminate message with a linefeed and a carriage return
153
+ // Serial.print(13,BYTE);
154
+ // Serial.print(10,BYTE);
155
+
156
+ //Serial.println(touchState);
157
+ //Serial.print(byte(50));
158
+ // * Serial.print(78, BYTE) gives "N"
159
+ // * Serial.print(78, BIN) gives "1001110"
160
+ // * Serial.print(78, OCT) gives "116"
161
+ // * Serial.print(78, DEC) gives "78"
162
+ // * Serial.print(78, HEX) gives "4E"
163
+ // * Serial.println(1.23456, 0) gives "1"
164
+ // * Serial.println(1.23456, 2) gives "1.23"
165
+ // * Serial.println(1.23456, 4) gives "1.2346"
166
+ // lightVal = buffer;
167
+
168
+ // if (analogRead(i2) > 200) {
169
+ // analogWrite(d3, 0);
170
+ // } else {
171
+ // analogWrite(d3, 250);
172
+ // }
173
+
174
+
175
+ while ( Serial.available() ) message.process(Serial.read());
12
176
 
13
177
  }
14
178
 
15
- void loop() {
179
+ // void pulseJob(pin) {
180
+ // analogWrite(pin, 250);
181
+ // delay(2000);
182
+ // analogWrite(pin, LOW);
183
+ // }
184
+
185
+ // From Doorduino
186
+ // http://github.com/martymcguire/Doorduino/blob/master/Doorduino.pde
187
+ // Log a system message to console
188
+ // void log(char* message)
189
+ // {
190
+ // static char timeString[20];
191
+ // getTime(timeString);
192
+
193
+ // Serial.print("[");
194
+ // Serial.print(timeString);
195
+ // Serial.print("] DOOR: ");
196
+ // Serial.println(message);
197
+
198
+ // }
199
+
200
+ // void readRTC(time& currentTime)
201
+ // {
202
+ // Wire.beginTransmission(DS1307);
203
+ // Wire.send(R_SECS);
204
+ // Wire.endTransmission();
205
+
206
+ // Wire.requestFrom(DS1307, 7);
207
+ // currentTime.second = bcd2Dec(Wire.receive());
208
+ // currentTime.minute = bcd2Dec(Wire.receive());
209
+ // currentTime.hour = bcd2Dec(Wire.receive());
210
+ // currentTime.wkDay = bcd2Dec(Wire.receive());
211
+ // currentTime.day = bcd2Dec(Wire.receive());
212
+ // currentTime.month = bcd2Dec(Wire.receive());
213
+ // currentTime.year = bcd2Dec(Wire.receive());
214
+ // }
215
+
216
+
217
+ // void setRTC(time& newTime)
218
+ // {
219
+ // Wire.beginTransmission(DS1307);
220
+ // Wire.send(dec2Bcd(R_SECS));
221
+ // Wire.send(dec2Bcd(newTime.second));
222
+ // Wire.send(dec2Bcd(newTime.minute));
223
+ // Wire.send(dec2Bcd(newTime.hour));
224
+ // Wire.send(dec2Bcd(newTime.wkDay));
225
+ // Wire.send(dec2Bcd(newTime.day));
226
+ // Wire.send(dec2Bcd(newTime.month));
227
+ // Wire.send(dec2Bcd(newTime.year));
228
+ // Wire.endTransmission();
229
+ // }
230
+
231
+
232
+ // Build a human-readable representation of the current time
233
+ // @string character array to put the time in, must be 20 bytes long
234
+ // void getTime(char* string)
235
+ // {
236
+ // // Grab the latest time from the RTC
237
+ // time currentTime;
238
+ // readRTC(currentTime);
239
+
240
+ // // And build a formatted string to represent it
241
+ // sprintf(string, "20%02d-%02d-%02dT%02d:%02d:%02dZ",
242
+ // currentTime.year, currentTime.month, currentTime.day,
243
+ // currentTime.hour, currentTime.minute, currentTime.second);
244
+ // }
245
+
246
+
247
+ // void setTimeFromSerial()
248
+ // {
249
+ // time newTime;
250
+
251
+ // char temp = 0;
252
+
253
+ // // Wait for full time to be received
254
+ // for (int i = 0; i < 7; i++)
255
+ // {
256
+ // while (Serial.available() == 0) {}
257
+
258
+ // temp = Serial.read();
259
+
260
+ // switch (i) {
261
+ // case 0: newTime.year = temp; break;
262
+ // case 1: newTime.month = temp; break;
263
+ // case 2: newTime.day = temp; break;
264
+ // case 3: newTime.wkDay = temp; break;
265
+ // case 4: newTime.hour = temp; break;
266
+ // case 5: newTime.minute = temp; break;
267
+ // case 6: newTime.second = temp; break;
268
+ // }
269
+ // }
270
+
271
+ // setRTC(newTime);
272
+ // }
273
+
274
+
275
+ byte bcd2Dec(byte bcdVal)
276
+ {
277
+ return bcdVal / 16 * 10 + bcdVal % 16;
278
+ }
16
279
 
280
+ byte dec2Bcd(byte decVal)
281
+ {
282
+ return decVal / 10 * 16 + decVal % 10;
17
283
  }