Class: UsbPdMatch::Result
- Inherits:
-
Struct
- Object
- Struct
- UsbPdMatch::Result
- Defined in:
- lib/usb_pd_match/negotiator.rb
Overview
Result of a USB-PD negotiation between a Charger (source) and Device (sink).
Instance Attribute Summary collapse
-
#charger ⇒ Object
Returns the value of attribute charger.
-
#current ⇒ Object
Returns the value of attribute current.
-
#device ⇒ Object
Returns the value of attribute device.
-
#voltage ⇒ Object
Returns the value of attribute voltage.
-
#watts ⇒ Object
Returns the value of attribute watts.
Instance Method Summary collapse
-
#efficiency ⇒ Object
Fraction of the device’s requested power actually delivered (0.0–1.0).
-
#full_power? ⇒ Boolean
True when the device receives its full rated power.
- #summary ⇒ Object
- #to_h ⇒ Object
Instance Attribute Details
#charger ⇒ Object
Returns the value of attribute charger
5 6 7 |
# File 'lib/usb_pd_match/negotiator.rb', line 5 def charger @charger end |
#current ⇒ Object
Returns the value of attribute current
5 6 7 |
# File 'lib/usb_pd_match/negotiator.rb', line 5 def current @current end |
#device ⇒ Object
Returns the value of attribute device
5 6 7 |
# File 'lib/usb_pd_match/negotiator.rb', line 5 def device @device end |
#voltage ⇒ Object
Returns the value of attribute voltage
5 6 7 |
# File 'lib/usb_pd_match/negotiator.rb', line 5 def voltage @voltage end |
#watts ⇒ Object
Returns the value of attribute watts
5 6 7 |
# File 'lib/usb_pd_match/negotiator.rb', line 5 def watts @watts end |
Instance Method Details
#efficiency ⇒ Object
Fraction of the device’s requested power actually delivered (0.0–1.0).
7 8 9 10 11 |
# File 'lib/usb_pd_match/negotiator.rb', line 7 def efficiency return 1.0 if device.max_watts.zero? [(watts / device.max_watts).round(4), 1.0].min end |
#full_power? ⇒ Boolean
True when the device receives its full rated power.
14 15 16 |
# File 'lib/usb_pd_match/negotiator.rb', line 14 def full_power? watts >= device.max_watts - 0.01 end |
#summary ⇒ Object
18 19 20 21 |
# File 'lib/usb_pd_match/negotiator.rb', line 18 def summary format("%s → %s: %.1fV @ %.2fA = %.1fW (%d%% of device rating)", charger.name, device.name, voltage, current, watts, (efficiency * 100).round) end |
#to_h ⇒ Object
23 24 25 26 |
# File 'lib/usb_pd_match/negotiator.rb', line 23 def to_h { voltage: voltage, current: current, watts: watts, efficiency: efficiency, full_power: full_power? } end |