Sha256: 22bdf18a8516887de1e3dab7329e70d8df50e45ab504da01cd58419e97ecabc9

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'extension/minilab_hardware'

class LibraryTranslator #:nodoc:
  include MinilabConstants

  def get_port_for_pin(pin)
    case pin
    when 30..37
      :porta
    when 3..10
      :portb
    when 26..29
      :portcl
    when 22..25
      :portch
    else
      raise "Pin #{pin} does not map to a known minilab DB37 port."
    end
  end

  def get_library_pin_number(pin)
    case pin
    when 30..37  # port a pins
      7 - (pin - 30)
    when 3..10   # port b pins
      15 - (pin - 3)
    when 26..29  # port cl pins
      19 - (pin - 26)
    when 22..25  # port ch pins
      23 - (pin - 22)
    else
      raise "Pin #{pin} does not map to a minilab library pin number."
    end
  end
  
  def get_library_port(port)
    port_to_library_port_mapping = {
      :porta => FIRSTPORTA,
      :portb => FIRSTPORTB,
      :portcl => FIRSTPORTCL,
      :portch => FIRSTPORTCH
    }

    library_port = port_to_library_port_mapping[port]
    return library_port unless library_port.nil?
    raise "Port #{port} is not a valid port."
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
minilab-1.0.0-mswin32 lib/library_translator.rb