Class: PiDriver::I2CMaster
- Inherits:
-
Object
- Object
- PiDriver::I2CMaster
- Defined in:
- lib/pi_driver/i2c_master.rb
Class Method Summary collapse
Instance Method Summary collapse
- #ack ⇒ Object
-
#initialize(options = {}) ⇒ I2CMaster
constructor
A new instance of I2CMaster.
- #read ⇒ Object
- #start ⇒ Object (also: #restart)
- #stop ⇒ Object
- #write(byte) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ I2CMaster
Returns a new instance of I2CMaster.
3 4 5 6 7 8 9 |
# File 'lib/pi_driver/i2c_master.rb', line 3 def initialize( = {}) @frequency = 100_000 @delta_time = @frequency**-1.0 @clock_pin = [:clock_pin] @data_pin = [:data_pin] stop end |
Class Method Details
.prepare_address_for_read(address_byte) ⇒ Object
45 46 47 |
# File 'lib/pi_driver/i2c_master.rb', line 45 def self.prepare_address_for_read(address_byte) (address_byte << 1) | 1 end |
.prepare_address_for_write(address_byte) ⇒ Object
41 42 43 |
# File 'lib/pi_driver/i2c_master.rb', line 41 def self.prepare_address_for_write(address_byte) address_byte << 1 end |
Instance Method Details
#ack ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/pi_driver/i2c_master.rb', line 33 def ack release_data_pin release_clock_pin success = @data_pin.clear? drive_clock_pin success end |
#read ⇒ Object
28 29 30 31 |
# File 'lib/pi_driver/i2c_master.rb', line 28 def read release_data_pin read_data end |
#start ⇒ Object Also known as: restart
16 17 18 19 |
# File 'lib/pi_driver/i2c_master.rb', line 16 def start drive_data_pin drive_clock_pin end |
#stop ⇒ Object
11 12 13 14 |
# File 'lib/pi_driver/i2c_master.rb', line 11 def stop release_clock_pin release_data_pin end |
#write(byte) ⇒ Object
23 24 25 26 |
# File 'lib/pi_driver/i2c_master.rb', line 23 def write(byte) send_data byte byte end |