tuxdroid 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/LICENSE.txt +340 -0
- data/Manifest.txt +8 -0
- data/README.txt +50 -0
- data/Rakefile +15 -0
- data/lib/tuxdroid.rb +210 -0
- data/lib/tuxdroid/constants.rb +150 -0
- data/test/test_tuxdroid.rb +363 -0
- metadata +61 -0
data/History.txt
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,340 @@
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
2
|
+
Version 2, June 1991
|
3
|
+
|
4
|
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
5
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
6
|
+
Everyone is permitted to copy and distribute verbatim copies
|
7
|
+
of this license document, but changing it is not allowed.
|
8
|
+
|
9
|
+
Preamble
|
10
|
+
|
11
|
+
The licenses for most software are designed to take away your
|
12
|
+
freedom to share and change it. By contrast, the GNU General Public
|
13
|
+
License is intended to guarantee your freedom to share and change free
|
14
|
+
software--to make sure the software is free for all its users. This
|
15
|
+
General Public License applies to most of the Free Software
|
16
|
+
Foundation's software and to any other program whose authors commit to
|
17
|
+
using it. (Some other Free Software Foundation software is covered by
|
18
|
+
the GNU Lesser General Public License instead.) You can apply it to
|
19
|
+
your programs, too.
|
20
|
+
|
21
|
+
When we speak of free software, we are referring to freedom, not
|
22
|
+
price. Our General Public Licenses are designed to make sure that you
|
23
|
+
have the freedom to distribute copies of free software (and charge for
|
24
|
+
this service if you wish), that you receive source code or can get it
|
25
|
+
if you want it, that you can change the software or use pieces of it
|
26
|
+
in new free programs; and that you know you can do these things.
|
27
|
+
|
28
|
+
To protect your rights, we need to make restrictions that forbid
|
29
|
+
anyone to deny you these rights or to ask you to surrender the rights.
|
30
|
+
These restrictions translate to certain responsibilities for you if you
|
31
|
+
distribute copies of the software, or if you modify it.
|
32
|
+
|
33
|
+
For example, if you distribute copies of such a program, whether
|
34
|
+
gratis or for a fee, you must give the recipients all the rights that
|
35
|
+
you have. You must make sure that they, too, receive or can get the
|
36
|
+
source code. And you must show them these terms so they know their
|
37
|
+
rights.
|
38
|
+
|
39
|
+
We protect your rights with two steps: (1) copyright the software, and
|
40
|
+
(2) offer you this license which gives you legal permission to copy,
|
41
|
+
distribute and/or modify the software.
|
42
|
+
|
43
|
+
Also, for each author's protection and ours, we want to make certain
|
44
|
+
that everyone understands that there is no warranty for this free
|
45
|
+
software. If the software is modified by someone else and passed on, we
|
46
|
+
want its recipients to know that what they have is not the original, so
|
47
|
+
that any problems introduced by others will not reflect on the original
|
48
|
+
authors' reputations.
|
49
|
+
|
50
|
+
Finally, any free program is threatened constantly by software
|
51
|
+
patents. We wish to avoid the danger that redistributors of a free
|
52
|
+
program will individually obtain patent licenses, in effect making the
|
53
|
+
program proprietary. To prevent this, we have made it clear that any
|
54
|
+
patent must be licensed for everyone's free use or not licensed at all.
|
55
|
+
|
56
|
+
The precise terms and conditions for copying, distribution and
|
57
|
+
modification follow.
|
58
|
+
|
59
|
+
GNU GENERAL PUBLIC LICENSE
|
60
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
61
|
+
|
62
|
+
0. This License applies to any program or other work which contains
|
63
|
+
a notice placed by the copyright holder saying it may be distributed
|
64
|
+
under the terms of this General Public License. The "Program", below,
|
65
|
+
refers to any such program or work, and a "work based on the Program"
|
66
|
+
means either the Program or any derivative work under copyright law:
|
67
|
+
that is to say, a work containing the Program or a portion of it,
|
68
|
+
either verbatim or with modifications and/or translated into another
|
69
|
+
language. (Hereinafter, translation is included without limitation in
|
70
|
+
the term "modification".) Each licensee is addressed as "you".
|
71
|
+
|
72
|
+
Activities other than copying, distribution and modification are not
|
73
|
+
covered by this License; they are outside its scope. The act of
|
74
|
+
running the Program is not restricted, and the output from the Program
|
75
|
+
is covered only if its contents constitute a work based on the
|
76
|
+
Program (independent of having been made by running the Program).
|
77
|
+
Whether that is true depends on what the Program does.
|
78
|
+
|
79
|
+
1. You may copy and distribute verbatim copies of the Program's
|
80
|
+
source code as you receive it, in any medium, provided that you
|
81
|
+
conspicuously and appropriately publish on each copy an appropriate
|
82
|
+
copyright notice and disclaimer of warranty; keep intact all the
|
83
|
+
notices that refer to this License and to the absence of any warranty;
|
84
|
+
and give any other recipients of the Program a copy of this License
|
85
|
+
along with the Program.
|
86
|
+
|
87
|
+
You may charge a fee for the physical act of transferring a copy, and
|
88
|
+
you may at your option offer warranty protection in exchange for a fee.
|
89
|
+
|
90
|
+
2. You may modify your copy or copies of the Program or any portion
|
91
|
+
of it, thus forming a work based on the Program, and copy and
|
92
|
+
distribute such modifications or work under the terms of Section 1
|
93
|
+
above, provided that you also meet all of these conditions:
|
94
|
+
|
95
|
+
a) You must cause the modified files to carry prominent notices
|
96
|
+
stating that you changed the files and the date of any change.
|
97
|
+
|
98
|
+
b) You must cause any work that you distribute or publish, that in
|
99
|
+
whole or in part contains or is derived from the Program or any
|
100
|
+
part thereof, to be licensed as a whole at no charge to all third
|
101
|
+
parties under the terms of this License.
|
102
|
+
|
103
|
+
c) If the modified program normally reads commands interactively
|
104
|
+
when run, you must cause it, when started running for such
|
105
|
+
interactive use in the most ordinary way, to print or display an
|
106
|
+
announcement including an appropriate copyright notice and a
|
107
|
+
notice that there is no warranty (or else, saying that you provide
|
108
|
+
a warranty) and that users may redistribute the program under
|
109
|
+
these conditions, and telling the user how to view a copy of this
|
110
|
+
License. (Exception: if the Program itself is interactive but
|
111
|
+
does not normally print such an announcement, your work based on
|
112
|
+
the Program is not required to print an announcement.)
|
113
|
+
|
114
|
+
These requirements apply to the modified work as a whole. If
|
115
|
+
identifiable sections of that work are not derived from the Program,
|
116
|
+
and can be reasonably considered independent and separate works in
|
117
|
+
themselves, then this License, and its terms, do not apply to those
|
118
|
+
sections when you distribute them as separate works. But when you
|
119
|
+
distribute the same sections as part of a whole which is a work based
|
120
|
+
on the Program, the distribution of the whole must be on the terms of
|
121
|
+
this License, whose permissions for other licensees extend to the
|
122
|
+
entire whole, and thus to each and every part regardless of who wrote it.
|
123
|
+
|
124
|
+
Thus, it is not the intent of this section to claim rights or contest
|
125
|
+
your rights to work written entirely by you; rather, the intent is to
|
126
|
+
exercise the right to control the distribution of derivative or
|
127
|
+
collective works based on the Program.
|
128
|
+
|
129
|
+
In addition, mere aggregation of another work not based on the Program
|
130
|
+
with the Program (or with a work based on the Program) on a volume of
|
131
|
+
a storage or distribution medium does not bring the other work under
|
132
|
+
the scope of this License.
|
133
|
+
|
134
|
+
3. You may copy and distribute the Program (or a work based on it,
|
135
|
+
under Section 2) in object code or executable form under the terms of
|
136
|
+
Sections 1 and 2 above provided that you also do one of the following:
|
137
|
+
|
138
|
+
a) Accompany it with the complete corresponding machine-readable
|
139
|
+
source code, which must be distributed under the terms of Sections
|
140
|
+
1 and 2 above on a medium customarily used for software interchange; or,
|
141
|
+
|
142
|
+
b) Accompany it with a written offer, valid for at least three
|
143
|
+
years, to give any third party, for a charge no more than your
|
144
|
+
cost of physically performing source distribution, a complete
|
145
|
+
machine-readable copy of the corresponding source code, to be
|
146
|
+
distributed under the terms of Sections 1 and 2 above on a medium
|
147
|
+
customarily used for software interchange; or,
|
148
|
+
|
149
|
+
c) Accompany it with the information you received as to the offer
|
150
|
+
to distribute corresponding source code. (This alternative is
|
151
|
+
allowed only for noncommercial distribution and only if you
|
152
|
+
received the program in object code or executable form with such
|
153
|
+
an offer, in accord with Subsection b above.)
|
154
|
+
|
155
|
+
The source code for a work means the preferred form of the work for
|
156
|
+
making modifications to it. For an executable work, complete source
|
157
|
+
code means all the source code for all modules it contains, plus any
|
158
|
+
associated interface definition files, plus the scripts used to
|
159
|
+
control compilation and installation of the executable. However, as a
|
160
|
+
special exception, the source code distributed need not include
|
161
|
+
anything that is normally distributed (in either source or binary
|
162
|
+
form) with the major components (compiler, kernel, and so on) of the
|
163
|
+
operating system on which the executable runs, unless that component
|
164
|
+
itself accompanies the executable.
|
165
|
+
|
166
|
+
If distribution of executable or object code is made by offering
|
167
|
+
access to copy from a designated place, then offering equivalent
|
168
|
+
access to copy the source code from the same place counts as
|
169
|
+
distribution of the source code, even though third parties are not
|
170
|
+
compelled to copy the source along with the object code.
|
171
|
+
|
172
|
+
4. You may not copy, modify, sublicense, or distribute the Program
|
173
|
+
except as expressly provided under this License. Any attempt
|
174
|
+
otherwise to copy, modify, sublicense or distribute the Program is
|
175
|
+
void, and will automatically terminate your rights under this License.
|
176
|
+
However, parties who have received copies, or rights, from you under
|
177
|
+
this License will not have their licenses terminated so long as such
|
178
|
+
parties remain in full compliance.
|
179
|
+
|
180
|
+
5. You are not required to accept this License, since you have not
|
181
|
+
signed it. However, nothing else grants you permission to modify or
|
182
|
+
distribute the Program or its derivative works. These actions are
|
183
|
+
prohibited by law if you do not accept this License. Therefore, by
|
184
|
+
modifying or distributing the Program (or any work based on the
|
185
|
+
Program), you indicate your acceptance of this License to do so, and
|
186
|
+
all its terms and conditions for copying, distributing or modifying
|
187
|
+
the Program or works based on it.
|
188
|
+
|
189
|
+
6. Each time you redistribute the Program (or any work based on the
|
190
|
+
Program), the recipient automatically receives a license from the
|
191
|
+
original licensor to copy, distribute or modify the Program subject to
|
192
|
+
these terms and conditions. You may not impose any further
|
193
|
+
restrictions on the recipients' exercise of the rights granted herein.
|
194
|
+
You are not responsible for enforcing compliance by third parties to
|
195
|
+
this License.
|
196
|
+
|
197
|
+
7. If, as a consequence of a court judgment or allegation of patent
|
198
|
+
infringement or for any other reason (not limited to patent issues),
|
199
|
+
conditions are imposed on you (whether by court order, agreement or
|
200
|
+
otherwise) that contradict the conditions of this License, they do not
|
201
|
+
excuse you from the conditions of this License. If you cannot
|
202
|
+
distribute so as to satisfy simultaneously your obligations under this
|
203
|
+
License and any other pertinent obligations, then as a consequence you
|
204
|
+
may not distribute the Program at all. For example, if a patent
|
205
|
+
license would not permit royalty-free redistribution of the Program by
|
206
|
+
all those who receive copies directly or indirectly through you, then
|
207
|
+
the only way you could satisfy both it and this License would be to
|
208
|
+
refrain entirely from distribution of the Program.
|
209
|
+
|
210
|
+
If any portion of this section is held invalid or unenforceable under
|
211
|
+
any particular circumstance, the balance of the section is intended to
|
212
|
+
apply and the section as a whole is intended to apply in other
|
213
|
+
circumstances.
|
214
|
+
|
215
|
+
It is not the purpose of this section to induce you to infringe any
|
216
|
+
patents or other property right claims or to contest validity of any
|
217
|
+
such claims; this section has the sole purpose of protecting the
|
218
|
+
integrity of the free software distribution system, which is
|
219
|
+
implemented by public license practices. Many people have made
|
220
|
+
generous contributions to the wide range of software distributed
|
221
|
+
through that system in reliance on consistent application of that
|
222
|
+
system; it is up to the author/donor to decide if he or she is willing
|
223
|
+
to distribute software through any other system and a licensee cannot
|
224
|
+
impose that choice.
|
225
|
+
|
226
|
+
This section is intended to make thoroughly clear what is believed to
|
227
|
+
be a consequence of the rest of this License.
|
228
|
+
|
229
|
+
8. If the distribution and/or use of the Program is restricted in
|
230
|
+
certain countries either by patents or by copyrighted interfaces, the
|
231
|
+
original copyright holder who places the Program under this License
|
232
|
+
may add an explicit geographical distribution limitation excluding
|
233
|
+
those countries, so that distribution is permitted only in or among
|
234
|
+
countries not thus excluded. In such case, this License incorporates
|
235
|
+
the limitation as if written in the body of this License.
|
236
|
+
|
237
|
+
9. The Free Software Foundation may publish revised and/or new versions
|
238
|
+
of the General Public License from time to time. Such new versions will
|
239
|
+
be similar in spirit to the present version, but may differ in detail to
|
240
|
+
address new problems or concerns.
|
241
|
+
|
242
|
+
Each version is given a distinguishing version number. If the Program
|
243
|
+
specifies a version number of this License which applies to it and "any
|
244
|
+
later version", you have the option of following the terms and conditions
|
245
|
+
either of that version or of any later version published by the Free
|
246
|
+
Software Foundation. If the Program does not specify a version number of
|
247
|
+
this License, you may choose any version ever published by the Free Software
|
248
|
+
Foundation.
|
249
|
+
|
250
|
+
10. If you wish to incorporate parts of the Program into other free
|
251
|
+
programs whose distribution conditions are different, write to the author
|
252
|
+
to ask for permission. For software which is copyrighted by the Free
|
253
|
+
Software Foundation, write to the Free Software Foundation; we sometimes
|
254
|
+
make exceptions for this. Our decision will be guided by the two goals
|
255
|
+
of preserving the free status of all derivatives of our free software and
|
256
|
+
of promoting the sharing and reuse of software generally.
|
257
|
+
|
258
|
+
NO WARRANTY
|
259
|
+
|
260
|
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261
|
+
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
262
|
+
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
263
|
+
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
264
|
+
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
265
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
266
|
+
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
267
|
+
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
268
|
+
REPAIR OR CORRECTION.
|
269
|
+
|
270
|
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
271
|
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
272
|
+
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
273
|
+
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
274
|
+
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
275
|
+
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
276
|
+
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
277
|
+
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278
|
+
POSSIBILITY OF SUCH DAMAGES.
|
279
|
+
|
280
|
+
END OF TERMS AND CONDITIONS
|
281
|
+
|
282
|
+
How to Apply These Terms to Your New Programs
|
283
|
+
|
284
|
+
If you develop a new program, and you want it to be of the greatest
|
285
|
+
possible use to the public, the best way to achieve this is to make it
|
286
|
+
free software which everyone can redistribute and change under these terms.
|
287
|
+
|
288
|
+
To do so, attach the following notices to the program. It is safest
|
289
|
+
to attach them to the start of each source file to most effectively
|
290
|
+
convey the exclusion of warranty; and each file should have at least
|
291
|
+
the "copyright" line and a pointer to where the full notice is found.
|
292
|
+
|
293
|
+
<one line to give the program's name and a brief idea of what it does.>
|
294
|
+
Copyright (C) <year> <name of author>
|
295
|
+
|
296
|
+
This program is free software; you can redistribute it and/or modify
|
297
|
+
it under the terms of the GNU General Public License as published by
|
298
|
+
the Free Software Foundation; either version 2 of the License, or
|
299
|
+
(at your option) any later version.
|
300
|
+
|
301
|
+
This program is distributed in the hope that it will be useful,
|
302
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
303
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
304
|
+
GNU General Public License for more details.
|
305
|
+
|
306
|
+
You should have received a copy of the GNU General Public License along
|
307
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
308
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
309
|
+
|
310
|
+
Also add information on how to contact you by electronic and paper mail.
|
311
|
+
|
312
|
+
If the program is interactive, make it output a short notice like this
|
313
|
+
when it starts in an interactive mode:
|
314
|
+
|
315
|
+
Gnomovision version 69, Copyright (C) year name of author
|
316
|
+
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
317
|
+
This is free software, and you are welcome to redistribute it
|
318
|
+
under certain conditions; type `show c' for details.
|
319
|
+
|
320
|
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
321
|
+
parts of the General Public License. Of course, the commands you use may
|
322
|
+
be called something other than `show w' and `show c'; they could even be
|
323
|
+
mouse-clicks or menu items--whatever suits your program.
|
324
|
+
|
325
|
+
You should also get your employer (if you work as a programmer) or your
|
326
|
+
school, if any, to sign a "copyright disclaimer" for the program, if
|
327
|
+
necessary. Here is a sample; alter the names:
|
328
|
+
|
329
|
+
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
330
|
+
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
331
|
+
|
332
|
+
<signature of Ty Coon>, 1 April 1989
|
333
|
+
Ty Coon, President of Vice
|
334
|
+
|
335
|
+
This General Public License does not permit incorporating your program into
|
336
|
+
proprietary programs. If your program is a subroutine library, you may
|
337
|
+
consider it more useful to permit linking proprietary applications with the
|
338
|
+
library. If this is what you want to do, use the GNU Lesser General
|
339
|
+
Public License instead of this License.
|
340
|
+
|
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
TuxDroid
|
2
|
+
by Andrew Montgomery
|
3
|
+
http://www.darkliquid.co.uk
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A Ruby Command Interface for the TuxDroid from Kysoh
|
8
|
+
See: http://www.tuxisalive.com for more info
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
* Simple interface to all basic actions
|
13
|
+
* No sound support yet
|
14
|
+
* No reading the status of any motors or sensors yet
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
require 'tuxdroid'
|
19
|
+
tux = TuxDroid::Tux.new
|
20
|
+
tux.mouth :open
|
21
|
+
tux.mouth :close
|
22
|
+
tux.wings :flap, :times => 2, :speed => 3
|
23
|
+
|
24
|
+
== REQUIREMENTS:
|
25
|
+
|
26
|
+
* ruby-usb svn version (last tested with revision 512)
|
27
|
+
* libusb
|
28
|
+
|
29
|
+
== INSTALL:
|
30
|
+
|
31
|
+
* sudo gem install tuxdroid
|
32
|
+
|
33
|
+
== LICENSE:
|
34
|
+
|
35
|
+
(The GPL2 License)
|
36
|
+
|
37
|
+
Copyright (c) 2007 Andrew Montgomery
|
38
|
+
|
39
|
+
This program is free software; you can redistribute it and/or modify
|
40
|
+
it under the terms of the GNU General Public License as published by
|
41
|
+
the Free Software Foundation; version 2 ONLY.
|
42
|
+
|
43
|
+
This program is distributed in the hope that it will be useful,
|
44
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
45
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
46
|
+
GNU General Public License for more details.
|
47
|
+
|
48
|
+
You should have received a copy of the GNU General Public License along
|
49
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
50
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/tuxdroid'
|
6
|
+
|
7
|
+
Hoe.new('tuxdroid', TuxDroid::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'tuxdroid'
|
9
|
+
p.summary = 'A Ruby Command Interface API to the TuxDroid from Kysoh'
|
10
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
11
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
12
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
# vim: syntax=Ruby
|
data/lib/tuxdroid.rb
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
# TuxDroid module - everything to do with Tux Droid
|
2
|
+
#
|
3
|
+
# License: GPL2
|
4
|
+
#
|
5
|
+
# Copyright: Andrew Montgomery <darkliquid@darkliquid.co.uk>
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'usb'
|
9
|
+
require File.dirname(__FILE__) + '/tuxdroid/constants.rb'
|
10
|
+
|
11
|
+
module TuxDroid
|
12
|
+
|
13
|
+
# Tux Interface Class
|
14
|
+
#
|
15
|
+
class Tux
|
16
|
+
|
17
|
+
include USBCodes
|
18
|
+
|
19
|
+
attr_reader :usb_status
|
20
|
+
|
21
|
+
# Creates a new interface between ruby and the TuxDroid
|
22
|
+
def initialize
|
23
|
+
@tux_device = self.class.get_usb_device()
|
24
|
+
@tux_handle = self.class.get_usb_interface(@tux_device)
|
25
|
+
@usb_status = :connected
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Command wrappers to low-level send_command routine
|
30
|
+
#
|
31
|
+
|
32
|
+
# Accepts:
|
33
|
+
# * :open => opens mouth
|
34
|
+
# * :closes => closes mouth
|
35
|
+
# * :move => toggles mouth (specify option ":times => n" for n amount of toggles)
|
36
|
+
def mouth(cmd, options = {})
|
37
|
+
validate_within(options, :times => 0..255)
|
38
|
+
case cmd
|
39
|
+
when :open
|
40
|
+
send_command(Actions::OPEN_MOUTH)
|
41
|
+
when :close
|
42
|
+
send_command(Actions::CLOSE_MOUTH)
|
43
|
+
when :move
|
44
|
+
send_command(Actions::MOVE_MOUTH, options[:times] || 1)
|
45
|
+
else
|
46
|
+
raise UnknownTuxDroidActionError.new("Command: #{cmd.inspect} Options: #{options.inspect}")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Accepts:
|
51
|
+
# * :open => opens eyes
|
52
|
+
# * :closes => closes eyes
|
53
|
+
# * :blink => toggles eyes (specify option ":times => n" for n amount of toggles)
|
54
|
+
# * :stop => stops current eye motions
|
55
|
+
def eyes(cmd, options = {})
|
56
|
+
validate_within(options, :times => 0..255)
|
57
|
+
case cmd
|
58
|
+
when :open
|
59
|
+
send_command(Actions::OPEN_EYES)
|
60
|
+
when :close
|
61
|
+
send_command(Actions::BLINK_EYES, 1)
|
62
|
+
when :blink
|
63
|
+
send_command(Actions::BLINK_EYES, options[:times] || 1)
|
64
|
+
when :stop
|
65
|
+
send_command(Actions::STOP_EYES)
|
66
|
+
else
|
67
|
+
raise UnknownTuxDroidActionError.new("Command: #{cmd.inspect} Options: #{options.inspect}")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Accepts:
|
72
|
+
# * :toggle => toggles wings, options are :speed => (1..5)
|
73
|
+
# * :reset => runs wing reset routine (flaps twice)
|
74
|
+
# * :flap => toggles wings, options are :times => n (n amount of times), :speed => (1..5)
|
75
|
+
def wings(cmd, options = {})
|
76
|
+
validate_within(options, :times => 0..255, :speed => 1..5)
|
77
|
+
case cmd
|
78
|
+
when :toggle
|
79
|
+
send_command(Actions::WAVE_WINGS, 1, options[:speed] || 3)
|
80
|
+
when :reset
|
81
|
+
send_command(Actions::RESET_WINGS)
|
82
|
+
when :flap
|
83
|
+
send_command(Actions::WAVE_WINGS, options[:times] || 1, options[:speed] || 3)
|
84
|
+
else
|
85
|
+
raise UnknownTuxDroidActionError.new("Command: #{cmd.inspect} Options: #{options.inspect}")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Accepts:
|
90
|
+
# * :left => spins left roughly 90 degrees, options are :times => n (n amount of times), :speed => (1..5)
|
91
|
+
# * :right => spins right roughly 90 degrees, options are :times => n (n amount of times), :speed => (1..5)
|
92
|
+
# * :stop => stops current spinning motion
|
93
|
+
def spin(cmd, options = {})
|
94
|
+
validate_within(options, :times => 0..255, :speed => 1..5)
|
95
|
+
case cmd
|
96
|
+
when :left
|
97
|
+
send_command(Actions::SPIN_LEFT, options[:times] || 1, options[:speed] || 3)
|
98
|
+
when :right
|
99
|
+
send_command(Actions::SPIN_RIGHT, options[:times] || 1, options[:speed] || 3)
|
100
|
+
when :stop
|
101
|
+
send_command(Actions::STOP_SPIN)
|
102
|
+
else
|
103
|
+
raise UnknownTuxDroidActionError.new("Command: #{cmd.inspect} Options: #{options.inspect}")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Accepts:
|
108
|
+
# * :on => light up both eyes
|
109
|
+
# * :off => turn off both eyes
|
110
|
+
# * :left_on => light up left eye
|
111
|
+
# * :left_off => turn off left eye
|
112
|
+
# * :right_on => light up right eye
|
113
|
+
# * :right_off => turn off right eye
|
114
|
+
# * :blink => blink both eyes, options are :times => n (n amount of blinks), :delay => n (n x 4ms delay between blinks)
|
115
|
+
def leds(cmd, options = {})
|
116
|
+
validate_within(options, :times => 0..255, :delay => 0..255)
|
117
|
+
case cmd
|
118
|
+
when :on
|
119
|
+
send_command(Actions::LED_ON)
|
120
|
+
when :off
|
121
|
+
send_command(Actions::LED_OFF)
|
122
|
+
when :left_on
|
123
|
+
send_command(Actions::LED_LEFT_ON)
|
124
|
+
when :left_off
|
125
|
+
send_command(Actions::LED_LEFT_OFF)
|
126
|
+
when :right_on
|
127
|
+
send_command(Actions::LED_RIGHT_ON)
|
128
|
+
when :right_off
|
129
|
+
send_command(Actions::LED_RIGHT_OFF)
|
130
|
+
when :blink
|
131
|
+
send_command(Actions::LED_BLINK, options[:times] || 1, options[:delay] || 20)
|
132
|
+
else
|
133
|
+
raise UnknownTuxDroidActionError.new("Command: #{cmd.inspect} Options: #{options.inspect}")
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# Command validators
|
139
|
+
#
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def validate_within(options, checks)
|
144
|
+
checks.each do |k,v|
|
145
|
+
unless options[k].nil? or v.include?(options[k])
|
146
|
+
raise TuxDroidCommandOptionsError.new("#{k.inspect} is not within #{v.inspect}")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Low-level methods
|
153
|
+
#
|
154
|
+
|
155
|
+
private
|
156
|
+
|
157
|
+
def self.get_usb_device
|
158
|
+
tux_device = USB.devices.find {|d| d.idProduct == PRODUCT_ID and d.idVendor == VENDOR_ID }
|
159
|
+
raise USBDeviceNotFoundError if tux_device.nil?
|
160
|
+
raise FirmwareTooOldError if tux_device.bcdDevice < FIRMWARE_REV
|
161
|
+
return tux_device
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.get_usb_interface(tux_device)
|
165
|
+
tux_handle = tux_device.open
|
166
|
+
raise CannotOpenDeviceError if tux_handle.nil?
|
167
|
+
|
168
|
+
retries = 0
|
169
|
+
begin
|
170
|
+
error_code = tux_handle.usb_claim_interface(INTERFACE)
|
171
|
+
raise CannotClaimInterfaceError unless error_code.nil?
|
172
|
+
rescue CannotClaimInterfaceError
|
173
|
+
tux_handle.usb_detach_kernel_driver_np(INTERFACE);
|
174
|
+
if retries.zero?
|
175
|
+
retries += 1
|
176
|
+
retry
|
177
|
+
else
|
178
|
+
raise $!
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
error_code = tux_handle.set_altinterface(0)
|
183
|
+
raise CannotSetAlternativeInterfaceError unless error_code.nil?
|
184
|
+
|
185
|
+
tux_handle
|
186
|
+
end
|
187
|
+
|
188
|
+
def send_command(command, param1 = 0, param2 = 0, param3 = 0)
|
189
|
+
bytes = [0]
|
190
|
+
bytes << command
|
191
|
+
bytes << param1.to_i
|
192
|
+
bytes << param2.to_i
|
193
|
+
bytes << param3.to_i
|
194
|
+
@tux_handle.usb_interrupt_write(WRITE_ENDPOINT, bytes.pack('C*'), WRITE_TIMEOUT)
|
195
|
+
end
|
196
|
+
|
197
|
+
def get_status
|
198
|
+
# Send a dongle command (I think)
|
199
|
+
@tux_handle.usb_interrupt_write(WRITE_ENDPOINT, [1,1,0,0,0].pack('C*'), WRITE_TIMEOUT)
|
200
|
+
# Build an empty binary string
|
201
|
+
data_pack = ([0]*64).pack('C*')
|
202
|
+
# Read usb data into binary string
|
203
|
+
@tux_handle.usb_interrupt_read(READ_ENDPOINT, data_pack, READ_TIMEOUT)
|
204
|
+
# Return the result as an array
|
205
|
+
return data_pack.unpack('C*')
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module TuxDroid
|
2
|
+
|
3
|
+
VERSION = '0.1.0'
|
4
|
+
|
5
|
+
module Actions
|
6
|
+
BLINK_EYES = 0x40 # param1: number
|
7
|
+
STOP_EYES = 0x32
|
8
|
+
OPEN_EYES = 0x33
|
9
|
+
MOVE_MOUTH = 0x41 # param1: number
|
10
|
+
|
11
|
+
OPEN_MOUTH = 0x34
|
12
|
+
CLOSE_MOUTH = 0x35
|
13
|
+
STOP_MOUTH = 0x36
|
14
|
+
WAVE_WINGS = 0x80 # param1: number, param2: speed (1-5)
|
15
|
+
|
16
|
+
STOP_WINGS = 0x30
|
17
|
+
RESET_WINGS = 0x31
|
18
|
+
SPIN_LEFT = 0x82 # param1: number*90 degrees, param2: speed (1-5)
|
19
|
+
SPIN_RIGHT = 0x83 # param1: number*90 degrees, param2: speed (1-5)
|
20
|
+
STOP_SPIN = 0x37
|
21
|
+
|
22
|
+
TURN_IR_ON = 0x17
|
23
|
+
TURN_IR_OFF = 0x18
|
24
|
+
IR_SEND_RC5 = 0x91 # param1: xxTAAAAA (T: toggle bit, A: RC5 5 bits address)
|
25
|
+
# param2: xxCCCCCC (C: RC5 6 bits command)
|
26
|
+
|
27
|
+
LED_ON = 0x1A
|
28
|
+
LED_OFF = 0x1B
|
29
|
+
LED_LEFT_ON = 0x1C
|
30
|
+
LED_LEFT_OFF = 0x1D
|
31
|
+
LED_RIGHT_ON = 0x1E
|
32
|
+
LED_RIGHT_OFF = 0x1F
|
33
|
+
LED_BLINK = 0x9A # param1: toggles, param2: delay*4ms
|
34
|
+
|
35
|
+
PLAY_SOUND = 0x90 # param1: number, param2: volume
|
36
|
+
STORE_SOUND = 0x52 # param1: number
|
37
|
+
STORE_INDEX = 0xD0 # param1: lower, param2: middle, param3: higher
|
38
|
+
TEST_SOUND = 0x10
|
39
|
+
MUTE = 0x92 # param1: state,
|
40
|
+
end
|
41
|
+
|
42
|
+
module Remote
|
43
|
+
K_0 = 0x00
|
44
|
+
K_1 = 0x01
|
45
|
+
K_2 = 0x02
|
46
|
+
K_3 = 0x03
|
47
|
+
K_4 = 0x04
|
48
|
+
K_5 = 0x05
|
49
|
+
K_6 = 0x06
|
50
|
+
K_7 = 0x07
|
51
|
+
K_8 = 0x08
|
52
|
+
K_9 = 0x09
|
53
|
+
K_STANDBY = 0x0C
|
54
|
+
K_MUTE = 0x0D
|
55
|
+
K_VOLUMEPLUS = 0x10
|
56
|
+
K_VOLUMEMINUS = 0x11
|
57
|
+
K_ESCAPE = 0x12
|
58
|
+
K_YES = 0x13
|
59
|
+
K_NO = 0x14
|
60
|
+
K_BACKSPACE = 0x15
|
61
|
+
K_STARTVOIP = 0x16
|
62
|
+
K_RECEIVECALL = 0x17
|
63
|
+
K_HANGUP = 0x18
|
64
|
+
K_STAR = 0x19
|
65
|
+
K_SHARP = 0x1A
|
66
|
+
K_RED = 0x1B
|
67
|
+
K_GREEN = 0x1C
|
68
|
+
K_BLUE = 0x1D
|
69
|
+
K_YELLOW = 0x1E
|
70
|
+
K_CHANNELPLUS = 0x20
|
71
|
+
K_CHANNELMINUS = 0x21
|
72
|
+
K_UP = 0x22
|
73
|
+
K_DOWN = 0x23
|
74
|
+
K_LEFT = 0x24
|
75
|
+
K_RIGHT = 0x25
|
76
|
+
K_OK = 0x26
|
77
|
+
K_FASTREWIND = 0x32
|
78
|
+
K_FASTFORWARD = 0x34
|
79
|
+
K_PLAYPAUSE = 0x35
|
80
|
+
K_STOP = 0x36
|
81
|
+
K_RECORDING = 0x37
|
82
|
+
K_PREVIOUS = 0x38
|
83
|
+
K_NEXT = 0x39
|
84
|
+
K_MENU = 0x3A
|
85
|
+
K_MOUSE = 0x3B
|
86
|
+
K_ALT = 0x3C
|
87
|
+
end
|
88
|
+
|
89
|
+
module Status
|
90
|
+
WINGS_MOTOR_BACKWARD = 0x01
|
91
|
+
SPIN_MOTOR_BACKWARD = 0x02
|
92
|
+
SPIN_MOTOR_FORWARD = 0x03
|
93
|
+
MOUTH_OPEN_POSITION = 0x04
|
94
|
+
MOUTH_CLOSED_POSITION = 0x05
|
95
|
+
HEAD_PUSH_POSITION = 0x06
|
96
|
+
CHARGER_INHIBIT_SIGNAL = 0x07
|
97
|
+
WINGS_POSITION_SWITCH = 0x08
|
98
|
+
MOTOR_FOR_WINGS = 0x09
|
99
|
+
LEFT_BLUE_LED = 0x0A
|
100
|
+
I2C_SDA_LINE = 0x0B
|
101
|
+
I2C_SCL_LINE = 0x0C
|
102
|
+
HEAD_MOTOR_FOR_MOUTH = 0x0D
|
103
|
+
HEAD_MOTOR_FOR_EYES = 0x0E
|
104
|
+
IR_RECEIVER_SIGNAL = 0x0F
|
105
|
+
SPIN_POSITION_SWITCH = 0x10
|
106
|
+
WINGS_MOTOR_FORWARD = 0x11
|
107
|
+
IR_LED = 0x12
|
108
|
+
EYES_OPEN_POSITION_SWITCH = 0x13
|
109
|
+
EYES_CLOSED_POSITION_SWITCH = 0x14
|
110
|
+
LEFT_WING_PUSH = 0x15
|
111
|
+
RIGHT_WING_PUSH = 0x16
|
112
|
+
POWER_PLUG_SWITCH = 0x17
|
113
|
+
HEAD_PUSH_SWITCH = 0x18
|
114
|
+
CHARGER_LED_STATUS = 0x19
|
115
|
+
MUTE_STATUS = 0x1A
|
116
|
+
LIGHT_LEVEL = 0x1B
|
117
|
+
EYES_POSITION_COUNTER = 0x1C
|
118
|
+
MOUTH_POSITION_COUNTER = 0x1D
|
119
|
+
WINGS_POSITION_COUNTER = 0x1E
|
120
|
+
SPIN_POSITION_COUNTER = 0x1F
|
121
|
+
RIGHT_BLUE_LED = 0x20
|
122
|
+
RF_CONNECTED = 0x21
|
123
|
+
IR_CODE = 0x22
|
124
|
+
SOUND_COUNT = 0x23
|
125
|
+
PONG = 0x24
|
126
|
+
end
|
127
|
+
|
128
|
+
module USBCodes
|
129
|
+
# Constants
|
130
|
+
PRODUCT_ID = 0xFF07
|
131
|
+
VENDOR_ID = 0x03EB
|
132
|
+
FIRMWARE_REV = 0x100
|
133
|
+
INTERFACE = 0x03
|
134
|
+
RECV_LENGTH = 0x05
|
135
|
+
SEND_LENGTH = 0x05
|
136
|
+
WRITE_ENDPOINT = 0x05
|
137
|
+
READ_ENDPOINT = 0x84
|
138
|
+
WRITE_TIMEOUT = 5000
|
139
|
+
READ_TIMEOUT = 5000
|
140
|
+
end
|
141
|
+
|
142
|
+
# Tux Exceptions
|
143
|
+
class FirmwareTooOldError < StandardError; end
|
144
|
+
class CannotOpenDeviceError < StandardError; end
|
145
|
+
class CannotClaimInterfaceError < StandardError; end
|
146
|
+
class CannotSetAlternativeInterfaceError < StandardError; end
|
147
|
+
class UnknownTuxDroidActionError < StandardError; end
|
148
|
+
class TuxDroidCommandOptionsError < StandardError; end
|
149
|
+
class USBDeviceNotFoundError < StandardError; end
|
150
|
+
end
|
@@ -0,0 +1,363 @@
|
|
1
|
+
require './lib/tuxdroid.rb'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
class TuxDroidTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
#
|
9
|
+
# Eye tests
|
10
|
+
#
|
11
|
+
|
12
|
+
def test_eyes_open
|
13
|
+
tux = setup_tux do |i|
|
14
|
+
expect_command(i, TuxDroid::Actions::OPEN_EYES)
|
15
|
+
end
|
16
|
+
assert_nothing_raised { tux.eyes :open }
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_eyes_close
|
20
|
+
tux = setup_tux do |i|
|
21
|
+
expect_command(i, TuxDroid::Actions::BLINK_EYES, 1)
|
22
|
+
end
|
23
|
+
assert_nothing_raised { tux.eyes :close }
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_eyes_blink
|
27
|
+
tux = setup_tux do |i|
|
28
|
+
expect_command(i, TuxDroid::Actions::BLINK_EYES, 1)
|
29
|
+
end
|
30
|
+
assert_nothing_raised { tux.eyes :blink }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_eyes_blink_3_times
|
34
|
+
tux = setup_tux do |i|
|
35
|
+
expect_command(i, TuxDroid::Actions::BLINK_EYES, 3)
|
36
|
+
end
|
37
|
+
assert_nothing_raised { tux.eyes :blink, :times => 3 }
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_eyes_stop
|
41
|
+
tux = setup_tux do |i|
|
42
|
+
expect_command(i, TuxDroid::Actions::STOP_EYES)
|
43
|
+
end
|
44
|
+
assert_nothing_raised { tux.eyes :stop }
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_eyes_raise_on_unknown_action
|
48
|
+
tux = setup_tux
|
49
|
+
assert_raises(TuxDroid::UnknownTuxDroidActionError) { tux.eyes :explode }
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# LED tests
|
54
|
+
#
|
55
|
+
|
56
|
+
def test_leds_both_turn_on
|
57
|
+
tux = setup_tux do |i|
|
58
|
+
expect_command(i, TuxDroid::Actions::LED_ON)
|
59
|
+
end
|
60
|
+
assert_nothing_raised { tux.leds :on }
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_leds_both_turn_off
|
64
|
+
tux = setup_tux do |i|
|
65
|
+
expect_command(i, TuxDroid::Actions::LED_OFF)
|
66
|
+
end
|
67
|
+
assert_nothing_raised { tux.leds :off }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_leds_left_turn_on
|
71
|
+
tux = setup_tux do |i|
|
72
|
+
expect_command(i, TuxDroid::Actions::LED_LEFT_ON)
|
73
|
+
end
|
74
|
+
assert_nothing_raised { tux.leds :left_on }
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_leds_left_turn_off
|
78
|
+
tux = setup_tux do |i|
|
79
|
+
expect_command(i, TuxDroid::Actions::LED_LEFT_OFF)
|
80
|
+
end
|
81
|
+
assert_nothing_raised { tux.leds :left_off }
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_leds_right_turn_on
|
85
|
+
tux = setup_tux do |i|
|
86
|
+
expect_command(i, TuxDroid::Actions::LED_RIGHT_ON)
|
87
|
+
end
|
88
|
+
assert_nothing_raised { tux.leds :right_on }
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_leds_right_turn_off
|
92
|
+
tux = setup_tux do |i|
|
93
|
+
expect_command(i, TuxDroid::Actions::LED_RIGHT_OFF)
|
94
|
+
end
|
95
|
+
assert_nothing_raised { tux.leds :right_off }
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_leds_blink
|
99
|
+
tux = setup_tux do |i|
|
100
|
+
expect_command(i, TuxDroid::Actions::LED_BLINK, 1, 20)
|
101
|
+
end
|
102
|
+
assert_nothing_raised { tux.leds :blink }
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_leds_blink_4_times
|
106
|
+
tux = setup_tux do |i|
|
107
|
+
expect_command(i, TuxDroid::Actions::LED_BLINK, 4, 20)
|
108
|
+
end
|
109
|
+
assert_nothing_raised { tux.leds :blink, :times => 4 }
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_leds_blink_4_times_with_100_delay
|
113
|
+
tux = setup_tux do |i|
|
114
|
+
expect_command(i, TuxDroid::Actions::LED_BLINK, 4, 100)
|
115
|
+
end
|
116
|
+
assert_nothing_raised { tux.leds :blink, :times => 4, :delay => 100 }
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_leds_raise_on_unknown_action
|
120
|
+
tux = setup_tux
|
121
|
+
assert_raises(TuxDroid::UnknownTuxDroidActionError) { tux.leds :explode }
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# Mouth tests
|
126
|
+
#
|
127
|
+
|
128
|
+
def test_mouth_opens
|
129
|
+
tux = setup_tux do |i|
|
130
|
+
expect_command(i, TuxDroid::Actions::OPEN_MOUTH)
|
131
|
+
end
|
132
|
+
assert_nothing_raised { tux.mouth :open }
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_mouth_closes
|
136
|
+
tux = setup_tux do |i|
|
137
|
+
expect_command(i, TuxDroid::Actions::CLOSE_MOUTH)
|
138
|
+
end
|
139
|
+
assert_nothing_raised { tux.mouth :close }
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_mouth_moves
|
143
|
+
tux = setup_tux do |i|
|
144
|
+
expect_command(i, TuxDroid::Actions::MOVE_MOUTH, 1)
|
145
|
+
end
|
146
|
+
assert_nothing_raised { tux.mouth :move }
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_mouth_moves_3_times
|
150
|
+
tux = setup_tux do |i|
|
151
|
+
expect_command(i, TuxDroid::Actions::MOVE_MOUTH, 3)
|
152
|
+
end
|
153
|
+
assert_nothing_raised { tux.mouth :move, :times => 3 }
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_mouth_raise_on_unknown_action
|
157
|
+
tux = setup_tux
|
158
|
+
assert_raises(TuxDroid::UnknownTuxDroidActionError) { tux.mouth :explode }
|
159
|
+
end
|
160
|
+
|
161
|
+
#
|
162
|
+
# Spin tests
|
163
|
+
#
|
164
|
+
|
165
|
+
def test_spin_left
|
166
|
+
tux = setup_tux do |i|
|
167
|
+
expect_command(i, TuxDroid::Actions::SPIN_LEFT, 1, 3)
|
168
|
+
end
|
169
|
+
assert_nothing_raised { tux.spin :left }
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_spin_left_3_times
|
173
|
+
tux = setup_tux do |i|
|
174
|
+
expect_command(i, TuxDroid::Actions::SPIN_LEFT, 3, 3)
|
175
|
+
end
|
176
|
+
assert_nothing_raised { tux.spin :left, :times => 3 }
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_spin_left_3_times_fast
|
180
|
+
tux = setup_tux do |i|
|
181
|
+
expect_command(i, TuxDroid::Actions::SPIN_LEFT, 3, 5)
|
182
|
+
end
|
183
|
+
assert_nothing_raised { tux.spin :left, :times => 3, :speed => 5 }
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_spin_right
|
187
|
+
tux = setup_tux do |i|
|
188
|
+
expect_command(i, TuxDroid::Actions::SPIN_RIGHT, 1, 3)
|
189
|
+
end
|
190
|
+
assert_nothing_raised { tux.spin :right }
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_spin_left_3_times
|
194
|
+
tux = setup_tux do |i|
|
195
|
+
expect_command(i, TuxDroid::Actions::SPIN_RIGHT, 3, 3)
|
196
|
+
end
|
197
|
+
assert_nothing_raised { tux.spin :right, :times => 3 }
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_spin_left_3_times_fast
|
201
|
+
tux = setup_tux do |i|
|
202
|
+
expect_command(i, TuxDroid::Actions::SPIN_RIGHT, 3, 5)
|
203
|
+
end
|
204
|
+
assert_nothing_raised { tux.spin :right, :times => 3, :speed => 5 }
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_spin_stop
|
208
|
+
tux = setup_tux do |i|
|
209
|
+
expect_command(i, TuxDroid::Actions::STOP_SPIN)
|
210
|
+
end
|
211
|
+
assert_nothing_raised { tux.spin :stop }
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_spin_raises_on_unknown_action
|
215
|
+
tux = setup_tux
|
216
|
+
assert_raises(TuxDroid::UnknownTuxDroidActionError) { tux.spin :explode }
|
217
|
+
end
|
218
|
+
|
219
|
+
#
|
220
|
+
# Wing tests
|
221
|
+
#
|
222
|
+
|
223
|
+
def test_wings_toggle
|
224
|
+
tux = setup_tux do |i|
|
225
|
+
expect_command(i, TuxDroid::Actions::WAVE_WINGS, 1, 3)
|
226
|
+
end
|
227
|
+
assert_nothing_raised { tux.wings :toggle }
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_wings_toggle_fast
|
231
|
+
tux = setup_tux do |i|
|
232
|
+
expect_command(i, TuxDroid::Actions::WAVE_WINGS, 1, 5)
|
233
|
+
end
|
234
|
+
assert_nothing_raised { tux.wings :toggle, :speed => 5 }
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_wings_flap
|
238
|
+
tux = setup_tux do |i|
|
239
|
+
expect_command(i, TuxDroid::Actions::WAVE_WINGS, 1, 3)
|
240
|
+
end
|
241
|
+
assert_nothing_raised { tux.wings :flap }
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_wings_flap_3_times_fast
|
245
|
+
tux = setup_tux do |i|
|
246
|
+
expect_command(i, TuxDroid::Actions::WAVE_WINGS, 3, 5)
|
247
|
+
end
|
248
|
+
assert_nothing_raised { tux.wings :flap, :times => 3, :speed => 5 }
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_wings_reset
|
252
|
+
tux = setup_tux do |i|
|
253
|
+
expect_command(i, TuxDroid::Actions::RESET_WINGS)
|
254
|
+
end
|
255
|
+
assert_nothing_raised { tux.wings :reset }
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_wings_raises_on_unknown_action
|
259
|
+
tux = setup_tux
|
260
|
+
assert_raises(TuxDroid::UnknownTuxDroidActionError) { tux.wings :explode }
|
261
|
+
end
|
262
|
+
|
263
|
+
#
|
264
|
+
# Initialiser tests
|
265
|
+
#
|
266
|
+
|
267
|
+
def test_should_raise_when_cannot_get_usb_device
|
268
|
+
USB.stubs(:devices).returns(stub(:find => nil))
|
269
|
+
assert_raises(TuxDroid::USBDeviceNotFoundError) do
|
270
|
+
TuxDroid::Tux.get_usb_device
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_should_raise_when_usb_device_firmware_is_too_old
|
275
|
+
device = stub(:bcdDevice => TuxDroid::USBCodes::FIRMWARE_REV-1)
|
276
|
+
USB.stubs(:devices).returns(stub(:find => device))
|
277
|
+
assert_raises(TuxDroid::FirmwareTooOldError) do
|
278
|
+
TuxDroid::Tux.get_usb_device
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_should_raise_when_cannot_open_device
|
283
|
+
interface = mock()
|
284
|
+
interface.stubs(:usb_claim_interface).returns(1)
|
285
|
+
interface.stubs(:usb_detach_kernel_driver_np)
|
286
|
+
assert_raises(TuxDroid::CannotClaimInterfaceError) do
|
287
|
+
TuxDroid::Tux.get_usb_interface(stub(:open => interface))
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_should_raise_when_cannot_set_alternative_interface
|
292
|
+
interface = mock()
|
293
|
+
interface.stubs(:usb_claim_interface).returns(nil)
|
294
|
+
interface.stubs(:set_altinterface).returns(1)
|
295
|
+
assert_raises(TuxDroid::CannotSetAlternativeInterfaceError) do
|
296
|
+
TuxDroid::Tux.get_usb_interface(stub(:open => interface))
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
#
|
301
|
+
# Send command test
|
302
|
+
#
|
303
|
+
|
304
|
+
def test_send_command
|
305
|
+
tux = setup_tux do |i|
|
306
|
+
i.expects(:usb_interrupt_write).with(
|
307
|
+
TuxDroid::USBCodes::WRITE_ENDPOINT,
|
308
|
+
"\000\001\001\001\001",
|
309
|
+
TuxDroid::USBCodes::WRITE_TIMEOUT
|
310
|
+
)
|
311
|
+
end
|
312
|
+
tux.send(:send_command, 1,1,1,1)
|
313
|
+
end
|
314
|
+
|
315
|
+
#
|
316
|
+
# Validator tests
|
317
|
+
#
|
318
|
+
|
319
|
+
def test_validate_within
|
320
|
+
tux = setup_tux
|
321
|
+
assert_nothing_raised do
|
322
|
+
tux.send(:validate_within, {:key => 5}, {:key => 1..6})
|
323
|
+
end
|
324
|
+
assert_raises(TuxDroid::TuxDroidCommandOptionsError) do
|
325
|
+
tux.send(:validate_within, {:key => 5}, {:key => 1..4})
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
#
|
330
|
+
# USB status tests
|
331
|
+
#
|
332
|
+
|
333
|
+
#def test_usb_status
|
334
|
+
# raise NotImplementedError, 'Need to write test_usb_status'
|
335
|
+
#end
|
336
|
+
|
337
|
+
private
|
338
|
+
|
339
|
+
def setup_tux
|
340
|
+
usb_interface = mock()
|
341
|
+
if block_given?
|
342
|
+
yield usb_interface
|
343
|
+
else
|
344
|
+
usb_interface.stubs(:usb_interrupt_write)
|
345
|
+
end
|
346
|
+
TuxDroid::Tux.stubs(:get_usb_device)
|
347
|
+
TuxDroid::Tux.stubs(:get_usb_interface).returns(usb_interface)
|
348
|
+
return TuxDroid::Tux.new
|
349
|
+
end
|
350
|
+
|
351
|
+
def expect_command(interface, command, param1 = 0, param2 = 0, param3 = 0)
|
352
|
+
bytes = [0]
|
353
|
+
bytes << command
|
354
|
+
bytes << param1.to_i
|
355
|
+
bytes << param2.to_i
|
356
|
+
bytes << param3.to_i
|
357
|
+
interface.expects(:usb_interrupt_write).with(
|
358
|
+
TuxDroid::USBCodes::WRITE_ENDPOINT,
|
359
|
+
bytes.pack('C*'),
|
360
|
+
TuxDroid::USBCodes::WRITE_TIMEOUT
|
361
|
+
)
|
362
|
+
end
|
363
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: tuxdroid
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-03-25 00:00:00 +00:00
|
8
|
+
summary: A Ruby Command Interface API to the TuxDroid from Kysoh
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: ryand-ruby@zenspider.com
|
12
|
+
homepage: " by Andrew Montgomery"
|
13
|
+
rubyforge_project: tuxdroid
|
14
|
+
description: "== FEATURES/PROBLEMS: * Simple interface to all basic actions * No sound support yet * No reading the status of any motors or sensors yet == SYNOPSIS: require 'tuxdroid' tux = TuxDroid::Tux.new tux.mouth :open tux.mouth :close tux.wings :flap, :times => 2, :speed => 3 == REQUIREMENTS:"
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Ryan Davis
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- LICENSE.txt
|
36
|
+
- Rakefile
|
37
|
+
- lib/tuxdroid.rb
|
38
|
+
- lib/tuxdroid/constants.rb
|
39
|
+
- test/test_tuxdroid.rb
|
40
|
+
test_files:
|
41
|
+
- test/test_tuxdroid.rb
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
executables: []
|
47
|
+
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
dependencies:
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: hoe
|
55
|
+
version_requirement:
|
56
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.2.0
|
61
|
+
version:
|