rb-blink1 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +17 -34
- data/Rakefile +27 -3
- data/ext/blink1/blink1.c +128 -6
- data/ext/blink1/{include/color_funcs.h → color_funcs.h} +0 -0
- data/ext/blink1/extconf.rb +4 -6
- data/ext/blink1/{include/hidapi.h → hidapi.h} +0 -0
- data/ext/blink1/{include/osccal.h → osccal.h} +0 -0
- data/ext/blink1/{include/usbconfig.h → usbconfig.h} +0 -0
- data/lib/blink1/version.rb +2 -1
- data/lib/blink1.rb +63 -14
- data/rb-blink1.gemspec +14 -6
- data/spec/blink1_spec.rb +17 -0
- data/spec/spec_helper.rb +16 -0
- metadata +145 -15
- data/ext/blink1/include/blink1-lib.h +0 -83
data/README.rdoc
CHANGED
@@ -2,13 +2,23 @@
|
|
2
2
|
|
3
3
|
The Ruby interface for blink(1)
|
4
4
|
|
5
|
+
{<img src="https://travis-ci.org/ngs/rb-blink1.png?branch=master" alt="Build Status" />}[https://travis-ci.org/ngs/rb-blink1]
|
6
|
+
|
5
7
|
== Install
|
6
8
|
|
7
9
|
gem install rb-blink1
|
8
10
|
|
9
11
|
== Usage
|
10
12
|
|
11
|
-
===
|
13
|
+
=== Play in a block
|
14
|
+
|
15
|
+
require 'blink1'
|
16
|
+
|
17
|
+
Blink1.open do |blink1|
|
18
|
+
blink1.set_rgb(255, 255, 255)
|
19
|
+
end
|
20
|
+
|
21
|
+
=== Open and close manually
|
12
22
|
|
13
23
|
require 'blink1'
|
14
24
|
|
@@ -17,22 +27,17 @@ The Ruby interface for blink(1)
|
|
17
27
|
blink1.set_rgb(255, 255, 255)
|
18
28
|
blink1.close
|
19
29
|
|
20
|
-
===
|
30
|
+
=== Set RGB
|
21
31
|
|
22
|
-
|
32
|
+
blink1.set_rgb(255, 255, 255)
|
23
33
|
|
24
|
-
|
25
|
-
|
26
|
-
|
34
|
+
|
35
|
+
=== Fade to RGB
|
36
|
+
|
27
37
|
blink1.fade_to_rgb(100, 255, 255, 255)
|
28
|
-
blink1.close
|
29
38
|
|
30
39
|
=== Create and play pattern line
|
31
40
|
|
32
|
-
require 'blink1'
|
33
|
-
|
34
|
-
blink1 = Blink1.new
|
35
|
-
blink1.open
|
36
41
|
blink1.write_pattern_line(100, 255, 255, 255, 0)
|
37
42
|
blink1.write_pattern_line(100, 0, 255, 255, 1)
|
38
43
|
blink1.write_pattern_line(100, 255, 255, 0, 2)
|
@@ -45,45 +50,23 @@ The Ruby interface for blink(1)
|
|
45
50
|
blink1.write_pattern_line(100, 0, 255, 255, 9)
|
46
51
|
blink1.write_pattern_line(100, 255, 255, 0, 10)
|
47
52
|
blink1.play(0)
|
48
|
-
blink1.close
|
49
53
|
|
50
54
|
=== Blink with specified color
|
51
55
|
|
52
|
-
require 'blink1'
|
53
|
-
|
54
|
-
blink1 = Blink1.new
|
55
|
-
blink1.open
|
56
56
|
blink1.blink(255, 255, 0, 5)
|
57
|
-
blink1.close
|
58
57
|
|
59
58
|
=== Random color
|
60
59
|
|
61
|
-
require 'blink1'
|
62
|
-
|
63
|
-
blink1 = Blink1.new
|
64
|
-
blink1.open
|
65
60
|
blink1.random(25)
|
66
|
-
blink1.close
|
67
61
|
|
68
62
|
=== Turn LED on
|
69
63
|
|
70
|
-
require 'blink1'
|
71
|
-
|
72
|
-
blink1 = Blink1.new
|
73
|
-
blink1.open
|
74
64
|
blink1.on
|
75
|
-
blink1.close
|
76
65
|
|
77
66
|
=== Turn LED off
|
78
67
|
|
79
|
-
require 'blink1'
|
80
|
-
|
81
|
-
blink1 = Blink1.new
|
82
|
-
blink1.open
|
83
68
|
blink1.off
|
84
|
-
blink1.close
|
85
|
-
|
86
69
|
|
87
70
|
== Author
|
88
71
|
|
89
|
-
|
72
|
+
{Atsushi Nagase}[http://ngs.io/]
|
data/Rakefile
CHANGED
@@ -1,5 +1,29 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rdoc/task'
|
3
|
+
require 'rspec/core/rake_task'
|
3
4
|
|
4
|
-
|
5
|
+
task :default => :spec
|
6
|
+
task :spec => :build
|
5
7
|
|
8
|
+
task :build do
|
9
|
+
Dir.chdir('ext/blink1') do
|
10
|
+
output = `ruby extconf.rb`
|
11
|
+
raise output unless $? == 0
|
12
|
+
output = `make`
|
13
|
+
raise output unless $? == 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
RSpec::Core::RakeTask.new
|
19
|
+
|
20
|
+
RDoc::Task.new do |rdoc|
|
21
|
+
|
22
|
+
rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb", "ext/blink1/blink1.c")
|
23
|
+
rdoc.generator = 'bootstrap'
|
24
|
+
rdoc.main = "README.rdoc"
|
25
|
+
rdoc.rdoc_dir = 'html'
|
26
|
+
rdoc.title = 'rb-blink1'
|
27
|
+
rdoc.options << '--line-numbers'
|
28
|
+
|
29
|
+
end
|
data/ext/blink1/blink1.c
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
/*
|
2
|
+
* Blink1
|
3
|
+
* Ruby interface for blink(1).
|
4
|
+
* Wraps methods in blink1-lib.c.
|
5
|
+
*/
|
1
6
|
#include <stdlib.h>
|
2
7
|
#include "ruby.h"
|
3
8
|
#include "blink1-lib.h"
|
@@ -12,36 +17,61 @@ static int degamma = 1;
|
|
12
17
|
|
13
18
|
#pragma mark - Static methods
|
14
19
|
|
20
|
+
/** Return vendor ID */
|
15
21
|
static VALUE rb_blink1_vid(VALUE self) {
|
16
22
|
return INT2NUM(blink1_vid());
|
17
23
|
}
|
18
24
|
|
25
|
+
/** Return product ID */
|
19
26
|
static VALUE rb_blink1_pid(VALUE self) {
|
20
27
|
return INT2NUM(blink1_pid());
|
21
28
|
}
|
22
29
|
|
30
|
+
/** Sort cached device by path. */
|
23
31
|
static VALUE rb_blink1_sortPaths(VALUE self) {
|
24
32
|
blink1_sortPaths();
|
25
33
|
return Qnil;
|
26
34
|
}
|
27
35
|
|
36
|
+
/** Sort cached device by serial id. */
|
28
37
|
static VALUE rb_blink1_sortSerials(VALUE self) {
|
29
38
|
blink1_sortSerials();
|
30
39
|
return Qnil;
|
31
40
|
}
|
32
41
|
|
42
|
+
/** Get all devices by default +product_id+, +vendor_id+. */
|
33
43
|
static VALUE rb_blink1_enumerate(VALUE self) {
|
34
44
|
return INT2NUM(blink1_enumerate());
|
35
45
|
}
|
36
46
|
|
47
|
+
/**
|
48
|
+
* :call-seq:
|
49
|
+
* <span class="name">enumerate_by_vid_pid</span> <span class="arguments">(vid, pid) -> integer</span>
|
50
|
+
*
|
51
|
+
* Get all matching devices by VID/PID pair.
|
52
|
+
*
|
53
|
+
* Return number of devices.
|
54
|
+
*/
|
37
55
|
static VALUE rb_blink1_enumerateByVidPid(VALUE self, VALUE vid, VALUE pid) {
|
38
56
|
return INT2NUM(blink1_enumerateByVidPid(FIX2INT(vid), FIX2INT(pid)));
|
39
57
|
}
|
40
58
|
|
59
|
+
/**
|
60
|
+
* :call-seq:
|
61
|
+
* <span class="name">cached_path</span> <span class="arguments">(index) -> string</span>
|
62
|
+
*
|
63
|
+
* Return cached device path by index.
|
64
|
+
*/
|
41
65
|
static VALUE rb_blink1_blink1_getCachedPath(VALUE self, VALUE i) {
|
42
66
|
return rb_str_new2(blink1_getCachedPath(FIX2INT(i)));
|
43
67
|
}
|
44
68
|
|
69
|
+
/**
|
70
|
+
* :call-seq:
|
71
|
+
* <span class="name">cached_serial</span> <span class="arguments">(index) -> string</span>
|
72
|
+
*
|
73
|
+
* Return cached device serial id by index.
|
74
|
+
*/
|
45
75
|
static VALUE rb_blink1_getCachedSerial(VALUE self, VALUE i) {
|
46
76
|
const wchar_t *ret = blink1_getCachedSerial(FIX2INT(i));
|
47
77
|
char dest[16] = {"\0"};
|
@@ -49,19 +79,29 @@ static VALUE rb_blink1_getCachedSerial(VALUE self, VALUE i) {
|
|
49
79
|
return rb_str_new2(dest);
|
50
80
|
}
|
51
81
|
|
82
|
+
/**
|
83
|
+
* :call-seq:
|
84
|
+
* <span class="name">cached_count</span> <span class="arguments">-> integer</span>
|
85
|
+
*
|
86
|
+
* Return number of cached devices.
|
87
|
+
*/
|
52
88
|
static VALUE rb_blink1_getCachedCount(VALUE self) {
|
53
89
|
return INT2NUM(blink1_getCachedCount());
|
54
90
|
}
|
55
91
|
|
92
|
+
|
93
|
+
/* :nodoc: */
|
56
94
|
static VALUE rb_blink1_error_msg(VALUE self, VALUE code) {
|
57
95
|
char *msg = blink1_error_msg(FIX2INT(code));
|
58
96
|
return msg == NULL ? Qnil : rb_str_new2(msg);
|
59
97
|
}
|
60
98
|
|
99
|
+
/** Return degamma enabled. */
|
61
100
|
static VALUE rb_blink1_getDegammaEnabled(VALUE self) {
|
62
101
|
return degamma == 1 ? Qtrue : Qfalse;
|
63
102
|
}
|
64
103
|
|
104
|
+
/** Set degamma enabled. */
|
65
105
|
static VALUE rb_blink1_setDegammaEnabled(VALUE self, VALUE enabled) {
|
66
106
|
if(RTEST(enabled)) {
|
67
107
|
degamma = 1;
|
@@ -73,10 +113,12 @@ static VALUE rb_blink1_setDegammaEnabled(VALUE self, VALUE enabled) {
|
|
73
113
|
return Qnil;
|
74
114
|
}
|
75
115
|
|
116
|
+
/** Return gamma corrected value for a RGB component. */
|
76
117
|
static VALUE rb_blink1_degamma(VALUE self, VALUE i) {
|
77
118
|
return INT2NUM(blink1_degamma(FIX2INT(i)));
|
78
119
|
}
|
79
120
|
|
121
|
+
/** Sleeps for milliseconds. */
|
80
122
|
static VALUE rb_blink1_sleep(VALUE self, VALUE delayMillis) {
|
81
123
|
blink1_sleep(FIX2UINT(delayMillis));
|
82
124
|
return Qnil;
|
@@ -84,6 +126,7 @@ static VALUE rb_blink1_sleep(VALUE self, VALUE delayMillis) {
|
|
84
126
|
|
85
127
|
#pragma mark - Instance methods
|
86
128
|
|
129
|
+
/** :nodoc: */
|
87
130
|
void rb_blink1_free(struct Blink1Instance *ins) {
|
88
131
|
if(ins->opened == 1) {
|
89
132
|
blink1_close(ins->dev);
|
@@ -93,18 +136,21 @@ void rb_blink1_free(struct Blink1Instance *ins) {
|
|
93
136
|
ruby_xfree(ins);
|
94
137
|
}
|
95
138
|
|
139
|
+
/** :nodoc: */
|
96
140
|
static VALUE rb_blink1_allocate(VALUE self) {
|
97
141
|
struct Blink1Instance *ins = malloc(sizeof(struct Blink1Instance));
|
98
142
|
ins->opened = 0;
|
99
143
|
return Data_Wrap_Struct(self, 0, rb_blink1_free, ins);
|
100
144
|
}
|
101
145
|
|
146
|
+
/** Return the device is opened. */
|
102
147
|
static VALUE rb_blink1_opened(VALUE self) {
|
103
148
|
struct Blink1Instance *ins;
|
104
149
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
105
150
|
return ins->opened == 1 ? Qtrue : Qfalse;
|
106
151
|
}
|
107
152
|
|
153
|
+
/** Open device by default +vendor_id+, +product_id+. */
|
108
154
|
static VALUE rb_blink1_open(VALUE self) {
|
109
155
|
struct Blink1Instance *ins;
|
110
156
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
@@ -116,6 +162,7 @@ static VALUE rb_blink1_open(VALUE self) {
|
|
116
162
|
return Qfalse;
|
117
163
|
}
|
118
164
|
|
165
|
+
/** Open device by device path. */
|
119
166
|
static VALUE rb_blink1_openByPath(VALUE self, VALUE path) {
|
120
167
|
struct Blink1Instance *ins;
|
121
168
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
@@ -127,6 +174,7 @@ static VALUE rb_blink1_openByPath(VALUE self, VALUE path) {
|
|
127
174
|
return Qfalse;
|
128
175
|
}
|
129
176
|
|
177
|
+
/** Open device by serial id. */
|
130
178
|
static VALUE rb_blink1_openBySerial(VALUE self, VALUE serial) {
|
131
179
|
struct Blink1Instance *ins;
|
132
180
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
@@ -138,6 +186,7 @@ static VALUE rb_blink1_openBySerial(VALUE self, VALUE serial) {
|
|
138
186
|
return Qfalse;
|
139
187
|
}
|
140
188
|
|
189
|
+
/** Open device by id. */
|
141
190
|
static VALUE rb_blink1_openById(VALUE self, VALUE id) {
|
142
191
|
struct Blink1Instance *ins;
|
143
192
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
@@ -149,6 +198,7 @@ static VALUE rb_blink1_openById(VALUE self, VALUE id) {
|
|
149
198
|
return Qfalse;
|
150
199
|
}
|
151
200
|
|
201
|
+
/** Closes the device. */
|
152
202
|
static VALUE rb_blink1_close(VALUE self) {
|
153
203
|
struct Blink1Instance *ins;
|
154
204
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
@@ -159,24 +209,47 @@ static VALUE rb_blink1_close(VALUE self) {
|
|
159
209
|
return Qnil;
|
160
210
|
}
|
161
211
|
|
212
|
+
/** Return blink(1) version. */
|
162
213
|
static VALUE rb_blink1_getVersion(VALUE self) {
|
163
214
|
struct Blink1Instance *ins;
|
164
215
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
165
216
|
return INT2NUM(blink1_getVersion(ins->dev));
|
166
217
|
}
|
167
218
|
|
219
|
+
/**
|
220
|
+
* :call-seq:
|
221
|
+
* <span class="name">fade_to_rgb</span> <span class="arguments">(fade_millis, r, g, b) -> integer</span>
|
222
|
+
*
|
223
|
+
* Fade LED color to RGB in +fade_millis+.
|
224
|
+
*
|
225
|
+
* Return the actual number of bytes written and -1 on error.
|
226
|
+
*/
|
168
227
|
static VALUE rb_blink1_fadeToRGB(VALUE self, VALUE fadeMillis, VALUE r, VALUE g, VALUE b) {
|
169
228
|
struct Blink1Instance *ins;
|
170
229
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
171
230
|
return INT2NUM(blink1_fadeToRGB(ins->dev, FIX2UINT(fadeMillis), FIX2UINT(r), FIX2UINT(g), FIX2UINT(b)));
|
172
231
|
}
|
173
232
|
|
233
|
+
/**
|
234
|
+
* :call-seq:
|
235
|
+
* <span class="name">set_rgb</span> <span class="arguments">(r, g, b) -> integer</span>
|
236
|
+
*
|
237
|
+
* Set LED color to RGB.
|
238
|
+
*
|
239
|
+
* Return the actual number of bytes written and -1 on error.
|
240
|
+
*/
|
174
241
|
static VALUE rb_blink1_setRGB(VALUE self, VALUE r, VALUE g, VALUE b) {
|
175
242
|
struct Blink1Instance *ins;
|
176
243
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
177
244
|
return INT2NUM(blink1_setRGB(ins->dev, FIX2UINT(r), FIX2UINT(g), FIX2UINT(b)));
|
178
245
|
}
|
179
246
|
|
247
|
+
/**
|
248
|
+
* :call-seq:
|
249
|
+
* <span class="name">eeread</span> <span class="arguments">(addr) -> integer</span>
|
250
|
+
*
|
251
|
+
* Returns an EEPROM byte.
|
252
|
+
*/
|
180
253
|
static VALUE rb_blink1_eeread(VALUE self, VALUE addr) {
|
181
254
|
struct Blink1Instance *ins;
|
182
255
|
uint8_t val = 0;
|
@@ -185,12 +258,21 @@ static VALUE rb_blink1_eeread(VALUE self, VALUE addr) {
|
|
185
258
|
return UINT2NUM(val);
|
186
259
|
}
|
187
260
|
|
261
|
+
/**
|
262
|
+
* :call-seq:
|
263
|
+
* <span class="name">eewrite</span> <span class="arguments">(addr, val) -> integer</span>
|
264
|
+
*
|
265
|
+
* Write an EEPROM byte.
|
266
|
+
*
|
267
|
+
* Return the actual number of bytes written and -1 on error.
|
268
|
+
*/
|
188
269
|
static VALUE rb_blink1_eewrite(VALUE self, VALUE addr, VALUE val) {
|
189
270
|
struct Blink1Instance *ins;
|
190
271
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
191
272
|
return INT2NUM(blink1_eewrite(ins->dev, FIX2UINT(addr), FIX2UINT(val)));
|
192
273
|
}
|
193
274
|
|
275
|
+
/** :nodoc: */
|
194
276
|
static VALUE rb_blink1_serialnumread(VALUE self) {
|
195
277
|
struct Blink1Instance *ins;
|
196
278
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
@@ -199,6 +281,7 @@ static VALUE rb_blink1_serialnumread(VALUE self) {
|
|
199
281
|
return UINT2NUM(serialnum);
|
200
282
|
}
|
201
283
|
|
284
|
+
/** :nodoc: */
|
202
285
|
static VALUE rb_blink1_serialnumwrite(VALUE self, VALUE serialnumstr) {
|
203
286
|
struct Blink1Instance *ins;
|
204
287
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
@@ -208,30 +291,70 @@ static VALUE rb_blink1_serialnumwrite(VALUE self, VALUE serialnumstr) {
|
|
208
291
|
return INT2NUM(blink1_serialnumwrite(ins->dev, (uint8_t *)serialnum));
|
209
292
|
}
|
210
293
|
|
294
|
+
/**
|
295
|
+
* :call-seq:
|
296
|
+
* <span class="name">serverdown</span> <span class="arguments">(on, millisecond) -> integer</span>
|
297
|
+
*
|
298
|
+
* Turn on/off servertickle
|
299
|
+
*
|
300
|
+
* Return the actual number of bytes written and -1 on error.
|
301
|
+
*/
|
211
302
|
static VALUE rb_blink1_serverdown(VALUE self, VALUE on, VALUE millis) {
|
212
303
|
struct Blink1Instance *ins;
|
213
304
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
214
305
|
return INT2NUM(blink1_serverdown(ins->dev, RTEST(on) ? 1 : 0, FIX2UINT(millis)));
|
215
306
|
}
|
216
307
|
|
308
|
+
/**
|
309
|
+
* :call-seq:
|
310
|
+
* <span class="name">play</span> <span class="arguments">(pos) -> integer</span>
|
311
|
+
*
|
312
|
+
* Start playing color sequence (at pos)
|
313
|
+
*
|
314
|
+
* Return the actual number of bytes written and -1 on error.
|
315
|
+
*/
|
217
316
|
static VALUE rb_blink1_play(VALUE self, VALUE pos) {
|
218
317
|
struct Blink1Instance *ins;
|
219
318
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
220
319
|
return INT2NUM(blink1_play(ins->dev, 1, FIX2UINT(pos)));
|
221
320
|
}
|
222
321
|
|
322
|
+
/**
|
323
|
+
* :call-seq:
|
324
|
+
* <span class="name">stop</span> <span class="arguments">(pos) -> integer</span>
|
325
|
+
*
|
326
|
+
* Stop playing color sequence (at pos)
|
327
|
+
*
|
328
|
+
* Return the actual number of bytes written and -1 on error.
|
329
|
+
*/
|
223
330
|
static VALUE rb_blink1_stop(VALUE self, VALUE pos) {
|
224
331
|
struct Blink1Instance *ins;
|
225
332
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
226
333
|
return INT2NUM(blink1_play(ins->dev, 0, FIX2UINT(pos)));
|
227
334
|
}
|
228
335
|
|
336
|
+
/**
|
337
|
+
* :call-seq:
|
338
|
+
* <span class="name">write_pattern_line</span> <span class="arguments">(fade_millis, r, g, b, pos) -> integer</span>
|
339
|
+
*
|
340
|
+
* Write pattern RGB value at pos
|
341
|
+
*
|
342
|
+
* Return the actual number of bytes written and -1 on error.
|
343
|
+
*/
|
229
344
|
static VALUE rb_blink1_writePatternLine(VALUE self, VALUE fadeMillis, VALUE r, VALUE g, VALUE b, VALUE pos) {
|
230
345
|
struct Blink1Instance *ins;
|
231
346
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
232
347
|
return INT2NUM(blink1_writePatternLine(ins->dev, FIX2UINT(fadeMillis), FIX2UINT(r), FIX2UINT(g), FIX2UINT(b), FIX2UINT(pos)));
|
233
348
|
}
|
234
349
|
|
350
|
+
/**
|
351
|
+
* :call-seq:
|
352
|
+
* <span class="name">read_pattern_line</span> <span class="arguments">(pos) -> hash</span>
|
353
|
+
*
|
354
|
+
* Read pattern RGB value at pos
|
355
|
+
*
|
356
|
+
* Return hash with value with key +"fade_millis"+, +"r"+, +"g"+, +"b"+
|
357
|
+
*/
|
235
358
|
static VALUE rb_blink1_readPatternLine(VALUE self, VALUE pos) {
|
236
359
|
struct Blink1Instance *ins;
|
237
360
|
Data_Get_Struct(self, struct Blink1Instance, ins);
|
@@ -245,12 +368,11 @@ static VALUE rb_blink1_readPatternLine(VALUE self, VALUE pos) {
|
|
245
368
|
return hash;
|
246
369
|
}
|
247
370
|
|
248
|
-
|
249
|
-
int blink1_write( hid_device* dev, void* buf, int len);
|
250
|
-
int blink1_read( hid_device* dev, void* buf, int len);
|
251
|
-
int blink1_getSerialNumber(hid_device *dev, char* buf);
|
252
|
-
|
253
|
-
*/
|
371
|
+
// UNSPPORT
|
372
|
+
// int blink1_write( hid_device* dev, void* buf, int len);
|
373
|
+
// int blink1_read( hid_device* dev, void* buf, int len);
|
374
|
+
// int blink1_getSerialNumber(hid_device *dev, char* buf);
|
375
|
+
// int blink1_playPattern(hid_device *dev,,);
|
254
376
|
|
255
377
|
|
256
378
|
void Init_blink1() {
|
File without changes
|
data/ext/blink1/extconf.rb
CHANGED
@@ -30,10 +30,10 @@ when 'Windows_NT'
|
|
30
30
|
when 'Linux'
|
31
31
|
|
32
32
|
$CFLAGS <<
|
33
|
-
" #{ `pkg-config libusb-1.0 --cflags
|
33
|
+
" #{ `pkg-config libusb-1.0 --cflags`.strip } "
|
34
34
|
|
35
35
|
$LIBS <<
|
36
|
-
" #{ `pkg-config libusb-1.0 --libs
|
36
|
+
" #{ `pkg-config libusb-1.0 --libs`.strip }"
|
37
37
|
' -lrt -lpthread -ldl -static '
|
38
38
|
|
39
39
|
$HID_C = "#{$srcdir}/hid.c.libusb"
|
@@ -49,8 +49,6 @@ end
|
|
49
49
|
|
50
50
|
FileUtils.copy $HID_C, "#{$srcdir}/hid.c"
|
51
51
|
|
52
|
-
$CFLAGS <<
|
53
|
-
' -std=gnu99' <<
|
54
|
-
" -I #{$srcdir}/include"
|
52
|
+
$CFLAGS << " -std=gnu99 -I#{$srcdir}/include"
|
55
53
|
|
56
|
-
create_makefile('blink1')
|
54
|
+
create_makefile('blink1')
|
File without changes
|
File without changes
|
File without changes
|
data/lib/blink1/version.rb
CHANGED
data/lib/blink1.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
require 'blink1/blink1'
|
2
2
|
require 'blink1/version'
|
3
3
|
|
4
|
+
#
|
5
|
+
# A Ruby interface for blink(1)[http://blink1.thingm.com/].
|
6
|
+
#
|
4
7
|
class Blink1
|
5
8
|
|
9
|
+
# Fade duration in millisecond.
|
6
10
|
attr_accessor :millis
|
11
|
+
# Delay to next color in millisecond.
|
7
12
|
attr_accessor :delay_millis
|
8
13
|
|
14
|
+
# :call-seq:
|
15
|
+
# <span class="name">new</span> <span class="arguments">( {Fixnum} id )</span>
|
16
|
+
# <span class="name">new</span> <span class="arguments">( {Boolean} auto_open )</span>
|
17
|
+
# <span class="name">new</span> <span class="arguments">( {String} serial_id )</span>
|
18
|
+
# <span class="name">new</span> <span class="arguments">( :path => <em>device_path</em> )</span>
|
19
|
+
# <span class="name">new</span> <span class="arguments">( :serial => <em>serial_id</em> )</span>
|
20
|
+
#
|
21
|
+
# Returns new instance of +Blink1+
|
22
|
+
#
|
9
23
|
def initialize option = nil
|
10
24
|
case option
|
11
25
|
when Fixnum
|
@@ -20,11 +34,42 @@ class Blink1
|
|
20
34
|
end
|
21
35
|
when String
|
22
36
|
open_by_serial(option)
|
37
|
+
else
|
38
|
+
open if option == true
|
23
39
|
end
|
24
40
|
@millis ||= 300
|
25
41
|
@delay_millis ||= 500
|
26
42
|
end
|
27
43
|
|
44
|
+
#
|
45
|
+
# :call-seq:
|
46
|
+
# <span class="name">open</span> <span class="arguments">( {Fixnum} id ) { |blink1| }</span>
|
47
|
+
# <span class="name">open</span> <span class="arguments">( {Boolean} autoopen ) { |blink1| }</span>
|
48
|
+
# <span class="name">open</span> <span class="arguments">( {String} serial_id ) { |blink1| }</span>
|
49
|
+
# <span class="name">open</span> <span class="arguments">( :path => <em>device_path</em> ) { |blink1| }</span>
|
50
|
+
# <span class="name">open</span> <span class="arguments">( :serial => <em>serial_id</em> ) { |blink1| }</span>
|
51
|
+
#
|
52
|
+
# If block given, yieds new instance of +Blink1+.
|
53
|
+
#
|
54
|
+
# If not, returns new +Blink1+
|
55
|
+
#
|
56
|
+
def self.open option = nil, &block
|
57
|
+
b = self.new(option)
|
58
|
+
b.open if option.nil?
|
59
|
+
if block
|
60
|
+
begin
|
61
|
+
b.instance_eval &block
|
62
|
+
ensure
|
63
|
+
b.close
|
64
|
+
end
|
65
|
+
else
|
66
|
+
b
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Blink with RGB value for +times+.
|
72
|
+
#
|
28
73
|
def blink r, g, b, times
|
29
74
|
times.times do
|
30
75
|
self.fade_to_rgb(millis, r, g, b)
|
@@ -34,6 +79,9 @@ class Blink1
|
|
34
79
|
end
|
35
80
|
end
|
36
81
|
|
82
|
+
#
|
83
|
+
# Flash random color for +times+.
|
84
|
+
#
|
37
85
|
def random times
|
38
86
|
times.times do
|
39
87
|
r = rand(0xff)
|
@@ -44,18 +92,30 @@ class Blink1
|
|
44
92
|
end
|
45
93
|
end
|
46
94
|
|
95
|
+
#
|
96
|
+
# Turn LED white.
|
97
|
+
#
|
47
98
|
def on
|
48
99
|
self.fade_to_rgb(millis, 0xff, 0xff, 0xff)
|
49
100
|
end
|
50
101
|
|
102
|
+
#
|
103
|
+
# Turn LED off.
|
104
|
+
#
|
51
105
|
def off
|
52
106
|
self.fade_to_rgb(millis, 0, 0, 0)
|
53
107
|
end
|
54
108
|
|
109
|
+
#
|
110
|
+
# Alias for +read_pattern_line+.
|
111
|
+
#
|
55
112
|
def [] index
|
56
113
|
self.read_pattern_line(index)
|
57
114
|
end
|
58
115
|
|
116
|
+
#
|
117
|
+
# Write pattern line with hash with key +fade_millis+, +r+, +g+, +b+.
|
118
|
+
#
|
59
119
|
def []= index, prop
|
60
120
|
fade_millis = prop[:fade_millis] || prop['fade_millis']
|
61
121
|
r = prop[:r] || prop['r']
|
@@ -64,6 +124,9 @@ class Blink1
|
|
64
124
|
self.write_pattern_line(index, fade_millis, r, g, b)
|
65
125
|
end
|
66
126
|
|
127
|
+
#
|
128
|
+
# Returns array of hash with keys +:id+, +:serial+, +:path+
|
129
|
+
#
|
67
130
|
def self.list
|
68
131
|
count = enumerate_vid_pid(vendor_id, product_id)
|
69
132
|
i = 0
|
@@ -79,18 +142,4 @@ class Blink1
|
|
79
142
|
devs
|
80
143
|
end
|
81
144
|
|
82
|
-
def self.open option = nil, &block
|
83
|
-
b = self.new(option)
|
84
|
-
b.open if option.nil?
|
85
|
-
if block
|
86
|
-
begin
|
87
|
-
b.instance_eval &block
|
88
|
-
ensure
|
89
|
-
b.close
|
90
|
-
end
|
91
|
-
else
|
92
|
-
b
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
145
|
end
|
data/rb-blink1.gemspec
CHANGED
@@ -8,16 +8,24 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ['Atsushi Nagase']
|
10
10
|
s.email = ['a@ngs.io']
|
11
|
-
s.homepage = "http://github.com/
|
12
|
-
s.summary = "Ruby interface for blink(1)"
|
11
|
+
s.homepage = "http://ngs.github.com/rb-blink1"
|
12
|
+
s.summary = "A Ruby interface for blink(1)"
|
13
13
|
s.description = "Controls blink(1)"
|
14
|
+
s.requirements << "libusb, version 1.0 or greater"
|
14
15
|
|
15
16
|
s.rubyforge_project = "blink1"
|
16
|
-
s.add_development_dependency 'bundler', '~> 1.0'
|
17
|
-
# s.add_development_dependency 'rspec', '~> 2.11'
|
18
|
-
# s.add_development_dependency 'guard-rspec', '~> 1.2'
|
19
17
|
|
20
|
-
s.
|
18
|
+
s.add_development_dependency 'bundler'
|
19
|
+
s.add_development_dependency 'guard-rake'
|
20
|
+
s.add_development_dependency 'guard-rspec'
|
21
|
+
s.add_development_dependency 'guard-spork'
|
22
|
+
s.add_development_dependency 'hanna-bootstrap', '>= 0.0.3'
|
23
|
+
s.add_development_dependency 'rb-fsevent'
|
24
|
+
s.add_development_dependency 'rdoc'
|
25
|
+
s.add_development_dependency 'rspec'
|
26
|
+
s.add_development_dependency 'spork'
|
27
|
+
|
28
|
+
s.files = `git ls-files`.split("\n").reject{|f| f =~ /^(\..+|Gemfile.*|Guardfile|)$/}
|
21
29
|
s.extensions = ["ext/blink1/extconf.rb"]
|
22
30
|
s.require_paths = ["lib", "ext"]
|
23
31
|
end
|
data/spec/blink1_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spork'
|
3
|
+
require 'rspec'
|
4
|
+
#uncomment the following line to use spork with the debugger
|
5
|
+
#require 'spork/ext/ruby-debug'
|
6
|
+
|
7
|
+
Spork.prefork do; end
|
8
|
+
|
9
|
+
Spork.each_run do; end
|
10
|
+
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'ext'))
|
15
|
+
|
16
|
+
require 'blink1'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb-blink1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,152 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: guard-rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: guard-rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: guard-spork
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: hanna-bootstrap
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.0.3
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.0.3
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rb-fsevent
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rdoc
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: spork
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
30
158
|
description: Controls blink(1)
|
31
159
|
email:
|
32
160
|
- a@ngs.io
|
@@ -41,19 +169,20 @@ files:
|
|
41
169
|
- ext/blink1/blink1-lib.c
|
42
170
|
- ext/blink1/blink1-lib.h
|
43
171
|
- ext/blink1/blink1.c
|
172
|
+
- ext/blink1/color_funcs.h
|
44
173
|
- ext/blink1/extconf.rb
|
45
174
|
- ext/blink1/hid.c.libusb
|
46
175
|
- ext/blink1/hid.c.mac
|
47
176
|
- ext/blink1/hid.c.windows
|
48
|
-
- ext/blink1/
|
49
|
-
- ext/blink1/
|
50
|
-
- ext/blink1/
|
51
|
-
- ext/blink1/include/osccal.h
|
52
|
-
- ext/blink1/include/usbconfig.h
|
177
|
+
- ext/blink1/hidapi.h
|
178
|
+
- ext/blink1/osccal.h
|
179
|
+
- ext/blink1/usbconfig.h
|
53
180
|
- lib/blink1.rb
|
54
181
|
- lib/blink1/version.rb
|
55
182
|
- rb-blink1.gemspec
|
56
|
-
|
183
|
+
- spec/blink1_spec.rb
|
184
|
+
- spec/spec_helper.rb
|
185
|
+
homepage: http://ngs.github.com/rb-blink1
|
57
186
|
licenses: []
|
58
187
|
post_install_message:
|
59
188
|
rdoc_options: []
|
@@ -72,10 +201,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
201
|
- - ! '>='
|
73
202
|
- !ruby/object:Gem::Version
|
74
203
|
version: '0'
|
75
|
-
requirements:
|
204
|
+
requirements:
|
205
|
+
- libusb, version 1.0 or greater
|
76
206
|
rubyforge_project: blink1
|
77
|
-
rubygems_version: 1.8.
|
207
|
+
rubygems_version: 1.8.23
|
78
208
|
signing_key:
|
79
209
|
specification_version: 3
|
80
|
-
summary: Ruby interface for blink(1)
|
210
|
+
summary: A Ruby interface for blink(1)
|
81
211
|
test_files: []
|
@@ -1,83 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* blink(1) C library --
|
3
|
-
*
|
4
|
-
* 2012, Tod E. Kurt, http://todbot.com/blog/ , http://thingm.com/
|
5
|
-
*
|
6
|
-
*/
|
7
|
-
|
8
|
-
|
9
|
-
#ifndef __BLINK1_LIB_H__
|
10
|
-
#define __BLINK1_LIB_H__
|
11
|
-
|
12
|
-
#include <stdint.h>
|
13
|
-
|
14
|
-
#include "hidapi.h"
|
15
|
-
#include "usbconfig.h" // from firmware, for VID,PID,vendor name & product name
|
16
|
-
|
17
|
-
#ifdef __cplusplus
|
18
|
-
extern "C" {
|
19
|
-
#endif
|
20
|
-
|
21
|
-
#define blink1_max_devices 16
|
22
|
-
|
23
|
-
|
24
|
-
int blink1_vid(void);
|
25
|
-
int blink1_pid(void);
|
26
|
-
void blink1_sortPaths(void);
|
27
|
-
void blink1_sortSerials(void);
|
28
|
-
|
29
|
-
int blink1_enumerate();
|
30
|
-
int blink1_enumerateByVidPid(int vid, int pid);
|
31
|
-
const char* blink1_getCachedPath(int i);
|
32
|
-
const wchar_t* blink1_getCachedSerial(int i);
|
33
|
-
int blink1_getCachedCount(void);
|
34
|
-
|
35
|
-
hid_device* blink1_open(void);
|
36
|
-
hid_device* blink1_openByPath(const char* path);
|
37
|
-
hid_device* blink1_openBySerial(const wchar_t* serial);
|
38
|
-
hid_device* blink1_openById( int i );
|
39
|
-
|
40
|
-
void blink1_close( hid_device* dev );
|
41
|
-
|
42
|
-
int blink1_write( hid_device* dev, void* buf, int len);
|
43
|
-
int blink1_read( hid_device* dev, void* buf, int len);
|
44
|
-
|
45
|
-
int blink1_getSerialNumber(hid_device *dev, char* buf);
|
46
|
-
int blink1_getVersion(hid_device *dev);
|
47
|
-
|
48
|
-
int blink1_fadeToRGB(hid_device *dev, uint16_t fadeMillis,
|
49
|
-
uint8_t r, uint8_t g, uint8_t b );
|
50
|
-
|
51
|
-
int blink1_setRGB(hid_device *dev, uint8_t r, uint8_t g, uint8_t b );
|
52
|
-
|
53
|
-
int blink1_eeread(hid_device *dev, uint16_t addr, uint8_t* val);
|
54
|
-
int blink1_eewrite(hid_device *dev, uint16_t addr, uint8_t val);
|
55
|
-
|
56
|
-
int blink1_serialnumread(hid_device *dev, uint8_t** serialnumstr);
|
57
|
-
int blink1_serialnumwrite(hid_device *dev, uint8_t* serialnumstr);
|
58
|
-
|
59
|
-
//int blink1_nightlight(hid_device *dev, uint8_t on);
|
60
|
-
int blink1_serverdown(hid_device *dev, uint8_t on, uint16_t millis);
|
61
|
-
|
62
|
-
int blink1_play(hid_device *dev, uint8_t play, uint8_t pos);
|
63
|
-
int blink1_writePatternLine(hid_device *dev, uint16_t fadeMillis,
|
64
|
-
uint8_t r, uint8_t g, uint8_t b,
|
65
|
-
uint8_t pos);
|
66
|
-
int blink1_readPatternLine(hid_device *dev, uint16_t* fadeMillis,
|
67
|
-
uint8_t* r, uint8_t* g, uint8_t* b,
|
68
|
-
uint8_t pos);
|
69
|
-
//int blink1_playPattern(hid_device *dev,,);
|
70
|
-
|
71
|
-
char *blink1_error_msg(int errCode);
|
72
|
-
|
73
|
-
void blink1_enableDegamma();
|
74
|
-
void blink1_disableDegamma();
|
75
|
-
int blink1_degamma(int n);
|
76
|
-
|
77
|
-
void blink1_sleep(uint16_t delayMillis);
|
78
|
-
|
79
|
-
#ifdef __cplusplus
|
80
|
-
}
|
81
|
-
#endif
|
82
|
-
|
83
|
-
#endif
|