rf_rgb 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5159ee522b80b0230b43725004ea8f67ad0adbcc
4
+ data.tar.gz: cb0e2ccab51300a5a69cb7ff004921c277f54fc9
5
+ SHA512:
6
+ metadata.gz: 0bf1c0a4fe75adce0180ad4dc7a80906c97185499098563f713cb62574097219120831e4b8c71ee2ef924fc50b833dd22a3d08576225a634d5b8354920a8aebc
7
+ data.tar.gz: 622e71c6041b93d56b351f1d66b2539a9c37a7f7ffb3dde64128b8ca72c068066e3f13e7fee2faabbcb39c539d0c135d8dc619bfc6da440ec4653f44a32f2bfc
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
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rf_rgb.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Michael Dungan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # RfRgb
2
+
3
+ ### What it is
4
+ Some code to allow for interacting with Topre Realforce RGB keyboards. The software provided by
5
+ the manufacturer only supports Windows.
6
+
7
+ ### What it isn't
8
+ This isn't intended to be a full replacement for the Realforce software - just some basic classes that can
9
+ be used as building blocks.
10
+
11
+ ## Requirements
12
+ 1. Ruby 2.3+. Earlier versions of Ruby may work, but are not supported.
13
+ 1. [libusb](http://libusb.info) 1.0.0 or greater. The old version 0.1 is not supported.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's `Gemfile`:
18
+
19
+ ```ruby
20
+ gem 'rf_rgb'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself with:
28
+
29
+ $ gem install rf_rgb
30
+
31
+ ## Usage
32
+
33
+ ```ruby
34
+ keyboard = nil
35
+ begin
36
+ # .new without an arg will automatically find and initialize the first Realforce RGB keyboard it finds.
37
+ # Keyboard cannot be used at this point, as it's owned by this program until .release_to_os is called.
38
+ keyboard = RfRgb::Keyboard.new
39
+
40
+ keyboard.effect_rainbow_wave
41
+ # keyboard.effect_shooting_star("\xff\x00\xff", RfRgb::Protocol::INTERVAL_6)
42
+ # keyboard.effect_pressed_key("\xaa\xee\xff")
43
+ # keyboard.disable_effect
44
+ keyboard.brightness = RfRgb::Protocol::BRIGHTNESS_LOW
45
+ keyboard.actuation_height = RfRgb::Protocol::HEIGHT_22
46
+ keyboard.swap_caps_ctrl
47
+ keyboard.save
48
+ ensure
49
+ keyboard&.release_to_os
50
+ end
51
+ ```
52
+
53
+ OR
54
+
55
+ ```ruby
56
+ RfRgb::Keyboard.run_and_release do |keyboard|
57
+ keyboard.effect_rainbow_wave
58
+ keyboard.brightness = RfRgb::Protocol::BRIGHTNESS_LOW
59
+ keyboard.actuation_height = RfRgb::Protocol::HEIGHT_22
60
+ keyboard.swap_caps_ctrl
61
+ keyboard.save
62
+ end
63
+ ```
64
+
65
+ See `lib/rf_rgb/keyboard.rb` for effects and arguments, and
66
+ `lib/rf_rgb/protocol.rb` for any needed constants.
67
+
68
+ On Ubuntu Linux at least, some udev configuration was necessary to be able to run as a non-root user,
69
+ and prevent `usbhid` from taking the device over. If you're in that boat, try this:
70
+
71
+ 1. create `/etc/udev/rules.d/99-topre.rules` with the following content:
72
+ ```
73
+ SUBSYSTEM=="usb", ATTRS{idVendor}=="0853", ATTRS{idProduct}=="013a", MODE="0666", GROUP="plugdev"
74
+ ATTRS{idVendor}=="0853", ATTRS{idProduct}=="013a", RUN="/bin/sh -c 'echo -n $kernel >/sys/bus/usb/drivers/usbhid/unbind'"
75
+ ```
76
+ 1. Add your user to the `plugdev` group: `sudo usermod -a -G plugdev $USER`
77
+ 1. (Probably) log out and back in, so the new group is applied to your user
78
+ 1. Unplug and re-plug the keyboard into a USB slot.
79
+
80
+ ## Protocol Notes
81
+
82
+ When commands are sent from the host to the OUT endpoint, there is a response that can
83
+ be read from IN endpoint #3, but this module ignores these responses completely at
84
+ time of writing.
85
+
86
+ Some effects have a User 1-3 setting in the Windows UI. It's not clear what these
87
+ are actually for, and are ignored in this module for now.
88
+
89
+ ## Development
90
+
91
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
+
93
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/xxx/rf_rgb.
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rf_rgb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,136 @@
1
+ module RfRgb
2
+ class Keyboard
3
+ VENDOR_ID = 0x0853
4
+ PRODUCT_ID = 0x013a
5
+ ENDPOINT = 0x04
6
+ INTERFACE = 0
7
+
8
+ attr_reader :device, :handle
9
+
10
+ def self.all
11
+ context = LIBUSB::Context.new
12
+ context.debug = LIBUSB_DEBUG
13
+ context.devices(idVendor: VENDOR_ID, idProduct: PRODUCT_ID)
14
+ end
15
+
16
+ def self.first
17
+ all.first
18
+ end
19
+
20
+ def self.run_and_release(device = RfRgb::Keyboard.first, &block)
21
+ keyboard = nil
22
+ begin
23
+ keyboard = new(device)
24
+ yield keyboard
25
+ ensure
26
+ keyboard&.release_to_os
27
+ end
28
+ end
29
+
30
+ def initialize(device = RfRgb::Keyboard.first)
31
+ @device = device
32
+ @handle = initialize_device(device)
33
+ end
34
+
35
+ def save
36
+ send_message RfRgb::Protocol.save_changes
37
+ end
38
+
39
+ def release_to_os
40
+ return unless @handle
41
+ @handle.release_interface(INTERFACE)
42
+ @handle.close
43
+ end
44
+
45
+ def disable_effect
46
+ reset_effect
47
+ send_message RfRgb::Protocol.disable_effects
48
+ end
49
+
50
+ def effect_rainbow_wave
51
+ reset_effect
52
+ send_message RfRgb::Protocol.rainbow_wave
53
+ end
54
+
55
+ def effect_pressed_key(rgb_hex)
56
+ reset_effect
57
+ send_message RfRgb::Protocol.pressed_key_lighting(rgb_hex)
58
+ end
59
+
60
+ def effect_pressed_key_with_backlight(rgb_hex)
61
+ reset_effect
62
+ send_message RfRgb::Protocol.pressed_key_lighting_with_backlight(rgb_hex)
63
+ end
64
+
65
+ def effect_shooting_star(rgb_hex, interval)
66
+ reset_effect
67
+ send_message RfRgb::Protocol.shooting_star(rgb_hex, interval)
68
+ end
69
+
70
+ def effect_demo_mode
71
+ reset_effect
72
+ send_message RfRgb::Protocol.demo_mode
73
+ end
74
+
75
+ def effect_random_lights
76
+ reset_effect
77
+ send_message RfRgb::Protocol.random_lights
78
+ end
79
+
80
+ def effect_color_bar
81
+ reset_effect
82
+ send_message RfRgb::Protocol.color_bar
83
+ end
84
+
85
+ # There's more to key locking than just this, but the way it's done is odd
86
+ # and is among the lowest of priorities on this project.
87
+ def lock_keys
88
+ send_message RfRgb::Protocol.key_lock
89
+ end
90
+
91
+ def unlock_keys
92
+ send_message RfRgb::Protocol.key_unlock
93
+ end
94
+
95
+ def brightness=(new_brightness)
96
+ send_message RfRgb::Protocol.change_brightness(new_brightness)
97
+ end
98
+
99
+ def actuation_height=(new_height)
100
+ send_message RfRgb::Protocol.change_actuation_height_all(new_height)
101
+ end
102
+
103
+ def swap_caps_ctrl
104
+ send_message RfRgb::Protocol.swap_caps_ctrl
105
+ end
106
+
107
+ def unswap_caps_ctrl
108
+ send_message RfRgb::Protocol.unswap_caps_ctrl
109
+ end
110
+
111
+ private
112
+
113
+ # I don't know what this actually does, but the Windows software
114
+ # sends this message before any effect change.
115
+ def reset_effect
116
+ send_message RfRgb::Protocol.reset_effect
117
+ end
118
+
119
+ def initialize_device(device)
120
+ handle = device.open
121
+ handle.auto_detach_kernel_driver = true
122
+ handle.set_configuration(1) rescue nil
123
+ handle.claim_interface(INTERFACE)
124
+ # handle.clear_halt endpoint0
125
+ handle
126
+ end
127
+
128
+ def send_message(data)
129
+ @handle.interrupt_transfer(
130
+ endpoint: ENDPOINT,
131
+ dataOut: data,
132
+ timeout: 10_000
133
+ )
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,96 @@
1
+ module RfRgb
2
+ module Protocol
3
+ BRIGHTNESS_HIGH = "\x00".freeze
4
+ BRIGHTNESS_MEDIUM = "\x01".freeze
5
+ BRIGHTNESS_LOW = "\x02".freeze
6
+
7
+ # Actuation heights
8
+ HEIGHT_15 = "\x00".freeze
9
+ HEIGHT_22 = "\x01".freeze
10
+ HEIGHT_30 = "\x02".freeze
11
+
12
+ # Only the Shooting Star effect uses these.
13
+ INTERVAL_0 = "\x00".freeze # slowest, ~12 seconds
14
+ INTERVAL_1 = "\x01".freeze
15
+ INTERVAL_2 = "\x02".freeze
16
+ INTERVAL_3 = "\x03".freeze
17
+ INTERVAL_4 = "\x04".freeze
18
+ INTERVAL_5 = "\x05".freeze
19
+ INTERVAL_6 = "\x06".freeze
20
+ INTERVAL_7 = "\x07".freeze
21
+ INTERVAL_8 = "\x08".freeze
22
+ INTERVAL_9 = "\x09".freeze # fastest, ~1 second
23
+
24
+ # I'm not actually clear on the point of users, but here they are.
25
+ USER_0 = "\x00".freeze
26
+ USER_1 = "\x01".freeze
27
+ USER_2 = "\x02".freeze
28
+ USER_3 = "\x03".freeze
29
+
30
+ def self.reset_effect
31
+ "\xaa\xaa\x60".force_encoding(Encoding::BINARY).freeze
32
+ end
33
+
34
+ def self.save_changes
35
+ "\xaa\xaa\x04".force_encoding(Encoding::BINARY).freeze
36
+ end
37
+
38
+ def self.pressed_key_lighting(rgb_hex, user = :user0)
39
+ # byte number 6 (just before rgb) determines user. 0x00-0x03
40
+ "\xaa\xaa\x62\x00\x04\x00#{rgb_hex}".force_encoding(Encoding::BINARY).freeze
41
+ end
42
+
43
+ # Backlight color can't be changed AFAICT. Always white.
44
+ def self.pressed_key_lighting_with_backlight(rgb_hex, user = :user0)
45
+ "\xaa\xaa\x63\x00\x04\x00#{rgb_hex}".force_encoding(Encoding::BINARY).freeze
46
+ end
47
+
48
+ def self.rainbow_wave
49
+ "\xaa\xaa\x61".force_encoding(Encoding::BINARY).freeze
50
+ end
51
+
52
+ def self.shooting_star(rgb_hex, interval, user = USER_0)
53
+ "\xaa\xaa\x64\x00\x05\x00#{interval}#{rgb_hex}".force_encoding(Encoding::BINARY).freeze
54
+ end
55
+
56
+ def self.demo_mode
57
+ "\xaa\xaa\x66".force_encoding(Encoding::BINARY).freeze
58
+ end
59
+
60
+ def self.random_lights
61
+ "\xaa\xaa\x67".force_encoding(Encoding::BINARY).freeze
62
+ end
63
+
64
+ def self.color_bar
65
+ "\xaa\xaa\x68".force_encoding(Encoding::BINARY).freeze
66
+ end
67
+
68
+ def self.disable_effects
69
+ "\xaa\xaa\x69".force_encoding(Encoding::BINARY).freeze
70
+ end
71
+
72
+ def self.key_lock
73
+ "\xaa\xaa\x82\x00\x01\x01".force_encoding(Encoding::BINARY).freeze
74
+ end
75
+
76
+ def self.key_unlock
77
+ "\xaa\xaa\x82\x00\x01\x00".force_encoding(Encoding::BINARY).freeze
78
+ end
79
+
80
+ def self.change_brightness(new_brightness)
81
+ "\xaa\xaa\x42\x00\x01#{new_brightness}".force_encoding(Encoding::BINARY).freeze
82
+ end
83
+
84
+ def self.change_actuation_height_all(new_height)
85
+ "\xaa\xaa\x20\x00\x01#{new_height}".force_encoding(Encoding::BINARY).freeze
86
+ end
87
+
88
+ def self.swap_caps_ctrl
89
+ "\xaa\xaa\x84\x00\x01\x01".force_encoding(Encoding::BINARY).freeze
90
+ end
91
+
92
+ def self.unswap_caps_ctrl
93
+ "\xaa\xaa\x84\x00\x01\x00".force_encoding(Encoding::BINARY).freeze
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,3 @@
1
+ module RfRgb
2
+ VERSION = '0.8.0'.freeze
3
+ end
data/lib/rf_rgb.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'libusb'
2
+ require 'rf_rgb/keyboard'
3
+ require 'rf_rgb/protocol'
4
+ require 'rf_rgb/version'
5
+
6
+ module RfRgb
7
+ # 0 is silent, 4 is spewy.
8
+ LIBUSB_DEBUG = ENV['LIBUSB_DEBUG'] || 3
9
+ end
data/rf_rgb.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rf_rgb/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rf_rgb"
8
+ spec.version = RfRgb::VERSION
9
+ spec.authors = ["mpd"]
10
+ spec.email = ["mpd@jesters-court.net"]
11
+
12
+ spec.summary = %q{Some classes to interact with Topre Realforce RGB keyboards.}
13
+ spec.description = %q{Some classes to allow for read and writing key colors and actuation heights on Topre Realforce RGB keyboards}
14
+ spec.homepage = "https://github.com/xxx/rf_rgb"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "libusb", "~> 0.6"
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.15"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rf_rgb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: ruby
6
+ authors:
7
+ - mpd
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: libusb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Some classes to allow for read and writing key colors and actuation heights
70
+ on Topre Realforce RGB keyboards
71
+ email:
72
+ - mpd@jesters-court.net
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".ruby-version"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/rf_rgb.rb
88
+ - lib/rf_rgb/keyboard.rb
89
+ - lib/rf_rgb/protocol.rb
90
+ - lib/rf_rgb/version.rb
91
+ - rf_rgb.gemspec
92
+ homepage: https://github.com/xxx/rf_rgb
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ allowed_push_host: https://rubygems.org
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.12
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Some classes to interact with Topre Realforce RGB keyboards.
117
+ test_files: []