Module: Denko::I2C::Peripheral
- Included in:
- AnalogIO::ADS1115, Display::SSD1306, RTC::DS3231, Sensor::AHT10, Sensor::AHT20, Sensor::BME280, Sensor::BMP180, Sensor::HTU21D, Sensor::HTU31D, Sensor::QMP6988, Sensor::RCWL9620, Sensor::SHT3X
- Defined in:
- lib/denko/i2c/peripheral.rb
Instance Attribute Summary collapse
-
#i2c_frequency ⇒ Object
Returns the value of attribute i2c_frequency.
-
#i2c_repeated_start ⇒ Object
Returns the value of attribute i2c_repeated_start.
Attributes included from Behaviors::Callbacks
Attributes included from Behaviors::BusPeripheral
Attributes included from Behaviors::Component
Instance Method Summary collapse
- #before_initialize(options = {}) ⇒ Object
- #i2c_read(register, num_bytes) ⇒ Object
- #i2c_write(bytes = []) ⇒ Object
Methods included from Behaviors::Reader
#_read, #read, #read_using, #wait_for_read
Methods included from Behaviors::Callbacks
#add_callback, #callbacks, #initialize, #pre_callback_filter, #remove_callback, #update
Methods included from Behaviors::State
Methods included from Behaviors::BusPeripheral
Methods included from Behaviors::Component
Instance Attribute Details
#i2c_frequency ⇒ Object
Returns the value of attribute i2c_frequency.
26 27 28 |
# File 'lib/denko/i2c/peripheral.rb', line 26 def i2c_frequency @i2c_frequency end |
#i2c_repeated_start ⇒ Object
Returns the value of attribute i2c_repeated_start.
26 27 28 |
# File 'lib/denko/i2c/peripheral.rb', line 26 def i2c_repeated_start @i2c_repeated_start end |
Instance Method Details
#before_initialize(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/denko/i2c/peripheral.rb', line 7 def before_initialize(={}) # Allow peripherals to set @i2c_address. @address ||= @i2c_address # I2C defaults if peripheral does not set. @i2c_frequency ||= 100000 @i2c_repeated_start ||= false # Override defaults if given in options. @i2c_frequency = [:i2c_frequency] if [:i2c_frequency] @i2c_repeated_start = [:i2c_repeated_start] if [:i2c_frequency] # Allow generic :address option to be given as :i2c_address before validation. # Superclass method will hande override. [:address] ||= [:i2c_address] super() end |
#i2c_read(register, num_bytes) ⇒ Object
33 34 35 |
# File 'lib/denko/i2c/peripheral.rb', line 33 def i2c_read(register, num_bytes) bus._read(address, register, num_bytes, i2c_frequency, i2c_repeated_start) end |
#i2c_write(bytes = []) ⇒ Object
29 30 31 |
# File 'lib/denko/i2c/peripheral.rb', line 29 def i2c_write(bytes=[]) bus.write(address, bytes, i2c_frequency, i2c_repeated_start) end |