pixo 0.2.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75fb2c5c0651d7735b03609db63ad188253e78a9
4
- data.tar.gz: db5e21e1f9965f1c1f7c3a530666232e9e8d9ba4
3
+ metadata.gz: 6b6f02aec4edb8967668a68b0e5e82d06989a41a
4
+ data.tar.gz: e7722d6196838c3dc7f3e8c15f04318737f161b0
5
5
  SHA512:
6
- metadata.gz: 0426b2618eee3d91704d99e61bf4747d5f42c0f1aa2f1927989a8885d726b83ad8675e7bb3525588326cc0f1f0b0caf1536345551ad88b1987bc7e405ac2f95a
7
- data.tar.gz: 2052de8af02515ebc49206fcb22855c61b5919f1ed9e5b60424e5f1a80f4df9ad3d7e4bddcc258f216e642837b88bb7c6703bf686d704fd7f57c591497f3e1da
6
+ metadata.gz: 901ba8065c211abf4e5382139e279ee315befbe652d0743e2bd61816f2984fe20da791f0bd9fbedd601346e234c6c3ffd02f11c08354b306418df282fa97f81d
7
+ data.tar.gz: 4a6474b8ea8552582c4e6509debc6bd93e2f884d399f54d274765aa4ecd02da7fd793bb07f891af6a4084a769ecce12c7bb2d2281993502ffc0a44814874aa54
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pixo (0.2.6)
4
+ pixo (0.3.0)
5
5
  concurrent-ruby
6
6
 
7
7
  GEM
data/exe/pixo CHANGED
@@ -3,12 +3,8 @@
3
3
  require 'pixo'
4
4
  require 'pixo/application'
5
5
 
6
- app = Pixo::Application.instance
6
+ app = Pixo::Application.new
7
7
 
8
- service_thread = Thread.new do
9
- Pixo::Ipc::Service.new(STDIN, STDOUT).run
10
- app.shutdown
11
- end
12
8
  Signal.trap('INT') { app.shutdown }
13
9
  Signal.trap('TERM') { app.shutdown }
14
10
 
@@ -78,6 +78,8 @@ VALUE application_initialize(VALUE self)
78
78
  ApplicationHolder * holder;
79
79
 
80
80
  Data_Get_Struct(self, ApplicationHolder, holder);
81
+
82
+ holder->self = self;
81
83
 
82
84
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
83
85
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
@@ -101,9 +103,24 @@ VALUE application_initialize(VALUE self)
101
103
  }
102
104
 
103
105
  holder->app = new App();
106
+ glfwSetWindowUserPointer(holder->window, holder);
107
+
108
+ glfwSetKeyCallback(holder->window,
109
+ [](GLFWwindow *window, int key, int scancode, int action, int mods) {
110
+ if (action == GLFW_REPEAT) {
111
+ return;
112
+ }
113
+
114
+ ApplicationHolder *holder = (ApplicationHolder *)glfwGetWindowUserPointer(window);
115
+
116
+ rb_funcall(holder->self, rb_intern("key_callback"), 4, INT2NUM(key), INT2NUM(scancode), INT2NUM(action), INT2NUM(mods));
117
+ });
104
118
  return self;
105
119
  }
106
120
 
121
+ VALUE application_key_callback(VALUE self, VALUE key, VALUE scancode, VALUE action, VALUE mods)
122
+ { }
123
+
107
124
  VALUE application_tick(VALUE self, VALUE r_pattern, VALUE r_brightness)
108
125
  {
109
126
  GLenum glErr;
@@ -17,10 +17,14 @@ public:
17
17
  GLFWwindow* window;
18
18
 
19
19
  std::vector<VALUE> fade_candies;
20
+
21
+ VALUE self;
20
22
  };
21
23
 
22
24
  VALUE application_allocate(VALUE klass);
23
25
 
26
+ VALUE application_key_callback(VALUE self, VALUE key, VALUE scancode, VALUE action, VALUE mods);
27
+
24
28
  VALUE application_close(VALUE self);
25
29
 
26
30
  VALUE application_initialize(VALUE self);
@@ -46,6 +46,7 @@ extern "C" void Init_libpixgem() {
46
46
  rb_define_method(ApplicationClass, "initialize", (VALUE(*)(ANYARGS))application_initialize, 0);
47
47
  rb_define_method(ApplicationClass, "close", (VALUE(*)(ANYARGS))application_close, 0);
48
48
  rb_define_method(ApplicationClass, "tick", (VALUE(*)(ANYARGS))application_tick, 2);
49
+ rb_define_method(ApplicationClass, "key_callback", (VALUE(*)(ANYARGS))application_key_callback, 4);
49
50
  rb_define_method(ApplicationClass, "add_fadecandy", (VALUE(*)(ANYARGS))application_add_fadecandy, 1);
50
51
 
51
52
  VALUE FadeCandyClass = rb_define_class_under(Native, "FadeCandy", rb_cObject);
@@ -23,6 +23,7 @@ namespace Pixlib {
23
23
 
24
24
  out vec2 TexCoords;
25
25
  out vec3 Normal;
26
+ out vec4 Position;
26
27
 
27
28
  uniform mat4 view;
28
29
  uniform mat4 projection;
@@ -34,6 +35,7 @@ namespace Pixlib {
34
35
  gl_Position = projection * view * positionOffset * vec4(position, 1.0f);
35
36
  TexCoords = texCoords + texCoordsOffset;
36
37
  Normal = normal;
38
+ Position = positionOffset*vec4(position, 1.0f);
37
39
  })",
38
40
  R"(#version 330 core
39
41
 
@@ -42,6 +44,7 @@ namespace Pixlib {
42
44
  #endif
43
45
 
44
46
  in vec2 TexCoords;
47
+ in vec3 Position;
45
48
 
46
49
  out vec4 color;
47
50
 
@@ -7,11 +7,29 @@ module Pixo
7
7
  class Application < Pixo::Native::Application
8
8
  attr_accessor :running, :leds_on
9
9
 
10
- def self.instance
11
- @instance ||= Pixo::Application.new
10
+ def initialize()
11
+ super
12
+ self.running = false
13
+ self.brightness = 1.0
14
+ self.leds_on = true
15
+ @procs = Array.new
16
+
17
+ @procs_lock = Mutex.new
18
+
19
+ @service = Pixo::Ipc::Service.new(STDIN, STDOUT, user_data: self)
20
+
21
+ @service_thread = Thread.new do
22
+ while(!self.running)
23
+ sleep 0.1
24
+ end
25
+ @service.run
26
+ self.shutdown
27
+ end
12
28
  end
13
29
 
14
30
  def run
31
+ self.running = tick(active_pattern, brightness)
32
+
15
33
  while(running)
16
34
  @procs_lock.synchronize {
17
35
  @procs.each {|proc| proc.call(self) }
@@ -29,12 +47,14 @@ module Pixo
29
47
  end
30
48
 
31
49
  def post(proc)
32
-
33
50
  @procs_lock.synchronize {
34
51
  @procs << proc
35
52
  }
36
53
  end
37
54
 
55
+ def key_callback(key, scancode, action, mods)
56
+ @service.request(Pixo::Renderer::OnKey.new(key, scancode, action, mods))
57
+ end
38
58
 
39
59
  def patterns
40
60
  unless @patterns
@@ -74,18 +94,12 @@ module Pixo
74
94
  leds_on ? @brightness : 0.0
75
95
  end
76
96
 
77
- private
97
+ private
98
+
78
99
 
79
- def initialize()
80
- super
81
- self.running = true
82
- self.brightness = 1.0
83
- self.leds_on = true
84
- @procs = Array.new
85
100
 
86
- @procs_lock = Mutex.new
87
- #
88
- end
89
101
  end
102
+
103
+
90
104
  end
91
105
 
@@ -5,21 +5,25 @@ require 'thread'
5
5
 
6
6
  module Pixo::Ipc
7
7
  class Service
8
+ attr_reader :user_data
8
9
 
9
- def initialize(reader_pipe, writer_pipe)
10
+ def initialize(reader_pipe, writer_pipe, user_data: nil)
10
11
  @reader_pipe = reader_pipe
11
12
  @writer_pipe = writer_pipe
13
+
12
14
  @running = true
13
15
  @live_requests = Concurrent::Hash.new
14
16
 
15
17
  @pipe_mutex = Mutex.new
18
+
19
+ @user_data = user_data
16
20
  end
17
21
 
18
22
  def run
19
23
  while @running && (line = @reader_pipe.readline)
20
24
  message = Marshal.load(Base64.strict_decode64(line.strip))
21
25
  if message.is_a?(Pixo::Ipc::RequestMessage)
22
- resp = Pixo::Ipc::ResponseMessage.new(message.data.call, message.rid)
26
+ resp = Pixo::Ipc::ResponseMessage.new(message.data.call(self), message.rid)
23
27
 
24
28
  bytes_to_write = Base64.strict_encode64(Marshal.dump(resp))
25
29
  @pipe_mutex.synchronize do
@@ -33,8 +37,8 @@ module Pixo::Ipc
33
37
  request.send_result(message.data) if request
34
38
  end
35
39
  end
36
- rescue EOFError
37
- rescue IOError
40
+ rescue EOFError => e
41
+ rescue IOError => e
38
42
  end
39
43
 
40
44
  def shutdown
@@ -43,16 +47,19 @@ module Pixo::Ipc
43
47
  @writer_pipe.close
44
48
  end
45
49
 
46
- def request(message, timeout: nil)
50
+ def request(message, timeout: 10)
47
51
  request = Pixo::Ipc::Request.new(message)
48
52
  @live_requests[request.message.rid] = request
49
53
 
50
- @writer_pipe.write(Base64.strict_encode64(Marshal.dump(request.message)))
51
- @writer_pipe.write($/)
52
- @writer_pipe.flush
54
+ bytes_to_write = Base64.strict_encode64(Marshal.dump(request.message))
55
+ @pipe_mutex.synchronize do
56
+ @writer_pipe.write(bytes_to_write)
57
+ @writer_pipe.write($/)
58
+ @writer_pipe.flush
59
+ end
53
60
 
54
61
  unless request.latch.wait(timeout)
55
- raise Timeout::Error.new("%s: request timed out after %.3f seconds." % [request.rid, timeout] )
62
+ raise Timeout::Error.new("%s: request timed out after %.3f seconds." % [request.message.rid, timeout] )
56
63
  end
57
64
 
58
65
  return request.response
data/lib/pixo/renderer.rb CHANGED
@@ -2,10 +2,43 @@ module Pixo
2
2
  class Renderer
3
3
  attr_reader :service, :service_thread
4
4
 
5
- def initialize()
6
- i, o, t = Open3.popen2('bundle exec pixo')
7
- @service = Pixo::Ipc::Service.new(o, i)
8
- @service_thread = Thread.new { self.service.run }
5
+ class OnKey
6
+ def initialize(key, scancode, action, mods)
7
+ @key = key
8
+ @scancode = scancode
9
+ @action = action
10
+ @mods = mods
11
+ end
12
+
13
+ def call(service)
14
+ service.on_key(@key, @scancode, @action, @mods)
15
+ self
16
+ end
17
+ end
18
+
19
+ class Service < Pixo::Ipc::Service
20
+ attr_reader :renderer
21
+
22
+ def initialize(renderer)
23
+ @renderer = renderer
24
+ i, o, t = Open3.popen2('bundle exec pixo')
25
+ super(o, i)
26
+ @service_thread = Thread.new { self.run }
27
+ end
28
+
29
+
30
+ def on_key(key, scancode, action, mods)
31
+ renderer.on_key(key, scancode, action, mods)
32
+ end
33
+
34
+ end
35
+
36
+ def initialize
37
+ @service = Pixo::Renderer::Service.new(self)
38
+ end
39
+
40
+ def on_key(key, scancode, action, mods)
41
+
9
42
  end
10
43
 
11
44
  def pattern_names
@@ -48,39 +81,39 @@ module Pixo
48
81
  @count = count
49
82
  end
50
83
 
51
- def call
52
- Pixo::Application.instance.post Proc.new { |app| app.add_fadecandy(Pixo::Native::FadeCandy.new(@hostname, @count)) }
84
+ def call(service)
85
+ service.user_data.post Proc.new { |app| app.add_fadecandy(Pixo::Native::FadeCandy.new(@hostname, @count)) }
53
86
  self
54
87
  end
55
88
  end
56
89
 
57
90
  class GetPatternName
58
- def call
59
- Pixo::Application.instance.patterns.key(Pixo::Application.instance.active_pattern)
91
+ def call(service)
92
+ service.user_data.patterns.key(service.user_data.active_pattern)
60
93
  end
61
94
  end
62
95
 
63
96
  class GetPatternNames
64
- def call
65
- Pixo::Application.instance.patterns.keys
97
+ def call(service)
98
+ service.user_data.patterns.keys
66
99
  end
67
100
  end
68
101
 
69
102
  class SetPattern
70
- def initialize(pattern_name)
103
+ def initialize(pattern_name = nil)
71
104
  @pattern_name = pattern_name
72
105
  end
73
106
 
74
- def call
75
- pattern = Pixo::Application.instance.patterns[@pattern_name]
76
- Pixo::Application.instance.active_pattern = pattern if pattern
107
+ def call(service)
108
+ pattern = service.user_data.patterns[@pattern_name]
109
+ service.user_data.active_pattern = pattern
77
110
  @pattern_name
78
111
  end
79
112
  end
80
113
 
81
114
  class GetBrightness
82
- def call
83
- Pixo::Application.instance.brightness
115
+ def call(service)
116
+ service.user_data.brightness
84
117
  end
85
118
  end
86
119
 
@@ -89,15 +122,15 @@ module Pixo
89
122
  @brightness = brightness
90
123
  end
91
124
 
92
- def call
93
- Pixo::Application.instance.brightness = @brightness
125
+ def call(service)
126
+ service.user_data.brightness = @brightness
94
127
  end
95
128
  end
96
129
 
97
130
 
98
131
  class GetLedsOn
99
- def call
100
- Pixo::Application.instance.leds_on
132
+ def call(service)
133
+ service.user_data.leds_on
101
134
  end
102
135
  end
103
136
 
@@ -106,8 +139,8 @@ module Pixo
106
139
  @leds_on = leds_on
107
140
  end
108
141
 
109
- def call
110
- Pixo::Application.instance.leds_on = @leds_on
142
+ def call(service)
143
+ service.user_data.leds_on = @leds_on
111
144
  end
112
145
  end
113
146
 
data/lib/pixo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pixo
2
- VERSION = "0.2.6"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Constantine
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby