mono_matrix 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69a6c8a4696bbb3f2faafd3c5c8fc49d4adbe3c1
4
- data.tar.gz: 0ce65f1593eead9df1850f28f316ec5b54d74a22
3
+ metadata.gz: 3ebd7171772c374bf391382184333397d0d94dae
4
+ data.tar.gz: 957c1fcddb1b74387115f350845dbb71eabc15b1
5
5
  SHA512:
6
- metadata.gz: 2a96ccfe64a2af2baf48cb20be097b56abeb92d957198f1cb7385d32cbc49baedc9dd9c22462cfca2d1464f989069bdd7dcd94e4db341b3b9525d83ff1c9ffc7
7
- data.tar.gz: 0e3ca4efeda6515029747f47fe155a04a9df562ffe2e656960c8178f0181043a28d50eb3e7b41a9077e60207e9b8c5bf9a1c3dac932fbb08f3aa2de36fb55ad7
6
+ metadata.gz: 962b6aa8aace3c5b6e3f598f6e0def48a55a3422af2eb074280e23294ca4926dcc0087a89be727968acee0d5b5ee10aa0afeafa0d3f6654a2f94e62b608f228c
7
+ data.tar.gz: 235a06482e0562cbf269d97a327625dc7f8e97a317212296267480f4379c990339df626be2ab0a39e92ead87839d630ecee3e23a5891a7840924a1165391bbba
data/.semver CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
- :major: 0
2
+ :major: 1
3
3
  :minor: 0
4
- :patch: 3
4
+ :patch: 0
5
5
  :special: ''
6
6
  :metadata: ''
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # mono_matrix
2
+ [![Gem Version](https://badge.fury.io/rb/mono_matrix.svg)](http://badge.fury.io/rb/mono_matrix)
2
3
 
3
- A simple way to control your Monoprice HDX 4x2 Switcher/Splitter
4
+ A simple way to control your Monoprice HDX 4x2 Switcher/Splitter. Originally created for
5
+ https://github.com/defektive/hdx-api
6
+
7
+ [![Code Climate](https://codeclimate.com/github/defektive/mono_matrix/badges/gpa.svg)](https://codeclimate.com/github/defektive/mono_matrix)
4
8
 
5
9
  ## Installation
6
10
 
@@ -20,7 +24,7 @@ $ gem install monoprice_matrix
20
24
 
21
25
  ```
22
26
 
23
- matrix = MonoMatrix.new "/dev/ttyUSB0"
27
+ matrix = MonoMatrix::Switcher.new "/dev/ttyUSB0"
24
28
 
25
29
  # set output A to use input 1
26
30
  matrix.switch "A", 1
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mono_matrix/console'
4
+
5
+ MonoMatrix::Console.start(ARGV)
@@ -1,54 +1,55 @@
1
-
2
1
  require 'serialport'
3
2
 
4
- class MonoMatrix
5
3
 
6
- def initialize(tty)
7
- # Instance variables
8
- @tty = tty
9
- end
4
+ module MonoMatrix
5
+ class Switcher
10
6
 
11
- def switch(channel, input)
12
-
13
- # A = 1 "\x00\xFF\xD5\x7B";
14
- # A = 2 "\x01\xFE\xD5\x7B";
15
- # A = 3 "\x02\xFD\xD5\x7B";
16
- # A = 4 "\x03\xFC\xD5\x7B";
17
- # B = 1 "\x04\xFB\xD5\x7B";
18
- # B = 2 "\x05\xFA\xD5\x7B";
19
- # B = 3 "\x06\xF9\xD5\x7B";
20
- # B = 4 "\x07\xF8\xD5\x7B";
21
-
22
- end_bytes = ["\xD5","\x7B"]
23
- if channel == "A"
24
- case input
25
- when 1
26
- bytes = ["\x00", "\xFF"] + end_bytes
27
- when 2
28
- bytes = ["\x01", "\xFE"] + end_bytes
29
- when 3
30
- bytes = ["\x02", "\xFD"] + end_bytes
31
- when 4
32
- bytes = ["\x03", "\xFC"] + end_bytes
33
- end
7
+ def initialize(tty)
8
+ # Instance variables
9
+ @tty = tty
10
+
11
+
12
+ @end_bytes = ["\xD5","\x7B"]
13
+ @channels = {
14
+ "A" => [
15
+ ["\x00", "\xFF"],
16
+ ["\x01", "\xFE"],
17
+ ["\x02", "\xFD"],
18
+ ["\x03", "\xFC"]
19
+ ],
20
+
21
+ "B" => [
22
+ ["\x04", "\xFB"],
23
+ ["\x05", "\xFA"],
24
+ ["\x06", "\xF9"],
25
+ ["\x07", "\xF8"]
26
+ ]
27
+ }
28
+ end
29
+
30
+ def switch(channel, input)
31
+ channel = channel.upcase
32
+ input = input.to_i - 1
33
+
34
+ # A = 1 "\x00\xFF\xD5\x7B";
35
+ # A = 2 "\x01\xFE\xD5\x7B";
36
+ # A = 3 "\x02\xFD\xD5\x7B";
37
+ # A = 4 "\x03\xFC\xD5\x7B";
38
+ # B = 1 "\x04\xFB\xD5\x7B";
39
+ # B = 2 "\x05\xFA\xD5\x7B";
40
+ # B = 3 "\x06\xF9\xD5\x7B";
41
+ # B = 4 "\x07\xF8\xD5\x7B";
34
42
 
35
- elsif channel == "B"
36
- case input
37
- when 1
38
- bytes = ["\x04", "\xFB"] + end_bytes
39
- when 2
40
- bytes = ["\x05", "\xFA"] + end_bytes
41
- when 3
42
- bytes = ["\x06", "\xF9"] + end_bytes
43
- when 4
44
- bytes = ["\x07", "\xF8"] + end_bytes
43
+
44
+ bytes = @channels[channel][input] + @end_bytes if @channels[channel] && @channels[channel][input]
45
+
46
+ if bytes
47
+ puts channel +" to "+ input.to_s
48
+ serialConnection = SerialPort.new @tty, 9600
49
+ bytes.each {|byte| serialConnection.write byte}
50
+ bytes.each {|byte| serialConnection.write byte}
51
+ serialConnection.close
45
52
  end
46
53
  end
47
- puts channel +" to "+ input.to_s
48
- serialConnection = SerialPort.new @tty, 9600
49
- bytes.each {|byte| serialConnection.write byte}
50
- bytes.each {|byte| serialConnection.write byte}
51
- serialConnection.close
52
54
  end
53
-
54
- end
55
+ end
@@ -0,0 +1,13 @@
1
+ require 'thor'
2
+ require 'mono_matrix'
3
+
4
+ module MonoMatrix
5
+ class Console < Thor
6
+ desc "example FILE", "an example task"
7
+ method_option :device, :aliases => "-d", :desc => "Set the serial device to use", :default => "/dev/ttyAMA0"
8
+ def switch(output, input)
9
+ m = MonoMatrix::Switcher.new options[:device]
10
+ m.switch output, input
11
+ end
12
+ end
13
+ end
@@ -6,7 +6,9 @@ Gem::Specification.new do |s|
6
6
  s.version = MonoMatrix::VERSION
7
7
  s.date = '2014-11-26'
8
8
  s.summary = "Control monoprice 4x2 swithcer/splitter via serial"
9
- s.description = "A simple way to control your Monoprice 4x2 HDX***"
9
+ s.description = "A simple way to control your Monoprice 4x2 HDX***
10
+ Created for use in https://github.com/defektive/hdx-api
11
+ "
10
12
  s.authors = ["defektive"]
11
13
  s.email = 'sirbradleyd@gmail.com'
12
14
  s.homepage = 'http://rubygems.org/gems/mono_matrix'
@@ -18,6 +20,7 @@ Gem::Specification.new do |s|
18
20
  s.require_paths = ["lib"]
19
21
 
20
22
  s.add_runtime_dependency "serialport", '~> 1.3', '>= 1.3.1'
23
+ s.add_runtime_dependency "thor", '~> 0.19'
21
24
  s.add_development_dependency "rake", '~>10.4'
22
25
  s.add_development_dependency "semver2", '~>3.4'
23
26
  s.add_development_dependency "rubygems-update", '~>2.4'
File without changes
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mono_matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - defektive
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.3.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: thor
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.19'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.19'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: rake
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -72,9 +86,11 @@ dependencies:
72
86
  - - "~>"
73
87
  - !ruby/object:Gem::Version
74
88
  version: '2.4'
75
- description: A simple way to control your Monoprice 4x2 HDX***
89
+ description: "A simple way to control your Monoprice 4x2 HDX***\n Created for use
90
+ in https://github.com/defektive/hdx-api\n "
76
91
  email: sirbradleyd@gmail.com
77
- executables: []
92
+ executables:
93
+ - mono_matrix
78
94
  extensions: []
79
95
  extra_rdoc_files: []
80
96
  files:
@@ -84,9 +100,13 @@ files:
84
100
  - LICENSE.txt
85
101
  - README.md
86
102
  - Rakefile
103
+ - bin/mono_matrix
87
104
  - lib/mono_matrix.rb
105
+ - lib/mono_matrix/console.rb
88
106
  - lib/mono_matrix/version.rb
89
107
  - mono_matrix.gemspec
108
+ - spec/mock/serial_port.rb
109
+ - spec/mono_matrix.rb
90
110
  homepage: http://rubygems.org/gems/mono_matrix
91
111
  licenses:
92
112
  - MIT
@@ -111,4 +131,6 @@ rubygems_version: 2.2.2
111
131
  signing_key:
112
132
  specification_version: 4
113
133
  summary: Control monoprice 4x2 swithcer/splitter via serial
114
- test_files: []
134
+ test_files:
135
+ - spec/mock/serial_port.rb
136
+ - spec/mono_matrix.rb