Module: Denko::I2C::Peripheral
- Included in:
- AnalogIO::ADS1100, AnalogIO::ADS1115, DigitalIO::PCF8574, EEPROM::AT24C, RTC::DS3231, Sensor::AHT1X, Sensor::BME280, Sensor::BMP180, Sensor::HDC1080, Sensor::HTU21D, Sensor::HTU31D, Sensor::QMP6988, Sensor::RCWL9620, Sensor::SHT3X, Sensor::SHT4X, Sensor::VL53L0X
- Defined in:
- lib/denko/i2c/peripheral.rb
Constant Summary collapse
- I2C_ADDRESS =
Set I2C defaults for including classes by defining these constants in them.
nil- I2C_FREQUENCY =
100_000- I2C_REPEATED_START =
false
Constants included from Behaviors::Lifecycle
Behaviors::Lifecycle::CALLBACK_METHODS
Constants included from Behaviors::Reader
Behaviors::Reader::READ_WAIT_TIME
Instance Attribute Summary collapse
Attributes included from Behaviors::State
Attributes included from Behaviors::Component
Instance Method Summary collapse
-
#address ⇒ Object
(also: #i2c_address)
Use @address instead of @i2c_address for default BusPeripheral behavior.
- #i2c_default(sym) ⇒ Object
- #i2c_read(num_bytes, register: nil) ⇒ Object
- #i2c_read_raw(num_bytes, register: nil) ⇒ Object
- #i2c_write(bytes = []) ⇒ Object
Methods included from Behaviors::Lifecycle
Methods included from Behaviors::Reader
#_read, #read, #read_busy?, #read_nb, #read_raw, #read_using, #update
Methods included from Behaviors::Callbacks
#add_callback, #callbacks, #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
24 25 26 |
# File 'lib/denko/i2c/peripheral.rb', line 24 def i2c_frequency @i2c_frequency ||= params[:i2c_frequency] || params[:frequency] || i2c_default(:frequency) end |
#i2c_repeated_start ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/denko/i2c/peripheral.rb', line 28 def i2c_repeated_start return @i2c_repeated_start unless @i2c_repeated_start.nil? @i2c_repeated_start = params[:i2c_repeated_start] if @i2c_repeated_start.nil? @i2c_repeated_start = params[:repeated_start] if @i2c_repeated_start.nil? @i2c_repeated_start = i2c_default(:repeated_start) if @i2c_repeated_start.nil? @i2c_repeated_start end |
Instance Method Details
#address ⇒ Object Also known as: i2c_address
Use @address instead of @i2c_address for default BusPeripheral behavior.
19 20 21 |
# File 'lib/denko/i2c/peripheral.rb', line 19 def address @address ||= params[:i2c_address] || params[:address] || i2c_default(:address) end |
#i2c_default(sym) ⇒ Object
13 14 15 16 |
# File 'lib/denko/i2c/peripheral.rb', line 13 def i2c_default(sym) const_sym = "I2C_#{sym}".upcase.to_sym self.class.const_get(const_sym) if self.class.const_defined?(const_sym) end |
#i2c_read(num_bytes, register: nil) ⇒ Object
42 43 44 |
# File 'lib/denko/i2c/peripheral.rb', line 42 def i2c_read(num_bytes, register: nil) bus.read_nb(i2c_address, register, num_bytes, i2c_frequency, i2c_repeated_start) end |
#i2c_read_raw(num_bytes, register: nil) ⇒ Object
46 47 48 |
# File 'lib/denko/i2c/peripheral.rb', line 46 def i2c_read_raw(num_bytes, register: nil) read_raw -> { bus.read_nb(i2c_address, register, num_bytes, i2c_frequency, i2c_repeated_start)} end |
#i2c_write(bytes = []) ⇒ Object
38 39 40 |
# File 'lib/denko/i2c/peripheral.rb', line 38 def i2c_write(bytes=[]) bus.write(i2c_address, bytes, i2c_frequency, i2c_repeated_start) end |