powermate 1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4dda98b3b8202ea0b6444467aea82801808a2af9
4
+ data.tar.gz: 3a53254ceb6b9e5bae5d741c1c42ce5295234722
5
+ SHA512:
6
+ metadata.gz: cd1fc36f865ba1a18cb06f262d7886f73d7f355a34a91bb2cccb876a6bef7f64fe589f0ae0f234d17c7adf762fd831b482eac453cd333ab280e67d9ffd0b101d
7
+ data.tar.gz: 0947cd13607985f9b13499e74b105cc3e0d821ffde686e156c4e86a525b104694d35fa2fd9d9f7da22249fe401506c6d3ad8b99bf5acb02258a085cf24727eb0
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .gems
2
+ .bundle
3
+ pkg
4
+ .gem
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
@@ -0,0 +1 @@
1
+ ACTION=="add", ENV{ID_USB_DRIVER}=="powermate", SYMLINK+="input/powermate", GROUP="powermate", MODE="0660"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ #gem 'pulseaudio'
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ powermate (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ powermate!
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010-2015 Google, Inc. http://angularjs.org
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,56 @@
1
+ # Powermate
2
+
3
+ this is a gem to trigger things to happen when you turn your powermate
4
+
5
+ ``` ruby
6
+ # do_it.rb
7
+ require 'powermate'
8
+
9
+ pmate = Powermate::Device.scan.first
10
+ pmate.open
11
+
12
+ pmate.on_clockwise do |e|
13
+ puts 'turned clockwise'
14
+ end
15
+
16
+ pmate.on_counter_clockwise do |e|
17
+ puts 'turned counter clockwise'
18
+ end
19
+
20
+ Powermate.wait_for_events
21
+ ```
22
+
23
+ Install the gem:
24
+
25
+ ``` shell
26
+ gem install powermate
27
+ ```
28
+
29
+ And run with:
30
+
31
+ ``` shell
32
+ ruby do_it.rb
33
+ ```
34
+
35
+ ## Events
36
+
37
+ ``` ruby
38
+
39
+ pmate.on_clockwise do |e|
40
+ .. do something here ..
41
+ end
42
+
43
+ pmate.on_counter_clockwise do |e|
44
+ .. do something here ..
45
+ end
46
+
47
+ pmate.on_rotate do |e|
48
+ .. do something here ..
49
+ end
50
+
51
+ pmate.on_change do |e|
52
+ .. do something here ..
53
+ end
54
+
55
+ ```
56
+
@@ -0,0 +1,24 @@
1
+ require 'powermate'
2
+
3
+ pmate = Powermate::Device.scan.first
4
+ pmate.open
5
+
6
+ files = Dir["/home/lex/Sync/backgrounds/*"].select{ |x| x =~ /(png|jpg|jpeg)$/}
7
+ files = files.shuffle
8
+
9
+
10
+ pmate.on_clockwise do |e|
11
+ files.rotate!(1)
12
+ puts files.first
13
+ `feh --bg-scale #{files.first}`
14
+ end
15
+
16
+
17
+ pmate.on_counter_clockwise do |e|
18
+ files.rotate!(-1)
19
+ puts files.first
20
+ `feh --bg-scale #{files.first}`
21
+ end
22
+
23
+
24
+ Powermate.wait_for_events
data/example/volume.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'powermate'
2
+
3
+ #gem install pulseaudio
4
+ require 'pulseaudio'
5
+
6
+
7
+ pmate = Powermate::Device.scan.first
8
+ pmate.open
9
+
10
+
11
+ pmate.on_clockwise do |e|
12
+ sinks = PulseAudio::Sink.list
13
+ sinks.each do |sink|
14
+ sink.vol_incr if sink.active?
15
+ end
16
+ end
17
+
18
+
19
+ pmate.on_counter_clockwise do |e|
20
+ sinks = PulseAudio::Sink.list
21
+ sinks.each do |sink|
22
+ sink.vol_decr if sink.active?
23
+ end
24
+ end
25
+
26
+
27
+ Powermate.wait_for_events
data/lib/powermate.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+
3
+ require 'powermate/version'
4
+ require 'powermate/event'
5
+ require 'powermate/device'
6
+
7
+ module Powermate
8
+
9
+ module Wait
10
+ def wait_for_events
11
+ begin
12
+ sleep 1 while(true)
13
+ rescue Interrupt
14
+ exit(0)
15
+ end
16
+ end
17
+ end
18
+
19
+ #put the methods in wait directly on Powermate
20
+ extend Powermate::Wait
21
+
22
+ end
23
+
24
+
@@ -0,0 +1,81 @@
1
+ require 'json'
2
+
3
+ class Powermate::Device
4
+
5
+ #attr_reader :file
6
+ #SIZE = 24
7
+ SIZE = 48
8
+
9
+ def initialize path
10
+ @file = File.open path, File::Constants::RDONLY
11
+ @reader = nil
12
+ @on_change_blocks =[]
13
+ @on_rotate_blocks=[]
14
+ @on_clockwise_blocks=[]
15
+ @on_counter_clockwise_blocks=[]
16
+ @pressed = false
17
+ end
18
+
19
+ def self.scan
20
+ root = "/dev/input/by-id"
21
+ files = Dir.foreach(root).select{|f| f =~ /PowerMate/i}
22
+ files.map{|f| new(root + "\/" + f)}
23
+ end
24
+
25
+ def on_change &block
26
+ @on_change_blocks.push block
27
+ self
28
+ end
29
+
30
+ def on_rotate &block
31
+ @on_rotate_blocks.push block
32
+ self
33
+ end
34
+
35
+ def on_clockwise &block
36
+ @on_clockwise_blocks.push block
37
+ self
38
+ end
39
+
40
+ def on_counter_clockwise &block
41
+ @on_counter_clockwise_blocks.push block
42
+ self
43
+ end
44
+
45
+
46
+ def open
47
+ return if @reader
48
+ @reader = Thread.new{
49
+ #trash any old events
50
+ #@file.readbyte() #throw out the first byte, its junk
51
+ bytes =[]
52
+ while @reader do
53
+
54
+ bytes << @file.readbyte()
55
+
56
+ if bytes.size == SIZE
57
+ event = Powermate::Event.new(bytes, @pressed)
58
+ bytes = []
59
+ @pressed = event.pressed
60
+ @on_change_blocks.each{|w| w.call(event) }
61
+ @on_rotate_blocks.each{|w| w.call(event) } if event.clockwise || event.counter_clockwise
62
+ @on_clockwise_blocks.each{|w| w.call(event) } if event.clockwise
63
+ @on_counter_clockwise_blocks.each{|w| w.call(event) } if event.counter_clockwise
64
+
65
+ end
66
+
67
+ end
68
+ }
69
+ !!@reader
70
+ end
71
+
72
+ def close
73
+ @reader = nil
74
+ !@reader
75
+ end
76
+
77
+
78
+
79
+
80
+
81
+ end
@@ -0,0 +1,33 @@
1
+ require 'pry'
2
+
3
+ class Powermate::Event
4
+
5
+ attr_reader :clockwise, :counter_clockwise, :pressed
6
+
7
+ def initialize raw_event, old_pressed
8
+ @clockwise = false
9
+ @counter_clockwise = false
10
+ @pressed = old_pressed
11
+
12
+ type = raw_event[16] == 1 ? :push : :rotate
13
+ value = raw_event[20] == 1
14
+
15
+ if type == :push
16
+ @pressed = value
17
+ elsif type == :rotate
18
+ @clockwise = value
19
+ @counter_clockwise = !value
20
+ end
21
+
22
+ end
23
+
24
+ def to_hash
25
+ {
26
+ clockwise: @clockwise,
27
+ counter_clockwise: @counter_clockwise,
28
+ pressed: @pressed
29
+ }
30
+ end
31
+
32
+
33
+ end
@@ -0,0 +1,3 @@
1
+ module Powermate
2
+ VERSION = '1.0.0'
3
+ end
data/powermate.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'powermate/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "powermate"
8
+ gem.version = Powermate::VERSION
9
+ gem.authors = ["Lex Childs"]
10
+ gem.email = ["lexchilds@gmail.com"]
11
+ gem.description = %q{powermate events}
12
+ gem.summary = "a small lib to tie into powermate events"
13
+ gem.homepage = "https://github.com/lex148/powermate"
14
+
15
+ dependencies = %w''
16
+ dependencies.each do |d|
17
+ gem.add_dependency d
18
+ end
19
+
20
+ #dependencies = %w'rake minitest pry'
21
+ #dependencies.each do |d|
22
+ # gem.add_development_dependency d
23
+ #end
24
+
25
+ gem.files = `git ls-files`.split($/)
26
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
27
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
28
+ gem.require_paths = ["lib"]
29
+ end
data/powermate.rb ADDED
@@ -0,0 +1,14 @@
1
+ class Powermate
2
+
3
+
4
+ def init
5
+
6
+ end
7
+
8
+ def self.find
9
+
10
+ end
11
+
12
+
13
+ end
14
+
data/rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require "bundler/gem_tasks"
2
+ require 'bundler'
3
+ require 'rake/testtask'
4
+
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ Rake::TestTask.new(:test) do |test|
8
+ test.libs << 'lib' << 'spec'
9
+ test.pattern = './spec/**/*_spec.rb'
10
+ test.verbose = true
11
+ end
12
+
13
+ task :pry do |test|
14
+ require 'powermate'
15
+ require 'pry'
16
+ Powermate.pry
17
+ end
18
+
19
+
20
+ task :default => :test
data/setup.sh ADDED
@@ -0,0 +1,10 @@
1
+ #! /bin/bash
2
+ sudo groupadd powermate
3
+ sudo cp ./60-powermate.rules /etc/udev/rules.d/60-powermate.rules
4
+
5
+ echo "A group has been setup for powermate"
6
+ echo "add your user to the powermate group if you would like access"
7
+ echo "sudo usermod -a -G powermate `whoami`"
8
+ echo "NOTE: this does not take effect until you re-login"
9
+
10
+
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ describe Powermate do
4
+
5
+ it 'should respond to scan' do
6
+ Powermate::Device.must_respond_to :scan
7
+ end
8
+
9
+ it 'should find a powermate device' do
10
+ pmates = Powermate::Device.scan
11
+ pmates.first.must_be_instance_of Powermate::Device
12
+ end
13
+
14
+ it 'should open' do
15
+ pmates = Powermate::Device.scan
16
+ pmates.first.must_respond_to :open
17
+ end
18
+
19
+ it 'should close' do
20
+ pmates = Powermate::Device.scan
21
+ pmates.first.must_respond_to :close
22
+ end
23
+
24
+
25
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'ostruct'
4
+ require 'minitest/autorun'
5
+ require 'minitest/spec'
6
+ require 'minitest/pride'
7
+
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+
11
+ require "powermate"
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: powermate
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Lex Childs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: powermate events
14
+ email:
15
+ - lexchilds@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".ruby-version"
22
+ - 60-powermate.rules
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE
26
+ - README.md
27
+ - example/background.rb
28
+ - example/volume.rb
29
+ - lib/powermate.rb
30
+ - lib/powermate/device.rb
31
+ - lib/powermate/event.rb
32
+ - lib/powermate/version.rb
33
+ - powermate.gemspec
34
+ - powermate.rb
35
+ - rakefile
36
+ - setup.sh
37
+ - spec/device_spec.rb
38
+ - spec/helper.rb
39
+ homepage: https://github.com/lex148/powermate
40
+ licenses: []
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.4.5
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: a small lib to tie into powermate events
62
+ test_files:
63
+ - spec/device_spec.rb
64
+ - spec/helper.rb