memopri 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ac58d6086b19b85df3c802091323708b461cf92e
4
+ data.tar.gz: b64317f3ad396666c6170784ee38a685b064c99c
5
+ SHA512:
6
+ metadata.gz: b2e78b0ee4e1568e1a1a8e8f7722ae5aae25d0784624241886def7004295d1ba07e696d1c9b370fad6b47747afa93e073e64015912f7d688988b1003c0ba5816
7
+ data.tar.gz: 28763d0f0d37779045bbbd8b1d180112a35f0b0d58b36feb399c10256a91fc41dc0e3e36e9d753823861ca7b8ce36a9b9a234885acd255510daebab77847b3ff
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in memopri.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Hiroyuki Ikegami
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # CLI Utility for Memopri MEP-F10
2
+
3
+ This is a command line based application to use Casio's Memopri (MEP-F10).
4
+
5
+ # Installation
6
+
7
+ * gem install memopri
8
+
9
+ # Usage
10
+
11
+ * echo -e "hoge\nhoge" | memopri
12
+
13
+ # Test environment
14
+
15
+ Debian GNU/Linux w/ ruby 2.1.5p273 (2014-11-13) [x86-64-linux-gnu]
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/memopri ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'memopri/finder.rb'
4
+ require 'memopri/printer.rb'
5
+ require 'memopri/renderer.rb'
6
+ require 'memopri/version.rb'
7
+
8
+ require 'optparse'
9
+
10
+ devices = Memopri::Finder.find
11
+ device = nil
12
+ noline = 1
13
+
14
+ if devices == nil
15
+ exit -1
16
+ end
17
+
18
+ opt = OptionParser.new
19
+
20
+ opt.on('-d VAL'){|v|
21
+ device = devices[v.to_i]
22
+ }
23
+
24
+ opt.on('-l'){|v|
25
+ p devices
26
+ exit 0
27
+ }
28
+
29
+ opt.parse!(ARGV)
30
+
31
+ if device == nil
32
+ device = devices[0]
33
+ end
34
+
35
+ line = STDIN.readlines.join().chomp
36
+ if line == ""
37
+ exit -1
38
+ end
39
+
40
+ str_data = Memopri::Renderer.new(line)
41
+ memopri = Memopri::Printer.new(device[1][-1])
42
+ memopri.print(str_data.conv)
data/lib/label.png ADDED
Binary file
@@ -0,0 +1,21 @@
1
+ require 'socket'
2
+
3
+ class Memopri
4
+ class Finder
5
+ def self.find
6
+ sendsocket = UDPSocket.new()
7
+ recvsocket = UDPSocket.new()
8
+ recvsocket.bind("0.0.0.0", 49168)
9
+ sendsocket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
10
+ recvsocket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
11
+
12
+ sendsocket.connect("255.255.255.255", 49167)
13
+ sendsocket.send("MEP r2", 0)
14
+ return [recvsocket.recvfrom(47)]
15
+ end
16
+ end
17
+ end
18
+
19
+ if $0 == __FILE__
20
+ p Memopri::Finder.find
21
+ end
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'socket' # Sockets are in standard library
4
+
5
+ class Memopri
6
+ class Printer
7
+
8
+ def initialize(host, port=16402)
9
+ @hostname = host
10
+ @port = port
11
+ @socket = TCPSocket.open(@hostname, @port)
12
+ end
13
+
14
+ def _send(cmd)
15
+ cmd = cmd.pack('C*')
16
+ @socket.write(cmd)
17
+ @socket.flush()
18
+ end
19
+
20
+ def _recv(len)
21
+ return @socket.read(len)
22
+ end
23
+
24
+ def print(data)
25
+ cmd = [0x1b, 0x5a]
26
+ _send(cmd)
27
+ _recv(1)
28
+
29
+ cmd = [0x05]
30
+ _send(cmd)
31
+ _recv(6)
32
+
33
+ cmd = [0x06]
34
+ _send(cmd)
35
+ _recv(1)
36
+
37
+ cmd = [0x1b, 0x49]
38
+ _send(cmd)
39
+ _recv(1)
40
+
41
+ cmd = [0x05]
42
+ _send(cmd)
43
+ _recv(8)
44
+
45
+ cmd = [0x06]
46
+ _send(cmd)
47
+ _recv(1)
48
+
49
+ cmd = [0x1b, 0x50]
50
+ _send(cmd)
51
+ _recv(1)
52
+
53
+ length = data.size
54
+
55
+ cmd = [
56
+ 0x02, 0x80, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x02,
57
+ 0x80, 0x00,
58
+ (length/16) & 0x00FF, ((length/16) >> 8) & 0x00FF,
59
+ (length) & 0x00FF, ((length) >> 8) & 0x00FF,
60
+ 0x00, 0x00,
61
+ ]
62
+ _send(cmd)
63
+ _recv(1)
64
+
65
+ cmd = [0x1b, 0x56]
66
+ _send(cmd)
67
+ _recv(1)
68
+
69
+ data.each_slice(64){|x|
70
+ _send(x)
71
+ _recv(1)
72
+ }
73
+
74
+ cmd = [0x1b, 0x42]
75
+ _send(cmd)
76
+ _recv(1)
77
+ end
78
+ end
79
+ end
80
+
81
+
82
+ if $0 == __FILE__
83
+ memo=Memopri::Printer.new("192.168.0.74")
84
+ buf=[]
85
+ data=[]
86
+ (128*128).times{
87
+ buf.push(1)
88
+ }
89
+ buf.each_slice(8){|x|
90
+ data.push([x.join()].pack("B*"))
91
+ }
92
+ data = data.map{|x| x.unpack("C*")[0]}
93
+ memo.print(data)
94
+ end
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'cairo'
4
+ require 'pango'
5
+
6
+ class Memopri
7
+ class Renderer
8
+
9
+ attr_accessor :str, :nol
10
+
11
+ def initialize(str="")
12
+ @str = str
13
+ end
14
+
15
+ def conv()
16
+ format = Cairo::FORMAT_ARGB32
17
+ width = nil
18
+ height = 128
19
+ surface = Cairo::ImageSurface.new(format, 0, 128)
20
+ context = Cairo::Context.new(surface)
21
+ layout = context.create_pango_layout
22
+ layout.text = str
23
+ font_description = Pango::FontDescription.new("Sans-serif 18")
24
+
25
+ size = nil
26
+ begin
27
+ font_description.size *= 1.06
28
+ layout.font_description = font_description
29
+ size = layout.size.map{|x| x/Pango::SCALE}
30
+ end while size[1] <= 111
31
+
32
+ width = size[0] + 5
33
+
34
+ surface = Cairo::ImageSurface.new(format, width, 128)
35
+ context = Cairo::Context.new(surface)
36
+ layout = context.create_pango_layout
37
+ layout.text = str
38
+ #layout.width = width * Pango::SCALE * 0.9
39
+ layout.wrap = Pango::WRAP_CHAR
40
+ layout.font_description = font_description
41
+ context.translate(0, 7)
42
+ context.show_pango_layout(layout)
43
+ context.show_page
44
+
45
+ surface.write_to_png("/tmp/hinomaru.png")
46
+
47
+ data = []
48
+
49
+ surface.data.unpack("C*").each_slice(4) {|x|
50
+ x = x[3] > 10 ? 1 : 0
51
+ data.push(x)
52
+ }
53
+
54
+ data2 = []
55
+ data.each_slice(width) {|x|
56
+ data2.push(x)
57
+ }
58
+ data = data2.transpose.flatten
59
+
60
+ ret = []
61
+ data.each_slice(8) {|x|
62
+ ret.push([x.join()].pack("B*"))
63
+ }
64
+ ret = ret.map{|x| x.unpack("C*")[0]}
65
+ return ret
66
+ end
67
+ end
68
+ end
69
+
70
+ if $0 == __FILE__
71
+ r = Memopri::Renderer.new("aaa\naa\naaa")
72
+ r.conv()
73
+ end
@@ -0,0 +1,3 @@
1
+ class Memopri
2
+ VERSION = "0.0.1"
3
+ end
data/memopri.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'memopri/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "memopri"
8
+ spec.version = Memopri::VERSION
9
+ spec.authors = ["Hiroyuki Ikegami"]
10
+ spec.email = ["ikegam@mixallow.net"]
11
+ spec.summary = %q{Client software for CASIO Memopri MEP-F10}
12
+ spec.description = %q{Client software for CASIO Memopri MEP-F10}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.executables << 'memopri'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_dependency "cairo"
26
+ spec.add_dependency "pango"
27
+ end
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'socket' # Sockets are in standard library
4
+
5
+ hostname = '192.168.0.74'
6
+ port = 16402
7
+
8
+ s = TCPSocket.open(hostname, port)
9
+ cmd = [0x1b, 0x5a].pack('C*')
10
+ s.write(cmd)
11
+ s.flush()
12
+ line = s.read(1) # Read lines from the socket
13
+ p line
14
+
15
+ cmd = [0x05].pack('C*')
16
+ s.write(cmd)
17
+ s.flush()
18
+ line = s.read(6) # Read lines from the socket
19
+ p line
20
+
21
+ cmd = [0x06].pack('C*')
22
+ s.write(cmd)
23
+ s.flush()
24
+ line = s.read(1) # Read lines from the socket
25
+ p line
26
+
27
+ cmd = [0x1b, 0x49].pack('C*')
28
+ s.write(cmd)
29
+ s.flush()
30
+ line = s.read(1) # Read lines from the socket
31
+ p line
32
+
33
+ cmd = [0x05].pack('C*')
34
+ s.write(cmd)
35
+ s.flush()
36
+ line = s.read(8) # Read lines from the socket
37
+ p line
38
+
39
+ cmd = [0x06].pack('C*')
40
+ s.write(cmd)
41
+ s.flush()
42
+ line = s.read(1) # Read lines from the socket
43
+ p line
44
+
45
+ cmd = [0x1b, 0x46].pack('C*')
46
+ s.write(cmd)
47
+ s.flush()
48
+ line = s.read(1) # Read lines from the socket
49
+ p line
50
+
51
+ cmd = [0x05].pack('C*')
52
+ s.write(cmd)
53
+ s.flush()
54
+ line = s.read(8) # Read lines from the socket
55
+ p line
56
+
57
+ cmd = [0x06].pack('C*')
58
+ s.write(cmd)
59
+ s.flush()
60
+ line = s.read(1) # Read lines from the socket
61
+ p line
62
+
63
+ cmd = [0x1b, 0x50].pack('C*')
64
+ s.write(cmd)
65
+ s.flush()
66
+ line = s.read(1) # Read lines from the socket
67
+ p line
68
+
69
+ cmd = [
70
+ 0x02, 0x80, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x02,
71
+ # 0x80, 0x00, 0x2b, 0x00, 0xb0, 0x02, 0x00, 0x00,
72
+ # 0x80, 0x00, 0x55, 0x00, 0x50, 0x05, 0x00, 0x00,
73
+ # 0x80, 0x00, 0xa9, 0x00, 0x90, 0x0a, 0x00, 0x00,
74
+ # 0x80, 0x00, 0xfd, 0x00, 0xd0, 0x0f, 0x00, 0x00,
75
+ # 0x80, 0x00, rows(L:H), allbyte(L:H), 0x00, 0x00,
76
+ #0x80, 0x00, 0x51, 0x01, 0x10, 0x15, 0x00, 0x00,
77
+ 0x80, 0x00, 0xF4, 0x01, 0x40, 0x1F, 0x00, 0x00,
78
+ ].pack('C*')
79
+ s.write(cmd)
80
+ s.flush()
81
+ line = s.read(1) # Read lines from the socket
82
+ p line
83
+
84
+ cmd = [0x1b, 0x56].pack('C*')
85
+ s.write(cmd)
86
+ s.flush()
87
+ line = s.read(1) # Read lines from the socket
88
+ p line
89
+
90
+ require 'cairo'
91
+ require 'pango'
92
+
93
+ format = Cairo::FORMAT_ARGB32
94
+ width = 500
95
+ height = 128
96
+
97
+ surface = Cairo::ImageSurface.new(format, width, height)
98
+ context = Cairo::Context.new(surface)
99
+
100
+ font_description = Pango::FontDescription.new("Sans-serif 18")
101
+ 5.times {
102
+ font_description.size *= 1.06
103
+ }
104
+ layout = context.create_pango_layout
105
+ layout.font_description = font_description
106
+ layout.text = "あああ"
107
+ context.translate(0, 10)
108
+ context.show_pango_layout(layout)
109
+ context.show_page
110
+
111
+ surface.write_to_png("label.png")
112
+ data = []
113
+
114
+ surface.data.unpack("C*").each_slice(4) {|x|
115
+ x = x[3] > 0 ? 1 : 0
116
+ data.push(x)
117
+ }
118
+
119
+ data2 = []
120
+ data.each_slice(500) {|x|
121
+ data2.push(x)
122
+ }
123
+
124
+ data = data2.transpose.flatten
125
+
126
+ ret = []
127
+ data.each_slice(8) {|x|
128
+ #ret += x.join().unpack("C")
129
+ ret.push([x.join()].pack("B*"))
130
+ }
131
+
132
+ p ret.size
133
+
134
+ i=0
135
+ ret.each_slice(64){|x|
136
+ cmd = x.join()
137
+ p i+=1
138
+ s.write(cmd)
139
+ s.flush()
140
+ line = s.read(1) # Read lines from the socket
141
+ p line
142
+ }
143
+
144
+ cmd = [0x1b, 0x42].pack('C*')
145
+ s.write(cmd)
146
+ s.flush()
147
+ line = s.read(1) # Read lines from the socket
148
+ p line
149
+
150
+ s.close # Close the socket when done
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memopri
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hiroyuki Ikegami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cairo
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pango
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Client software for CASIO Memopri MEP-F10
70
+ email:
71
+ - ikegam@mixallow.net
72
+ executables:
73
+ - memopri
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/memopri
83
+ - lib/label.png
84
+ - lib/memopri/finder.rb
85
+ - lib/memopri/printer.rb
86
+ - lib/memopri/renderer.rb
87
+ - lib/memopri/version.rb
88
+ - memopri.gemspec
89
+ - sample/test-print.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Client software for CASIO Memopri MEP-F10
114
+ test_files: []