Class: Radio::Controls::Si570AVR

Inherits:
Object
  • Object
show all
Defined in:
lib/radio/controls/si570avr.rb

Overview

Support for Silicon Labs Si570 using Atmel AVR USB device. see: pe0fko.nl/SR-V9-Si570/ For SoftRock KB9YIG radio kits et al.

Constant Summary collapse

RT_IN =
LIBUSB::REQUEST_TYPE_VENDOR | LIBUSB::RECIPIENT_DEVICE | LIBUSB::ENDPOINT_IN
RT_OUT =
LIBUSB::REQUEST_TYPE_VENDOR | LIBUSB::RECIPIENT_DEVICE | LIBUSB::ENDPOINT_OUT
DWELL =

seconds

0.1

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Si570AVR

Returns a new instance of Si570AVR.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/radio/controls/si570avr.rb', line 28

def initialize options={}
  @divisor = options.delete(:divisor) || 4
  index = options.delete(:index) || 0
  @options = options
  if options.empty?
    @options[:idVendor] ||= 0x16c0
    @options[:idProduct] ||= 0x05dc
  end
  @device = LIBUSB::Context.new.devices(options)[index]
  raise 'USB Device Not Found' unless @device
end

Instance Method Details

#loObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/radio/controls/si570avr.rb', line 53

def lo
  return @lo if @lo and Time.now < @lo_expires
  data = nil
  @device.open do |handle|
    handle.claim_interface 0
    data = handle.control_transfer(
      :bmRequestType => RT_IN, :bRequest => 0x3a, 
      :wValue => 0, :wIndex => 0, :dataIn => 4
    )
    handle.release_interface 0
  end
  @lo_expires = Time.now + DWELL
  @lo = (data.unpack('L')[0].to_f / (1<<21) / @divisor).round 6
end

#lo=(freq) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/radio/controls/si570avr.rb', line 40

def lo= freq
  data = [freq * (1<<21) * @divisor].pack('L')
  @device.open do |handle|
    handle.claim_interface(0)
    handle.control_transfer(
      :bmRequestType => RT_OUT, :bRequest => 0x32, 
      :wValue => 0, :wIndex => 0, :dataOut => data
    )
    handle.release_interface(0)
  end
  @lo = nil
end

#stopObject



68
69
70
# File 'lib/radio/controls/si570avr.rb', line 68

def stop
  #noop
end