Class: Pixo::Application
- Inherits:
-
Native::Application
- Object
- Native::Application
- Pixo::Application
- Defined in:
- lib/pixo/application.rb
Instance Attribute Summary collapse
-
#leds_on ⇒ Object
Returns the value of attribute leds_on.
-
#running ⇒ Object
Returns the value of attribute running.
Class Method Summary collapse
Instance Method Summary collapse
- #active_pattern ⇒ Object
- #active_pattern=(pattern) ⇒ Object
- #brightness ⇒ Object
- #brightness=(val) ⇒ Object
- #patterns ⇒ Object
- #post(proc) ⇒ Object
- #random_pattern ⇒ Object
- #run ⇒ Object
- #shutdown ⇒ Object
Instance Attribute Details
#leds_on ⇒ Object
Returns the value of attribute leds_on.
8 9 10 |
# File 'lib/pixo/application.rb', line 8 def leds_on @leds_on end |
#running ⇒ Object
Returns the value of attribute running.
8 9 10 |
# File 'lib/pixo/application.rb', line 8 def running @running end |
Class Method Details
.instance ⇒ Object
10 11 12 |
# File 'lib/pixo/application.rb', line 10 def self.instance @instance ||= Pixo::Application.new end |
Instance Method Details
#active_pattern ⇒ Object
50 51 52 |
# File 'lib/pixo/application.rb', line 50 def active_pattern @active_pattern ||= random_pattern end |
#active_pattern=(pattern) ⇒ Object
58 59 60 61 |
# File 'lib/pixo/application.rb', line 58 def active_pattern=(pattern) pattern.reset_start @active_pattern = pattern end |
#brightness ⇒ Object
72 73 74 |
# File 'lib/pixo/application.rb', line 72 def brightness leds_on ? @brightness : 0.0 end |
#brightness=(val) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/pixo/application.rb', line 63 def brightness=(val) if val > 1.0 val = 1.0 elsif val < 0.0 val = 0.0 end @brightness = val end |
#patterns ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pixo/application.rb', line 38 def patterns unless @patterns @patterns = Hash.new patterns_dir = File.join(File.dirname(__FILE__), "..", "..", 'ext', 'pixo', 'patterns') Dir.entries(patterns_dir).each do | pattern_file| next unless pattern_file.end_with?('.glsl') @patterns[pattern_file] = Pixo::Native::Pattern.new(File.read(File.join(patterns_dir, pattern_file))) end end @patterns end |
#post(proc) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/pixo/application.rb', line 30 def post(proc) @procs_lock.synchronize { @procs << proc } end |
#random_pattern ⇒ Object
54 55 56 |
# File 'lib/pixo/application.rb', line 54 def random_pattern patterns[patterns.keys.sample] end |
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pixo/application.rb', line 14 def run while(running) @procs_lock.synchronize { @procs.each {|proc| proc.call(self) } @procs.clear } self.running = tick(active_pattern, brightness) && running end close end |
#shutdown ⇒ Object
26 27 28 |
# File 'lib/pixo/application.rb', line 26 def shutdown self.running = false end |