x10-cm17a 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +195 -189
- data/ext/cm17a_api/cm17a_api.c +28 -12
- data/lib/x10/cm17a.rb +0 -1
- data/lib/x10/cm17a_device.rb +18 -99
- data/lib/x10/cm17a_remote.rb +25 -0
- data/test/test_cm17a_controller.rb +1 -0
- data/test/test_cm17a_device.rb +12 -90
- metadata +3 -2
data/Rakefile
CHANGED
@@ -1,189 +1,195 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
|
3
|
-
require 'rake/clean'
|
4
|
-
require 'rake/testtask'
|
5
|
-
require 'rake/rdoctask'
|
6
|
-
require 'rbconfig'
|
7
|
-
|
8
|
-
begin
|
9
|
-
require 'rubygems'
|
10
|
-
require 'rake/gempackagetask'
|
11
|
-
rescue Exception
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
|
15
|
-
ARCH = Config::CONFIG['arch']
|
16
|
-
SO_FILE = "lib/#{ARCH}/cm17a_api.so"
|
17
|
-
|
18
|
-
MAKE = (ARCH =~ /win32/) ? 'nmake' : 'make'
|
19
|
-
|
20
|
-
CLOBBER.include(
|
21
|
-
SO_FILE,
|
22
|
-
'ext/cm17a_api/*.o',
|
23
|
-
'ext/cm17a_api/*.obj',
|
24
|
-
'ext/cm17a_api/*.def',
|
25
|
-
'ext/cm17a_api/*.exp',
|
26
|
-
'ext/cm17a_api/*.lib',
|
27
|
-
'ext/cm17a_api/*.pdb',
|
28
|
-
'ext/cm17a_api/*.so',
|
29
|
-
'ext/cm17a_api/Makefile',
|
30
|
-
'ext/cm17a_api/MANIFEST',
|
31
|
-
'lib/*-*',
|
32
|
-
'**/*.log'
|
33
|
-
)
|
34
|
-
|
35
|
-
desc "Default task (run tests)"
|
36
|
-
task :default => :test
|
37
|
-
|
38
|
-
desc "Run the unit tests"
|
39
|
-
|
40
|
-
test_files = FileList['test/test_*.rb']
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
rdoc.rdoc_files.
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
'
|
116
|
-
'
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
s.
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
#
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'rbconfig'
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'rubygems'
|
10
|
+
require 'rake/gempackagetask'
|
11
|
+
rescue Exception
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
|
15
|
+
ARCH = Config::CONFIG['arch']
|
16
|
+
SO_FILE = "lib/#{ARCH}/cm17a_api.so"
|
17
|
+
|
18
|
+
MAKE = (ARCH =~ /win32/) ? 'nmake' : 'make'
|
19
|
+
|
20
|
+
CLOBBER.include(
|
21
|
+
SO_FILE,
|
22
|
+
'ext/cm17a_api/*.o',
|
23
|
+
'ext/cm17a_api/*.obj',
|
24
|
+
'ext/cm17a_api/*.def',
|
25
|
+
'ext/cm17a_api/*.exp',
|
26
|
+
'ext/cm17a_api/*.lib',
|
27
|
+
'ext/cm17a_api/*.pdb',
|
28
|
+
'ext/cm17a_api/*.so',
|
29
|
+
'ext/cm17a_api/Makefile',
|
30
|
+
'ext/cm17a_api/MANIFEST',
|
31
|
+
'lib/*-*',
|
32
|
+
'**/*.log'
|
33
|
+
)
|
34
|
+
|
35
|
+
desc "Default task (run tests)"
|
36
|
+
task :default => :test
|
37
|
+
|
38
|
+
desc "Run the unit tests"
|
39
|
+
Rake::TestTask.new do |t|
|
40
|
+
t.test_files = FileList['test/test_*.rb']
|
41
|
+
t.libs << "lib/#{ARCH}"
|
42
|
+
end
|
43
|
+
task :test => [SO_FILE]
|
44
|
+
|
45
|
+
task :xtest => [SO_FILE] do
|
46
|
+
test_files = FileList['test/test_*.rb']
|
47
|
+
ruby "-Ilib", "-Ilib/#{ARCH}", '-e0', *test_files.collect { |fn| "-r#{fn}" }
|
48
|
+
end
|
49
|
+
|
50
|
+
task :compile => [SO_FILE]
|
51
|
+
|
52
|
+
directory File.dirname(SO_FILE)
|
53
|
+
|
54
|
+
file SO_FILE => ["ext/cm17a_api/cm17a_api.so", File.dirname(SO_FILE)] do |t|
|
55
|
+
cp t.prerequisites.first, SO_FILE
|
56
|
+
end
|
57
|
+
|
58
|
+
file "ext/cm17a_api/Makefile" => ["ext/cm17a_api/extconf.rb"] do
|
59
|
+
Dir.chdir("ext/cm17a_api") do ruby "extconf.rb" end
|
60
|
+
end
|
61
|
+
|
62
|
+
CM17A_FILES = FileList[
|
63
|
+
'ext/cm17a_api/*.c',
|
64
|
+
'ext/cm17a_api/*.h',
|
65
|
+
'ext/cm17a_api/extconf.rb',
|
66
|
+
'ext/cm17a_api/Makefile',
|
67
|
+
'ext/cm17a_api/MANIFEST',
|
68
|
+
]
|
69
|
+
|
70
|
+
file "ext/cm17a_api/cm17a_api.so" => CM17A_FILES do
|
71
|
+
Dir.chdir("ext/cm17a_api") do
|
72
|
+
sh MAKE
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# RDoc Documentation -------------------------------------------------
|
77
|
+
|
78
|
+
# Choose template, prefer the jamis template if it is available
|
79
|
+
|
80
|
+
def choose_rdoc_template
|
81
|
+
libdir = Config::CONFIG['rubylibdir']
|
82
|
+
templates = Dir[File.join(libdir, 'rdoc/**/jamis.rb')]
|
83
|
+
templates.empty? ? 'html': 'jamis'
|
84
|
+
end
|
85
|
+
|
86
|
+
rd = Rake::RDocTask.new("rdoc") { |rdoc|
|
87
|
+
rdoc.rdoc_dir = 'html'
|
88
|
+
rdoc.template = choose_rdoc_template
|
89
|
+
rdoc.title = "Ruby X10 Software"
|
90
|
+
rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
|
91
|
+
rdoc.rdoc_files.include(
|
92
|
+
'lib/**/*.rb',
|
93
|
+
'doc/*.rdoc',
|
94
|
+
'ext/**/cm17a_api.c',
|
95
|
+
'README',
|
96
|
+
'MIT-LICENSE')
|
97
|
+
rdoc.rdoc_files.exclude('lib/**/other.rb', 'lib/**/bottlerocket.rb')
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
# Packaging Tasks ----------------------------------------------------
|
102
|
+
|
103
|
+
file "ext/cm17a_api/MANIFEST" do |t|
|
104
|
+
open(t.name, "w") do |f|
|
105
|
+
f.puts Dir["ext/cm17a_api/*"].select { |fn|
|
106
|
+
fn =~ /\.(h|c|rb)$/
|
107
|
+
}.collect { |fn|
|
108
|
+
File.basename(fn)
|
109
|
+
}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
PKG_VERSION = '1.0.0'
|
114
|
+
PKG_FILES = FileList[
|
115
|
+
'Rakefile',
|
116
|
+
'setup.rb',
|
117
|
+
'test/*.rb',
|
118
|
+
'lib/**/*.rb',
|
119
|
+
'ext/cm17a_api/MANIFEST',
|
120
|
+
'ext/cm17a_api/*.h',
|
121
|
+
'ext/cm17a_api/*.c',
|
122
|
+
'ext/cm17a_api/*.rb',
|
123
|
+
]
|
124
|
+
|
125
|
+
if ! defined?(Gem)
|
126
|
+
puts "Package Target requires RubyGEMs"
|
127
|
+
else
|
128
|
+
spec = Gem::Specification.new do |s|
|
129
|
+
|
130
|
+
#### Basic information.
|
131
|
+
|
132
|
+
s.name = 'x10-cm17a'
|
133
|
+
s.version = PKG_VERSION
|
134
|
+
s.summary = "Ruby based X10 CM17A Firecracker Controller"
|
135
|
+
s.description = <<-EOF
|
136
|
+
EOF
|
137
|
+
|
138
|
+
s.files = PKG_FILES.to_a
|
139
|
+
|
140
|
+
#### C code extensions.
|
141
|
+
|
142
|
+
s.extensions << "ext/cm17a_api/extconf.rb"
|
143
|
+
|
144
|
+
#### Load-time details: library and application (you will need one or both).
|
145
|
+
|
146
|
+
s.require_path = 'lib' # Use these for libraries.
|
147
|
+
|
148
|
+
#### Documentation and testing.
|
149
|
+
|
150
|
+
s.has_rdoc = true
|
151
|
+
# s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
|
152
|
+
# s.rdoc_options <<
|
153
|
+
# '--title' << 'Rake -- Ruby Make' <<
|
154
|
+
# '--main' << 'README' <<
|
155
|
+
# '--line-numbers'
|
156
|
+
|
157
|
+
#### Author and project details.
|
158
|
+
|
159
|
+
s.author = "Jim Weirich"
|
160
|
+
s.email = "jim@weirichhouse.org"
|
161
|
+
# s.homepage = "http://rake.rubyforge.org"
|
162
|
+
end
|
163
|
+
|
164
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
165
|
+
pkg.need_zip = true
|
166
|
+
pkg.need_tar = true
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
# Publishing Tasks ---------------------------------------------------
|
172
|
+
|
173
|
+
|
174
|
+
task :publish_on_osb => ["pkg/cm17a-#{PKG_VERSION}.tgz", "pkg/cm17a-#{PKG_VERSION}.gem"] do |t|
|
175
|
+
sh %{ssh umlcoop mkdir -p "htdocs/software/cm17a"}
|
176
|
+
sh %{scp -rq #{t.prerequisites.join(' ')} umlcoop:htdocs/software/cm17a}
|
177
|
+
end
|
178
|
+
|
179
|
+
# Optional publish task for Rake
|
180
|
+
|
181
|
+
require 'rake/contrib/sshpublisher'
|
182
|
+
require 'rake/contrib/rubyforgepublisher'
|
183
|
+
|
184
|
+
publisher = Rake::CompositePublisher.new
|
185
|
+
publisher.add Rake::RubyForgePublisher.new('x10-cm17a', 'jimweirich')
|
186
|
+
publisher.add Rake::SshFilePublisher.new(
|
187
|
+
'umlcoop',
|
188
|
+
'htdocs/software/x10-cm17a',
|
189
|
+
'.',
|
190
|
+
'x10-cm17a.blurb')
|
191
|
+
|
192
|
+
desc "Publish the Documentation to RubyForge."
|
193
|
+
task :publish => [:rdoc] do
|
194
|
+
publisher.upload
|
195
|
+
end
|
data/ext/cm17a_api/cm17a_api.c
CHANGED
@@ -32,6 +32,10 @@ static VALUE mX10;
|
|
32
32
|
static VALUE mCm17a;
|
33
33
|
static VALUE cCm17aController;
|
34
34
|
static VALUE eX10Error;
|
35
|
+
static VALUE symON;
|
36
|
+
static VALUE symOFF;
|
37
|
+
static VALUE symDIM;
|
38
|
+
static VALUE symBRIGHTEN;
|
35
39
|
|
36
40
|
/*
|
37
41
|
* call-seq:
|
@@ -62,13 +66,13 @@ static VALUE cm17a_init(int argc, VALUE *argv, VALUE self)
|
|
62
66
|
* address is given by the +house+ code (0-15) and the +unit+ code
|
63
67
|
* (0-15). The command must be one of the following constants:
|
64
68
|
*
|
65
|
-
* * <tt
|
66
|
-
* * <tt
|
67
|
-
* * <tt
|
68
|
-
* * <tt
|
69
|
+
* * <tt>:on</tt> -- Turn the device on.
|
70
|
+
* * <tt>:off</tt> -- Turn the device off.
|
71
|
+
* * <tt>:dim</tt> -- Dim the device by +steps+ steps.
|
72
|
+
* * <tt>:brighten</tt> -- Brighten the device by +steps+ steps.
|
69
73
|
*
|
70
|
-
* Note that the unit code is ignored for the <tt
|
71
|
-
* <tt
|
74
|
+
* Note that the unit code is ignored for the <tt>:brighten</tt> and
|
75
|
+
* <tt>:dim</tt> commands. The bright/dim commands will effect the
|
72
76
|
* last addressed unit.
|
73
77
|
*/
|
74
78
|
static VALUE cm17a_ruby_command(
|
@@ -80,8 +84,20 @@ static VALUE cm17a_ruby_command(
|
|
80
84
|
{
|
81
85
|
int house = NUM2INT(rhouse);
|
82
86
|
int device = NUM2INT(rdevice);
|
83
|
-
int command = NUM2INT(rcommand);
|
84
87
|
int steps = NUM2INT(rsteps);
|
88
|
+
int command;
|
89
|
+
|
90
|
+
if (rcommand == symON)
|
91
|
+
command = CM17A_ON;
|
92
|
+
else if (rcommand == symOFF)
|
93
|
+
command = CM17A_OFF;
|
94
|
+
else if (rcommand == symDIM)
|
95
|
+
command = CM17A_DIM;
|
96
|
+
else if (rcommand == symBRIGHTEN)
|
97
|
+
command = CM17A_BRIGHTEN;
|
98
|
+
else
|
99
|
+
command = NUM2INT(rcommand);
|
100
|
+
|
85
101
|
cm17a_command(fd, house, device, command, steps);
|
86
102
|
return Qnil;
|
87
103
|
}
|
@@ -103,12 +119,12 @@ void Init_cm17a_api()
|
|
103
119
|
|
104
120
|
eX10Error = rb_eval_string("X10::X10Error");
|
105
121
|
|
122
|
+
symON = rb_eval_string(":on");
|
123
|
+
symOFF = rb_eval_string(":off");
|
124
|
+
symDIM = rb_eval_string(":dim");
|
125
|
+
symBRIGHTEN = rb_eval_string(":brighton");
|
126
|
+
|
106
127
|
rb_define_method(cCm17aController, "initialize", cm17a_init, -1);
|
107
128
|
rb_define_method(cCm17aController, "close", cm17a_close, 0);
|
108
129
|
rb_define_method(cCm17aController, "command", cm17a_ruby_command, 4);
|
109
|
-
|
110
|
-
rb_define_const(mCm17a, "ON", INT2NUM(CM17A_ON));
|
111
|
-
rb_define_const(mCm17a, "OFF", INT2NUM(CM17A_OFF));
|
112
|
-
rb_define_const(mCm17a, "BRIGHTEN", INT2NUM(CM17A_BRIGHTEN));
|
113
|
-
rb_define_const(mCm17a, "DIM", INT2NUM(CM17A_DIM));
|
114
130
|
}
|
data/lib/x10/cm17a.rb
CHANGED
data/lib/x10/cm17a_device.rb
CHANGED
@@ -32,111 +32,30 @@ module X10
|
|
32
32
|
|
33
33
|
# Turn the device on.
|
34
34
|
def on
|
35
|
-
@controller.command(@house, @unit,
|
36
|
-
@level = 1.0 if @on == false
|
37
|
-
@on = true
|
35
|
+
@controller.command(@house, @unit, :on, 0)
|
38
36
|
end
|
39
37
|
|
40
38
|
# Turn the device off.
|
41
39
|
def off
|
42
|
-
@controller.command(@house, @unit,
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
step = (steps > 6 ? 6 : steps)
|
60
|
-
if amount > 0
|
61
|
-
brighten(step)
|
62
|
-
else
|
63
|
-
dim(step)
|
64
|
-
end
|
65
|
-
steps -= step
|
40
|
+
@controller.command(@house, @unit, :off, 0)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Adjust the brightness level by +steps+. If +steps+ is
|
44
|
+
# positive, the brightness level is increased that many steps.
|
45
|
+
# If +steps+ is negative, the brightness level is decreased by
|
46
|
+
# <tt>|steps|</tt>.
|
47
|
+
#
|
48
|
+
# The controller limits the step size to 6, so larger steps must
|
49
|
+
# be broken up.
|
50
|
+
def step(steps)
|
51
|
+
direction = (steps > 0) ? :brighten : :dim
|
52
|
+
nsteps = steps.abs
|
53
|
+
while nsteps > 0
|
54
|
+
n = (nsteps > 6) ? 6 : nsteps
|
55
|
+
@controller.command(@house, @unit, direction, n)
|
56
|
+
nsteps -= n
|
66
57
|
end
|
67
|
-
if @level
|
68
|
-
@level += amount
|
69
|
-
@level = 0.0 if @level < 0
|
70
|
-
@level = 1.0 if @level > 1
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
|
76
|
-
# -- Questionable Methods --------------------------------------
|
77
|
-
|
78
|
-
# The following methods are provided as private methods. They
|
79
|
-
# are used in testing, but I am uncertain whether they should be
|
80
|
-
# part of the public interface, due to the uncertaintity of
|
81
|
-
# there implementation.
|
82
|
-
|
83
|
-
# Is the device on?
|
84
|
-
#
|
85
|
-
# Since the CM17A protocol is write only, we can't really sense
|
86
|
-
# the on/off state of the device, so we remember the last
|
87
|
-
# commanded state. This approach has the following
|
88
|
-
# disadvantages:
|
89
|
-
#
|
90
|
-
# * The on/off state is indeterminate until the first command is
|
91
|
-
# issued. Asking for the on/off state before the first
|
92
|
-
# command will throw an X10::X10Error exception.
|
93
|
-
# * If there is more than one device object controlling a single
|
94
|
-
# physical device, then the on/off state can be invalidated by
|
95
|
-
# second device object.
|
96
|
-
def on?
|
97
|
-
fail X10::X10Error, "On/Off state is unknown" if @on.nil?
|
98
|
-
@on
|
99
58
|
end
|
100
|
-
|
101
|
-
# Is the device off?
|
102
|
-
#
|
103
|
-
# See also the discussion in the on? method.
|
104
|
-
def off?
|
105
|
-
! on?
|
106
|
-
end
|
107
|
-
|
108
|
-
# Return the current brightness level between 0 (very dim) and
|
109
|
-
# 1.0 (very bright) of the device.
|
110
|
-
#
|
111
|
-
# Again, since the CM17A protocol is write only, the same
|
112
|
-
# caveats that apply to on? and off? are also applicable here.
|
113
|
-
#
|
114
|
-
# Furthermore, the real brightness level is a mystery. The
|
115
|
-
# protocol docs say that stepping the brighteness level changes
|
116
|
-
# it by approximately 5%. However, there seems to be only 10 or
|
117
|
-
# so steps from completely dim to completely bright.
|
118
|
-
def level
|
119
|
-
fail X10::X10Error, "Level is unknown" if @level.nil?
|
120
|
-
@level
|
121
|
-
end
|
122
|
-
|
123
|
-
# -- Helper Commands -------------------------------------------
|
124
|
-
|
125
|
-
# Brightness steps for the given amount.
|
126
|
-
def steps_for(amount)
|
127
|
-
(amount * 10).round.abs
|
128
|
-
end
|
129
|
-
|
130
|
-
# Send a dim command for the given number of steps.
|
131
|
-
def dim(steps)
|
132
|
-
@controller.command(@house, @unit, X10::Cm17a::DIM, steps)
|
133
|
-
end
|
134
|
-
|
135
|
-
# Send a brighten command for the given number of steps.
|
136
|
-
def brighten(steps)
|
137
|
-
@controller.command(@house, @unit, X10::Cm17a::BRIGHTEN, steps)
|
138
|
-
end
|
139
|
-
|
140
59
|
end
|
141
60
|
end
|
142
61
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'drb'
|
4
|
+
require 'x10'
|
5
|
+
require 'x10/cm17a_device'
|
6
|
+
|
7
|
+
module X10
|
8
|
+
module Cm17aRemote
|
9
|
+
class Controller
|
10
|
+
def initialize(uri="druby:localhost:7777")
|
11
|
+
@uri = uri
|
12
|
+
@remote = DRbObject.new(nil, @uri)
|
13
|
+
end
|
14
|
+
def command(house, unit, command, steps)
|
15
|
+
@remote.command(house, unit, command, steps)
|
16
|
+
end
|
17
|
+
def device(house, unit)
|
18
|
+
X10::Cm17a::Device.new(house, unit, self)
|
19
|
+
end
|
20
|
+
def self.x10_controller?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/test_cm17a_device.rb
CHANGED
@@ -26,7 +26,7 @@ class MockController < FlexMock
|
|
26
26
|
X10.controller = controller
|
27
27
|
controller.mock_handle(:device, 1) { |house, unit|
|
28
28
|
X10::Cm17a::Device.new(house, unit, controller)
|
29
|
-
}
|
29
|
+
}
|
30
30
|
end
|
31
31
|
|
32
32
|
def use
|
@@ -57,7 +57,7 @@ class TestCm17a < Test::Unit::TestCase
|
|
57
57
|
def test_on
|
58
58
|
MockController.use do |controller|
|
59
59
|
controller.mock_handle(:command, 1) { |house, unit, cmd, step|
|
60
|
-
assert_equal
|
60
|
+
assert_equal :on, cmd
|
61
61
|
assert_equal 0, step
|
62
62
|
}
|
63
63
|
dev = X10.device('a1')
|
@@ -68,7 +68,7 @@ class TestCm17a < Test::Unit::TestCase
|
|
68
68
|
def test_off
|
69
69
|
MockController.use do |controller|
|
70
70
|
controller.mock_handle(:command, 1) { |house, unit, cmd, step|
|
71
|
-
assert_equal
|
71
|
+
assert_equal :off, cmd
|
72
72
|
assert_equal 0, step
|
73
73
|
}
|
74
74
|
dev = X10.device('a1')
|
@@ -76,37 +76,27 @@ class TestCm17a < Test::Unit::TestCase
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
def test_step_size
|
80
|
-
MockController.use do |controller|
|
81
|
-
dev = X10.device('a1')
|
82
|
-
assert_equal 0, dev.send(:steps_for, 0.0)
|
83
|
-
assert_equal 5, dev.send(:steps_for, 0.5)
|
84
|
-
assert_equal 5, dev.send(:steps_for, -0.5)
|
85
|
-
assert_equal 10, dev.send(:steps_for, 1.0)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
79
|
def test_adjust
|
90
80
|
MockController.use do |controller|
|
91
81
|
controller.mock_handle(:command, 2) { |house, unit, cmd, step|
|
92
82
|
if step == 4
|
93
83
|
assert_equal 4, step
|
94
|
-
assert_equal
|
84
|
+
assert_equal :brighten, cmd
|
95
85
|
else
|
96
86
|
assert_equal 3, step
|
97
|
-
assert_equal
|
87
|
+
assert_equal :dim, cmd
|
98
88
|
end
|
99
89
|
}
|
100
90
|
dev = X10.device('a1')
|
101
|
-
dev.
|
102
|
-
dev.
|
91
|
+
dev.step(4)
|
92
|
+
dev.step(-3)
|
103
93
|
end
|
104
94
|
end
|
105
95
|
|
106
96
|
def test_big_adjustments
|
107
97
|
MockController.use do |controller|
|
108
98
|
controller.mock_handle(:command, 2) { |house, unit, cmd, step|
|
109
|
-
assert_equal
|
99
|
+
assert_equal :dim, cmd
|
110
100
|
if step == 6
|
111
101
|
assert_equal 6, step
|
112
102
|
else
|
@@ -114,7 +104,7 @@ class TestCm17a < Test::Unit::TestCase
|
|
114
104
|
end
|
115
105
|
}
|
116
106
|
dev = X10.device('a1')
|
117
|
-
dev.
|
107
|
+
dev.step(-9)
|
118
108
|
end
|
119
109
|
end
|
120
110
|
|
@@ -122,7 +112,7 @@ class TestCm17a < Test::Unit::TestCase
|
|
122
112
|
MockController.use do |controller|
|
123
113
|
controller.mock_handle(:command, 0) { }
|
124
114
|
dev = X10.device('a1')
|
125
|
-
dev.
|
115
|
+
dev.step(0)
|
126
116
|
end
|
127
117
|
end
|
128
118
|
|
@@ -135,80 +125,12 @@ class TestCm17a < Test::Unit::TestCase
|
|
135
125
|
dev = X10.device('b3')
|
136
126
|
dev.off
|
137
127
|
dev.on
|
138
|
-
dev.
|
139
|
-
dev.
|
128
|
+
dev.step(1)
|
129
|
+
dev.step(-1)
|
140
130
|
end
|
141
131
|
end
|
142
132
|
end
|
143
133
|
|
144
|
-
######################################################################
|
145
|
-
class TestCm17aNonApi < Test::Unit::TestCase
|
146
|
-
def setup
|
147
|
-
X10.controller = MockController.new
|
148
|
-
X10.controller.mock_handle(:command) { }
|
149
|
-
MockController.setup_controller(X10.controller)
|
150
|
-
@dev = X10.device("a1")
|
151
|
-
end
|
152
|
-
|
153
|
-
def teardown
|
154
|
-
X10.controller = nil
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_query
|
158
|
-
@dev.on
|
159
|
-
assert @dev.send(:on?)
|
160
|
-
assert ! @dev.send(:off?)
|
161
|
-
@dev.off
|
162
|
-
assert ! @dev.send(:on?)
|
163
|
-
assert @dev.send(:off?)
|
164
|
-
@dev.on
|
165
|
-
assert @dev.send(:on?)
|
166
|
-
assert ! @dev.send(:off?)
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_undefined_on_off_state
|
170
|
-
assert_raises(X10::X10Error) {
|
171
|
-
@dev.send(:on?)
|
172
|
-
}
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_undefined_level
|
176
|
-
assert_raises(X10::X10Error) {
|
177
|
-
@dev.send(:level)
|
178
|
-
}
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_undefined_level_after_adjust
|
182
|
-
assert_raises(X10::X10Error) {
|
183
|
-
@dev.adjust(0.3)
|
184
|
-
@dev.send(:level)
|
185
|
-
}
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_level
|
189
|
-
@dev.off
|
190
|
-
assert_equal 0.0, @dev.send(:level)
|
191
|
-
|
192
|
-
@dev.adjust(-0.5)
|
193
|
-
assert_equal 0.0, @dev.send(:level)
|
194
|
-
|
195
|
-
@dev.on
|
196
|
-
assert_equal 1.0, @dev.send(:level)
|
197
|
-
|
198
|
-
@dev.adjust(0.1)
|
199
|
-
assert_equal 1.0, @dev.send(:level)
|
200
|
-
|
201
|
-
@dev.adjust(-0.5)
|
202
|
-
assert_equal 0.5, @dev.send(:level)
|
203
|
-
|
204
|
-
@dev.adjust(-0.5)
|
205
|
-
assert_equal 0.0, @dev.send(:level)
|
206
|
-
|
207
|
-
@dev.adjust(-0.5)
|
208
|
-
assert_equal 0.0, @dev.send(:level)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
134
|
######################################################################
|
213
135
|
class TestCm17aController < Test::Unit::TestCase
|
214
136
|
def test_create
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.3
|
|
3
3
|
specification_version: 1
|
4
4
|
name: x10-cm17a
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date:
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2005-01-17
|
8
8
|
summary: Ruby based X10 CM17A Firecracker Controller
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/x10.rb
|
36
36
|
- lib/x10/cm17a.rb
|
37
37
|
- lib/x10/cm17a_device.rb
|
38
|
+
- lib/x10/cm17a_remote.rb
|
38
39
|
- ext/cm17a_api/MANIFEST
|
39
40
|
- ext/cm17a_api/cm17a.h
|
40
41
|
- ext/cm17a_api/cm17a.c
|