subduino 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/subduino +18 -5
- data/duino/Makefile +2 -3
- data/duino/duino.pde +97 -66
- data/lib/subduino/ard_io.rb +33 -14
- data/lib/subduino/ard_ps.rb +47 -24
- data/lib/subduino/os.rb +49 -0
- data/lib/subduino/parse/bool.rb +1 -1
- data/lib/subduino/parse/energy.rb +18 -0
- data/lib/subduino/parse/flow.rb +13 -0
- data/lib/subduino/parse/lux.rb +1 -1
- data/lib/subduino/parse/presence.rb +9 -0
- data/lib/subduino/parse/pressure.rb +13 -0
- data/lib/subduino/parse/temp.rb +1 -1
- data/lib/subduino/parse.rb +3 -3
- data/lib/subduino/scaffold/Makefile +72 -73
- data/lib/subduino/scaffold/scaffold.pde +77 -0
- data/lib/subduino/store.rb +1 -1
- data/spec/subduino/parse_spec.rb +1 -1
- data/subduino.gemspec +8 -249
- metadata +8 -249
- data/webapp/Gemfile +0 -8
- data/webapp/Gemfile.lock +0 -14
- data/webapp/Rakefile +0 -49
- data/webapp/Readme.textile +0 -45
- data/webapp/VERSION +0 -1
- data/webapp/config.yml +0 -20
- data/webapp/lib/app.rb +0 -103
- data/webapp/lib/duino.rb +0 -206
- data/webapp/lib/environment.rb +0 -36
- data/webapp/lib/messenger.rb +0 -16
- data/webapp/public/app.css +0 -119
- data/webapp/public/app.js +0 -34
- data/webapp/public/custom.js +0 -187
- data/webapp/public/date_input.css +0 -149
- data/webapp/public/facebox.css +0 -83
- data/webapp/public/facebox.js +0 -319
- data/webapp/public/favicon.ico +0 -0
- data/webapp/public/faye.js +0 -1
- data/webapp/public/icons/alarm-clock-blue.png +0 -0
- data/webapp/public/icons/alarm-clock.png +0 -0
- data/webapp/public/icons/balloon-left.png +0 -0
- data/webapp/public/icons/bandaid.png +0 -0
- data/webapp/public/icons/bell-disable.png +0 -0
- data/webapp/public/icons/bell.png +0 -0
- data/webapp/public/icons/big_icon.png +0 -0
- data/webapp/public/icons/bomb.png +0 -0
- data/webapp/public/icons/bookmark.png +0 -0
- data/webapp/public/icons/box-label.png +0 -0
- data/webapp/public/icons/brightness-control-up.png +0 -0
- data/webapp/public/icons/brightness-control.png +0 -0
- data/webapp/public/icons/brightness-small.png +0 -0
- data/webapp/public/icons/broom.png +0 -0
- data/webapp/public/icons/bug.png +0 -0
- data/webapp/public/icons/calculator.png +0 -0
- data/webapp/public/icons/calendar-day.png +0 -0
- data/webapp/public/icons/camera.png +0 -0
- data/webapp/public/icons/cards-address.png +0 -0
- data/webapp/public/icons/chart.png +0 -0
- data/webapp/public/icons/clock-select.png +0 -0
- data/webapp/public/icons/color.png +0 -0
- data/webapp/public/icons/compass.png +0 -0
- data/webapp/public/icons/control-power-small.png +0 -0
- data/webapp/public/icons/control-power.png +0 -0
- data/webapp/public/icons/control-record-small.png +0 -0
- data/webapp/public/icons/cpus.png +0 -0
- data/webapp/public/icons/credit-card.png +0 -0
- data/webapp/public/icons/cross-small.png +0 -0
- data/webapp/public/icons/current.png +0 -0
- data/webapp/public/icons/dashboard.png +0 -0
- data/webapp/public/icons/database.png +0 -0
- data/webapp/public/icons/databases.png +0 -0
- data/webapp/public/icons/day.png +0 -0
- data/webapp/public/icons/door-big.png +0 -0
- data/webapp/public/icons/door-open-in.png +0 -0
- data/webapp/public/icons/door-open-out.png +0 -0
- data/webapp/public/icons/door-open.png +0 -0
- data/webapp/public/icons/door.png +0 -0
- data/webapp/public/icons/drive-globe.png +0 -0
- data/webapp/public/icons/equalizer.png +0 -0
- data/webapp/public/icons/exclamation-diamond.png +0 -0
- data/webapp/public/icons/exclamation.png +0 -0
- data/webapp/public/icons/eye-disable.png +0 -0
- data/webapp/public/icons/eye.png +0 -0
- data/webapp/public/icons/false.png +0 -0
- data/webapp/public/icons/favicon.png +0 -0
- data/webapp/public/icons/gear-small.png +0 -0
- data/webapp/public/icons/gear.png +0 -0
- data/webapp/public/icons/groups.png +0 -0
- data/webapp/public/icons/heart.png +0 -0
- data/webapp/public/icons/heart_empty.png +0 -0
- data/webapp/public/icons/info.png +0 -0
- data/webapp/public/icons/irrigation.png +0 -0
- data/webapp/public/icons/key.png +0 -0
- data/webapp/public/icons/lamp-big.png +0 -0
- data/webapp/public/icons/lightbulb.png +0 -0
- data/webapp/public/icons/lightbulb_off.png +0 -0
- data/webapp/public/icons/lightning-disable.png +0 -0
- data/webapp/public/icons/lightning-small.png +0 -0
- data/webapp/public/icons/lightning.png +0 -0
- data/webapp/public/icons/lock-unlock.png +0 -0
- data/webapp/public/icons/lock.png +0 -0
- data/webapp/public/icons/locked.png +0 -0
- data/webapp/public/icons/lux.png +0 -0
- data/webapp/public/icons/marker.png +0 -0
- data/webapp/public/icons/media-player-phone.png +0 -0
- data/webapp/public/icons/megaphone.png +0 -0
- data/webapp/public/icons/mem.png +0 -0
- data/webapp/public/icons/microphone.png +0 -0
- data/webapp/public/icons/monitor.png +0 -0
- data/webapp/public/icons/navigation.png +0 -0
- data/webapp/public/icons/night.png +0 -0
- data/webapp/public/icons/noise.png +0 -0
- data/webapp/public/icons/off.png +0 -0
- data/webapp/public/icons/on.png +0 -0
- data/webapp/public/icons/onoff.png +0 -0
- data/webapp/public/icons/pin.png +0 -0
- data/webapp/public/icons/plug--exclamation.png +0 -0
- data/webapp/public/icons/plug-disable.png +0 -0
- data/webapp/public/icons/plug.png +0 -0
- data/webapp/public/icons/rain.png +0 -0
- data/webapp/public/icons/refrigeration.png +0 -0
- data/webapp/public/icons/restart.png +0 -0
- data/webapp/public/icons/ruby.png +0 -0
- data/webapp/public/icons/server.png +0 -0
- data/webapp/public/icons/shield-disable.png +0 -0
- data/webapp/public/icons/shield.png +0 -0
- data/webapp/public/icons/socket--exclamation.png +0 -0
- data/webapp/public/icons/socket-disable.png +0 -0
- data/webapp/public/icons/socket.png +0 -0
- data/webapp/public/icons/start.png +0 -0
- data/webapp/public/icons/stop.png +0 -0
- data/webapp/public/icons/switch--exclamation.png +0 -0
- data/webapp/public/icons/switch-disable.png +0 -0
- data/webapp/public/icons/switch-small.png +0 -0
- data/webapp/public/icons/switch.png +0 -0
- data/webapp/public/icons/target.png +0 -0
- data/webapp/public/icons/television-off.png +0 -0
- data/webapp/public/icons/television.png +0 -0
- data/webapp/public/icons/temp.png +0 -0
- data/webapp/public/icons/terminal.png +0 -0
- data/webapp/public/icons/tick-small.png +0 -0
- data/webapp/public/icons/traffic-light-off.png +0 -0
- data/webapp/public/icons/traffic-light.png +0 -0
- data/webapp/public/icons/traffic.png +0 -0
- data/webapp/public/icons/true.png +0 -0
- data/webapp/public/icons/umbrella.png +0 -0
- data/webapp/public/icons/unlocked.png +0 -0
- data/webapp/public/icons/unmonitor.png +0 -0
- data/webapp/public/icons/unmonitored.png +0 -0
- data/webapp/public/icons/users.png +0 -0
- data/webapp/public/icons/vcard.png +0 -0
- data/webapp/public/icons/wall.png +0 -0
- data/webapp/public/icons/wall_brick.png +0 -0
- data/webapp/public/icons/wall_disable.png +0 -0
- data/webapp/public/icons/wand-disable.png +0 -0
- data/webapp/public/icons/wand.png +0 -0
- data/webapp/public/icons/warn.png +0 -0
- data/webapp/public/icons/weather_clouds.png +0 -0
- data/webapp/public/icons/weather_cloudy.png +0 -0
- data/webapp/public/icons/weather_lightning.png +0 -0
- data/webapp/public/icons/weather_rain.png +0 -0
- data/webapp/public/icons/weather_snow.png +0 -0
- data/webapp/public/icons/weather_sun.png +0 -0
- data/webapp/public/icons/wrench-screwdriver.png +0 -0
- data/webapp/public/icons/wrench.png +0 -0
- data/webapp/public/images/ajax-loader.gif +0 -0
- data/webapp/public/images/b.png +0 -0
- data/webapp/public/images/bendl.gif +0 -0
- data/webapp/public/images/bendr.gif +0 -0
- data/webapp/public/images/bendsb.gif +0 -0
- data/webapp/public/images/bg.jpg +0 -0
- data/webapp/public/images/bhead.gif +0 -0
- data/webapp/public/images/bheadl.gif +0 -0
- data/webapp/public/images/bheadr.gif +0 -0
- data/webapp/public/images/bl.png +0 -0
- data/webapp/public/images/bnd.gif +0 -0
- data/webapp/public/images/br.png +0 -0
- data/webapp/public/images/bread.gif +0 -0
- data/webapp/public/images/btnb.gif +0 -0
- data/webapp/public/images/btnb_.gif +0 -0
- data/webapp/public/images/btnm.gif +0 -0
- data/webapp/public/images/btnm_.gif +0 -0
- data/webapp/public/images/btns.gif +0 -0
- data/webapp/public/images/btns_.gif +0 -0
- data/webapp/public/images/cal.jpg +0 -0
- data/webapp/public/images/close.png +0 -0
- data/webapp/public/images/closelabel.gif +0 -0
- data/webapp/public/images/error.gif +0 -0
- data/webapp/public/images/ft.gif +0 -0
- data/webapp/public/images/hdr.gif +0 -0
- data/webapp/public/images/hdrl.gif +0 -0
- data/webapp/public/images/hdrr.gif +0 -0
- data/webapp/public/images/hld.jpg +0 -0
- data/webapp/public/images/imgb.gif +0 -0
- data/webapp/public/images/imgo.gif +0 -0
- data/webapp/public/images/imgt.gif +0 -0
- data/webapp/public/images/info.gif +0 -0
- data/webapp/public/images/jquery.wysiwyg.gif +0 -0
- data/webapp/public/images/li.gif +0 -0
- data/webapp/public/images/mbg.png +0 -0
- data/webapp/public/images/nsp.gif +0 -0
- data/webapp/public/images/phs.gif +0 -0
- data/webapp/public/images/sdd.jpg +0 -0
- data/webapp/public/images/sdd_.jpg +0 -0
- data/webapp/public/images/sidebar.gif +0 -0
- data/webapp/public/images/sorta.gif +0 -0
- data/webapp/public/images/sortd.gif +0 -0
- data/webapp/public/images/srch.gif +0 -0
- data/webapp/public/images/srch_.gif +0 -0
- data/webapp/public/images/success.gif +0 -0
- data/webapp/public/images/thumb1.jpg +0 -0
- data/webapp/public/images/thumb2.jpg +0 -0
- data/webapp/public/images/thumb3.jpg +0 -0
- data/webapp/public/images/tiny.gif +0 -0
- data/webapp/public/images/tiny_.gif +0 -0
- data/webapp/public/images/tl.png +0 -0
- data/webapp/public/images/tr.png +0 -0
- data/webapp/public/images/upload.gif +0 -0
- data/webapp/public/images/warning.gif +0 -0
- data/webapp/public/iui/backButton.png +0 -0
- data/webapp/public/iui/blueButton.png +0 -0
- data/webapp/public/iui/cancel.png +0 -0
- data/webapp/public/iui/grayButton.png +0 -0
- data/webapp/public/iui/greenButton.png +0 -0
- data/webapp/public/iui/iui-logo-touch-icon.png +0 -0
- data/webapp/public/iui/iui.css +0 -396
- data/webapp/public/iui/iui.js +0 -511
- data/webapp/public/iui/iuix.css +0 -1
- data/webapp/public/iui/iuix.js +0 -1
- data/webapp/public/iui/listArrow.png +0 -0
- data/webapp/public/iui/listArrowSel.png +0 -0
- data/webapp/public/iui/listGroup.png +0 -0
- data/webapp/public/iui/loading.gif +0 -0
- data/webapp/public/iui/pinstripes.png +0 -0
- data/webapp/public/iui/redButton.png +0 -0
- data/webapp/public/iui/selection.png +0 -0
- data/webapp/public/iui/thumb.png +0 -0
- data/webapp/public/iui/toggle.png +0 -0
- data/webapp/public/iui/toggleOn.png +0 -0
- data/webapp/public/iui/toolButton.png +0 -0
- data/webapp/public/iui/toolbar.png +0 -0
- data/webapp/public/iui/whiteButton.png +0 -0
- data/webapp/public/iui/yellowButton.png +0 -0
- data/webapp/public/jquery.img.preload.js +0 -152
- data/webapp/public/jquery.js +0 -154
- data/webapp/public/jquery.sparkline.js +0 -85
- data/webapp/public/jquery.tablesorter.min.js +0 -2
- data/webapp/public/jquery.visualize.js +0 -452
- data/webapp/public/jquery.wysiwyg.css +0 -56
- data/webapp/public/layout.css +0 -33
- data/webapp/public/right.js +0 -9
- data/webapp/public/rt.js +0 -7
- data/webapp/public/sparkline.js +0 -85
- data/webapp/public/style.css +0 -881
- data/webapp/public/visualize.css +0 -32
- data/webapp/spec/duino_spec.rb +0 -8
- data/webapp/spec/spec_helper.rb +0 -10
- data/webapp/views/command.haml +0 -4
- data/webapp/views/icon.haml +0 -6
- data/webapp/views/index.haml +0 -367
- data/webapp/views/layout.haml +0 -88
- data/webapp/views/mobile.haml +0 -21
- data/webapp/views/switch.haml +0 -56
- data/webapp/views/template.haml +0 -676
- data/webapp/views/top.haml +0 -4
- data/webapp/views/watch.haml +0 -26
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/bin/subduino
CHANGED
@@ -3,16 +3,23 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'optparse'
|
5
5
|
require 'subduino'
|
6
|
+
require 'subduino/os'
|
6
7
|
require 'faye'
|
7
8
|
|
9
|
+
Debug = false
|
10
|
+
|
8
11
|
OptionParser.new { |op|
|
12
|
+
op.on('-d', '--debug') { |d| Debug = true }
|
9
13
|
op.on('-e env') { |val| set :environment, val.to_sym }
|
10
14
|
op.on('-s server') { |val| set :server, val }
|
11
15
|
op.on('-p port') { |val| set :port, val.to_i }
|
12
|
-
}.parse!(ARGV
|
16
|
+
}.parse!(ARGV)
|
13
17
|
|
14
18
|
# set :run, true
|
15
19
|
|
20
|
+
if Debug
|
21
|
+
puts "Starting on #{OS}"
|
22
|
+
end
|
16
23
|
|
17
24
|
if ARGV.empty? || ARGV.join =~ /yml/
|
18
25
|
LastRun = {:all => 0}
|
@@ -20,7 +27,7 @@ if ARGV.empty? || ARGV.join =~ /yml/
|
|
20
27
|
puts "Using config file #{f}"
|
21
28
|
AppConfig = YAML.load(File.read(f))["opts"]
|
22
29
|
else
|
23
|
-
AppConfig = { "log_interval" => 30, "bauds" =>
|
30
|
+
AppConfig = { "log_interval" => 30, "bauds" => 115200 }
|
24
31
|
end
|
25
32
|
|
26
33
|
client = Faye::Client.new('http://localhost:8000/faye')
|
@@ -28,9 +35,12 @@ if ARGV.empty? || ARGV.join =~ /yml/
|
|
28
35
|
EM.run do
|
29
36
|
|
30
37
|
Subduino.start do |read|
|
31
|
-
|
38
|
+
# Subduino::ArdIO.write("hi")
|
39
|
+
if Debug
|
40
|
+
# puts "--------------------- #{Time.now}"
|
41
|
+
p read
|
42
|
+
end
|
32
43
|
if LastRun[:all] < (Time.now.to_i - AppConfig["log_interval"])
|
33
|
-
p "Syncing...."
|
34
44
|
LastRun[:all] = Time.now.to_i
|
35
45
|
client.publish('/stats', 'data' => read)
|
36
46
|
Subduino::Store.add_csv_to_store(read, true)
|
@@ -40,6 +50,10 @@ if ARGV.empty? || ARGV.join =~ /yml/
|
|
40
50
|
end
|
41
51
|
|
42
52
|
end
|
53
|
+
elsif ARGV.join =~ /send/
|
54
|
+
txt = ARGV[1..-1].join
|
55
|
+
puts "Writing #{txt}"
|
56
|
+
Subduino::ArdPS.write(txt)
|
43
57
|
else
|
44
58
|
require "subduino/scaffold/generator"
|
45
59
|
dir = ARGV[0]
|
@@ -47,4 +61,3 @@ else
|
|
47
61
|
`mkdir #{dir}` unless File.exists?(dir)
|
48
62
|
Subduino::Generator.copy_files(dir)
|
49
63
|
end
|
50
|
-
|
data/duino/Makefile
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
#
|
16
16
|
TARGET = duino
|
17
17
|
ARDUINO_DIR = /usr/share/arduino
|
18
|
-
ARDUINO_LIBS =
|
18
|
+
# ARDUINO_LIBS = ExtraLib
|
19
19
|
|
20
20
|
MCU = atmega328p
|
21
21
|
F_CPU = 16000000
|
@@ -25,7 +25,6 @@ ARDUINO_PORT = /dev/ttyUSB*
|
|
25
25
|
AVR_TOOLS_PATH = /usr/bin
|
26
26
|
AVRDUDE_CONF = /usr/share/arduino/hardware/tools/avrdude.conf
|
27
27
|
|
28
|
-
# INC_DIRS = ./vendor/Messenger
|
29
28
|
|
30
29
|
# Hopefully these will be self-explanatory but in case they're not:
|
31
30
|
#
|
@@ -136,7 +135,7 @@ ifeq ($(strip $(NO_CORE)),)
|
|
136
135
|
ifdef ARDUINO_CORE_PATH
|
137
136
|
CORE_C_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.c)
|
138
137
|
CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp)
|
139
|
-
EXTRA_CPP_SRCS = $(wildcard $(ARDUINO_LIB_PATH)/
|
138
|
+
# EXTRA_CPP_SRCS = $(wildcard $(ARDUINO_LIB_PATH)/ExtraLib/*.cpp)
|
140
139
|
CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o) $(EXTRA_CPP_SRCS:.cpp=.o)
|
141
140
|
CORE_OBJS = $(patsubst $(ARDUINO_CORE_PATH)/%, $(OBJDIR)/%,$(CORE_OBJ_FILES))
|
142
141
|
endif
|
data/duino/duino.pde
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Arduin
|
2
|
+
* Arduin v2
|
3
3
|
*
|
4
4
|
*
|
5
5
|
* /home/nofxx/projects/ardo/control
|
@@ -7,12 +7,11 @@
|
|
7
7
|
*
|
8
8
|
*/
|
9
9
|
|
10
|
-
#
|
11
|
-
|
12
|
-
#define
|
13
|
-
#define
|
14
|
-
#define
|
15
|
-
#define day 86400000
|
10
|
+
#define SEC 1000
|
11
|
+
#define MIN 60000
|
12
|
+
#define HOUR 3600000
|
13
|
+
#define DAY 86400000
|
14
|
+
#define MAX 50
|
16
15
|
|
17
16
|
// Output
|
18
17
|
const int rxPin = 0;
|
@@ -43,55 +42,87 @@ const int d11 = 11;
|
|
43
42
|
const int d12 = 12;
|
44
43
|
|
45
44
|
// Intervals (s)
|
46
|
-
unsigned long
|
47
|
-
unsigned long
|
48
|
-
unsigned long time_now, last_shoot, last_sync;
|
45
|
+
unsigned long sync = 5 * SEC;
|
46
|
+
unsigned long time_now, last_sync;
|
49
47
|
|
48
|
+
int i = 0;
|
50
49
|
int btnState = 0;
|
51
50
|
int touchState = 0;
|
52
51
|
int motorState = 0;
|
53
52
|
|
54
|
-
char
|
53
|
+
char outbuf[MAX];
|
54
|
+
char cmdbuf[MAX];
|
55
55
|
|
56
56
|
volatile int rx_state = LOW;
|
57
57
|
volatile int tx_state = LOW;
|
58
58
|
|
59
|
-
Messenger message = Messenger();
|
60
|
-
|
61
|
-
// Create the callback function
|
62
59
|
|
63
60
|
unsigned long mintomilli(unsigned long m) {
|
64
61
|
return(m * 60000);
|
65
62
|
}
|
66
63
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
motorState = 0;
|
74
|
-
} else {
|
75
|
-
motorState = 1;
|
76
|
-
}
|
77
|
-
} else {
|
78
|
-
digitalWrite(infoPin, LOW);
|
79
|
-
analogWrite(d3, LOW);
|
80
|
-
}
|
64
|
+
int ctoi( int c )
|
65
|
+
{
|
66
|
+
return c - '0';
|
67
|
+
}
|
68
|
+
|
69
|
+
/*
|
81
70
|
|
71
|
+
Read Sensors Data
|
72
|
+
|
73
|
+
*/
|
74
|
+
void read_sensors() {
|
75
|
+
sprintf(outbuf, "i0:%d,i1:%d,i2:%d,i3:%d,i4:%d,i5:%d,d11:%d,d12:%d",
|
76
|
+
analogRead(i0),
|
77
|
+
analogRead(i1),
|
78
|
+
analogRead(i2),
|
79
|
+
analogRead(i3),
|
80
|
+
analogRead(i4),
|
81
|
+
analogRead(i5),
|
82
|
+
digitalRead(d11),
|
83
|
+
digitalRead(d12));
|
84
|
+
|
85
|
+
Serial.println(outbuf);
|
82
86
|
}
|
83
87
|
|
84
|
-
void
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|
88
|
+
void switch_pin(int pin) {
|
89
|
+
analogWrite(pin, digitalRead(pin) == 0 ? 999 : 0);
|
90
|
+
}
|
91
|
+
|
92
|
+
void pulse_pin(int pin) {
|
93
|
+
analogWrite(pin, HIGH);
|
94
|
+
delay(500);
|
95
|
+
analogWrite(pin, LOW);
|
96
|
+
}
|
94
97
|
|
98
|
+
/*
|
99
|
+
|
100
|
+
Command Protocol -> NNvvv
|
101
|
+
2 bytes pin number NN
|
102
|
+
3 bytes value vvv
|
103
|
+
Split commands with ','
|
104
|
+
|
105
|
+
13500,130,13999
|
106
|
+
|
107
|
+
Pin 13 -> 500 -> 000 -> 999
|
108
|
+
|
109
|
+
*/
|
110
|
+
void read_commands() {
|
111
|
+
char c;
|
112
|
+
while( Serial.available() && c != '\n' ) { // buffer up a line
|
113
|
+
c = Serial.read();
|
114
|
+
if (c == '\n' || c == ',') {
|
115
|
+
int pin; int val;
|
116
|
+
pin = (ctoi(cmdbuf[0])*10) + ctoi(cmdbuf[1]);
|
117
|
+
val = (ctoi(cmdbuf[2])*100) + (ctoi(cmdbuf[3])*10) + ctoi(cmdbuf[4]);
|
118
|
+
analogWrite(pin, val);
|
119
|
+
i = 0;
|
120
|
+
} else if (c == 'x') {
|
121
|
+
read_sensors();
|
122
|
+
} else {
|
123
|
+
cmdbuf[i++] = c;
|
124
|
+
}
|
125
|
+
}
|
95
126
|
}
|
96
127
|
|
97
128
|
void setup() {
|
@@ -99,39 +130,50 @@ void setup() {
|
|
99
130
|
pinMode(infoPin, OUTPUT);
|
100
131
|
pinMode(d2, OUTPUT);
|
101
132
|
pinMode(d3, OUTPUT);
|
133
|
+
pinMode(d4, OUTPUT);
|
134
|
+
pinMode(d5, OUTPUT);
|
102
135
|
pinMode(d6, OUTPUT);
|
136
|
+
pinMode(d7, OUTPUT);
|
103
137
|
pinMode(d10, OUTPUT);
|
104
138
|
|
105
|
-
//
|
106
|
-
shoot = mintomilli(shoot);
|
107
|
-
|
108
|
-
attachInterrupt(0, btnLed, CHANGE);
|
139
|
+
// attachInterrupt(0, btnLed, CHANGE);
|
109
140
|
Serial.begin(115200);
|
110
|
-
//Serial.begin(9600);
|
111
|
-
message.attach(messageReady);
|
112
141
|
}
|
113
142
|
|
114
143
|
|
115
144
|
void loop() {
|
116
|
-
|
117
145
|
time_now = millis();
|
118
146
|
|
147
|
+
read_commands();
|
148
|
+
|
119
149
|
// Sync over wire
|
120
150
|
if ( abs(time_now - last_sync) >= sync) {
|
121
151
|
last_sync = time_now;
|
122
|
-
|
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);
|
152
|
+
read_sensors();
|
132
153
|
}
|
133
154
|
|
134
155
|
|
156
|
+
}
|
157
|
+
|
158
|
+
|
159
|
+
// void btnLed() {
|
160
|
+
// if(digitalRead(d2) == 1) {
|
161
|
+
// Serial.println("BUTTON");
|
162
|
+
// digitalWrite(infoPin, HIGH);
|
163
|
+
// analogWrite(d3, 250);
|
164
|
+
// if (motorState != 0) {
|
165
|
+
// motorState = 0;
|
166
|
+
// } else {
|
167
|
+
// motorState = 1;
|
168
|
+
// }
|
169
|
+
// } else {
|
170
|
+
// digitalWrite(infoPin, LOW);
|
171
|
+
// analogWrite(d3, LOW);
|
172
|
+
// }
|
173
|
+
|
174
|
+
// }
|
175
|
+
|
176
|
+
|
135
177
|
// if (motorState != 0) {
|
136
178
|
// analogWrite(d10, (analogRead(i1)/5));
|
137
179
|
// } else {
|
@@ -141,14 +183,6 @@ void loop() {
|
|
141
183
|
// noInterrupts();
|
142
184
|
// interrupts();
|
143
185
|
|
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
186
|
// Terminate message with a linefeed and a carriage return
|
153
187
|
// Serial.print(13,BYTE);
|
154
188
|
// Serial.print(10,BYTE);
|
@@ -172,9 +206,6 @@ void loop() {
|
|
172
206
|
// }
|
173
207
|
|
174
208
|
|
175
|
-
while ( Serial.available() ) message.process(Serial.read());
|
176
|
-
|
177
|
-
}
|
178
209
|
|
179
210
|
// void pulseJob(pin) {
|
180
211
|
// analogWrite(pin, 250);
|
data/lib/subduino/ard_io.rb
CHANGED
@@ -3,39 +3,46 @@ module Subduino
|
|
3
3
|
class ArdIO
|
4
4
|
class << self
|
5
5
|
|
6
|
+
#
|
7
|
+
# Serial Port
|
8
|
+
#
|
9
|
+
# Direct access to the SerialPort instance.
|
10
|
+
#
|
6
11
|
def sp
|
7
12
|
@sp ||= SerialPort.new(Arduino.find_usb, BAUDS) #, DATA_BITS, DATA_STOP, parity)
|
8
13
|
# @sp.read_timeout = 10;# @sp.write_timeout = 10
|
9
14
|
end
|
10
15
|
|
16
|
+
#
|
17
|
+
# Read I/O
|
18
|
+
#
|
19
|
+
# Starts a thread that loops fetching serial bytes.
|
20
|
+
# It'll buffer it up until a \n or \r char are found.
|
21
|
+
# Feed it with a block to read the text.
|
22
|
+
#
|
11
23
|
def read(&proc)
|
12
24
|
Log.info "[USB] Starting USB Connect..." + sp.get_modem_params.map { |k,v| "#{k}: #{v}" }.join(" ")
|
13
25
|
Log.info "[USB] Read Timeout #{sp.read_timeout}" # {sp.write_timeout}"
|
14
26
|
|
15
|
-
#
|
16
|
-
# Read I/O
|
17
|
-
#
|
18
27
|
@iothread ||= Thread.new do
|
19
28
|
Thread.current.abort_on_exception = false
|
20
29
|
icache = []
|
21
|
-
|
22
30
|
loop do
|
23
31
|
begin
|
24
32
|
while char = sp.getc
|
25
|
-
if char
|
33
|
+
if !char.valid_encoding?
|
34
|
+
puts "Bad char #{char}"
|
35
|
+
elsif char !~ /\n|\r/
|
26
36
|
icache << char
|
27
37
|
else
|
28
38
|
data = icache.join(""); icache = []
|
29
|
-
|
39
|
+
unless data.empty?
|
40
|
+
Log.info "[IO RX] #{data}"
|
30
41
|
proc.call(data)
|
31
|
-
Log.info "[SENSOR] #{data}"
|
32
|
-
else
|
33
|
-
proc.call(data) unless data.empty?
|
34
|
-
# Log.info "[INPUT] Done."
|
35
42
|
end
|
36
43
|
end
|
44
|
+
# sleep 1
|
37
45
|
end
|
38
|
-
sleep 1
|
39
46
|
rescue => e
|
40
47
|
Log.error "[USB] Error #{e}"
|
41
48
|
Log.error e.backtrace.join("\n")
|
@@ -44,13 +51,25 @@ module Subduino
|
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
54
|
+
#
|
55
|
+
# Write I/O
|
56
|
+
#
|
57
|
+
# Prints bytes to the serial port.
|
58
|
+
# It'll use subduino convention of \n to end the message.
|
59
|
+
# Use #sp to write directly to the port. `ArdIO.sp.puts ('hi')`
|
60
|
+
#
|
47
61
|
def write(msg)
|
48
62
|
Log.info "[IO TX] #{msg}"
|
49
|
-
txt = msg.gsub("\
|
50
|
-
txt += "\
|
51
|
-
|
63
|
+
txt = msg.gsub("\r", "\n")
|
64
|
+
txt += "\n" unless txt =~ /^\\n/
|
65
|
+
puts "=> Sending #{txt.inspect}" if Debug
|
66
|
+
sp.puts(msg)
|
52
67
|
end
|
53
68
|
|
69
|
+
|
70
|
+
#
|
71
|
+
# Finish Him!
|
72
|
+
#
|
54
73
|
def stop!
|
55
74
|
sp.close
|
56
75
|
end
|
data/lib/subduino/ard_ps.rb
CHANGED
@@ -1,38 +1,61 @@
|
|
1
1
|
module Subduino
|
2
|
+
|
2
3
|
class ArdPS
|
4
|
+
class << self
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
#
|
7
|
+
# Redis PubSub
|
8
|
+
#
|
9
|
+
# Direct access to the Redis instance.
|
10
|
+
#
|
11
|
+
def redis
|
12
|
+
@redis ||= Redis.new(:timeout => 0) rescue false
|
13
|
+
end
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
#
|
16
|
+
# Read PubSub
|
17
|
+
#
|
18
|
+
# Join 'subduino' channel and send messages to I/O
|
19
|
+
#
|
20
|
+
def read
|
21
|
+
return Log.warn "[PubSub] Not started..." unless redis
|
22
|
+
Thread.new do
|
23
|
+
begin
|
24
|
+
redis.subscribe('subduino') do |on|
|
25
|
+
on.subscribe {|klass, num_subs| Log.info "[PubSub] Subscribed to #{klass} (#{num_subs} subscriptions)" }
|
26
|
+
on.message do |klass, msg|
|
27
|
+
Log.info "[PubSub] #{klass} - #{msg}"
|
28
|
+
ArdIO.write msg
|
29
|
+
# @redis.unsubscribe if msg == 'exit'
|
30
|
+
end
|
31
|
+
on.unsubscribe {|klass, num_subs| Log.info "[PubSub] Unsubscribed to #{klass} (#{num_subs} subscriptions)" }
|
18
32
|
end
|
19
|
-
|
33
|
+
rescue => e
|
34
|
+
Log.error "[PubSub] Error #{e}"
|
35
|
+
Log.error e.backtrace.join("\n")
|
20
36
|
end
|
21
|
-
|
22
|
-
Log.error "[PubSub] Error #{e}"
|
23
|
-
Log.error e.backtrace.join("\n")
|
37
|
+
|
24
38
|
end
|
39
|
+
end
|
25
40
|
|
41
|
+
#
|
42
|
+
# Write PubSub
|
43
|
+
#
|
44
|
+
# Write a message to the 'subduino' PubSub channel.
|
45
|
+
#
|
46
|
+
def write(msg)
|
47
|
+
redis.publish('subduino', msg)
|
26
48
|
end
|
27
|
-
end
|
28
49
|
|
29
|
-
def self.write(msg)
|
30
|
-
redis.publish('subdout', msg)
|
31
|
-
end
|
32
50
|
|
33
|
-
|
34
|
-
|
35
|
-
|
51
|
+
#
|
52
|
+
# Fatality
|
53
|
+
#
|
54
|
+
def stop!
|
55
|
+
redis.disconnect if redis
|
56
|
+
end
|
36
57
|
|
58
|
+
end
|
37
59
|
end
|
60
|
+
|
38
61
|
end
|
data/lib/subduino/os.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# From
|
2
|
+
# http://rbjl.net/
|
3
|
+
# Ruby Zucker
|
4
|
+
require 'rbconfig'; RbConfig::CONFIG['host_os']
|
5
|
+
|
6
|
+
module OS
|
7
|
+
class << self
|
8
|
+
def is?(what)
|
9
|
+
what === RbConfig::CONFIG['host_os']
|
10
|
+
end
|
11
|
+
alias is is?
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
RbConfig::CONFIG['host_os']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module_function
|
19
|
+
|
20
|
+
def linux?
|
21
|
+
OS.is? /linux|cygwin/
|
22
|
+
end
|
23
|
+
|
24
|
+
def mac?
|
25
|
+
OS.is? /mac|darwin/
|
26
|
+
end
|
27
|
+
|
28
|
+
def bsd?
|
29
|
+
OS.is? /bsd/
|
30
|
+
end
|
31
|
+
|
32
|
+
def windows?
|
33
|
+
OS.is? /mswin|win|mingw/
|
34
|
+
end
|
35
|
+
|
36
|
+
def solaris?
|
37
|
+
OS.is? /solaris|sunos/
|
38
|
+
end
|
39
|
+
|
40
|
+
def posix?
|
41
|
+
linux? or mac? or bsd? or solaris? or Process.respond_to?(:fork)
|
42
|
+
end
|
43
|
+
|
44
|
+
#def symbian?
|
45
|
+
#TODO who knows what symbian returns?
|
46
|
+
#end
|
47
|
+
|
48
|
+
# ...
|
49
|
+
end
|
data/lib/subduino/parse/bool.rb
CHANGED
data/lib/subduino/parse/lux.rb
CHANGED
data/lib/subduino/parse/temp.rb
CHANGED
data/lib/subduino/parse.rb
CHANGED
@@ -6,7 +6,7 @@ module Subduino
|
|
6
6
|
const_get(klass).new(v, name, id)
|
7
7
|
end
|
8
8
|
|
9
|
-
class
|
9
|
+
class Digital
|
10
10
|
def initialize(v,n=nil,id=nil)
|
11
11
|
@v = v.to_i
|
12
12
|
@id = id
|
@@ -31,7 +31,7 @@ module Subduino
|
|
31
31
|
|
32
32
|
end
|
33
33
|
|
34
|
-
class
|
34
|
+
class Analogic < Digital
|
35
35
|
def digital?; false; end
|
36
36
|
def parse; @v; end
|
37
37
|
def ratio
|
@@ -40,7 +40,7 @@ module Subduino
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
class Knob <
|
43
|
+
class Knob < Analogic
|
44
44
|
end
|
45
45
|
|
46
46
|
|