Module: Ansible::KNX::ScalarValue
- Included in:
- DPT5
- Defined in:
- lib/ansible/knx/knx_dpt_scalar.rb
Overview
KNX specification declares some special DPTs (5.001 and 5.003) that need scalar adjustment functions to get the true value contained in a DPT frame.
Instance Method Summary collapse
-
#from_scalar(val, data_range, scalar_range) ⇒ Object
convert value from its scalar representation e.g.
-
#to_scalar(val, data_range, scalar_range) ⇒ Object
convert value to its scalar representation e.g.
Instance Method Details
#from_scalar(val, data_range, scalar_range) ⇒ Object
convert value from its scalar representation e.g. in DPT5.001, 50(%) => 0x7F , 100(%) => 0xFF
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ansible/knx/knx_dpt_scalar.rb', line 47 def from_scalar(val, data_range, scalar_range) if data_range.is_a?(Range) and scalar_range.is_a?(Range) then a = (scalar_range.max - scalar_range.min).to_f / (data_range.max - data_range.min) b = (scalar_range.min - data_range.min) #puts "a=#{a} b=#{b}" return ((val - b) / a).round else return val end end |
#to_scalar(val, data_range, scalar_range) ⇒ Object
convert value to its scalar representation e.g. in DPT5.001, 0x7F => 50(%), 0xFF => 100(%)
35 36 37 38 39 40 41 42 43 |
# File 'lib/ansible/knx/knx_dpt_scalar.rb', line 35 def to_scalar(val, data_range, scalar_range) if data_range.is_a?(Range) and scalar_range.is_a?(Range) then a = (scalar_range.max - scalar_range.min).to_f / (data_range.max - data_range.min) b = (scalar_range.min - data_range.min) return (a*val + b).round else return val end end |