ruboty-pi_gpio 0.1.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: 456dc6bcc3362889dd2a91251a4217f09acd2d15
4
+ data.tar.gz: 0541ab66806548ddb6fc78117008d45b97d2475c
5
+ SHA512:
6
+ metadata.gz: bbc76f7b82b1c7115f1f273706a0a0748bd5e217fdfb8c44dce28753ff21bc5ca3a0d7df5297d07e62462ce93579c985291d5661450c5bed875711ff669bb771
7
+ data.tar.gz: 5d568a1a6e34081ec8ba23cc13bb07cfca9d430f3ce79b1fe7ce5a675089ec1404d26a89d2ffc0dbd09465b3b6531e24f47d48391de04e839b097fe5150d82bf
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-pi_gpio.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Ruboty::PiGpio
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruboty/pi_gpio`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruboty-pi_gpio'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruboty-pi_gpio
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/ruboty-pi_gpio/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/pi_gpio"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class PiGpio < Base
4
+ on(/set gpio mode (?<pin>\d{,2}) (?<mode>in|out)/, name: :mode, description: 'Set GPIO mode')
5
+ on(/set gpio value (?<pin>\d{,2}) (?<value>high|low)/, name: :write, description: 'Set GPIO value')
6
+ on(/get gpio value (?<pin>\d{,2})/, name: :read, description: 'Get GPIO value')
7
+ on(/unexport gpio (?<pin>\d{,2})/, name: :unexport, description: 'Unexport GPIO')
8
+
9
+ def mode(message)
10
+ Ruboty::PiGpio::Actions::Mode.new(message).call
11
+ end
12
+
13
+ def write
14
+ Ruboty::PiGpio::Actions::Write.new(message).call
15
+ end
16
+
17
+ def read
18
+ Ruboty::PiGpio::Actions::Read.new(message).call
19
+ end
20
+
21
+ def unexport
22
+ Ruboty::PiGpio::Actions::Unexport.new(message).call
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ module Ruboty
2
+ module PiGpio
3
+ module Actions
4
+ class Base < Ruboty::Actions::Base
5
+ protected
6
+
7
+ def pin
8
+ message[:pin]
9
+ end
10
+
11
+ def export
12
+ open('/sys/class/gpio/export', 'w') { |f| f.write(pin) }
13
+ end
14
+
15
+ def unexport
16
+ open('/sys/class/gpio/unexport', 'w') { |f| f.write(pin) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module Ruboty
2
+ module PiGpio
3
+ module Actions
4
+ class Mode < Base
5
+ def call
6
+ export
7
+ set_mode
8
+ message.reply("Set GPIO#{pin} to #{mode} successfully")
9
+ rescue
10
+ message.reply("Failed to set GPIO#{pin} to #{mode}")
11
+ end
12
+
13
+ private
14
+
15
+ def set_mode
16
+ open("/sys/class/gpio/gpio#{pin}/direction", 'w') { |f| f.write(mode) }
17
+ end
18
+
19
+ def mode
20
+ message[:mode]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ module Ruboty
2
+ module PiGpio
3
+ module Actions
4
+ class Read < Base
5
+ def call
6
+ message.reply("GPIO#{pin} is #{value}")
7
+ rescue
8
+ message.reply("Failed to get GPIO#{pin} value")
9
+ end
10
+
11
+ private
12
+
13
+ def value
14
+ File.read("/sys/class/gpio/gpio#{pin}/value")
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,15 @@
1
+ module Ruboty
2
+ module PiGpio
3
+ module Actions
4
+ class Unexport < Base
5
+ def call
6
+ unexport
7
+ message.reply("Unexport GPIO#{pin} successfully")
8
+ rescue
9
+ message.reply("Failed to unexport GPIO#{pin}")
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,30 @@
1
+ module Ruboty
2
+ module PiGpio
3
+ module Actions
4
+ class Write < Base
5
+ HIGH = 1
6
+ LOW = 0
7
+
8
+ def call
9
+ set_value
10
+ message.reply("Set GPIO#{pin} to #{value} successfully")
11
+ rescue
12
+ message.reply("Failed to set GPIO#{pin} to #{value}")
13
+ end
14
+
15
+ private
16
+
17
+ def set_value
18
+ open("/sys/class/gpio/gpio#{pin}/value", 'w') { |f| f.write(value) }
19
+ end
20
+
21
+ def value
22
+ case message[:value]
23
+ when 'low' then 0
24
+ when 'high' then 1
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module PiGpio
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ require "ruboty/pi_gpio/version"
2
+ require "ruboty/handlers/pi_gpio"
3
+ require "ruboty/pi_gpio/actions/base"
4
+ require "ruboty/pi_gpio/actions/mode"
5
+ require "ruboty/pi_gpio/actions/write"
6
+ require "ruboty/pi_gpio/actions/read"
7
+ require "ruboty/pi_gpio/actions/unexport"
8
+
9
+ END {
10
+ Dir.glob('/sys/class/gpio/gpio*').each do |gpio|
11
+ open('/sys/classs/gpio/unexport', 'w') { |f| f.write(gpio) }
12
+ end
13
+ }
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/pi_gpio/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-pi_gpio"
8
+ spec.version = Ruboty::PiGpio::VERSION
9
+ spec.authors = ["izumin5210"]
10
+ spec.email = ["masayuki@izumin.info"]
11
+
12
+ spec.summary = "Control GPIO of Raspberry PI via Ruboty"
13
+ spec.homepage = "https://github.com/izumin5210/ruboty-pi_gpio"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "ruboty"
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-pi_gpio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - izumin5210
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
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
+ description:
56
+ email:
57
+ - masayuki@izumin.info
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/ruboty/handlers/pi_gpio.rb
71
+ - lib/ruboty/pi_gpio.rb
72
+ - lib/ruboty/pi_gpio/actions/base.rb
73
+ - lib/ruboty/pi_gpio/actions/mode.rb
74
+ - lib/ruboty/pi_gpio/actions/read.rb
75
+ - lib/ruboty/pi_gpio/actions/unexport.rb
76
+ - lib/ruboty/pi_gpio/actions/write.rb
77
+ - lib/ruboty/pi_gpio/version.rb
78
+ - ruboty-pi_gpio.gemspec
79
+ homepage: https://github.com/izumin5210/ruboty-pi_gpio
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.5
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Control GPIO of Raspberry PI via Ruboty
103
+ test_files: []