Class: Artoo::Drivers::Wiidriver
- Defined in:
- lib/artoo/drivers/wiidriver.rb
Overview
Wii-based controller shared driver behaviors for Firmata
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#joystick ⇒ Object
readonly
Returns the value of attribute joystick.
Attributes inherited from Driver
Instance Method Summary collapse
- #address ⇒ Object
-
#initialize(params = {}) ⇒ Wiidriver
constructor
A new instance of Wiidriver.
- #start_driver ⇒ Object
- #update(value) ⇒ Object
Methods inherited from Driver
#connection, #event_topic_name, #interval, #method_missing, #pin
Methods included from Celluloid
Constructor Details
#initialize(params = {}) ⇒ Wiidriver
Returns a new instance of Wiidriver.
11 12 13 14 15 |
# File 'lib/artoo/drivers/wiidriver.rb', line 11 def initialize(params={}) @joystick = get_defaults @data = {} super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Artoo::Drivers::Driver
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/artoo/drivers/wiidriver.rb', line 7 def data @data end |
#joystick ⇒ Object (readonly)
Returns the value of attribute joystick.
7 8 9 |
# File 'lib/artoo/drivers/wiidriver.rb', line 7 def joystick @joystick end |
Instance Method Details
#address ⇒ Object
9 |
# File 'lib/artoo/drivers/wiidriver.rb', line 9 def address; 0x52; end |
#start_driver ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/artoo/drivers/wiidriver.rb', line 17 def start_driver begin listener = ->(value) { update(value) } connection.on("i2c_reply", listener) connection.i2c_config(0) every(interval) do connection.i2c_write_request(address, 0x40, 0x00) p connection.i2c_write_request(address, 0x00, 0x00) p connection.i2c_read_request(address, 6) p connection.read_and_process end super rescue Exception => e p "start driver" p e. p e.backtrace.inspect end end |
#update(value) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/artoo/drivers/wiidriver.rb', line 41 def update(value) if encrypted?(value) Logger.error "Encrypted bytes from wii device!" raise "Encrypted bytes from wii device!" end @data = parse(value) end |