chiplotle-cli-wrapper 0.0.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.
data/bin/print_text.rb ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # example of a simple app that write text to a plotter
4
+ #
5
+
6
+ require 'chiplotle-cli-wrapper'
7
+
8
+ # FIXME: check args..
9
+ message = ARGV[0]
10
+ pen_no = ARGV[1]
11
+ height = ARGV[2]
12
+ width = ARGV[3]
13
+ x = ARGV[4]
14
+ y = ARGV[5]
15
+
16
+ plotter = ChiplotleCliWrapper::Plotter.new
17
+
18
+ plotter.debug = true
19
+
20
+ plotter.print_text(message, pen_no, height, width, x, y)
21
+
22
+ plotter.close
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module ChiplotleCliWrapper
4
+ class Plotter
5
+
6
+ attr_accessor :debug
7
+
8
+ def initialize(log_file = './log/chiplotle.log')
9
+
10
+ # FIXME: check for chiplotle installation
11
+
12
+ # FIXME: don't have a log file like this..
13
+
14
+ @chiplotle = IO.popen("chiplotle > ./log/chiplotle.log 2>&1", "w")
15
+ @log = File.open(log_file, "w+")
16
+ @debug = false
17
+
18
+ # wait for chiplotle to initialize plotter
19
+ @log.read.split('\n').each { |line| break if line == "chiplotle> " }
20
+ end
21
+
22
+ def log(message)
23
+ puts message if @debug
24
+ end
25
+
26
+ def close
27
+ # FIXME: perform any reset actions...
28
+
29
+ @chiplotle.close
30
+ @log.close
31
+ end
32
+
33
+ def plotter(command)
34
+ log "plotter.write(#{command})"
35
+
36
+ @chiplotle.puts "plotter.write(#{command})"
37
+
38
+ #"oh no! #{@log.read}" if @log.read != "chiplotle> "
39
+ end
40
+
41
+ def pen(pen_no)
42
+ plotter "hpgl.SP(#{pen_no})"
43
+ end
44
+
45
+ def position(x, y)
46
+ plotter "hpgl.PA([(#{x}, #{y})])"
47
+ end
48
+
49
+ def label(text)
50
+ plotter "hpgl.LB('#{text}')"
51
+ end
52
+
53
+ def label_size(height, width)
54
+ plotter "hpgl.SI(#{height}, #{width})"
55
+ end
56
+
57
+ def label_size_reset
58
+ plotter "hpgl.SI()"
59
+ end
60
+
61
+ def replace_pen
62
+ pen(0)
63
+ end
64
+
65
+ def print_text(text, pen_no, height, width, x, y)
66
+
67
+ # pick up a pen
68
+ pen(pen_no)
69
+
70
+ # scale label
71
+ label_size(height, width)
72
+
73
+ # move to position
74
+ position(x, y)
75
+
76
+ # print message
77
+ label(text)
78
+
79
+ # reset text size
80
+ label_size_reset
81
+
82
+ # replace pen
83
+ replace_pen
84
+ end
85
+
86
+ def write_hgpl(hgpl)
87
+ hgpl.each do |command|
88
+ plotter(command)
89
+ end
90
+ end
91
+
92
+ def write_file(file)
93
+ # FIXME
94
+ end
95
+ end
96
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chiplotle-cli-wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rob Wilson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A Wrapper for the chiplotle command line interface to the Chiplotle python
15
+ library
16
+ email: roobert@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/chiplotle-cli-wrapper.rb
22
+ - bin/print_text.rb
23
+ homepage: http://github.com/roobert/chiplotle-cli-wrapper
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.23
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Wrapper for chiplotle-cli
47
+ test_files: []