sudden_motion_sensor 1.0.0-universal-darwin-9
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +2 -0
- data/LICENSE +110 -0
- data/README +37 -0
- data/demo.rb +7 -0
- data/lib/sudden_motion_sensor.rb +86 -0
- metadata +79 -0
data/Changelog
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
The Don't Be a Dick License (http://github.com/SFEley/candy/blob/master/LICENSE.markdown)
|
2
|
+
===========================
|
3
|
+
_version 0.1_
|
4
|
+
|
5
|
+
**Project:** [Candy](http://github.com/SFEley/candy) v0.2
|
6
|
+
**Author:** Stephen Eley (<sfeley@gmail.com>)
|
7
|
+
|
8
|
+
This is a proposed draft of the **Don't Be a Dick** license for open source projects. The purpose of this license is to permit the broadest feasible scope for reuse and modification of creative work, restricted only by the requirement that one is not a dick about it.
|
9
|
+
|
10
|
+
1. Legal Parameters
|
11
|
+
-------------------
|
12
|
+
For legal purposes, the DBAD license is a superset of the [Apache License, Version 2.0][1] and incorporates all terms, conditions, privileges and limitations therein. The following text is a binding part of this license for this project:
|
13
|
+
|
14
|
+
> Copyright 2010 Stephen Eley
|
15
|
+
|
16
|
+
> Licensed under the Apache License, Version 2.0 (the "License");
|
17
|
+
you may not use this file except in compliance with the License.
|
18
|
+
You may obtain a copy of the License at
|
19
|
+
|
20
|
+
> <http://www.apache.org/licenses/LICENSE-2.0>
|
21
|
+
|
22
|
+
> Unless required by applicable law or agreed to in writing, software
|
23
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
24
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
25
|
+
See the License for the specific language governing permissions and
|
26
|
+
limitations under the License.
|
27
|
+
|
28
|
+
Nothing in the following text should be construed to inhibit, contradict, or override any part of the Apache License, Version 2.0.
|
29
|
+
|
30
|
+
2. Definitions
|
31
|
+
--------------
|
32
|
+
The following terms and definitions shall be in effect for the rest of this document.
|
33
|
+
|
34
|
+
> **NOTE:** Singular nouns and pronouns are used throughout this License for
|
35
|
+
grammatical convenience. However, any of the terms below _may_ refer to a
|
36
|
+
collective work or group of people. If this pegs your punctiliousness, you
|
37
|
+
are directed to mentally substitute "Person _or persons_," "Dick _or
|
38
|
+
dicks,_" etc., throughout this license. Just don't tell us about it.
|
39
|
+
|
40
|
+
### A. Project
|
41
|
+
|
42
|
+
A creative work of (software | writing | visual art | music) into which significant time and energy have been invested by people who _are not you,_ and which has been released into the world for the benefit of the general public (_including you._)
|
43
|
+
|
44
|
+
The **Project** may include, incorporate, derive from, or be inspired by other works. The Author, being a Reasonable Person, has made use of such source materials only as permitted by their own licenses or applicable law. The License you are reading applies only to those portions of the Project which are original and distinct to it. Source materials may be covered by their own licenses or conditions, and should not be assumed to have coverage under this License. (However, you are strongly encouraged not to be a dick about them either.)
|
45
|
+
|
46
|
+
### B. Author
|
47
|
+
|
48
|
+
A person who has invested significant time and energy into the Project licensed herein. Given the Author's release of the Project to the world under a liberal license, the Author is declared a Reasonable Person (at least within this context) and inherits all attributes, freedoms, and responsibilities thereof. No other assumptions are made about the Author, nor should you make any.
|
49
|
+
|
50
|
+
### C. Reasonable Person
|
51
|
+
|
52
|
+
A person who respects the time and energy that have been invested in the Project licensed herein, and acts accordingly. A Reasonable Person is broadly characterized as one who exercises his or her privilege to use, _not_ use, redistribute, modify, improve, worsen, review, report issues upon, participate in the community of, or ignore the work _without_ placing undue demands upon the Author. I.e., a Reasonable Person is a constituent of the majority of open source users and the population at large who are not Dicks.
|
53
|
+
|
54
|
+
### D. Dick
|
55
|
+
|
56
|
+
A person who _does not_ respect the time and energy that have been invested in the Project, and acts to punish such effort by giving others associated with the Project -- including, but not limited to, the Author -- a hard time. A Dick is nearly always selfish, but not necessarily with deliberate intent; some Dicks are merely thoughtless. The distinguishing characteristic of a Dick is that he or she places burdens upon Reasonable People, reducing their motivation to engage in open source activities. This damping effect is a significant detriment to the Project, to open source in general, to the production of new intellectual value in the world -- and, ultimately, to the Dick himself or herself.
|
57
|
+
|
58
|
+
> **NOTE:** Despite its original gender association, the word "Dick" is used herein in a _cultural_ context and not a _genital_ context. This License has chosen to adopt the term for its linguistic force and psychological impact, and sincerely regrets any inference of sexism. For purposes of the terms and conditions contained herein, it is understood that both men and women are equally capable of being Dicks.
|
59
|
+
|
60
|
+
> (But they shouldn't be.)
|
61
|
+
|
62
|
+
3. Permissions
|
63
|
+
--------------
|
64
|
+
|
65
|
+
The following privileges are granted explicitly and exclusively to Reasonable People. Although the Author acknowledges the practical unfeasibility of barring Dicks from enjoying the same privileges, they are nevertheless asked to refrain from any activity related to the Project _and/or_ to reconsider their behavior and stop being Dicks.
|
66
|
+
|
67
|
+
1. You are permitted to use the Project or any component of the Project.
|
68
|
+
|
69
|
+
2. You are permitted to redistribute the Project or any component of the Project, by itself or as part of a different work, provided that you give fair and reasonable credit back to the Author.
|
70
|
+
|
71
|
+
3. You are permitted to change the Project for your own needs or anyone else's. You may keep your changes to yourself or submit them back to the Author or the community, as you see fit, provided you are not a Dick about it.
|
72
|
+
|
73
|
+
4. You are permitted and encouraged to participate in any community related to the Project, or to create new communities.
|
74
|
+
|
75
|
+
5. You are permitted to report issues or problems with the Project, and to request that they be addressed, so long as the request is made in a reasonable fashion. (This privilege does _not_ oblige the Author to respond.)
|
76
|
+
|
77
|
+
6. You are permitted to make money from the Project. No recompense is owed to the Author unless by separate agreement, although sharing opportunities for mutual benefit is by no means discouraged.
|
78
|
+
|
79
|
+
7. You are permitted to discuss the Project in any medium, in any positive or negative spirit, so long as criticism is not libelous nor _ad hominem._ (I.e., don't lie, and keep it about the _work_ and not the _people._)
|
80
|
+
|
81
|
+
8. You are permitted to ignore the Project completely and make no use of it whatsoever. This right is irrevocable and absolute, and extended to Dicks and Reasonable People alike.
|
82
|
+
|
83
|
+
4. Limitations
|
84
|
+
--------------
|
85
|
+
|
86
|
+
The following restrictions are imposed explicitly and exclusively upon Dicks. These limitations are the inverse of the above privileges and are also tautological, as the prohibited actions are those _definitive_ of Dickhood.
|
87
|
+
|
88
|
+
1. You may not impede Reasonable People from exercising their privilege to use, redistribute, change, participate in, profit from, discuss, or ignore the Project.
|
89
|
+
|
90
|
+
2. You may not withhold the Author's credit for the Project, nor otherwise present the work of anyone else as your own.
|
91
|
+
|
92
|
+
3. You may not hold the Author responsible for any use or abuse of the Project by you or anyone else.
|
93
|
+
|
94
|
+
4. You may not troll, flame, nor dumb down any community associated with the Project.
|
95
|
+
|
96
|
+
5. Barring separate agreements, you may not _demand_ any time or attention on the part of the Author nor anyone else in the community. You may not hold the Author personally accountable for any issues you discover nor otherwise spread your own problems to other people.
|
97
|
+
|
98
|
+
6. You may not attempt to _compel_ time nor money from the Author nor any other community member by any means, including but not limited to legal action, intimidation, or annoyance.
|
99
|
+
|
100
|
+
7. You may not engage in _ad hominem_ (i.e. personal) attacks or criticism of the Author in the course of criticizing the Project.
|
101
|
+
|
102
|
+
8. You may not impede the absolute and irrevocable privilege of the Author and other members of the community to ignore you.
|
103
|
+
|
104
|
+
5. Contact
|
105
|
+
----------
|
106
|
+
For more information about this Project or the DBAD License, contact the Author at:
|
107
|
+
|
108
|
+
* Stephen Eley - <sfeley@gmail.com>
|
109
|
+
|
110
|
+
[1]: http://apache.org/licenses/LICENSE-2.0
|
data/README
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# sudden-motion-sensor
|
2
|
+
|
3
|
+
This gem reads data from the sudden motion sensor inside most Intel-based Macbooks and Macbook Pros and some late model Powerbooks. Returns the data in a 3-axis array of integers representing orientation along the X and Y axis and relative acceleration along the Z axis.
|
4
|
+
|
5
|
+
Based in part on code from http://fazibear.blogspot.com/2008/12/process-mac-sudden-motion-sensor-with.html.
|
6
|
+
|
7
|
+
More Info: http://en.wikipedia.org/wiki/Sudden_Motion_Sensor
|
8
|
+
|
9
|
+
Installation:
|
10
|
+
|
11
|
+
sudo gem install xunker-sudden_motion_sensor
|
12
|
+
|
13
|
+
Usage:
|
14
|
+
|
15
|
+
require 'rubygems'
|
16
|
+
require 'lib/sudden_motion_sensor'
|
17
|
+
|
18
|
+
100.times do
|
19
|
+
x,y,z = SuddenMotionSensor.values
|
20
|
+
puts "X: #{x}, Y: #{y}, Z: #{z}"
|
21
|
+
sleep 0.1
|
22
|
+
end
|
23
|
+
|
24
|
+
That code will print out the X,Y and Z data 100 times.
|
25
|
+
|
26
|
+
Data returned may be dependent on the model of Macbook you have and accelerometer part used. For the 2009 Unibody Macbook 15-inch and data returned will be X and Y as a signed integer from -255 to +255 and Z as an indication of gravity (~262 average at rest).
|
27
|
+
|
28
|
+
For X and Y axis, 0 indicated the unit is flat along the plane (either right-side-up or upside-down) and 255/-255 indicates 90-degree inclination.
|
29
|
+
|
30
|
+
Methods:
|
31
|
+
|
32
|
+
Values()
|
33
|
+
Returns (X, Y, Z)
|
34
|
+
Class method that returns an array of 3 signed integers indicating X Y and Z orientation.
|
35
|
+
|
36
|
+
|
37
|
+
|
data/demo.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require "inline"
|
3
|
+
|
4
|
+
class SuddenMotionSensor
|
5
|
+
class << self
|
6
|
+
inline do |builder|
|
7
|
+
builder.add_compile_flags '-x objective-c', '-framework IOKit'
|
8
|
+
builder.include "<IOKit/IOKitLib.h>"
|
9
|
+
builder.c %q{
|
10
|
+
VALUE values(){
|
11
|
+
|
12
|
+
struct data {
|
13
|
+
signed short x;
|
14
|
+
signed short y;
|
15
|
+
signed short z;
|
16
|
+
char pad[34];
|
17
|
+
};
|
18
|
+
|
19
|
+
kern_return_t result;
|
20
|
+
|
21
|
+
mach_port_t masterPort;
|
22
|
+
IOMasterPort(MACH_PORT_NULL, &masterPort);
|
23
|
+
CFMutableDictionaryRef matchingDictionary = IOServiceMatching("SMCMotionSensor");
|
24
|
+
|
25
|
+
io_iterator_t iterator;
|
26
|
+
result = IOServiceGetMatchingServices(masterPort, matchingDictionary, &iterator);
|
27
|
+
|
28
|
+
if(result != KERN_SUCCESS) {
|
29
|
+
return rb_str_new2("Error");
|
30
|
+
}
|
31
|
+
|
32
|
+
io_object_t device = IOIteratorNext(iterator);
|
33
|
+
IOObjectRelease(iterator);
|
34
|
+
if(device == 0){
|
35
|
+
return rb_str_new2("Error");
|
36
|
+
}
|
37
|
+
|
38
|
+
io_connect_t dataPort;
|
39
|
+
result = IOServiceOpen(device, mach_task_self(), 0, &dataPort);
|
40
|
+
IOObjectRelease(device);
|
41
|
+
|
42
|
+
if(result != KERN_SUCCESS) {
|
43
|
+
return rb_str_new2("Error");
|
44
|
+
}
|
45
|
+
|
46
|
+
IOItemCount structureInputSize;
|
47
|
+
IOByteCount structureOutputSize;
|
48
|
+
|
49
|
+
struct data inputStructure;
|
50
|
+
struct data outputStructure;
|
51
|
+
structureInputSize = sizeof(struct data);
|
52
|
+
structureOutputSize = sizeof(struct data);
|
53
|
+
|
54
|
+
memset(&inputStructure, 1, sizeof(inputStructure));
|
55
|
+
memset(&outputStructure, 0, sizeof(outputStructure));
|
56
|
+
|
57
|
+
result = IOConnectMethodStructureIStructureO(
|
58
|
+
dataPort,
|
59
|
+
5,
|
60
|
+
structureInputSize,
|
61
|
+
&structureOutputSize,
|
62
|
+
&inputStructure,
|
63
|
+
&outputStructure
|
64
|
+
);
|
65
|
+
|
66
|
+
if(result != KERN_SUCCESS) {
|
67
|
+
return rb_str_new2("Error");
|
68
|
+
}
|
69
|
+
|
70
|
+
IOServiceClose(dataPort);
|
71
|
+
|
72
|
+
VALUE coords = rb_ary_new2(3);
|
73
|
+
rb_ary_store(coords, 0, INT2FIX(outputStructure.x));
|
74
|
+
rb_ary_store(coords, 1, INT2FIX(outputStructure.y));
|
75
|
+
rb_ary_store(coords, 2, INT2FIX(outputStructure.z));
|
76
|
+
|
77
|
+
return coords;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
def values
|
83
|
+
# returns [x,y,z] which are signed integers of the value of each axis.
|
84
|
+
super
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sudden_motion_sensor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: universal-darwin-9
|
11
|
+
authors:
|
12
|
+
- Matthew Nielsen
|
13
|
+
autorequire: name
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-16 00:00:00 -06:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: RubyInline
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 8
|
30
|
+
- 4
|
31
|
+
version: 3.8.4
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Read orientation and acceleration data from the Sudden Motion Sensor inside many Apple Macbook and Macbook Pro laptops.
|
35
|
+
email: xunker@pyxidis.org
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- README
|
42
|
+
files:
|
43
|
+
- README
|
44
|
+
- Changelog
|
45
|
+
- LICENSE
|
46
|
+
- demo.rb
|
47
|
+
- lib/sudden_motion_sensor.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://n4k3d.com/code/sudden_motion_sensor/
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.6
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Reads data from Macbook Sudden Motion Sensor
|
78
|
+
test_files: []
|
79
|
+
|