dream_cheeky 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,3 +1,57 @@
1
1
  # Dream Cheeky
2
2
 
3
+ Make your Dream Cheeky USB Device do something cool.
4
+
3
5
  World, the time has come to PUSH THE BUTTON!
6
+
7
+ ## Support
8
+ The following Dream Cheeky USB Devices are supported `(vendor_id:product_id)`
9
+
10
+ Big Red Button ``(1d34:000d)``
11
+ USB Fidget ``(1d34:0001)``
12
+
13
+ Please get in touch if you have an unsupported Dream Cheeky device.
14
+
15
+ ## Usage
16
+
17
+ Simple:
18
+
19
+ ```ruby
20
+ require 'rubygems'
21
+ require 'dream_cheeky'
22
+
23
+ DreamCheeky::UsbFidget.run do
24
+ push do
25
+ `say "BEEP!"`
26
+ end
27
+ end
28
+ ```
29
+
30
+ Advanced:
31
+
32
+ ```ruby
33
+ require 'rubygems'
34
+ require 'dream_cheeky'
35
+ require 'watir-webdriver'
36
+
37
+ DreamCheeky::BigRedButton.run do
38
+ browser = Watir::Browser.new
39
+
40
+ open do
41
+ browser.goto 'devastatingexplosions.com'
42
+ end
43
+
44
+ close do
45
+ browser.close
46
+ end
47
+
48
+ push do
49
+ browser.object(:id => 'flashcontent').click
50
+ end
51
+ end
52
+ ```
53
+
54
+ ## Requirements
55
+
56
+ 1. A supported Dream Cheeky USB Device. Example: http://dreamcheeky.com/big-red-button
57
+ 2. Mac OS X with Developer Tools installed. (Support for Linux and Windows is planned).
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Derrick Spell"]
9
9
  s.email = ["derrick.spell@gmail.com"]
10
10
  s.homepage = ""
11
- s.summary = "Ruby Inteface to Dream Cheeky(TM) USB Devices"
12
- s.description = "Ruby Inteface to Dream Cheeky(TM) USB Devices"
11
+ s.summary = "Ruby Interface to Dream Cheeky(TM) USB Devices"
12
+ s.description = "Ruby Interface to Dream Cheeky(TM) USB Devices"
13
13
 
14
14
  s.rubyforge_project = "dream_cheeky"
15
15
 
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'dream_cheeky'
3
+ require 'watir-webdriver'
4
+
5
+ DreamCheeky::BigRedButton.run do
6
+ browser = ""
7
+
8
+ open do
9
+ ## to use google chrome instead of default firefox add :chrome after new (with a space) and add the ChromeDriver http://code.google.com/p/chromedriver/downloads/list to your $PATH
10
+ browser = Watir::Browser.new
11
+ browser.goto 'devastatingexplosions.com'
12
+ end
13
+
14
+ close do
15
+ browser.close
16
+ end
17
+
18
+ push do
19
+ browser.object(:id => 'flashcontent').click
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'dream_cheeky'
3
+
4
+ DreamCheeky::BigRedButton.run do
5
+ open do
6
+ `say "World, the time has come to"`
7
+ `say -v Zarvox -r 100 "Push the button"`
8
+ end
9
+
10
+ close do
11
+ `say -v Bad "Dum dum da dum dum da dum da dum da dum"`
12
+ end
13
+
14
+ push do
15
+ `say "Boom!" -r 10`
16
+ `say "Oh, the humanity!"`
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'dream_cheeky'
3
+
4
+ DreamCheeky::UsbFidget.run do
5
+ push do
6
+ `say "BEEP!"`
7
+ end
8
+ end
@@ -7,4 +7,5 @@ void Init_dream_cheeky(void)
7
7
  mDreamCheeky = rb_define_module("DreamCheeky");
8
8
 
9
9
  Init_dream_cheeky_big_red_button();
10
+ Init_dream_cheeky_usb_fidget();
10
11
  }
@@ -1,11 +1,12 @@
1
1
  #ifndef RUBY_DREAM_CHEEKY
2
2
  #define RUBY_DREAM_CHEEKY
3
-
4
- #include <ruby.h>;
5
- #include <hidapi.h>;
6
3
 
7
- #include <dream_cheeky_big_red_button.h>;
8
-
4
+ #include <ruby.h>
5
+ #include <hidapi.h>
6
+
7
+ #include <dream_cheeky_big_red_button.h>
8
+ #include <dream_cheeky_usb_fidget.h>
9
+
9
10
  extern VALUE mDreamCheeky;
10
-
11
+
11
12
  #endif
@@ -29,12 +29,12 @@ static VALUE get_current_state(VALUE self)
29
29
 
30
30
  Data_Get_Struct(self, hid_device, handle);
31
31
 
32
- // Set up the command buffer.
33
- memset(buf,0x00,sizeof(buf));
34
- buf[0] = 0x08;
35
- buf[7] = 0x02;
32
+ // Set up the command buffer.
33
+ memset(buf,0x00,sizeof(buf));
34
+ buf[0] = 0x08;
35
+ buf[7] = 0x02;
36
36
 
37
- hid_write(handle, buf, 8);
37
+ hid_write(handle, buf, 8);
38
38
  res = 0;
39
39
  while (0 == res) {
40
40
  res = hid_read(handle, buf, 8);
@@ -0,0 +1,56 @@
1
+ #include <dream_cheeky_usb_fidget.h>
2
+
3
+
4
+ static void deallocate(void * handle)
5
+ {
6
+ hid_close((hid_device *)handle);
7
+ }
8
+
9
+ static VALUE allocate(VALUE klass)
10
+ {
11
+ hid_device * handle;
12
+
13
+ handle = hid_open(0x1d34, 0x0001, NULL);
14
+ if(!handle) {
15
+ rb_exc_raise(rb_exc_new2(rb_eRuntimeError, "No USB Fidget Detected"));
16
+ }
17
+
18
+ hid_set_nonblocking(handle, 1);
19
+
20
+ return Data_Wrap_Struct(klass, NULL, deallocate, handle);
21
+ }
22
+
23
+ static VALUE get_current_state(VALUE self)
24
+ {
25
+ hid_device * handle;
26
+ int res;
27
+ unsigned char buf[8];
28
+
29
+ Data_Get_Struct(self, hid_device, handle);
30
+
31
+ // Set up the command buffer.
32
+ memset(buf,0x00,sizeof(buf));
33
+ buf[0] = 0x08;
34
+ buf[7] = 0x02;
35
+
36
+ hid_write(handle, buf, 8);
37
+ res = 0;
38
+ while (0 == res) {
39
+ res = hid_read(handle, buf, 8);
40
+ if (res == 0) {
41
+ hid_write(handle, buf, 8);
42
+ usleep(10000);
43
+ }
44
+ }
45
+
46
+ return INT2NUM(buf[0]);
47
+ }
48
+
49
+
50
+ void Init_dream_cheeky_usb_fidget()
51
+ {
52
+ VALUE cDreamCheekyUsbFidget = rb_define_class_under(mDreamCheeky, "UsbFidget", rb_cObject);
53
+
54
+ rb_define_alloc_func(cDreamCheekyUsbFidget, allocate);
55
+ rb_define_method(cDreamCheekyUsbFidget, "get_current_state", get_current_state, 0);
56
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef RUBY_DREAM_CHEEKY_USB_FIDGET
2
+ #define RUBY_DREAM_CHEEKY_USB_FIDGET
3
+
4
+ #include <dream_cheeky.h>
5
+
6
+ void Init_dream_cheeky_usb_fidget();
7
+
8
+ #endif
@@ -1,3 +1,4 @@
1
1
  require 'dream_cheeky/version'
2
2
  require 'dream_cheeky/dream_cheeky'
3
3
  require 'dream_cheeky/big_red_button'
4
+ require 'dream_cheeky/usb_fidget'
@@ -0,0 +1,53 @@
1
+ module DreamCheeky
2
+ class UsbFidget
3
+
4
+ DEPRESSED = 0x1E
5
+
6
+ def self.run(&block)
7
+ brb = new
8
+ brb.instance_eval(&block)
9
+ brb.run
10
+ end
11
+
12
+ def push(&block)
13
+ @button_pushed_callback = block
14
+ end
15
+
16
+ def run
17
+ poll_usb
18
+ end
19
+
20
+
21
+ private ####################################################################
22
+
23
+ attr_accessor :prior_state, :current_state
24
+
25
+ def poll_usb
26
+ init_loop
27
+ begin
28
+ case check_button
29
+ when DEPRESSED
30
+ push! unless already_pushed?
31
+ end
32
+ end while(true)
33
+ end
34
+
35
+ def init_loop
36
+ self.prior_state = self.current_state = get_current_state
37
+ end
38
+
39
+ def check_button
40
+ self.prior_state = current_state
41
+ self.current_state = get_current_state
42
+ end
43
+
44
+ def push!
45
+ @button_pushed_callback && @button_pushed_callback.call
46
+ end
47
+
48
+ def already_pushed?
49
+ DEPRESSED == prior_state
50
+ end
51
+
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module DreamCheeky
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'dream_cheeky'
2
+
3
+ describe DreamCheeky::UsbFidget do
4
+
5
+ it "should raise an error when instantiated if it can't find a UsbFidget device" do
6
+ pending
7
+ expect { subject }.to raise_error
8
+ end
9
+ end
@@ -6,4 +6,8 @@ describe DreamCheeky do
6
6
  expect { DreamCheeky::BigRedButton.new }.to_not raise_error(NameError)
7
7
  end
8
8
 
9
+ it "should contain a UsbFidget class" do
10
+ expect { DreamCheeky::UsbFidget.new }.to_not raise_error(NameError)
11
+ end
12
+
9
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dream_cheeky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-21 00:00:00.000000000Z
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70258907999700 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,8 +21,13 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70258907999700
25
- description: Ruby Inteface to Dream Cheeky(TM) USB Devices
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Ruby Interface to Dream Cheeky(TM) USB Devices
26
31
  email:
27
32
  - derrick.spell@gmail.com
28
33
  executables: []
@@ -34,17 +39,24 @@ files:
34
39
  - README.md
35
40
  - Rakefile
36
41
  - dream_cheeky.gemspec
42
+ - examples/big_red_button-browse.rb
43
+ - examples/big_red_button-speak.rb
44
+ - examples/usb_fidget-speak.rb
37
45
  - ext/dream_cheeky/dream_cheeky.c
38
46
  - ext/dream_cheeky/dream_cheeky.h
39
47
  - ext/dream_cheeky/dream_cheeky_big_red_button.c
40
48
  - ext/dream_cheeky/dream_cheeky_big_red_button.h
49
+ - ext/dream_cheeky/dream_cheeky_usb_fidget.c
50
+ - ext/dream_cheeky/dream_cheeky_usb_fidget.h
41
51
  - ext/dream_cheeky/extconf.rb
42
52
  - ext/dream_cheeky/hidapi-mac.c
43
53
  - ext/dream_cheeky/hidapi.h
44
54
  - lib/dream_cheeky.rb
45
55
  - lib/dream_cheeky/big_red_button.rb
56
+ - lib/dream_cheeky/usb_fidget.rb
46
57
  - lib/dream_cheeky/version.rb
47
58
  - spec/dream_cheeky/big_red_button_spec.rb
59
+ - spec/dream_cheeky/usb_fidget_spec.rb
48
60
  - spec/dream_cheeky_spec.rb
49
61
  homepage: ''
50
62
  licenses: []
@@ -66,10 +78,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
78
  version: '0'
67
79
  requirements: []
68
80
  rubyforge_project: dream_cheeky
69
- rubygems_version: 1.8.11
81
+ rubygems_version: 1.8.21
70
82
  signing_key:
71
83
  specification_version: 3
72
- summary: Ruby Inteface to Dream Cheeky(TM) USB Devices
84
+ summary: Ruby Interface to Dream Cheeky(TM) USB Devices
73
85
  test_files:
74
86
  - spec/dream_cheeky/big_red_button_spec.rb
87
+ - spec/dream_cheeky/usb_fidget_spec.rb
75
88
  - spec/dream_cheeky_spec.rb