diff --git a/CHECKLIST.txt b/CHECKLIST.txt deleted file mode 100644 index 394329e..0000000 --- a/CHECKLIST.txt +++ /dev/null @@ -1,58 +0,0 @@ -Self-Check ----------- -DO NOT RELEASE IF TIRED OR VERY LATE! :) - - -Version Strings ---------------- - [ ] RPIO/__init__.py - [ ] py_gpio.c - [ ] pwm_py.c - [ ] setup.py - [ ] doc/source/conf.py - [ ] doc/source/index.rst (section 'Changes') - - -Commit dev branch ------------------ - [ ] $ make doc - [ ] $ git status - [ ] $ git commit - - -Double-Check Tests and sdist ----------------------------- - [ ] $ fab upload build test test3 - - - upload sdist to Raspberry - [ ] test update with python2 - [ ] test update with python3 - - -Switch to master or staging branch ----------------------------------- - [ ] $ git checkout master - - -GIT Master Merge & Push ------------------------ - [ ] $ git merge -Xtheirs dev --squash - [ ] $ make doc - [ ] $ git status - [ ] $ git commit - - ... - - [ ] $ git push - - -Add Git Tag and Push --------------------- - [ ] tag added (eg. `git tag -a v0.1.2`) - [ ] git push --tags - - -Upload to PyPi --------------- - [ ] make doc_upload - [ ] fab upload_to_pypi # edit safety line in fabfile first diff --git a/LICENSE.txt b/LICENSE.txt index 20d40b6..02bbb60 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,674 +1,165 @@ - GNU GENERAL PUBLIC LICENSE + GNU LESSER 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 -. \ No newline at end of file + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser 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 +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index 88b7955..2019bde 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ graft source/c_gpio graft source/c_pwm -include source/rpio -include source/rpio-curses +include source/scripts/rpio +include source/scripts/rpio-curses diff --git a/Makefile b/Makefile index 23eee6d..d93c5fa 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,23 @@ +# $Id: Makefile,v 1.0 2013/03/12 01:01:35 Chris Hager Exp $ +# + +all: + @echo "make source - Create source package" + @echo "make doc - Generate the html documentation" + @echo "make doc_upload - make doc and upload to pythonhosted.com/RPIO" + @echo "make clean - Clean up build directories" + +source: + $(PYTHON) setup.py sdist $(COMPILE) + + +clean: + python setup.py clean + find . -name '*.pyc' -delete + rm -rf build dist MANIFEST Debug/ source/Debug RPIO.egg-info source/RPIO.egg-info + cd documentation && make clean + cd source/scripts/man && make clean + doc_upload: doc python setup.py upload_docs --upload-dir=documentation/build/html/ @@ -5,8 +25,3 @@ doc: cd documentation && make html cd source/scripts/man && make man cp source/scripts/man/build/man/rpio.1 source/scripts/man/ - -clean: - rm -rf build dist RPIO.egg-info - cd documentation && make clean - cd source/scripts/man && make clean diff --git a/README.rst b/README.rst index f3a77e0..52efdb9 100644 --- a/README.rst +++ b/README.rst @@ -1,12 +1,12 @@ RPIO is an advanced GPIO module for the Raspberry Pi. +* PWM via DMA (up to 1µs resolution) * GPIO input and output (drop-in replacement for `RPi.GPIO `_) * GPIO interrupts (callbacks when events occur on input gpios) * TCP socket interrupts (callbacks when tcp socket clients send data) -* PWM via DMA (up to 1µs resolution; 500kHz) * Command-line tools ``rpio`` and ``rpio-curses`` * Well documented, fast source code with minimal CPU usage -* Open source (GPLv3+) +* Open source (LGPLv3+) `Visit pythonhosted.org/RPIO for the documentation. `_ @@ -22,6 +22,8 @@ The easiest way to install/update RPIO on a Raspberry Pi is with either ``easy_i After the installation you can use ``import RPIO`` as well as the command-line tools ``rpio`` and ``rpio-curses``. +Debian packages are available at `metachris.github.com/rpio/download `_. + Examples -------- @@ -39,15 +41,22 @@ if you've encountered a bug. License ------- - RPIO 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 + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - RPIO is distributed in the hope that it will be useful, + 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. + GNU Lesser General Public License for more details at + + + +Copyright +--------- + + Copyright (C) 2013 Chris Hager Links diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..10e2f00 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,19 @@ +rpio (0.9.5) unstable; urgency=low + + * Cleanup + + -- Chris Hager Wed, 13 Mar 2013 02:24:08 +0100 + +rpio (0.9.4) unstable; urgency=low + + * Debounce timeout for interrupts (Closes: #XXXXXX) + * Threaded argument for wait_for_interrupts() + * Refactoring + + -- Chris Hager Tue, 12 Mar 2013 22:34:04 +0100 + +rpio (0.9.2) unstable; urgency=low + + * Initial PWM release. (Closes: #XXXXXX) + + -- Chris Hager Tue, 12 Mar 2013 17:59:56 +0100 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..3f80db7 --- /dev/null +++ b/debian/control @@ -0,0 +1,24 @@ +Source: rpio +Section: python +Priority: optional +Maintainer: Chris Hager +Build-Depends: debhelper (>= 8.0.0), python (>= 2.6.6-3~), python3 (>= 3.1.3-12~), python-setuptools, python3-setuptools, python-dev, python3-dev +Standards-Version: 3.8.4 +X-Python-Version: >= 2.6 +X-Python3-Version: >= 3.2 +Homepage: https://github.com/metachris/RPIO + +Package: python-rpio +Architecture: armhf +Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends} +Description: Advanced GPIO module for Python 2.x. Extends RPi.GPIO with + PWM, GPIO interrups, TCP socket interrupts, command line tools + and more. + + +Package: python3-rpio +Architecture: armhf +Depends: ${shlibs:Depends}, ${misc:Depends}, ${python3:Depends} +Description: Advanced GPIO module for Python 3.x. Extends RPi.GPIO with + PWM, GPIO interrups, TCP socket interrupts, command line tools + and more. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..91595d0 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,22 @@ +This package is provided to you by Chris Hager + +Files: * +Copyright: + 2013, Chris Hager +License: LGPLv3+ + +Files: debian/* +Copyright: + 2013, Chris Hager +License: LGPLv3+ + +License: LGPLv3+ + RPIO is free software: you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + RPIO 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. diff --git a/debian/python-rpio.install b/debian/python-rpio.install new file mode 100644 index 0000000..16789c6 --- /dev/null +++ b/debian/python-rpio.install @@ -0,0 +1,2 @@ +usr/lib/python2.*/ +usr/bin/ diff --git a/debian/python3-rpio.install b/debian/python3-rpio.install new file mode 100644 index 0000000..92a25ed --- /dev/null +++ b/debian/python3-rpio.install @@ -0,0 +1,2 @@ +usr/lib/python3/ + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..498c100 --- /dev/null +++ b/debian/rules @@ -0,0 +1,25 @@ +#!/usr/bin/make -f +# -*- makefile -*- + +PYTHON2=$(shell pyversions -vr) +PYTHON3=$(shell py3versions -vr) + +%: + dh $@ --with python2,python3 + +build-python%: + python$* setup.py build + +override_dh_auto_build: $(PYTHON3:%=build-python%) + dh_auto_build + +install-python%: + python$* setup.py install --root=debian/tmp --install-layout=deb + +override_dh_auto_install: $(PYTHON3:%=install-python%) + dh_auto_install + +override_dh_auto_clean: + dh_auto_clean + rm -rf build + rm -rf *.egg-info diff --git a/documentation/source/conf.py b/documentation/source/conf.py index e11b470..7880979 100644 --- a/documentation/source/conf.py +++ b/documentation/source/conf.py @@ -48,7 +48,7 @@ # built documents. # # The short X.Y version. -version = '0.9.2' +version = '0.9.5' # The full version, including alpha/beta/rc tags. release = version diff --git a/documentation/source/index.rst b/documentation/source/index.rst index bb30444..a73c0e2 100644 --- a/documentation/source/index.rst +++ b/documentation/source/index.rst @@ -3,13 +3,13 @@ Welcome to RPIO's documentation! RPIO is an advanced GPIO module for the Raspberry Pi. +* PWM via DMA (up to 1µs resolution) * GPIO input and output (drop-in replacement for `RPi.GPIO `_) * GPIO interrupts (callbacks when events occur on input gpios) * TCP socket interrupts (callbacks when tcp socket clients send data) -* PWM via DMA (up to 1µs resolution; 500kHz) * Command-line tools ``rpio`` and ``rpio-curses`` * Well documented, fast source code with minimal CPU usage -* Open source (GPLv3+) +* Open source (LGPLv3+) RPIO consists of two main components: @@ -74,38 +74,6 @@ Please send feedback and ideas to chris@linuxuser.at, and `open an issue at Gith you've encountered a bug. -FAQ ---- - -**How does RPIO work?** - - RPIO extends RPi.GPIO, a GPIO controller written in C which uses a low-level memory interface. Interrupts are - implemented with ``epoll`` via ``/sys/class/gpio/``. For more detailled information take a look at the `source `_, it's well documented and easy to build. - - -**Should I update RPIO often?** - - Yes, because RPIO is getting better by the day. You can use ``$ rpio --update-rpio`` or see :ref:`Installation ` for more information about methods to update. - - -**I've encountered a bug, what next?** - - * Make sure you are using the latest version of RPIO (see :ref:`Installation `) - * Open an issue at Github - - * Go to https://github.com/metachris/RPIO/issues/new - * Describe the problem and steps to replicate - * Add the output of ``$ rpio --version`` and ``$ rpio --sysinfo`` - - -**pip is throwing an error during the build:** ``source/c_gpio/py_gpio.c:9:20: fatal error: Python.h: No such file or directory`` - - You need to install the ``python-dev`` package (eg. ``$ sudo apt-get install python-dev``), or use ``easy_install`` (see :ref:`Installation `). - - * ``rpio-curses`` - * Bugfix in RPIO: tcp callbacks (first parameter ``socket`` works now) - * Renamed ``RPIO.rpi_sysinfo()`` to ``RPIO.sysinfo`` - Links ----- @@ -115,39 +83,44 @@ Links * http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf * http://www.kernel.org/doc/Documentation/gpio.txt - * Added TCP socket callbacks - * ``RPIO`` does not auto-clean interfaces on exceptions anymore, but will auto-clean them - as needed. This means you should now call ``RPIO.cleanup_interrupts()`` to properly close - the sockets and unexport the interfaces. - * Renamed ``RPIO.rpi_sysinfo()`` to ``RPIO.sysinfo()`` -License -------- +License & Copyright +------------------- :: - RPIO 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. + Copyright - RPIO 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. + Copyright (C) 2013 Chris Hager + + License + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + - * Improved auto-cleaning of interrupt interfaces - * BOARD numbering scheme support for interrupts - * Support for software pullup and -down resistor with interrupts - * New method ``RPIO.set_pullupdn(..)`` - * ``rpio`` now supports P5 header gpios (28, 29, 30, 31) (only in BCM mode) - * Tests added in ``source/run_tests.py`` and ``fabfile.py`` - * Major refactoring of C GPIO code - * Various minor updates and fixes Changes ------- +* v0.9.5 + + * Added ``debounce_timeout_ms`` argument to ``RPIO.add_interrupt_callback(..)`` + * Added ``threaded`` argument to ``RPIO.wait_for_interrupts(..)`` + * Interrupt callbacks now receive integer values ``0`` or ``1`` instead of strings + * Interrupt callbacks with edge=``rising`` or ``falling`` only receive the correct values + * Added ``RPIO.close_tcp_client(fileno)`` + * Debian .deb package builds + * License changed to GNU Lesser General Public License v3 or later (LGPLv3+) + * ``RPIO.sysinfo()`` returns is_overclocked (improved detection in cpuinfo.c) + * v0.9.1 * PWM diff --git a/documentation/source/pwm_py.rst b/documentation/source/pwm_py.rst index 5b6e854..819d281 100644 --- a/documentation/source/pwm_py.rst +++ b/documentation/source/pwm_py.rst @@ -4,8 +4,7 @@ ============================================== ``RPIO.PWM`` provides PWM via DMA for the Raspberry Pi, using the onboard PWM module for -semi-hardware pulse width modulation. Pulses can be set as short as 1µs, which -equates to a frequency of 500kHz. +semi-hardware pulse width modulation with a precision of up to 1µs. With ``RPIO.PWM`` you can use any of the 15 DMA channels and any number of GPIOs per channel. Since the PWM is done via DMA, ``RPIO.PWM`` uses almost zero CPU @@ -21,7 +20,8 @@ in beta, please send feedback to chris@linuxuser.at. As of yet only BCM GPIO num Examples -------- -Example of using ``PWM.Servo``:: +Example of using ``PWM.Servo`` (with the default subcycle time of 20ms and default pulse-width +increment granularity of 10µs):: from RPIO import PWM @@ -84,7 +84,7 @@ Low-level PWM method documentation (from ``$ pydoc RPIO.PWM``):: FUNCTIONS - add_channel_pulse(dma_channel, gpio, width_start, width) + add_channel_pulse(dma_channel, gpio, start, width) Add a pulse for a specific GPIO to a dma channel (within the subcycle) cleanup() @@ -145,47 +145,43 @@ for more details. Subcycles ^^^^^^^^^ -One second is divided into subcycles of user-defined length (within 2ms and 1s) -which will be repeated endlessly. The subcycle length is set -per DMA channel; the shorter the length of a subcycle, the less DMA memory will -be used. Do not set below 2ms - we started seeing weird behaviors of the RPi. - -To use servos for instance, a typical subcycle time is 20ms (which will be repeated -50 times a second). Each subcycle includes the specific pulse(s) to set the servo -to the correct position. +Each DMA channel is setup with a specific subcycle, within which pulses +are added, and which will be repeated endlessly. Servos, for instance, +typically use a subcycle of 20ms, which will be repeated 50 times a second. +You can add pulses for multiple GPIOs, as well as multiple pulses for +one GPIO. Subcycles cannot be lower than 2ms. -You can add pulses to the subcycle, and they will be repeated accordingly (eg. -a 100ms subcycle will be repeated 10 times per second; as are all the pulses -within that subcycle). You can use any number of GPIOs, and set multiple pulses -for each one. Longer subcycles use more DMA memory. +For more information about subcycles, see the examples below. The left oscilloscope +images zoom in on one subcycle, the right-handed images are zoomed out to show their repetition. Pulse-width increment granularity ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Another very important setting is the pulse width increment granularity, which -defaults to 10µs and is used for _all_ DMA channels (since its passed to the PWM -timing hardware). Under the hood you need to set the pulse widths as multiples -of the increment-granularity. Eg. in order to set 500µs pulses with a granularity -setting of 10µs, you'll need to set the pulse-width as 50 (50 * 10µs = 500µs). -Less granularity needs more DMA memory. -To achieve shorter pulses than 10µs, you simply need set a lower granularity. +The pulse-width increment granularity (10µs by default) is used for all DMA channels +(since its passed to the PWM timing hardware). Pulses are added to a subcycle by +specifying a ``start`` and a ``width`` parameter, both in multiples of the granularity. +For instance to set 500µs pulses with a granularity setting of 10µs, +you'll need to set the pulse-width as 50 (50 * 10µs = 500µs). + +The pulse-width granularity is a **system-wide setting** used by the PWM hardware, +therefore you cannot use different granularities at the same time, even in different processes. Example with Oscilloscope ------------------------- -Setup PWM.Servo with the default 20ms subcycle. On the oscilloscope GPIO 15 the -blue channel, GPIO 17 the yellow one. - -:: +In the oscilloscope images, GPIO 15 the blue channel and GPIO 17 the yellow one. The left +oscilloscope images show one subcycle, the right images are 'zoomed out' to show their repitition. +First we setup PWM.Servo with the default 20ms subcycle and 10µs pulse-width +increment granularity:: from RPIO import PWM servo = PWM.Servo() .. image:: images/pwm_0.png -Now we set a 4000us (4ms) pulse every 20ms for GPIO 15:: +Now set a 4000us (4ms) pulse every 20ms for GPIO 15:: servo.set_servo(15, 4000) @@ -197,8 +193,9 @@ Now a 1000us (1ms) pulse for GPIO 17:: .. image:: images/pwm_2.png -We can use the low-level PWM methods to add further pulses to a subcycle:: +We can use the low-level PWM methods to add further pulses to a subcycle. This is done in multiples +of the pulse-width increment granularity (``start=200*10µs=2000µs``, ``width=100*10µs=1000µs``):: - PWM.add_channel_pulse(0, 17, 200, width=100) + PWM.add_channel_pulse(0, 17, start=200, width=100) .. image:: images/pwm_3.png diff --git a/documentation/source/rpio_py.rst b/documentation/source/rpio_py.rst index 148625d..6b3cf72 100644 --- a/documentation/source/rpio_py.rst +++ b/documentation/source/rpio_py.rst @@ -6,7 +6,7 @@ RPIO.py extends `RPi.GPIO `_ in various ways, and uses the BCM GPIO numbering scheme by default. -* :ref:`GPIO Interrupts ` +* :ref:`GPIO Interrupts ` with debouncing * :ref:`TCP Socket Interrupts ` * :ref:`GPIO Input & Output ` * :ref:`Hardware PWM ` @@ -31,12 +31,20 @@ notification times, and the ability to trigger on specific edge transitions (``rising``, ``falling`` or ``both``). You can also set a software pull-up or pull-down resistor. -.. method:: RPIO.add_interrupt_callback(gpio_id, callback, edge='both', pull_up_down=RPIO.PUD_OFF, threaded_callback=False) +.. method:: RPIO.add_interrupt_callback(gpio_id, callback, edge='both', pull_up_down=RPIO.PUD_OFF, threaded_callback=False, debounce_timeout_ms=None) Adds a callback to receive notifications when a GPIO changes it's value. Possible ``pull_up_down`` values are ``RPIO.PUD_UP``, ``RPIO.PUD_DOWN`` and ``RPIO.PUD_OFF`` (default). Possible edges are ``rising``, - ``falling`` and ``both`` (default). Note that ``rising`` and ``falling`` edges may receive values - not corresponding to the edge, so be sure to double check. + ``falling`` and ``both`` (default). The values passed to the callback are of type integer, and either ``0`` or ``1``. + A callback might look like this: ``def gpio_callback(gpio_id, value):``. + + If ``debounce_timeout_ms`` is set, interrupt callbacks will not be started until the specified milliseconds have passed since the last interrupt. Adjust this to your needs (typically between 10ms and 100ms). + + +.. method:: RPIO.del_interrupt_callback(gpio_id) + + Removes all callbacks for this particular GPIO. + .. _ref-rpio-py-tcpserver: @@ -51,16 +59,23 @@ Its easy to open ports for incoming TCP connections with just this one method: by RPIO creating a TCP server socket at the specified port. Incoming connections will be accepted when ``RPIO.wait_for_interrupts()`` runs. The callback must accept exactly two parameters: socket and message (eg. ``def callback(socket, msg)``). - The callback can use the socket parameter to send values back to the client (eg. ``socket.send("hi there\n")``). To close the connection to a client, you can use ``socket.close()``. A client can close the connection the same way or by sending an empty message to the server. + The callback can use the socket parameter to send values back to the client (eg. ``socket.send("hi there\n")``). To close the connection to a client, use ``RPIO.close_tcp_client(..)``. A client can close the connection the same way or by sending an empty message to the server. + + You can use ``socket.getpeername()`` to get the IP address of the client. `Socket object documentation `_. You can test the TCP socket interrupts with ``$ telnet `` (eg. ``$ telnet localhost 8080``). An empty string tells the server to close the client connection (for instance if you just press enter in telnet, you'll get disconnected). +.. method:: RPIO.close_tcp_client(self, fileno) + + Closes the client socket connection and removes it from epoll. You can use this from the callback with ``RPIO.close_tcp_client(socket.fileno())``. + + Example ^^^^^^^ -The following example shows how to listen for GPIO and TCP interrupts (on port 8080):: +The following example shows how to listen for some GPIO and TCP interrupts:: import RPIO @@ -88,16 +103,28 @@ The following example shows how to listen for GPIO and TCP interrupts (on port 8 If you want to receive a callback inside a Thread (to not block RPIO from returning to wait for interrupts), set ``threaded_callback`` to ``True`` when adding it:: - # for GPIO interrupts RPIO.add_interrupt_callback(7, do_something, threaded_callback=True) # for socket interrupts RPIO.add_tcp_callback(8080, socket_callback, threaded_callback=True) -To stop the ``wait_for_interrupts()`` loop you can call ``RPIO.stop_waiting_for_interrupts()``. -After using ``RPIO.wait_for_interrupts()`` you should call ``RPIO.cleanup_interrupts()`` before your -program quits, to shut everything down nicely. + +To debounce GPIO interrupts, you can add the argument ``debounce_timeout_ms`` +to ``add_interrupt_callback(..)`` like this:: + + RPIO.add_interrupt_callback(7, do_something, debounce_timeout_ms=100) + + +``wait_for_interrupts()`` is a blocking method which, while running, will listen for +interrupts and start the callbacks. You can add the argument ``threaded=True`` to put +``wait_for_interrupts()`` in a thread to run in the background:: + + RPIO.wait_for_interrupts(threaded=True) + +To stop ``wait_for_interrupts(..)``, call ``RPIO.stop_waiting_for_interrupts()``. After using +``RPIO.wait_for_interrupts()`` you should call ``RPIO.cleanup_interrupts()`` before your +program quits, to shut everything down cleanly. .. _ref-rpio-py-rpigpio: @@ -190,9 +217,10 @@ Additional Methods Interrupt Handling -* ``RPIO.add_interrupt_callback(gpio_id, callback, edge='both', pull_up_down=RPIO.PUD_OFF, threaded_callback=False)`` +* ``RPIO.add_interrupt_callback(gpio_id, callback, edge='both', pull_up_down=RPIO.PUD_OFF, threaded_callback=False, debounce_timeout_ms=None)`` * ``RPIO.add_tcp_callback(port, callback, threaded_callback=False)`` * ``RPIO.del_interrupt_callback(gpio_id)`` -* ``RPIO.wait_for_interrupts(epoll_timeout=1)`` +* ``RPIO.close_tcp_client(fileno)`` +* ``RPIO.wait_for_interrupts(epoll_timeout=1, threaded=False)`` * ``RPIO.stop_waiting_for_interrupts()`` * implemented with ``epoll`` diff --git a/examples/example1_interrupts.py b/examples/example1_interrupts.py index afcc3f6..82d38b2 100644 --- a/examples/example1_interrupts.py +++ b/examples/example1_interrupts.py @@ -1,18 +1,30 @@ -import logging -log_format = '%(levelname)s | %(asctime)-15s | %(message)s' -logging.basicConfig(format=log_format, level=logging.DEBUG) +#import logging +#log_format = '%(levelname)s | %(asctime)-15s | %(message)s' +#logging.basicConfig(format=log_format, level=logging.DEBUG) + import RPIO +def gpio_callback(gpio_id, val): + print("gpio %s: %s" % (gpio_id, val)) + + def socket_callback(socket, val): print("socket %s: '%s'" % (socket.fileno(), val)) socket.send("echo: %s\n" % val) + RPIO.close_tcp_client(socket.fileno()) -def gpio_callback(gpio_id, val): - print("gpio %s: %s" % (gpio_id, val)) - - +# Add two GPIO interrupt callbacks (second one with a debouce timeout of 100ms) RPIO.add_interrupt_callback(17, gpio_callback) +RPIO.add_interrupt_callback(14, gpio_callback, edge='rising', \ + debounce_timeout_ms=100) + +# Add one TCP interrupt callback (opens socket server at port 8080) RPIO.add_tcp_callback(8080, socket_callback) -RPIO.wait_for_interrupts() + +# Wait for interrupts indefinitely, and clean up before quitting +try: + RPIO.wait_for_interrupts() +finally: + RPIO.cleanup() diff --git a/fabfile.py b/fabfile.py index 254e819..cdfde7b 100644 --- a/fabfile.py +++ b/fabfile.py @@ -1,16 +1,14 @@ """ -Fabric makes it super easy to build and test the code on a Raspberry. You can see all commands with `$ fab -l`. Typical usages: $ fab upload build_gpio test_gpio $ fab upload build_pwm $ fab upload test + $ fab build_deb -You'll need to have Fabric installed ('$ sudo pip install fabric'), -SSH access to the Raspberry Pi, abd the right host in env.hosts. """ from fabric.api import run, local, cd, put, env -from fabric.operations import prompt +from fabric.operations import prompt, get env.use_ssh_config = True @@ -19,20 +17,13 @@ env.hosts = ["raspberry_dev_local"] -def clean(): - run("rm -rf /tmp/source/") - -# Set default hosts -if not env.hosts: - env.hosts = ["raspberry_dev_local"] +def _get_cur_version(): + return local("bash version_update.sh --show", capture=True) def clean(): run("rm -rf /tmp/source/") -# Set default hosts -if not env.hosts: - env.hosts = ["raspberry_dev_local"] def upload(): """ Uploads source/ to raspberrypi:/tmp/source/ """ @@ -44,12 +35,74 @@ def upload(): run("cp source/scripts/rpio-curses source/") -def upload_dist(): - """ Makes an sdist and uploads it to /tmp """ +def make_sdist(): + """ Makes an sdist package """ local("python setup.py sdist") + + +def upload_sdist(): + """ Makes an sdist and uploads it to /tmp """ + make_sdist() put("dist/*.tar.gz", "/tmp/") +# +# Packaging +# +def build_rpm(): + pass + # "python setup.py bdist_rpm + # --post-install=rpm/postinstall --pre-uninstall=rpm/preuninstall" + + +def build_deb(): + v = _get_cur_version() + + run("rm -rf /tmp/RPIO*") + run("rm -rf /tmp/build") + run("mkdir /tmp/build") + + # Upload the sdist + upload_sdist() + with cd("/tmp/build"): + run("tar -xvf /tmp/RPIO-%s.tar.gz" % v) + run("mv RPIO-%s rpio-%s" % (v, v)) + + run("mkdir rpio-%s/dist" % v) + run("mv /tmp/RPIO-%s.tar.gz rpio-%s/dist/rpio_%s.orig.tar.gz" % \ + (v, v, v)) + + # Upload debian/ + local("tar -czf /tmp/rpio_debian.tar.gz debian") + put("/tmp/rpio_debian.tar.gz", "/tmp/") + with cd("/tmp/build/rpio-%s" % v): + run("tar -xvf /tmp/rpio_debian.tar.gz") + run("dpkg-buildpackage -i -I -rfakeroot") + + +def upload_deb(): + # Custom github upload + v = _get_cur_version() + t = ("/Users/chris/Projects/private/web/metachris.github.com/" + "rpio/download/%s/") % v + local("mkdir -p %s" % t) + get("/tmp/build/python-rpio_%s_armhf.deb" % v, t) + get("/tmp/build/python3-rpio_%s_armhf.deb" % v, t) + get("/tmp/build/rpio_*", t) + print + print "Debian release files copied. Do this now:" + print "" + print " $ cd %s/.." % t + print " $ ./gen_version_index.sh %s" % v + print " $ ./gen_index.sh" + print " $ git status" + print " $ git commit -am 'Debian packages for RPIO %s" % v + print " $ git push" + + +# +# Building of GPIO and PWM C sources +# def build_gpio(): """ Builds source with Python 2.7 and 3.2, and tests import """ with cd("/tmp/source/c_gpio"): @@ -81,6 +134,9 @@ def build(): build_pwm() +# +# Tests +# def test_gpio(): """ Invokes test suite in `run_tests.py` """ with cd("/tmp/source/RPIO"): @@ -118,6 +174,9 @@ def test3_pwm(): run("cp PWM/_PWM27.so PWM/_PWM.so") +# +# Other +# def upload_to_pypi(): """ Upload sdist and bdist_eggs to pypi """ # DO_UPLOAD provides a safety mechanism to avoid accidental pushes to pypi. diff --git a/setup.py b/setup.py index d3fab61..f856ec5 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ def read(fname): setup( name="RPIO", - version="0.9.2", + version="0.9.5", package_dir={"": "source"}, packages=['RPIO', 'RPIO.PWM'], ext_modules=[ @@ -19,8 +19,8 @@ def read(fname): scripts=["source/scripts/rpio", "source/scripts/rpio-curses"], description=(("Advanced GPIO for the Raspberry Pi. Extends RPi.GPIO with " - "GPIO interrups, TCP socket interrupts, a command line tool and " - "more")), + "PWM, GPIO interrups, TCP socket interrupts, command line tools " + "and more")), long_description=read('README.rst'), url="https://github.com/metachris/RPIO", @@ -40,7 +40,7 @@ def read(fname): "Topic :: System :: Hardware", "Intended Audience :: Developers", ("License :: OSI Approved :: " - "GNU General Public License v3 or later (GPLv3+)"), + "GNU Lesser General Public License v3 or later (LGPLv3+)"), "License :: Other/Proprietary License", ], ) diff --git a/source/RPIO/I2C.py b/source/RPIO/I2C.py deleted file mode 100644 index 1eab904..0000000 --- a/source/RPIO/I2C.py +++ /dev/null @@ -1,9 +0,0 @@ -""" -- https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/ - blob/master/Adafruit_I2C/Adafruit_I2C.py -- http://www.skpang.co.uk/blog/archives/575 -""" - - -class I2C(object): - pass diff --git a/source/RPIO/PWM.py b/source/RPIO/PWM.py deleted file mode 100644 index 814ae35..0000000 --- a/source/RPIO/PWM.py +++ /dev/null @@ -1,2 +0,0 @@ -class PWM(object): - pass diff --git a/source/RPIO/PWM/Notes.py b/source/RPIO/PWM/Notes.py deleted file mode 100644 index 23decdc..0000000 --- a/source/RPIO/PWM/Notes.py +++ /dev/null @@ -1,94 +0,0 @@ -""" -Frequencies in Hz for common acoustic notes. -""" - - -B0 = 31 -C1 = 33 -CS1 = 35 -D1 = 37 -DS1 = 39 -E1 = 41 -F1 = 44 -FS1 = 46 -G1 = 49 -GS1 = 52 -A1 = 55 -AS1 = 58 -B1 = 62 -C2 = 65 -CS2 = 69 -D2 = 73 -DS2 = 78 -E2 = 82 -F2 = 87 -FS2 = 93 -G2 = 98 -GS2 = 104 -A2 = 110 -AS2 = 117 -B2 = 123 -C3 = 131 -CS3 = 139 -D3 = 147 -DS3 = 156 -E3 = 165 -F3 = 175 -FS3 = 185 -G3 = 196 -GS3 = 208 -A3 = 220 -AS3 = 233 -B3 = 247 -C4 = 262 -CS4 = 277 -D4 = 294 -DS4 = 311 -E4 = 330 -F4 = 349 -FS4 = 370 -G4 = 392 -GS4 = 415 -A4 = 440 -AS4 = 466 -B4 = 494 -C5 = 523 -CS5 = 554 -D5 = 587 -DS5 = 622 -E5 = 659 -F5 = 698 -FS5 = 740 -G5 = 784 -GS5 = 831 -A5 = 880 -AS5 = 932 -B5 = 988 -C6 = 1047 -CS6 = 1109 -D6 = 1175 -DS6 = 1245 -E6 = 1319 -F6 = 1397 -FS6 = 1480 -G6 = 1568 -GS6 = 1661 -A6 = 1760 -AS6 = 1865 -B6 = 1976 -C7 = 2093 -CS7 = 2217 -D7 = 2349 -DS7 = 2489 -E7 = 2637 -F7 = 2794 -FS7 = 2960 -G7 = 3136 -GS7 = 3322 -A7 = 3520 -AS7 = 3729 -B7 = 3951 -C8 = 4186 -CS8 = 4435 -D8 = 4699 -DS8 = 4978 diff --git a/source/RPIO/PWM/__init__.py b/source/RPIO/PWM/__init__.py index 14931a0..f500164 100644 --- a/source/RPIO/PWM/__init__.py +++ b/source/RPIO/PWM/__init__.py @@ -1,14 +1,31 @@ # -*- coding: utf-8 -*- +# +# This file is part of RPIO. +# +# Copyright +# +# Copyright (C) 2013 Chris Hager +# +# License +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser 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 Lesser General Public License for more details at +# +# +# Documentation +# +# http://pythonhosted.org/RPIO +# """ -This file is part of RPIO. - -Author: Chris Hager -Docs: http://pythonhosted.org/RPIO -URL: https://github.com/metachris/RPIO -License: GPLv3+ - -Flexible PWM via DMA for the Raspberry Pi. Supports frequencies up to 500kHz -(1µs per pulse), multiple DMA channels, multiple GPIOs per channel, timing by +Flexible PWM via DMA for the Raspberry Pi. Supports pulse width granularities +of down to 1µs, multiple DMA channels, multiple GPIOs per channel, timing by PWM (default) or PCM and more. RPIO.PWM is BETA; feedback highly appreciated. You can directly access the low-level methods via PWM.init_channel(), etc. as diff --git a/source/RPIO/_RPIO.py b/source/RPIO/_RPIO.py new file mode 100644 index 0000000..1c1cc7b --- /dev/null +++ b/source/RPIO/_RPIO.py @@ -0,0 +1,354 @@ +# -*- coding: utf-8 -*- +# +# This file is part of RPIO. +# +# Copyright +# +# Copyright (C) 2013 Chris Hager +# +# License +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser 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 Lesser General Public License for more details at +# +# +# Documentation +# +# http://pythonhosted.org/RPIO +# +import socket +import select +import os.path +import time + +from logging import debug, info, warn, error +from threading import Thread +from functools import partial + +import RPIO._GPIO as _GPIO + +# Internals +_SYS_GPIO_ROOT = '/sys/class/gpio/' +_TCP_SOCKET_HOST = "0.0.0.0" +GPIO_FUNCTIONS = {0: "OUTPUT", 1: "INPUT", 4: "ALT0", 7: "-"} +_PULL_UPDN = ("PUD_OFF", "PUD_DOWN", "PUD_UP") + + +class Interruptor: + """ + Object-based wrapper for interrupt management. + """ + _epoll = select.epoll() + _show_warnings = True + + # Interrupt callback maps + _map_fileno_to_file = {} + _map_fileno_to_gpioid = {} + _map_fileno_to_options = {} + _map_gpioid_to_fileno = {} + _map_gpioid_to_callbacks = {} + + # Keep track of created kernel interfaces for later cleanup + _gpio_kernel_interfaces_created = [] + + # TCP socket stuff + _tcp_client_sockets = {} # { fileno: (socket, cb) } + _tcp_server_sockets = {} # { fileno: (socket, cb) } + + # Whether to continue the epoll loop or quit at next chance. You + # can manually set this to False to stop `wait_for_interrupts()`. + _is_waiting_for_interrupts = False + + def add_tcp_callback(self, port, callback, threaded_callback=False): + """ + Adds a unix socket server callback, which will be invoked when values + arrive from a connected socket client. The callback must accept two + parameters, eg. ``def callback(socket, msg)``. + """ + if not callback: + raise AttributeError("No callback") + + serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + serversocket.bind((_TCP_SOCKET_HOST, port)) + serversocket.listen(1) + serversocket.setblocking(0) + self._epoll.register(serversocket.fileno(), select.EPOLLIN) + + # Prepare the callback (wrap in Thread if needed) + cb = callback if not threaded_callback else \ + partial(_threaded_callback, callback) + + self._tcp_server_sockets[serversocket.fileno()] = (serversocket, cb) + debug("Socket server started at port %s and callback added." % port) + + def add_interrupt_callback(self, gpio_id, callback, edge='both', + pull_up_down=_GPIO.PUD_OFF, threaded_callback=False, + debounce_timeout_ms=None): + """ + Add a callback to be executed when the value on 'gpio_id' changes to + the edge specified via the 'edge' parameter (default='both'). + + `pull_up_down` can be set to `RPIO.PUD_UP`, `RPIO.PUD_DOWN`, and + `RPIO.PUD_OFF`. + + If `threaded_callback` is True, the callback will be started + inside a Thread. + """ + gpio_id = channel_to_gpio(gpio_id) + debug("Adding callback for GPIO %s" % gpio_id) + if not edge in ["falling", "rising", "both", "none"]: + raise AttributeError("'%s' is not a valid edge." % edge) + + if not pull_up_down in [PUD_UP, PUD_DOWN, PUD_OFF]: + raise AttributeError("'%s' is not a valid pull_up_down." % edge) + + # Make sure the gpio_id is valid + if not gpio_id in (GPIO_LIST_R1 if RPI_REVISION == 1 else \ + GPIO_LIST_R2): + raise AttributeError("GPIO %s is not a valid gpio-id." % gpio_id) + + # Require INPUT pin setup; and set the correct PULL_UPDN + if gpio_function(int(gpio_id)) == IN: + _GPIO.set_pullupdn(gpio_id, pull_up_down) + else: + debug("- changing gpio function from %s to INPUT" % \ + (GPIO_FUNCTIONS[gpio_function(int(gpio_id))])) + _GPIO.setup(gpio_id, IN, pull_up_down) + + # Prepare the callback (wrap in Thread if needed) + cb = callback if not threaded_callback else \ + partial(_threaded_callback, callback) + + # Prepare the /sys/class path of this gpio + path_gpio = "%sgpio%s/" % (_SYS_GPIO_ROOT, gpio_id) + + # If initial callback for this GPIO then set everything up. Else make + # sure the edge detection is the same. + if gpio_id in self._map_gpioid_to_callbacks: + with open(path_gpio + "edge", "r") as f: + e = f.read().strip() + if e != edge: + raise AttributeError(("Cannot add callback for gpio %s:" + " edge detection '%s' not compatible with existing" + " edge detection '%s'.") % (gpio_id, edge, e)) + + # Check whether edge is the same, else throw Exception + debug("- kernel interface already setup for GPIO %s" % gpio_id) + self._map_gpioid_to_callbacks[gpio_id].append(cb) + + else: + # If kernel interface already exists unexport first for clean setup + if os.path.exists(path_gpio): + if self._show_warnings: + warn("Kernel interface for GPIO %s already exists." % \ + gpio_id) + debug("- unexporting kernel interface for GPIO %s" % gpio_id) + with open(_SYS_GPIO_ROOT + "unexport", "w") as f: + f.write("%s" % gpio_id) + time.sleep(0.1) + + # Export kernel interface /sys/class/gpio/gpioN + with open(_SYS_GPIO_ROOT + "export", "w") as f: + f.write("%s" % gpio_id) + self._gpio_kernel_interfaces_created.append(gpio_id) + debug("- kernel interface exported for GPIO %s" % gpio_id) + + # Configure gpio as input + with open(path_gpio + "direction", "w") as f: + f.write("in") + + # Configure gpio edge detection + with open(path_gpio + "edge", "w") as f: + f.write(edge) + + debug(("- kernel interface configured for GPIO %s " + "(edge='%s', pullupdn=%s)") % (gpio_id, edge, \ + _PULL_UPDN[pull_up_down])) + + # Open the gpio value stream and read the initial value + f = open(path_gpio + "value", 'r') + val_initial = f.read().strip() + debug("- inital gpio value: %s" % val_initial) + f.seek(0) + + # Add callback info to the mapping dictionaries + self._map_fileno_to_file[f.fileno()] = f + self._map_fileno_to_gpioid[f.fileno()] = gpio_id + self._map_fileno_to_options[f.fileno()] = { + "debounce_timeout_s": debounce_timeout_ms / 1000.0 if \ + debounce_timeout_ms else 0, + "interrupt_last": 0, + "edge": edge + } + self._map_gpioid_to_fileno[gpio_id] = f.fileno() + self._map_gpioid_to_callbacks[gpio_id] = [cb] + + # Add to epoll + self._epoll.register(f.fileno(), select.EPOLLPRI | select.EPOLLERR) + + def del_interrupt_callback(self, gpio_id): + """ Delete all interrupt callbacks from a certain gpio """ + debug("- removing interrupts on gpio %s" % gpio_id) + gpio_id = channel_to_gpio(gpio_id) + fileno = self._map_gpioid_to_fileno[gpio_id] + + # 1. Remove from epoll + self._epoll.unregister(fileno) + + # 2. Cache the file + f = self._map_fileno_to_file[fileno] + + # 3. Remove from maps + del self._map_fileno_to_file[fileno] + del self._map_fileno_to_gpioid[fileno] + del self._map_fileno_to_options[fileno] + del self._map_gpioid_to_fileno[gpio_id] + del self._map_gpioid_to_callbacks[gpio_id] + + # 4. Close file last in case of IOError + f.close() + + def _handle_interrupt(self, fileno, val): + """ Internally distributes interrupts to all attached callbacks """ + val = int(val) + + # Filter invalid edge values (sometimes 1 comes in when edge=falling) + edge = self._map_fileno_to_options[fileno]["edge"] + if (edge == 'rising' and val == 0) or (edge == 'falling' and val == 1): + return + + # If user activated debounce for this callback, check timing now + debounce = self._map_fileno_to_options[fileno]["debounce_timeout_s"] + if debounce: + t = time.time() + t_last = self._map_fileno_to_options[fileno]["interrupt_last"] + if t - t_last < debounce: + debug("- don't start interrupt callback due to debouncing") + return + self._map_fileno_to_options[fileno]["interrupt_last"] = t + + # Start the callback(s) now + gpio_id = self._map_fileno_to_gpioid[fileno] + if gpio_id in self._map_gpioid_to_callbacks: + for cb in self._map_gpioid_to_callbacks[gpio_id]: + cb(gpio_id, val) + + def close_tcp_client(self, fileno): + debug("closing client socket fd %s" % fileno) + self._epoll.unregister(fileno) + socket, cb = self._tcp_client_sockets[fileno] + socket.close() + del self._tcp_client_sockets[fileno] + + def wait_for_interrupts(self, epoll_timeout=1): + """ + Blocking loop to listen for GPIO interrupts and distribute them to + associated callbacks. epoll_timeout is an easy way to shutdown the + blocking function. Per default the timeout is set to 1 second; if + `_is_waiting_for_interrupts` is set to False the loop will exit. + + If an exception occurs while waiting for interrupts, the interrupt + gpio interfaces will be cleaned up (/sys/class/gpio unexports). In + this case all interrupts will be reset and you'd need to add the + callbacks again before using `wait_for_interrupts(..)` again. + """ + self._is_waiting_for_interrupts = True + #try: + while self._is_waiting_for_interrupts: + events = self._epoll.poll(epoll_timeout) + for fileno, event in events: + debug("- epoll event on fd %s: %s" % (fileno, event)) + if fileno in self._tcp_server_sockets: + # New client connection to socket server + serversocket, cb = self._tcp_server_sockets[fileno] + connection, address = serversocket.accept() + connection.setblocking(0) + f = connection.fileno() + self._epoll.register(f, select.EPOLLIN) + self._tcp_client_sockets[f] = (connection, cb) + + elif event & select.EPOLLIN: + # Input from TCP socket + socket, cb = self._tcp_client_sockets[fileno] + content = socket.recv(1024) + if not content or not content.strip(): + # No content means quitting + self.close_tcp_client(fileno) + else: + sock, cb = self._tcp_client_sockets[fileno] + cb(self._tcp_client_sockets[fileno][0], \ + content.strip()) + + elif event & select.EPOLLHUP: + # TCP Socket Hangup + self.close_tcp_client(fileno) + + elif event & select.EPOLLPRI: + # GPIO interrupts + f = self._map_fileno_to_file[fileno] + # read() is workaround for not getting new values + # with read(1) + val = f.read().strip() + f.seek(0) + self._handle_interrupt(fileno, val) + + #except: + # debug("RPIO: auto-cleaning interfaces after an exception") + # cleanup_interfaces() + # cleanup_tcpsockets() + # raise + + def stop_waiting_for_interrupts(self): + """ + Ends the blocking `wait_for_interrupts()` loop the next time it can, + which depends on the `epoll_timeout` (per default its 1 second). + """ + self._is_waiting_for_interrupts = False + + def cleanup_interfaces(self): + """ + Removes all /sys/class/gpio/gpioN interfaces that this script created, + and deletes callback bindings. Should be used after using interrupts. + """ + debug("Cleaning up interfaces...") + for gpio_id in self._gpio_kernel_interfaces_created: + # Close the value-file and remove interrupt bindings + self.del_interrupt_callback(gpio_id) + + # Remove the kernel GPIO interface + debug("- unexporting GPIO %s" % gpio_id) + with open(_SYS_GPIO_ROOT + "unexport", "w") as f: + f.write("%s" % gpio_id) + + # Reset list of created interfaces + self._gpio_kernel_interfaces_created = [] + + def cleanup_tcpsockets(self): + """ + Closes all TCP connections and then the socket servers + """ + for fileno in self._tcp_client_sockets.keys(): + self.close_tcp_client(fileno) + for fileno, items in self._tcp_server_sockets.items(): + socket, cb = items + debug("- _cleanup server socket connection (fd %s)" % fileno) + self._epoll.unregister(fileno) + socket.close() + self._tcp_server_sockets = {} + + def cleanup_interrupts(self): + """ + Clean up all interrupt-related sockets and interfaces. Recommended to + use before exiting your program! After this you'll need to re-add the + interrupt callbacks before waiting for interrupts again. + """ + self.cleanup_tcpsockets() + self.cleanup_interfaces() diff --git a/source/RPIO/__init__.py b/source/RPIO/__init__.py index 09e9329..e6c39d5 100644 --- a/source/RPIO/__init__.py +++ b/source/RPIO/__init__.py @@ -1,4 +1,28 @@ # -*- coding: utf-8 -*- +# +# This file is part of RPIO. +# +# Copyright +# +# Copyright (C) 2013 Chris Hager +# +# License +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser 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 Lesser General Public License for more details at +# +# +# Documentation +# +# http://pythonhosted.org/RPIO +# """ RPIO extends RPi.GPIO with GPIO interrupts, TCP socket interrupts and more. @@ -41,12 +65,14 @@ def socket_callback(socket, val): RPIO.add_interrupt_callback(7, do_something, threaded_callback=True) RPIO.add_tcp_callback(8080, socket_callback, threaded_callback=True)) +To debounce GPIO interrupts, you can add the argument ``debounce_timeout_ms`` +to the ``add_interrupt_callback(..)`` call: -Make sure to double-check the value returned from the interrupt, since it -is not necessarily corresponding to the edge (eg. 0 may come in as value, -even if edge="rising"). To remove all callbacks from a certain gpio pin, use -`RPIO.del_interrupt_callback(gpio_id)`. To stop the `wait_for_interrupts()` -loop you can call `RPIO.stop_waiting_for_interrupts()`. + RPIO.add_interrupt_callback(7, do_something, debounce_timeout_ms=100) + +To stop the `wait_for_interrupts()` loop, call +`RPIO.stop_waiting_for_interrupts()`. To remove all callbacks from a certain +gpio pin, use `RPIO.del_interrupt_callback(gpio_id)`. Besides the interrupt handling, you can use RPIO just as RPi.GPIO: @@ -87,48 +113,44 @@ def socket_callback(socket, val): Author: Chris Hager URL: https://github.com/metachris/RPIO -License: GPLv3 +License: LGPLv3+ """ -import socket -import select -import os.path - -from logging import debug, info, warn, error from threading import Thread -from functools import partial -from time import sleep - -from RPIO._GPIO import * -from RPIO._GPIO import cleanup as _cleanup_orig -from RPIO._GPIO import setmode as _setmode - -VERSION = "0.9.2" +import RPIO._GPIO as _GPIO +from RPIO._RPIO import Interruptor + + +VERSION = "0.9.5" + +# Exposing constants from RPi.GPIO +VERSION_GPIO = _GPIO.VERSION_GPIO +RPI_REVISION = _GPIO.RPI_REVISION +RPI_REVISION_HEX = _GPIO.RPI_REVISION_HEX +HIGH = _GPIO.HIGH +LOW = _GPIO.LOW +OUT = _GPIO.OUT +IN = _GPIO.IN +ALT0 = _GPIO.ALT0 +BOARD = _GPIO.BOARD +BCM = _GPIO.BCM +PUD_OFF = _GPIO.PUD_OFF +PUD_UP = _GPIO.PUD_UP +PUD_DOWN = _GPIO.PUD_DOWN + +# Exposing methods from RPi.GPIO +setup = _GPIO.setup +output = _GPIO.output +input = _GPIO.input +setmode = _GPIO.setmode +forceoutput = _GPIO.forceoutput +forceinput = _GPIO.forceinput +set_pullupdn = _GPIO.set_pullupdn +gpio_function = _GPIO.gpio_function +channel_to_gpio = _GPIO.channel_to_gpio # BCM numbering mode by default -setmode(BCM) - -# Interrupt callback maps -_map_fileno_to_file = {} -_map_fileno_to_gpioid = {} -_map_gpioid_to_fileno = {} -_map_gpioid_to_callbacks = {} - -# Keep track of created kernel interfaces for later cleanup -_gpio_kernel_interfaces_created = [] - -# TCP socket stuff -_TCP_SOCKET_HOST = "0.0.0.0" -_tcp_client_sockets = {} # { fileno: (socket, cb) } -_tcp_server_sockets = {} # { fileno: (socket, cb) } - -# Whether to continue the epoll loop or quit at next chance. You -# can manually set this to False to stop `wait_for_interrupts()`. -_is_waiting_for_interrupts = False - -# Internals -_epoll = select.epoll() -_SYS_GPIO_ROOT = '/sys/class/gpio/' -GPIO_FUNCTIONS = {0: "OUTPUT", 1: "INPUT", 4: "ALT0", 7: "-"} +_GPIO.setmode(BCM) + MODEL_DATA = { '2': ('B', '1.0', 256, '?'), '3': ('B', '1.0', 256, '?'), @@ -142,7 +164,6 @@ def socket_callback(socket, val): 'e': ('B', '2.0', 512, 'Sony'), 'f': ('B', '2.0', 512, 'Qisda') } -_PULL_UPDN = ("PUD_OFF", "PUD_DOWN", "PUD_UP") # List of valid bcm gpio ids for raspberry rev1 and rev2. Used for inspect-all. GPIO_LIST_R1 = (0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25) @@ -157,6 +178,9 @@ def socket_callback(socket, val): PIN_LIST = (3, 5, 7, 8, 10, 11, 12, 13, 15, 16, 18, 19, 21, 22, 23, 24, 26, \ 3 | HEADER_P5, 4 | HEADER_P5, 5 | HEADER_P5, 6 | HEADER_P5) +# _rpio is the interrupt handling wrapper object +_rpio = Interruptor() + def _threaded_callback(callback, *args): """ Internal wrapper to start a callback in threaded mode """ @@ -164,36 +188,27 @@ def _threaded_callback(callback, *args): def sysinfo(): - """ Returns (model, revision, mb-ram and maker) for this raspberry """ + """ Returns (model, revision, mb-ram, maker) for this raspberry """ return (RPI_REVISION_HEX,) + MODEL_DATA[RPI_REVISION_HEX.lstrip("0")] +def version(): + """ Returns a tuple of (VERSION, VERSION_GPIO) """ + return (VERSION, VERSION_GPIO) + + def add_tcp_callback(port, callback, threaded_callback=False): """ Adds a unix socket server callback, which will be invoked when values arrive from a connected socket client. The callback must accept two parameters, eg. ``def callback(socket, msg)``. """ - if not callback: - raise AttributeError("No callback") - - serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - serversocket.bind((_TCP_SOCKET_HOST, port)) - serversocket.listen(1) - serversocket.setblocking(0) - _epoll.register(serversocket.fileno(), select.EPOLLIN) - - # Prepare the callback (wrap in Thread if needed) - cb = callback if not threaded_callback else \ - partial(_threaded_callback, callback) + _rpio.add_tcp_callback(port, callback, threaded_callback) - _tcp_server_sockets[serversocket.fileno()] = (serversocket, cb) - debug("Socket server started at port %s and callback added." % port) - -def add_interrupt_callback(gpio_id, callback, edge='both', - pull_up_down=PUD_OFF, threaded_callback=False): +def add_interrupt_callback(gpio_id, callback, edge='both', \ + pull_up_down=PUD_OFF, threaded_callback=False, \ + debounce_timeout_ms=None): """ Add a callback to be executed when the value on 'gpio_id' changes to the edge specified via the 'edge' parameter (default='both'). @@ -203,133 +218,25 @@ def add_interrupt_callback(gpio_id, callback, edge='both', If `threaded_callback` is True, the callback will be started inside a Thread. - """ - gpio_id = channel_to_gpio(gpio_id) - debug("Adding callback for GPIO %s" % gpio_id) - if not edge in ["falling", "rising", "both", "none"]: - raise AttributeError("'%s' is not a valid edge." % edge) - - if not pull_up_down in [PUD_UP, PUD_DOWN, PUD_OFF]: - raise AttributeError("'%s' is not a valid pull_up_down value." % edge) - - # Make sure the gpio_id is valid - if not gpio_id in (GPIO_LIST_R1 if RPI_REVISION == 1 else GPIO_LIST_R2): - raise AttributeError("GPIO %s is not a valid gpio-id for this board." \ - % gpio_id) - - # Require INPUT pin setup; and set the correct PULL_UPDN - if gpio_function(int(gpio_id)) == IN: - set_pullupdn(gpio_id, pull_up_down) - else: - debug("- changing gpio function from %s to INPUT" % \ - (GPIO_FUNCTIONS[gpio_function(int(gpio_id))])) - setup(gpio_id, IN, pull_up_down) - - # Prepare the callback (wrap in Thread if needed) - cb = callback if not threaded_callback else \ - partial(_threaded_callback, callback) - - # Prepare the /sys/class path of this gpio - path_gpio = "%sgpio%s/" % (_SYS_GPIO_ROOT, gpio_id) - - # If initial callback for this GPIO then set everything up. Else make sure - # the edge detection is the same and add this to the callback list. - if gpio_id in _map_gpioid_to_callbacks: - with open(path_gpio + "edge", "r") as f: - e = f.read().strip() - if e != edge: - raise AttributeError(("Cannot add callback for gpio %s:" - " edge detection '%s' not compatible with existing" - " edge detection '%s'.") % (gpio_id, edge, e)) - - # Check whether edge is the same, else throw Exception - debug("- kernel interface already configured for GPIO %s" % gpio_id) - _map_gpioid_to_callbacks[gpio_id].append(cb) - else: - # If kernel interface already exists, unexport first for clean setup - if os.path.exists(path_gpio): - debug("- unexporting kernel interface for GPIO %s" % gpio_id) - with open(_SYS_GPIO_ROOT + "unexport", "w") as f: - f.write("%s" % gpio_id) - sleep(0.1) - - # Export kernel interface /sys/class/gpio/gpioN - with open(_SYS_GPIO_ROOT + "export", "w") as f: - f.write("%s" % gpio_id) - global _gpio_kernel_interfaces_created - _gpio_kernel_interfaces_created.append(gpio_id) - debug("- kernel interface exported for GPIO %s" % gpio_id) - - # Configure gpio as input - with open(path_gpio + "direction", "w") as f: - f.write("in") - - # Configure gpio edge detection - with open(path_gpio + "edge", "w") as f: - f.write(edge) - - debug(("- kernel interface configured for GPIO %s " - "(edge='%s', pullupdn=%s)") % (gpio_id, edge, \ - _PULL_UPDN[pull_up_down])) - - # Open the gpio value stream and read the initial value - f = open(path_gpio + "value", 'r') - val_initial = f.read().strip() - debug("- inital gpio value: %s" % val_initial) - f.seek(0) - - # Add callback info to the mapping dictionaries - _map_fileno_to_file[f.fileno()] = f - _map_fileno_to_gpioid[f.fileno()] = gpio_id - _map_gpioid_to_fileno[gpio_id] = f.fileno() - _map_gpioid_to_callbacks[gpio_id] = [cb] - - # Add to epoll - _epoll.register(f.fileno(), select.EPOLLPRI | select.EPOLLERR) + If debounce_timeout_ms is set, new interrupts will not be forwarded + until after the specified amount of milliseconds. + """ + _rpio.add_interrupt_callback(gpio_id, callback, edge, pull_up_down, \ + threaded_callback, debounce_timeout_ms) def del_interrupt_callback(gpio_id): """ Delete all interrupt callbacks from a certain gpio """ - debug("- removing interrupts on gpio %s" % gpio_id) - gpio_id = channel_to_gpio(gpio_id) - fileno = _map_gpioid_to_fileno[gpio_id] - - # 1. Remove from epoll - _epoll.unregister(fileno) - - # 2. Cache the file - f = _map_fileno_to_file[fileno] + _rpio.del_interrupt_callback(gpio_id) - # 3. Remove from maps - del _map_fileno_to_file[fileno] - del _map_fileno_to_gpioid[fileno] - del _map_gpioid_to_fileno[gpio_id] - del _map_gpioid_to_callbacks[gpio_id] - # 4. Close file last. In case of IOError everything else has been shutdown - f.close() +def close_tcp_client(fileno): + """ Closes TCP connection to a client and removes client from epoll """ + _rpio.close_tcp_client(fileno) -def _handle_interrupt(fileno, val): - """ Internally distributes interrupts to all attached callbacks """ - gpio_id = _map_fileno_to_gpioid[fileno] - if gpio_id in _map_gpioid_to_callbacks: - for cb in _map_gpioid_to_callbacks[gpio_id]: - # Start the callback! - cb(gpio_id, val) - - -def _close_tcp_client(fileno): - debug("closing client socket fd %s" % fileno) - global _tcp_client_sockets - _epoll.unregister(fileno) - socket, cb = _tcp_client_sockets[fileno] - socket.close() - del _tcp_client_sockets[fileno] - - -def wait_for_interrupts(epoll_timeout=1): +def wait_for_interrupts(epoll_timeout=1, threaded=False): """ Blocking loop to listen for GPIO interrupts and distribute them to associated callbacks. epoll_timeout is an easy way to shutdown the @@ -340,52 +247,14 @@ def wait_for_interrupts(epoll_timeout=1): gpio interfaces will be cleaned up (/sys/class/gpio unexports). In this case all interrupts will be reset and you'd need to add the callbacks again before using `wait_for_interrupts(..)` again. + + If the argument `threaded` is True, wait_for_interrupts will be + started in a Thread. To quit it, call `RPIO.stop_waiting_for_interrupts()`. """ - global _is_waiting_for_interrupts - _is_waiting_for_interrupts = True - #try: - while _is_waiting_for_interrupts: - events = _epoll.poll(epoll_timeout) - for fileno, event in events: - debug("- epoll event on fd %s: %s" % (fileno, event)) - if fileno in _tcp_server_sockets: - # New client connection to socket server - serversocket, cb = _tcp_server_sockets[fileno] - connection, address = serversocket.accept() - connection.setblocking(0) - f = connection.fileno() - _epoll.register(f, select.EPOLLIN) - _tcp_client_sockets[f] = (connection, cb) - - elif event & select.EPOLLIN: - # Input from TCP socket - socket, cb = _tcp_client_sockets[fileno] - content = socket.recv(1024) - if not content or not content.strip(): - # No content means quitting - _close_tcp_client(fileno) - else: - sock, cb = _tcp_client_sockets[fileno] - cb(_tcp_client_sockets[fileno][0], content.strip()) - - elif event & select.EPOLLHUP: - # TCP Socket Hangup - _close_tcp_client(fileno) - - elif event & select.EPOLLPRI: - # GPIO interrupts - f = _map_fileno_to_file[fileno] - # read() is workaround for not getting new values - # with read(1) - val = f.read().strip() - f.seek(0) - _handle_interrupt(fileno, val) - - #except: - # debug("RPIO: auto-cleaning interfaces after an exception") - # _cleanup_interfaces() - # _cleanup_tcpsockets() - # raise + if threaded: + Thread(target=_rpio.wait_for_interrupts, args=(epoll_timeout,)).start() + else: + _rpio.wait_for_interrupts(epoll_timeout) def stop_waiting_for_interrupts(): @@ -393,46 +262,7 @@ def stop_waiting_for_interrupts(): Ends the blocking `wait_for_interrupts()` loop the next time it can, which depends on the `epoll_timeout` (per default its 1 second). """ - global _is_waiting_for_interrupts - _is_waiting_for_interrupts = False - - -def _cleanup_interfaces(): - """ - Remove all /sys/class/gpio/gpioN interfaces that this script created, - and delete all callback bindings. Should be used after using interrupts. - """ - debug("Cleaning up interfaces...") - global _gpio_kernel_interfaces_created - for gpio_id in _gpio_kernel_interfaces_created: - # Close the value-file and remove interrupt bindings - try: - del_interrupt_callback(gpio_id) - except: - pass - - # Remove the kernel GPIO interface - debug("- unexporting GPIO %s" % gpio_id) - with open(_SYS_GPIO_ROOT + "unexport", "w") as f: - f.write("%s" % gpio_id) - - # Reset list of created interfaces - _gpio_kernel_interfaces_created = [] - - -def _cleanup_tcpsockets(): - """ - Closes all TCP connections and then the socket servers - """ - global _tcp_server_sockets - for fileno in _tcp_client_sockets.keys(): - _close_tcp_client(fileno) - for fileno, items in _tcp_server_sockets.items(): - socket, cb = items - debug("- _cleanup server socket connection (fd %s)" % fileno) - _epoll.unregister(fileno) - socket.close() - _tcp_server_sockets = {} + _rpio.stop_waiting_for_interrupts() def cleanup_interrupts(): @@ -441,8 +271,7 @@ def cleanup_interrupts(): use before exiting your program! After this you'll need to re-add the interrupt callbacks before waiting for interrupts again. """ - _cleanup_tcpsockets() - _cleanup_interfaces() + _rpio.cleanup_interrupts() def cleanup(): @@ -453,9 +282,10 @@ def cleanup(): to add the interrupt callbacks again before waiting for interrupts again. """ cleanup_interrupts() - _cleanup_orig() + _GPIO.cleanup() -def version(): - """ Returns a tuple of (VERSION, VERSION_GPIO) """ - return (VERSION, VERSION_GPIO) +def setwarnings(enabled=True): + """ Show warnings (either `True` or `False`) """ + _GPIO.setwarnings(enabled) + _rpio._show_warnings = enabled diff --git a/source/c_gpio/c_gpio.c b/source/c_gpio/c_gpio.c index 24cf387..25a04ca 100644 --- a/source/c_gpio/c_gpio.c +++ b/source/c_gpio/c_gpio.c @@ -1,18 +1,31 @@ /* -c_gpio.c is based on RPi.GPIO by Ben Croston, and provides a Python interface to -interact with the gpio-related C methods. This file is under active development -as part of the RPIO package by Chris Hager . - -URL: https://github.com/metachris/RPIO -License: c_gpio.c is released under the MIT License - -Internally everything works with BCM gpio numbering mode! - -Changes: -- PEP7 cleanup -- Added some documentation -- Removed experimental event detection methods -*/ + * This file is part of RPIO. + * + * Copyright + * + * Copyright (C) 2013 Chris Hager + * + * License + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + * + * + * Documentation + * + * http://pythonhosted.org/RPIO + * + * + * c_gpio.c is based on RPi.GPIO by Ben Croston, and provides a Python interface to + * interact with the gpio-related C methods. + */ #include #include #include diff --git a/source/c_gpio/c_gpio.h b/source/c_gpio/c_gpio.h index ee80f9e..ef2a69c 100644 --- a/source/c_gpio/c_gpio.h +++ b/source/c_gpio/c_gpio.h @@ -1,3 +1,27 @@ +/* + * This file is part of RPIO. + * + * Copyright + * + * Copyright (C) 2013 Chris Hager + * + * License + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + * + * + * Documentation + * + * http://pythonhosted.org/RPIO + */ int setup(void); void setup_gpio(int gpio, int direction, int pud); void output_gpio(int gpio, int value); diff --git a/source/c_gpio/cpuinfo.c b/source/c_gpio/cpuinfo.c index 186aae3..e37ca7a 100644 --- a/source/c_gpio/cpuinfo.c +++ b/source/c_gpio/cpuinfo.c @@ -1,11 +1,27 @@ /* -cpuinfo.c is based on RPi.GPIO by Ben Croston, and provides a Python interface to -interact with the gpio-related C methods. This file is under active development -as part of the RPIO package by Chris Hager . - -URL: https://github.com/metachris/RPIO -License: cpuinfo.c is released under the MIT License -*/ + * This file is part of RPIO. + * + * Copyright + * + * Copyright (C) 2013 Chris Hager + * + * License + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + * + * + * Documentation + * + * http://pythonhosted.org/RPIO + */ #include #include #include "cpuinfo.h" @@ -15,6 +31,10 @@ License: cpuinfo.c is released under the MIT License // 1 (raspberry with revision 1 pin setup) // 0 (not a raspberry pi) // -1 (could not open /proc/cpuinfo) +// +// revision_hex will be four characters revision id (eg. '0004'), +// the over-voltage header, if present, is removed (since it is +// not consistently present on all overclocked boards). int get_cpuinfo_revision(char *revision_hex) { @@ -38,15 +58,22 @@ get_cpuinfo_revision(char *revision_hex) if (!rpi_found) { revision_hex = NULL; return 0; - } else if ((strcmp(revision_hex, "0002") == 0) || - (strcmp(revision_hex, "1000002") == 0 ) || - (strcmp(revision_hex, "0003") == 0) || - (strcmp(revision_hex, "1000003") == 0 )) { + } + + // If over-voltage is present, remove it + char* pos = strstr(revision_hex, "1000"); + if (pos && pos - revision_hex == 0 && strlen(revision_hex) > 5) { + strcpy(revision_hex, revision_hex+4); + } + + // Returns revision + if ((strcmp(revision_hex, "0002") == 0) || + (strcmp(revision_hex, "0003") == 0)) { return 1; } else { - // assume rev 2 (0004 0005 0006 1000004 1000005 1000006 ...) + // assume rev 2 (0004 0005 0006 ...) return 2; } - return -1; + return -1; } diff --git a/source/c_gpio/cpuinfo.h b/source/c_gpio/cpuinfo.h index 9610346..3b54068 100644 --- a/source/c_gpio/cpuinfo.h +++ b/source/c_gpio/cpuinfo.h @@ -1 +1,25 @@ -int get_cpuinfo_revision(char *revision_hex); +/* + * This file is part of RPIO. + * + * Copyright + * + * Copyright (C) 2013 Chris Hager + * + * License + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + * + * + * Documentation + * + * http://pythonhosted.org/RPIO + */ +int get_cpuinfo_revision(char *revision_hex); \ No newline at end of file diff --git a/source/c_gpio/py_gpio.c b/source/c_gpio/py_gpio.c index 7db5520..d4b0536 100644 --- a/source/c_gpio/py_gpio.c +++ b/source/c_gpio/py_gpio.c @@ -1,11 +1,30 @@ /* -py_gpio.c is based on RPi.GPIO by Ben Croston, and provides a Python interface to -interact with the gpio-related C methods. This file is under active development -as part of the RPIO package by Chris Hager . - -URL: https://github.com/metachris/RPIO -License: py_gpio.c is released under the MIT License -*/ + * This file is part of RPIO. + * + * Copyright + * + * Copyright (C) 2013 Chris Hager + * + * License + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + * + * + * Documentation + * + * http://pythonhosted.org/RPIO + * + * py_gpio.c is based on RPi.GPIO by Ben Croston, and provides a Python interface to + * interact with the gpio-related C methods. + */ #include "Python.h" #include "c_gpio.h" #include "cpuinfo.h" @@ -299,25 +318,6 @@ py_set_pullupdn(PyObject *self, PyObject *args, PyObject *kwargs) return Py_None; } -// python function output(channel, value) without direction check -static PyObject* -py_set_pullupdn(PyObject *self, PyObject *args, PyObject *kwargs) -{ - int gpio, channel; - int pud = PUD_OFF; - - static char *kwlist[] = {"channel", "pull_up_down", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii", kwlist, &channel, &pud)) - return NULL; - - if ((gpio = channel_to_gpio(channel)) < 0) - return NULL; - - // printf("Setting gpio %d PULLUPDN to %d", gpio, pud); - set_pullupdn(gpio, pud); - return Py_None; -} - // python function value = input(channel) static PyObject* py_input_gpio(PyObject *self, PyObject *args) @@ -540,7 +540,7 @@ PyMODINIT_FUNC init_GPIO(void) rpi_revision_hex = Py_BuildValue("s", revision_hex); PyModule_AddObject(module, "RPI_REVISION_HEX", rpi_revision_hex); - version = Py_BuildValue("s", "0.9.2/0.4.2a"); + version = Py_BuildValue("s", "0.9.5/0.4.2a"); PyModule_AddObject(module, "VERSION_GPIO", version); // set up mmaped areas diff --git a/source/c_pwm/pwm.c b/source/c_pwm/pwm.c index daab78c..86729f3 100644 --- a/source/c_pwm/pwm.c +++ b/source/c_pwm/pwm.c @@ -1,17 +1,32 @@ /* * This file is part of RPIO. * - * Author: Chris Hager - * URL: https://github.com/metachris/RPIO - * License: GPLv3+ (and an optional commercial license) + * Copyright * - * pwm.c provides flexible PWM via DMA for the Raspberry Pi, supporting frequencies - * up to 500kHz (1us per pulse), multiple DMA channels, multiple GPIOs per channel, - * timing by PWM (default) or PCM, a Python wrapper, and more. + * Copyright (C) 2013 Chris Hager * - * pwm.c is based on the excellent servod.c by Richard Hirst, which has been refactored - * and upgraded primarily with runtime PWM control (to use it as a library), support - * for all 15 DMA channels and GPIO multiplexing within a single channel. + * License + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + * + * + * Documentation + * + * http://pythonhosted.org/RPIO + * + * + * pwm.c, based on the excellent servod.c by Richard Hirst, provides flexible + * PWM via DMA for the Raspberry Pi, supporting a resolution of up to 1us, + * all 15 DMA channels, multiple GPIOs per channel, timing by PWM (default) + * or PCM, a Python wrapper, and more. * * Feedback is much appreciated. * diff --git a/source/c_pwm/pwm.h b/source/c_pwm/pwm.h index 6ed5033..d181211 100644 --- a/source/c_pwm/pwm.h +++ b/source/c_pwm/pwm.h @@ -1,9 +1,26 @@ /* * This file is part of RPIO. * - * License: GPLv3+ - * Author: Chris Hager - * URL: https://github.com/metachris/RPIO + * Copyright + * + * Copyright (C) 2013 Chris Hager + * + * License + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + * + * + * Documentation + * + * http://pythonhosted.org/RPIO */ int setup(int pw_incr_us, int hw); void shutdown(void); diff --git a/source/c_pwm/pwm_py.c b/source/c_pwm/pwm_py.c index 54d30c8..fc1fac5 100644 --- a/source/c_pwm/pwm_py.c +++ b/source/c_pwm/pwm_py.c @@ -1,9 +1,26 @@ /* * This file is part of RPIO. * - * License: GPLv3+ - * Author: Chris Hager - * URL: https://github.com/metachris/RPIO + * Copyright + * + * Copyright (C) 2013 Chris Hager + * + * License + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + * + * + * Documentation + * + * http://pythonhosted.org/RPIO */ #include "Python.h" #include @@ -228,7 +245,7 @@ PyMODINIT_FUNC init_PWM(void) return; #endif - PyModule_AddObject(module, "VERSION", Py_BuildValue("s", "0.9.2")); + PyModule_AddObject(module, "VERSION", Py_BuildValue("s", "0.9.5")); PyModule_AddObject(module, "DELAY_VIA_PWM", Py_BuildValue("i", DELAY_VIA_PWM)); PyModule_AddObject(module, "DELAY_VIA_PCM", Py_BuildValue("i", DELAY_VIA_PCM)); PyModule_AddObject(module, "LOG_LEVEL_DEBUG", Py_BuildValue("i", LOG_LEVEL_DEBUG)); diff --git a/source/c_pwm/servod.c b/source/c_pwm/servod.c index b291f89..c93e17f 100644 --- a/source/c_pwm/servod.c +++ b/source/c_pwm/servod.c @@ -1,6 +1,28 @@ /* - * rpio_pwm.c: PWM via DMA for the RaspberryPi, based on the excellent - * ServoBlaster by Richard Hirst. + * This file is part of RPIO. + * + * Copyright + * + * Copyright (C) 2013 Chris Hager + * + * License + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License for more details at + * + * + * Documentation + * + * http://pythonhosted.org/RPIO + * + * Based on the excellent ServoBlaster by Richard Hirst. * * Documentation * ============= @@ -20,12 +42,7 @@ * This documentation is work in progress. Look here for more information: * - https://github.com/metachris/raspberrypi-pwm * - https://github.com/richardghirst/PiBits/blob/master/ServoBlaster - * - * - * Author: Chris Hager - * URL: https://github.com/metachris/raspberrypi-pwm */ - #include #include #include diff --git a/source/scripts/man/rpio.1 b/source/scripts/man/rpio.1 index 276137e..ee2f3dd 100644 --- a/source/scripts/man/rpio.1 +++ b/source/scripts/man/rpio.1 @@ -1,4 +1,4 @@ -.TH "RPIO" "1" "March 09, 2013" "0.9.2" "RPIO" +.TH "RPIO" "1" "March 13, 2013" "0.9.5" "RPIO" .SH NAME rpio \- RPIO Documentation . diff --git a/source/scripts/rpio b/source/scripts/rpio index 2c1d2ce..40f30b9 100644 --- a/source/scripts/rpio +++ b/source/scripts/rpio @@ -61,7 +61,7 @@ Here are some examples of how to use `rpio`: Model B, Revision 2.0, RAM: 256 MB, Maker: Sony Author: Chris Hager -License: GPLv3 +License: LGPLv3+ URL: https://github.com/metachris/RPIO """ import os diff --git a/source/scripts/rpio-curses b/source/scripts/rpio-curses index 5a5cbb5..1753111 100644 --- a/source/scripts/rpio-curses +++ b/source/scripts/rpio-curses @@ -5,7 +5,7 @@ Curses-based rpio interface Author: Chris Hager URL: http://pythonhosted.org//RPIO -License: GPLv3+ +License: LGPLv3+ """ import os import sys @@ -42,7 +42,7 @@ of a menu you can press [arrow-left] or [ESC]. Author: Chris Hager URL: http://pythonhosted.org/RPIO -License: GPLv3+ +License: LGPLv3+ """ # Timeout between refreshing the GPIO states. You can adjust @@ -69,9 +69,11 @@ POS_GPIOINFO_Y = 2 CURSOR_WIDTHS = {0: 23, 1: 30, 4: 17} # Only import RPIO if not on a dev machine +RPIO_VERSION = "dev" if "no_rpio" not in CMD_OPTIONS: import RPIO RPIO.setwarnings(False) + RPIO_VERSION = RPIO.VERSION def get_gpiolist(): pins = RPIO.GPIO_LIST_R1 if RPIO.RPI_REVISION == 1 \ else RPIO.GPIO_LIST_R2 @@ -163,7 +165,7 @@ class Drawer(object): #screen.clear() #screen.refresh() - screen.addstr(0, 0, "RPIO v%s" % "0.8.4") + screen.addstr(0, 0, "RPIO v%s" % RPIO_VERSION) pos_y = POS_GPIOLIST_Y for gpio in self.gpios: diff --git a/source/scripts/rpio-gui b/source/scripts/rpio-gui deleted file mode 100644 index e69de29..0000000 diff --git a/source/tests_gpio.py b/source/tests_gpio.py index 32ee185..c113ce1 100644 --- a/source/tests_gpio.py +++ b/source/tests_gpio.py @@ -1,4 +1,28 @@ #!/usr/bin/env python +# +# This file is part of RPIO. +# +# Copyright +# +# Copyright (C) 2013 Chris Hager +# +# License +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser 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 Lesser General Public License for more details at +# +# +# Documentation +# +# http://pythonhosted.org/RPIO +# """ This test suite runs on the Raspberry Pi and tests RPIO inside out. """ @@ -15,8 +39,8 @@ import RPIO RPIO.setwarnings(False) -GPIO_IN = 17 -GPIO_OUT = 14 +GPIO_IN = 14 +GPIO_OUT = 17 def run(cmd): @@ -43,11 +67,11 @@ def test3_input(self): logging.info(" ") logging.info(" ") logging.info("=== INPUT TESTS ===") - with self.assertRaises(RPIO.InvalidChannelException): + with self.assertRaises(RPIO._GPIO.InvalidChannelException): RPIO.setup(5, RPIO.IN) - with self.assertRaises(RPIO.InvalidChannelException): + with self.assertRaises(RPIO._GPIO.InvalidChannelException): RPIO.setup(0, RPIO.IN) - with self.assertRaises(RPIO.InvalidChannelException): + with self.assertRaises(RPIO._GPIO.InvalidChannelException): RPIO.setup(32, RPIO.IN) RPIO.setup(GPIO_IN, RPIO.IN) @@ -69,13 +93,13 @@ def test4_output(self): logging.info(" ") logging.info(" ") logging.info("=== OUTPUT TESTS ===") - with self.assertRaises(RPIO.InvalidChannelException): + with self.assertRaises(RPIO._GPIO.InvalidChannelException): # 5 is not a valid gpio RPIO.setup(5, RPIO.OUT) - with self.assertRaises(RPIO.InvalidChannelException): + with self.assertRaises(RPIO._GPIO.InvalidChannelException): # 5 is not a valid gpio RPIO.setup(0, RPIO.OUT) - with self.assertRaises(RPIO.InvalidChannelException): + with self.assertRaises(RPIO._GPIO.InvalidChannelException): # 5 is not a valid gpio RPIO.setup(32, RPIO.OUT) @@ -100,9 +124,9 @@ def test5_board_pin_numbers(self): for pin in pins: gpio_id = RPIO.channel_to_gpio(pin) logging.info("- BCM channel %s = gpio %s", pin, gpio_id) - with self.assertRaises(RPIO.InvalidChannelException): + with self.assertRaises(RPIO._GPIO.InvalidChannelException): gpio_id = RPIO.channel_to_gpio(32) - with self.assertRaises(RPIO.InvalidChannelException): + with self.assertRaises(RPIO._GPIO.InvalidChannelException): gpio_id = RPIO.channel_to_gpio(5) logging.info(" ") @@ -116,7 +140,7 @@ def test5_board_pin_numbers(self): continue gpio_id = RPIO.channel_to_gpio(pin) logging.info("- BOARD channel %s = gpio %s", pin, gpio_id) - with self.assertRaises(RPIO.InvalidChannelException): + with self.assertRaises(RPIO._GPIO.InvalidChannelException): gpio_id = RPIO.channel_to_gpio(0) RPIO.setmode(RPIO.BCM) @@ -182,11 +206,11 @@ def socket_client(timeout=3): # # Auto interrupt shutdown with thread and stop_waiting_for_interrupts # - logging.info(" ") + logging.info("start second ") RPIO.add_interrupt_callback(GPIO_IN, test_callback, edge='both', \ pull_up_down=RPIO.PUD_OFF) RPIO.add_interrupt_callback(GPIO_OUT, test_callback, edge='falling', \ - pull_up_down=RPIO.PUD_UP) + pull_up_down=RPIO.PUD_UP, debounce_timeout_ms=100) logging.info("- waiting 3s for interrupts on gpio %s and %s...", \ GPIO_IN, GPIO_OUT) Thread(target=stop_interrupts, args=(3,)).start() diff --git a/source/tests_pwm.py b/source/tests_pwm.py index 4439413..0b07435 100644 --- a/source/tests_pwm.py +++ b/source/tests_pwm.py @@ -1,4 +1,28 @@ #!/usr/bin/env python +# +# This file is part of RPIO. +# +# Copyright +# +# Copyright (C) 2013 Chris Hager +# +# License +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser 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 Lesser General Public License for more details at +# +# +# Documentation +# +# http://pythonhosted.org/RPIO +# """ This test suite runs on the Raspberry Pi and tests RPIO inside out. """ diff --git a/version_update.sh b/version_update.sh new file mode 100644 index 0000000..f6d5f4c --- /dev/null +++ b/version_update.sh @@ -0,0 +1,51 @@ +#! /bin/bash +# +# This script updates the version number in all necessary places +# throughout the project, and adds a new entry to debian/changelog. +# +DATE_STR=`date +"%a, %d %b %Y %H:%M:%S +0100"` +VERSION_FILES=('setup.py' 'source/RPIO/__init__.py' 'source/c_gpio/py_gpio.c' 'source/c_pwm/pwm_py.c' 'documentation/source/conf.py'); +VERSION_LAST=`head -n1 debian/changelog | awk '{print $2}' | sed "s/[()]//g"` + +if [ "$1" == "--show" ]; then + echo $VERSION_LAST + exit 0 +fi + +echo "The last version is $VERSION_LAST." +echo -n "New version number: " +read version + +if [ -e $version ]; then + exit 1 +fi + +echo -n "Are you sure you want to update the project to v$version? [y/n] " +read confirm + +if [ -e $confirm ]; then + exit 1 +fi + +echo "Updating project to v$version..." +for fn in ${VERSION_FILES[@]}; do + echo "- $fn"; + #echo $cmd + sed -i '' "s/$VERSION_LAST/$version/g" $fn +done + +# Update Changelog +echo "rpio ($version) unstable; urgency=low" > CHANGELOG.new +echo "" >> CHANGELOG.new +echo " * " >> CHANGELOG.new +echo " * " >> CHANGELOG.new +echo " * " >> CHANGELOG.new +echo "" >> CHANGELOG.new +echo " -- Chris Hager $DATE_STR" >> CHANGELOG.new +echo "" >> CHANGELOG.new +cat debian/changelog >> CHANGELOG.new +mv CHANGELOG.new debian/changelog +nano -w debian/changelog + +# Now rebuild doc for latest version +echo "Run 'make doc' now, to build documentation with the new version number" \ No newline at end of file