Class: DreamCheeky::BigRedButton
- Inherits:
-
Object
- Object
- DreamCheeky::BigRedButton
- Defined in:
- lib/dream_cheeky/big_red_button.rb,
ext/dream_cheeky/dream_cheeky_big_red_button.c
Constant Summary collapse
- CLOSED =
0x15
- OPEN =
0x17
- DEPRESSED =
0x16
Class Method Summary collapse
Instance Method Summary collapse
- #close(&block) ⇒ Object
- #get_current_state ⇒ Object
- #open(&block) ⇒ Object
- #push(&block) ⇒ Object
- #run ⇒ Object
Class Method Details
.run(&block) ⇒ Object
8 9 10 11 12 |
# File 'lib/dream_cheeky/big_red_button.rb', line 8 def self.run(&block) brb = new brb.instance_eval(&block) brb.run end |
Instance Method Details
#close(&block) ⇒ Object
18 19 20 |
# File 'lib/dream_cheeky/big_red_button.rb', line 18 def close(&block) @button_closed_callback = block end |
#get_current_state ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'ext/dream_cheeky/dream_cheeky_big_red_button.c', line 24
static VALUE get_current_state(VALUE self)
{
hid_device * handle;
int res;
unsigned char buf[8];
Data_Get_Struct(self, hid_device, handle);
// Set up the command buffer.
memset(buf,0x00,sizeof(buf));
buf[0] = 0x08;
buf[7] = 0x02;
hid_write(handle, buf, 8);
res = 0;
while (0 == res) {
res = hid_read(handle, buf, 8);
if (res == 0) {
hid_write(handle, buf, 8);
usleep(10000);
}
}
return INT2NUM(buf[0]);
}
|
#open(&block) ⇒ Object
14 15 16 |
# File 'lib/dream_cheeky/big_red_button.rb', line 14 def open(&block) @button_opened_callback = block end |
#push(&block) ⇒ Object
22 23 24 |
# File 'lib/dream_cheeky/big_red_button.rb', line 22 def push(&block) @button_pushed_callback = block end |
#run ⇒ Object
26 27 28 |
# File 'lib/dream_cheeky/big_red_button.rb', line 26 def run poll_usb end |