Class: Tamashii::Agent::Device::Keyboard::TTP229Serial
- Inherits:
-
Base
- Object
- DeviceBase
- Base
- Tamashii::Agent::Device::Keyboard::TTP229Serial
show all
- Defined in:
- lib/tamashii/agent/device/keyboard/ttp229_serial.rb
Constant Summary
collapse
- HALF_BIT_TIME =
0.001
Instance Method Summary
collapse
Methods inherited from Base
#add_callback, #default_watch, #initialize, #initialize_watcher, #mark_key_down, #mark_key_up, #number_of_keys, #on_key_down, #on_key_pressed, #on_key_up, #poll_key, #process_callbacks, #record_key_state, #shutdown, #start_watcher_thread, #stop_watcher_thread, #watcher_loop, #watcher_stopping?
Methods inherited from DeviceBase
#fetch_option, #fetch_option!, #initialize, #shutdown, #unexport_pin
#display_name, #logger, #progname
Instance Method Details
#default_number_of_keys ⇒ Object
23
24
25
|
# File 'lib/tamashii/agent/device/keyboard/ttp229_serial.rb', line 23
def default_number_of_keys
8
end
|
#default_scl_pin ⇒ Object
27
28
29
|
# File 'lib/tamashii/agent/device/keyboard/ttp229_serial.rb', line 27
def default_scl_pin
17
end
|
#default_sdo_pin ⇒ Object
31
32
33
|
# File 'lib/tamashii/agent/device/keyboard/ttp229_serial.rb', line 31
def default_sdo_pin
4
end
|
#finalize_hardware ⇒ Object
35
36
37
38
|
# File 'lib/tamashii/agent/device/keyboard/ttp229_serial.rb', line 35
def finalize_hardware
unexport_pin(@scl_pin.pin)
unexport_pin(@sdo_pin.pin)
end
|
#initialize_hardware ⇒ Object
12
13
14
15
16
17
|
# File 'lib/tamashii/agent/device/keyboard/ttp229_serial.rb', line 12
def initialize_hardware
@scl_pin = PiPiper::Pin.new(pin: fetch_option(:scl_pin, default_scl_pin), direction: :out)
@sdo_pin = PiPiper::Pin.new(pin: fetch_option(:sdo_pin, default_sdo_pin), direction: :in)
@scl_pin.on
sleep(HALF_BIT_TIME)
end
|
#polling_interval ⇒ Object
19
20
21
|
# File 'lib/tamashii/agent/device/keyboard/ttp229_serial.rb', line 19
def polling_interval
10*HALF_BIT_TIME
end
|
#read_key ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/tamashii/agent/device/keyboard/ttp229_serial.rb', line 40
def read_key
current_key = nil
@number_of_keys.times do |key|
@scl_pin.off
sleep(HALF_BIT_TIME)
@sdo_pin.read
if @sdo_pin.off?
current_key = key
mark_key_down(key)
else
mark_key_up(key)
end
@scl_pin.on
sleep(HALF_BIT_TIME)
end
current_key
end
|