diff --git a/ReadMe.md b/ReadMe.md index 3e9034807..825037c86 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -12,25 +12,10 @@ - To avoid Application errors and duplicates, delete /ext/apps before doing the RM firmware update - Known Issues: `Chess`, `Tanks` & `Chip8` (No Controls) - Last Synced/Checked [Unleashed/xMasterX](https://github.com/Eng1n33r/flipperzero-firmware), changes in [changelog](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/blob/420/CHANGELOG.md): `2022-09-27 04:47 GMT` -- Last Synced/Checked [OFW](https://github.com/flipperdevices/flipperzero-firmware), changes in [commits](https://github.com/flipperdevices/flipperzero-firmware/commits/dev): `2022-09-27 04:47 GMT` -- Assets: Includes New Dolphin Animations: [Calcifier & Last Unicorn (By NeonKodama)] -- Assets: Includes New Dolphin Animations: [Jiji Milk (By NeonKodama)] -- Assets: Includes New Dolphin Animations: [Kam3Ham3Ha (By RogueMaster)] -- Assets: Includes New Dolphin Animations: [M3gamanZ3r0 Battle (By RogueMaster)] -- Assets: Includes New Dolphin Animations: [OP G3ar 4 (By RogueMaster)] -- Assets: Includes New Dolphin Animations: [Kirbs (By RogueMaster)] -- Assets: Includes New Dolphin Animations: [Kirbs Confused (By RogueMaster)] -- Assets: Includes New Dolphin Animations: [Z3lda 0h (By RogueMaster)] -- Assets: Includes New Dolphin Animations: [Init D Water (By RogueMaster)] -- Assets: Includes New Dolphin Animations: [Hexadecimal (By RogueMaster)] -- Assets: Includes New Dolphin Animations: [Halloween (By RogueMaster)] -- Assets: Includes New Dolphin Animations: [Rekall (By Kuronons)] -- Restored iButton CLI [thanks to ESurge](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/pull/346) -- Corrected MiFare Classic Dictionary [thanks to bernouilli](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/pull/347) -- Assets: Includes New Dolphin Animations: [Stick Fight (By Sasquach)] -- Assets: Includes New Dolphin Animations: [G0ku, Lufy & Mug1wara (By Haseo)] -- Assets: Includes New Dolphin Animations: [Tardi5 (By RogueMaster)] +- Last Synced/Checked [OFW](https://github.com/flipperdevices/flipperzero-firmware), changes in [commits](https://github.com/flipperdevices/flipperzero-firmware/commits/dev): `2022-09-27 22:03 GMT` - Assets: Includes New Dolphin Animations: [80s (By Haseo)] +- Added: [Minesweeper (By panki27)](https://github.com/panki27/minesweeper) Thank you @Panki27 +- Added: [USB Keyboard (By huuck)](https://github.com/huuck/FlipperZeroUSBKeyboard)
TO DO
@@ -197,6 +182,7 @@ $ ./fbt plugin_dist FIRMWARE_APP_SET=ext_apps - [Flappy Bird (By DroomOne)](https://github.com/DroomOne/flipperzero-firmware/tree/dev/applications/flappy_bird) - [Game of Life (Updated to work by tgxn) (By itsyourbedtime)](https://github.com/tgxn/flipperzero-firmware/blob/dev/applications/game_of_life/game_of_life.c) - [Mandelbrot Set (By Possibly-Matt)](https://github.com/Possibly-Matt/flipperzero-firmware-wPlugins) +- [Minesweeper (By panki27)](https://github.com/panki27/minesweeper) - [Monty Hall (By DevMilanIan)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/pull/203) - Snake [OFW] - [TAMA P1 (By GMMan)](https://github.com/GMMan/flipperzero-firmware/tree/tama-p1) requires [this rom](https://tinyurl.com/tamap1) IN `tama_p1` on SD as `rom.bin` to make it work. @@ -235,6 +221,7 @@ $ ./fbt plugin_dist FIRMWARE_APP_SET=ext_apps - [Sub-GHz Bruteforcer (By Ganapati & xMasterX)](https://github.com/Eng1n33r/flipperzero-firmware/pull/57) - [Sub-GHz Playlist (By darmiel)](https://github.com/darmiel/flipper-playlist) - [UPC-A Generator (By McAzzaMan)](https://github.com/McAzzaMan/flipperzero-firmware/tree/UPC-A_Barcode_Generator/applications/barcode_generator) +- [USB Keyboard (By huuck)](https://github.com/huuck/FlipperZeroUSBKeyboard) - [WAV Player (By Zlo)](https://github.com/flipperdevices/flipperzero-firmware/tree/zlo/wav-player) Updated by Atmanos & RogueMaster To Work - [WiFi (Deauther) (By Timmotools)](https://github.com/Timmotools/flipperzero_esp8266_deautherv2) - [WiFi (Marauder) (By 0xchocolate)](https://github.com/0xchocolate/flipperzero-firmware-with-wifi-marauder-companion) `REQUIRES ESP32 WITH MARAUDER FLASHED` diff --git a/applications/plugins/minesweeper/LICENSE b/applications/plugins/minesweeper/LICENSE new file mode 100644 index 000000000..f288702d2 --- /dev/null +++ b/applications/plugins/minesweeper/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/applications/plugins/minesweeper/README.md b/applications/plugins/minesweeper/README.md new file mode 100644 index 000000000..4297cbed7 --- /dev/null +++ b/applications/plugins/minesweeper/README.md @@ -0,0 +1,17 @@ +# Minesweeper + +This is a Minesweeper implementation for the Flipper Zero device. + +![screenshot](img/screenshot.png) + +## Controls + +- Arrow buttons to move +- Push center button to open field +- Hold center button to toggle flag + +## Compiling + +``` +./fbt firmware_minesweeper +``` diff --git a/applications/plugins/minesweeper/application.fam b/applications/plugins/minesweeper/application.fam new file mode 100644 index 000000000..b544085d9 --- /dev/null +++ b/applications/plugins/minesweeper/application.fam @@ -0,0 +1,12 @@ +App( + appid="Minesweeper", + name="Minesweeper", + apptype=FlipperAppType.EXTERNAL, + entry_point="minesweeper_app", + cdefines=["APP_MINESWEEPER"], + requires=["gui"], + stack_size=4 * 1024, + fap_category="Games", + fap_icon="minesweeper_icon.png", + order=35, +) diff --git a/applications/plugins/minesweeper/assets.h b/applications/plugins/minesweeper/assets.h new file mode 100644 index 000000000..403c8de29 --- /dev/null +++ b/applications/plugins/minesweeper/assets.h @@ -0,0 +1,48 @@ +#define tile_0_width 8 +#define tile_0_height 8 +static uint8_t tile_0_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; +#define tile_1_width 8 +#define tile_1_height 8 +static uint8_t tile_1_bits[] = { + 0x00, 0x10, 0x18, 0x10, 0x10, 0x10, 0x10, 0x00, }; +#define tile_2_width 8 +#define tile_2_height 8 +static uint8_t tile_2_bits[] = { + 0x00, 0x1C, 0x20, 0x20, 0x18, 0x04, 0x3C, 0x00, }; +#define tile_3_width 8 +#define tile_3_height 8 +static uint8_t tile_3_bits[] = { + 0x00, 0x1C, 0x20, 0x20, 0x18, 0x20, 0x1C, 0x00, }; +#define tile_4_width 8 +#define tile_4_height 8 +static uint8_t tile_4_bits[] = { + 0x00, 0x04, 0x14, 0x14, 0x3C, 0x10, 0x10, 0x00, }; +#define tile_5_width 8 +#define tile_5_height 8 +static uint8_t tile_5_bits[] = { + 0x00, 0x3C, 0x04, 0x1C, 0x20, 0x20, 0x1C, 0x00, }; +#define tile_6_width 8 +#define tile_6_height 8 +static uint8_t tile_6_bits[] = { + 0x00, 0x18, 0x24, 0x04, 0x1C, 0x24, 0x18, 0x00, }; +#define tile_7_width 8 +#define tile_7_height 8 +static uint8_t tile_7_bits[] = { + 0x00, 0x3C, 0x20, 0x20, 0x10, 0x08, 0x08, 0x00, }; +#define tile_8_width 8 +#define tile_8_height 8 +static uint8_t tile_8_bits[] = { + 0x00, 0x18, 0x24, 0x18, 0x24, 0x24, 0x18, 0x00, }; +#define tile_flag_width 8 +#define tile_flag_height 8 +static uint8_t tile_flag_bits[] = { + 0xFF, 0x81, 0xB9, 0x89, 0x89, 0x9D, 0x81, 0xFF, }; +#define tile_mine_width 8 +#define tile_mine_height 8 +static uint8_t tile_mine_bits[] = { + 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, }; +#define tile_uncleared_width 8 +#define tile_uncleared_height 8 +static uint8_t tile_uncleared_bits[] = { + 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF, }; diff --git a/applications/plugins/minesweeper/assets/asset b/applications/plugins/minesweeper/assets/asset new file mode 100644 index 000000000..80a6c89f5 --- /dev/null +++ b/applications/plugins/minesweeper/assets/asset @@ -0,0 +1,48 @@ +#define tile_0_width 8 +#define tile_0_height 8 +static uint8_t tile_0_bits[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }; +#define tile_1_width 8 +#define tile_1_height 8 +static uint8_t tile_1_bits[] = { + 0x00, 0x10, 0x18, 0x10, 0x10, 0x10, 0x10, 0x00, }; +#define tile_2_width 8 +#define tile_2_height 8 +static uint8_t tile_2_bits[] = { + 0x00, 0x1C, 0x20, 0x20, 0x18, 0x04, 0x3C, 0x00, }; +#define tile_3_width 8 +#define tile_3_height 8 +static uint8_t tile_3_bits[] = { + 0x00, 0x1C, 0x20, 0x20, 0x18, 0x20, 0x1C, 0x00, }; +#define tile_4_width 8 +#define tile_4_height 8 +static uint8_t tile_4_bits[] = { + 0x00, 0x04, 0x14, 0x14, 0x3C, 0x10, 0x10, 0x00, }; +#define tile_5_width 8 +#define tile_5_height 8 +static uint8_t tile_5_bits[] = { + 0x00, 0x3C, 0x04, 0x1C, 0x20, 0x20, 0x1C, 0x00, }; +#define tile_6_width 8 +#define tile_6_height 8 +static uint8_t tile_6_bits[] = { + 0x00, 0x18, 0x24, 0x04, 0x1C, 0x24, 0x18, 0x00, }; +#define tile_7_width 8 +#define tile_7_height 8 +static uint8_t tile_7_bits[] = { + 0x00, 0x3C, 0x20, 0x20, 0x10, 0x08, 0x08, 0x00, }; +#define tile_8_width 8 +#define tile_8_height 8 +static uint8_t tile_8_bits[] = { + 0x00, 0x18, 0x24, 0x18, 0x24, 0x24, 0x18, 0x00, }; +#define tile_flag_width 8 +#define tile_flag_height 8 +static uint8_t tile_flag_bits[] = { + 0xFF, 0x81, 0xB9, 0x89, 0x89, 0x9D, 0x81, 0xFF, }; +#define tile_mine_width 8 +#define tile_mine_height 8 +static uint8_t tile_mine_bits[] = { + 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, }; +#define tile_uncleared_width 8 +#define tile_uncleared_height 8 +static uint8_t tile_uncleared_bits[] = { + 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF, }; diff --git a/applications/plugins/minesweeper/assets/mockup.png b/applications/plugins/minesweeper/assets/mockup.png new file mode 100644 index 000000000..00d99b1f2 Binary files /dev/null and b/applications/plugins/minesweeper/assets/mockup.png differ diff --git a/applications/plugins/minesweeper/assets/tile_0.png b/applications/plugins/minesweeper/assets/tile_0.png new file mode 100644 index 000000000..c7fec6cca Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_0.png differ diff --git a/applications/plugins/minesweeper/assets/tile_0.xbm b/applications/plugins/minesweeper/assets/tile_0.xbm new file mode 100644 index 000000000..3da1fa7d7 --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_0.xbm @@ -0,0 +1,4 @@ +#define tile_0_width 8 +#define tile_0_height 8 +static char tile_0_bits[] = { + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, }; diff --git a/applications/plugins/minesweeper/assets/tile_1.png b/applications/plugins/minesweeper/assets/tile_1.png new file mode 100644 index 000000000..588d77c2a Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_1.png differ diff --git a/applications/plugins/minesweeper/assets/tile_1.xbm b/applications/plugins/minesweeper/assets/tile_1.xbm new file mode 100644 index 000000000..568c72155 --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_1.xbm @@ -0,0 +1,4 @@ +#define tile_1_width 8 +#define tile_1_height 8 +static uint8_t tile_1_bits[] = { + 0x00, 0x10, 0x18, 0x10, 0x10, 0x10, 0x10, 0x00, }; diff --git a/applications/plugins/minesweeper/assets/tile_2.png b/applications/plugins/minesweeper/assets/tile_2.png new file mode 100644 index 000000000..9c1c59013 Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_2.png differ diff --git a/applications/plugins/minesweeper/assets/tile_2.xbm b/applications/plugins/minesweeper/assets/tile_2.xbm new file mode 100644 index 000000000..198ae0879 --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_2.xbm @@ -0,0 +1,4 @@ +#define tile_2_width 8 +#define tile_2_height 8 +static uint8_t tile_2_bits[] = { + 0x00, 0x1C, 0x20, 0x20, 0x18, 0x04, 0x3C, 0x00, }; diff --git a/applications/plugins/minesweeper/assets/tile_3.png b/applications/plugins/minesweeper/assets/tile_3.png new file mode 100644 index 000000000..a229d01f5 Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_3.png differ diff --git a/applications/plugins/minesweeper/assets/tile_3.xbm b/applications/plugins/minesweeper/assets/tile_3.xbm new file mode 100644 index 000000000..022bd3c6b --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_3.xbm @@ -0,0 +1,4 @@ +#define tile_3_width 8 +#define tile_3_height 8 +static uint8_t tile_3_bits[] = { + 0x00, 0x1C, 0x20, 0x20, 0x18, 0x20, 0x1C, 0x00, }; diff --git a/applications/plugins/minesweeper/assets/tile_4.png b/applications/plugins/minesweeper/assets/tile_4.png new file mode 100644 index 000000000..dfaab7b27 Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_4.png differ diff --git a/applications/plugins/minesweeper/assets/tile_4.xbm b/applications/plugins/minesweeper/assets/tile_4.xbm new file mode 100644 index 000000000..58287176c --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_4.xbm @@ -0,0 +1,4 @@ +#define tile_4_width 8 +#define tile_4_height 8 +static uint8_t tile_4_bits[] = { + 0x00, 0x04, 0x14, 0x14, 0x3C, 0x10, 0x10, 0x00, }; diff --git a/applications/plugins/minesweeper/assets/tile_5.png b/applications/plugins/minesweeper/assets/tile_5.png new file mode 100644 index 000000000..2c8f03c3d Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_5.png differ diff --git a/applications/plugins/minesweeper/assets/tile_5.xbm b/applications/plugins/minesweeper/assets/tile_5.xbm new file mode 100644 index 000000000..e36f51a36 --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_5.xbm @@ -0,0 +1,4 @@ +#define tile_5_width 8 +#define tile_5_height 8 +static uint8_t tile_5_bits[] = { + 0x00, 0x3C, 0x04, 0x1C, 0x20, 0x20, 0x1C, 0x00, }; diff --git a/applications/plugins/minesweeper/assets/tile_6.png b/applications/plugins/minesweeper/assets/tile_6.png new file mode 100644 index 000000000..2af1b6511 Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_6.png differ diff --git a/applications/plugins/minesweeper/assets/tile_6.xbm b/applications/plugins/minesweeper/assets/tile_6.xbm new file mode 100644 index 000000000..74b290e07 --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_6.xbm @@ -0,0 +1,4 @@ +#define tile_6_width 8 +#define tile_6_height 8 +static uint8_t tile_6_bits[] = { + 0x00, 0x18, 0x24, 0x04, 0x1C, 0x24, 0x18, 0x00, }; diff --git a/applications/plugins/minesweeper/assets/tile_7.png b/applications/plugins/minesweeper/assets/tile_7.png new file mode 100644 index 000000000..c6a4e204b Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_7.png differ diff --git a/applications/plugins/minesweeper/assets/tile_7.xbm b/applications/plugins/minesweeper/assets/tile_7.xbm new file mode 100644 index 000000000..6aafa6ad0 --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_7.xbm @@ -0,0 +1,4 @@ +#define tile_7_width 8 +#define tile_7_height 8 +static uint8_t tile_7_bits[] = { + 0x00, 0x3C, 0x20, 0x20, 0x10, 0x08, 0x08, 0x00, }; diff --git a/applications/plugins/minesweeper/assets/tile_8.png b/applications/plugins/minesweeper/assets/tile_8.png new file mode 100644 index 000000000..cebbe5389 Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_8.png differ diff --git a/applications/plugins/minesweeper/assets/tile_8.xbm b/applications/plugins/minesweeper/assets/tile_8.xbm new file mode 100644 index 000000000..05ab21045 --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_8.xbm @@ -0,0 +1,4 @@ +#define tile_8_width 8 +#define tile_8_height 8 +static uint8_t tile_8_bits[] = { + 0x00, 0x18, 0x24, 0x18, 0x24, 0x24, 0x18, 0x00, }; diff --git a/applications/plugins/minesweeper/assets/tile_empty.png b/applications/plugins/minesweeper/assets/tile_empty.png new file mode 100644 index 000000000..1f48880fb Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_empty.png differ diff --git a/applications/plugins/minesweeper/assets/tile_flag.png b/applications/plugins/minesweeper/assets/tile_flag.png new file mode 100644 index 000000000..6ec2a71f8 Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_flag.png differ diff --git a/applications/plugins/minesweeper/assets/tile_flag.xbm b/applications/plugins/minesweeper/assets/tile_flag.xbm new file mode 100644 index 000000000..ed4b9c0aa --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_flag.xbm @@ -0,0 +1,4 @@ +#define tile_flag_width 8 +#define tile_flag_height 8 +static uint8_t tile_flag_bits[] = { + 0xFF, 0x81, 0xB9, 0x89, 0x89, 0x9D, 0x81, 0xFF, }; diff --git a/applications/plugins/minesweeper/assets/tile_mine.png b/applications/plugins/minesweeper/assets/tile_mine.png new file mode 100644 index 000000000..3c4a38e6e Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_mine.png differ diff --git a/applications/plugins/minesweeper/assets/tile_mine.xbm b/applications/plugins/minesweeper/assets/tile_mine.xbm new file mode 100644 index 000000000..6e05347ae --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_mine.xbm @@ -0,0 +1,4 @@ +#define tile_mine_width 8 +#define tile_mine_height 8 +static uint8_t tile_mine_bits[] = { + 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, }; diff --git a/applications/plugins/minesweeper/assets/tile_uncleared.png b/applications/plugins/minesweeper/assets/tile_uncleared.png new file mode 100644 index 000000000..b98de1116 Binary files /dev/null and b/applications/plugins/minesweeper/assets/tile_uncleared.png differ diff --git a/applications/plugins/minesweeper/assets/tile_uncleared.xbm b/applications/plugins/minesweeper/assets/tile_uncleared.xbm new file mode 100644 index 000000000..e8a8ef610 --- /dev/null +++ b/applications/plugins/minesweeper/assets/tile_uncleared.xbm @@ -0,0 +1,4 @@ +#define tile_uncleared_width 8 +#define tile_uncleared_height 8 +static uint8_t tile_uncleared_bits[] = { + 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF, }; diff --git a/applications/plugins/minesweeper/img/screenshot.png b/applications/plugins/minesweeper/img/screenshot.png new file mode 100644 index 000000000..65b307c55 Binary files /dev/null and b/applications/plugins/minesweeper/img/screenshot.png differ diff --git a/applications/plugins/minesweeper/minesweeper.c b/applications/plugins/minesweeper/minesweeper.c new file mode 100644 index 000000000..3ccd5fd41 --- /dev/null +++ b/applications/plugins/minesweeper/minesweeper.c @@ -0,0 +1,509 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "assets.h" + +#define PLAYFIELD_WIDTH 16 +#define PLAYFIELD_HEIGHT 7 +#define TILE_WIDTH 8 +#define TILE_HEIGHT 8 + +#define MINECOUNT 20 + +typedef enum { + EventTypeTick, + EventTypeKey, +} EventType; + +typedef struct { + EventType type; + InputEvent input; +} PluginEvent; + +typedef enum { + TileType0, // this HAS to be in order, for hint assignment to be ez pz + TileType1, + TileType2, + TileType3, + TileType4, + TileType5, + TileType6, + TileType7, + TileType8, + TileTypeUncleared, + TileTypeFlag, + TileTypeMine +} TileType; + +typedef enum { + FieldEmpty, // <-- same goes for this + FieldMine +} Field; + +typedef struct { + Field minefield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT]; + TileType playfield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT]; + int cursor_x; + int cursor_y; + int mines_left; + int fields_cleared; + int flags_set; + bool game_started; + bool showing_dialog; + uint32_t game_started_tick; +} Minesweeper; + +static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { + furi_assert(event_queue); + + PluginEvent event = {.type = EventTypeKey, .input = *input_event}; + furi_message_queue_put(event_queue, &event, FuriWaitForever); +} + +static void render_callback(Canvas* const canvas, void* ctx) { + const Minesweeper* minesweeper_state = acquire_mutex((ValueMutex*)ctx, 25); + if (minesweeper_state == NULL) { + return; + } + if (minesweeper_state->showing_dialog) { + release_mutex((ValueMutex*)ctx, minesweeper_state); + return; + } + string_t tempStr; + string_init(tempStr); + string_printf(tempStr, "Mines: %d", MINECOUNT - minesweeper_state->flags_set); + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, string_get_cstr(tempStr)); + string_clear(tempStr); + int seconds = 0; + int minutes = 0; + if (minesweeper_state->game_started) { + uint32_t ticks_elapsed = furi_get_tick() - minesweeper_state->game_started_tick; + seconds = (int) ticks_elapsed / furi_kernel_get_tick_frequency(); + minutes = (int) seconds / 60; + seconds = seconds % 60; + } + string_printf(tempStr, "%01d:%02d", minutes, seconds); + canvas_draw_str_aligned(canvas, 128, 0, AlignRight, AlignTop, string_get_cstr(tempStr)); + string_clear(tempStr); + + for (int y = 0; y < PLAYFIELD_HEIGHT; y++) { + for (int x = 0; x < PLAYFIELD_WIDTH; x++) { + if ( x == minesweeper_state->cursor_x && y == minesweeper_state->cursor_y) { + canvas_invert_color(canvas); + } + switch (minesweeper_state->playfield[x][y]) { + case TileType0: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_0_bits); + break; + case TileType1: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_1_bits); + break; + case TileType2: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_2_bits); + break; + case TileType3: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_3_bits); + break; + case TileType4: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_4_bits); + break; + case TileType5: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_5_bits); + break; + case TileType6: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_6_bits); + break; + case TileType7: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_7_bits); + break; + case TileType8: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_8_bits); + break; + case TileTypeFlag: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_flag_bits); + break; + case TileTypeUncleared: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_uncleared_bits); + break; + case TileTypeMine: + canvas_draw_xbm( + canvas, + x*TILE_HEIGHT, // x + 8 + (y * TILE_WIDTH), // y + TILE_WIDTH, + TILE_HEIGHT, + tile_mine_bits); + break; + } + if ( x == minesweeper_state->cursor_x && y == minesweeper_state->cursor_y) { + canvas_invert_color(canvas); + } + } + } + string_clear(tempStr); + release_mutex((ValueMutex*)ctx, minesweeper_state); +} + +static void setup_playfield(Minesweeper* minesweeper_state) { + int mines_left = MINECOUNT; + for (int y = 0; y < PLAYFIELD_HEIGHT; y++) { + for (int x = 0; x < PLAYFIELD_WIDTH; x++){ + minesweeper_state->minefield[x][y] = FieldEmpty; + minesweeper_state->playfield[x][y] = TileTypeUncleared; + } + } + while(mines_left > 0) { + int rand_x = rand() % PLAYFIELD_WIDTH; + int rand_y = rand() % PLAYFIELD_HEIGHT; + // make sure first guess isn't a mine + if (minesweeper_state->minefield[rand_x][rand_y] == FieldEmpty && + (minesweeper_state->cursor_x != rand_x && minesweeper_state->cursor_y != rand_y )) { + minesweeper_state->minefield[rand_x][rand_y] = FieldMine; + mines_left--; + } + minesweeper_state->mines_left = MINECOUNT; + minesweeper_state->fields_cleared = 0; + minesweeper_state->flags_set = 0; + minesweeper_state->game_started_tick = furi_get_tick(); + minesweeper_state->game_started = false; + minesweeper_state->showing_dialog = false; + } +} + +static void place_flag(Minesweeper* minesweeper_state) { + if (minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] == TileTypeUncleared) { + minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] = TileTypeFlag; + minesweeper_state->flags_set++; + } else if (minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] == TileTypeFlag) { + minesweeper_state->playfield[minesweeper_state->cursor_x][minesweeper_state->cursor_y] = TileTypeUncleared; + minesweeper_state->flags_set--; + } +} + +static bool game_lost(Minesweeper* minesweeper_state) { + // returns true if the player wants to restart, otherwise false + minesweeper_state->showing_dialog = true; + NotificationApp* notifications = furi_record_open(RECORD_NOTIFICATION); + DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS); + + DialogMessage* message = dialog_message_alloc(); + const char* header_text = "Game Over"; + const char* message_text = "You hit a mine!"; + + dialog_message_set_header(message, header_text, 64, 3, AlignCenter, AlignTop); + dialog_message_set_text(message, message_text, 64, 32, AlignCenter, AlignCenter); + dialog_message_set_buttons(message, NULL, "Play again", NULL); + + dialog_message_set_icon(message, NULL, 0, 10); + + notification_message(notifications, &sequence_set_vibro_on); + furi_delay_ms(200); + notification_message(notifications, &sequence_reset_vibro); + + DialogMessageButton choice = dialog_message_show(dialogs, message); + dialog_message_free(message); + furi_record_close(RECORD_NOTIFICATION); + + return choice == DialogMessageButtonCenter; +} + +static bool game_won(Minesweeper* minesweeper_state) { + DialogsApp *dialogs = furi_record_open(RECORD_DIALOGS); + + minesweeper_state->showing_dialog = true; + + string_t tempStr; + string_init(tempStr); + + int seconds = 0; + int minutes = 0; + uint32_t ticks_elapsed = furi_get_tick() - minesweeper_state->game_started_tick; + seconds = (int) ticks_elapsed / furi_kernel_get_tick_frequency(); + minutes = (int) seconds / 60; + seconds = seconds % 60; + + DialogMessage* message = dialog_message_alloc(); + const char* header_text = "Game won!"; + string_printf(tempStr, "Minefield cleared in %01d:%02d", minutes, seconds); + dialog_message_set_header(message, header_text, 64, 3, AlignCenter, AlignTop); + dialog_message_set_text(message, string_get_cstr(tempStr), 64, 32, AlignCenter, AlignCenter); + dialog_message_set_buttons(message, NULL, "Play again", NULL); + // TODO: create icon + dialog_message_set_icon(message, NULL, 72, 17); + + DialogMessageButton choice = dialog_message_show(dialogs, message); + dialog_message_free(message); + //minesweeper_state->showing_dialog = false; + string_clear(tempStr); + string_reset(tempStr); + furi_record_close(RECORD_DIALOGS); + return choice == DialogMessageButtonCenter; +} + +static bool play_move(Minesweeper* minesweeper_state, int cursor_x, int cursor_y) { + if (minesweeper_state->playfield[cursor_x][cursor_y] != TileTypeUncleared) { + // we're on an already uncovered field + return true; + } + if (minesweeper_state->minefield[cursor_x][cursor_y] == FieldMine) { + // TODO: player loses! + minesweeper_state->playfield[cursor_x][cursor_y] = TileTypeMine; + return false; + } else { + // get number of surrounding mines. + int hint = 0; + for (int y = cursor_y-1; y <= cursor_y+1; y++) { + for (int x = cursor_x-1; x <= cursor_x+1; x++) { + if ( x == cursor_x && y == cursor_y ) { + // we're on the cell the user selected, so ignore. + continue; + } + // make sure we don't go OOB + if ( x >= 0 && x < PLAYFIELD_WIDTH && y >= 0 && y < PLAYFIELD_HEIGHT) { + if(minesweeper_state->minefield[x][y] == FieldMine) { + hint ++; + } + } + } + } + // 〜( ̄▽ ̄〜) don't judge me (〜 ̄▽ ̄)〜 + minesweeper_state->playfield[cursor_x][cursor_y] = hint; + minesweeper_state->fields_cleared++; + FURI_LOG_D("Minesweeper", "Setting %d,%d to %d", cursor_x, cursor_y, hint); + if (hint == 0) { + // auto open surrounding fields. + for (int auto_y = cursor_y-1; auto_y <= cursor_y+1; auto_y++) { + for (int auto_x = cursor_x-1; auto_x <= cursor_x+1; auto_x++) { + if ( auto_x == cursor_x && auto_y == cursor_y ) { + continue; + } + if ( auto_x >= 0 && auto_x < PLAYFIELD_WIDTH && auto_y >= 0 && auto_y < PLAYFIELD_HEIGHT) { + if (minesweeper_state->playfield[auto_x][auto_y] == TileTypeUncleared) { + play_move(minesweeper_state, auto_x, auto_y); + } + } + } + } + } + return true; + } +} + +static void minesweeper_state_init(Minesweeper* const minesweeper_state) { + minesweeper_state->cursor_x = minesweeper_state->cursor_y = 0; + minesweeper_state->game_started = false; + minesweeper_state->showing_dialog = false; + for (int y = 0; y < PLAYFIELD_HEIGHT; y++) { + for (int x = 0; x < PLAYFIELD_WIDTH; x++){ + minesweeper_state->playfield[x][y] = TileTypeUncleared; + } + } +} + +int32_t minesweeper_app(void* p) { + UNUSED(p); + + FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); + + Minesweeper* minesweeper_state = malloc(sizeof(Minesweeper)); + // setup + minesweeper_state_init(minesweeper_state); + + ValueMutex state_mutex; + if (!init_mutex(&state_mutex, minesweeper_state, sizeof(minesweeper_state))) { + FURI_LOG_E("Minesweeper", "cannot create mutex\r\n"); + free(minesweeper_state); + return 255; + } + // BEGIN IMPLEMENTATION + + // Set system callbacks + ViewPort* view_port = view_port_alloc(); + view_port_draw_callback_set(view_port, render_callback, &state_mutex); + view_port_input_callback_set(view_port, input_callback, event_queue); + + // Open GUI and register view_port + Gui* gui = furi_record_open("gui"); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); + + PluginEvent event; + for (bool processing = true; processing;) { + FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); + Minesweeper* minesweeper_state = (Minesweeper*)acquire_mutex_block(&state_mutex); + if (minesweeper_state->showing_dialog) { + // this should not happen. + //release_mutex(&state_mutex, minesweeper_state); + processing = false; + //continue; + } + if(event_status == FuriStatusOk) { + // press events + if(event.type == EventTypeKey) { + if(event.input.type == InputTypeShort) { + switch(event.input.key) { + case InputKeyUp: + minesweeper_state->cursor_y--; + if(minesweeper_state->cursor_y < 0) { + minesweeper_state->cursor_y = 0; + } + break; + case InputKeyDown: + minesweeper_state->cursor_y++; + if(minesweeper_state->cursor_y >= PLAYFIELD_HEIGHT) { + minesweeper_state->cursor_y = PLAYFIELD_HEIGHT-1; + } + break; + case InputKeyRight: + minesweeper_state->cursor_x++; + if(minesweeper_state->cursor_x >= PLAYFIELD_WIDTH) { + minesweeper_state->cursor_x = PLAYFIELD_WIDTH-1; + } + break; + case InputKeyLeft: + minesweeper_state->cursor_x--; + if(minesweeper_state->cursor_x < 0) { + minesweeper_state->cursor_x = 0; + } + break; + case InputKeyOk: + if (!minesweeper_state->game_started) { + setup_playfield(minesweeper_state); + minesweeper_state->game_started = true; + } + if (!play_move(minesweeper_state, minesweeper_state->cursor_x, minesweeper_state->cursor_y)) { + // ooops. looks like we hit a mine! + if (game_lost(minesweeper_state)) { + // player wants to restart. + setup_playfield(minesweeper_state); + } else { + // player wants to exit :( + processing = false; + } + } else { + // check win condition. + if (minesweeper_state->fields_cleared == (PLAYFIELD_HEIGHT*PLAYFIELD_WIDTH) - MINECOUNT){ + if (game_won(minesweeper_state)) { + //player wants to restart + setup_playfield(minesweeper_state); + } else { + processing = false; + } + } + } + break; + case InputKeyBack: + // Exit the plugin + processing = false; + break; + } + } else if (event.input.type == InputTypeLong) { + // hold events + FURI_LOG_D("Minesweeper", "Got a long press!"); + switch(event.input.key) { + case InputKeyUp: + case InputKeyDown: + case InputKeyRight: + case InputKeyLeft: + break; + case InputKeyOk: + FURI_LOG_D("Minesweeper", "Toggling flag"); + place_flag(minesweeper_state); + break; + case InputKeyBack: + processing = false; + break; + } + } + } + } else { + // event timeout + ; + } + view_port_update(view_port); + release_mutex(&state_mutex, minesweeper_state); + } + view_port_enabled_set(view_port, false); + gui_remove_view_port(gui, view_port); + furi_record_close("gui"); + view_port_free(view_port); + furi_message_queue_free(event_queue); + delete_mutex(&state_mutex); + free(minesweeper_state); + + return 0; +} + diff --git a/applications/plugins/minesweeper/minesweeper_icon.png b/applications/plugins/minesweeper/minesweeper_icon.png new file mode 100644 index 000000000..8a7cd9468 Binary files /dev/null and b/applications/plugins/minesweeper/minesweeper_icon.png differ diff --git a/applications/plugins/usbkeyboard/README.md b/applications/plugins/usbkeyboard/README.md new file mode 100644 index 000000000..b2e31f9f4 --- /dev/null +++ b/applications/plugins/usbkeyboard/README.md @@ -0,0 +1,8 @@ +# FlipperZeroUSBKeyboard +Turn your Flipper Zero into an USB keyboard. Works with the [latest Unleashed firmware](https://github.com/Eng1n33r/flipperzero-firmware). See the release on how to install the external app on the sdcard. For building instructions please refer the [official FAP guide](https://github.com/Eng1n33r/flipperzero-firmware/blob/dev/documentation/AppsOnSDCard.md). + +How it works: https://twitter.com/hookgab/status/1572537933210718211 + +Credits: + +All the good people that made the [BT HID remote](https://github.com/flipperdevices/flipperzero-firmware/tree/873e1f114b7ca55a72dc68bf1b1fa6d169e7c17e/applications/plugins/bt_hid_app) and the [USB Mouse](https://github.com/flipperdevices/flipperzero-firmware/tree/873e1f114b7ca55a72dc68bf1b1fa6d169e7c17e/applications/debug/usb_mouse). diff --git a/applications/plugins/usbkeyboard/application.fam b/applications/plugins/usbkeyboard/application.fam new file mode 100644 index 000000000..06428b8aa --- /dev/null +++ b/applications/plugins/usbkeyboard/application.fam @@ -0,0 +1,14 @@ +App( + appid="USB_Keyboard", + name="USB Keyboard", + apptype=FlipperAppType.EXTERNAL, + entry_point="usb_hid_app", + stack_size=1 * 1024, + cdefines=["APP_USB_KEYBOARD"], + requires=[ + "gui", + ], + order=60, + fap_icon="usb_keyboard_10px.png", + fap_category="Tools", +) diff --git a/applications/plugins/usbkeyboard/usb_hid.c b/applications/plugins/usbkeyboard/usb_hid.c new file mode 100644 index 000000000..c2344565b --- /dev/null +++ b/applications/plugins/usbkeyboard/usb_hid.c @@ -0,0 +1,171 @@ +#include "usb_hid.h" +#include +#include +#include + +#define TAG "UsbHidApp" + +enum UsbDebugSubmenuIndex { + UsbHidSubmenuIndexDirpad, + UsbHidSubmenuIndexKeyboard, + UsbHidSubmenuIndexMedia, + UsbHidSubmenuIndexMouse, +}; + +void usb_hid_submenu_callback(void* context, uint32_t index) { + furi_assert(context); + UsbHid* app = context; + if(index == UsbHidSubmenuIndexDirpad) { + app->view_id = UsbHidViewDirpad; + view_dispatcher_switch_to_view(app->view_dispatcher, UsbHidViewDirpad); + } else if(index == UsbHidSubmenuIndexKeyboard) { + app->view_id = UsbHidViewKeyboard; + view_dispatcher_switch_to_view(app->view_dispatcher, UsbHidViewKeyboard); + } else if(index == UsbHidSubmenuIndexMedia) { + app->view_id = UsbHidViewMedia; + view_dispatcher_switch_to_view(app->view_dispatcher, UsbHidViewMedia); + } else if(index == UsbHidSubmenuIndexMouse) { + app->view_id = UsbHidViewMouse; + view_dispatcher_switch_to_view(app->view_dispatcher, UsbHidViewMouse); + } +} + +void usb_hid_dialog_callback(DialogExResult result, void* context) { + furi_assert(context); + UsbHid* app = context; + if(result == DialogExResultLeft) { + view_dispatcher_stop(app->view_dispatcher); + } else if(result == DialogExResultRight) { + view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id); // Show last view + } else if(result == DialogExResultCenter) { + view_dispatcher_switch_to_view(app->view_dispatcher, UsbHidViewSubmenu); + } +} + +uint32_t usb_hid_exit_confirm_view(void* context) { + UNUSED(context); + return UsbHidViewExitConfirm; +} + +uint32_t usb_hid_exit(void* context) { + UNUSED(context); + return VIEW_NONE; +} + +UsbHid* usb_hid_app_alloc() { + UsbHid* app = malloc(sizeof(UsbHid)); + + // Gui + app->gui = furi_record_open(RECORD_GUI); + + // Notifications + app->notifications = furi_record_open(RECORD_NOTIFICATION); + + // View dispatcher + app->view_dispatcher = view_dispatcher_alloc(); + view_dispatcher_enable_queue(app->view_dispatcher); + view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); + + // Submenu view + app->submenu = submenu_alloc(); + submenu_add_item( + app->submenu, "Dirpad", UsbHidSubmenuIndexDirpad, usb_hid_submenu_callback, app); + submenu_add_item( + app->submenu, "Keyboard", UsbHidSubmenuIndexKeyboard, usb_hid_submenu_callback, app); + submenu_add_item(app->submenu, "Media", UsbHidSubmenuIndexMedia, usb_hid_submenu_callback, app); + submenu_add_item(app->submenu, "Mouse", UsbHidSubmenuIndexMouse, usb_hid_submenu_callback, app); + view_set_previous_callback(submenu_get_view(app->submenu), usb_hid_exit); + view_dispatcher_add_view( + app->view_dispatcher, UsbHidViewSubmenu, submenu_get_view(app->submenu)); + + // Dialog view + app->dialog = dialog_ex_alloc(); + dialog_ex_set_result_callback(app->dialog, usb_hid_dialog_callback); + dialog_ex_set_context(app->dialog, app); + dialog_ex_set_left_button_text(app->dialog, "Exit"); + dialog_ex_set_right_button_text(app->dialog, "Stay"); + dialog_ex_set_center_button_text(app->dialog, "Menu"); + dialog_ex_set_header(app->dialog, "Close Current App?", 16, 12, AlignLeft, AlignTop); + view_dispatcher_add_view( + app->view_dispatcher, UsbHidViewExitConfirm, dialog_ex_get_view(app->dialog)); + + // Dirpad view + app->usb_hid_dirpad = usb_hid_dirpad_alloc(); + view_set_previous_callback( + usb_hid_dirpad_get_view(app->usb_hid_dirpad), usb_hid_exit_confirm_view); + view_dispatcher_add_view( + app->view_dispatcher, UsbHidViewDirpad, usb_hid_dirpad_get_view(app->usb_hid_dirpad)); + + // Keyboard view + app->usb_hid_keyboard = usb_hid_keyboard_alloc(); + view_set_previous_callback( + usb_hid_keyboard_get_view(app->usb_hid_keyboard), usb_hid_exit_confirm_view); + view_dispatcher_add_view( + app->view_dispatcher, UsbHidViewKeyboard, usb_hid_keyboard_get_view(app->usb_hid_keyboard)); + + // Media view + app->usb_hid_media = usb_hid_media_alloc(); + view_set_previous_callback(usb_hid_media_get_view(app->usb_hid_media), usb_hid_exit_confirm_view); + view_dispatcher_add_view( + app->view_dispatcher, UsbHidViewMedia, usb_hid_media_get_view(app->usb_hid_media)); + + // Mouse view + app->usb_hid_mouse = usb_hid_mouse_alloc(); + view_set_previous_callback(usb_hid_mouse_get_view(app->usb_hid_mouse), usb_hid_exit_confirm_view); + view_dispatcher_add_view( + app->view_dispatcher, UsbHidViewMouse, usb_hid_mouse_get_view(app->usb_hid_mouse)); + + // TODO switch to menu after Media is done + app->view_id = UsbHidViewSubmenu; + view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id); + + return app; +} + +void usb_hid_app_free(UsbHid* app) { + furi_assert(app); + + // Reset notification + notification_internal_message(app->notifications, &sequence_reset_blue); + + // Free views + view_dispatcher_remove_view(app->view_dispatcher, UsbHidViewSubmenu); + submenu_free(app->submenu); + view_dispatcher_remove_view(app->view_dispatcher, UsbHidViewExitConfirm); + dialog_ex_free(app->dialog); + view_dispatcher_remove_view(app->view_dispatcher, UsbHidViewDirpad); + usb_hid_dirpad_free(app->usb_hid_dirpad); + view_dispatcher_remove_view(app->view_dispatcher, UsbHidViewKeyboard); + usb_hid_keyboard_free(app->usb_hid_keyboard); + view_dispatcher_remove_view(app->view_dispatcher, UsbHidViewMedia); + usb_hid_media_free(app->usb_hid_media); + view_dispatcher_remove_view(app->view_dispatcher, UsbHidViewMouse); + usb_hid_mouse_free(app->usb_hid_mouse); + view_dispatcher_free(app->view_dispatcher); + // Close records + furi_record_close(RECORD_GUI); + app->gui = NULL; + furi_record_close(RECORD_NOTIFICATION); + app->notifications = NULL; + + // Free rest + free(app); +} + +int32_t usb_hid_app(void* p) { + UNUSED(p); + // Switch profile to Hid + UsbHid* app = usb_hid_app_alloc(); + + FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config(); + furi_hal_usb_unlock(); + furi_check(furi_hal_usb_set_config(&usb_hid, NULL) == true); + + view_dispatcher_run(app->view_dispatcher); + + // Change back profile + furi_hal_usb_set_config(usb_mode_prev, NULL); + usb_hid_app_free(app); + + return 0; +} diff --git a/applications/plugins/usbkeyboard/usb_hid.h b/applications/plugins/usbkeyboard/usb_hid.h new file mode 100644 index 000000000..90c214c48 --- /dev/null +++ b/applications/plugins/usbkeyboard/usb_hid.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include +#include +#include "views/usb_hid_dirpad.h" +#include "views/usb_hid_keyboard.h" +#include "views/usb_hid_media.h" +#include "views/usb_hid_mouse.h" + +typedef struct { + Gui* gui; + NotificationApp* notifications; + ViewDispatcher* view_dispatcher; + Submenu* submenu; + DialogEx* dialog; + UsbHidDirpad* usb_hid_dirpad; + UsbHidKeyboard* usb_hid_keyboard; + UsbHidMedia* usb_hid_media; + UsbHidMouse* usb_hid_mouse; + uint32_t view_id; +} UsbHid; + +typedef enum { + UsbHidViewSubmenu, + UsbHidViewDirpad, + UsbHidViewKeyboard, + UsbHidViewMedia, + UsbHidViewMouse, + UsbHidViewExitConfirm, +} UsbHidView; diff --git a/applications/plugins/usbkeyboard/usb_keyboard_10px.png b/applications/plugins/usbkeyboard/usb_keyboard_10px.png new file mode 100644 index 000000000..7649138eb Binary files /dev/null and b/applications/plugins/usbkeyboard/usb_keyboard_10px.png differ diff --git a/applications/plugins/usbkeyboard/views/usb_hid_dirpad.c b/applications/plugins/usbkeyboard/views/usb_hid_dirpad.c new file mode 100644 index 000000000..32e3d830e --- /dev/null +++ b/applications/plugins/usbkeyboard/views/usb_hid_dirpad.c @@ -0,0 +1,197 @@ +#include "usb_hid_dirpad.h" +#include +#include +#include + +struct UsbHidDirpad { + View* view; +}; + +typedef struct { + bool left_pressed; + bool up_pressed; + bool right_pressed; + bool down_pressed; + bool ok_pressed; + bool back_pressed; + bool connected; +} UsbHidDirpadModel; + +static void usb_hid_dirpad_draw_arrow(Canvas* canvas, uint8_t x, uint8_t y, CanvasDirection dir) { + canvas_draw_triangle(canvas, x, y, 5, 3, dir); + if(dir == CanvasDirectionBottomToTop) { + canvas_draw_line(canvas, x, y + 6, x, y - 1); + } else if(dir == CanvasDirectionTopToBottom) { + canvas_draw_line(canvas, x, y - 6, x, y + 1); + } else if(dir == CanvasDirectionRightToLeft) { + canvas_draw_line(canvas, x + 6, y, x - 1, y); + } else if(dir == CanvasDirectionLeftToRight) { + canvas_draw_line(canvas, x - 6, y, x + 1, y); + } +} + +static void usb_hid_dirpad_draw_callback(Canvas* canvas, void* context) { + furi_assert(context); + UsbHidDirpadModel* model = context; + + canvas_set_font(canvas, FontPrimary); + elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "Dirpad"); + + canvas_draw_icon(canvas, 68, 2, &I_Pin_back_arrow_10x8); + canvas_set_font(canvas, FontSecondary); + elements_multiline_text_aligned(canvas, 127, 3, AlignRight, AlignTop, "Hold to exit"); + + // Up + canvas_draw_icon(canvas, 21, 24, &I_Button_18x18); + if(model->up_pressed) { + elements_slightly_rounded_box(canvas, 24, 26, 13, 13); + canvas_set_color(canvas, ColorWhite); + } + usb_hid_dirpad_draw_arrow(canvas, 30, 30, CanvasDirectionBottomToTop); + canvas_set_color(canvas, ColorBlack); + + // Down + canvas_draw_icon(canvas, 21, 45, &I_Button_18x18); + if(model->down_pressed) { + elements_slightly_rounded_box(canvas, 24, 47, 13, 13); + canvas_set_color(canvas, ColorWhite); + } + usb_hid_dirpad_draw_arrow(canvas, 30, 55, CanvasDirectionTopToBottom); + canvas_set_color(canvas, ColorBlack); + + // Left + canvas_draw_icon(canvas, 0, 45, &I_Button_18x18); + if(model->left_pressed) { + elements_slightly_rounded_box(canvas, 3, 47, 13, 13); + canvas_set_color(canvas, ColorWhite); + } + usb_hid_dirpad_draw_arrow(canvas, 7, 53, CanvasDirectionRightToLeft); + canvas_set_color(canvas, ColorBlack); + + // Right + canvas_draw_icon(canvas, 42, 45, &I_Button_18x18); + if(model->right_pressed) { + elements_slightly_rounded_box(canvas, 45, 47, 13, 13); + canvas_set_color(canvas, ColorWhite); + } + usb_hid_dirpad_draw_arrow(canvas, 53, 53, CanvasDirectionLeftToRight); + canvas_set_color(canvas, ColorBlack); + + // Ok + canvas_draw_icon(canvas, 63, 25, &I_Space_65x18); + if(model->ok_pressed) { + elements_slightly_rounded_box(canvas, 66, 27, 60, 13); + canvas_set_color(canvas, ColorWhite); + } + canvas_draw_icon(canvas, 74, 29, &I_Ok_btn_9x9); + elements_multiline_text_aligned(canvas, 91, 36, AlignLeft, AlignBottom, "Space"); + canvas_set_color(canvas, ColorBlack); + + // Back + canvas_draw_icon(canvas, 63, 45, &I_Space_65x18); + if(model->back_pressed) { + elements_slightly_rounded_box(canvas, 66, 47, 60, 13); + canvas_set_color(canvas, ColorWhite); + } + canvas_draw_icon(canvas, 74, 49, &I_Pin_back_arrow_10x8); + elements_multiline_text_aligned(canvas, 91, 57, AlignLeft, AlignBottom, "Back"); +} + +static void usb_hid_dirpad_process(UsbHidDirpad* usb_hid_dirpad, InputEvent* event) { + with_view_model( + usb_hid_dirpad->view, (UsbHidDirpadModel * model) { + if(event->type == InputTypePress) { + if(event->key == InputKeyUp) { + model->up_pressed = true; + furi_hal_hid_kb_press(HID_KEYBOARD_UP_ARROW); + } else if(event->key == InputKeyDown) { + model->down_pressed = true; + furi_hal_hid_kb_press(HID_KEYBOARD_DOWN_ARROW); + } else if(event->key == InputKeyLeft) { + model->left_pressed = true; + furi_hal_hid_kb_press(HID_KEYBOARD_LEFT_ARROW); + } else if(event->key == InputKeyRight) { + model->right_pressed = true; + furi_hal_hid_kb_press(HID_KEYBOARD_RIGHT_ARROW); + } else if(event->key == InputKeyOk) { + model->ok_pressed = true; + furi_hal_hid_kb_press(HID_KEYBOARD_SPACEBAR); + } else if(event->key == InputKeyBack) { + model->back_pressed = true; + } + } else if(event->type == InputTypeRelease) { + if(event->key == InputKeyUp) { + model->up_pressed = false; + furi_hal_hid_kb_release(HID_KEYBOARD_UP_ARROW); + } else if(event->key == InputKeyDown) { + model->down_pressed = false; + furi_hal_hid_kb_release(HID_KEYBOARD_DOWN_ARROW); + } else if(event->key == InputKeyLeft) { + model->left_pressed = false; + furi_hal_hid_kb_release(HID_KEYBOARD_LEFT_ARROW); + } else if(event->key == InputKeyRight) { + model->right_pressed = false; + furi_hal_hid_kb_release(HID_KEYBOARD_RIGHT_ARROW); + } else if(event->key == InputKeyOk) { + model->ok_pressed = false; + furi_hal_hid_kb_release(HID_KEYBOARD_SPACEBAR); + } else if(event->key == InputKeyBack) { + model->back_pressed = false; + } + } else if(event->type == InputTypeShort) { + if(event->key == InputKeyBack) { + furi_hal_hid_kb_press(HID_KEYBOARD_DELETE); + furi_hal_hid_kb_release(HID_KEYBOARD_DELETE); + furi_hal_hid_consumer_key_press(HID_CONSUMER_AC_BACK); + furi_hal_hid_consumer_key_release(HID_CONSUMER_AC_BACK); + } + } + return true; + }); +} + +static bool usb_hid_dirpad_input_callback(InputEvent* event, void* context) { + furi_assert(context); + UsbHidDirpad* usb_hid_dirpad = context; + bool consumed = false; + + if(event->type == InputTypeLong && event->key == InputKeyBack) { + furi_hal_hid_kb_release_all(); + } else { + usb_hid_dirpad_process(usb_hid_dirpad, event); + consumed = true; + } + + return consumed; +} + +UsbHidDirpad* usb_hid_dirpad_alloc() { + UsbHidDirpad* usb_hid_dirpad = malloc(sizeof(UsbHidDirpad)); + usb_hid_dirpad->view = view_alloc(); + view_set_context(usb_hid_dirpad->view, usb_hid_dirpad); + view_allocate_model(usb_hid_dirpad->view, ViewModelTypeLocking, sizeof(UsbHidDirpadModel)); + view_set_draw_callback(usb_hid_dirpad->view, usb_hid_dirpad_draw_callback); + view_set_input_callback(usb_hid_dirpad->view, usb_hid_dirpad_input_callback); + + return usb_hid_dirpad; +} + +void usb_hid_dirpad_free(UsbHidDirpad* usb_hid_dirpad) { + furi_assert(usb_hid_dirpad); + view_free(usb_hid_dirpad->view); + free(usb_hid_dirpad); +} + +View* usb_hid_dirpad_get_view(UsbHidDirpad* usb_hid_dirpad) { + furi_assert(usb_hid_dirpad); + return usb_hid_dirpad->view; +} + +void usb_hid_dirpad_set_connected_status(UsbHidDirpad* usb_hid_dirpad, bool connected) { + furi_assert(usb_hid_dirpad); + with_view_model( + usb_hid_dirpad->view, (UsbHidDirpadModel * model) { + model->connected = connected; + return true; + }); +} diff --git a/applications/plugins/usbkeyboard/views/usb_hid_dirpad.h b/applications/plugins/usbkeyboard/views/usb_hid_dirpad.h new file mode 100644 index 000000000..305e051b4 --- /dev/null +++ b/applications/plugins/usbkeyboard/views/usb_hid_dirpad.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +typedef struct UsbHidDirpad UsbHidDirpad; + +UsbHidDirpad* usb_hid_dirpad_alloc(); + +void usb_hid_dirpad_free(UsbHidDirpad* usb_hid_dirpad); + +View* usb_hid_dirpad_get_view(UsbHidDirpad* usb_hid_dirpad); + +void usb_hid_dirpad_set_connected_status(UsbHidDirpad* usb_hid_dirpad, bool connected); diff --git a/applications/plugins/usbkeyboard/views/usb_hid_keyboard.c b/applications/plugins/usbkeyboard/views/usb_hid_keyboard.c new file mode 100644 index 000000000..11c330574 --- /dev/null +++ b/applications/plugins/usbkeyboard/views/usb_hid_keyboard.c @@ -0,0 +1,371 @@ +#include "usb_hid_keyboard.h" +#include +#include +#include +#include + +struct UsbHidKeyboard { + View* view; +}; + +typedef struct { + bool shift; + bool alt; + bool ctrl; + bool gui; + uint8_t x; + uint8_t y; + uint8_t last_key_code; + uint16_t modifier_code; + bool ok_pressed; + bool back_pressed; + bool connected; + char key_string[5]; +} UsbHidKeyboardModel; + +typedef struct { + uint8_t width; + char* key; + const Icon* icon; + char* shift_key; + uint8_t value; +} UsbHidKeyboardKey; + +typedef struct { + int8_t x; + int8_t y; +} UsbHidKeyboardPoint; + +// 4 BY 12 +#define MARGIN_TOP 0 +#define MARGIN_LEFT 4 +#define KEY_WIDTH 9 +#define KEY_HEIGHT 12 +#define KEY_PADDING 1 +#define ROW_COUNT 6 +#define COLUMN_COUNT 12 + +// 0 width items are not drawn, but there value is used +const UsbHidKeyboardKey usb_hid_keyboard_keyset[ROW_COUNT][COLUMN_COUNT] = { + { + {.width = 1, .icon = NULL, .key = "1", .shift_key = "!", .value = HID_KEYBOARD_1}, + {.width = 1, .icon = NULL, .key = "2", .shift_key = "@", .value = HID_KEYBOARD_2}, + {.width = 1, .icon = NULL, .key = "3", .shift_key = "#", .value = HID_KEYBOARD_3}, + {.width = 1, .icon = NULL, .key = "4", .shift_key = "$", .value = HID_KEYBOARD_4}, + {.width = 1, .icon = NULL, .key = "5", .shift_key = "%", .value = HID_KEYBOARD_5}, + {.width = 1, .icon = NULL, .key = "6", .shift_key = "^", .value = HID_KEYBOARD_6}, + {.width = 1, .icon = NULL, .key = "7", .shift_key = "&", .value = HID_KEYBOARD_7}, + {.width = 1, .icon = NULL, .key = "8", .shift_key = "*", .value = HID_KEYBOARD_8}, + {.width = 1, .icon = NULL, .key = "9", .shift_key = "(", .value = HID_KEYBOARD_9}, + {.width = 1, .icon = NULL, .key = "0", .shift_key = ")", .value = HID_KEYBOARD_0}, + {.width = 2, .icon = &I_Pin_arrow_left_9x7, .value = HID_KEYBOARD_DELETE}, + {.width = 0, .value = HID_KEYBOARD_DELETE}, + }, + { + {.width = 1, .icon = NULL, .key = "q", .shift_key = "Q", .value = HID_KEYBOARD_Q}, + {.width = 1, .icon = NULL, .key = "w", .shift_key = "W", .value = HID_KEYBOARD_W}, + {.width = 1, .icon = NULL, .key = "e", .shift_key = "E", .value = HID_KEYBOARD_E}, + {.width = 1, .icon = NULL, .key = "r", .shift_key = "R", .value = HID_KEYBOARD_R}, + {.width = 1, .icon = NULL, .key = "t", .shift_key = "T", .value = HID_KEYBOARD_T}, + {.width = 1, .icon = NULL, .key = "y", .shift_key = "Y", .value = HID_KEYBOARD_Y}, + {.width = 1, .icon = NULL, .key = "u", .shift_key = "U", .value = HID_KEYBOARD_U}, + {.width = 1, .icon = NULL, .key = "i", .shift_key = "I", .value = HID_KEYBOARD_I}, + {.width = 1, .icon = NULL, .key = "o", .shift_key = "O", .value = HID_KEYBOARD_O}, + {.width = 1, .icon = NULL, .key = "p", .shift_key = "P", .value = HID_KEYBOARD_P}, + {.width = 1, .icon = NULL, .key = "[", .shift_key = "{", .value = HID_KEYBOARD_OPEN_BRACKET}, + {.width = 1, + .icon = NULL, + .key = "]", + .shift_key = "}", + .value = HID_KEYBOARD_CLOSE_BRACKET}, + }, + { + {.width = 1, .icon = NULL, .key = "a", .shift_key = "A", .value = HID_KEYBOARD_A}, + {.width = 1, .icon = NULL, .key = "s", .shift_key = "S", .value = HID_KEYBOARD_S}, + {.width = 1, .icon = NULL, .key = "d", .shift_key = "D", .value = HID_KEYBOARD_D}, + {.width = 1, .icon = NULL, .key = "f", .shift_key = "F", .value = HID_KEYBOARD_F}, + {.width = 1, .icon = NULL, .key = "g", .shift_key = "G", .value = HID_KEYBOARD_G}, + {.width = 1, .icon = NULL, .key = "h", .shift_key = "H", .value = HID_KEYBOARD_H}, + {.width = 1, .icon = NULL, .key = "j", .shift_key = "J", .value = HID_KEYBOARD_J}, + {.width = 1, .icon = NULL, .key = "k", .shift_key = "K", .value = HID_KEYBOARD_K}, + {.width = 1, .icon = NULL, .key = "l", .shift_key = "L", .value = HID_KEYBOARD_L}, + {.width = 1, .icon = NULL, .key = ";", .shift_key = ":", .value = HID_KEYBOARD_SEMICOLON}, + {.width = 2, .icon = &I_Pin_arrow_right_9x7, .value = HID_KEYBOARD_RETURN}, + {.width = 0, .value = HID_KEYBOARD_RETURN}, + }, + { + {.width = 1, .icon = NULL, .key = "z", .shift_key = "Z", .value = HID_KEYBOARD_Z}, + {.width = 1, .icon = NULL, .key = "x", .shift_key = "X", .value = HID_KEYBOARD_X}, + {.width = 1, .icon = NULL, .key = "c", .shift_key = "C", .value = HID_KEYBOARD_C}, + {.width = 1, .icon = NULL, .key = "v", .shift_key = "V", .value = HID_KEYBOARD_V}, + {.width = 1, .icon = NULL, .key = "b", .shift_key = "B", .value = HID_KEYBOARD_B}, + {.width = 1, .icon = NULL, .key = "n", .shift_key = "N", .value = HID_KEYBOARD_N}, + {.width = 1, .icon = NULL, .key = "m", .shift_key = "M", .value = HID_KEYBOARD_M}, + {.width = 1, .icon = NULL, .key = "/", .shift_key = "?", .value = HID_KEYBOARD_SLASH}, + {.width = 1, .icon = NULL, .key = "\\", .shift_key = "|", .value = HID_KEYBOARD_BACKSLASH}, + {.width = 1, .icon = NULL, .key = "`", .shift_key = "~", .value = HID_KEYBOARD_GRAVE_ACCENT}, + {.width = 1, .icon = &I_ButtonUp_7x4, .value = HID_KEYBOARD_UP_ARROW}, + {.width = 1, .icon = NULL, .key = "-", .shift_key = "_", .value = HID_KEYBOARD_MINUS}, + }, + { + {.width = 1, .icon = &I_Pin_arrow_up_7x9, .value = HID_KEYBOARD_L_SHIFT}, + {.width = 1, .icon = NULL, .key = ",", .shift_key = "<", .value = HID_KEYPAD_COMMA}, + {.width = 1, .icon = NULL, .key = ".", .shift_key = ">", .value = HID_KEYBOARD_DOT}, + {.width = 4, .icon = NULL, .key = " ", .value = HID_KEYBOARD_SPACEBAR}, + {.width = 0, .value = HID_KEYBOARD_SPACEBAR}, + {.width = 0, .value = HID_KEYBOARD_SPACEBAR}, + {.width = 0, .value = HID_KEYBOARD_SPACEBAR}, + {.width = 1, .icon = NULL, .key = "'", .shift_key = "\"", .value = HID_KEYBOARD_APOSTROPHE}, + {.width = 1, .icon = NULL, .key = "=", .shift_key = "+", .value = HID_KEYBOARD_EQUAL_SIGN}, + {.width = 1, .icon = &I_ButtonLeft_4x7, .value = HID_KEYBOARD_LEFT_ARROW}, + {.width = 1, .icon = &I_ButtonDown_7x4, .value = HID_KEYBOARD_DOWN_ARROW}, + {.width = 1, .icon = &I_ButtonRight_4x7, .value = HID_KEYBOARD_RIGHT_ARROW}, + }, + { + {.width = 3, .icon = NULL, .key = "Ctrl", .value = HID_KEYBOARD_L_CTRL}, + {.width = 0, .icon = NULL, .value = HID_KEYBOARD_L_CTRL}, + {.width = 0, .icon = NULL, .value = HID_KEYBOARD_L_CTRL}, + {.width = 3, .icon = NULL, .key = "Alt", .value = HID_KEYBOARD_L_ALT}, + {.width = 0, .icon = NULL, .value = HID_KEYBOARD_L_ALT}, + {.width = 0, .icon = NULL, .value = HID_KEYBOARD_L_ALT}, + {.width = 3, .icon = NULL, .key = "Cmd", .value = HID_KEYBOARD_L_GUI}, + {.width = 0, .icon = NULL, .value = HID_KEYBOARD_L_GUI}, + {.width = 0, .icon = NULL, .value = HID_KEYBOARD_L_GUI}, + {.width = 3, .icon = NULL, .key = "Tab", .value = HID_KEYBOARD_TAB}, + {.width = 0, .icon = NULL, .value = HID_KEYBOARD_TAB}, + {.width = 0, .icon = NULL, .value = HID_KEYBOARD_TAB}, + }, +}; + +static void usb_hid_keyboard_to_upper(char* str) { + while(*str) { + *str = toupper((unsigned char)*str); + str++; + } +} + +static void usb_hid_keyboard_draw_key( + Canvas* canvas, + UsbHidKeyboardModel* model, + uint8_t x, + uint8_t y, + UsbHidKeyboardKey key, + bool selected) { + if(!key.width) return; + + canvas_set_color(canvas, ColorBlack); + uint8_t keyWidth = KEY_WIDTH * key.width + KEY_PADDING * (key.width - 1); + if(selected) { + // Draw a filled box + elements_slightly_rounded_box( + canvas, + MARGIN_LEFT + x * (KEY_WIDTH + KEY_PADDING), + MARGIN_TOP + y * (KEY_HEIGHT + KEY_PADDING), + keyWidth, + KEY_HEIGHT); + canvas_set_color(canvas, ColorWhite); + } else { + // Draw a framed box + elements_slightly_rounded_frame( + canvas, + MARGIN_LEFT + x * (KEY_WIDTH + KEY_PADDING), + MARGIN_TOP + y * (KEY_HEIGHT + KEY_PADDING), + keyWidth, + KEY_HEIGHT); + } + if(key.icon != NULL) { + // Draw the icon centered on the button + canvas_draw_icon( + canvas, + MARGIN_LEFT + x * (KEY_WIDTH + KEY_PADDING) + keyWidth / 2 - key.icon->width / 2, + MARGIN_TOP + y * (KEY_HEIGHT + KEY_PADDING) + KEY_HEIGHT / 2 - key.icon->height / 2, + key.icon); + } else { + // If shift is toggled use the shift key when available + strcpy(model->key_string, (model->shift && key.shift_key != 0) ? key.shift_key : key.key); + // Upper case if ctrl or alt was toggled true + if((model->ctrl && key.value == HID_KEYBOARD_L_CTRL) || + (model->alt && key.value == HID_KEYBOARD_L_ALT) || + (model->gui && key.value == HID_KEYBOARD_L_GUI)) { + usb_hid_keyboard_to_upper(model->key_string); + } + canvas_draw_str_aligned( + canvas, + MARGIN_LEFT + x * (KEY_WIDTH + KEY_PADDING) + keyWidth / 2 + 1, + MARGIN_TOP + y * (KEY_HEIGHT + KEY_PADDING) + KEY_HEIGHT / 2, + AlignCenter, + AlignCenter, + model->key_string); + } +} + +static void usb_hid_keyboard_draw_callback(Canvas* canvas, void* context) { + furi_assert(context); + UsbHidKeyboardModel* model = context; + + canvas_set_font(canvas, FontKeyboard); + // Start shifting the all keys up if on the next row (Scrolling) + uint8_t initY = model->y - 4 > 0 ? model->y - 4 : 0; + for(uint8_t y = initY; y < ROW_COUNT; y++) { + const UsbHidKeyboardKey* keyboardKeyRow = usb_hid_keyboard_keyset[y]; + uint8_t x = 0; + for(uint8_t i = 0; i < COLUMN_COUNT; i++) { + UsbHidKeyboardKey key = keyboardKeyRow[i]; + // Select when the button is hovered + // Select if the button is hovered within its width + // Select if back is clicked and its the backspace key + // Deselect when the button clicked or not hovered + bool keySelected = (x <= model->x && model->x < (x + key.width)) && y == model->y; + bool backSelected = model->back_pressed && key.value == HID_KEYBOARD_DELETE; + usb_hid_keyboard_draw_key( + canvas, + model, + x, + y - initY, + key, + (!model->ok_pressed && keySelected) || backSelected); + x += key.width; + } + } +} + +static uint8_t usb_hid_keyboard_get_selected_key(UsbHidKeyboardModel* model) { + UsbHidKeyboardKey key = usb_hid_keyboard_keyset[model->y][model->x]; + // Use upper case if shift is toggled + bool useUppercase = model->shift; + // Check if the key has an upper case version + bool hasUppercase = key.shift_key != 0; + if(useUppercase && hasUppercase) + return key.value; + else + return key.value; +} + +static void usb_hid_keyboard_get_select_key(UsbHidKeyboardModel* model, UsbHidKeyboardPoint delta) { + // Keep going until a valid spot is found, this allows for nulls and zero width keys in the map + do { + if(((int8_t)model->y) + delta.y < 0) + model->y = ROW_COUNT - 1; + else + model->y = (model->y + delta.y) % ROW_COUNT; + } while(delta.y != 0 && usb_hid_keyboard_keyset[model->y][model->x].value == 0); + + do { + if(((int8_t)model->x) + delta.x < 0) + model->x = COLUMN_COUNT - 1; + else + model->x = (model->x + delta.x) % COLUMN_COUNT; + } while(delta.x != 0 && usb_hid_keyboard_keyset[model->y][model->x].width == + 0); // Skip zero width keys, pretend they are one key +} + +static void usb_hid_keyboard_process(UsbHidKeyboard* usb_hid_keyboard, InputEvent* event) { + with_view_model( + usb_hid_keyboard->view, (UsbHidKeyboardModel * model) { + if(event->key == InputKeyOk) { + if(event->type == InputTypePress) { + model->ok_pressed = true; + } else if(event->type == InputTypeLong || event->type == InputTypeShort) { + model->last_key_code = usb_hid_keyboard_get_selected_key(model); + + // Toggle the modifier key when clicked, and click the key + if(model->last_key_code == HID_KEYBOARD_L_SHIFT) { + model->shift = !model->shift; + if(model->shift) + model->modifier_code |= KEY_MOD_LEFT_SHIFT; + else + model->modifier_code &= ~KEY_MOD_LEFT_SHIFT; + } else if(model->last_key_code == HID_KEYBOARD_L_ALT) { + model->alt = !model->alt; + if(model->alt) + model->modifier_code |= KEY_MOD_LEFT_ALT; + else + model->modifier_code &= ~KEY_MOD_LEFT_ALT; + } else if(model->last_key_code == HID_KEYBOARD_L_CTRL) { + model->ctrl = !model->ctrl; + if(model->ctrl) + model->modifier_code |= KEY_MOD_LEFT_CTRL; + else + model->modifier_code &= ~KEY_MOD_LEFT_CTRL; + } else if(model->last_key_code == HID_KEYBOARD_L_GUI) { + model->gui = !model->gui; + if(model->gui) + model->modifier_code |= KEY_MOD_LEFT_GUI; + else + model->modifier_code &= ~KEY_MOD_LEFT_GUI; + } + furi_hal_hid_kb_press(model->modifier_code | model->last_key_code); + } else if(event->type == InputTypeRelease) { + // Release happens after short and long presses + furi_hal_hid_kb_release(model->modifier_code | model->last_key_code); + model->ok_pressed = false; + } + } else if(event->key == InputKeyBack) { + // If back is pressed for a short time, backspace + if(event->type == InputTypePress) { + model->back_pressed = true; + } else if(event->type == InputTypeShort) { + furi_hal_hid_kb_press(HID_KEYBOARD_DELETE); + furi_hal_hid_kb_release(HID_KEYBOARD_DELETE); + } else if(event->type == InputTypeRelease) { + model->back_pressed = false; + } + } else if(event->type == InputTypePress || event->type == InputTypeRepeat) { + // Cycle the selected keys + if(event->key == InputKeyUp) { + usb_hid_keyboard_get_select_key(model, (UsbHidKeyboardPoint){.x = 0, .y = -1}); + } else if(event->key == InputKeyDown) { + usb_hid_keyboard_get_select_key(model, (UsbHidKeyboardPoint){.x = 0, .y = 1}); + } else if(event->key == InputKeyLeft) { + usb_hid_keyboard_get_select_key(model, (UsbHidKeyboardPoint){.x = -1, .y = 0}); + } else if(event->key == InputKeyRight) { + usb_hid_keyboard_get_select_key(model, (UsbHidKeyboardPoint){.x = 1, .y = 0}); + } + } + return true; + }); +} + +static bool usb_hid_keyboard_input_callback(InputEvent* event, void* context) { + furi_assert(context); + UsbHidKeyboard* usb_hid_keyboard = context; + bool consumed = false; + + if(event->type == InputTypeLong && event->key == InputKeyBack) { + furi_hal_hid_kb_release_all(); + } else { + usb_hid_keyboard_process(usb_hid_keyboard, event); + consumed = true; + } + + return consumed; +} + +UsbHidKeyboard* usb_hid_keyboard_alloc() { + UsbHidKeyboard* usb_hid_keyboard = malloc(sizeof(UsbHidKeyboard)); + + usb_hid_keyboard->view = view_alloc(); + view_set_context(usb_hid_keyboard->view, usb_hid_keyboard); + view_allocate_model(usb_hid_keyboard->view, ViewModelTypeLocking, sizeof(UsbHidKeyboardModel)); + view_set_draw_callback(usb_hid_keyboard->view, usb_hid_keyboard_draw_callback); + view_set_input_callback(usb_hid_keyboard->view, usb_hid_keyboard_input_callback); + + with_view_model( + usb_hid_keyboard->view, (UsbHidKeyboardModel * model) { + model->connected = true; + return true; + }); + + return usb_hid_keyboard; +} + +void usb_hid_keyboard_free(UsbHidKeyboard* usb_hid_keyboard) { + furi_assert(usb_hid_keyboard); + view_free(usb_hid_keyboard->view); + free(usb_hid_keyboard); +} + +View* usb_hid_keyboard_get_view(UsbHidKeyboard* usb_hid_keyboard) { + furi_assert(usb_hid_keyboard); + return usb_hid_keyboard->view; +} \ No newline at end of file diff --git a/applications/plugins/usbkeyboard/views/usb_hid_keyboard.h b/applications/plugins/usbkeyboard/views/usb_hid_keyboard.h new file mode 100644 index 000000000..4dee5fbee --- /dev/null +++ b/applications/plugins/usbkeyboard/views/usb_hid_keyboard.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +typedef struct UsbHidKeyboard UsbHidKeyboard; + +UsbHidKeyboard* usb_hid_keyboard_alloc(); + +void usb_hid_keyboard_free(UsbHidKeyboard* usb_hid_keyboard); + +View* usb_hid_keyboard_get_view(UsbHidKeyboard* usb_hid_keyboard); + +void usb_hid_keyboard_set_connected_status(UsbHidKeyboard* usb_hid_keyboard, bool connected); diff --git a/applications/plugins/usbkeyboard/views/usb_hid_media.c b/applications/plugins/usbkeyboard/views/usb_hid_media.c new file mode 100644 index 000000000..992ca17c9 --- /dev/null +++ b/applications/plugins/usbkeyboard/views/usb_hid_media.c @@ -0,0 +1,202 @@ +#include "usb_hid_media.h" +#include +#include +#include + +struct UsbHidMedia { + View* view; +}; + +typedef struct { + bool left_pressed; + bool up_pressed; + bool right_pressed; + bool down_pressed; + bool ok_pressed; + bool connected; +} UsbHidMediaModel; + +static void usb_hid_media_draw_arrow(Canvas* canvas, uint8_t x, uint8_t y, CanvasDirection dir) { + canvas_draw_triangle(canvas, x, y, 5, 3, dir); + if(dir == CanvasDirectionBottomToTop) { + canvas_draw_dot(canvas, x, y - 1); + } else if(dir == CanvasDirectionTopToBottom) { + canvas_draw_dot(canvas, x, y + 1); + } else if(dir == CanvasDirectionRightToLeft) { + canvas_draw_dot(canvas, x - 1, y); + } else if(dir == CanvasDirectionLeftToRight) { + canvas_draw_dot(canvas, x + 1, y); + } +} + +static void usb_hid_media_draw_callback(Canvas* canvas, void* context) { + furi_assert(context); + UsbHidMediaModel* model = context; + + canvas_set_font(canvas, FontPrimary); + elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "Media"); + canvas_set_font(canvas, FontSecondary); + + // Keypad circles + canvas_draw_icon(canvas, 76, 8, &I_Circles_47x47); + + // Up + if(model->up_pressed) { + canvas_set_bitmap_mode(canvas, 1); + canvas_draw_icon(canvas, 93, 9, &I_Pressed_Button_13x13); + canvas_set_bitmap_mode(canvas, 0); + canvas_set_color(canvas, ColorWhite); + } + canvas_draw_icon(canvas, 96, 12, &I_Volup_8x6); + canvas_set_color(canvas, ColorBlack); + + // Down + if(model->down_pressed) { + canvas_set_bitmap_mode(canvas, 1); + canvas_draw_icon(canvas, 93, 41, &I_Pressed_Button_13x13); + canvas_set_bitmap_mode(canvas, 0); + canvas_set_color(canvas, ColorWhite); + } + canvas_draw_icon(canvas, 96, 45, &I_Voldwn_6x6); + canvas_set_color(canvas, ColorBlack); + + // Left + if(model->left_pressed) { + canvas_set_bitmap_mode(canvas, 1); + canvas_draw_icon(canvas, 77, 25, &I_Pressed_Button_13x13); + canvas_set_bitmap_mode(canvas, 0); + canvas_set_color(canvas, ColorWhite); + } + usb_hid_media_draw_arrow(canvas, 82, 31, CanvasDirectionRightToLeft); + usb_hid_media_draw_arrow(canvas, 86, 31, CanvasDirectionRightToLeft); + canvas_set_color(canvas, ColorBlack); + + // Right + if(model->right_pressed) { + canvas_set_bitmap_mode(canvas, 1); + canvas_draw_icon(canvas, 109, 25, &I_Pressed_Button_13x13); + canvas_set_bitmap_mode(canvas, 0); + canvas_set_color(canvas, ColorWhite); + } + usb_hid_media_draw_arrow(canvas, 112, 31, CanvasDirectionLeftToRight); + usb_hid_media_draw_arrow(canvas, 116, 31, CanvasDirectionLeftToRight); + canvas_set_color(canvas, ColorBlack); + + // Ok + if(model->ok_pressed) { + canvas_draw_icon(canvas, 93, 25, &I_Pressed_Button_13x13); + canvas_set_color(canvas, ColorWhite); + } + usb_hid_media_draw_arrow(canvas, 96, 31, CanvasDirectionLeftToRight); + canvas_draw_line(canvas, 100, 29, 100, 33); + canvas_draw_line(canvas, 102, 29, 102, 33); + canvas_set_color(canvas, ColorBlack); + + // Exit + canvas_draw_icon(canvas, 0, 54, &I_Pin_back_arrow_10x8); + canvas_set_font(canvas, FontSecondary); + elements_multiline_text_aligned(canvas, 13, 62, AlignLeft, AlignBottom, "Hold to exit"); +} + +static void usb_hid_media_process_press(UsbHidMedia* usb_hid_media, InputEvent* event) { + with_view_model( + usb_hid_media->view, (UsbHidMediaModel * model) { + if(event->key == InputKeyUp) { + model->up_pressed = true; + furi_hal_hid_consumer_key_press(HID_CONSUMER_VOLUME_INCREMENT); + } else if(event->key == InputKeyDown) { + model->down_pressed = true; + furi_hal_hid_consumer_key_press(HID_CONSUMER_VOLUME_DECREMENT); + } else if(event->key == InputKeyLeft) { + model->left_pressed = true; + furi_hal_hid_consumer_key_press(HID_CONSUMER_SCAN_PREVIOUS_TRACK); + } else if(event->key == InputKeyRight) { + model->right_pressed = true; + furi_hal_hid_consumer_key_press(HID_CONSUMER_SCAN_NEXT_TRACK); + } else if(event->key == InputKeyOk) { + model->ok_pressed = true; + furi_hal_hid_consumer_key_press(HID_CONSUMER_PLAY_PAUSE); + } + return true; + }); +} + +static void hid_media_process_release(UsbHidMedia* usb_hid_media, InputEvent* event) { + with_view_model( + usb_hid_media->view, (UsbHidMediaModel * model) { + if(event->key == InputKeyUp) { + model->up_pressed = false; + furi_hal_hid_consumer_key_release(HID_CONSUMER_VOLUME_INCREMENT); + } else if(event->key == InputKeyDown) { + model->down_pressed = false; + furi_hal_hid_consumer_key_release(HID_CONSUMER_VOLUME_DECREMENT); + } else if(event->key == InputKeyLeft) { + model->left_pressed = false; + furi_hal_hid_consumer_key_release(HID_CONSUMER_SCAN_PREVIOUS_TRACK); + } else if(event->key == InputKeyRight) { + model->right_pressed = false; + furi_hal_hid_consumer_key_release(HID_CONSUMER_SCAN_NEXT_TRACK); + } else if(event->key == InputKeyOk) { + model->ok_pressed = false; + furi_hal_hid_consumer_key_release(HID_CONSUMER_PLAY_PAUSE); + } + return true; + }); +} + +static bool usb_hid_media_input_callback(InputEvent* event, void* context) { + furi_assert(context); + UsbHidMedia* usb_hid_media = context; + bool consumed = false; + + if(event->type == InputTypePress) { + usb_hid_media_process_press(usb_hid_media, event); + consumed = true; + } else if(event->type == InputTypeRelease) { + hid_media_process_release(usb_hid_media, event); + consumed = true; + } else if(event->type == InputTypeShort) { + if(event->key == InputKeyBack) { + furi_hal_hid_kb_release_all(); + } + } + + return consumed; +} + +UsbHidMedia* usb_hid_media_alloc() { + UsbHidMedia* usb_hid_media = malloc(sizeof(UsbHidMedia)); + usb_hid_media->view = view_alloc(); + view_set_context(usb_hid_media->view, usb_hid_media); + view_allocate_model(usb_hid_media->view, ViewModelTypeLocking, sizeof(UsbHidMediaModel)); + view_set_draw_callback(usb_hid_media->view, usb_hid_media_draw_callback); + view_set_input_callback(usb_hid_media->view, usb_hid_media_input_callback); + + with_view_model( + usb_hid_media->view, (UsbHidMediaModel* model) { + model->connected = true; + return true; + }); + + return usb_hid_media; +} + +void usb_hid_media_free(UsbHidMedia* usb_hid_media) { + furi_assert(usb_hid_media); + view_free(usb_hid_media->view); + free(usb_hid_media); +} + +View* usb_hid_media_get_view(UsbHidMedia* usb_hid_media) { + furi_assert(usb_hid_media); + return usb_hid_media->view; +} + +void usb_hid_media_set_connected_status(UsbHidMedia* usb_hid_media, bool connected) { + furi_assert(usb_hid_media); + with_view_model( + usb_hid_media->view, (UsbHidMediaModel * model) { + model->connected = connected; + return true; + }); +} diff --git a/applications/plugins/usbkeyboard/views/usb_hid_media.h b/applications/plugins/usbkeyboard/views/usb_hid_media.h new file mode 100644 index 000000000..441e2bd6d --- /dev/null +++ b/applications/plugins/usbkeyboard/views/usb_hid_media.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +typedef struct UsbHidMedia UsbHidMedia; + +UsbHidMedia* usb_hid_media_alloc(); + +void usb_hid_media_free(UsbHidMedia* usb_hid_media); + +View* usb_hid_media_get_view(UsbHidMedia* usb_hid_media); + +void usb_hid_media_set_connected_status(UsbHidMedia* usb_hid_media, bool connected); diff --git a/applications/plugins/usbkeyboard/views/usb_hid_mouse.c b/applications/plugins/usbkeyboard/views/usb_hid_mouse.c new file mode 100644 index 000000000..cd8ae6164 --- /dev/null +++ b/applications/plugins/usbkeyboard/views/usb_hid_mouse.c @@ -0,0 +1,216 @@ +#include "usb_hid_mouse.h" +#include +#include +#include + +struct UsbHidMouse { + View* view; +}; +#define MOUSE_MOVE_SHORT 5 +#define MOUSE_MOVE_LONG 20 + +typedef struct { + bool left_pressed; + bool up_pressed; + bool right_pressed; + bool down_pressed; + bool left_mouse_pressed; + bool left_mouse_held; + bool right_mouse_pressed; + bool connected; +} UsbHidMouseModel; + +static void usb_hid_mouse_draw_callback(Canvas* canvas, void* context) { + furi_assert(context); + UsbHidMouseModel* model = context; + + // Header + if(model->connected) { + canvas_draw_icon(canvas, 0, 0, &I_Ble_connected_15x15); + } else { + canvas_draw_icon(canvas, 0, 0, &I_Ble_disconnected_15x15); + } + canvas_set_font(canvas, FontPrimary); + elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "Mouse"); + canvas_set_font(canvas, FontSecondary); + + if(model->left_mouse_held == true) { + elements_multiline_text_aligned(canvas, 0, 62, AlignLeft, AlignBottom, "Selecting..."); + } else { + canvas_draw_icon(canvas, 0, 54, &I_Pin_back_arrow_10x8); + canvas_set_font(canvas, FontSecondary); + elements_multiline_text_aligned(canvas, 13, 62, AlignLeft, AlignBottom, "Hold to exit"); + } + + // Keypad circles + canvas_draw_icon(canvas, 64, 8, &I_Circles_47x47); + + // Up + if(model->up_pressed) { + canvas_set_bitmap_mode(canvas, 1); + canvas_draw_icon(canvas, 81, 9, &I_Pressed_Button_13x13); + canvas_set_bitmap_mode(canvas, 0); + canvas_set_color(canvas, ColorWhite); + } + canvas_draw_icon(canvas, 84, 10, &I_Pin_arrow_up_7x9); + canvas_set_color(canvas, ColorBlack); + + // Down + if(model->down_pressed) { + canvas_set_bitmap_mode(canvas, 1); + canvas_draw_icon(canvas, 81, 41, &I_Pressed_Button_13x13); + canvas_set_bitmap_mode(canvas, 0); + canvas_set_color(canvas, ColorWhite); + } + canvas_draw_icon(canvas, 84, 43, &I_Pin_arrow_down_7x9); + canvas_set_color(canvas, ColorBlack); + + // Left + if(model->left_pressed) { + canvas_set_bitmap_mode(canvas, 1); + canvas_draw_icon(canvas, 65, 25, &I_Pressed_Button_13x13); + canvas_set_bitmap_mode(canvas, 0); + canvas_set_color(canvas, ColorWhite); + } + canvas_draw_icon(canvas, 67, 28, &I_Pin_arrow_left_9x7); + canvas_set_color(canvas, ColorBlack); + + // Right + if(model->right_pressed) { + canvas_set_bitmap_mode(canvas, 1); + canvas_draw_icon(canvas, 97, 25, &I_Pressed_Button_13x13); + canvas_set_bitmap_mode(canvas, 0); + canvas_set_color(canvas, ColorWhite); + } + canvas_draw_icon(canvas, 99, 28, &I_Pin_arrow_right_9x7); + canvas_set_color(canvas, ColorBlack); + + // Ok + if(model->left_mouse_pressed) { + canvas_draw_icon(canvas, 81, 25, &I_Ok_btn_pressed_13x13); + } else { + canvas_draw_icon(canvas, 83, 27, &I_Left_mouse_icon_9x9); + } + + // Back + if(model->right_mouse_pressed) { + canvas_draw_icon(canvas, 108, 48, &I_Ok_btn_pressed_13x13); + } else { + canvas_draw_icon(canvas, 110, 50, &I_Right_mouse_icon_9x9); + } +} + +static void usb_hid_mouse_process(UsbHidMouse* usb_hid_mouse, InputEvent* event) { + with_view_model( + usb_hid_mouse->view, (UsbHidMouseModel * model) { + if(event->key == InputKeyBack) { + if(event->type == InputTypeShort) { + furi_hal_hid_mouse_press(HID_MOUSE_BTN_RIGHT); + furi_hal_hid_mouse_release(HID_MOUSE_BTN_RIGHT); + } else if(event->type == InputTypePress) { + model->right_mouse_pressed = true; + } else if(event->type == InputTypeRelease) { + model->right_mouse_pressed = false; + } + } else if(event->key == InputKeyOk) { + if(event->type == InputTypeShort) { + // Just release if it was being held before + if(!model->left_mouse_held) furi_hal_hid_mouse_press(HID_MOUSE_BTN_LEFT); + furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT); + model->left_mouse_held = false; + } else if(event->type == InputTypeLong) { + furi_hal_hid_mouse_press(HID_MOUSE_BTN_LEFT); + model->left_mouse_held = true; + model->left_mouse_pressed = true; + } else if(event->type == InputTypePress) { + model->left_mouse_pressed = true; + } else if(event->type == InputTypeRelease) { + // Only release if it wasn't a long press + if(!model->left_mouse_held) model->left_mouse_pressed = false; + } + + } else if(event->key == InputKeyRight) { + if(event->type == InputTypePress) { + model->right_pressed = true; + furi_hal_hid_mouse_move(MOUSE_MOVE_SHORT, 0); + } else if(event->type == InputTypeRepeat) { + furi_hal_hid_mouse_move(MOUSE_MOVE_LONG, 0); + } else if(event->type == InputTypeRelease) { + model->right_pressed = false; + } + } else if(event->key == InputKeyLeft) { + if(event->type == InputTypePress) { + model->left_pressed = true; + furi_hal_hid_mouse_move(-MOUSE_MOVE_SHORT, 0); + } else if(event->type == InputTypeRepeat) { + furi_hal_hid_mouse_move(-MOUSE_MOVE_LONG, 0); + } else if(event->type == InputTypeRelease) { + model->left_pressed = false; + } + } else if(event->key == InputKeyDown) { + if(event->type == InputTypePress) { + model->down_pressed = true; + furi_hal_hid_mouse_move(0, MOUSE_MOVE_SHORT); + } else if(event->type == InputTypeRepeat) { + furi_hal_hid_mouse_move(0, MOUSE_MOVE_LONG); + } else if(event->type == InputTypeRelease) { + model->down_pressed = false; + } + } else if(event->key == InputKeyUp) { + if(event->type == InputTypePress) { + model->up_pressed = true; + furi_hal_hid_mouse_move(0, -MOUSE_MOVE_SHORT); + } else if(event->type == InputTypeRepeat) { + furi_hal_hid_mouse_move(0, -MOUSE_MOVE_LONG); + } else if(event->type == InputTypeRelease) { + model->up_pressed = false; + } + } + return true; + }); +} + +static bool usb_hid_mouse_input_callback(InputEvent* event, void* context) { + furi_assert(context); + UsbHidMouse* usb_hid_mouse = context; + bool consumed = false; + + if(event->type == InputTypeLong && event->key == InputKeyBack) { + furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT); + furi_hal_hid_mouse_release(HID_MOUSE_BTN_RIGHT); + } else { + usb_hid_mouse_process(usb_hid_mouse, event); + consumed = true; + } + + return consumed; +} + +UsbHidMouse* usb_hid_mouse_alloc() { + UsbHidMouse* usb_hid_mouse = malloc(sizeof(UsbHidMouse)); + usb_hid_mouse->view = view_alloc(); + view_set_context(usb_hid_mouse->view, usb_hid_mouse); + view_allocate_model(usb_hid_mouse->view, ViewModelTypeLocking, sizeof(UsbHidMouseModel)); + view_set_draw_callback(usb_hid_mouse->view, usb_hid_mouse_draw_callback); + view_set_input_callback(usb_hid_mouse->view, usb_hid_mouse_input_callback); + + with_view_model( + usb_hid_mouse->view, (UsbHidMouseModel* model) { + model->connected = true; + return true; + }); + + return usb_hid_mouse; +} + +void usb_hid_mouse_free(UsbHidMouse* usb_hid_mouse) { + furi_assert(usb_hid_mouse); + view_free(usb_hid_mouse->view); + free(usb_hid_mouse); +} + +View* usb_hid_mouse_get_view(UsbHidMouse* usb_hid_mouse) { + furi_assert(usb_hid_mouse); + return usb_hid_mouse->view; +} + diff --git a/applications/plugins/usbkeyboard/views/usb_hid_mouse.h b/applications/plugins/usbkeyboard/views/usb_hid_mouse.h new file mode 100644 index 000000000..e7eec9224 --- /dev/null +++ b/applications/plugins/usbkeyboard/views/usb_hid_mouse.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +typedef struct UsbHidMouse UsbHidMouse; + +UsbHidMouse* usb_hid_mouse_alloc(); + +void usb_hid_mouse_free(UsbHidMouse* usb_hid_mouse); + +View* usb_hid_mouse_get_view(UsbHidMouse* usb_hid_mouse); + +void usb_hid_mouse_set_connected_status(UsbHidMouse* usb_hid_mouse, bool connected);