module Rumba::Sensor
Constants
- INFRARED_CHARACTER
- SENSORS_GROUP_PACKETS
Sensors groups
- SENSORS_PACKETS_SIGNEDNESS
- SENSORS_PACKETS_SIZE
- SENSORS_PACKETS_SYMBOL
Human readable packets name
- SENSORS_PACKETS_VALUE
Sensors mapper
Public Instance Methods
get_sensor(sensor)
click to toggle source
convenience method for grabbing a single sensor
# File lib/rumba/sensors.rb, line 297 def get_sensor(sensor) get_sensors_list([sensor])[sensor] end
get_sensors(group=100)
click to toggle source
Get sensors by group Default group 100 = all packets
# File lib/rumba/sensors.rb, line 278 def get_sensors(group=100) sensors_bytes_to_packets(write_chars_with_read([SENSORS,group]),SENSORS_GROUP_PACKETS[group]) end
get_sensors_list(list)
click to toggle source
Get sensors by list Array entry can be packet ID or symbol
# File lib/rumba/sensors.rb, line 284 def get_sensors_list(list) ids_list = list.map { |l| if l.class == Symbol SENSORS_PACKETS_SYMBOL.find_index(l) else l end } sensors_bytes_to_packets(write_chars_with_read([Constants::QUERY_LIST,ids_list.length]+ids_list),ids_list) end
sensors_bytes_to_packets(bytes,packets)
click to toggle source
Convert sensors bytes to packets hash
# File lib/rumba/sensors.rb, line 232 def sensors_bytes_to_packets(bytes,packets) packets_h = {} pack = "" packets.each do |packet| size = SENSORS_PACKETS_SIZE[packet] signedness = SENSORS_PACKETS_SIGNEDNESS[packet] case size when 1 case signedness when :signed pack += "c" when :unsigned pack += "C" end when 2 case signedness when :signed pack += "s>" when :unsigned pack += "S>" end end end nums = bytes.unpack(pack) cur_packet = 0 packets.each do |packet| pname = SENSORS_PACKETS_SYMBOL[packet] unless pname == :ignore value = nums[cur_packet] conv = SENSORS_PACKETS_VALUE[pname] if conv value = conv.convert(value) end packets_h[pname] = value end cur_packet += 1 end packets_h end