Class: Pixo::Application

Inherits:
Native::Application show all
Defined in:
lib/pixo/application.rb

Defined Under Namespace

Classes: BlankPattern

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(full_screen = nil) ⇒ Application

Returns a new instance of Application.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pixo/application.rb', line 11

def initialize(full_screen = nil)
  super(full_screen)
  @procs = Concurrent::Array.new

  @procs_lock = Mutex.new
  @started_latch = Concurrent::CountDownLatch.new(1)
  @service = Pixo::Rpc::ApplicationService.new(STDIN, STDOUT, self, @started_latch)

  @patterns = Concurrent::Hash.new

  @active_pattern = BlankPattern.new
  self.running = false
  self.brightness = 1.0
  self.leds_on    = true
end

Instance Attribute Details

#leds_onObject

Returns the value of attribute leds_on.



8
9
10
# File 'lib/pixo/application.rb', line 8

def leds_on
  @leds_on
end

#patternsObject (readonly)

Returns the value of attribute patterns.



9
10
11
# File 'lib/pixo/application.rb', line 9

def patterns
  @patterns
end

#runningObject

Returns the value of attribute running.



8
9
10
# File 'lib/pixo/application.rb', line 8

def running
  @running
end

Instance Method Details

#add_fadecandy(hostname, count) ⇒ Object



51
52
53
# File 'lib/pixo/application.rb', line 51

def add_fadecandy(hostname, count)
  super(Pixo::Native::FadeCandy.new(hostname, count))
end

#add_pattern(name, code) ⇒ Object



47
48
49
# File 'lib/pixo/application.rb', line 47

def add_pattern(name, code)
  self.patterns[name] = Pixo::Native::Pattern.new(code)
end

#brightnessObject



86
87
88
# File 'lib/pixo/application.rb', line 86

def brightness
  leds_on ? @brightness : 0.0
end

#brightness=(val) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/pixo/application.rb', line 77

def brightness=(val)
  if val > 1.0
    val = 1.0
  elsif val < 0.0
    val = 0.0
  end
  @brightness = val
end

#key_callback(key, scancode, action, mods) ⇒ Object



61
62
63
# File 'lib/pixo/application.rb', line 61

def key_callback(key, scancode, action, mods)
  @service.request(Pixo::Rpc::OnKey.new(key, scancode, action, mods), async: true)
end

#patternObject



73
74
75
# File 'lib/pixo/application.rb', line 73

def pattern
  patterns.key(@active_pattern)
end

#pattern=(name) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/pixo/application.rb', line 65

def pattern=(name)
  pat = patterns[name]
  if (pat)
    pat.reset_start
    @active_pattern = pat
  end
end

#post(proc) ⇒ Object



55
56
57
58
59
# File 'lib/pixo/application.rb', line 55

def post(proc)
  @procs_lock.synchronize {
    @procs << proc
  }
end

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pixo/application.rb', line 27

def run
  self.running = tick(@active_pattern, brightness)
  @started_latch.count_down
  while(running)
    @procs_lock.synchronize {
      @procs.each {|proc| proc.call(self) }
      @procs.clear
    }

    self.running = tick(@active_pattern, brightness) && running
  end
ensure
  @service.shutdown
  close
end

#shutdownObject



43
44
45
# File 'lib/pixo/application.rb', line 43

def shutdown
  self.running = false
end