Class: PiSlides::Fim

Inherits:
Object
  • Object
show all
Defined in:
lib/pi_slides/fim.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Fim

Returns a new instance of Fim.



6
7
8
9
10
11
12
13
# File 'lib/pi_slides/fim.rb', line 6

def initialize(options = {})
  @mutex = Mutex.new
  options = {
    :host => 'localhost', :port => 9999
  }.merge options
  @host = options[:host]
  @port = options[:port]
end

Instance Method Details

#exec(cmd) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pi_slides/fim.rb', line 42

def exec(cmd)
  @mutex.synchronize do
    TCPSocket.open(@host, @port).tap do |s|
      s << cmd
      s.close
    end
  end
rescue
  # this happens from time to time when fim is busy
  PiSlides.debug "error sending command, will retry in 1s"
  PiSlides.debug "host=#{@host} port=#{@port} cmd=#{cmd}"
  PiSlides.debug $!
  #PiSlides.debug $!.backtrace.join "\n"
  sleep 1
  retry
end

#push(*files) ⇒ Object



34
35
36
# File 'lib/pi_slides/fim.rb', line 34

def push(*files)
  exec files.map{|f| "push '#{f}';"}.join + "prefetch;"
end

#set_vars(vars = {}) ⇒ Object



38
39
40
# File 'lib/pi_slides/fim.rb', line 38

def set_vars(vars = {})
  exec vars.to_a.map{|name, value| %{#{name}=#{value};}}.join
end

#show(path = nil) ⇒ Object

pushes the file, displays it and removes it from the list immediately shows and pops the next file from the list if path.nil?



17
18
19
# File 'lib/pi_slides/fim.rb', line 17

def show(path=nil)
  exec %{#{"push '#{path}';" if path}next;pop;}
end

#status_line(switch_on = true) ⇒ Object

turn status line on/off



22
23
24
25
26
27
28
# File 'lib/pi_slides/fim.rb', line 22

def status_line(switch_on = true)
  if switch_on
    set_vars :_display_busy => 1, :_display_status => 1
  else # switch off
    set_vars :_display_busy => 0, :_display_status => 0
  end
end

#toggle_autowidthObject



30
31
32
# File 'lib/pi_slides/fim.rb', line 30

def toggle_autowidth
  exec 'autowidth=1-autowidth;'
end