././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1734478811.0179114
nxt_python-3.5.1/.pre-commit-config.yaml 0000644 0000000 0000000 00000001475 14730405733 015156 0 ustar 00 repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: trailing-whitespace
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.1
hooks:
- id: mypy
pass_filenames: false
- repo: local
hooks:
- id: pytest
name: pytest
language: system
entry: poetry run pytest
types: [python]
pass_filenames: false
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1734218447.5151248
nxt_python-3.5.1/LICENSE 0000644 0000000 0000000 00000105757 14727411320 011705 0 ustar 00 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1734218447.5151248
nxt_python-3.5.1/README.md 0000644 0000000 0000000 00000006561 14727411320 012150 0 ustar 00 # 
NXT-Python is a package for controlling a LEGO NXT robot using the Python
programming language. It can communicate using either USB or Bluetooth.
NXT-Python for Python 2 is no longer supported.
NXT-Python repository is on [sourcehut][] with a mirror on [Github][].
[sourcehut]: https://sr.ht/~ni/nxt-python/ "NXT-Python repository on sourcehut"
[Github]: https://github.com/schodet/nxt-python "NXT-Python repository on Github"
## Requirements
- [Python 3.x](https://www.python.org)
- USB communication:
- [PyUSB](https://github.com/pyusb/pyusb)
- Bluetooth communication:
- [PyBluez](https://github.com/pybluez/pybluez)
## Installation
Install NXT-Python with pip:
python3 -m pip install --upgrade nxt-python
See [installation][] instructions in the documentation for more informations.
[installation]: https://ni.srht.site/nxt-python/latest/installation.html
## Next steps
You can read the [documentation][], or start directly with the [tutorial][].
[documentation]: https://ni.srht.site/nxt-python/latest/
[tutorial]: https://ni.srht.site/nxt-python/latest/handbook/tutorial.html
## Upgrading your code
If you used previous version of NXT-Python with Python 2, the documentation
includes an [migration guide][].
[migration guide]: https://ni.srht.site/nxt-python/latest/migration.html
## Contact
There is a [mailing list][] for questions.
NXT-Python repository maintainer is Nicolas Schodet, since 2021-11-06. You can
contact him on the mailing list.
You can use the [Github issues page][] to report problems, but please use the
mailing list for questions.
[mailing list]: https://lists.sr.ht/~ni/nxt-python
[Github issues page]: https://github.com/schodet/nxt-python/issues
## Thanks
- Doug Lau for writing NXT\_Python, our starting point.
- rhn for creating what would become v2, making lots of smaller changes, and
reviewing tons of code.
- Marcus Wanner for maintaining NXT-Python up to v2.2.2, his work has been
amazing!
- Elvin Luff for taking over the project after Marcus, making a lot of work
for the port to Python 3.
- mindsensors.com (esp. Ryan Kneip) for helping out with the code for a lot of
their sensors, expanding the sensors covered by the type checking database,
and providing hardware for testing.
- HiTechnic for providing identification information for their sensors. I note
that they have now included this information in their website. ;)
- Linus Atorf, Samuel Leeman-Munk, melducky, Simon Levy, Steve Castellotti,
Paulo Vieira, zonedabone, migpics, TC Wan, jerradgenson, henryacev, Paul
Hollensen, and anyone else I forgot for various fixes and additions.
- Goldsloth for making some useful changes and keeping the tickets moving
after the migration to Github.
- All our users for their interest and support!
## License
NXT-Python is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see .
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1654462568.7501733
nxt_python-3.5.1/contrib/60-libnxt.rules 0000644 0000000 0000000 00000000246 14247214151 015122 0 ustar 00 # Allow access to the NXT brick.
SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="0694", ATTR{idProduct}=="0002", \
MODE="0660", GROUP="plugdev", TAG+="uaccess"
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1704409096.3199499
nxt_python-3.5.1/contrib/_incr_version 0000755 0000000 0000000 00000000342 14545634010 015106 0 ustar 00 #!/bin/sh -eux
sed -i pyproject.toml -e "s/^version = \"${1}\"/version = \"${2}\"/"
sed -i docs/conf.py -e "s/^release = \"${1}\"/release = \"${2}\"/"
git add pyproject.toml docs/conf.py
git commit -m "Update version to ${2}"
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1638907410.063749
nxt_python-3.5.1/docs/Makefile 0000644 0000000 0000000 00000001172 14153737022 013255 0 ustar 00 # Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1734218447.5151248
nxt_python-3.5.1/docs/about.rst 0000644 0000000 0000000 00000002020 14727411320 013447 0 ustar 00 About
=====
Contact
-------
There is a `mailing list`_ for questions.
NXT-Python repository maintainer is Nicolas Schodet, since 2021-11-06. You can
contact him on the mailing list.
You can use the `Github issues page`_ to report problems, but please use the
mailing list for questions.
.. _mailing list: https://lists.sr.ht/~ni/nxt-python
.. _Github issues page: https://github.com/schodet/nxt-python/issues
License
-------
NXT-Python is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see https://www.gnu.org/licenses/.
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1735655274.1831486
nxt_python-3.5.1/docs/api/backends.rst 0000644 0000000 0000000 00000000644 14734777552 014716 0 ustar 00 Connection Backends
===================
.. module:: nxt.backend
Backends are used by :func:`nxt.locator.find`. You will usually not use them
directly.
USB
---
.. automodule:: nxt.backend.usb
:members:
Bluetooth
---------
.. automodule:: nxt.backend.bluetooth
:members:
Device file
-----------
.. automodule:: nxt.backend.devfile
:members:
Socket
------
.. automodule:: nxt.backend.socket
:members:
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1640641685.2549558
nxt_python-3.5.1/docs/api/brick.rst 0000644 0000000 0000000 00000006523 14162432225 014214 0 ustar 00 Brick
=====
.. automodule:: nxt.brick
.. autoclass:: Brick
Connection Management
---------------------
.. automethod:: Brick.close
You can also use the context manager interface::
with nxt.locator.find() as b:
b.play_tone(440, 1000)
# Here, connection is closed automatically.
Brick Information
-----------------
.. automethod:: Brick.get_device_info
.. automethod:: Brick.get_battery_level
.. automethod:: Brick.get_firmware_version
.. automethod:: Brick.set_brick_name
.. automethod:: Brick.keep_alive
Sound
-----
.. automethod:: Brick.play_tone_and_wait
.. automethod:: Brick.play_sound_file
.. automethod:: Brick.play_tone
.. automethod:: Brick.stop_sound_playback
Motors and Sensors
------------------
.. automethod:: Brick.get_motor
.. automethod:: Brick.get_sensor
Programs
--------
.. automethod:: Brick.start_program
.. automethod:: Brick.stop_program
.. automethod:: Brick.get_current_program_name
File System Access
------------------
Brick file system has no directory and file names are not case sensitive.
.. automethod:: Brick.open_file
.. automethod:: Brick.find_files
.. automethod:: Brick.file_delete
.. automethod:: Brick.delete_user_flash
Mailboxes
---------
Mailboxes can be used to exchange messages with the running program.
.. automethod:: Brick.message_write
.. automethod:: Brick.message_read
Low Level Modules Access
------------------------
Low level modules access allows to read and write directly in modules
memory. This can be used for example to take a screenshot or to debug the
virtual machine. You need to look at the firmware source code for how to
use it.
.. automethod:: Brick.find_modules
.. automethod:: Brick.read_io_map
.. automethod:: Brick.write_io_map
Low Level Output Ports Methods
------------------------------
These are low level methods, you can use the :mod:`nxt.motor` module for an
easier interface.
.. automethod:: Brick.set_output_state
.. automethod:: Brick.get_output_state
.. automethod:: Brick.reset_motor_position
Low Level Intput Ports Methods
------------------------------
This are low level methods, you can use the :mod:`nxt.sensor` module for an
easier interface.
.. automethod:: Brick.set_input_mode
.. automethod:: Brick.get_input_values
.. automethod:: Brick.reset_input_scaled_value
.. automethod:: Brick.ls_get_status
.. automethod:: Brick.ls_write
.. automethod:: Brick.ls_read
Low Level Methods
-----------------
Do not use these functions unless you know exactly what you are doing.
.. automethod:: Brick.file_open_read
.. automethod:: Brick.file_open_write
.. automethod:: Brick.file_read
.. automethod:: Brick.file_write
.. automethod:: Brick.file_close
.. automethod:: Brick.file_find_first
.. automethod:: Brick.file_find_next
.. automethod:: Brick.file_open_write_linear
.. automethod:: Brick.file_open_write_data
.. automethod:: Brick.file_open_append_data
.. automethod:: Brick.module_find_first
.. automethod:: Brick.module_find_next
.. automethod:: Brick.module_close
.. automethod:: Brick.poll_command_length
.. automethod:: Brick.poll_command
.. automethod:: Brick.boot
.. automethod:: Brick.bluetooth_factory_reset
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1639426484.7361743
nxt_python-3.5.1/docs/api/error.rst 0000644 0000000 0000000 00000000066 14155724665 014265 0 ustar 00 Errors
======
.. automodule:: nxt.error
:members:
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1639426617.3062723
nxt_python-3.5.1/docs/api/index.rst 0000644 0000000 0000000 00000000211 14155725071 014223 0 ustar 00 API Reference
=============
.. toctree::
:maxdepth: 2
locator
brick
motor
sensors/index
backends
error
motcont
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1639426617.3062723
nxt_python-3.5.1/docs/api/locator.rst 0000644 0000000 0000000 00000000072 14155725071 014564 0 ustar 00 Locator
=======
.. automodule:: nxt.locator
:members:
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1639426484.7361743
nxt_python-3.5.1/docs/api/motcont.rst 0000644 0000000 0000000 00000000160 14155724665 014612 0 ustar 00 Linus Atorf's MotorControl Support
==================================
.. automodule:: nxt.motcont
:members:
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1735744838.3915462
nxt_python-3.5.1/docs/api/motor.rst 0000644 0000000 0000000 00000000722 14735256506 014271 0 ustar 00 Motor
=====
Controlling the motors directly is not very precise because the NXT firmware
does not expose the needed method for precise control. If you need more than
basic controls, :class:`nxt.motcont.MotCont` provides finer controls thanks to
a program running on the NXT brick.
Work in progress... The :class:`nxt.motor.Motor` class will probably be
reworked in a future version.
.. automodule:: nxt.motor
:members:
:undoc-members:
:show-inheritance:
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1735744748.0544767
nxt_python-3.5.1/docs/api/sensors/generic.rst 0000644 0000000 0000000 00000000177 14735256354 016246 0 ustar 00 LEGO Mindstorms NXT Sensors
===========================
.. automodule:: nxt.sensor.generic
:members:
:show-inheritance:
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1735744617.268897
nxt_python-3.5.1/docs/api/sensors/hitechnic.rst 0000644 0000000 0000000 00000000177 14735256151 016563 0 ustar 00 HiTechnic Sensors
=================
Work in progress...
.. automodule:: nxt.sensor.hitechnic
:members:
:undoc-members:
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1735744748.0544767
nxt_python-3.5.1/docs/api/sensors/index.rst 0000644 0000000 0000000 00000000507 14735256354 015736 0 ustar 00 Sensors
=======
Work in progress...
.. automodule:: nxt.sensor
:members:
.. automodule:: nxt.sensor.analog
:members:
:undoc-members:
:show-inheritance:
.. automodule:: nxt.sensor.digital
:members:
:undoc-members:
:show-inheritance:
.. toctree::
:maxdepth: 2
generic
mindsensors
hitechnic
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1735744748.0544767
nxt_python-3.5.1/docs/api/sensors/mindsensors.rst 0000644 0000000 0000000 00000000233 14735256354 017167 0 ustar 00 Mindsensors Sensors
===================
Work in progress...
.. automodule:: nxt.sensor.mindsensors
:members:
:undoc-members:
:show-inheritance:
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1736613831.165182
nxt_python-3.5.1/docs/commands/common_options.rst 0000644 0000000 0000000 00000002424 14740517707 017224 0 ustar 00 Common options
--------------
Those options are common to programs using NXT-Python.
--backend NAME
Enable given backend. Can be used several times to enable several backends.
One of :mod:`~nxt.backend.usb`, :mod:`~nxt.backend.bluetooth`,
:mod:`~nxt.backend.socket` or :mod:`~nxt.backend.devfile`.
--config NAME
Name of configuration file section to use.
--config-filename PATH
Path to configuration file. Can be used several times to use several
configuration files.
--name NAME
Name of NXT brick (for example: NXT). Useful to find the right brick if
several bricks are connected.
--host ADDRESS
Bluetooth address of the NXT brick (for example: 00:16:53:01:02:03).
--server-host HOST
Server address or name to connect to when using :mod:`~nxt.backend.socket`
backend.
--server-port PORT
Server port to connect to when using :mod:`~nxt.backend.socket` backend.
--filename FILENAME
Device filename (for example: :file:`/dev/rfcomm0`), when using
`~nxt.backend.devfile` backend.
.. only:: man
See :manpage:`nxt-python.conf(5)` documentation for better explanation of
the options to find the NXT brick.
.. only:: not man
See :doc:`configuration file ` documentation for better
explanation of the options to find the NXT brick.
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1736613831.165182
nxt_python-3.5.1/docs/commands/common_see_also.rst 0000644 0000000 0000000 00000000220 14740517707 017313 0 ustar 00 .. only:: man
See also
--------
:manpage:`nxt-python.conf(5)`
NXT-Python documentation
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1736597911.3870773
nxt_python-3.5.1/docs/commands/index.rst 0000644 0000000 0000000 00000000151 14740460627 015261 0 ustar 00 Commands
========
.. toctree::
:maxdepth: 1
nxt-push
nxt-screenshot
nxt-server
nxt-test
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1736597911.3870773
nxt_python-3.5.1/docs/commands/nxt-push.rst 0000644 0000000 0000000 00000001754 14740460627 015752 0 ustar 00 Manual page for nxt-push
========================
Synopsis
--------
**nxt-push**
[**--backend** *NAME*]
[**--config** *NAME*]
[**--config-filename** *PATH*]
[**--name** *NAME*]
[**--host** *ADDRESS*]
[**--server-host** *HOST*]
[**--server-port** *PORT*]
[**--filename** *FILENAME*]
[**--log-level** *LEVEL*]
*FILE*...
Description
-----------
:program:`nxt-push` uploads files to a connected NXT brick file system.
The NXT brick can be connected using USB, Bluetooth or over the network.
Options
-------
*FILE*...
Names of files to send to the NXT brick.
--log-level LEVEL
Set the log level. One of **DEBUG**, **INFO**, **WARNING**, **ERROR**, or
**CRITICAL**. Messages whose level is below the current log level will not
be displayed.
.. include:: common_options.rst
Example
-------
``nxt-push --host 00:16:53:01:02:03 MotorControl22.rxe``
Sends the ``MotorControl22.rxe`` file to a connected NXT using its
Bluetooth address to find it.
.. include:: common_see_also.rst
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1736597911.3870773
nxt_python-3.5.1/docs/commands/nxt-screenshot.rst 0000644 0000000 0000000 00000002163 14740460627 017143 0 ustar 00 Manual page for nxt-screenshot
==============================
Synopsis
--------
**nxt-screenshot**
[**--backend** *NAME*]
[**--config** *NAME*]
[**--config-filename** *PATH*]
[**--name** *NAME*]
[**--host** *ADDRESS*]
[**--server-host** *HOST*]
[**--server-port** *PORT*]
[**--filename** *FILENAME*]
[**--log-level** *LEVEL*]
*FILE*
Description
-----------
:command:`nxt-screenshot` takes a capture of a connected NXT brick and write
the captured image to a *FILE*.
The NXT brick can be connected using USB, Bluetooth or over the network.
A wide range of image formats is supported, thanks to the Python Imaging
Library.
Options
-------
*FILE*
Filename to write captured image to.
--log-level LEVEL
Set the log level. One of **DEBUG**, **INFO**, **WARNING**, **ERROR**, or
**CRITICAL**. Messages whose level is below the current log level will not
be displayed.
.. include:: common_options.rst
Example
-------
``nxt-screenshot --host 00:16:53:01:02:03 capture.png``
Capture screen from connected NXT using its Bluetooth address. Save the
result image in ``capture.png``.
.. include:: common_see_also.rst
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1736597911.3870773
nxt_python-3.5.1/docs/commands/nxt-server.rst 0000644 0000000 0000000 00000002361 14740460627 016274 0 ustar 00 Manual page for nxt-server
==========================
Synopsis
--------
**nxt-server**
[**--backend** *NAME*]
[**--config** *NAME*]
[**--config-filename** *PATH*]
[**--name** *NAME*]
[**--host** *ADDRESS*]
[**--server-host** *HOST*]
[**--server-port** *PORT*]
[**--filename** *FILENAME*]
[**-p|--port** *PORT*]
[**--log-level** *LEVEL*]
Description
-----------
:command:`nxt-server` serves an interface to a connected NXT brick over the
network.
The NXT brick can be connected using USB, Bluetooth or over the network.
Options
-------
-p|--port *PORT*
Set the bind port. Same value must be given to the client using
**--server-port** or inside Python code. Default port is 2727.
--log-level LEVEL
Set the log level. One of **DEBUG**, **INFO**, **WARNING**, **ERROR**, or
**CRITICAL**. Messages whose level is below the current log level will not
be displayed.
.. include:: common_options.rst
Example
-------
``nxt-server --host 00:16:53:01:02:03``
Starting the server on a computer connected to a NXT brick, accepting
connection on default port 2727.
``nxt-test --server-host 192.168.1.2``
Assuming the first computer has address 192.168.1.2, remotely connect to
the server to run a test.
.. include:: common_see_also.rst
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1736675406.414134
nxt_python-3.5.1/docs/commands/nxt-test.rst 0000644 0000000 0000000 00000003037 14740710116 015735 0 ustar 00 Manual page for nxt-test
========================
Synopsis
--------
**nxt-test**
[**--backend** *NAME*]
[**--config** *NAME*]
[**--config-filename** *PATH*]
[**--name** *NAME*]
[**--host** *ADDRESS*]
[**--server-host** *HOST*]
[**--server-port** *PORT*]
[**--filename** *FILENAME*]
[**--no-sound**]
[**--log-level** *LEVEL*]
Description
-----------
:command:`nxt-test` tests connection with a NXT brick. It allows one to debug
the NXT-Python setup.
The NXT brick can be connected using USB, Bluetooth or over the network.
Options
-------
--no-sound
Be quiet, disable the sound test.
--log-level LEVEL
Set the log level. One of **DEBUG**, **INFO**, **WARNING**, **ERROR**, or
**CRITICAL**. Messages whose level is below the current log level will not
be displayed.
.. include:: common_options.rst
Examples
--------
Running for a NXT brick connected using USB::
$ nxt-test
Finding brick...
NXT brick name: NXT
Host address: 00:16:53:01:02:03
Bluetooth signal strengths: (0, 0, 0, 0)
Free user flash: 48480
Protocol version 1.124
Firmware version 1.29
Battery level 8433 mV
Play test sound...done
To report problems, please enable debug logs::
$ nxt-test --log-level DEBUG
When debugging Bluetooth connection problems, try to give the address
explicitly::
$ nxt-test --log-level DEBUG --host 00:16:53:01:02:03
The address can be found in the "Settings" menu, under "NXT Version" screen,
it is the last line labeled "ID". Add the colon to separate each pair of
digits.
.. include:: common_see_also.rst
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1736675522.160635
nxt_python-3.5.1/docs/conf.py 0000644 0000000 0000000 00000005642 14740710302 013114 0 ustar 00 # Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath(".."))
# -- Project information -----------------------------------------------------
project = "NXT-Python"
copyright = "2021-2025, Nicolas Schodet"
author = "Nicolas Schodet"
# The full version, including alpha/beta/rc tags
release = "3.5.1"
version = release
# -- General configuration ---------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
needs_sphinx = "3.4"
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
]
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build"]
nitpicky = True
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"
html_logo = "../logo.svg"
html_favicon = "favicon.ico"
html_copy_source = False
# -- Options for Man pages output --------------------------------------------
man_pages_authors = [
"This program is part of NXT-Python which is currently maintained by"
" Nicolas Schodet.",
]
man_pages = [
(
"config",
"nxt-python.conf",
"NXT-Python configuration file",
man_pages_authors,
5,
),
(
"commands/nxt-push",
"nxt-push",
"Push files to a NXT brick",
man_pages_authors,
1,
),
(
"commands/nxt-screenshot",
"nxt-screenshot",
"Capture screen utility for the NXT brick",
man_pages_authors,
1,
),
(
"commands/nxt-server",
"nxt-server",
"Network server for the NXT brick",
man_pages_authors,
1,
),
(
"commands/nxt-test",
"nxt-test",
"Test the NXT-Python setup",
man_pages_authors,
1,
),
]
# -- Options for autodoc -----------------------------------------------------
autodoc_member_order = "bysource"
autodoc_typehints = "description"
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1736675388.8464668
nxt_python-3.5.1/docs/config.rst 0000644 0000000 0000000 00000010160 14740710075 013612 0 ustar 00 Configuration files
===================
Description
-----------
The NXT-Python configuration files allow you to define the NXT bricks you want
to connect to, so that you do not need to give the needed argument for every
scripts.
You can place a :file:`.nxt-python.conf` in your home directory, or in the
current directory. You can also explicitly give configuration file name to the
invoked script or function.
Format
------
The configuration format is a INI-style format. It consists of several
sections introduced by the section name in square brackets on its line. Each
section contains a set of key/value pairs. The key and value are separated by
a equal sign ('=').
Configuration may include comments which are introduced by a '#' character.
When looking for a brick, you can request NXT-Python to use a specific
section, or :code:`[default]` if not specified. If the section is missing, or
if a value is missing, the :code:`[DEFAULT]` section (note the uppercase) is
used as a fallback.
The following values can be defined:
backends
This is the space separated list of backends to use to find and connect to
the brick. When not specified, a default list of backends is used:
- :mod:`~nxt.backend.devfile` if :code:`filename` is given,
- :mod:`~nxt.backend.socket` if :code:`server_host` or :code:`server_port`
is given,
- :mod:`~nxt.backend.usb` and,
- :mod:`~nxt.backend.bluetooth`.
name
Brick name which is used to find the brick (for example: NXT). The brick
name can be configured using the NXT brick menus.
host
Bluetooth address which is used to find the brick (for example:
00:16:53:01:02:03). When using Bluetooth backend, this allows a direct
connection without having to scan to find the brick. For other backends, it
can be used to select the right brick when several bricks are found.
The address can be found in the "Settings" menu, under "NXT Version"
screen, it is the last line labeled "ID". Add the colon to separated each
pair of digits.
server_host
Server address or name (example: 192.168.1.3, or localhost).
This is used by the :code:`socket` backend.
.. only:: man
The server is provided by the :manpage:`nxt-server(1)` command.
.. only:: not man
The server is provided by the :doc:`nxt-server `
command.
server_port
Server connection port (default: 2727).
This is used by the :code:`socket` backend.
.. only:: man
The server is provided by the :manpage:`nxt-server(1)` command.
.. only:: not man
The server is provided by the :doc:`nxt-server `
command.
filename
Device file name (default is platform specific).
This is used by the :mod:`~nxt.backend.devfile` backend to locate the
RFCOMM device file.
.. only:: man
Please see NXT-Python documentation for more details on how to use this.
Other values
Other values are passed as-is to backends.
Example
-------
Given the following configuration file:
.. code:: ini
[DEFAULT]
# Defines a fallback for every configuration name.
backends = usb
[default]
# My default NXT, sitting on my desk.
host = 00:16:53:01:02:03
name = NXT
[lab]
# When working at the lab, use my second NXT.
name = NXT2
[robot]
# Use Bluetooth for my third NXT, which is embedded in a robot, but try USB
# first as this is faster.
backends = usb bluetooth
host = 00:16:53:aa:bb:cc
name = ROBOT
When using the command line, NXT-Python will connect to my default NXT if I
do not give more options::
$ nxt-test
Finding brick...
NXT brick name: NXT
...
I can request to connect to my robot NXT brick like this::
$ nxt-test --config robot
Finding brick...
NXT brick name: ROBOT
...
Or when using a script:
.. code:: python
import nxt.locator
b = nxt.locator.find(config="robot")
Files
-----
:file:`$HOME/.nxt-python.conf`
Per user configuration file.
:file:`.nxt-python.conf`
Configuration file in current directory.
.. only:: man
See also
--------
:manpage:`nxt-test(1)`
NXT-Python documentation
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1734218447.5151248
nxt_python-3.5.1/docs/favicon.ico 0000644 0000000 0000000 00000001630 14727411320 013732 0 ustar 00 ‚ ‰PNG
IHDR szzô IIDATX…Å—ÁoE‡¿™Ùõnl7Å8
Ié !„HA ž‘€¿ ñ !\¸Áµ„ÔÇJí‰Kˆ#âm-R)ieª¸q-Å®k{wgçq°ëÚ)qÖNLßiGóö½ofçýö’Ël§x6vO'žQr€UÇ£DR¼¹f4X|
ÇÃlVr´Ö¿Æ_Þ qóÉ®öÁMŠ}IŽî8€Ãà—ßàØÉs¨ù¤G€¶6¤ú ú zÜeN+˜Ôžú¿]ÿ?›xâRÛ£·[EÒh’Û¾¦LްtㇳDÍ{D×?'èÞFÔt›¥Ä…k¨³ß’/¯Ï .&ˆîPˆþî@™ä=š}à«â&ïÞE¯ÆžÇágÔ`Zä ›&Á—ÎíäšÊ¬:Våi½ô)¦òˆ£[ê"Âri…œJ“îüJ©zOeŠ›À)¯r–Ò鈬ãÊÕ;ü¶Y§Öhòæ©%>ûðurž¡‰Ãýó]Ö°Ó—aœÂýf—Fó؈jÁÕ?¶ˆ£&Nn:áOpé—-~ºu—ÖÃÝn—8Š¡ZßCZÎ~Pghuc®ß®QÝÙåø1a¥,¤Ï¼»–$¿C» îÌü ´R¤6¡RT|õÁ^,VÛeA5ñâp’ƒNý¡ Š¡Ï{g޳]w¬nPÔ5ð¤1˜e(¼
ÝÜü ŒV||î46^!×øz
ð_pÊŸ€·+ó 0
L.ù
HÚ}
×Á”¦
5€–»s]ô aQ`ßêOv"¸ÿÃ@ˆ®¡%9z O:,V/ઓEF“àIç¨ FŠZT^÷ö}ë²0LP& ®ÈS¿c/Ù!Lw è™
Ö¯Œ¿+Ž(|™Ð³‹«°ñ
..Y¤–öó„õ‹ ´ŸŸàµ/PÆ.X“#(Î`¼€üÒÓw—Z’`q8ÖÁ"…^E›é[úCô„²Ïó¡ ²ñôÓ7+Y=9†{¦IIê7x¨}jÏÅ¥Hg{È mÚwFi3™@ilý&OtBÉe’Ç Ù¯f‚G‚§ú¬øX|²üˆö½šø*ÂgúÜS ÙÕoÔ4°9Ó›Gc[ÿàÌ;;‰00ä IEND®B`‚ ././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1735745029.1577604
nxt_python-3.5.1/docs/handbook/index.rst 0000644 0000000 0000000 00000000121 14735257005 015240 0 ustar 00 Handbook
========
.. toctree::
:maxdepth: 2
overview
tutorial
tips
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1736597911.3870773
nxt_python-3.5.1/docs/handbook/overview.rst 0000644 0000000 0000000 00000004024 14740460627 016007 0 ustar 00 Overview
========
Using NXT-Python, you can control one or several NXT bricks from your
computer. The program you write is running on your computer, not on the NXT
brick, so the computer must be able to communicate with the brick during the
whole program lifetime.
Communication is done through USB or Bluetooth. You can also relay
communication over the network through another computer running the
:command:`nxt-server` program which is part of NXT-Python.
The Brick Object
----------------
All interaction with the NXT brick is done using the :class:`~nxt.brick.Brick`
class. You will first have to find a brick using the :func:`nxt.locator.find`
function which will return an instance of this class.
The :class:`~nxt.brick.Brick` object have functions to access the brick
capabilities. There is a function for every low level system and direct
command exposed by the NXT brick.
There are also higher level functions to access the brick file system for
example.
You could do everything just using low level functions, but to access motors
and sensors, you will likely prefer to use the motors and sensors objects.
Motor Control
-------------
You can make an instance of the :class:`~nxt.motor.Motor` class for each
connected motor. This allows to control the motors with a nicer interface than
using the low level function.
Keep in mind that as the program is running on your computer, there can be a
delay which will reduce the motor control precision. To solve this problem,
you can use the :class:`~nxt.motcont.MotCont` class which cooperates with a
program running on the NXT brick to allow fine control.
The situation could be improved by using an improved firmware for the NXT
brick, but this is not supported yet.
Sensors
-------
Many different sensors can be connected to the NXT brick. This is supported in
NXT-Python thanks to the :mod:`~nxt.sensor` classes hierarchy. There is a
class for every LEGO official sensor, and also classes for HiTechnic and
Mindsensors sensors.
If your sensor is not supported, please contribute its support!
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1639426617.3062723
nxt_python-3.5.1/docs/handbook/tips.rst 0000644 0000000 0000000 00000002155 14155725071 015120 0 ustar 00 Tips and Tricks
===============
Make Bluetooth Connection Faster
--------------------------------
When looking for a NXT brick, the :mod:`~nxt.backend.bluetooth` backend will
first try to discover which device is available. If you know the Bluetooth
address of your brick, you can skip this step.
First connect to your brick to get its address::
import nxt.locator
with nxt.locator.find() as b:
print(b.get_device_info()[0:2])
You should see something like::
('NXT', '00:16:53:01:02:03')
Now you can use the address in your programs::
import nxt.locator
with nxt.locator.find(host="00:16:53:01:02:03") as b:
b.play_tone(440, 1000)
Or in your configuration::
# .nxt-python.conf
[default]
host = 00:16:53:01:02:03
How to read inputs while controlling a motor?
---------------------------------------------
When using :meth:`!nxt.motor.Motor.turn`, NXT-Python is kept active while
watching the motor. If you need to read sensors at the same time, you can:
- use non blocking functions, like :meth:`nxt.motor.Motor.run`,
- use threads,
- or use :class:`nxt.motcont.MotCont`.
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1654462568.7501733
nxt_python-3.5.1/docs/handbook/tutorial.rst 0000644 0000000 0000000 00000003241 14247214151 015773 0 ustar 00 Tutorial
========
First, make sure that NXT-Python is installed correctly, see
:doc:`/installation`.
This is not a Python tutorial, you must know how to program using Python to
use NXT-Python.
First step when writing a NXT-Python script is to find the brick. This is the
role of the :func:`nxt.locator.find` function:
.. literalinclude:: ../../examples/tutorial/find.py
Once the brick is found, the :func:`nxt.locator.find` function returns an
object to interact with it: the :class:`~nxt.brick.Brick` object. Here the
script query device information and play a tone.
Now something a little bit more interesting, plug a motor on the port A and
try the following script:
.. literalinclude:: ../../examples/tutorial/motor.py
Try changing the parameters and see what happen. You can of course drive
several motors, just use the :func:`~nxt.brick.Brick.get_motor` function for
each one.
You can also get information from sensors:
.. literalinclude:: ../../examples/tutorial/sensor_us.py
Digital sensors can be automatically detected as long as the corresponding
module is loaded. In the retail set, only the ultra-sound distance sensor is
digital, all the other sensors are analog. When using an analog sensor, you
must give the sensor class explicitly:
.. literalinclude:: ../../examples/tutorial/sensor_touch.py
If you run into problems, you can increase the log level. NXT-Python is using
the :mod:`logging` module from the standard Python distribution. Try this
script:
.. literalinclude:: ../../examples/tutorial/debug.py
You should now have enough information to start playing with NXT-Python. See
the :doc:`/api/index`, or the :doc:`/handbook/tips` pages for more informations.
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1736613831.165182
nxt_python-3.5.1/docs/index.rst 0000644 0000000 0000000 00000001310 14740517707 013460 0 ustar 00 NXT-Python
==========
NXT-Python is a package for controlling a LEGO NXT robot using the Python
programming language. It can communicate using either USB or Bluetooth.
NXT-Python for Python 2 is no longer supported.
NXT-Python sources are available on `NXT-Python repository on sourcehut`_ and
mirrored on `NXT-Python repository on Github`_.
.. _NXT-Python repository on sourcehut: https://sr.ht/~ni/nxt-python/
.. _NXT-Python repository on Github: https://github.com/schodet/nxt-python
.. toctree::
:maxdepth: 2
installation
handbook/index
api/index
commands/index
config
migration
about
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1736633256.3202848
nxt_python-3.5.1/docs/installation.rst 0000644 0000000 0000000 00000005357 14740565650 015071 0 ustar 00 Installation
============
Install NXT-Python with :command:`pip`::
python3 -m pip install --upgrade nxt-python
To check that NXT-Python is correctly installed, connect your NXT brick using
a USB cable, and run::
nxt-test
In case of problem, enable debugging for extra diagnostics::
nxt-test --log-level=debug
USB
---
USB support is provided by PyUSB which is installed automatically with
NXT-Python. You can also use the package from your Linux distribution if you
wish, in this case, install it before installing NXT-Python.
PyUSB requires libusb or OpenUSB running on your system.
- For Linux users, you can install it from your package manager if not
installed yet.
- For MacOS users, you can use ``brew install libusb`` to install it using
Homebrew.
- For Windows users, libusb 1.0 DLLs are provided in the releases. Check the
`PyUSB FAQ`_.
.. _PyUSB FAQ: https://github.com/pyusb/pyusb/blob/master/docs/faq.rst#how-do-i-install-libusb-on-windows
USB access permissions for Linux
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You need to allow connection to the NXT brick for your user. If you install
any package interacting with the NXT brick from your distribution, this is
usually already done for you (for example, nbc, or libnxt).
In other cases, copy `contrib/60-libnxt.rules` from the NXT-Python source
distribution to your `/etc/udev/rules.d` directory, then make sure that udev
see the change: restart your computer or use the following commands::
sudo udevadm control --reload
sudo udevadm trigger
Bluetooth
---------
NXT-Python is only installed with USB by default, you need to install
Bluetooth support explicitly.
Installation from Linux Distribution Package
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The easiest solution is to install PyBluez from your distribution.
On Debian based distributions, like Ubuntu::
apt install python3-bluez
On ArchLinux::
pacman -S python-pybluez
On Fedora::
dnf install python3-bluez
Installation Using Pip
^^^^^^^^^^^^^^^^^^^^^^
You can install PyBluez using :command:`pip`. This is easy if there is a
pre-build package for your system and python version. This is much harder if
this is not the case.
Try this::
python3 -m pip install PyBluez
On MacOS:
The current PyPi version of pybluez does not work with nxt-python. You will need to a more recent version from GitHub.
Download and install Xcode from App Store or Apple Developer site
Then activate the Xcode installation::
xcode-select -s /Applications/Xcode.app/Contents/Developer
Then install pybluez from GitHub::
pip3 install https://github.com/pybluez/pybluez/tarball/07ebef044195331a48bbb90a3acb911922048ba0
As of 06/18/2022, commit 07ebef044195331a48bbb90a3acb911922048ba0 works with nxt-python 3.1.0.
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1734218447.5151248
nxt_python-3.5.1/docs/migration.rst 0000644 0000000 0000000 00000022600 14727411320 014334 0 ustar 00 Migrating to 3.0
================
If you have a working program using NXT-Python 2, you will have to make
changes to port it to NXT-Python 3.
Porting to Python 3
-------------------
First of all you need to port your code to Python 3, there is an `guide`_ in
Python documentation. You do not need to worry about keeping the code
compatible with Python 2 as it is no longer supported.
There is also an automatic script to ease the porting, called `2to3`_.
.. _guide: https://docs.python.org/3/howto/pyporting.html
.. _2to3: https://docs.python.org/3/library/2to3.html
One major change in Python is the distinction between text string
(:class:`str`) and binary string (:class:`bytes`). This means that you need to
make sure to use the right one when passing arguments to NXT-Python functions.
Porting to NXT-Python 3
-----------------------
Next step is to adapt the code for NXT-Python.
Major Changes
^^^^^^^^^^^^^
The :func:`!nxt.locator.find_one_brick` function has been removed and replaced
with the simpler :func:`nxt.locator.find` function. Actually, the whole
:mod:`nxt.locator` has been replaced.
Many `debug` arguments have been removed, now NXT-Python uses the
:mod:`logging` module to log messages. If you want to enable debug messages,
use this code before calling any NXT-Python function::
import logging
logging.basicConfig(level=logging.DEBUG)
The :mod:`!nxt` and :mod:`nxt.sensor` modules no longer exports name from
sub-modules. In general, NXT-Python now avoids to have two names for the same
object.
Output port constants are replaced by enumerations, using the :mod:`enum`
module:
.. py:currentmodule:: nxt.motor
=============================== ============================
NXT-Python 2 NXT-Python 3
=============================== ============================
:data:`!PORT_A` :attr:`Port.A`
:data:`!PORT_B` :attr:`Port.B`
:data:`!PORT_C` :attr:`Port.C`
:data:`!MODE_IDLE` :attr:`Mode.IDLE`
:data:`!MODE_MOTOR_ON` :attr:`Mode.ON`
:data:`!MODE_BRAKE` :attr:`Mode.BRAKE`
:data:`!MODE_REGULATED` :attr:`Mode.REGULATED`
:data:`!REGULATION_IDLE` :attr:`RegulationMode.IDLE`
:data:`!REGULATION_MOTOR_SPEED` :attr:`RegulationMode.SPEED`
:data:`!REGULATION_MOTOR_SYNC` :attr:`RegulationMode.SYNC`
:data:`!RUN_STATE_IDLE` :attr:`RunState.IDLE`
:data:`!RUN_STATE_RAMP_UP` :attr:`RunState.RAMP_UP`
:data:`!RUN_STATE_RUNNING` :attr:`RunState.RUNNING`
:data:`!RUN_STATE_RAMP_DOWN` :attr:`RunState.RAMP_DOWN`
=============================== ============================
You can now create :class:`nxt.motor.Motor` objects using
:meth:`nxt.brick.Brick.get_motor`, however direct creation still works.
Input port constants are replaced by enumerations, using the :mod:`enum`
module. The :mod:`!nxt.sensor.common` module has been removed, its content is
directly available in :mod:`nxt.sensor`:
.. py:currentmodule:: nxt.sensor
=============================== ============================
NXT-Python 2 NXT-Python 3
=============================== ============================
:data:`!PORT_1` :attr:`Port.S1`
:data:`!PORT_2` :attr:`Port.S2`
:data:`!PORT_3` :attr:`Port.S3`
:data:`!PORT_4` :attr:`Port.S4`
:attr:`!Type.NO_SENSOR` :attr:`Type.NO_SENSOR`
:attr:`!Type.SWITCH` :attr:`Type.SWITCH`
:attr:`!Type.TEMPERATURE` :attr:`Type.TEMPERATURE`
:attr:`!Type.REFLECTION` :attr:`Type.REFLECTION`
:attr:`!Type.ANGLE` :attr:`Type.ANGLE`
:attr:`!Type.LIGHT_ACTIVE` :attr:`Type.LIGHT_ACTIVE`
:attr:`!Type.LIGHT_INACTIVE` :attr:`Type.LIGHT_INACTIVE`
:attr:`!Type.SOUND_DB` :attr:`Type.SOUND_DB`
:attr:`!Type.SOUND_DBA` :attr:`Type.SOUND_DBA`
:attr:`!Type.CUSTOM` :attr:`Type.CUSTOM`
:attr:`!Type.LOW_SPEED` :attr:`Type.LOW_SPEED`
:attr:`!Type.LOW_SPEED_9V` :attr:`Type.LOW_SPEED_9V`
:attr:`!Type.HIGH_SPEED` :attr:`Type.HIGH_SPEED`
:attr:`!Type.COLORFULL` :attr:`Type.COLOR_FULL`
:attr:`!Type.COLORRED` :attr:`Type.COLOR_RED`
:attr:`!Type.COLORGREEN` :attr:`Type.COLOR_GREEN`
:attr:`!Type.COLORBLUE` :attr:`Type.COLOR_BLUE`
:attr:`!Type.COLORNONE` :attr:`Type.COLOR_NONE`
:attr:`!Type.COLOREXIT` :attr:`Type.COLOR_EXIT`
:attr:`!Mode.RAW` :attr:`Mode.RAW`
:attr:`!Mode.BOOLEAN` :attr:`Mode.BOOL`
:attr:`!Mode.TRANSITION_CNT` :attr:`Mode.EDGE`
:attr:`!Mode.PERIOD_COUNTER` :attr:`Mode.PULSE`
:attr:`!Mode.PCT_FULL_SCALE` :attr:`Mode.PERCENT`
:attr:`!Mode.CELSIUS` :attr:`Mode.CELSIUS`
:attr:`!Mode.FAHRENHEIT` :attr:`Mode.FAHRENHEIT`
:attr:`!Mode.ANGLE_STEPS` :attr:`Mode.ROTATION`
:attr:`!Mode.MASK` Removed
:attr:`!Mode.MASK_SLOPE` Removed
=============================== ============================
You can now create :mod:`~nxt.sensor` objects using
:meth:`nxt.brick.Brick.get_sensor`, however direct creation still works. For
digital sensors with identification information, this can automatically detect
the sensor type as with previous version. The new `cls` argument allows
creating a sensor object using another class.
Text String or Binary String
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The NXT brick only understands ASCII, so this is the default encoding used in
NXT-Python.
From :class:`nxt.brick.Brick`:
.. py:currentmodule:: nxt.brick
- :meth:`~Brick.get_device_info` now returns a :class:`str` for the brick
name.
- :meth:`~Brick.file_write`, :meth:`~Brick.write_io_map` and
:meth:`~Brick.message_write` now take :class:`bytes` instead of a
:class:`str`.
- :meth:`~Brick.file_read`, :meth:`~Brick.read_io_map` and
:meth:`~Brick.poll_command` no longer return the read size, but the returned
:class:`bytes` object is cut to the right size.
- :meth:`~Brick.get_current_program_name` returns a :class:`str`.
- :meth:`~Brick.file_delete` is fixed and returns a :class:`str`.
- :meth:`~Brick.find_files` and :meth:`~Brick.find_modules` use :class:`str`
for file and module names.
File Access
^^^^^^^^^^^
File reading and writing are now implemented using classes implementing
:class:`io.RawIOBase`. When using :meth:`~nxt.brick.Brick.open_file`,
depending of the parameters, the raw file-like object is returned directly, or
wrapped in a :class:`io.BufferedIOBase` or :class:`io.TextIOBase` object.
Default access mode is now text with ASCII encoding, you need to ask
explicitly for binary if needed.
This means that file access should be similar to regular Python file access.
Renamed
^^^^^^^
From :class:`nxt.brick.Brick`:
.. py:currentmodule:: nxt.brick
- :meth:`!delete` has been renamed to :meth:`~Brick.file_delete`.
- Many low level file and module access methods now have a ``file_`` or
``module_`` prefix. They are however not supposed to be used directly.
From :mod:`nxt.error`:
.. py:currentmodule:: nxt.error
- :exc:`!DirProtError` and :exc:`!SysProtError` have been renamed to
:exc:`DirectProtocolError` and :exc:`SystemProtocolError`.
- :exc:`!FileNotFound` has been renamed to :exc:`FileNotFoundError`.
- :exc:`!ModuleNotFound` has been renamed to :exc:`ModuleNotFoundError`.
- New :exc:`EmptyMailboxError` and :exc:`NoActiveProgramError` have been added
as subclasses of :exc:`DirectProtocolError`.
Sensors:
- :class:`!nxt.sensor.generic.Color20` has been renamed to
:class:`nxt.sensor.generic.Color`.
Removed
^^^^^^^
Some attributes are now private (prefixed with ``_``).
Support for the lightblue module has been removed. It has been integrated into
`PyBluez`_.
.. _PyBluez: https://github.com/pybluez/pybluez
From :mod:`nxt.brick`:
.. py:currentmodule:: nxt.brick
- :meth:`!Brick.open_read_linear` has been removed, it has never been
accessible from outside the NXT brick.
- :class:`!File`, :class:`!FileReader` and :class:`!FileWriter` have been
removed, use :meth:`Brick.open_file`.
- :class:`!FileFinder` has been removed, use :meth:`Brick.find_files`.
- :class:`!ModuleFinder` has been removed, use :meth:`Brick.find_modules`.
- :attr:`!Brick.mc` has been removed, make an instance using::
mc = nxt.motcont.MotCont(the_brick)
From other modules:
- :meth:`!nxt.motcont.MotCont.move_to` has been removed as it is not part of
`MotorControl` interface and its role was not clear.
- :exc:`!nxt.motcont.MotorConError` has been removed and replaced with
:exc:`nxt.error.ProtocolError`.
- :exc:`!nxt.telegram.InvalidReplyError` and
:exc:`!nxt.telegram.InvalidOpcodeError` have been removed and replaced with
:exc:`nxt.error.ProtocolError`.
Module :mod:`!nxt.utils` has been removed, use :mod:`argparse`.
Other Changes
^^^^^^^^^^^^^
From :class:`nxt.brick.Brick`:
.. py:currentmodule:: nxt.brick
- :meth:`~Brick.get_device_info` returns a tuple for the Bluetooth signal
strength values instead of a single 32 bit value.
- :meth:`~Brick.find_files` and :meth:`~Brick.find_modules` return an empty
iterator instead of raising an exception when no file or module is found.
- :meth:`~Brick.close` now closes the connection to the NXT brick. Also
:class:`Brick` now implements the context manager interface so that it can
be used with the ``with`` syntax.
- :meth:`~Brick.boot` now takes a argument to avoid accidental firmware
erasure.
Other:
- :class:`nxt.motcont.MotCont` methods accept tuple as argument to control
several ports.
- Scripts command line interface has changed.
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1734218447.5151248
nxt_python-3.5.1/examples/hitechnic-superpro/example1.py 0000644 0000000 0000000 00000001757 14727411320 020412 0 ustar 00 import nxt.locator
from nxt.sensor.hitechnic import SuperPro
"""
Experiment 1, adapted from the SuperPro demo
For this demo, attach an LED between B0 and GND, a button between 3V and A0, and
a 10kOhm resistor between GND and A0.
When you press the button, it will turn on the LED.
"""
# Find NXT, configure sensor
with nxt.locator.find() as brick:
pro = SuperPro(brick, nxt.sensor.Port.S1)
# Configure B0 as output
pro.set_digital_modes_byte(0x01)
while True:
try:
# The original demo doesn't convert to volts, but I think displaying volts
# to the user is better than bits.
analog_value = pro.get_analog_volts()["a0"]
print(f"Analog 0: {analog_value}V")
if analog_value > 3.3 / 2.0:
pro.set_digital_byte(0x01)
else:
pro.set_digital_byte(0x00)
except KeyboardInterrupt:
break
# When program stopped, turn off outputs
pro.set_digital_byte(0x00)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1734218447.5151248
nxt_python-3.5.1/examples/hitechnic-superpro/example2.py 0000644 0000000 0000000 00000002303 14727411320 020377 0 ustar 00 import nxt.locator
from nxt.sensor.hitechnic import SuperPro
"""
Experiment 2, adapted from the SuperPro demo
For this demo, attach LEDs between B0-B5 and GND, and a 10K between GND, 3V, and A0 (the
wiper pin to A0).
When you turn the dial, the voltage changes and the LED's turn on roughly indicating the
voltage at A0.
"""
# Find NXT, configure sensor
with nxt.locator.find() as brick:
pro = SuperPro(brick, nxt.sensor.Port.S1)
# Configure B0-5 as output
pro.set_digital_modes_byte(0x3F)
while True:
try:
# The original demo doesn't convert to volts, but I think displaying volts
# to the user is better than bits.
analog_value = pro.get_analog_volts()["a0"]
print(f"Analog 0: {analog_value}V")
# Convert voltage to 6 divisions
segmented = int((analog_value / 3.3) * 6)
# This prevents 3.3V "exactly" from being no LED's lit.
if segmented == 6:
segmented = 5
# Set the corresponding bit
pro.set_digital_byte(2**segmented)
except KeyboardInterrupt:
break
# When program stopped, turn off outputs
pro.set_digital_byte(0x00)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1734218447.5151248
nxt_python-3.5.1/examples/hitechnic-superpro/example3.py 0000644 0000000 0000000 00000002240 14727411320 020400 0 ustar 00 import nxt.locator
from nxt.sensor.generic import Ultrasonic
from nxt.sensor.hitechnic import SuperPro
"""
Experiment 3, adapted from the SuperPro demo
For this demo, attach LEDs between B0-B5 and GND, and connect an Ultrasonic to Sensor
Port 4.
When you change the distance, the LED's will roughly indicate the distance in 10cm
increments.
"""
# Find NXT, configure sensor
with nxt.locator.find() as brick:
pro = SuperPro(brick, nxt.sensor.Port.S1)
ultrasonic = Ultrasonic(brick, nxt.sensor.Port.S4)
# Configure B0-5 as output
pro.set_digital_modes_byte(0x3F)
while True:
try:
# Get distance (cm)
distance_cm = ultrasonic.get_distance()
print(f"Distance: {distance_cm}cm")
# Convert distance to 6 divisions
segmented = int(distance_cm / 10.0)
# This prevents longer distances from turning off the LED
if segmented > 6:
segmented = 5
# Set the corresponding bit
pro.set_digital_byte(2**segmented)
except KeyboardInterrupt:
break
# When program stopped, turn off outputs
pro.set_digital_byte(0x00)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1734218447.5151248
nxt_python-3.5.1/examples/hitechnic-superpro/example4.py 0000644 0000000 0000000 00000002046 14727411320 020405 0 ustar 00 from time import sleep
import nxt.locator
from nxt.sensor.hitechnic import SuperPro
"""
Experiment 4, adapted from the SuperPro demo
For this demo, attach a photo-resistor between A0 and 3V and a 4.7kOhm resistor between
GND and A0.
Note: In testing I used a 10kOhm since I don't have 4.7kOhm handy.
It measures brightness and prints to the console. The brighter it is, the higher the
voltage.
In my testing, a phone flashlight puts it to 3.2V and putting my hand over it results in
0.1V, with natural light levels in my workspace being around 1.9-2.0V
"""
# Find NXT, configure sensor
with nxt.locator.find() as brick:
pro = SuperPro(brick, nxt.sensor.Port.S1)
while True:
try:
# Get brightness (measured in volts)
analog_value = pro.get_analog_volts()["a0"]
print(f"Analog 0: {analog_value}V")
# Sleep 0.1s to allow console to be read.
sleep(0.1)
except KeyboardInterrupt:
break
# When program stopped, turn off outputs
pro.set_digital_byte(0x00)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1704409096.3199499
nxt_python-3.5.1/examples/hitechnic-superpro/example6.py 0000644 0000000 0000000 00000003170 14545634010 020407 0 ustar 00 import nxt.locator
from nxt.sensor.hitechnic import SuperPro
"""
Experiment 6, adapted from the SuperPro demo
For this demo, connect LEDs between B0-B1 and GND. Connect buttons between 3V and B4-B5.
Connect 10kOhm resistors between B4-B5 and GND.
Since the delay in signals being sent to/from the NXT is pretty long (10+ms in testing),
I just turned this into a demo that uses the input and output on the digital bus for
testing with the example circuit provided.
If you press the B4 button, B0 turns on, and if you press B5, B1 turns on.
"""
# Find NXT, configure sensor
with nxt.locator.find() as brick:
pro = SuperPro(brick, nxt.sensor.Port.S1)
# Configure B0,B1 as output
pro.set_digital_modes_byte(0b0000011)
pro.set_digital_byte(0x00)
while True:
try:
digital_input = pro.get_digital()
left_button = digital_input["b4"]
right_button = digital_input["b5"]
left_button_status = ""
if left_button:
left_button_status = "Pressed"
else:
left_button_status = "Released"
right_button_status = ""
if right_button:
right_button_status = "Pressed"
else:
right_button_status = "Released"
print(
"Left Button: {}\nRight Button: {}\n".format(
left_button_status, right_button_status
)
)
pro.set_digital_byte(left_button + right_button * 2)
except KeyboardInterrupt:
break
# When program stopped, turn off outputs
pro.set_digital_byte(0x00)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1734218447.5151248
nxt_python-3.5.1/examples/hitechnic-superpro/example7.py 0000644 0000000 0000000 00000002053 14727411320 020406 0 ustar 00 import nxt.locator
from nxt.sensor.hitechnic import SuperPro
"""
Experiment 7, adapted from the SuperPro demo
For this demo, connect a LED between B4 and GND. Connect the magnetic hall-effect sensor
(A3212EUA-T) as follows:
* Pin 1: 3V
* Pin 2: GND
* Pin 3: B0
Connect B0 to 3V with a 10kOhm resistor
Note: My magnetic hall effect sensor appears to be broken, so I couldn't really test
this. RIP
"""
# Find NXT, configure sensor
with nxt.locator.find() as brick:
pro = SuperPro(brick, nxt.sensor.Port.S1)
# Configure B4 as output
pro.set_digital_modes_byte(0b00010000)
pro.set_digital_byte(0x00)
while True:
try:
# Read B0 (magnet signal is inverted, low = magnet, then write back B4 with
# the value.
hall_effect_sensor = pro.get_digital()["b0"]
print(f"Magnet: {not hall_effect_sensor}")
pro.set_digital_byte((not hall_effect_sensor) << 4)
except KeyboardInterrupt:
break
# When program stopped, turn off outputs
pro.set_digital_byte(0x00)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1704409096.3199499
nxt_python-3.5.1/examples/hitechnic-superpro/example9.py 0000644 0000000 0000000 00000002606 14545634010 020415 0 ustar 00 from time import sleep
import nxt.locator
from nxt.sensor.hitechnic import SuperPro
"""
Experiment 9, adapted from the SuperPro demo
For this demo, connect a speaker between O0 and O1.
"""
A4_FREQ = 440
C4_FREQ = 261
DS4_FREQ = 311
E4_FREQ = 329
F4_FREQ = 349
G4_FREQ = 392
# Find NXT, configure sensor
with nxt.locator.find() as brick:
pro = SuperPro(brick, nxt.sensor.Port.S1)
pro.analog_out_voltage(0, SuperPro.AnalogOutputMode.SQUARE, C4_FREQ, 3.3)
sleep(0.2)
pro.analog_out_voltage(0, SuperPro.AnalogOutputMode.SQUARE, DS4_FREQ, 3.3)
sleep(0.2)
pro.analog_out_voltage(0, SuperPro.AnalogOutputMode.SQUARE, E4_FREQ, 3.3)
sleep(0.2)
pro.analog_out_voltage(0, SuperPro.AnalogOutputMode.SQUARE, 1, 0.0)
sleep(0.2)
pro.analog_out_voltage(0, SuperPro.AnalogOutputMode.SQUARE, F4_FREQ, 3.3)
pro.analog_out_voltage(1, SuperPro.AnalogOutputMode.SQUARE, A4_FREQ, 3.3)
sleep(0.2)
pro.analog_out_voltage(0, SuperPro.AnalogOutputMode.SQUARE, E4_FREQ, 3.3)
pro.analog_out_voltage(1, SuperPro.AnalogOutputMode.SQUARE, G4_FREQ, 3.3)
sleep(0.2)
pro.analog_out_voltage(0, SuperPro.AnalogOutputMode.SQUARE, C4_FREQ, 3.3)
pro.analog_out_voltage(1, SuperPro.AnalogOutputMode.SQUARE, E4_FREQ, 3.3)
sleep(0.2)
pro.analog_out_voltage(0, SuperPro.AnalogOutputMode.SQUARE, 1, 0.0)
pro.analog_out_voltage(1, SuperPro.AnalogOutputMode.SQUARE, 1, 0.0)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1704409096.3199499
nxt_python-3.5.1/examples/hitechnic-superpro/hitechnic-superpro-bar-display.py 0000644 0000000 0000000 00000002271 14545634010 024707 0 ustar 00 from time import sleep
import nxt.locator
from nxt.sensor.hitechnic import SuperPro
"""
For this demo, attach LED's to the HiTechnic SuperPro from pins B0-B7 to GND.
No resistors necessary, as these pins already have 220 ohm resistors.
After electrical connections are completed, connect the SuperPro to Port S1 on the NXT.
Note: The original kit only comes with 6 green/red LED's, so if you're short on LED's
just connect B0-B5.
WARNING: If you are light sensitive, avoid this demo. It flashes the B0 LED at ~5Hz.
"""
# Find NXT, configure sensor
with nxt.locator.find() as brick:
pro = SuperPro(brick, nxt.sensor.Port.S1)
# Configure digital pins as outputs.
# Outputs have 220 ohm resistors in series, so directly connect LED's from pins to
# GND
pro.set_digital_modes_byte(0xFF)
# For x in 0 to 255 (inclusive) - byte representation, Python range() is
# range(inclusive, exclusive)
for x in range(0, 256):
pro.set_digital_byte(x)
print("Outputting {0:3} ({0:<08b})".format(x))
sleep(0.1)
# Output 0 to turn off all pins
pro.set_digital_byte(0x00)
# Put all pins back as inputs (default state)
pro.set_digital_modes_byte(0x00)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1654790421.7212286
nxt_python-3.5.1/examples/motcont.py 0000644 0000000 0000000 00000001346 14250414426 014541 0 ustar 00 #!/usr/bin/env python3
"""NXT-Python example to use Linus Atorf's MotorControl.
You need to have MotorControl22 program installed on the brick, you can find it here:
https://github.com/schodet/MotorControl
Build it and install it with nxc, or upload the precompiled version (MotorControl22.rxe
file).
"""
import time
import nxt.locator
import nxt.motcont
import nxt.motor
with nxt.locator.find() as b:
mc = nxt.motcont.MotCont(b)
def wait():
while not mc.is_ready(nxt.motor.Port.A) or not mc.is_ready(nxt.motor.Port.B):
time.sleep(0.5)
mc.start()
mc.cmd((nxt.motor.Port.A, nxt.motor.Port.B), 50, 360)
wait()
mc.cmd((nxt.motor.Port.A, nxt.motor.Port.B), -50, 360)
wait()
mc.stop()
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1735655266.0230055
nxt_python-3.5.1/examples/nxt-screen.py 0000755 0000000 0000000 00000014164 14734777542 015173 0 ustar 00 #!/usr/bin/env python3
import sys
import pygame
import nxt.locator
from nxt.error import DirectProtocolError
""" example that reads out the memory region used for the display content
("framebuffer") of a USB-connected NXT
useful for those bricks with displays that died of old age (the display is
probably still fine, but the glue on the ribbon cable usually isn't)
this code basically reimplements what
https://bricxcc.sourceforge.net/utilities.html -> "NeXTScreen"
in a less obscure programming language ;-)
"""
PIXEL_SIZE = 6
WINDOW_WIDTH = 100 * PIXEL_SIZE
WINDOW_HEIGHT = (64 + 32) * PIXEL_SIZE # Additional 32 lines for the GUI-buttons
MAIN_WINDOW_SURFACE = None
FPS_CLOCK = pygame.time.Clock()
def NXT_get_display_data(b):
# each "module" has it's own memory region, id, ...
# for t in b.find_modules():
# print(t, hex(t[1]))
mod_display = 0xA0001
# display is WxH = 100x64 pixels
# their memory layout is in eight lines of 100 bytes, with each byte encoding
# a strip of eight vertical pixels
data = b""
pixels = [""] * 64
DisplayOffsetNormal = 119
for i in range(20):
data += b.read_io_map(mod_display, DisplayOffsetNormal + i * 40, 40)[1]
for line in range(8):
for x in range(100):
b = data[line * 100 + x]
for y in range(8):
bitsels = format(
b, "08b"
) # abuse the stringification to get 8 1's and 0's
pixels[line * 8 + y] += bitsels[7 - y]
return pixels
def initialize_pygame():
pygame.init()
main_window_size = (WINDOW_WIDTH, WINDOW_HEIGHT)
global MAIN_WINDOW_SURFACE
MAIN_WINDOW_SURFACE = pygame.display.set_mode(main_window_size)
pygame.display.set_caption("NXT Screen")
# paint the buttons...
rect_return = pygame.Rect(
(50 - 13) * PIXEL_SIZE, (64 + 2) * PIXEL_SIZE, 26 * PIXEL_SIZE, 16 * PIXEL_SIZE
)
pygame.draw.rect(MAIN_WINDOW_SURFACE, pygame.Color("orange"), rect_return)
pygame.draw.polygon(
MAIN_WINDOW_SURFACE,
pygame.Color("antiquewhite3"),
(
((50 - 13 - 30) * PIXEL_SIZE, (64 + 2 + 8) * PIXEL_SIZE),
((50 - 13 - 30 + 26) * PIXEL_SIZE, (64 + 2) * PIXEL_SIZE),
((50 - 13 - 30 + 26) * PIXEL_SIZE, (64 + 2 + 16) * PIXEL_SIZE),
),
)
pygame.draw.polygon(
MAIN_WINDOW_SURFACE,
pygame.Color("antiquewhite3"),
(
((50 + 13 + 30) * PIXEL_SIZE - 1, (64 + 2 + 8) * PIXEL_SIZE),
((50 + 13 + 30 - 26) * PIXEL_SIZE - 1, (64 + 2) * PIXEL_SIZE),
((50 + 13 + 30 - 26) * PIXEL_SIZE - 1, (64 + 2 + 16) * PIXEL_SIZE),
),
)
rect_exit = pygame.Rect(
(50 - 13) * PIXEL_SIZE, (64 + 20) * PIXEL_SIZE, 26 * PIXEL_SIZE, 10 * PIXEL_SIZE
)
pygame.draw.rect(MAIN_WINDOW_SURFACE, pygame.Color("antiquewhite4"), rect_exit)
def draw(pixels):
for y in range(64):
for x in range(100):
p = pixels[y][x]
if p == "0":
color = pygame.Color("grey66")
else:
color = pygame.Color("black")
rect = pygame.Rect(x * PIXEL_SIZE, y * PIXEL_SIZE, PIXEL_SIZE, PIXEL_SIZE)
pygame.draw.rect(MAIN_WINDOW_SURFACE, color, rect)
def main_loop():
b = nxt.locator.find()
print("Found brick:", b.get_device_info()[0])
# And play a recognizable note.
b.play_tone(440, 250)
while True:
for event in pygame.event.get():
# react to titlebar 'X' beeing clicked
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# or the press of the 'Esc' key
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
elif (
event.type == pygame.MOUSEBUTTONDOWN
): # interpret mouse-button clicks on the GUI buttons
if (50 - 13) * PIXEL_SIZE <= event.pos[0] <= (
50 - 13 + 26
) * PIXEL_SIZE and (64 + 2) * PIXEL_SIZE <= event.pos[1] <= (
64 + 2 + 16
) * PIXEL_SIZE:
b.write_io_map(0x40001, 35, bytearray([0x80]))
b.write_io_map(0x40001, 35, bytearray([0x80]))
if (50 - 13 - 30) * PIXEL_SIZE <= event.pos[0] <= (
50 - 13 - 30 + 26
) * PIXEL_SIZE and (64 + 2) * PIXEL_SIZE <= event.pos[1] <= (
64 + 2 + 16
) * PIXEL_SIZE:
b.write_io_map(0x40001, 34, bytearray([0x80]))
b.write_io_map(0x40001, 34, bytearray([0x80]))
if (50 + 13 + 30 - 26) * PIXEL_SIZE <= event.pos[0] <= (
50 + 13 + 30
) * PIXEL_SIZE and (64 + 2) * PIXEL_SIZE <= event.pos[1] <= (
64 + 2 + 16
) * PIXEL_SIZE:
b.write_io_map(0x40001, 33, bytearray([0x80]))
b.write_io_map(0x40001, 33, bytearray([0x80]))
if (50 - 13) * PIXEL_SIZE <= event.pos[0] <= (
50 - 13 + 26
) * PIXEL_SIZE and (64 + 20) * PIXEL_SIZE <= event.pos[1] <= (
64 + 20 + 10
) * PIXEL_SIZE:
try:
b.stop_program()
except DirectProtocolError:
b.write_io_map(0x40001, 32, bytearray([0x80]))
b.write_io_map(0x40001, 32, bytearray([0x80]))
# beep to let the user know that a screen refresh happended
# removed beep as it annoyed me :-)
# b.play_tone(440, 25)
p = NXT_get_display_data(b)
draw(p)
pygame.display.update()
# keep the refresh rate low, to not interfere with the NXP too much
# since usb-commands keep the command processor busy, which might tripp
# up the more timing critical bluetooth handling parts
# in my case 10 fps is still OK when connecting via USB:
FPS_CLOCK.tick(10)
if __name__ == "__main__":
initialize_pygame()
main_loop()
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1654462568.7501733
nxt_python-3.5.1/examples/sensors.py 0000644 0000000 0000000 00000001115 14247214151 014543 0 ustar 00 #!/usr/bin/env python3
"""NXT-Python example to use sensors."""
import time
import nxt.locator
import nxt.sensor
import nxt.sensor.generic
with nxt.locator.find() as b:
touch = b.get_sensor(nxt.sensor.Port.S1, nxt.sensor.generic.Touch)
sound = b.get_sensor(nxt.sensor.Port.S2, nxt.sensor.generic.Sound)
light = b.get_sensor(nxt.sensor.Port.S3, nxt.sensor.generic.Light, False)
us = b.get_sensor(nxt.sensor.Port.S4)
sensors = [touch, sound, light, us]
while True:
samples = [s.get_sample() for s in sensors]
print(samples)
time.sleep(0.5)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1704409096.3199499
nxt_python-3.5.1/examples/stop_turning_motor.py 0000644 0000000 0000000 00000001470 14545634010 017027 0 ustar 00 #!/usr/bin/env python3
"""NXT-Python example to use thread to stop a motor."""
import threading
import time
import nxt.locator
import nxt.motor
with nxt.locator.find() as b:
# Get the motor connected to the port A.
mymotor = b.get_motor(nxt.motor.Port.A)
stop_motor = False # controls whether the motor should stop turning
# create thread that turns the motor
t = threading.Thread(
target=mymotor.turn,
kwargs={
"power": 50,
"tacho_units": 360 * 4,
"brake": True,
"stop_turn": lambda: stop_motor,
},
)
t.start()
# stop motor after 1sec (motor would turn approximately 3sec)
time.sleep(1)
stop_motor = True
t.join()
# release motor after 1sec since brake=True
time.sleep(1)
mymotor.idle()
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1654462568.7501733
nxt_python-3.5.1/examples/tutorial/debug.py 0000644 0000000 0000000 00000000476 14247214151 016011 0 ustar 00 #!/usr/bin/python3
"""NXT-Python tutorial: increase log level."""
import logging
import nxt.locator
# Increase the log level, must be done before using any NXT-Python function. See logging
# documentation for details.
logging.basicConfig(level=logging.DEBUG)
with nxt.locator.find() as b:
b.play_tone(440, 250)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1654462568.7501733
nxt_python-3.5.1/examples/tutorial/find.py 0000644 0000000 0000000 00000000422 14247214151 015632 0 ustar 00 #!/usr/bin/python3
"""NXT-Python tutorial: find the brick."""
import nxt.locator
# Find a brick.
with nxt.locator.find() as b:
# Once found, print its name.
print("Found brick:", b.get_device_info()[0])
# And play a recognizable note.
b.play_tone(440, 250)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1654462568.7501733
nxt_python-3.5.1/examples/tutorial/motor.py 0000644 0000000 0000000 00000000536 14247214151 016060 0 ustar 00 #!/usr/bin/python3
"""NXT-Python tutorial: turn a motor."""
import nxt.locator
import nxt.motor
with nxt.locator.find() as b:
# Get the motor connected to the port A.
mymotor = b.get_motor(nxt.motor.Port.A)
# Full circle in one direction.
mymotor.turn(25, 360)
# Full circle in the opposite direction.
mymotor.turn(-25, 360)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1654462568.7501733
nxt_python-3.5.1/examples/tutorial/sensor_touch.py 0000644 0000000 0000000 00000001024 14247214151 017424 0 ustar 00 #!/usr/bin/python3
"""NXT-Python tutorial: use touch sensor."""
import time
import nxt.locator
import nxt.sensor
import nxt.sensor.generic
with nxt.locator.find() as b:
# Get the sensor connected to port 1, not a digital sensor, must give the sensor
# class.
mysensor = b.get_sensor(nxt.sensor.Port.S1, nxt.sensor.generic.Touch)
# Read the sensor in a loop (until interrupted).
print("Use Ctrl-C to interrupt")
while True:
value = mysensor.get_sample()
print(value)
time.sleep(0.5)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1654462568.7541735
nxt_python-3.5.1/examples/tutorial/sensor_us.py 0000644 0000000 0000000 00000001023 14247214151 016730 0 ustar 00 #!/usr/bin/python3
"""NXT-Python tutorial: use ultra-sonic sensor."""
import time
import nxt.locator
import nxt.sensor
# Need to import generic sensors for auto-detection to work.
import nxt.sensor.generic
with nxt.locator.find() as b:
# Find the sensor connected to port 4.
mysensor = b.get_sensor(nxt.sensor.Port.S4)
# Read the sensor in a loop (until interrupted).
print("Use Ctrl-C to interrupt")
while True:
distance_cm = mysensor.get_sample()
print(distance_cm)
time.sleep(0.5)
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1638907410.063749
nxt_python-3.5.1/logo.svg 0000644 0000000 0000000 00000021314 14153737022 012346 0 ustar 00
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1638907410.063749
nxt_python-3.5.1/nxt/__init__.py 0000644 0000000 0000000 00000001162 14153737022 013606 0 ustar 00 # nxt.__init__ module -- LEGO Mindstorms NXT python package
# Copyright (C) 2006 Douglas P Lau
# Copyright (C) 2009 Marcus Wanner
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1638907410.063749
nxt_python-3.5.1/nxt/backend/__init__.py 0000644 0000000 0000000 00000001105 14153737022 015172 0 ustar 00 # nxt.backend.__init__ module -- Backend package
# Copyright (C) 2021 Nicolas Schodet
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1640640738.8467605
nxt_python-3.5.1/nxt/backend/bluetooth.py 0000644 0000000 0000000 00000011136 14162430343 015441 0 ustar 00 # nxt.backend.bluetooth module -- Bluetooth backend
# Copyright (C) 2006, 2007 Douglas P Lau
# Copyright (C) 2009 Marcus Wanner
# Copyright (C) 2021 Nicolas Schodet
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import logging
import struct
import nxt.brick
logger = logging.getLogger(__name__)
# NXT brick RFCOMM port.
PORT = 1
class BluetoothSock:
"""Bluetooth socket connected to a NXT brick."""
#: Block size.
bsize = 118
#: Connection type, used to evaluate latency.
type = "bluetooth"
def __init__(self, bluetooth, host):
self._bluetooth = bluetooth
self._host = host
self._sock = None
def __str__(self):
return f"Bluetooth ({self._host})"
def connect(self):
"""Connect to NXT brick.
:return: Connected brick.
:rtype: Brick
"""
logger.info("connecting via %s", self)
sock = self._bluetooth.BluetoothSocket(self._bluetooth.RFCOMM)
sock.connect((self._host, PORT))
self._sock = sock
return nxt.brick.Brick(self)
def close(self):
"""Close the connection."""
if self._sock is not None:
logger.info("closing %s connection", self)
self._sock.close()
self._sock = None
def send(self, data):
"""Send raw data.
:param bytes data: Data to send.
"""
data = struct.pack("