triggerino 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'dino',
6
+ git: 'git://github.com/supherman/dino.git',
7
+ branch: 'lcdv3'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Herman Moreno
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Triggerino
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'triggerino'
8
+
9
+ And then execute:
10
+
11
+ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ gem install triggerino
16
+
17
+ ## Usage
18
+
19
+ 2. Create a "triggerino" dir
20
+
21
+ mkdir triggerino
22
+
23
+ 3. Define your action classes
24
+
25
+ touch triggerino/my_action.rb
26
+
27
+ class MyAction
28
+ include Triggerino::Action
29
+
30
+ def perform
31
+ # puts your action logic here
32
+ end
33
+
34
+ def to_s
35
+ 'A descriptive name for your action'
36
+ end
37
+ end
38
+
39
+ 2. Run the listener
40
+
41
+ bundle exec triggerino
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/triggerino ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler'
4
+ Bundler.require
5
+
6
+ Signal.trap("SIGINT") do
7
+ Thread.current.exit
8
+ end
9
+
10
+ files = File.expand_path('*.rb', Triggerino::Config.load_path)
11
+ actions = []
12
+
13
+ def constantize(path)
14
+ name = Pathname.new(path).basename('.rb').to_s
15
+ Module.const_get name.capitalize.split('_').map(&:capitalize).join
16
+ end
17
+
18
+ Dir[files].each do |f|
19
+ require f
20
+ actions << constantize(f).new
21
+ end
22
+
23
+ board = Dino::Board.new(Dino::TxRx.new)
24
+ button = Dino::Components::Button.new(pin: 10, board: board, pullup: true)
25
+ button2 = Dino::Components::Button.new(pin: 9, board: board, pullup: true)
26
+ lcd = Dino::Components::LCD.new(
27
+ board: board,
28
+ pins: { rs: 12, enable: 11, d4: 5, d5: 4, d6: 3, d7: 2 }
29
+ )
30
+ lcd.begin(16,2)
31
+ display = Triggerino::Display.new lcd
32
+ list = Triggerino::ActionList.new display, *actions
33
+ selector = Triggerino::Selector.new list, button
34
+ trigger = Triggerino::Trigger.new list, button2
35
+
36
+ at_exit do
37
+ lcd.clear
38
+ end
39
+
40
+ sleep
@@ -0,0 +1,17 @@
1
+ require 'celluloid'
2
+
3
+ module Triggerino
4
+ module Action
5
+ def self.included(base)
6
+ base.send :include, Celluloid
7
+ end
8
+
9
+ def perform
10
+ raise 'Not implemented'
11
+ end
12
+
13
+ def to_s
14
+ raise 'Not implemented'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ require 'observer'
2
+
3
+ module Triggerino
4
+ class ActionList
5
+ include Enumerable
6
+ include Observable
7
+
8
+ extend Forwardable
9
+
10
+ def_instance_delegators :@actions, :each, :size
11
+
12
+ attr_reader :selected
13
+
14
+ def initialize observer, *actions
15
+ @actions = actions
16
+ @selected = @actions.first
17
+ add_observer observer
18
+ notify_changed
19
+ end
20
+
21
+ def select_next
22
+ @selected = @actions[selected_index + 1] || @actions.first
23
+ notify_changed
24
+ end
25
+
26
+ def selected= action
27
+ raise 'The action is not included in the list' if !@actions.include?(action)
28
+ @selected = action
29
+ notify_changed
30
+ end
31
+
32
+ private
33
+
34
+ def selected_index
35
+ @actions.index(@selected)
36
+ end
37
+
38
+ def notify_changed
39
+ changed
40
+ notify_observers @selected
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ module Triggerino
2
+ module ButtonActionable
3
+ def initialize action_list, button
4
+ @action_list = action_list
5
+ @button = button
6
+ bind_events
7
+ end
8
+
9
+ def bind_events
10
+ @button.down { button_down }
11
+ @button.up { button_up }
12
+ end
13
+
14
+ def button_down
15
+ raise 'Not implemented'
16
+ end
17
+
18
+ def button_up
19
+ raise 'Not implemented'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ module Triggerino
2
+ module Config
3
+ extend self
4
+ attr_accessor :load_path
5
+
6
+ @load_path = 'triggerino'
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ module Triggerino
2
+ class Display
3
+ def initialize lcd
4
+ @lcd = lcd
5
+ end
6
+
7
+ def update value
8
+ @lcd.clear
9
+ @lcd.puts value.to_s
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Triggerino
2
+ class Selector
3
+ include Triggerino::ButtonActionable
4
+
5
+ def button_down
6
+ @action_list.select_next
7
+ end
8
+
9
+ def button_up; end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Triggerino
2
+ class Trigger
3
+ include Triggerino::ButtonActionable
4
+
5
+ def button_down
6
+ end
7
+
8
+ def button_up
9
+ @action_list.selected.future.perform
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Triggerino
2
+ VERSION = "0.0.1"
3
+ end
data/lib/triggerino.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "triggerino/version"
2
+
3
+ module Triggerino
4
+ autoload :ActionList, 'triggerino/action_list'
5
+ autoload :Display, 'triggerino/display'
6
+ autoload :ButtonActionable, 'triggerino/button_actionable'
7
+ autoload :Selector, 'triggerino/selector'
8
+ autoload :Trigger, 'triggerino/trigger'
9
+ autoload :Action, 'triggerino/action'
10
+ autoload :Config, 'triggerino/config'
11
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ module Triggerino
4
+ describe ActionList do
5
+ let(:action1) { mock('action1') }
6
+ let(:action2) { mock('action2') }
7
+ let(:observer) { mock(update: false) }
8
+
9
+ subject { ActionList.new(observer, action1, action2) }
10
+
11
+ describe 'behaves like a list of actions' do
12
+ it 'has a size' do
13
+ expect(subject.size).to be 2
14
+ end
15
+
16
+ it 'can be iterated' do
17
+ expect(subject.respond_to? :each).to be true
18
+ end
19
+ end
20
+
21
+ describe '#selected' do
22
+ it 'has a selected action by default' do
23
+ expect(subject.selected).to be action1
24
+ end
25
+
26
+ it 'can set the selection' do
27
+ subject.selected = action2
28
+ expect(subject.selected).to be action2
29
+ end
30
+
31
+ it 'returns false if the action does not exist in the list' do
32
+ expect{subject.selected = mock}.to raise_exception
33
+ end
34
+ end
35
+
36
+ describe '#select_next' do
37
+ it 'select the next action' do
38
+ subject.select_next
39
+ expect(subject.selected).to be action2
40
+ end
41
+
42
+ context 'last action in the list' do
43
+ it 'selects the first action' do
44
+ subject.selected = action2
45
+ subject.select_next
46
+ expect(subject.selected).to be action1
47
+ end
48
+ end
49
+ end
50
+
51
+ describe 'observable' do
52
+ it 'should has an observer' do
53
+ expect(subject.count_observers).to be 1
54
+ end
55
+
56
+ it 'notify the observer when selected change' do
57
+ subject.should_receive :changed
58
+ subject.should_receive :notify_observers
59
+ subject.selected = action2
60
+ end
61
+
62
+ it 'notify the observer when next is selected' do
63
+ subject.should_receive :changed
64
+ subject.should_receive :notify_observers
65
+ subject.select_next
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ module Triggerino
4
+ describe Config do
5
+ it 'has "triggerino" as default load path' do
6
+ expect(Triggerino::Config.load_path).to eq 'triggerino'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ module Triggerino
4
+ describe Display do
5
+ let(:lcd) { mock }
6
+
7
+ subject { Display.new(lcd) }
8
+
9
+ describe '#update' do
10
+ it 'prints in the display' do
11
+ lcd.should_receive(:clear)
12
+ lcd.should_receive(:puts).with 'Hello'
13
+ subject.update('Hello')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Triggerino
4
+ describe Selector do
5
+ let(:button) { mock(:button, down: stub, up: stub) }
6
+ let(:action_list) { mock(:list) }
7
+
8
+ subject { Selector.new(action_list, button) }
9
+
10
+ describe '#button_down' do
11
+ it 'select the next action in the list' do
12
+ action_list.should_receive(:select_next)
13
+ subject.button_down
14
+ end
15
+ end
16
+
17
+ describe '#button_up' do
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module Triggerino
4
+ describe Trigger do
5
+ let(:button) { mock(:button, down: stub, up: stub) }
6
+ let(:selected) { mock(:action) }
7
+ let(:action_list) { mock(:list, selected: selected) }
8
+
9
+ subject { Trigger.new(action_list, button) }
10
+
11
+ describe '#button_down' do
12
+ it 'triggers the selected action' do
13
+ selected.stub_chain(:future, :perform)
14
+ subject.button_down
15
+ end
16
+ end
17
+
18
+ describe '#button_up' do
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require File.expand_path(File.join('../..', 'lib/triggerino'), __FILE__)
8
+
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'triggerino/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "triggerino"
8
+ spec.version = Triggerino::VERSION
9
+ spec.authors = ["Herman Moreno"]
10
+ spec.email = ["herman.moreno@crowdint.com"]
11
+ spec.description = %q{A magic black box}
12
+ spec.summary = %q{A magic black box}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_dependency "dino"
25
+ spec.add_dependency "celluloid"
26
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: triggerino
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Herman Moreno
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: dino
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: celluloid
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: A magic black box
95
+ email:
96
+ - herman.moreno@crowdint.com
97
+ executables:
98
+ - triggerino
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - .rspec
104
+ - Gemfile
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - bin/triggerino
109
+ - lib/triggerino.rb
110
+ - lib/triggerino/action.rb
111
+ - lib/triggerino/action_list.rb
112
+ - lib/triggerino/button_actionable.rb
113
+ - lib/triggerino/config.rb
114
+ - lib/triggerino/display.rb
115
+ - lib/triggerino/selector.rb
116
+ - lib/triggerino/trigger.rb
117
+ - lib/triggerino/version.rb
118
+ - spec/lib/action_list_spec.rb
119
+ - spec/lib/config_spec.rb
120
+ - spec/lib/display_spec.rb
121
+ - spec/lib/selector_spec.rb
122
+ - spec/lib/trigger_spec.rb
123
+ - spec/spec_helper.rb
124
+ - triggerino.gemspec
125
+ homepage: ''
126
+ licenses:
127
+ - MIT
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 1.8.23
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: A magic black box
150
+ test_files:
151
+ - spec/lib/action_list_spec.rb
152
+ - spec/lib/config_spec.rb
153
+ - spec/lib/display_spec.rb
154
+ - spec/lib/selector_spec.rb
155
+ - spec/lib/trigger_spec.rb
156
+ - spec/spec_helper.rb
157
+ has_rdoc: