Class: Artoo::Drivers::Wiidriver
- Inherits:
-
Driver
- Object
- Driver
- 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.
Instance Method Summary collapse
- #address ⇒ Object
- #handle_events ⇒ Object
-
#initialize(params = {}) ⇒ Wiidriver
constructor
Create new Wiidriver.
-
#start_driver ⇒ Object
Starts drives and required connections.
-
#update(value) ⇒ Object
Get and update data.
Constructor Details
#initialize(params = {}) ⇒ Wiidriver
Create new Wiidriver
12 13 14 15 16 |
# File 'lib/artoo/drivers/wiidriver.rb', line 12 def initialize(params={}) @joystick = get_defaults @data = {} super end |
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 |
#handle_events ⇒ Object
49 50 51 52 53 54 |
# File 'lib/artoo/drivers/wiidriver.rb', line 49 def handle_events while i = find_event(:i2c_reply) do event = events.slice!(i) update(event.data.first) if !event.nil? end end |
#start_driver ⇒ Object
Starts drives and required connections
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/artoo/drivers/wiidriver.rb', line 19 def start_driver begin connection.i2c_config(0) every(interval) do connection.i2c_write_request(address, 0x40, 0x00) connection.i2c_write_request(address, 0x00, 0x00) connection.i2c_read_request(address, 6) connection.read_and_process handle_events end super rescue Exception => e Logger.error "Error starting wii driver!" Logger.error e. Logger.error e.backtrace.inspect end end |
#update(value) ⇒ Object
Get and update data
40 41 42 43 44 45 46 47 |
# File 'lib/artoo/drivers/wiidriver.rb', line 40 def update(value) if encrypted?(value) Logger.error "Encrypted bytes from wii device!" raise "Encrypted bytes from wii device!" end @data = parse(value) end |