Class: Klear::File

Inherits:
Object
  • Object
show all
Defined in:
lib/klear/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ File

Returns a new instance of File.



7
8
9
# File 'lib/klear/file.rb', line 7

def initialize path = nil
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/klear/file.rb', line 5

def path
  @path
end

Instance Method Details

#dimensionsObject



19
20
21
# File 'lib/klear/file.rb', line 19

def dimensions
  @dimensions ||= info['geometry']
end

#frame_countObject



23
24
25
# File 'lib/klear/file.rb', line 23

def frame_count
  @frame_count ||= (zipfile.dir.entries("/frames").size)
end

#framesObject



27
28
29
30
31
32
# File 'lib/klear/file.rb', line 27

def frames
  @frames ||= (
    data = zipfile.read("cache/frames.bin")
    Klear::Frames.new(dimensions[:columns], dimensions[:rows], data)
  )
end

#infoObject



11
12
13
# File 'lib/klear/file.rb', line 11

def info
  @info ||= YAML.load(zipfile.read('META-INF/kle.yml'))
end

#manifestObject



15
16
17
# File 'lib/klear/file.rb', line 15

def manifest
  @manifest ||= YAML.load(zipfile.read('META-INF/MANIFEST.MF'))
end

#motorsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/klear/file.rb', line 34

def motors
  @motors ||= (
    #begin 
    #  data = zipfile.read("cache/motors.bin")
    #  Klear::Motors.new(dimensions[:columns], data)
    ##rescue Errno::ENOENT => e
    #  puts " ~~ empty motors cache (#{e})"
    #  Klear::Motors.new(dimensions[:columns])
    #end

    motors = frames.all.map do |frame|
      (frame.row 0) # convention: row zero is the motors
    end
    Klear::Motors.new(dimensions[:columns], motors)

    #animations = {}
    #frames.each do |frame, no|
    #  puts "frame: ##{no}"
    #  row = (frame.row 0) # convention: row zero is the motors
#
#        # scale input onto manta geometry
#        low, high = @config[:low], @config[:high]
#        d = (high - low).to_f
#
#        row.each_with_index do |v_in, x|
#          v_out = (low + d * (v_in.value.to_f / 0xffff)).to_i
#          (animations[x+1] ||= []) << v_out
#        end
#      end
  )
end