artoo-spark 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: 1d98e9fe1cfaaf67fe06a462d3802e114a763cfc
4
+ data.tar.gz: e9be753b3535f5aab83ac995225e1120bef14d61
5
+ SHA512:
6
+ metadata.gz: bc0cc92b544731c63d141cb72641acbcc213f278371daed056ade767eacd7ae0adfa80120c27089baf3f957790508091582a35c5e381a6e2f0879de9ae2aa10a
7
+ data.tar.gz: c378e218b61549cda3e9eba97646a9f2c43620e1b5985b536431a475e52cfcca7403c90c3146cac9db6397f24012b65e3cd1ee660e35f8b8c526df5c7b356b33
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in artoo-spark.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2013 The Hybrid Group
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Artoo Adaptor For Spark
2
+
3
+ This repository contains the Artoo (http://artoo.io/) adaptor for the Spark core device (http://spark.io) using the built-in Tinker protocol.
4
+
5
+ Artoo is a open source micro-framework for robotics using Ruby.
6
+
7
+ For more information abut Artoo, check out our repo at https://github.com/hybridgroup/artoo
8
+
9
+ [![Code Climate](https://codeclimate.com/github/hybridgroup/artoo-spark.png)](https://codeclimate.com/github/hybridgroup/artoo-spark) [![Build Status](https://travis-ci.org/hybridgroup/artoo-spark.png?branch=master)](https://travis-ci.org/hybridgroup/artoo-spark)
10
+
11
+ ## Installing
12
+
13
+ ```
14
+ gem install artoo-spark
15
+ ```
16
+
17
+ You will need to have a Spark device, and an access token from a registered Spark account.
18
+
19
+
20
+ ## Using
21
+
22
+ ```ruby
23
+ require 'artoo'
24
+
25
+ connection :spark, :adaptor => :spark, :access_token => 'XYZABC123'
26
+ device :led, :driver => :led, :pin => 'D0'
27
+
28
+ work do
29
+ every(1.second) do
30
+ led.toggle
31
+ end
32
+ end
33
+ ```
34
+
35
+ ## Connecting to Spark
36
+
37
+ Once your Spark is connected via Wifi, you're done. It should keep itself connected, and your Artoo program should be able to connect to it via the Internet, using the access token that Spark has given you.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.pattern = "test/**/*_test.rb"
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "artoo-spark/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "artoo-spark"
7
+ s.version = Artoo::Spark::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ron Evans"]
10
+ s.email = ["artoo@hybridgroup.com"]
11
+ s.homepage = "https://github.com/hybridgroup/artoo-spark"
12
+ s.summary = %q{Artoo adaptor for Spark}
13
+ s.description = %q{Artoo adaptor for Spark}
14
+ s.license = 'Apache 2.0'
15
+
16
+ s.rubyforge_project = "artoo-spark"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_runtime_dependency 'artoo', '>= 1.4.1'
24
+ s.add_runtime_dependency 'http'
25
+ s.add_development_dependency 'minitest', '>= 5.0'
26
+ s.add_development_dependency 'minitest-happy'
27
+ s.add_development_dependency 'mocha', '>= 0.14.0'
28
+ end
data/examples/blink.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'artoo'
2
+
3
+ connection :spark, :adaptor => :spark, :device_id => "", :access_token => ""
4
+ device :led, :driver => :led, :pin => "D7"
5
+
6
+ work do
7
+ every 1.second do
8
+ led.toggle
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ require 'lib/artoo/adaptors/spark'
2
+ require 'lib/artoo/drivers/spark'
3
+ require 'lib/artoo-spark/version'
@@ -0,0 +1,5 @@
1
+ module Artoo
2
+ module Spark
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,77 @@
1
+ require 'artoo/adaptors/adaptor'
2
+ require 'http'
3
+
4
+ module Artoo
5
+ module Adaptors
6
+ # Connect to a spark device
7
+ # @see device documentation for more information
8
+ class Spark < Adaptor
9
+ attr_reader :device_id, :access_token
10
+
11
+ def initialize(params={})
12
+ @device_id = params[:additional_params][:device_id]
13
+ @access_token = params[:additional_params][:access_token]
14
+ super
15
+ end
16
+
17
+ # Creates a connection with device
18
+ # @return [Boolean]
19
+ def connect
20
+ super
21
+ end
22
+
23
+ # Name of device
24
+ # @return [String]
25
+ def firmware_name
26
+ "spark"
27
+ end
28
+
29
+ # Version of device
30
+ # @return [String]
31
+ def version
32
+ Artoo::Spark::VERSION
33
+ end
34
+
35
+ # GPIO - digital
36
+ def digital_write(pin, level)
37
+ url = device_url + "/digitalwrite"
38
+ post(url, {:params => "#{pin},#{level.upcase}"})
39
+ end
40
+
41
+ def digital_read(pin)
42
+ url = device_url + "/digitalread"
43
+ post(url, {:params => pin})
44
+ end
45
+
46
+ # GPIO - analog
47
+ def analog_write(pin, level)
48
+ url = device_url + "/analogwrite"
49
+ post(url, {:params => "#{pin},#{level.upcase}"})
50
+ end
51
+
52
+ def analog_read(pin)
53
+ url = device_url + "/analogread"
54
+ post(url, {:params => pin})
55
+ end
56
+
57
+ # GPIO - PWM
58
+ def pwm_write(pin, level)
59
+ analog_write(pin, level)
60
+ end
61
+
62
+ # GPIO - servo
63
+ def servo_write(pin, angle)
64
+ analog_write(pin, angle)
65
+ end
66
+
67
+ def post(url, data={})
68
+ data[:access_token] = access_token
69
+ HTTP.post(url, :form => data).response
70
+ end
71
+
72
+ def device_url
73
+ "https://api.spark.io/v1/devices/#{device_id}"
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+ require 'artoo/adaptors/spark'
3
+
4
+ describe Artoo::Adaptors::Spark do
5
+ before do
6
+ @adaptor = Artoo::Adaptors::Spark.new(:additional_params => {:device_id => "AABBCCDD", :access_token => "ABC123"})
7
+ end
8
+
9
+ it 'Artoo::Adaptors::Spark#connect' do
10
+ @adaptor.connect.must_equal true
11
+ end
12
+
13
+ it 'Artoo::Adaptors::Spark#disconnect' do
14
+ @adaptor.connect
15
+ @adaptor.disconnect
16
+
17
+ @adaptor.connected?.must_equal false
18
+ end
19
+
20
+ describe "device info interface" do
21
+ it "#firmware_name"
22
+ it "#version"
23
+ end
24
+
25
+ describe "digital GPIO interface" do
26
+ it "#digital_read"
27
+ it "#digital_write"
28
+ end
29
+
30
+ describe "analog GPIO interface" do
31
+ it "#analog_read"
32
+ it "#analog_write"
33
+ end
34
+
35
+ describe "PWM GPIO interface" do
36
+ it "#pwm_write"
37
+ end
38
+
39
+ describe "servo GPIO interface" do
40
+ it "#servo_write"
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ require 'artoo/robot'
2
+
3
+ require 'minitest/autorun'
4
+
5
+ Celluloid.logger = nil
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: artoo-spark
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ron Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: artoo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-happy
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.14.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.14.0
83
+ description: Artoo adaptor for Spark
84
+ email:
85
+ - artoo@hybridgroup.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - artoo-spark.gemspec
95
+ - examples/blink.rb
96
+ - lib/artoo-spark.rb
97
+ - lib/artoo-spark/version.rb
98
+ - lib/artoo/adaptors/spark.rb
99
+ - test/adaptors/spark_adaptor_test.rb
100
+ - test/test_helper.rb
101
+ homepage: https://github.com/hybridgroup/artoo-spark
102
+ licenses:
103
+ - Apache 2.0
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project: artoo-spark
121
+ rubygems_version: 2.0.3
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Artoo adaptor for Spark
125
+ test_files: []