Module: LittleWire::SoftwarePWM
- Included in:
- LittleWire
- Defined in:
- lib/littlewire/software-pwm.rb
Overview
Interface to LittleWire 1.1’s software pwm feature
Instance Attribute Summary collapse
-
#software_pwm_enabled ⇒ Object
Has the software pwm module been enabled?.
Instance Method Summary collapse
- #is_software_pwm_available? ⇒ Boolean
-
#software_pwm ⇒ Object
An array of current software pwm values.
-
#software_pwm=(values) ⇒ Object
Set software pwm to the values of an array - values must be a number between 0 and 255 inclusive.
-
#software_pwm_read(channel) ⇒ Object
Get the value of a single software pwm channel.
-
#software_pwm_write(*args) ⇒ Object
Set the value of a single software pwm channel - value must be a number between 0 and 255 inclusive.
Instance Attribute Details
#software_pwm_enabled ⇒ Object
Has the software pwm module been enabled?
4 5 6 |
# File 'lib/littlewire/software-pwm.rb', line 4 def software_pwm_enabled @software_pwm_enabled end |
Instance Method Details
#is_software_pwm_available? ⇒ Boolean
50 51 52 |
# File 'lib/littlewire/software-pwm.rb', line 50 def is_software_pwm_available? version_hex >= 0x11 end |
#software_pwm ⇒ Object
An array of current software pwm values
17 |
# File 'lib/littlewire/software-pwm.rb', line 17 def software_pwm; @software_pwm.dup; end |
#software_pwm=(values) ⇒ Object
Set software pwm to the values of an array - values must be a number between 0 and 255 inclusive
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/littlewire/software-pwm.rb', line 20 def software_pwm= values require_software_pwm_available self.software_pwm_enabled = true 3.times do |idx| @software_pwm[idx] = values[idx].to_i % 256 end control_transfer(function: :update_softpwm, wValue: @software_pwm[1] << 8 | @software_pwm[0], wIndex: @software_pwm[2]) end |
#software_pwm_read(channel) ⇒ Object
Get the value of a single software pwm channel
32 33 34 |
# File 'lib/littlewire/software-pwm.rb', line 32 def software_pwm_read channel @software_pwm[get_pin(LittleWire::SoftwarePWMPinMap, channel)] end |
#software_pwm_write(*args) ⇒ Object
Set the value of a single software pwm channel - value must be a number between 0 and 255 inclusive
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/littlewire/software-pwm.rb', line 37 def software_pwm_write *args if args.first.is_a? Hash state = self.software_pwm args.first.each do |channel, value| state[get_pin(LittleWire::SoftwarePWMPinMap, channel)] = value end self.software_pwm = state else raise "Invalid Arguments" unless args.length == 2 self.software_pwm_write(args.first => args.last) end end |