2 Commits
Author SHA1 Message Date
CrazyRedMachine 067e824218 awful code 2021-03-15 02:28:42 +01:00
CrazyRedMachine e4690e6070 awful code 2021-03-15 01:03:10 +01:00
18 changed files with 630 additions and 1975 deletions
-674
View File
@@ -1,674 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
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.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 <https://www.gnu.org/licenses/>.
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:
<program> Copyright (C) <year> <name of author>
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
<https://www.gnu.org/licenses/>.
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
<https://www.gnu.org/licenses/why-not-lgpl.html>.
Binary file not shown.
+2 -5
View File
@@ -2,12 +2,9 @@
#Persistent
#include AHKHID.ahk
MsgBox Sorry, this script is currently broken (I now need to get it to send a proper feature report instead of an output report)
ExitApp
hArd := HID_Open("1ccf","1000")
hArd := HID_Open("2341","003E")
while (hLED = -1) {
hArd := HID_Open("1ccf","1000")
hArd := HID_Open("2341","003E")
Sleep, 5000
}
if 0 < 1 ; The left side of a non-expression if-statement is always the name of a variable.
-2
View File
@@ -1,5 +1,3 @@
# NOTE: ModeSwitch is broken for now, fixing is low priority as long as nobody needs it, so open an issue if needed.
# ModeSwitch for the Pop'n Ultimate Controller
This is a binary meant to set the LightMode used by the Pop'n Controller. It is mostly useful for multi-boot frontends as it allows to switch to the correct mode before launching a game.
+9 -56
View File
@@ -1,8 +1,6 @@
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate?hosted_button_id=WT735CX4UMZ9U)
# Ultimate Pop'n Controller
USB HID controller with 13 inputs (9 buttons, coin, test, reset, service), 20 named outputs (18 lights, coin blocker, coin counter), 4 features (dip switches), 12-key matrix numpad, high polling rate, custom dll for full cabinet compatibility, Pop'n beMouse and Lively native compatibility, and nice programmable features.
USB HID controller with 12 buttons, 18 lights, 12-key matrix numpad, high polling rate and nice programmable features.
The goal was to replace the official IO Board from my pop'n cabinet with a DIY controller instead, for stability reasons (Konami IO boards are prone to failure, most Pop'n Music cabinets in the wild have broken lamps...) but also for QoL improvements (this allows me to use my panel system-wide and not only in-game, which means I can control a multiboot menu, play with emulators etc..).
@@ -10,18 +8,12 @@ In combination with the PN5180-cardio project, the whole IO from a Pop'n Music c
# Leonardo version
This code was originally written for Arduino Due but is also compatible with Leonardo without any change required.
Due to lack of gpio, in this case there's only 11 buttons and 9 lights, no keypad support, and reactive mode won't include AC light simulation (there's no side or top lamps, but you might want to have a look at the ambilight branch for ws2812b side/top lamps). However, there is **Playstation compatibility** as well.
Because I loved the ModeSwitch feature, I adapted the code so it could compile for Leonardo as well. Due to lack of gpio, in this case there's only 11 buttons and 9 lights, no keypad support, and reactive mode won't include AC light simulation (there's no side or top lamps, duh).
I'm also taking advantage of the Leonardo EEPROM. On manually switching, the resulting lightmode is stored in the EEPROM so that it persists on controller disconnect/reconnect.
You only need to select "Leonardo" as your board type in Arduino IDE before flashing.
# Demo
https://www.instagram.com/p/CKE9HCQFCYM/
https://www.instagram.com/p/CBWgSMklvvT/
# Acknowledgments
@@ -36,12 +28,9 @@ The keypad code uses the Keypad library by Mark Stanley and Alexander Brevig.
Switch debouncing is done with Bounce2 library by Thomas O Fredericks.
Playstation compatibility uses parts of progmem's excellent https://github.com/progmem/re-usbemani/ project
# Supported devices and requirements
This code was designed for Arduino Due. It will compile for Leonardo as well but some features are stripped due to lack of gpio (only 11 buttons and 9 lights, no keypad, lower polling rate).
Code is updated automatically depending on the selected target board, no changes are needed.
This code was designed for Arduino Due. It will compile for Leonardo as well but some features are stripped due to lack of gpio (only 11 buttons and 9 lights, no keypad). The HID descriptor is updated accordingly depending on the selected target board.
The controller code requires the Bounce2 library by Thomas O Fredericks. It can be installed from the Arduino IDE Library manager.
@@ -51,9 +40,9 @@ The keypad code requires the Keypad library by Mark Stanley and Alexander Brevig
## I/O
This controller has 13 buttons (9 buttons + coin + service + reset + test), 4 dip-switches (only DIP4 is used in cabinets to select between 15 or 31kHz monitor resolution on boot), 18 lights (9 buttons + 5 top neon + 4 side pillar), 2 coin outputs (coin blocker, coin counter).
This controller has 12 buttons (9 buttons + coin + service + test) and 18 lights (9 buttons + 5 top neon + 4 side pillar).
It also has 7 pins for the 12-key numpad, following the original cabinet pinout. It is recognized as a separate keyboard, and it is mapped to the keyboard toprow rather than the numpad (due to lack of stability when sending the numlock command to the BemaniPC).
It also has 7 pins for the 12-key numpad, following the original cabinet pinout. It is recognized as a separate keyboard, and it is mapped to the toprow rather than the numpad (due to lack of stability when sending the numlock command to the BemaniPC).
The 00 key is mapped to comma (for direct compatibility with spicetools) and the originally unused bottom right key is mapped to the default card scan key.
@@ -61,13 +50,9 @@ It also has a cool light animation on boot which you can easily adapt to your li
## ezusb driver
The I/O is HID so it can be mapped with the usual IO emulation tools, and even has named outputs for ease of use, but it can also be used just like an official IOBoard, provided you replace the original `ezusb.dll` file with the one from this repo.
The I/O is HID so it can be mapped with the usual IO emulation tools, but it can also be used without emulation, just like an official IOBoard, provided you replace the original `ezusb.dll` file with the one from this repo.
This way the firmware is fully compatible with anything that works on an official cabinet (PopnForwarder (a bit silly but why not :D), DJMame, ezPSXe pad plugin...)
## pop'n beMouse
The controller will enumerate in a way that is directly compatible with the old Pop'n beMouse software (it also directly works with Pop'n Lively).
This way the firmware is fully compatible with anything that works on an official cabinet (PopnForwarder (a bit silly but why not :D), DJMame...)
## Light modes
@@ -105,48 +90,16 @@ I included pre-compiled binaries and sources in the "ModeSwitch" folder. Refer t
# Pinout (DUE)
The Arduino DUE has 3.3v logic whereas the Pop'n Music cabinet outputs use 12V.
The Arduino DUE has 3.3v logic whereas the Pop'n Music cabinet outputs (lamps, coin blocker, coin counter) use 12V.
Therefore I'm using transistors to do level shifting (the parts I used were three ULN2003APG or TBD62003APG chips).
You can also buy pre-made level shifters such as this one https://www.tindie.com/products/ddebeer/12-channel-level-shifter-and-buffer/ (you'd need two of them since there are 20 outputs to control for a Pop'n cabinet).
Therefore I'm using transistors to do level shifting (the parts I used were three ULN2003APG or TBD62003APG chips). You can also buy pre-made level shifters such as this one https://www.tindie.com/products/ddebeer/12-channel-level-shifter-and-buffer/ (you'd need two of them since there are 20 outputs to control for a Pop'n cabinet).
Refer to ```pinout.png``` to see how it is all wired to a Pop'n Music cabinet.
![pinout](https://github.com/CrazyRedMachine/UltimatePopnController/blob/master/pinout.png?raw=true)
## Pop'n IOShield
I've also built a custom arduino shield with integrated level-shifting circuitry. This allows you to simply connect a Pop'n Music cabinet through 2 connectors present in your cab (unplug CN7 and CN8 from the power distribution board and plug them on this shield instead, then splice 12V from CN63 connector and feed it to the shield 12V in connector). You can contact me for more information.
![shield](https://github.com/CrazyRedMachine/UltimatePopnController/blob/master/shield.png?raw=true)
Demo : https://www.instagram.com/p/CKE9HCQFCYM/
# Pinout (Leonardo)
Arduino Leonardo has 5V logic therefore one can directly connect 5V leds to it.
![pinout](https://github.com/CrazyRedMachine/UltimatePopnController/blob/master/pinout_leonardo.png?raw=true)
## Playstation compatibility
Arduino Leonardo version is also compatible with Playstation and Playstation 2 (it can be made to be plugged directly to the controller port, using the following pinout).
![pinout_psx](https://github.com/CrazyRedMachine/UltimatePopnController/blob/master/pinout_leonardo_psx.png?raw=true)
For ACK (TXLED aka PD5) and SS (RXLED aka PB0) you have to solder new headers or cables directly on the leonardo PCB (or you can use an Arduino Micro (not pro micro) which has everything broken out).
LEDs will be dimmer due to 3.3v power. Using the 7V rumble motor line to Vin instead, and using NPN transistors like 2N2222A on MISO and ACK lines to prevent backfeeding voltage into the console will solve the issue (set INVERT_CIPO and INVERT_ACK to 1 in `ps2.c`).
**BEWARE: DO NOT PLUG USB AND PSX AT THE SAME TIME, THIS CAN DAMAGE YOUR CONSOLE**
# Donation
If this project helps you and you want to give back, you can help me with my future projects.
While not necessary, donations are much appreciated and will only go towards funding future github projects (arcade hardware ain't cheap :( ).
Of course you'll also receive my gratitude and I'll remember you if you post a feature request ;)
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate?hosted_button_id=WT735CX4UMZ9U)
Binary file not shown.
BIN
View File
Binary file not shown.
+3 -1
View File
@@ -14,4 +14,6 @@ The dll makes the lights turn on for 1 sec on load so you'll know if the game ma
## How to retrieve devicepath
The dll will attempt to open the device automatically based on the custom VID/PID. In case it doesn't work you can put a `devicepath.dat` file in the same folder as the dll.
The dll will attempt to open the default paths from the Due and Leonardo versions of this firmware, in case it doesn't work you can put a `devicepath.dat` file in the same folder as the dll.
See instructions from ModeSwitch to know more about the path format and how to find the one corresponding to your device.
+64 -172
View File
@@ -1,78 +1,15 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "ezusb.h"
/* TO BE COMPILED WITH VISUAL STUDIO SO THAT EXPORTS ARE PROPERLY MANGLED */
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
extern "C" {
// This file is in the Windows DDK available from Microsoft.
#include <hidsdi.h>
#include <SetupAPI.h>
}
#include <cstdint>
#include <fstream>
#include "ezusb.h"
//#define DEBUG
//#define DEBUG_LAMP
HANDLE g_hid_handle;
uint8_t g_dip_state = 0;
// GUID_DEVCLASS_HIDCLASS
static GUID hidclass_guid = {0x745a17a0, 0x74d3, 0x11d0, 0xb6, 0xfe, 0x00, 0xa0, 0xc9, 0x0f, 0x57, 0xda};
BOOLEAN get_device_path(wchar_t *lPath)
{
const GUID *guid = &hidclass_guid;
HidD_GetHidGuid(&hidclass_guid);
// Get device interface info set handle
// for all devices attached to system
HDEVINFO hDevInfo = SetupDiGetClassDevs(guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); // Function class devices.
if(hDevInfo == INVALID_HANDLE_VALUE)
return FALSE;
// Retrieve a context structure for a device interface of a device information set.
BYTE buf[1024];
PSP_DEVICE_INTERFACE_DETAIL_DATA pspdidd = (PSP_DEVICE_INTERFACE_DETAIL_DATA)buf;
SP_DEVICE_INTERFACE_DATA spdid;
SP_DEVINFO_DATA spdd;
DWORD dwSize;
spdid.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
// Iterate through all the interfaces and try to match one based on
// the device number.
DWORD device_index = 0;
for(DWORD i = 0; SetupDiEnumDeviceInterfaces(hDevInfo, NULL,guid, i, &spdid); i++)
{
// Get the device path.
dwSize = 0;
SetupDiGetDeviceInterfaceDetail(hDevInfo, &spdid, NULL, 0, &dwSize, NULL);
if(dwSize == 0 || dwSize > sizeof(buf))
continue;
pspdidd->cbSize = sizeof(*pspdidd);
ZeroMemory((PVOID)&spdd, sizeof(spdd));
spdd.cbSize = sizeof(spdd);
if(!SetupDiGetDeviceInterfaceDetail(hDevInfo, &spdid, pspdidd,
dwSize, &dwSize, &spdd))
continue;
/* check if the device contains our wanted vid/pid */
if ( wcsstr( pspdidd->DevicePath, L"vid_1ccf&pid_1000&mi_02" ) == NULL )
{
continue;
}
#ifdef DEBUG
printf("\r\nDevice found at %S\r\n", &pspdidd->DevicePath);
#endif
//copy devpath into lPath
wcscpy(lPath, pspdidd->DevicePath);
SetupDiDestroyDeviceInfoList(hDevInfo);
return TRUE;
}
SetupDiDestroyDeviceInfoList(hDevInfo);
return FALSE;
}
/**
* Initialize the g_hid_handle global variable
@@ -83,52 +20,47 @@ BOOLEAN get_device_path(wchar_t *lPath)
* @return 0 on success, -1 on error
*/
static int controller_init(){
static uint8_t err_count = 0;
wchar_t lPath[256];
char path[256];
FILE *file;
char path[256];
/* first check if there's a devicepath.dat override */
file = fopen("devicepath.dat", "r");
if (file != NULL)
if (file == NULL)
{
while ( fgets(path,256,file) != NULL )
{
path[strcspn(path, "\r\n")] = 0;
g_hid_handle = CreateFileA(path, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if ( g_hid_handle != INVALID_HANDLE_VALUE )
{
fclose(file);
return 0;
}
}
fclose(file);
goto last_resort;
}
/* auto detect device path */
if (!get_device_path(lPath))
while ( fgets(path,256,file) != NULL )
{
printf("\r\nPOPN MUSIC USB not detected.\r\n");
err_count++;
if (err_count > 2){
printf("Could not init device after multiple attempts. Exiting.\r\n");
exit(1);
}
return -1;
path[strcspn(path, "\r\n")] = 0;
g_hid_handle = CreateFile(path, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if ( g_hid_handle != INVALID_HANDLE_VALUE )
break;
}
fclose(file);
g_hid_handle = CreateFile(lPath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if ( g_hid_handle == INVALID_HANDLE_VALUE )
{
printf("Could not open detected device (err = %x).\r\n", GetLastError());
return -1;
goto last_resort;
}
return 0;
last_resort:
g_hid_handle = CreateFile("\\\\?\\HID#VID_2341&PID_003E&MI_02#7&3156e204&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}",
GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if ( g_hid_handle != INVALID_HANDLE_VALUE )
return 0;
g_hid_handle = CreateFile("\\\\?\\HID#VID_2341&PID_8036&MI_02#7&63200bf&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}",
GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if ( g_hid_handle != INVALID_HANDLE_VALUE )
return 0;
printf("Couldn't open device. Make sure devicepath.dat exists and contains the correct path.\r\n");
return -1;
}
/**
* Read buttons state from the board and convert them into Pop'n Music format
* Read buttons state from the Arduino and convert them into Pop'n Music format
*
* Pop'n Music processes button states as a uint32_t bitfield with the following format :
* bits 0 (LSB) to 5 : nothing
@@ -136,47 +68,41 @@ static int controller_init(){
* bit 7 : test
* bits 8 to 16 : buttons 1 to 9
* bit 22 : coin mech
* bits 24 to 27 : dip 1 to 4
*
* @param pad_bits[out] button state bitfield
* @return 0 on success, -1 on error
*/
static int controller_read_buttons(uint32_t *pad_bits){
DWORD bytesRead = 0;
uint8_t res[4];
unsigned char buf[6]; // gamepad report length is 3 bytes in firmware, doubled because NumInputBuffer is set to 2
DWORD BytesRead = 0;
byte res[4];
unsigned char buf[6]; // gamepad report length is 3 bytes in Arduino firmware, doubled because NumInputBuffer is set to 2
buf[0] = 0x04; // gamepad report ID is 4 in firmware
buf[0] = 0x04; // gamepad report ID is 4 in Arduino firmware
*pad_bits = 0;
ReadFile(g_hid_handle, buf, 6, &bytesRead, NULL);
// bytesRead should either be 6 (if it successfully read 2 reports) or 3 (only one)
if ( bytesRead != 6 && bytesRead != 3 )
ReadFile(g_hid_handle, buf, 6, &BytesRead, NULL);
// BytesRead should either be 6 (if it successfully read 2 reports) or 3 (only one)
if ( BytesRead != 6 && BytesRead != 3 )
{
#ifdef DEBUG
printf("HID read error (got %u bytes)\n",bytesRead);
#endif
return -1;
}
/* HID read ok, convert latest report bytes to pop'n bitfield */
res[3] = g_dip_state; // dip switches
res[2] = (buf[bytesRead-1]<<3 | buf[bytesRead-1]) & 0x41; // button 9 (0x01) and coin mech (0x40)
res[1] = buf[bytesRead-2]; // button 1 to 8
res[3] = 0;
res[2] = (buf[BytesRead-1]<<3 | buf[BytesRead-1]) & 0x41;
res[1] = buf[BytesRead-2];
res[0] = 0;
buf[bytesRead-1] >>= 1;
if ( buf[bytesRead-1]&1 ) res[0] |= 0x80; // test
buf[bytesRead-1] >>= 1;
if ( buf[bytesRead-1]&1 ) res[0] |= 0x40; // service
buf[BytesRead-1] >>= 1;
if ( buf[BytesRead-1]&1 ) res[0] |= 0x80;
buf[BytesRead-1] >>= 1;
if ( buf[BytesRead-1]&1 ) res[0] |= 0x40;
*pad_bits = *(uint32_t *)res;
#ifdef DEBUG
for (int i = 0; i<32; i++){
printf("%c",( ((uint32_t )*pad_bits>>(31-i))&1)?'1':'0');
if (((i+1)%4)==0) printf(" ");
}
printf("\n");
if (*pad_bits & 0x8000000) printf("31kHz mode\r\n");
#endif
return 0;
}
@@ -187,41 +113,30 @@ static int controller_read_buttons(uint32_t *pad_bits){
* Pop'n Music sends lights state as a int32_t bitfield with the following format :
* bits 0 (LSB) to 4 : neons from top to bottom
* bits 8 to 11 : side lamps (left blue, left red, right blue, right red)
* bits 16 to 19 : coin blocker (0x0 for on, 0xF for off)
* bits 23 to 31 : button lamps from left to right (note: technically game sets the whole 20-23 to 0xF rather than 0x8 for lamp 1)
* bits 23 to 31 : button lamps from left to right
*
* @param lamp_bits[in] lamp state bitfield
* @return 0 on success, -1 on error
*/
static int controller_write_leds(int32_t lamp_bits){
DWORD bytesWritten = 0;
uint8_t *src = (uint8_t*) &lamp_bits; //cast as uint8_t array for fast conversion
uint8_t buf[5]; // HID lights report length is 5 bytes in Arduino firmware
#ifdef DEBUG_LAMP
for (int i = 0; i<32; i++){
printf("%c",( ((uint32_t )lamp_bits>>(31-i))&1)?'1':'0');
if (((i+1)%4)==0) printf(" ");
}
printf("\n");
#endif
DWORD BytesWritten = 0;
byte *src = (byte*) &lamp_bits; //cast as byte array for fast conversion
byte buf[5]; // HID lights report length is 5 bytes in Arduino firmware
/* convert bitfield into HID Report format */
buf[4] = 0; // hid report padding
buf[3] = ((src[1]&0x0F) >> 2); // right lamps
if ( !(src[2] & 0x0F) ) buf[3] |= 0x04; // coin blocker
if ( src[1] & 0xF0 ) buf[3] |= 0x08; // coin counter?
buf[2] = (src[1] << 6) | (src[0] << 1) | (src[3] >> 7); // button 9, top and left lamps
buf[1] = (src[3] << 1) | (src[2] >> 7); // button lamps 1-8
buf[0] = 0x05; // HID lights report id
buf[4] = 0;
buf[3] = (src[1] >> 2);
buf[2] = (src[1] << 6) | (src[0] << 1) | (src[3] >> 7);
buf[1] = (src[3] << 1) | (src[2] >> 7);
buf[0] = 0x05; // HID lights report id is 5 in Arduino firmware
/* send HID Report */
WriteFile(g_hid_handle, buf, 5, &bytesWritten, NULL);
if ( bytesWritten == 5 )
WriteFile(g_hid_handle, buf, 5, &BytesWritten, NULL);
if ( BytesWritten == 5 )
return 0;
#ifdef DEBUG_LAMP
printf("Error sending HID report (%u bytes written)\r\n",bytesWritten);
#ifdef DEBUG
printf("Error sending HID report (%u bytes written)\r\n",BytesWritten);
#endif
return -1;
}
@@ -229,7 +144,7 @@ static int controller_write_leds(int32_t lamp_bits){
/* EZUSB EXPORTS */
#ifdef POPN15_FORMAT
#if POPN15_FORMAT == 1
extern "C" {
#endif
@@ -275,10 +190,7 @@ __declspec(dllexport) int __cdecl usbPadRead(unsigned long *pad_bits) {
}
__declspec(dllexport) int __cdecl usbPadReadLast(uint8_t *a1) {
/* This memset is what is being done by the usual hooks.
* However, it breaks Pop'n 15~18 compatibility and seems
* to have no effect on later Pop'n so I removed it... */
//memset(a1, 0, 40);
memset(a1, 0, 4);
return 0;
}
@@ -313,40 +225,25 @@ __declspec(dllexport) int __cdecl usbSetExtIo(int i) {
__declspec(dllexport) int __cdecl usbStart(int i) {
if (controller_init() == -1)
{
printf("Could not init device.\r\n");
printf("Could not init device.\n");
return -1;
}
BOOLEAN hidres = HidD_SetNumInputBuffers(
bool hidres = HidD_SetNumInputBuffers(
g_hid_handle,
2);
if (!hidres)
{
printf("Error %d setnuminputbuff\r\n",GetLastError());
printf("error %d setnuminputbuff\n",GetLastError());
return -1;
}
/* read dip switches */
uint8_t feat[2] = {0x06, 0x00};
if (!HidD_GetFeature(g_hid_handle, &feat, 2))
{
printf("Cannot read dipswitches (error %d)\r\n",GetLastError());
};
g_dip_state = feat[1];
#ifdef FORCE_DIP4
g_dip_state |= 0x08;
#endif
/* light everything for 1 sec to get visual confirmation
* the device is working */
controller_write_leds((uint32_t) 0xFFFFFFFF);
Sleep(1000);
controller_write_leds((uint32_t) 0x00000000);
#ifdef DEBUG
printf("Managed to open device %x\n",g_hid_handle);
printf("Dip state is %x\n", g_dip_state);
#endif
return 0;
}
@@ -362,20 +259,15 @@ __declspec(dllexport) int __cdecl usbWdtStartDone() {
return 0;
}
#ifdef POPN15_FORMAT
#if POPN15_FORMAT == 1
}
#endif
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD fdwReason,
LPVOID lpReserved
) {
int __stdcall DllMain(HINSTANCE hinstDLL, DWORD fdwReason, void *) {
if (fdwReason == 1) {
//https://blogs.msdn.microsoft.com/larryosterman/2004/06/03/little-known-win32-apis-disablethreadlibrarycalls/
DisableThreadLibraryCalls(hModule);
DisableThreadLibraryCalls(hinstDLL);
}
return 1;
}
}
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 664 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 489 KiB

After

Width:  |  Height:  |  Size: 415 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 680 KiB

+394 -512
View File
@@ -1,535 +1,417 @@
/* Arduino-HID-Lighting-Library
*
* This Arduino-HID-Lighting-Library is derived from Arduino-HID-Lighting, whose copyriht owner is mon.
* More information about Arduino-HID-Lighting you can find under:
*
* mon's Arduino-HID-Lighting
* https://github.com/mon/Arduino-HID-Lighting
*
* 2018 (C) Arduino-HID-Lighting-Library, Knuckleslee
This Arduino-HID-Lighting-Library is derived from Arduino-HID-Lighting, whose copyriht owner is mon.
More information about Arduino-HID-Lighting you can find under:
mon's Arduino-HID-Lighting
https://github.com/mon/Arduino-HID-Lighting
2018 (C) Arduino-HID-Lighting-Library, Knuckleslee
*/
#include "POPNHID.h"
byte extern LightPins[];
byte extern DipPins[];
#include <FastLED.h>
/* HID DESCRIPTOR */
static const byte PROGMEM _hidReportPOPN[] = {
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
0x09, 0x05, /* USAGE (Game Pad) */
0xa1, 0x01, /* COLLECTION (Application) */
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
0x09, 0x05, /* USAGE (Game Pad) */
0xa1, 0x01, /* COLLECTION (Application) */
/*Buttons */
0x85, 0x04, /* REPORT_ID 4 */
0x05, 0x09, /* USAGE_PAGE (Button) */
0x19, 0x01, /* USAGE_MINIMUM (Button 1) */
0x29, 0x0d, /* USAGE_MAXIMUM (Button 13)*/
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
#if defined(ARDUINO_ARCH_SAM)
0x95, 0x0d, /* REPORT_COUNT (13) */
#else
0x95, 0x0b, /* REPORT_COUNT (11) */
#endif
0x75, 0x01, /* REPORT_SIZE (1) */
0x81, 0x02, /* INPUT (Data,Var,Abs) */
/* Reserved bits */
0x95, 0x01, /* REPORT_COUNT (1) */
#if defined(ARDUINO_ARCH_SAM)
0x75, 0x03, /* REPORT_SIZE (3) */
#else
0x75, 0x05, /* REPORT_SIZE (5) */
#endif
0x81, 0x03, /* INPUT (Cnst,Var,Abs) */
/*Lights */
0x85, 0x05, /* REPORT_ID 5*/
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
/*Led 1 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x01, /* USAGE (Instance 1) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x04, /* STRING INDEX (4) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 2 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x02, /* USAGE (Instance 2) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x05,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 3 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x03, /* USAGE (Instance 3) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x06,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 4 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x04, /* USAGE (Instance 4) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x07,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 5 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x05, /* USAGE (Instance 5) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x08,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 6 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x06, /* USAGE (Instance 6) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x09,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 7 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x07, /* USAGE (Instance 7) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x0a,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 8 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x08, /* USAGE (Instance 8) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x0b,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 9 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x09, /* USAGE (Instance 9) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x0c,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
#if defined(ARDUINO_ARCH_SAM)
/*Led 10 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0a, /* USAGE (Instance 10) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x0d,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 11 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0b, /* USAGE (Instance 11) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x0e,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 12 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0c, /* USAGE (Instance 12) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x0f,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 13 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0d, /* USAGE (Instance 13) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x10,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 14 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0e, /* USAGE (Instance 14) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x11,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 15 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0f, /* USAGE (Instance 15) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x12,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 16 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x10, /* USAGE (Instance 16) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x13,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 17 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x11, /* USAGE (Instance 17) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x14,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 18 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x12, /* USAGE (Instance 18) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x15,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/* Coin blocker */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x13, /* USAGE (Instance 19) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x16,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/* Coin counter */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x14, /* USAGE (Instance 20) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x79, 0x17,
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/* Reserved 12 bits */
0x95, 0x01, /* REPORT_COUNT (1) */
0x75, 0x0C, /* REPORT_SIZE (12) */
0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */
#else
/* Reserved 23 bits */
0x95, 0x01, /* REPORT_COUNT (1) */
0x75, 0x17, /* REPORT_SIZE (23) */
0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */
#endif
/*Buttons */
0x85, 0x04, /* REPORT_ID 4 */
0x05, 0x09, /* USAGE_PAGE (Button) */
0x19, 0x01, /* USAGE_MINIMUM (Button 1) */
0x29, 0x0c, /* USAGE_MAXIMUM (Button 12)*/
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x95, 0x0c, /* REPORT_COUNT (12) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x81, 0x02, /* INPUT (Data,Var,Abs) */
/* Reserved bits */
0x95, 0x01, /* REPORT_COUNT (1) */
0x75, 0x04, /* REPORT_SIZE (4) */
0x81, 0x03, /* INPUT (Cnst,Var,Abs) */
#if defined(ARDUINO_ARCH_SAM)
/*Dip switches*/
0x85, 0x06, /* REPORT_ID 6 */
0x05, 0x09, /* USAGE_PAGE (Button) */
0x19, 0x01, /* USAGE_MINIMUM (Button 1) */
0x29, 0x04, /* USAGE_MAXIMUM (Button 4)*/
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x95, 0x04, /* REPORT_COUNT (4) */
0x75, 0x01, /* REPORT_SIZE (1) */
0xb1, 0x02, /* FEATURE (Data,Var,Abs) */
/* Reserved bits */
0x95, 0x01, /* REPORT_COUNT (1) */
0x75, 0x04, /* REPORT_SIZE (4) */
0xb1, 0x03, /* FEATURE (Cnst,Var,Abs) */
#endif
/*Light mode switch*/
0x85, 0x07, /* REPORT_ID 7 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x19, 0x00, /* USAGE_MINIMUM (Button 1) */
0x29, 0x04, /* USAGE_MAXIMUM (Button 4)*/
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x04, /* LOGICAL_MAXIMUM (4) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x75, 0x04, /* REPORT_SIZE (4) */
0xb1, 0x02, /* FEATURE (Data,Var,Abs) */
/* Reserved bits */
0x95, 0x01, /* REPORT_COUNT (1) */
0x75, 0x04, /* REPORT_SIZE (4) */
0xb1, 0x03, /* FEATURE (Cnst,Var,Abs) */
/*Footer */
0xc0 /* END_COLLECTION */
/*Lights */
0x85, 0x05, /* REPORT_ID 5*/
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
/*Led 1 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x01, /* USAGE (Instance 1) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 2 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x02, /* USAGE (Instance 2) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 3 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x03, /* USAGE (Instance 3) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 4 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x04, /* USAGE (Instance 4) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 5 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x05, /* USAGE (Instance 5) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 6 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x06, /* USAGE (Instance 6) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 7 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x07, /* USAGE (Instance 7) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 8 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x08, /* USAGE (Instance 8) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 9 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x09, /* USAGE (Instance 9) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 10 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0a, /* USAGE (Instance 10) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 11 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0b, /* USAGE (Instance 11) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 12 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0c, /* USAGE (Instance 12) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 13 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0d, /* USAGE (Instance 13) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 14 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0e, /* USAGE (Instance 14) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 15 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x0f, /* USAGE (Instance 15) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 16 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x10, /* USAGE (Instance 16) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 17 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x11, /* USAGE (Instance 17) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/*Led 18 */
0x05, 0x0a, /* USAGE_PAGE (Ordinals) */
0x09, 0x12, /* USAGE (Instance 18) */
0xa1, 0x02, /* COLLECTION (Logical) */
0x05, 0x08, /* USAGE_PAGE (LEDs) */
0x09, 0x4b, /* USAGE (Generic Indicator 1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x95, 0x01, /* REPORT_COUNT (1) */
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
0xc0, /* END_COLLECTION */
/* Reserved 14 bits */
0x95, 0x01, /* REPORT_COUNT (1) */
0x75, 0x0E, /* REPORT_SIZE (14) */
0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */
/*Footer */
0xc0 /* END_COLLECTION */
};
static bool SendControl(uint8_t d)
{
return USB_SendControl(0, &d, 1) == 1;
}
static bool USB_SendStringDescriptor(const char *string_P, uint8_t string_len, uint8_t flags) {
SendControl(2 + string_len * 2);
SendControl(3);
bool pgm = flags & TRANSFER_PGM;
for(uint8_t i = 0; i < string_len; i++) {
bool r = SendControl(pgm ? pgm_read_byte(&string_P[i]) : string_P[i]);
r &= SendControl(0); // high byte
if(!r) {
return false;
}
}
return true;
}
/* HID Light descriptor strings */
const char* const PROGMEM String_Manufacturer = "CrazyRedMachine";
const char* const PROGMEM String_Product = "Pop'n controller";
const char* const PROGMEM String_Serial = "POPNHID";
const char* const PROGMEM LEDString_00 = "Button 1";
const char* const PROGMEM LEDString_01 = "Button 2";
const char* const PROGMEM LEDString_02 = "Button 3";
const char* const PROGMEM LEDString_03 = "Button 4";
const char* const PROGMEM LEDString_04 = "Button 5";
const char* const PROGMEM LEDString_05 = "Button 6";
const char* const PROGMEM LEDString_06 = "Button 7";
const char* const PROGMEM LEDString_07 = "Button 8";
const char* const PROGMEM LEDString_08 = "Button 9";
const char* const PROGMEM LEDString_09 = "Hi Lamp 1";
const char* const PROGMEM LEDString_10 = "Hi Lamp 2";
const char* const PROGMEM LEDString_11 = "Hi Lamp 3";
const char* const PROGMEM LEDString_12 = "Hi Lamp 4";
const char* const PROGMEM LEDString_13 = "Hi Lamp 5";
const char* const PROGMEM LEDString_14 = "Left Lamp 1";
const char* const PROGMEM LEDString_15 = "Left Lamp 2";
const char* const PROGMEM LEDString_16 = "Right Lamp 1";
const char* const PROGMEM LEDString_17 = "Right Lamp 2";
const char* const PROGMEM BlockerString = "Coin blocker";
const char* const PROGMEM CounterString = "Coin counter";
const char* LEDString_indiv[] = {LEDString_00,LEDString_01,LEDString_02,LEDString_03,LEDString_04,LEDString_05,LEDString_06,LEDString_07,LEDString_08,LEDString_09,LEDString_10,LEDString_11,LEDString_12,LEDString_13,LEDString_14,LEDString_15,LEDString_16,LEDString_17,BlockerString,CounterString};
#if defined(ARDUINO_ARCH_SAM)
uint8_t STRING_ID_LED_Count = 20;
#else
uint8_t STRING_ID_LED_Count = 9;
#endif
const DeviceDescriptor PROGMEM USB_DeviceDescriptorIAD =
D_DEVICE(0xEF,0x02,0x01,64,0x1ccf,0x1000,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1);
/* PluggableUSBModule IMPLEMENTATION */
POPNHID_::POPNHID_(void) : PluggableUSBModule(1, 1, epType) {
epType[0] = EP_TYPE_INTERRUPT_IN;
PluggableUSB().plug(this);
}
POPNHID_::POPNHID_(void) : PluggableUSBModule(1, 1, epType) {
epType[0] = EP_TYPE_INTERRUPT_IN;
PluggableUSB().plug(this);
}
int POPNHID_::getInterface(byte* interfaceCount) {
*interfaceCount += 1; // uses 1
HIDDescriptor hidInterface = {
D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
D_HIDREPORT(sizeof(_hidReportPOPN)),
D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, USB_EP_BINTERVAL)
};
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
}
int POPNHID_::getDescriptor(USBSetup& setup)
{
if(setup.wValueH == USB_DEVICE_DESCRIPTOR_TYPE) {
return USB_SendControl(TRANSFER_PGM, (const uint8_t*)&USB_DeviceDescriptorIAD, sizeof(USB_DeviceDescriptorIAD));
}
if(setup.wValueH == USB_STRING_DESCRIPTOR_TYPE) {
if (setup.wValueL == IPRODUCT) {
return USB_SendStringDescriptor(String_Product, strlen(String_Product), 0);
}
else if (setup.wValueL == IMANUFACTURER) {
return USB_SendStringDescriptor(String_Manufacturer, strlen(String_Manufacturer), 0);
}
else if (setup.wValueL == ISERIAL) {
return USB_SendStringDescriptor(String_Serial, strlen(String_Serial), 0);
}
else if(setup.wValueL >= STRING_ID_LED_Base && setup.wValueL < (STRING_ID_LED_Base + STRING_ID_LED_Count)) {
return USB_SendStringDescriptor(LEDString_indiv[setup.wValueL - STRING_ID_LED_Base], strlen(LEDString_indiv[setup.wValueL - STRING_ID_LED_Base]), 0);
}
}
// Check if this is a HID Class Descriptor request
if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; }
if (setup.wValueH != HID_REPORT_DESCRIPTOR_TYPE) { return 0; }
int POPNHID_::getInterface(byte* interfaceCount) {
*interfaceCount += 1; // uses 1
HIDDescriptor hidInterface = {
D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
D_HIDREPORT(sizeof(_hidReportPOPN)),
D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) // this last parameter is the bInterval (requested polling rate)
};
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
}
// In a HID Class Descriptor wIndex contains the interface number
if (setup.wIndex != pluggedInterface) { return 0; }
int POPNHID_::getDescriptor(USBSetup& setup)
{
// Check if this is a HID Class Descriptor request
if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) {
return 0;
}
if (setup.wValueH != HID_REPORT_DESCRIPTOR_TYPE) {
return 0;
}
return USB_SendControl(TRANSFER_PGM, _hidReportPOPN, sizeof(_hidReportPOPN));
}
bool POPNHID_::setup(USBSetup& setup)
{
if (pluggedInterface != setup.wIndex) {
return false;
}
// In a HID Class Descriptor wIndex contains the interface number
if (setup.wIndex != pluggedInterface) {
return 0;
}
byte request = setup.bRequest;
byte requestType = setup.bmRequestType;
return USB_SendControl(TRANSFER_PGM, _hidReportPOPN, sizeof(_hidReportPOPN));
}
if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE)
{
#if defined(ARDUINO_ARCH_SAM)
/* dip switches */
if (setup.wValueH == HID_REPORT_TYPE_FEATURE && setup.wValueL == 6) {
uint8_t dip_data[2] = {6,0x00};
for(int i=0; i<4; i++)
{
if (digitalRead(DipPins[i]) == LOW)
{
dip_data[1] |= 1<<i;
}
}
USB_SendControl(0, &dip_data, 2);
return true;
}
#endif
/* lightmode info */
if (setup.wValueH == HID_REPORT_TYPE_FEATURE && setup.wValueL == 7) {
uint8_t lm_data[2] = {7,0x00};
lm_data[1] = lightMode;
USB_SendControl(0, &lm_data, 2);
return true;
}
bool POPNHID_::setup(USBSetup& setup)
{
if (pluggedInterface != setup.wIndex) {
return false;
}
byte request = setup.bRequest;
byte requestType = setup.bmRequestType;
if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE)
{
return true;
}
if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE) {
if (request == HID_SET_REPORT) {
if (setup.wValueH == HID_REPORT_TYPE_OUTPUT && setup.wLength == 5) {
lastHidUpdate = millis();
USB_RecvControl(led_data, 5);
return true;
}
if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE) {
if (request == HID_SET_REPORT) {
if(setup.wValueH == HID_REPORT_TYPE_OUTPUT && setup.wLength == 5){
lastHidUpdate = millis();
USB_RecvControl(led_data, 5);
return true;
}
else if (setup.wValueH == HID_REPORT_TYPE_FEATURE ) {
/* lightmode switch */
byte usb_data[5];
USB_RecvControl(usb_data, setup.wLength);
if (usb_data[0] == 7)
{
mode_data = usb_data[1];
return true;
}
}
}
}
return false;
}
}
return false;
}
uint8_t POPNHID_::getShortName(char *name)
{
name[0] = 'P';
name[1] = 'O';
name[2] = 'P';
name[3] = 'N';
return 4;
}
/* CUSTOM POPN FUNCTIONS */
uint8_t POPNHID_::getLightMode(){
return lightMode;
}
unsigned long POPNHID_::getLastHidUpdate(){
return lastHidUpdate;
}
uint8_t POPNHID_::setLightMode(uint8_t mode){
uint8_t effective_mode = mode;
if ((effective_mode > 4)) {
effective_mode = 2;
}
lightMode = effective_mode;
mode_data = lightMode;
return lightMode;
}
void POPNHID_::updateLightMode(){
uint8_t mode = mode_data;
if (mode != lightMode) {
mode_data = setLightMode(mode);
}
}
void POPNHID_::updateLeds(uint32_t buttonsState, bool invert){
uint32_t* bitfield = (uint32_t*)&(led_data[1]);
uint32_t leds = (*bitfield|buttonsState);
if (invert)
leds = ~leds;
for(int i = 0; i < 9; i++) {
if (leds>>i&1)
digitalWrite(LightPins[i],HIGH);
else
digitalWrite(LightPins[i],LOW);
}
#if defined(ARDUINO_ARCH_SAM)
for(int i = 9; i < 20; i++) {
if (leds>>i&1)
digitalWrite(LightPins[i],HIGH);
else
digitalWrite(LightPins[i],LOW);
}
#endif
}
int POPNHID_::sendState(uint32_t buttonsState){
uint8_t data[3];
data[0] = (uint8_t) 4; //report id
data[1] = (uint8_t) (buttonsState & 0xFF);
data[2] = (uint8_t) (buttonsState >> 8) & 0xFF;
return USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, 3);
uint8_t POPNHID_::getLightMode() {
return lightMode;
}
unsigned long POPNHID_::getLastHidUpdate() {
return lastHidUpdate;
}
void POPNHID_::setLightMode(uint8_t mode) {
if ((mode > 4) || (mode < 0)) {
lightMode = 2;
return;
}
lightMode = mode;
}
void POPNHID_::updateLightMode() {
uint32_t* bitfield = (uint32_t*) & (led_data[1]);
if (*bitfield >> 28 & 1) {
uint8_t mode = (*bitfield >> 24) & 0x0F;
setLightMode(mode);
*bitfield &= ~((uint32_t)0xFF << 24);
}
}
#define BUT_LED_PIN A0
#define BUT_NUM_LEDS 9
#define LEFT_LED_PIN 8
#define LEFT_NUM_LEDS 9
#define RIGHT_LED_PIN 9
#define RIGHT_NUM_LEDS 9
CRGB extern but_leds[];
CRGB extern left_leds[];
CRGB extern right_leds[];
CRGB extern but_led_colors[];
byte extern lightOrder[];
byte extern NeonPins[];
#define PILLAR_BRIGHTNESS 64
#define BUTTON_BRIGHTNESS 220
uint16_t popnhid_convert_order(uint16_t lightDesc) {
uint16_t res = 0;
for (int i = 0; i < BUT_NUM_LEDS; i++) {
if ((lightDesc >> i) & 1) {
res |= 1 << (lightOrder[i]);
}
}
return res;
}
/* Light up button lights according to bitfield */
void popnhid_but_lights(uint16_t lightDesc) {
static uint16_t prev = 0;
if (lightDesc == prev) return;
prev = lightDesc;
//conversion de lightDesc
lightDesc = popnhid_convert_order(lightDesc);
//allumage
for (int i = 0; i < BUT_NUM_LEDS; i++) {
if ((lightDesc >> i) & 1) {
but_leds[i] = but_led_colors[i];
} else {
but_leds[i] = 0;
}
}
FastLED.show();
}
/* Light up pillars and top neons according to bitfield */
void popnhid_neon_lights(uint16_t lightDesc) {
static uint16_t prev = 0;
if (lightDesc == prev) return;
prev = lightDesc;
//Top-Lamp
for (int i = 0; i < 5; i++) {
if ((lightDesc >> i) & 1) {
digitalWrite(NeonPins[i], HIGH);
} else {
digitalWrite(NeonPins[i], LOW);
}
}
//LEFT
CRGB left_color = 0;
if ((lightDesc >> 5) & 1) left_color.b += PILLAR_BRIGHTNESS;
if ((lightDesc >> 6) & 1) left_color.r += PILLAR_BRIGHTNESS;
for (int i = 1; i < 8; i++) {
left_leds[i] = left_color;
}
//RIGHT
CRGB right_color = 0;
if ((lightDesc >> 7) & 1) right_color.b += PILLAR_BRIGHTNESS;
if ((lightDesc >> 8) & 1) right_color.r += PILLAR_BRIGHTNESS;
for (int i = 1; i < 8; i++) {
right_leds[i] = right_color;
}
FastLED.show();
}
void POPNHID_::updateLeds(uint32_t buttonsState, bool invert) {
uint32_t* bitfield = (uint32_t*) & (led_data[1]);
uint32_t leds = (*bitfield | buttonsState);
if (invert)
leds = ~leds;
//ici on allume les boutons
popnhid_but_lights((uint16_t) leds);
popnhid_neon_lights(leds >> 9);
}
int POPNHID_::sendState(uint32_t buttonsState) {
uint8_t data[3];
data[0] = (uint8_t) 4; //report id
data[1] = (uint8_t) (buttonsState & 0xFF);
data[2] = (uint8_t) (buttonsState >> 8) & 0xFF;
return USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, 3);
}
+24 -50
View File
@@ -1,68 +1,42 @@
#include "HID.h"
#include <HID.h>
#define USB_EP_BINTERVAL 1
#if defined(ARDUINO_ARCH_AVR)
#define EPTYPE_DESCRIPTOR_SIZE uint8_t
#elif defined(ARDUINO_ARCH_SAM)
#define EPTYPE_DESCRIPTOR_SIZE uint32_t
#define USB_EP_SIZE 64
#define TRANSFER_PGM 0x80
#define USB_SendControl USBD_SendControl
#define USB_RecvControl USBD_RecvControl
#define USB_Recv USBD_Recv
#define USB_Send USBD_Send
#define USB_Flush USBD_Flush
#define HID_REPORT_TYPE_INPUT 1
#define HID_REPORT_TYPE_OUTPUT 2
#define HID_REPORT_TYPE_FEATURE 3
#else
#error "Unsupported architecture"
#endif
#define STRING_ID_LED_Base 4
#define EPTYPE_DESCRIPTOR_SIZE uint8_t
class POPNHID_ : public PluggableUSBModule {
public:
POPNHID_(void);
/**
* Updates the led status based on led_data (HID report received) and button states
* param[in] buttonState bitfield with currently pressed buttons (used to force additional lights for mixed mode)
* param[in] invert set to true to invert on/off status (used for invert lightmode)
*/
Updates the led status based on led_data (HID report received) and button states
param[in] buttonState bitfield with currently pressed buttons (used to force additional lights for mixed mode)
param[in] invert set to true to invert on/off status (used for invert lightmode)
*/
void updateLeds(uint32_t buttonsState, bool invert);
/**
* Sends the gamepad button states to the PC as an HID report
* param[in] buttonsState bitfield with currently pressed buttons
* return USB_Send() return value
*/
Sends the gamepad button states to the PC as an HID report
param[in] buttonsState bitfield with currently pressed buttons
return USB_Send() return value
*/
int sendState(uint32_t buttonsState);
/**
* Changes the lightMode if a received HID report asks for it
*/
Changes the lightMode if a received HID report asks for it
*/
void updateLightMode();
/**
* getter and setter for lightMode protected field.
*/
getter and setter for lightMode protected field.
*/
uint8_t getLightMode();
uint8_t setLightMode(uint8_t mode);
void setLightMode(uint8_t mode);
/**
* getter for lastHidUpdate protected field.
*/
getter for lastHidUpdate protected field.
*/
unsigned long getLastHidUpdate();
protected:
/* current lightMode (0 = reactive, 1 = HID only, 2 = mixed (HID+reactive auto-switch), 3 = combined (HID+button presses), 4 = combined invert) */
uint8_t lightMode = 2;
@@ -70,15 +44,15 @@ class POPNHID_ : public PluggableUSBModule {
unsigned long lastHidUpdate = 0;
/* byte array to receive HID reports from the PC */
byte led_data[5];
byte mode_data;
/* Implementation of the PUSBListNode */
EPTYPE_DESCRIPTOR_SIZE epType[1];
uint8_t protocol;
uint8_t idle;
uint8_t idle;
int getInterface(uint8_t* interfaceCount);
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);
uint8_t getShortName(char *name);
};
extern POPNHID_ POPNHID;
+134 -216
View File
@@ -1,135 +1,61 @@
#define BOUNCE_WITH_PROMPT_DETECTION
#include <Bounce2.h>
#if defined(ARDUINO_ARCH_SAM)
#include <Keypad.h>
#include <Keyboard.h>
#else
#include <EEPROM.h>
#define WITH_PSX 0 //enable PSX compatibility
#if WITH_PSX == 1
#include "ps2.h"
#endif
#endif
#include <FastLED.h>
#include "POPNHID.h"
#if defined(ARDUINO_ARCH_SAM)
/* 1 frame (as declared in POPNHID.cpp) on highspeed USB spec is 125µs */
#define REPORT_DELAY 120
#else
/* 1 frame (as declared in POPNHID.cpp) on fullspeed USB spec is 1ms */
#define REPORT_DELAY 995
#endif
#define MILLIDEBOUNCE 5
#define REPORT_DELAY 1000
#define MILLIDEBOUNCE 15
POPNHID_ POPNHID;
/* Buttons + Lights declarations */
#if defined(ARDUINO_ARCH_SAM)
byte LightPins[] = {A7, CANTX, A8, A9, CANRX, A10, DAC1, A11, DAC0, 14, 15, 16, 17, 18, A6, A5, A4, A3, 19, 20};
byte ButtonPins[] = {5, 4, 3, 2, 1, 6, 7, 8, 9, 11, 13, 10, 12};
byte DipPins[] = {22, 24, 26, 28};
#else
uint8_t LightPins[] = {11,12,13,23,22,21,20,19,18};
uint8_t ButtonPins[] = {0,1,2,3,4,5,6,7,8,9,10};
#endif
#define BUT_LED_PIN A0
#define BUT_NUM_LEDS 9
#define LEFT_LED_PIN 8
#define LEFT_NUM_LEDS 9
#define RIGHT_LED_PIN 9
#define RIGHT_NUM_LEDS 9
CRGB but_leds[BUT_NUM_LEDS];
CRGB left_leds[LEFT_NUM_LEDS];
CRGB right_leds[RIGHT_NUM_LEDS];
CRGB but_led_colors[BUT_NUM_LEDS] = {CRGB::White, CRGB::Green, CRGB::Red, CRGB::Green, CRGB::White, CRGB::Yellow, CRGB::Blue, CRGB::Blue, CRGB::Yellow};
#define PILLAR_BRIGHTNESS 64
#define BUTTON_BRIGHTNESS 220
uint8_t NeonPins[] = {A1, A2, A3, A4, A5};
uint8_t ButtonPins[] = {0, 1, 2, 3, 4, 5, 6, 7, 11, 12, 13};
uint8_t sysPin = 12;
//this array contains the light offset given buttons 0 to 8 as ref
uint8_t lightOrder[] = {0, 8, 1, 7, 2, 6, 3, 5, 4};
const byte ButtonCount = sizeof(ButtonPins) / sizeof(ButtonPins[0]);
const byte LightCount = sizeof(LightPins) / sizeof(LightPins[0]);
const byte NeonCount = sizeof(NeonPins) / sizeof(NeonPins[0]);
Bounce buttons[ButtonCount];
uint16_t buttonsState = 0;
#if defined(ARDUINO_ARCH_SAM)
/* Keypad declarations */
const byte ROWS = 4;
const byte COLS = 3;
/*
// To use the keypad as the numpad keys (will require to send numlock for it to work)
char numpad[ROWS][COLS] = {
{'\347', '\350', '\351'},
{'\344', '\345', '\346'},
{'\341', '\342', '\343'},
{'\352', ',', '\337'}
};
*/
/* This is to use the toprow keys instead */
char numpad[ROWS][COLS] = {
{'7', '8', '9'},
{'4', '5', '6'},
{'1', '2', '3'},
{'0', ',', '\337'}
};
/* This follows the Pop'n Music cabinet numpad pins order */
//byte rowPins[ROWS] = {46, 44, 42, 40}; //connect to the row pinouts of the keypad
//byte colPins[COLS] = {48, 50, 52}; //connect to the column pinouts of the keypad
/* For mini keypad
*/
byte rowPins[ROWS] = {50, 40, 42, 46}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {48, 52, 44}; //connect to the column pinouts of the keypad
Keypad kpd = Keypad( makeKeymap(numpad), rowPins, colPins, ROWS, COLS );
#endif
/* SETUP */
void setup() {
// setup I/O for pins
for (int i = 0; i < ButtonCount; i++) {
buttons[i] = Bounce();
buttons[i].attach(ButtonPins[i], INPUT_PULLUP);
buttons[i].interval(MILLIDEBOUNCE);
buttons[i] = Bounce();
buttons[i].attach(ButtonPins[i], INPUT_PULLUP);
buttons[i].interval(MILLIDEBOUNCE);
}
for (int i = 0; i < LightCount; i++) {
pinMode(LightPins[i], OUTPUT);
for (int i = 0; i < NeonCount; i++) {
pinMode(NeonPins[i], OUTPUT);
}
#if defined(ARDUINO_ARCH_SAM)
for (int i = 0; i < 4; i++) {
pinMode(DipPins[i], INPUT_PULLUP);
}
kpd.setDebounceTime(30);
Keyboard.begin();
/* activate numlock if you are not using the toprow keys */
/* delay(2000);
Keyboard.press(136 + 83);
delay(500);
Keyboard.release(136+83);
*/
POPNHID.setLightMode(2);
#else
FastLED.addLeds<WS2812, BUT_LED_PIN, GRB>(but_leds, BUT_NUM_LEDS);
FastLED.addLeds<WS2812, LEFT_LED_PIN, GRB>(left_leds, LEFT_NUM_LEDS);
FastLED.addLeds<WS2812, RIGHT_LED_PIN, GRB>(right_leds, RIGHT_NUM_LEDS);
FastLED.setBrightness( BUTTON_BRIGHTNESS );
uint8_t lightMode;
EEPROM.get(0, lightMode);
if (lightMode > 4)
if (lightMode < 0 || lightMode > 3)
lightMode = 2;
POPNHID.setLightMode(lightMode);
#if WITH_PSX == 1
PS2_MapInput(&buttonsState, (1<<0), PS2_TRIANGLE);
PS2_MapInput(&buttonsState, (1<<1), PS2_CIRCLE);
PS2_MapInput(&buttonsState, (1<<2), PS2_R1);
PS2_MapInput(&buttonsState, (1<<3), PS2_CROSS);
PS2_MapInput(&buttonsState, (1<<4), PS2_L1);
PS2_MapInput(&buttonsState, (1<<5), PS2_SQUARE);
PS2_MapInput(&buttonsState, (1<<6), PS2_R2);
PS2_MapInput(&buttonsState, (1<<7), PS2_UP);
PS2_MapInput(&buttonsState, (1<<8), PS2_L2);
PS2_MapInput(&buttonsState, (1<<9), PS2_SELECT);
PS2_MapInput(&buttonsState, (1<<10), PS2_START);
PS2_AlwaysInput(PS2_LEFT|PS2_DOWN|PS2_RIGHT);
PS2_Init();
#endif
#endif
//boot animation
uint16_t anim[] = {1, 4, 16, 64, 256, 128, 32, 8, 2};
animate(anim, 9, 100);
@@ -141,55 +67,47 @@ void setup() {
/* LOOP */
unsigned long lastReport = 0;
uint16_t prevButtonsState = 0;
uint32_t prevButtonsState = 0;
bool modeChanged = false;
void loop() {
/* BUTTONS */
buttonsState = 0;
uint32_t buttonsState = 0;
for (int i = 0; i < ButtonCount; i++) {
buttons[i].update();
int value = buttons[i].read();
if (value != HIGH){
buttonsState |= (uint16_t)1 << i;
buttons[i].update();
int value = buttons[i].read();
if (value != HIGH) {
buttonsState |= (uint32_t)1 << i;
} else {
buttonsState &= ~((uint16_t)1 << i);
buttonsState &= ~((uint32_t)1 << i);
}
}
#if defined(ARDUINO_ARCH_AVR)
#if WITH_PSX == 1
PS2_Task();
#endif
#endif
/* USB DATA */
if ( ( (micros() - lastReport) >= REPORT_DELAY) )
{
POPNHID.sendState(buttonsState);
lastReport = micros();
prevButtonsState = buttonsState;
prevButtonsState = buttonsState;
//check for HID-requested lightmode change
POPNHID.updateLightMode();
}
/* LAMPS */
uint8_t mode = POPNHID.getLightMode();
/* mixed mode will behave sometimes like HID, sometimes like reactive */
if (mode == 2){
if ((millis()-POPNHID.getLastHidUpdate()) > 3000)
mode = 0;
else
mode = 1;
if (mode == 2) {
if ((millis() - POPNHID.getLastHidUpdate()) > 3000)
mode = 0;
else
mode = 1;
}
switch (mode)
{
/* Reactive mode, locally determined lamp data */
case 0:
but_lights(buttonsState & 0x1ff);
#if defined(ARDUINO_ARCH_SAM)
reactive_neon(buttonsState & 0x1ff);
#endif
break;
/* HID mode, only based on received HID data */
case 1:
@@ -206,46 +124,17 @@ void loop() {
default:
break;
}
#if defined(ARDUINO_ARCH_SAM)
/* KEYPAD */
if (kpd.getKeys())
{
for (int i = 0; i < LIST_MAX; i++) // Scan the whole key list.
{
if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
{
switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
Keyboard.press(kpd.key[i].kchar);
break;
case HOLD:
break;
case RELEASED:
Keyboard.release(kpd.key[i].kchar);
break;
case IDLE:
break;
}
}
}
}
#endif
/* MANUAL LIGHTMODE UPDATE */
if ( buttonsState & 1024 ) {
if ( (buttonsState & 2) && (modeChanged == false)) {
modeChanged = true;
uint8_t mode = POPNHID.getLightMode()+1;
uint8_t mode = POPNHID.getLightMode() + 1;
if (mode > 4) mode = 0;
POPNHID.setLightMode(mode);
#if defined(ARDUINO_ARCH_AVR)
EEPROM.put(0, mode);
#endif
}
else if (!(buttonsState&2)) {
else if (!(buttonsState & 2)) {
modeChanged = false;
}
}
@@ -253,40 +142,59 @@ void loop() {
/* Light up button lights according to bitfield */
void but_lights(uint16_t lightDesc) {
for (int i = 0; i < 9; i++) {
//conversion de lightDesc
lightDesc = convert_order(lightDesc);
//allumage
for (int i = 0; i < BUT_NUM_LEDS; i++) {
if ((lightDesc >> i) & 1) {
digitalWrite(LightPins[i], HIGH);
} else {
digitalWrite(LightPins[i], LOW);
but_leds[i] = but_led_colors[i];
} else {
but_leds[i] = 0;
}
}
FastLED.show();
}
/* Light up pillars and top neons according to bitfield */
void neon_lights(uint16_t lightDesc) {
for (int i = 0; i < 9; i++) {
//Top-Lamp
for (int i = 0; i < NeonCount; i++) {
if ((lightDesc >> i) & 1) {
digitalWrite(LightPins[i + 9], HIGH);
digitalWrite(NeonPins[i], HIGH);
} else {
digitalWrite(LightPins[i + 9], LOW);
digitalWrite(NeonPins[i], LOW);
}
}
//LEFT
CRGB left_color = 0;
if ((lightDesc >> 5) & 1) left_color.b += PILLAR_BRIGHTNESS;
if ((lightDesc >> 6) & 1) left_color.r += PILLAR_BRIGHTNESS;
for (int i = 1; i < 8; i++) {
left_leds[i] = left_color;
}
//RIGHT
CRGB right_color = 0;
if ((lightDesc >> 7) & 1) right_color.b += PILLAR_BRIGHTNESS;
if ((lightDesc >> 8) & 1) right_color.r += PILLAR_BRIGHTNESS;
for (int i = 1; i < 8; i++) {
right_leds[i] = right_color;
}
FastLED.show();
}
/* Display animation on the cab according to a bitfield array */
void animate(uint16_t* tab, uint8_t n, int mswait) {
for (int i = 0; i < n; i++) {
but_lights(tab[i]);
#if defined(ARDUINO_ARCH_SAM)
neon_lights(tab[i]);
#endif
delay(mswait);
}
}
/* ARDUINO DUE ONLY FUNCTIONS */
#if defined(ARDUINO_ARCH_SAM)
/* Manage pillars and top neons in reactive mode */
uint16_t neon_anim[] = {16, 24, 28, 30, 31, 30, 28, 24};
int neon_anim_index = 0;
@@ -302,63 +210,63 @@ unsigned long neonRate = 200;
void reactive_neon(uint16_t buttonsState) {
uint16_t neons = 0;
unsigned long currTime = millis();
/*
* SIDE PILLARS
* When pressing any button the side pillars will blink for half a second
* The color is randomly chosen with blue being predominant, red rare and purple super rare
*/
SIDE PILLARS
When pressing any button the side pillars will blink for half a second
The color is randomly chosen with blue being predominant, red rare and purple super rare
*/
if ( buttonsState != prevState )
{
if ( buttonsState != 0 ){
long randNumber = random(21);
if (randNumber == 0)
{
pillar_state_index = 3;
if ( buttonsState != 0 ) {
long randNumber = random(21);
if (randNumber == 0)
{
pillar_state_index = 3;
}
else if (randNumber < 3)
{
pillar_state_index = 1;
} else {
pillar_state_index = 2;
}
pillar_lit = true;
if (buttonsState != 0) lastButtonAction = currTime;
}
else if (randNumber < 3)
{
pillar_state_index = 1;
} else {
pillar_state_index = 2;
}
pillar_lit = true;
if (buttonsState != 0) lastButtonAction = currTime;
}
prevState = buttonsState;
} else { /* no state change, continue to blink for 50ms */
if (currTime - lastBlink > 50) {
prevState = buttonsState;
} else { /* no state change, continue to blink for 50ms */
if (currTime - lastBlink > 50) {
pillar_lit = !pillar_lit;
lastBlink = currTime;
}
if (currTime - lastButtonAction > 500) {
if (currTime - lastButtonAction > 500) {
pillar_state_index = 0;
}
}
}
if (pillar_lit)
neons |= pillar_state[pillar_state_index];
if (pillar_lit)
neons |= pillar_state[pillar_state_index];
/*
* Adjusting top neon animation speed (should go faster when you hit buttons quickly)
*/
actionRate = currTime - lastButtonAction;
if (15*actionRate < neonRate)
Adjusting top neon animation speed (should go faster when you hit buttons quickly)
*/
actionRate = currTime - lastButtonAction;
if (15 * actionRate < neonRate)
neonRate *= 0.99995;
else if (actionRate > 10*neonRate){
neonRate = neonRate*1.01;
else if (actionRate > 10 * neonRate) {
neonRate = neonRate * 1.01;
if (neonRate < 100) neonRate++;
}
if (neonRate > 400)
}
if (neonRate > 400)
neonRate = 400;
if (neonRate < 40)
if (neonRate < 40)
neonRate = 40;
/*
* Cycling through the top neon animation
*/
Cycling through the top neon animation
*/
if ((currTime - lastNeonUpdate) > neonRate)
{
neon_anim_index++;
@@ -369,8 +277,18 @@ if (pillar_lit)
neons |= neon_anim[neon_anim_index];
/*
* Light the leds
*/
Light the leds
*/
neon_lights(neons);
}
#endif
/* BARTOP ONLY FUNCTIONS */
uint16_t convert_order(uint16_t lightDesc) {
uint16_t res = 0;
for (int i = 0; i < BUT_NUM_LEDS; i++) {
if ((lightDesc >> i) & 1) {
res |= 1 << (lightOrder[i]);
}
}
return res;
}
-237
View File
@@ -1,237 +0,0 @@
#include "ps2.h"
#if defined(ARDUINO_ARCH_AVR)
/* USER CUSTOMIZABLE SETTINGS */
#define ACK_PORT PORTD
#define ACK_DDR DDRD
#define ACK_PIN 5 // PD5 (TXLED)
/* RECOMMENDED DO NOT CHANGE */
#define INVERT_CIPO 0 // Set to 1 if CIPO is open-drain via transistor (recommended)
#define INVERT_ACK 0 // Set to 1 if ACK is open-drain via transistor (recommended)
/* END OF USER CUSTOMIZABLE SETTINGS */
// Stores a constructed packet for the PS2.
uint16_t Data = 0;
// List of available PS2 inputs.
PS2_InputList_t *PS2Input = NULL;
// Current PS2 state.
void (*PS2Handler)(uint8_t) = NULL;
void PS2_Acknowledge(void) {
// Burn a few cycles before acknowledging
asm volatile(
"nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\n"
);
#if INVERT_ACK == 0
ACK_DDR |= (1<<ACK_PIN);
#else
ACK_DDR &= ~(1<<ACK_PIN);
#endif
// 40 cycles of delay should give us the same delay as a real PS1 controller
asm volatile(
"nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\n"
);
#if INVERT_ACK == 0
ACK_DDR &= ~(1<<ACK_PIN);
#else
ACK_DDR |= (1<<ACK_PIN);
#endif
}
void PS2_Listen(uint8_t in);
void PS2_Addressed(uint8_t in);
void PS2_HeaderFinished(uint8_t in);
void PS2_LowerSent(uint8_t in);
uint8_t memory_card_timeout = 0;
void PS2_MemoryCardTimeout(uint8_t in) {
if (memory_card_timeout) --memory_card_timeout;
if (!memory_card_timeout)
PS2Handler = PS2_Listen;
}
void PS2_MemoryCardID2(uint8_t in) {
// If we receive a 0x01 here, revert back to the listener
--memory_card_timeout;
if (in == 0x01) {
memory_card_timeout = 0;
PS2_Listen(in);
return;
}
PS2Handler = PS2_MemoryCardTimeout;
}
void PS2_MemoryCardID1(uint8_t in) {
// If we receive a 0x01 here, revert back to the listener
--memory_card_timeout;
if (in == 0x01) {
memory_card_timeout = 0;
PS2_Listen(in);
return;
}
PS2Handler = PS2_MemoryCardID2;
}
// Memory card addressed; ignore input
void PS2_MemoryCardAddressed(uint8_t in) {
memory_card_timeout = 8;
if (in == 'R')
memory_card_timeout = 138;
if (in == 'W')
memory_card_timeout = 136;
PS2Handler = PS2_MemoryCardID1;
}
// Idle state.
void PS2_Listen(uint8_t in) {
if (in == 0x81) {
DDRB &= ~0x08;
PS2Handler = PS2_MemoryCardAddressed;
}
// Report as a digital controller when addressed
if (in == 0x01) {
DDRB |= 0x08;
#if INVERT_CIPO == 1
SPDR = ~0x41;
#else
SPDR = 0x41;
#endif
PS2Handler = PS2_Addressed;
PS2_Acknowledge();
}
}
// When polling is requested, begin responding
void PS2_Addressed(uint8_t in) {
if (in == 0x42) {
#if INVERT_CIPO == 1
SPDR = ~0x5A;
#else
SPDR = 0x5A;
#endif
PS2Handler = PS2_HeaderFinished;
PS2_Acknowledge();
}
}
// After end-of-header sent, send the first byte
void PS2_HeaderFinished(uint8_t in) {
uint8_t *data = (uint8_t *)&Data;
#if INVERT_CIPO == 1
SPDR = ~(*data);
#else
SPDR = (*data);
#endif
PS2Handler = PS2_LowerSent;
PS2_Acknowledge();
}
// After first byte sent, send the second and go back to listening.
void PS2_LowerSent(uint8_t in) {
uint8_t *data = (uint8_t *)&Data + 1;
#if INVERT_CIPO == 1
SPDR = ~(*data);
#else
SPDR = (*data);
#endif
PS2Handler = PS2_Listen;
PS2_Acknowledge();
}
void PS2_Init(void) {
cli();
#if INVERT_ACK == 0
ACK_PORT &= ~(1<<ACK_PIN);
#else
ACK_PORT |= (1<<ACK_PIN);
#endif
PS2_Acknowledge();
// Set MISO as an output pin
DDRB |= 0x08;
// Setup data on falling edge, sample on rising edge (SPI mode 3)
SPCR = (1 << CPOL) | (1 << CPHA)
// Transmit LSB first
| (1 << DORD)
// Enable interrupts for SPI
| (1 << SPIE)
// Enable SPI
| (1 << SPE);
// Set the first byte up
#if INVERT_CIPO == 1
SPDR = 0x00; // 0xFF;
#else
SPDR = 0xFF;
#endif
PS2Handler = PS2_Listen;
sei();
}
// Update the stored data packet
void PS2_Task(void) {
if (PINB & 0x01)
{
#if INVERT_CIPO == 1
SPDR = 0x00;
#else
SPDR = 0xFF;
#endif
}
PS2_InputList_t *map = PS2Input;
uint16_t new_data = 0;
while(map) {
if (!map->input || (*map->input & map->mask))
new_data |= map->buttons;
map = map->parent;
}
Data = ~new_data;
}
void PS2_MapInput(uint16_t *input, uint16_t mask, PS2_INPUT buttons) {
PS2_InputList_t *child = calloc(1, sizeof(PS2_InputList_t));
child->input = input,
child->mask = mask,
child->buttons = buttons,
child->parent = PS2Input;
PS2Input = child;
}
void PS2_AlwaysInput(PS2_INPUT buttons) {
PS2_InputList_t *child = calloc(1, sizeof(PS2_InputList_t));
child->input = NULL,
child->mask = 0,
child->buttons = buttons,
child->parent = PS2Input;
PS2Input = child;
}
// When a transfer is complete, determine what to do next
ISR(SPI_STC_vect) {
uint8_t input = SPDR;
if (input == 0x01 && (!memory_card_timeout)) PS2Handler = PS2_Listen;
PS2Handler(SPDR);
}
#endif
-50
View File
@@ -1,50 +0,0 @@
#if defined(ARDUINO_ARCH_AVR)
#include <stdlib.h>
#include <stdint.h>
#include <avr/interrupt.h>
typedef enum {
PS2_NC = 0,
PS2_SELECT = (1 << 0),
PS2_L3 = (1 << 1),
PS2_R3 = (1 << 2),
PS2_START = (1 << 3),
PS2_UP = (1 << 4),
PS2_RIGHT = (1 << 5),
PS2_DOWN = (1 << 6),
PS2_LEFT = (1 << 7),
PS2_L2 = (1 << 8),
PS2_R2 = (1 << 9),
PS2_L1 = (1 << 10),
PS2_R1 = (1 << 11),
PS2_TRIANGLE = (1 << 12),
PS2_CIRCLE = (1 << 13),
PS2_CROSS = (1 << 14),
PS2_SQUARE = (1 << 15),
} PS2_INPUT;
typedef struct PS2_InputList_t PS2_InputList_t;
struct PS2_InputList_t {
uint16_t *input; // Input source; NULL is always true
uint16_t mask; // Mask to check; (*input & mask)
PS2_INPUT buttons; // OR the following if true
PS2_InputList_t *parent;
};
#ifdef __cplusplus
extern "C"{
#endif
void PS2_Init(void);
void PS2_Task(void);
void PS2_MapInput(uint16_t *input, uint16_t mask, PS2_INPUT buttons);
void PS2_AlwaysInput(PS2_INPUT buttons);
#ifdef __cplusplus
}
#endif
#endif
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 693 KiB