Class: DreamCheeky::UsbFidget

Inherits:
Object
  • Object
show all
Defined in:
lib/dream_cheeky/usb_fidget.rb,
ext/dream_cheeky/dream_cheeky_usb_fidget.c

Constant Summary collapse

DEPRESSED =
0x1E

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(&block) ⇒ Object



6
7
8
9
10
# File 'lib/dream_cheeky/usb_fidget.rb', line 6

def self.run(&block)
  brb = new
  brb.instance_eval(&block)
  brb.run
end

Instance Method Details

#get_current_stateObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'ext/dream_cheeky/dream_cheeky_usb_fidget.c', line 23

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]);
}

#push(&block) ⇒ Object



12
13
14
# File 'lib/dream_cheeky/usb_fidget.rb', line 12

def push(&block)
  @button_pushed_callback = block
end

#runObject



16
17
18
# File 'lib/dream_cheeky/usb_fidget.rb', line 16

def run
  poll_usb
end