Merge branch 'release-candidate' into release
							
								
								
									
										66
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						| @ -1,6 +1,13 @@ | ||||
| name: 'Build' | ||||
| 
 | ||||
| on: push | ||||
| on:  | ||||
|   push: | ||||
|     branches: | ||||
|       - dev | ||||
|       - "release*" | ||||
|     tags: | ||||
|       - '*' | ||||
|   pull_request: | ||||
| 
 | ||||
| env: | ||||
|   TARGETS: f6 | ||||
| @ -58,18 +65,6 @@ jobs: | ||||
|               make -j$(nproc) -C bootloader TARGET=${TARGET} | ||||
|             done | ||||
| 
 | ||||
|       - name: 'Generate dfu file for bootloader' | ||||
|         uses: ./.github/actions/docker | ||||
|         with: | ||||
|           run: | | ||||
|             for TARGET in ${TARGETS} | ||||
|             do | ||||
|               hex2dfu \ | ||||
|                 -i bootloader/.obj/${TARGET}/bootloader.hex \ | ||||
|                 -o bootloader/.obj/${TARGET}/bootloader.dfu \ | ||||
|                 -l "Flipper Zero $(echo $TARGET | tr a-z A-Z)" | ||||
|             done | ||||
| 
 | ||||
|       - name: 'Build firmware in docker' | ||||
|         uses: ./.github/actions/docker | ||||
|         with: | ||||
| @ -79,19 +74,8 @@ jobs: | ||||
|               make -j$(nproc) -C firmware TARGET=${TARGET} | ||||
|             done | ||||
| 
 | ||||
|       - name: 'Generate dfu file for firmware' | ||||
|         uses: ./.github/actions/docker | ||||
|         with: | ||||
|           run: | | ||||
|             for TARGET in ${TARGETS} | ||||
|             do | ||||
|               hex2dfu \ | ||||
|                 -i firmware/.obj/${TARGET}/firmware.hex \ | ||||
|                 -o firmware/.obj/${TARGET}/firmware.dfu \ | ||||
|                 -l "Flipper Zero $(echo $TARGET | tr a-z A-Z)" | ||||
|             done | ||||
| 
 | ||||
|       - name: 'Generate full hex file' | ||||
|         if: ${{ !github.event.pull_request.head.repo.fork }} | ||||
|         uses: ./.github/actions/docker | ||||
|         with: | ||||
|           run: | | ||||
| @ -104,6 +88,7 @@ jobs: | ||||
|             done | ||||
| 
 | ||||
|       - name: 'Move upload files' | ||||
|         if: ${{ !github.event.pull_request.head.repo.fork }} | ||||
|         uses: ./.github/actions/docker | ||||
|         with: | ||||
|           run: | | ||||
| @ -124,6 +109,7 @@ jobs: | ||||
|             done | ||||
| 
 | ||||
|       - name: 'Generate full dfu file' | ||||
|         if: ${{ !github.event.pull_request.head.repo.fork }} | ||||
|         uses: ./.github/actions/docker | ||||
|         with: | ||||
|           run: | | ||||
| @ -136,6 +122,7 @@ jobs: | ||||
|             done | ||||
| 
 | ||||
|       - name: 'Full flash asssembly: bootloader as base' | ||||
|         if: ${{ !github.event.pull_request.head.repo.fork }} | ||||
|         run: | | ||||
|           for TARGET in ${TARGETS} | ||||
|           do | ||||
| @ -145,13 +132,15 @@ jobs: | ||||
|           done | ||||
| 
 | ||||
|       - name: 'Full flash asssembly: bootloader padding' | ||||
|         if: ${{ !github.event.pull_request.head.repo.fork }} | ||||
|         run: | | ||||
|           for TARGET in ${TARGETS} | ||||
|           do | ||||
|             truncate -s 32768 artifacts/flipper-z-${TARGET}-full-${SUFFIX}.bin | ||||
|           done | ||||
|        | ||||
| 
 | ||||
|       - name: 'Full flash asssembly: append firmware' | ||||
|         if: ${{ !github.event.pull_request.head.repo.fork }} | ||||
|         run: | | ||||
|           for TARGET in ${TARGETS} | ||||
|           do | ||||
| @ -160,7 +149,31 @@ jobs: | ||||
|               >> artifacts/flipper-z-${TARGET}-full-${SUFFIX}.bin | ||||
|           done | ||||
| 
 | ||||
|       - name: 'Bundle core2 firmware' | ||||
|         if: ${{ !github.event.pull_request.head.repo.fork }} | ||||
|         run: | | ||||
|           test -d core2_firmware && rm -rf core2_firmware || true | ||||
|           mkdir core2_firmware | ||||
|           cp \ | ||||
|             lib/STM32CubeWB/package.xml \ | ||||
|             lib/STM32CubeWB/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/stm32wb5x_FUS_fw.bin \ | ||||
|             lib/STM32CubeWB/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/stm32wb5x_FUS_fw_for_fus_0_5_3.bin \ | ||||
|             lib/STM32CubeWB/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/stm32wb5x_BLE_Stack_full_fw.bin \ | ||||
|             core2_firmware | ||||
|           tar czpf artifacts/flipper-z-any-core2_firmware-${SUFFIX}.tgz core2_firmware | ||||
| 
 | ||||
|       - name: 'Bundle scripts' | ||||
|         if: ${{ !github.event.pull_request.head.repo.fork }} | ||||
|         run: | | ||||
|           tar czpf artifacts/flipper-z-any-scripts-${SUFFIX}.tgz scripts | ||||
| 
 | ||||
|       - name: 'Bundle resources' | ||||
|         if: ${{ !github.event.pull_request.head.repo.fork }} | ||||
|         run: | | ||||
|           tar czpf artifacts/flipper-z-any-resources-${SUFFIX}.tgz -C assets resources | ||||
| 
 | ||||
|       - name: 'Upload artifacts to update server' | ||||
|         if: ${{ !github.event.pull_request.head.repo.fork }} | ||||
|         uses: burnett01/rsync-deployments@4.1 | ||||
|         with: | ||||
|           switches: -avzP --delete | ||||
| @ -172,6 +185,7 @@ jobs: | ||||
|           remote_key: ${{ secrets.RSYNC_DEPLOY_KEY }} | ||||
| 
 | ||||
|       - name: 'Trigger update server reindex' | ||||
|         if: ${{ !github.event.pull_request.head.repo.fork }} | ||||
|         uses: wei/curl@master | ||||
|         with: | ||||
|           args: -X POST -F 'key=${{ secrets.REINDEX_KEY }}' ${{ secrets.REINDEX_URL }} | ||||
|  | ||||
							
								
								
									
										46
									
								
								.github/workflows/build_toolchain.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,46 @@ | ||||
| name: 'Build toolchain Docker image' | ||||
| 
 | ||||
| on: | ||||
|   push: | ||||
|     branches: | ||||
|       - dev | ||||
|     tags: | ||||
|       - '*' | ||||
| 
 | ||||
| jobs: | ||||
|   build: | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|       - name: Checkout code | ||||
|         uses: actions/checkout@v2 | ||||
|         with: | ||||
|           fetch-depth: 0 | ||||
|       - name: Docker meta | ||||
|         id: meta | ||||
|         uses: docker/metadata-action@v3 | ||||
|         with: | ||||
|           images: flipperdevices/flipperzero-toolchain | ||||
|           flavor: latest=${{ startsWith(github.ref, 'refs/tags/') && !endsWith(github.ref, 'rc')}} | ||||
|           tags: | | ||||
|             type=ref,event=branch | ||||
|             type=ref,event=tag | ||||
|       - name: Set up QEMU | ||||
|         uses: docker/setup-qemu-action@v1 | ||||
|       - name: Set up Docker Buildx | ||||
|         uses: docker/setup-buildx-action@v1 | ||||
|       - name: Login to DockerHub | ||||
|         uses: docker/login-action@v1 | ||||
|         with: | ||||
|           username: ${{ secrets.DOCKERHUB_USERNAME }} | ||||
|           password: ${{ secrets.DOCKERHUB_TOKEN }} | ||||
|       - name: Build and push | ||||
|         id: docker_build | ||||
|         uses: docker/build-push-action@v2 | ||||
|         with: | ||||
|           context: docker/ | ||||
|           push: true | ||||
|           tags: ${{ steps.meta.outputs.tags }} | ||||
|           labels: ${{ steps.meta.outputs.labels }} | ||||
|           platforms: linux/amd64,linux/arm64 | ||||
|           cache-from: type=registry,ref=flipperdevices/flipperzero-toolchain:buildcache | ||||
|           cache-to: type=registry,ref=flipperdevices/flipperzero-toolchain:buildcache,mode=max | ||||
							
								
								
									
										25
									
								
								.github/workflows/lint_c.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						| @ -1,6 +1,13 @@ | ||||
| name: 'Lint C/C++ with clang-format' | ||||
| 
 | ||||
| on: pull_request | ||||
| on:  | ||||
|   push: | ||||
|     branches: | ||||
|       - dev | ||||
|       - "release*" | ||||
|     tags: | ||||
|       - '*' | ||||
|   pull_request: | ||||
| 
 | ||||
| env: | ||||
|   TARGETS: f6 | ||||
| @ -37,7 +44,19 @@ jobs: | ||||
|         uses: ./.github/actions/docker | ||||
| 
 | ||||
|       - name: 'Check syntax' | ||||
|         id: syntax_check | ||||
|         uses: ./.github/actions/docker | ||||
|         continue-on-error: false | ||||
|         with: | ||||
|           run: /syntax_check.sh | ||||
|           run: SET_GH_OUTPUT=1 /syntax_check.sh | ||||
| 
 | ||||
|       - name: Report syntax errors | ||||
|         if: failure() && steps.syntax_check.outputs.errors && github.event.pull_request | ||||
|         uses: peter-evans/create-or-update-comment@v1 | ||||
|         with: | ||||
|           issue-number: ${{ github.event.pull_request.number }} | ||||
|           body: | | ||||
|             Please fix following syntax errors: | ||||
|             ``` | ||||
|             ${{ steps.syntax_check.outputs.errors }} | ||||
|             ``` | ||||
|             You might want to run `docker compose exec dev /syntax_check.sh` for an auto-fix. | ||||
							
								
								
									
										9
									
								
								.github/workflows/lint_python.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						| @ -1,6 +1,13 @@ | ||||
| name: 'Python Lint' | ||||
| 
 | ||||
| on: pull_request | ||||
| on:  | ||||
|   push: | ||||
|     branches: | ||||
|       - dev | ||||
|       - "release*" | ||||
|     tags: | ||||
|       - '*' | ||||
|   pull_request: | ||||
| 
 | ||||
| jobs: | ||||
|   lint_python: | ||||
|  | ||||
							
								
								
									
										674
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,674 @@ | ||||
|                     GNU GENERAL PUBLIC LICENSE | ||||
|                        Version 3, 29 June 2007 | ||||
| 
 | ||||
|  Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> | ||||
|  Everyone is permitted to copy and distribute verbatim copies | ||||
|  of this license document, but changing it is not allowed. | ||||
| 
 | ||||
|                             Preamble | ||||
| 
 | ||||
|   The GNU General Public License is a free, copyleft license for | ||||
| software and other kinds of works. | ||||
| 
 | ||||
|   The licenses for most software and other practical works are designed | ||||
| to take away your freedom to share and change the works.  By contrast, | ||||
| the GNU General Public License is intended to guarantee your freedom to | ||||
| share and change all versions of a program--to make sure it remains free | ||||
| software for all its users.  We, the Free Software Foundation, use the | ||||
| GNU General Public License for most of our software; it applies also to | ||||
| any other work released this way by its authors.  You can apply it to | ||||
| your programs, too. | ||||
| 
 | ||||
|   When we speak of free software, we are referring to freedom, not | ||||
| price.  Our General Public Licenses are designed to make sure that you | ||||
| have the freedom to distribute copies of free software (and charge for | ||||
| them if you wish), that you receive source code or can get it if you | ||||
| want it, that you can change the software or use pieces of it in new | ||||
| free programs, and that you know you can do these things. | ||||
| 
 | ||||
|   To protect your rights, we need to prevent others from denying you | ||||
| these rights or asking you to surrender the rights.  Therefore, you have | ||||
| certain responsibilities if you distribute copies of the software, or if | ||||
| you modify it: responsibilities to respect the freedom of others. | ||||
| 
 | ||||
|   For example, if you distribute copies of such a program, whether | ||||
| gratis or for a fee, you must pass on to the recipients the same | ||||
| freedoms that you received.  You must make sure that they, too, receive | ||||
| or can get the source code.  And you must show them these terms so they | ||||
| know their rights. | ||||
| 
 | ||||
|   Developers that use the GNU GPL protect your rights with two steps: | ||||
| (1) assert copyright on the software, and (2) offer you this License | ||||
| giving you legal permission to copy, distribute and/or modify it. | ||||
| 
 | ||||
|   For the developers' and authors' protection, the GPL clearly explains | ||||
| that there is no warranty for this free software.  For both users' and | ||||
| authors' sake, the GPL requires that modified versions be marked as | ||||
| changed, so that their problems will not be attributed erroneously to | ||||
| authors of previous versions. | ||||
| 
 | ||||
|   Some devices are designed to deny users access to install or run | ||||
| modified versions of the software inside them, although the manufacturer | ||||
| can do so.  This is fundamentally incompatible with the aim of | ||||
| protecting users' freedom to change the software.  The systematic | ||||
| pattern of such abuse occurs in the area of products for individuals to | ||||
| use, which is precisely where it is most unacceptable.  Therefore, we | ||||
| have designed this version of the GPL to prohibit the practice for those | ||||
| products.  If such problems arise substantially in other domains, we | ||||
| stand ready to extend this provision to those domains in future versions | ||||
| of the GPL, as needed to protect the freedom of users. | ||||
| 
 | ||||
|   Finally, every program is threatened constantly by software patents. | ||||
| States should not allow patents to restrict development and use of | ||||
| software on general-purpose computers, but in those that do, we wish to | ||||
| avoid the special danger that patents applied to a free program could | ||||
| make it effectively proprietary.  To prevent this, the GPL assures that | ||||
| patents cannot be used to render the program non-free. | ||||
| 
 | ||||
|   The precise terms and conditions for copying, distribution and | ||||
| modification follow. | ||||
| 
 | ||||
|                        TERMS AND CONDITIONS | ||||
| 
 | ||||
|   0. Definitions. | ||||
| 
 | ||||
|   "This License" refers to version 3 of the GNU General Public License. | ||||
| 
 | ||||
|   "Copyright" also means copyright-like laws that apply to other kinds of | ||||
| works, such as semiconductor masks. | ||||
| 
 | ||||
|   "The Program" refers to any copyrightable work licensed under this | ||||
| License.  Each licensee is addressed as "you".  "Licensees" and | ||||
| "recipients" may be individuals or organizations. | ||||
| 
 | ||||
|   To "modify" a work means to copy from or adapt all or part of the work | ||||
| in a fashion requiring copyright permission, other than the making of an | ||||
| exact copy.  The resulting work is called a "modified version" of the | ||||
| earlier work or a work "based on" the earlier work. | ||||
| 
 | ||||
|   A "covered work" means either the unmodified Program or a work based | ||||
| on the Program. | ||||
| 
 | ||||
|   To "propagate" a work means to do anything with it that, without | ||||
| permission, would make you directly or secondarily liable for | ||||
| infringement under applicable copyright law, except executing it on a | ||||
| computer or modifying a private copy.  Propagation includes copying, | ||||
| distribution (with or without modification), making available to the | ||||
| public, and in some countries other activities as well. | ||||
| 
 | ||||
|   To "convey" a work means any kind of propagation that enables other | ||||
| parties to make or receive copies.  Mere interaction with a user through | ||||
| a computer network, with no transfer of a copy, is not conveying. | ||||
| 
 | ||||
|   An interactive user interface displays "Appropriate Legal Notices" | ||||
| to the extent that it includes a convenient and prominently visible | ||||
| feature that (1) displays an appropriate copyright notice, and (2) | ||||
| tells the user that there is no warranty for the work (except to the | ||||
| extent that warranties are provided), that licensees may convey the | ||||
| work under this License, and how to view a copy of this License.  If | ||||
| the interface presents a list of user commands or options, such as a | ||||
| menu, a prominent item in the list meets this criterion. | ||||
| 
 | ||||
|   1. Source Code. | ||||
| 
 | ||||
|   The "source code" for a work means the preferred form of the work | ||||
| for making modifications to it.  "Object code" means any non-source | ||||
| form of a work. | ||||
| 
 | ||||
|   A "Standard Interface" means an interface that either is an official | ||||
| standard defined by a recognized standards body, or, in the case of | ||||
| interfaces specified for a particular programming language, one that | ||||
| is widely used among developers working in that language. | ||||
| 
 | ||||
|   The "System Libraries" of an executable work include anything, other | ||||
| than the work as a whole, that (a) is included in the normal form of | ||||
| packaging a Major Component, but which is not part of that Major | ||||
| Component, and (b) serves only to enable use of the work with that | ||||
| Major Component, or to implement a Standard Interface for which an | ||||
| implementation is available to the public in source code form.  A | ||||
| "Major Component", in this context, means a major essential component | ||||
| (kernel, window system, and so on) of the specific operating system | ||||
| (if any) on which the executable work runs, or a compiler used to | ||||
| produce the work, or an object code interpreter used to run it. | ||||
| 
 | ||||
|   The "Corresponding Source" for a work in object code form means all | ||||
| the source code needed to generate, install, and (for an executable | ||||
| work) run the object code and to modify the work, including scripts to | ||||
| control those activities.  However, it does not include the work's | ||||
| System Libraries, or general-purpose tools or generally available free | ||||
| programs which are used unmodified in performing those activities but | ||||
| which are not part of the work.  For example, Corresponding Source | ||||
| includes interface definition files associated with source files for | ||||
| the work, and the source code for shared libraries and dynamically | ||||
| linked subprograms that the work is specifically designed to require, | ||||
| such as by intimate data communication or control flow between those | ||||
| subprograms and other parts of the work. | ||||
| 
 | ||||
|   The Corresponding Source need not include anything that users | ||||
| can regenerate automatically from other parts of the Corresponding | ||||
| Source. | ||||
| 
 | ||||
|   The Corresponding Source for a work in source code form is that | ||||
| same work. | ||||
| 
 | ||||
|   2. Basic Permissions. | ||||
| 
 | ||||
|   All rights granted under this License are granted for the term of | ||||
| copyright on the Program, and are irrevocable provided the stated | ||||
| conditions are met.  This License explicitly affirms your unlimited | ||||
| permission to run the unmodified Program.  The output from running a | ||||
| covered work is covered by this License only if the output, given its | ||||
| content, constitutes a covered work.  This License acknowledges your | ||||
| rights of fair use or other equivalent, as provided by copyright law. | ||||
| 
 | ||||
|   You may make, run and propagate covered works that you do not | ||||
| convey, without conditions so long as your license otherwise remains | ||||
| in force.  You may convey covered works to others for the sole purpose | ||||
| of having them make modifications exclusively for you, or provide you | ||||
| with facilities for running those works, provided that you comply with | ||||
| the terms of this License in conveying all material for which you do | ||||
| not control copyright.  Those thus making or running the covered works | ||||
| for you must do so exclusively on your behalf, under your direction | ||||
| and control, on terms that prohibit them from making any copies of | ||||
| your copyrighted material outside their relationship with you. | ||||
| 
 | ||||
|   Conveying under any other circumstances is permitted solely under | ||||
| the conditions stated below.  Sublicensing is not allowed; section 10 | ||||
| makes it unnecessary. | ||||
| 
 | ||||
|   3. Protecting Users' Legal Rights From Anti-Circumvention Law. | ||||
| 
 | ||||
|   No covered work shall be deemed part of an effective technological | ||||
| measure under any applicable law fulfilling obligations under article | ||||
| 11 of the WIPO copyright treaty adopted on 20 December 1996, or | ||||
| similar laws prohibiting or restricting circumvention of such | ||||
| measures. | ||||
| 
 | ||||
|   When you convey a covered work, you waive any legal power to forbid | ||||
| circumvention of technological measures to the extent such circumvention | ||||
| is effected by exercising rights under this License with respect to | ||||
| the covered work, and you disclaim any intention to limit operation or | ||||
| modification of the work as a means of enforcing, against the work's | ||||
| users, your or third parties' legal rights to forbid circumvention of | ||||
| technological measures. | ||||
| 
 | ||||
|   4. Conveying Verbatim Copies. | ||||
| 
 | ||||
|   You may convey verbatim copies of the Program's source code as you | ||||
| receive it, in any medium, provided that you conspicuously and | ||||
| appropriately publish on each copy an appropriate copyright notice; | ||||
| keep intact all notices stating that this License and any | ||||
| non-permissive terms added in accord with section 7 apply to the code; | ||||
| keep intact all notices of the absence of any warranty; and give all | ||||
| recipients a copy of this License along with the Program. | ||||
| 
 | ||||
|   You may charge any price or no price for each copy that you convey, | ||||
| and you may offer support or warranty protection for a fee. | ||||
| 
 | ||||
|   5. Conveying Modified Source Versions. | ||||
| 
 | ||||
|   You may convey a work based on the Program, or the modifications to | ||||
| produce it from the Program, in the form of source code under the | ||||
| terms of section 4, provided that you also meet all of these conditions: | ||||
| 
 | ||||
|     a) The work must carry prominent notices stating that you modified | ||||
|     it, and giving a relevant date. | ||||
| 
 | ||||
|     b) The work must carry prominent notices stating that it is | ||||
|     released under this License and any conditions added under section | ||||
|     7.  This requirement modifies the requirement in section 4 to | ||||
|     "keep intact all notices". | ||||
| 
 | ||||
|     c) You must license the entire work, as a whole, under this | ||||
|     License to anyone who comes into possession of a copy.  This | ||||
|     License will therefore apply, along with any applicable section 7 | ||||
|     additional terms, to the whole of the work, and all its parts, | ||||
|     regardless of how they are packaged.  This License gives no | ||||
|     permission to license the work in any other way, but it does not | ||||
|     invalidate such permission if you have separately received it. | ||||
| 
 | ||||
|     d) If the work has interactive user interfaces, each must display | ||||
|     Appropriate Legal Notices; however, if the Program has interactive | ||||
|     interfaces that do not display Appropriate Legal Notices, your | ||||
|     work need not make them do so. | ||||
| 
 | ||||
|   A compilation of a covered work with other separate and independent | ||||
| works, which are not by their nature extensions of the covered work, | ||||
| and which are not combined with it such as to form a larger program, | ||||
| in or on a volume of a storage or distribution medium, is called an | ||||
| "aggregate" if the compilation and its resulting copyright are not | ||||
| used to limit the access or legal rights of the compilation's users | ||||
| beyond what the individual works permit.  Inclusion of a covered work | ||||
| in an aggregate does not cause this License to apply to the other | ||||
| parts of the aggregate. | ||||
| 
 | ||||
|   6. Conveying Non-Source Forms. | ||||
| 
 | ||||
|   You may convey a covered work in object code form under the terms | ||||
| of sections 4 and 5, provided that you also convey the | ||||
| machine-readable Corresponding Source under the terms of this License, | ||||
| in one of these ways: | ||||
| 
 | ||||
|     a) Convey the object code in, or embodied in, a physical product | ||||
|     (including a physical distribution medium), accompanied by the | ||||
|     Corresponding Source fixed on a durable physical medium | ||||
|     customarily used for software interchange. | ||||
| 
 | ||||
|     b) Convey the object code in, or embodied in, a physical product | ||||
|     (including a physical distribution medium), accompanied by a | ||||
|     written offer, valid for at least three years and valid for as | ||||
|     long as you offer spare parts or customer support for that product | ||||
|     model, to give anyone who possesses the object code either (1) a | ||||
|     copy of the Corresponding Source for all the software in the | ||||
|     product that is covered by this License, on a durable physical | ||||
|     medium customarily used for software interchange, for a price no | ||||
|     more than your reasonable cost of physically performing this | ||||
|     conveying of source, or (2) access to copy the | ||||
|     Corresponding Source from a network server at no charge. | ||||
| 
 | ||||
|     c) Convey individual copies of the object code with a copy of the | ||||
|     written offer to provide the Corresponding Source.  This | ||||
|     alternative is allowed only occasionally and noncommercially, and | ||||
|     only if you received the object code with such an offer, in accord | ||||
|     with subsection 6b. | ||||
| 
 | ||||
|     d) Convey the object code by offering access from a designated | ||||
|     place (gratis or for a charge), and offer equivalent access to the | ||||
|     Corresponding Source in the same way through the same place at no | ||||
|     further charge.  You need not require recipients to copy the | ||||
|     Corresponding Source along with the object code.  If the place to | ||||
|     copy the object code is a network server, the Corresponding Source | ||||
|     may be on a different server (operated by you or a third party) | ||||
|     that supports equivalent copying facilities, provided you maintain | ||||
|     clear directions next to the object code saying where to find the | ||||
|     Corresponding Source.  Regardless of what server hosts the | ||||
|     Corresponding Source, you remain obligated to ensure that it is | ||||
|     available for as long as needed to satisfy these requirements. | ||||
| 
 | ||||
|     e) Convey the object code using peer-to-peer transmission, provided | ||||
|     you inform other peers where the object code and Corresponding | ||||
|     Source of the work are being offered to the general public at no | ||||
|     charge under subsection 6d. | ||||
| 
 | ||||
|   A separable portion of the object code, whose source code is excluded | ||||
| from the Corresponding Source as a System Library, need not be | ||||
| included in conveying the object code work. | ||||
| 
 | ||||
|   A "User Product" is either (1) a "consumer product", which means any | ||||
| tangible personal property which is normally used for personal, family, | ||||
| or household purposes, or (2) anything designed or sold for incorporation | ||||
| into a dwelling.  In determining whether a product is a consumer product, | ||||
| doubtful cases shall be resolved in favor of coverage.  For a particular | ||||
| product received by a particular user, "normally used" refers to a | ||||
| typical or common use of that class of product, regardless of the status | ||||
| of the particular user or of the way in which the particular user | ||||
| actually uses, or expects or is expected to use, the product.  A product | ||||
| is a consumer product regardless of whether the product has substantial | ||||
| commercial, industrial or non-consumer uses, unless such uses represent | ||||
| the only significant mode of use of the product. | ||||
| 
 | ||||
|   "Installation Information" for a User Product means any methods, | ||||
| procedures, authorization keys, or other information required to install | ||||
| and execute modified versions of a covered work in that User Product from | ||||
| a modified version of its Corresponding Source.  The information must | ||||
| suffice to ensure that the continued functioning of the modified object | ||||
| code is in no case prevented or interfered with solely because | ||||
| modification has been made. | ||||
| 
 | ||||
|   If you convey an object code work under this section in, or with, or | ||||
| specifically for use in, a User Product, and the conveying occurs as | ||||
| part of a transaction in which the right of possession and use of the | ||||
| User Product is transferred to the recipient in perpetuity or for a | ||||
| fixed term (regardless of how the transaction is characterized), the | ||||
| Corresponding Source conveyed under this section must be accompanied | ||||
| by the Installation Information.  But this requirement does not apply | ||||
| if neither you nor any third party retains the ability to install | ||||
| modified object code on the User Product (for example, the work has | ||||
| been installed in ROM). | ||||
| 
 | ||||
|   The requirement to provide Installation Information does not include a | ||||
| requirement to continue to provide support service, warranty, or updates | ||||
| for a work that has been modified or installed by the recipient, or for | ||||
| the User Product in which it has been modified or installed.  Access to a | ||||
| network may be denied when the modification itself materially and | ||||
| adversely affects the operation of the network or violates the rules and | ||||
| protocols for communication across the network. | ||||
| 
 | ||||
|   Corresponding Source conveyed, and Installation Information provided, | ||||
| in accord with this section must be in a format that is publicly | ||||
| documented (and with an implementation available to the public in | ||||
| source code form), and must require no special password or key for | ||||
| unpacking, reading or copying. | ||||
| 
 | ||||
|   7. Additional Terms. | ||||
| 
 | ||||
|   "Additional permissions" are terms that supplement the terms of this | ||||
| License by making exceptions from one or more of its conditions. | ||||
| Additional permissions that are applicable to the entire Program shall | ||||
| be treated as though they were included in this License, to the extent | ||||
| that they are valid under applicable law.  If additional permissions | ||||
| apply only to part of the Program, that part may be used separately | ||||
| under those permissions, but the entire Program remains governed by | ||||
| this License without regard to the additional permissions. | ||||
| 
 | ||||
|   When you convey a copy of a covered work, you may at your option | ||||
| remove any additional permissions from that copy, or from any part of | ||||
| it.  (Additional permissions may be written to require their own | ||||
| removal in certain cases when you modify the work.)  You may place | ||||
| additional permissions on material, added by you to a covered work, | ||||
| for which you have or can give appropriate copyright permission. | ||||
| 
 | ||||
|   Notwithstanding any other provision of this License, for material you | ||||
| add to a covered work, you may (if authorized by the copyright holders of | ||||
| that material) supplement the terms of this License with terms: | ||||
| 
 | ||||
|     a) Disclaiming warranty or limiting liability differently from the | ||||
|     terms of sections 15 and 16 of this License; or | ||||
| 
 | ||||
|     b) Requiring preservation of specified reasonable legal notices or | ||||
|     author attributions in that material or in the Appropriate Legal | ||||
|     Notices displayed by works containing it; or | ||||
| 
 | ||||
|     c) Prohibiting misrepresentation of the origin of that material, or | ||||
|     requiring that modified versions of such material be marked in | ||||
|     reasonable ways as different from the original version; or | ||||
| 
 | ||||
|     d) Limiting the use for publicity purposes of names of licensors or | ||||
|     authors of the material; or | ||||
| 
 | ||||
|     e) Declining to grant rights under trademark law for use of some | ||||
|     trade names, trademarks, or service marks; or | ||||
| 
 | ||||
|     f) Requiring indemnification of licensors and authors of that | ||||
|     material by anyone who conveys the material (or modified versions of | ||||
|     it) with contractual assumptions of liability to the recipient, for | ||||
|     any liability that these contractual assumptions directly impose on | ||||
|     those licensors and authors. | ||||
| 
 | ||||
|   All other non-permissive additional terms are considered "further | ||||
| restrictions" within the meaning of section 10.  If the Program as you | ||||
| received it, or any part of it, contains a notice stating that it is | ||||
| governed by this License along with a term that is a further | ||||
| restriction, you may remove that term.  If a license document contains | ||||
| a further restriction but permits relicensing or conveying under this | ||||
| License, you may add to a covered work material governed by the terms | ||||
| of that license document, provided that the further restriction does | ||||
| not survive such relicensing or conveying. | ||||
| 
 | ||||
|   If you add terms to a covered work in accord with this section, you | ||||
| must place, in the relevant source files, a statement of the | ||||
| additional terms that apply to those files, or a notice indicating | ||||
| where to find the applicable terms. | ||||
| 
 | ||||
|   Additional terms, permissive or non-permissive, may be stated in the | ||||
| form of a separately written license, or stated as exceptions; | ||||
| the above requirements apply either way. | ||||
| 
 | ||||
|   8. Termination. | ||||
| 
 | ||||
|   You may not propagate or modify a covered work except as expressly | ||||
| provided under this License.  Any attempt otherwise to propagate or | ||||
| modify it is void, and will automatically terminate your rights under | ||||
| this License (including any patent licenses granted under the third | ||||
| paragraph of section 11). | ||||
| 
 | ||||
|   However, if you cease all violation of this License, then your | ||||
| license from a particular copyright holder is reinstated (a) | ||||
| provisionally, unless and until the copyright holder explicitly and | ||||
| finally terminates your license, and (b) permanently, if the copyright | ||||
| holder fails to notify you of the violation by some reasonable means | ||||
| prior to 60 days after the cessation. | ||||
| 
 | ||||
|   Moreover, your license from a particular copyright holder is | ||||
| reinstated permanently if the copyright holder notifies you of the | ||||
| violation by some reasonable means, this is the first time you have | ||||
| received notice of violation of this License (for any work) from that | ||||
| copyright holder, and you cure the violation prior to 30 days after | ||||
| your receipt of the notice. | ||||
| 
 | ||||
|   Termination of your rights under this section does not terminate the | ||||
| licenses of parties who have received copies or rights from you under | ||||
| this License.  If your rights have been terminated and not permanently | ||||
| reinstated, you do not qualify to receive new licenses for the same | ||||
| material under section 10. | ||||
| 
 | ||||
|   9. Acceptance Not Required for Having Copies. | ||||
| 
 | ||||
|   You are not required to accept this License in order to receive or | ||||
| run a copy of the Program.  Ancillary propagation of a covered work | ||||
| occurring solely as a consequence of using peer-to-peer transmission | ||||
| to receive a copy likewise does not require acceptance.  However, | ||||
| nothing other than this License grants you permission to propagate or | ||||
| modify any covered work.  These actions infringe copyright if you do | ||||
| not accept this License.  Therefore, by modifying or propagating a | ||||
| covered work, you indicate your acceptance of this License to do so. | ||||
| 
 | ||||
|   10. Automatic Licensing of Downstream Recipients. | ||||
| 
 | ||||
|   Each time you convey a covered work, the recipient automatically | ||||
| receives a license from the original licensors, to run, modify and | ||||
| propagate that work, subject to this License.  You are not responsible | ||||
| for enforcing compliance by third parties with this License. | ||||
| 
 | ||||
|   An "entity transaction" is a transaction transferring control of an | ||||
| organization, or substantially all assets of one, or subdividing an | ||||
| organization, or merging organizations.  If propagation of a covered | ||||
| work results from an entity transaction, each party to that | ||||
| transaction who receives a copy of the work also receives whatever | ||||
| licenses to the work the party's predecessor in interest had or could | ||||
| give under the previous paragraph, plus a right to possession of the | ||||
| Corresponding Source of the work from the predecessor in interest, if | ||||
| the predecessor has it or can get it with reasonable efforts. | ||||
| 
 | ||||
|   You may not impose any further restrictions on the exercise of the | ||||
| rights granted or affirmed under this License.  For example, you may | ||||
| not impose a license fee, royalty, or other charge for exercise of | ||||
| rights granted under this License, and you may not initiate litigation | ||||
| (including a cross-claim or counterclaim in a lawsuit) alleging that | ||||
| any patent claim is infringed by making, using, selling, offering for | ||||
| sale, or importing the Program or any portion of it. | ||||
| 
 | ||||
|   11. Patents. | ||||
| 
 | ||||
|   A "contributor" is a copyright holder who authorizes use under this | ||||
| License of the Program or a work on which the Program is based.  The | ||||
| work thus licensed is called the contributor's "contributor version". | ||||
| 
 | ||||
|   A contributor's "essential patent claims" are all patent claims | ||||
| owned or controlled by the contributor, whether already acquired or | ||||
| hereafter acquired, that would be infringed by some manner, permitted | ||||
| by this License, of making, using, or selling its contributor version, | ||||
| but do not include claims that would be infringed only as a | ||||
| consequence of further modification of the contributor version.  For | ||||
| purposes of this definition, "control" includes the right to grant | ||||
| patent sublicenses in a manner consistent with the requirements of | ||||
| this License. | ||||
| 
 | ||||
|   Each contributor grants you a non-exclusive, worldwide, royalty-free | ||||
| patent license under the contributor's essential patent claims, to | ||||
| make, use, sell, offer for sale, import and otherwise run, modify and | ||||
| propagate the contents of its contributor version. | ||||
| 
 | ||||
|   In the following three paragraphs, a "patent license" is any express | ||||
| agreement or commitment, however denominated, not to enforce a patent | ||||
| (such as an express permission to practice a patent or covenant not to | ||||
| sue for patent infringement).  To "grant" such a patent license to a | ||||
| party means to make such an agreement or commitment not to enforce a | ||||
| patent against the party. | ||||
| 
 | ||||
|   If you convey a covered work, knowingly relying on a patent license, | ||||
| and the Corresponding Source of the work is not available for anyone | ||||
| to copy, free of charge and under the terms of this License, through a | ||||
| publicly available network server or other readily accessible means, | ||||
| then you must either (1) cause the Corresponding Source to be so | ||||
| available, or (2) arrange to deprive yourself of the benefit of the | ||||
| patent license for this particular work, or (3) arrange, in a manner | ||||
| consistent with the requirements of this License, to extend the patent | ||||
| license to downstream recipients.  "Knowingly relying" means you have | ||||
| actual knowledge that, but for the patent license, your conveying the | ||||
| covered work in a country, or your recipient's use of the covered work | ||||
| in a country, would infringe one or more identifiable patents in that | ||||
| country that you have reason to believe are valid. | ||||
| 
 | ||||
|   If, pursuant to or in connection with a single transaction or | ||||
| arrangement, you convey, or propagate by procuring conveyance of, a | ||||
| covered work, and grant a patent license to some of the parties | ||||
| receiving the covered work authorizing them to use, propagate, modify | ||||
| or convey a specific copy of the covered work, then the patent license | ||||
| you grant is automatically extended to all recipients of the covered | ||||
| work and works based on it. | ||||
| 
 | ||||
|   A patent license is "discriminatory" if it does not include within | ||||
| the scope of its coverage, prohibits the exercise of, or is | ||||
| conditioned on the non-exercise of one or more of the rights that are | ||||
| specifically granted under this License.  You may not convey a covered | ||||
| work if you are a party to an arrangement with a third party that is | ||||
| in the business of distributing software, under which you make payment | ||||
| to the third party based on the extent of your activity of conveying | ||||
| the work, and under which the third party grants, to any of the | ||||
| parties who would receive the covered work from you, a discriminatory | ||||
| patent license (a) in connection with copies of the covered work | ||||
| conveyed by you (or copies made from those copies), or (b) primarily | ||||
| for and in connection with specific products or compilations that | ||||
| contain the covered work, unless you entered into that arrangement, | ||||
| or that patent license was granted, prior to 28 March 2007. | ||||
| 
 | ||||
|   Nothing in this License shall be construed as excluding or limiting | ||||
| any implied license or other defenses to infringement that may | ||||
| otherwise be available to you under applicable patent law. | ||||
| 
 | ||||
|   12. No Surrender of Others' Freedom. | ||||
| 
 | ||||
|   If conditions are imposed on you (whether by court order, agreement or | ||||
| otherwise) that contradict the conditions of this License, they do not | ||||
| excuse you from the conditions of this License.  If you cannot convey a | ||||
| covered work so as to satisfy simultaneously your obligations under this | ||||
| License and any other pertinent obligations, then as a consequence you may | ||||
| not convey it at all.  For example, if you agree to terms that obligate you | ||||
| to collect a royalty for further conveying from those to whom you convey | ||||
| the Program, the only way you could satisfy both those terms and this | ||||
| License would be to refrain entirely from conveying the Program. | ||||
| 
 | ||||
|   13. Use with the GNU Affero General Public License. | ||||
| 
 | ||||
|   Notwithstanding any other provision of this License, you have | ||||
| permission to link or combine any covered work with a work licensed | ||||
| under version 3 of the GNU Affero General Public License into a single | ||||
| combined work, and to convey the resulting work.  The terms of this | ||||
| License will continue to apply to the part which is the covered work, | ||||
| but the special requirements of the GNU Affero General Public License, | ||||
| section 13, concerning interaction through a network will apply to the | ||||
| combination as such. | ||||
| 
 | ||||
|   14. Revised Versions of this License. | ||||
| 
 | ||||
|   The Free Software Foundation may publish revised and/or new versions of | ||||
| the GNU General Public License from time to time.  Such new versions will | ||||
| be similar in spirit to the present version, but may differ in detail to | ||||
| address new problems or concerns. | ||||
| 
 | ||||
|   Each version is given a distinguishing version number.  If the | ||||
| Program specifies that a certain numbered version of the GNU General | ||||
| Public License "or any later version" applies to it, you have the | ||||
| option of following the terms and conditions either of that numbered | ||||
| version or of any later version published by the Free Software | ||||
| Foundation.  If the Program does not specify a version number of the | ||||
| GNU General Public License, you may choose any version ever published | ||||
| by the Free Software Foundation. | ||||
| 
 | ||||
|   If the Program specifies that a proxy can decide which future | ||||
| versions of the GNU General Public License can be used, that proxy's | ||||
| public statement of acceptance of a version permanently authorizes you | ||||
| to choose that version for the Program. | ||||
| 
 | ||||
|   Later license versions may give you additional or different | ||||
| permissions.  However, no additional obligations are imposed on any | ||||
| author or copyright holder as a result of your choosing to follow a | ||||
| later version. | ||||
| 
 | ||||
|   15. Disclaimer of Warranty. | ||||
| 
 | ||||
|   THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY | ||||
| APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT | ||||
| HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY | ||||
| OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, | ||||
| THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||||
| PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM | ||||
| IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF | ||||
| ALL NECESSARY SERVICING, REPAIR OR CORRECTION. | ||||
| 
 | ||||
|   16. Limitation of Liability. | ||||
| 
 | ||||
|   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||||
| WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS | ||||
| THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY | ||||
| GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE | ||||
| USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF | ||||
| DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD | ||||
| PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), | ||||
| EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF | ||||
| SUCH DAMAGES. | ||||
| 
 | ||||
|   17. Interpretation of Sections 15 and 16. | ||||
| 
 | ||||
|   If the disclaimer of warranty and limitation of liability provided | ||||
| above cannot be given local legal effect according to their terms, | ||||
| reviewing courts shall apply local law that most closely approximates | ||||
| an absolute waiver of all civil liability in connection with the | ||||
| Program, unless a warranty or assumption of liability accompanies a | ||||
| copy of the Program in return for a fee. | ||||
| 
 | ||||
|                      END OF TERMS AND CONDITIONS | ||||
| 
 | ||||
|             How to Apply These Terms to Your New Programs | ||||
| 
 | ||||
|   If you develop a new program, and you want it to be of the greatest | ||||
| possible use to the public, the best way to achieve this is to make it | ||||
| free software which everyone can redistribute and change under these terms. | ||||
| 
 | ||||
|   To do so, attach the following notices to the program.  It is safest | ||||
| to attach them to the start of each source file to most effectively | ||||
| state the exclusion of warranty; and each file should have at least | ||||
| the "copyright" line and a pointer to where the full notice is found. | ||||
| 
 | ||||
|     <one line to give the program's name and a brief idea of what it does.> | ||||
|     Copyright (C) <year>  <name of author> | ||||
| 
 | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| Also add information on how to contact you by electronic and paper mail. | ||||
| 
 | ||||
|   If the program does terminal interaction, make it output a short | ||||
| notice like this when it starts in an interactive mode: | ||||
| 
 | ||||
|     <program>  Copyright (C) <year>  <name of author> | ||||
|     This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | ||||
|     This is free software, and you are welcome to redistribute it | ||||
|     under certain conditions; type `show c' for details. | ||||
| 
 | ||||
| The hypothetical commands `show w' and `show c' should show the appropriate | ||||
| parts of the General Public License.  Of course, your program's commands | ||||
| might be different; for a GUI interface, you would use an "about box". | ||||
| 
 | ||||
|   You should also get your employer (if you work as a programmer) or school, | ||||
| if any, to sign a "copyright disclaimer" for the program, if necessary. | ||||
| For more information on this, and how to apply and follow the GNU GPL, see | ||||
| <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
|   The GNU General Public License does not permit incorporating your program | ||||
| into proprietary programs.  If your program is a subroutine library, you | ||||
| may consider it more useful to permit linking proprietary applications with | ||||
| the library.  If this is what you want to do, use the GNU Lesser General | ||||
| Public License instead of this License.  But first, please read | ||||
| <https://www.gnu.org/licenses/why-not-lgpl.html>. | ||||
							
								
								
									
										184
									
								
								ReadMe.md
									
									
									
									
									
								
							
							
						
						| @ -1,16 +1,15 @@ | ||||
| # Flipper Zero Firmware community repo | ||||
| # Flipper Zero Firmware | ||||
| 
 | ||||
| [](http://flipperzero.one/discord) | ||||
| 
 | ||||
| <img src="https://habrastorage.org/webt/eo/m0/e4/eom0e4btudte7nrhnyic-laiog0.png" /> | ||||
|  | ||||
| 
 | ||||
| Welcome to [Flipper Zero](https://flipperzero.one/)'s Firmware repo! | ||||
| Our goal is to create nice and clean code along with good documentation, to make it a pleasure for everyone to work with. | ||||
| This repo will become completely public closer to the device shipping date. | ||||
| Our goal is to create nice and clean code with good documentation, to make it a pleasure for everyone to work with. | ||||
| 
 | ||||
| # Update firmware | ||||
| 
 | ||||
| <a href="https://update.flipperzero.one/">Get Latest Firmware from Update Server</a> | ||||
| [Get Latest Firmware from Update Server](https://update.flipperzero.one/) | ||||
| 
 | ||||
| 
 | ||||
| Flipper Zero's firmware consists of three components: | ||||
| @ -27,7 +26,7 @@ All 3 of them must be flashed in order described. | ||||
| 
 | ||||
| Prerequisites: | ||||
| 
 | ||||
| - Linux / MacOs | ||||
| - Linux / macOS | ||||
| - Terminal | ||||
| - STM32_Programmer_CLI added to $PATH | ||||
| 
 | ||||
| @ -37,9 +36,9 @@ One liner: `./flash_core2_ble.sh` | ||||
| 
 | ||||
| Prerequisites: | ||||
| 
 | ||||
| - Linux / MacOs | ||||
| - Linux / macOS | ||||
| - Terminal | ||||
| - Arm gcc noneabi | ||||
| - [arm-gcc-none-eabi](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads) | ||||
| - openocd | ||||
| 
 | ||||
| One liner: `./flash_core1_main.sh` | ||||
| @ -52,81 +51,138 @@ One liner: `./flash_core1_main.sh` | ||||
|  - Press and hold `← Left` + `↩ Back` for reset  | ||||
|  - Release `← Left` and keep holding `↩ Back` until blue LED lights up | ||||
|  - Release `↩ Back` | ||||
| <img src="https://habrastorage.org/webt/uu/c3/g2/uuc3g2n36f2sju19rskcvjzjf6w.png" /> | ||||
|  | ||||
| 
 | ||||
| 1. Run `dfu-util -D full.dfu -a 0` | ||||
| 
 | ||||
| # Build from source | ||||
| 
 | ||||
| `docker-compose exec dev make -C firmware flash` for build and flash dev board (see `applications/applications.mk` for list of applications/examples) | ||||
| ## Prerequisites | ||||
| 
 | ||||
| 1. Install [Docker Engine and Docker Compose](https://www.docker.com/get-started) | ||||
| 2. Clone the repo: | ||||
|    ```sh | ||||
|    git clone https://github.com/flipperdevices/flipperzero-firmware | ||||
|    cd flipperzero-firmware | ||||
|    ``` | ||||
| 3. Prepare the container: | ||||
|    ```sh | ||||
|    docker compose up -d | ||||
|    ``` | ||||
| 
 | ||||
| ## Compile bootloader | ||||
| 
 | ||||
| ```sh | ||||
| docker compose exec dev make -j$(nproc) -C bootloader TARGET=f6 | ||||
| ``` | ||||
| 
 | ||||
| Bootloader compilation results: | ||||
| * `bootloader/.obj/f6/bootloader.elf` | ||||
| * `bootloader/.obj/f6/bootloader.hex` | ||||
| * `bootloader/.obj/f6/bootloader.bin` | ||||
| * **`bootloader/.obj/f6/bootloader.dfu`** - should be used to flash | ||||
| 
 | ||||
| ## Compile firmware | ||||
| 
 | ||||
| ```sh | ||||
| docker compose exec dev make -j$(nproc) -C firmware TARGET=f6 | ||||
| ``` | ||||
| 
 | ||||
| Firmware compilation results: | ||||
| * `firmware/.obj/f6/firmware.elf` | ||||
| * `firmware/.obj/f6/firmware.hex` | ||||
| * `firmware/.obj/f6/firmware.bin` | ||||
| * **`firmware/.obj/f6/firmware.dfu`** - should be used to flash | ||||
| 
 | ||||
| ## Concatenate bootloader and firmware | ||||
| 
 | ||||
| You might want to do this to distribute the firmware as a single file. | ||||
| 
 | ||||
| That's exactly how we generate our `full` builds. | ||||
| 
 | ||||
| 1. Concatenate HEX files: | ||||
|    ```sh | ||||
|    docker compose exec dev srec_cat \ | ||||
|     bootloader/.obj/f6/bootloader.hex -Intel \ | ||||
|     firmware/.obj/f6/firmware.hex -Intel \ | ||||
|     -o firmware/.obj/f6/full.hex -Intel | ||||
|    ``` | ||||
| 2. Convert HEX to DFU: | ||||
|    ```sh | ||||
|    docker compose exec dev hex2dfu \ | ||||
|     -i firmware/.obj/f6/full.hex \ | ||||
|     -o firmware/.obj/f6/full.dfu \ | ||||
|     -l "Flipper Zero F6" | ||||
|    ``` | ||||
| 
 | ||||
| Finally, you will have **`firmware/.obj/f6/full.dfu`** file that can be distributed and flashed. | ||||
| 
 | ||||
| # Links | ||||
| * Task tracker: [Jira](https://flipperzero.atlassian.net/) | ||||
| * Discord server: [flipperzero.one/discord](https://flipperzero.one/discord) | ||||
| * Project website: [flipperzero.one](https://flipperzero.one) | ||||
| * Discord: [flipp.dev/discord](https://flipp.dev/discord) | ||||
| * Website: [flipperzero.one](https://flipperzero.one) | ||||
| * Kickstarter page: [kickstarter.com](https://www.kickstarter.com/projects/flipper-devices/flipper-zero-tamagochi-for-hackers) | ||||
| * Forum: [forum.flipperzero.one](https://forum.flipperzero.one/) | ||||
| 
 | ||||
| # Folders structure | ||||
| 
 | ||||
| - applications - application and services | ||||
|  * accessor - Wiegand server | ||||
|  * archive - Archive and file manager  | ||||
|  * bt - BLE service and application | ||||
|  * cli - Console service | ||||
|  * debug_tools - different tools that we use on factory and for debug | ||||
|  * dialogs - service for showing GUI dialogs | ||||
|  * dolphin - dolphin service and supplientary apps | ||||
|  * gpio-tester - GPIO control application | ||||
|  * gui - GUI service | ||||
|  * ibutton - ibutton application, onewire keys and more | ||||
|  * input - input service | ||||
|  * irda - irda application, controls your IR devices  | ||||
|  * irda_monitor - irda debug tool  | ||||
|  * lfrfid - LF RFID application | ||||
|  * lfrfid-debug - LF RFID debug tool | ||||
|  * loader - application loader service | ||||
|  * menu - main menu service | ||||
|  * music-player - music player app (demo) | ||||
|  * nfc - NFC application, HF rfid, EMV and etc | ||||
|  * notification - notification service  | ||||
|  * power - power service | ||||
|  * power-observer - power debug tool | ||||
|  * scened-app-example - c++ application example  | ||||
|  * storage - storage service, internal + sdcard | ||||
|  * storage-settings - storage settings app | ||||
|  * subghz - subghz application, 433 fobs and etc | ||||
|  * tests - unit tests and etc | ||||
|   * accessor - Wiegand server | ||||
|   * archive - Archive and file manager  | ||||
|   * bt - BLE service and application | ||||
|   * cli - Console service | ||||
|   * debug_tools - different tools that we use on factory and for debug | ||||
|   * dialogs - service for showing GUI dialogs | ||||
|   * dolphin - dolphin service and supplientary apps | ||||
|   * gpio-tester - GPIO control application | ||||
|   * gui - GUI service | ||||
|   * ibutton - ibutton application, onewire keys and more | ||||
|   * input - input service | ||||
|   * irda - irda application, controls your IR devices  | ||||
|   * irda_monitor - irda debug tool  | ||||
|   * lfrfid - LF RFID application | ||||
|   * lfrfid-debug - LF RFID debug tool | ||||
|   * loader - application loader service | ||||
|   * menu - main menu service | ||||
|   * music-player - music player app (demo) | ||||
|   * nfc - NFC application, HF rfid, EMV and etc | ||||
|   * notification - notification service  | ||||
|   * power - power service | ||||
|   * power-observer - power debug tool | ||||
|   * scened-app-example - c++ application example  | ||||
|   * storage - storage service, internal + sdcard | ||||
|   * storage-settings - storage settings app | ||||
|   * subghz - subghz application, 433 fobs and etc | ||||
|   * tests - unit tests and etc | ||||
| - assets - assets used by applications and services | ||||
|  * compiled - compilation results | ||||
|  * icons - source icons images | ||||
|   * compiled - compilation results | ||||
|   * icons - source icons images | ||||
| - bootloader - bootloader for flipper | ||||
|  * src - bootloader sources | ||||
|  * targets - targets' hal and implementation | ||||
|   * src - bootloader sources | ||||
|   * targets - targets' hal and implementation | ||||
| - core - core libraries: home for furi | ||||
| - debug - debug helpers, plugins and tools | ||||
| - docker - docker image sources (used for automated firmware build) | ||||
| - firmware - firmware for flipper | ||||
|  * targets - targets' hal and implementation | ||||
|   * targets - targets' hal and implementation | ||||
| - lib - different libraries and drivers that apps and firmware uses | ||||
|  * ST25RFAL002 - ST253916 driver and NFC hal | ||||
|  * STM32CubeWB - STM32WB hal | ||||
|  * app-scened-template - scened template app library | ||||
|  * app-template - template app library | ||||
|  * callback-connector - callback connector library | ||||
|  * common-api - common api delaration library | ||||
|  * cyfral - cyfral library | ||||
|  * drivers - drivers that we wrote | ||||
|  * fatfs - external storage file system | ||||
|  * fnv1a-hash - fnv1a hash library  | ||||
|  * irda - irda library | ||||
|  * littlefs - internal storage file system | ||||
|  * mlib - algorithms and containers  | ||||
|  * nfc_protocols - nfc protocols library | ||||
|  * onewire - one wire library  | ||||
|  * qrcode - qr code generator library | ||||
|  * subghz - subghz library | ||||
|  * toolbox - toolbox of things that we are using but don't place in core | ||||
|  * u8g2 - graphics library that we use to draw GUI | ||||
|   * ST25RFAL002 - ST253916 driver and NFC hal | ||||
|   * STM32CubeWB - STM32WB hal | ||||
|   * app-scened-template - scened template app library | ||||
|   * app-template - template app library | ||||
|   * callback-connector - callback connector library | ||||
|   * common-api - common api delaration library | ||||
|   * cyfral - cyfral library | ||||
|   * drivers - drivers that we wrote | ||||
|   * fatfs - external storage file system | ||||
|   * fnv1a-hash - fnv1a hash library  | ||||
|   * irda - irda library | ||||
|   * littlefs - internal storage file system | ||||
|   * mlib - algorithms and containers  | ||||
|   * nfc_protocols - nfc protocols library | ||||
|   * onewire - one wire library  | ||||
|   * qrcode - qr code generator library | ||||
|   * subghz - subghz library | ||||
|   * toolbox - toolbox of things that we are using but don't place in core | ||||
|   * u8g2 - graphics library that we use to draw GUI | ||||
| - make - make helpers | ||||
| - scripts - supplimentary scripts | ||||
|  | ||||
| @ -28,9 +28,6 @@ extern int32_t keypad_test_app(void* p); | ||||
| extern int32_t lfrfid_app(void* p); | ||||
| extern int32_t lfrfid_debug_app(void* p); | ||||
| extern int32_t nfc_app(void* p); | ||||
| extern int32_t passport_app(void* p); | ||||
| extern int32_t food_minigame_app(void* p); | ||||
| extern int32_t scene_app(void* p); | ||||
| extern int32_t scened_app(void* p); | ||||
| extern int32_t storage_test_app(void* p); | ||||
| extern int32_t subghz_app(void* p); | ||||
| @ -248,19 +245,6 @@ const FlipperApplication FLIPPER_ARCHIVE = | ||||
|     {.app = archive_app, .name = "Archive", .stack_size = 4096, .icon = &A_FileManager_14}; | ||||
| #endif | ||||
| 
 | ||||
| #ifdef SRV_DOLPHIN | ||||
| const FlipperApplication FLIPPER_SCENE = | ||||
|     {.app = scene_app, .name = "Scenes", .stack_size = 1024, .icon = &A_Games_14}; | ||||
| 
 | ||||
| const FlipperApplication FLIPPER_SCENE_APPS[] = { | ||||
|     {.app = passport_app, .name = "Passport", .stack_size = 1024, .icon = &A_Games_14}, | ||||
|     {.app = food_minigame_app, .name = "Food minigame", .stack_size = 1024, .icon = &A_Games_14}, | ||||
| }; | ||||
| 
 | ||||
| const size_t FLIPPER_SCENE_APPS_COUNT = sizeof(FLIPPER_SCENE_APPS) / sizeof(FlipperApplication); | ||||
| 
 | ||||
| #endif | ||||
| 
 | ||||
| // Settings menu
 | ||||
| const FlipperApplication FLIPPER_SETTINGS_APPS[] = { | ||||
| #ifdef SRV_NOTIFICATION | ||||
|  | ||||
| @ -10,9 +10,15 @@ static void dolphin_switch_to_app(Dolphin* dolphin, const FlipperApplication* fl | ||||
|     furi_assert(flipper_app->app); | ||||
|     furi_assert(flipper_app->name); | ||||
| 
 | ||||
|     if(furi_thread_get_state(dolphin->scene_thread) != FuriThreadStateStopped) { | ||||
|         FURI_LOG_E("Dolphin", "Thread is already running"); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     furi_thread_set_name(dolphin->scene_thread, flipper_app->name); | ||||
|     furi_thread_set_stack_size(dolphin->scene_thread, flipper_app->stack_size); | ||||
|     furi_thread_set_callback(dolphin->scene_thread, flipper_app->app); | ||||
| 
 | ||||
|     furi_thread_start(dolphin->scene_thread); | ||||
| } | ||||
| 
 | ||||
| @ -117,14 +123,8 @@ bool dolphin_view_idle_main_input(InputEvent* event, void* context) { | ||||
|             with_value_mutex( | ||||
|                 dolphin->menu_vm, (Menu * menu) { menu_ok(menu); }); | ||||
|         } else if(event->key == InputKeyUp && event->type == InputTypeShort) { | ||||
|             osTimerStart(dolphin->timeout_timer, 40); | ||||
|             osTimerStart(dolphin->timeout_timer, 64); | ||||
|             view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewLockMenu); | ||||
|         } else if(event->key == InputKeyLeft && event->type == InputTypeShort) { | ||||
| #if 0 | ||||
|             dolphin_switch_to_app(dolphin, &FAV_APP); | ||||
| #endif | ||||
|         } else if(event->key == InputKeyRight && event->type == InputTypeShort) { | ||||
|             dolphin_switch_to_app(dolphin, &FLIPPER_SCENE); | ||||
|         } else if(event->key == InputKeyDown && event->type == InputTypeShort) { | ||||
|             dolphin_switch_to_app(dolphin, &FLIPPER_ARCHIVE); | ||||
|         } else if(event->key == InputKeyDown && event->type == InputTypeLong) { | ||||
| @ -180,6 +180,12 @@ static void lock_menu_callback(void* context, uint8_t index) { | ||||
|         break; | ||||
| 
 | ||||
|     default: | ||||
|         // wip message
 | ||||
|         with_view_model( | ||||
|             dolphin->view_lockmenu, (DolphinViewLockMenuModel * model) { | ||||
|                 model->hint_timeout = HINT_TIMEOUT_H; | ||||
|                 return true; | ||||
|             }); | ||||
|         break; | ||||
|     } | ||||
| } | ||||
| @ -199,6 +205,8 @@ bool dolphin_view_lockmenu_input(InputEvent* event, void* context) { | ||||
| 
 | ||||
|     DolphinViewLockMenuModel* model = view_get_model(dolphin->view_lockmenu); | ||||
| 
 | ||||
|     model->hint_timeout = 0; // clear hint timeout
 | ||||
| 
 | ||||
|     if(event->key == InputKeyUp) { | ||||
|         model->idx = CLAMP(model->idx - 1, 2, 0); | ||||
|     } else if(event->key == InputKeyDown) { | ||||
|  | ||||
| @ -46,8 +46,6 @@ struct Dolphin { | ||||
|     View* idle_view_first_start; | ||||
|     View* idle_view_main; | ||||
|     View* idle_view_dolphin_stats; | ||||
|     View* idle_view_down; | ||||
|     View* idle_view_meta; | ||||
|     View* view_hw_mismatch; | ||||
|     View* view_lockmenu; | ||||
|     ViewPort* lock_viewport; | ||||
|  | ||||
| @ -63,7 +63,7 @@ void dolphin_view_idle_main_draw(Canvas* canvas, void* model) { | ||||
|         canvas_draw_icon_animation(canvas, 0, -3, m->animation); | ||||
|     } | ||||
| 
 | ||||
|     if(m->hint_timeout > 0) { | ||||
|     if(m->hint_timeout) { | ||||
|         m->hint_timeout--; | ||||
|         if(m->locked) { | ||||
|             canvas_draw_icon(canvas, 13, 5, &I_LockPopup_100x49); | ||||
| @ -98,10 +98,19 @@ void dolphin_view_lockmenu_draw(Canvas* canvas, void* model) { | ||||
|         if(m->door_left_x == -57) { | ||||
|             for(uint8_t i = 0; i < 3; ++i) { | ||||
|                 canvas_draw_str_aligned( | ||||
|                     canvas, 64, 13 + (i * 17), AlignCenter, AlignCenter, Lockmenu_Items[i]); | ||||
|                     canvas, | ||||
|                     64, | ||||
|                     13 + (i * 17), | ||||
|                     AlignCenter, | ||||
|                     AlignCenter, | ||||
|                     (m->hint_timeout && m->idx == i) ? "Not implemented" : Lockmenu_Items[i]); | ||||
|                 if(m->idx == i) elements_frame(canvas, 15, 5 + (i * 17), 98, 15); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if(m->hint_timeout) { | ||||
|             m->hint_timeout--; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -41,6 +41,8 @@ typedef struct { | ||||
|     int8_t door_left_x; | ||||
|     int8_t door_right_x; | ||||
|     uint8_t exit_timeout; | ||||
|     uint8_t hint_timeout; | ||||
| 
 | ||||
|     bool locked; | ||||
| } DolphinViewLockMenuModel; | ||||
| 
 | ||||
|  | ||||
| @ -1,321 +0,0 @@ | ||||
| #include <furi.h> | ||||
| #include <gui/gui.h> | ||||
| #include "dolphin/dolphin_state.h" | ||||
| 
 | ||||
| #define MAX_TRIES 3 | ||||
| #define DISHES_TOTAL 3 | ||||
| #define LID_POS_MAX 20 | ||||
| #define TRY_TIMEOUT 10 | ||||
| 
 | ||||
| typedef enum { | ||||
|     EventTypeTick, | ||||
|     EventTypeKey, | ||||
|     EventTypeDeed, | ||||
| } EventType; | ||||
| 
 | ||||
| typedef struct { | ||||
|     union { | ||||
|         InputEvent input; | ||||
|     } value; | ||||
|     EventType type; | ||||
| } AppEvent; | ||||
| 
 | ||||
| typedef enum { | ||||
|     PlayerChoiceEvent, | ||||
|     OpenLootEvent, | ||||
|     WinEvent, | ||||
|     LooseEvent, | ||||
|     FinishedEvent, | ||||
|     ExitGameEvent, | ||||
|     GameEventTotal, | ||||
| } GameEventType; | ||||
| 
 | ||||
| typedef enum { | ||||
|     LootSkeleton, | ||||
|     LootFish, | ||||
|     LootShit, | ||||
|     LootTotalNum, | ||||
| } LootIdEnum; | ||||
| 
 | ||||
| typedef struct { | ||||
|     GameEventType current_event; | ||||
|     osMessageQueueId_t event_queue; | ||||
|     LootIdEnum loot_list[DISHES_TOTAL]; | ||||
| 
 | ||||
|     uint8_t cursor_pos; | ||||
|     uint8_t lid_pos; | ||||
|     uint8_t timeout; | ||||
|     uint8_t try; | ||||
| 
 | ||||
|     bool selected; | ||||
|     bool deed; | ||||
| 
 | ||||
| } GameState; | ||||
| 
 | ||||
| typedef struct { | ||||
|     const Icon* f; | ||||
|     const Icon* b; | ||||
| } LootGfx; | ||||
| 
 | ||||
| static const Icon* letters[DISHES_TOTAL] = {&I_letterA_10x10, &I_letterB_10x10, &I_letterC_10x10}; | ||||
| 
 | ||||
| static const LootGfx loot[LootTotalNum] = { | ||||
|     [LootSkeleton] = | ||||
|         { | ||||
|             .f = &I_skeleton_25x17, | ||||
|             .b = &I_blackskeleton_25x17, | ||||
|         }, | ||||
|     [LootFish] = | ||||
|         { | ||||
|             .f = &I_fish_25x17, | ||||
|             .b = &I_blackfish_25x17, | ||||
|         }, | ||||
|     [LootShit] = | ||||
|         { | ||||
|             .f = &I_shit_25x17, | ||||
|             .b = &I_blackshit_25x17, | ||||
|         }, | ||||
| }; | ||||
| 
 | ||||
| static void input_callback(InputEvent* input_event, void* ctx) { | ||||
|     osMessageQueueId_t event_queue = ctx; | ||||
|     AppEvent event; | ||||
|     event.type = EventTypeKey; | ||||
|     event.value.input = *input_event; | ||||
|     osMessageQueuePut(event_queue, &event, 0, osWaitForever); | ||||
| } | ||||
| 
 | ||||
| static void draw_dish(Canvas* canvas, GameState* state, uint8_t x, uint8_t y, uint8_t id) { | ||||
|     bool active = state->cursor_pos == id; | ||||
|     bool opened = state->current_event == OpenLootEvent && active; | ||||
| 
 | ||||
|     canvas_set_bitmap_mode(canvas, true); | ||||
|     canvas_set_color(canvas, ColorBlack); | ||||
| 
 | ||||
|     if(active) { | ||||
|         canvas_draw_icon(canvas, x, y, &I_active_plate_48x18); | ||||
|     } | ||||
| 
 | ||||
|     if(opened) { | ||||
|         state->lid_pos = CLAMP(state->lid_pos + 1, LID_POS_MAX, 0); | ||||
|     } | ||||
| 
 | ||||
|     uint8_t lid_pos = (y - 17) - (opened ? state->lid_pos : 0); | ||||
| 
 | ||||
|     canvas_draw_icon(canvas, x + 3, y - 6, &I_plate_42x19); | ||||
| 
 | ||||
|     canvas_set_color(canvas, ColorWhite); | ||||
|     canvas_draw_icon(canvas, x + 11, y - 10, loot[state->loot_list[id]].b); | ||||
|     canvas_set_color(canvas, ColorBlack); | ||||
|     canvas_draw_icon(canvas, x + 11, y - 10, loot[state->loot_list[id]].f); | ||||
| 
 | ||||
|     canvas_set_color(canvas, ColorWhite); | ||||
|     canvas_draw_icon(canvas, x + 6, lid_pos, &I_blacklid_36x27); | ||||
|     canvas_set_color(canvas, ColorBlack); | ||||
|     canvas_draw_icon(canvas, x + 6, lid_pos, &I_lid_36x27); | ||||
|     canvas_set_bitmap_mode(canvas, false); | ||||
| 
 | ||||
|     canvas_draw_icon(canvas, x + 19, y + 8, letters[id]); | ||||
| } | ||||
| 
 | ||||
| static void draw_dishes_scene(Canvas* canvas, GameState* state) { | ||||
|     uint8_t tries_left = MAX_TRIES - state->try; | ||||
|     for(size_t i = 0; i < MAX_TRIES; i++) { | ||||
|         if(i < tries_left) { | ||||
|             canvas_draw_disc(canvas, 5 + i * 8, 5, 2); | ||||
|         } else { | ||||
|             canvas_draw_circle(canvas, 5 + i * 8, 5, 2); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     for(size_t i = 0; i < DISHES_TOTAL; i++) { | ||||
|         draw_dish(canvas, state, i * 40, i % 2 ? 26 : 44, i); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| static void render_callback(Canvas* canvas, void* ctx) { | ||||
|     GameState* state = (GameState*)acquire_mutex((ValueMutex*)ctx, 25); | ||||
|     canvas_clear(canvas); | ||||
| 
 | ||||
|     switch(state->current_event) { | ||||
|     case WinEvent: | ||||
|         canvas_draw_str(canvas, 30, 30, "Dolphin_happy.png"); | ||||
|         break; | ||||
|     case LooseEvent: | ||||
|         canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignCenter, "Try again!"); | ||||
|         break; | ||||
|     case ExitGameEvent: | ||||
|         break; | ||||
|     case FinishedEvent: | ||||
|         break; | ||||
|     default: | ||||
|         draw_dishes_scene(canvas, state); | ||||
|         break; | ||||
|     } | ||||
| 
 | ||||
|     release_mutex((ValueMutex*)ctx, state); | ||||
| } | ||||
| static void reset_lid_pos(GameState* state) { | ||||
|     state->selected = false; | ||||
|     state->lid_pos = 0; | ||||
| } | ||||
| 
 | ||||
| void dolphin_food_deed(GameState* state) { | ||||
|     furi_assert(state); | ||||
|     AppEvent event; | ||||
|     event.type = EventTypeDeed; | ||||
|     furi_check(osMessageQueuePut(state->event_queue, &event, 0, osWaitForever) == osOK); | ||||
| } | ||||
| 
 | ||||
| static void reset_loot_array(GameState* state) { | ||||
|     for(size_t i = 0; i < LootTotalNum; i++) { | ||||
|         state->loot_list[i] = i; | ||||
|     } | ||||
| 
 | ||||
|     for(size_t i = 0; i < LootTotalNum; i++) { | ||||
|         int temp = state->loot_list[i]; | ||||
|         int r_idx = rand() % LootTotalNum; | ||||
| 
 | ||||
|         state->loot_list[i] = state->loot_list[r_idx]; | ||||
|         state->loot_list[r_idx] = temp; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| static bool selected_is_food(GameState* state) { | ||||
|     return state->loot_list[state->cursor_pos] == LootFish; | ||||
| } | ||||
| 
 | ||||
| static bool tries_exceed(GameState* state) { | ||||
|     return state->try == MAX_TRIES; | ||||
| } | ||||
| 
 | ||||
| static bool timeout_exceed(GameState* state) { | ||||
|     return state->timeout == TRY_TIMEOUT; | ||||
| } | ||||
| 
 | ||||
| static void gamestate_update(GameState* state, DolphinState* dolphin_state) { | ||||
|     switch(state->current_event) { | ||||
|     case PlayerChoiceEvent: | ||||
|         if(state->selected) { | ||||
|             state->current_event = OpenLootEvent; | ||||
|         } | ||||
|         break; | ||||
|     case OpenLootEvent: | ||||
|         state->timeout = CLAMP(state->timeout + 1, TRY_TIMEOUT, 0); | ||||
|         if(timeout_exceed(state)) { | ||||
|             state->timeout = 0; | ||||
|             state->current_event = selected_is_food(state) ? WinEvent : LooseEvent; | ||||
|             state->deed = selected_is_food(state); | ||||
|         } | ||||
|         break; | ||||
|     case LooseEvent: | ||||
|         state->timeout = CLAMP(state->timeout + 1, TRY_TIMEOUT, 0); | ||||
|         if(timeout_exceed(state)) { | ||||
|             state->timeout = 0; | ||||
|             state->current_event = FinishedEvent; | ||||
|         } | ||||
|         break; | ||||
|     case WinEvent: | ||||
|         if(state->deed) { | ||||
|             dolphin_food_deed(state); | ||||
|         } | ||||
|         break; | ||||
|     case FinishedEvent: | ||||
|         reset_lid_pos(state); | ||||
|         reset_loot_array(state); | ||||
| 
 | ||||
|         state->try++; | ||||
|         state->current_event = tries_exceed(state) ? ExitGameEvent : PlayerChoiceEvent; | ||||
|         break; | ||||
| 
 | ||||
|     default: | ||||
|         break; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| static void food_minigame_controls(GameState* state, AppEvent* event) { | ||||
|     furi_assert(state); | ||||
|     furi_assert(event); | ||||
| 
 | ||||
|     if(event->value.input.key == InputKeyRight) { | ||||
|         if(state->current_event == PlayerChoiceEvent) { | ||||
|             state->cursor_pos = CLAMP(state->cursor_pos + 1, DISHES_TOTAL - 1, 0); | ||||
|         } | ||||
|     } else if(event->value.input.key == InputKeyLeft) { | ||||
|         if(state->current_event == PlayerChoiceEvent) { | ||||
|             state->cursor_pos = CLAMP(state->cursor_pos - 1, DISHES_TOTAL - 1, 0); | ||||
|         } | ||||
|     } else if(event->value.input.key == InputKeyOk) { | ||||
|         switch(state->current_event) { | ||||
|         case PlayerChoiceEvent: | ||||
|             state->selected = true; | ||||
|             break; | ||||
|         case WinEvent: | ||||
|             state->current_event = FinishedEvent; | ||||
|             break; | ||||
|         default: | ||||
|             break; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| int32_t food_minigame_app(void* p) { | ||||
|     GameState* state = furi_alloc(sizeof(GameState)); | ||||
|     DolphinState* dolphin_state = dolphin_state_alloc(); | ||||
|     dolphin_state_load(dolphin_state); | ||||
| 
 | ||||
|     ValueMutex state_mutex; | ||||
| 
 | ||||
|     state->event_queue = osMessageQueueNew(2, sizeof(AppEvent), NULL); | ||||
| 
 | ||||
|     furi_check(state->event_queue); | ||||
| 
 | ||||
|     if(!init_mutex(&state_mutex, state, sizeof(GameState*))) { | ||||
|         printf("[Food minigame] cannot create mutex\r\n"); | ||||
|         return 0; | ||||
|     } | ||||
| 
 | ||||
|     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, state->event_queue); | ||||
| 
 | ||||
|     Gui* gui = furi_record_open("gui"); | ||||
|     gui_add_view_port(gui, view_port, GuiLayerFullscreen); | ||||
| 
 | ||||
|     reset_loot_array(state); | ||||
| 
 | ||||
|     AppEvent event; | ||||
|     while(1) { | ||||
|         osStatus_t event_status = osMessageQueueGet(state->event_queue, &event, NULL, 100); | ||||
|         if(event_status == osOK) { | ||||
|             if(event.type == EventTypeKey && event.value.input.type == InputTypeShort) { | ||||
|                 food_minigame_controls(state, &event); | ||||
| 
 | ||||
|                 if(event.value.input.key == InputKeyBack) { | ||||
|                     break; | ||||
|                 } | ||||
|             } else if(event.type == EventTypeDeed) { | ||||
|                 dolphin_state_on_deed(dolphin_state, DolphinDeedIButtonRead); | ||||
|                 dolphin_state_save(dolphin_state); | ||||
|                 state->deed = false; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if(state->current_event == ExitGameEvent) { | ||||
|             break; | ||||
|         } | ||||
|         gamestate_update(state, dolphin_state); | ||||
|         view_port_update(view_port); | ||||
|     } | ||||
| 
 | ||||
|     gui_remove_view_port(gui, view_port); | ||||
|     view_port_free(view_port); | ||||
|     furi_record_close("gui"); | ||||
|     delete_mutex(&state_mutex); | ||||
|     osMessageQueueDelete(state->event_queue); | ||||
|     dolphin_state_free(dolphin_state); | ||||
|     free(state); | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
| @ -1,147 +0,0 @@ | ||||
| #include <furi.h> | ||||
| #include <gui/gui.h> | ||||
| #include <furi-hal-version.h> | ||||
| #include "dolphin/dolphin.h" | ||||
| #include "dolphin/dolphin_state.h" | ||||
| #include "math.h" | ||||
| 
 | ||||
| #define MOODS_TOTAL 3 | ||||
| #define BUTTHURT_MAX 3 | ||||
| 
 | ||||
| typedef enum { | ||||
|     EventTypeTick, | ||||
|     EventTypeKey, | ||||
| } EventType; | ||||
| 
 | ||||
| typedef struct { | ||||
|     union { | ||||
|         InputEvent input; | ||||
|     } value; | ||||
|     EventType type; | ||||
| } AppEvent; | ||||
| 
 | ||||
| // Moods, corresponding to butthurt level. (temp, unclear about max level)
 | ||||
| static const char* mood_strings[MOODS_TOTAL] = {[0] = "Happy", [1] = "Ok", [2] = "Bad"}; | ||||
| 
 | ||||
| static const Icon* portrait_happy[BUTTHURT_MAX] = { | ||||
|     &I_passport_happy1_43x45, | ||||
|     &I_passport_happy2_43x45, | ||||
|     &I_passport_happy3_43x45}; | ||||
| static const Icon* portrait_ok[BUTTHURT_MAX] = { | ||||
|     &I_passport_okay1_43x45, | ||||
|     &I_passport_okay2_43x45, | ||||
|     &I_passport_okay3_43x45}; | ||||
| static const Icon* portrait_bad[BUTTHURT_MAX] = { | ||||
|     &I_passport_bad1_43x45, | ||||
|     &I_passport_bad2_43x45, | ||||
|     &I_passport_bad3_43x45}; | ||||
| static const Icon** portraits[MOODS_TOTAL] = {portrait_happy, portrait_ok, portrait_bad}; | ||||
| 
 | ||||
| static void input_callback(InputEvent* input_event, void* ctx) { | ||||
|     osMessageQueueId_t event_queue = ctx; | ||||
|     AppEvent event; | ||||
|     event.type = EventTypeKey; | ||||
|     event.value.input = *input_event; | ||||
|     osMessageQueuePut(event_queue, &event, 0, osWaitForever); | ||||
| } | ||||
| 
 | ||||
| static void render_callback(Canvas* canvas, void* ctx) { | ||||
|     DolphinState* state = (DolphinState*)acquire_mutex((ValueMutex*)ctx, 25); | ||||
| 
 | ||||
|     char level[20]; | ||||
|     char mood[32]; | ||||
| 
 | ||||
|     uint32_t butthurt = CLAMP(dolphin_state_get_butthurt(state), BUTTHURT_MAX - 1, 0); | ||||
|     uint32_t current_level = dolphin_state_get_level(state); | ||||
|     uint32_t prev_cap = dolphin_state_xp_to_levelup(state, current_level - 1, false); | ||||
|     uint32_t exp = (dolphin_state_xp_to_levelup(state, current_level, true) * 63) / | ||||
|                    (dolphin_state_xp_to_levelup(state, current_level, false) - prev_cap); | ||||
|     uint8_t portrait_level = CLAMP(floor(current_level / 14), MOODS_TOTAL - 1, 0); | ||||
| 
 | ||||
|     canvas_clear(canvas); | ||||
| 
 | ||||
|     // multipass
 | ||||
|     canvas_draw_icon(canvas, 0, 0, &I_PassportLeft_6x47); | ||||
|     canvas_draw_icon(canvas, 0, 47, &I_PassportBottom_128x17); | ||||
|     canvas_draw_line(canvas, 6, 0, 125, 0); | ||||
|     canvas_draw_line(canvas, 127, 2, 127, 47); | ||||
|     canvas_draw_dot(canvas, 126, 1); | ||||
| 
 | ||||
|     //portrait frame
 | ||||
|     canvas_draw_line(canvas, 9, 6, 9, 53); | ||||
|     canvas_draw_line(canvas, 10, 5, 52, 5); | ||||
|     canvas_draw_line(canvas, 55, 8, 55, 53); | ||||
|     canvas_draw_line(canvas, 10, 54, 54, 54); | ||||
|     canvas_draw_line(canvas, 53, 5, 55, 7); | ||||
| 
 | ||||
|     // portrait
 | ||||
|     canvas_draw_icon(canvas, 10, 9, portraits[butthurt][portrait_level]); | ||||
|     canvas_draw_line(canvas, 59, 18, 124, 18); | ||||
|     canvas_draw_line(canvas, 59, 31, 124, 31); | ||||
|     canvas_draw_line(canvas, 59, 44, 124, 44); | ||||
| 
 | ||||
|     const char* my_name = furi_hal_version_get_name_ptr(); | ||||
|     canvas_draw_str(canvas, 59, 15, my_name ? my_name : "Unknown"); | ||||
| 
 | ||||
|     snprintf(level, 20, "Level: %ld", current_level); | ||||
|     snprintf(mood, 20, "Mood: %s", mood_strings[butthurt]); | ||||
| 
 | ||||
|     canvas_draw_str(canvas, 59, 28, mood); | ||||
| 
 | ||||
|     canvas_draw_str(canvas, 59, 41, level); | ||||
|     canvas_set_color(canvas, ColorWhite); | ||||
|     canvas_draw_box(canvas, 123 - exp, 48, exp + 1, 6); | ||||
|     canvas_set_color(canvas, ColorBlack); | ||||
|     canvas_draw_line(canvas, 123 - exp, 48, 123 - exp, 54); | ||||
| 
 | ||||
|     release_mutex((ValueMutex*)ctx, state); | ||||
| } | ||||
| 
 | ||||
| int32_t passport_app(void* p) { | ||||
|     DolphinState* dolphin_state = dolphin_state_alloc(); | ||||
|     ValueMutex state_mutex; | ||||
|     dolphin_state_load(dolphin_state); | ||||
| 
 | ||||
|     osMessageQueueId_t event_queue = osMessageQueueNew(2, sizeof(AppEvent), NULL); | ||||
|     furi_check(event_queue); | ||||
| 
 | ||||
|     if(!init_mutex(&state_mutex, dolphin_state, sizeof(DolphinState*))) { | ||||
|         printf("[Passport] cannot create mutex\r\n"); | ||||
|         return 0; | ||||
|     } | ||||
| 
 | ||||
|     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); | ||||
| 
 | ||||
|     Gui* gui = furi_record_open("gui"); | ||||
|     gui_add_view_port(gui, view_port, GuiLayerFullscreen); | ||||
| 
 | ||||
|     AppEvent event; | ||||
|     while(1) { | ||||
|         osStatus_t event_status = osMessageQueueGet(event_queue, &event, NULL, 25); | ||||
|         if(event_status == osOK) { | ||||
|             if(event.type == EventTypeKey && event.value.input.type == InputTypeShort && | ||||
|                event.value.input.key == InputKeyBack) { | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         view_port_update(view_port); | ||||
|     } | ||||
| 
 | ||||
|     gui_remove_view_port(gui, view_port); | ||||
| 
 | ||||
|     view_port_free(view_port); | ||||
| 
 | ||||
|     furi_record_close("gui"); | ||||
| 
 | ||||
|     delete_mutex(&state_mutex); | ||||
| 
 | ||||
|     osMessageQueueDelete(event_queue); | ||||
| 
 | ||||
|     dolphin_state_free(dolphin_state); | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
| @ -1,12 +0,0 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| // temp
 | ||||
| const char* console_emotes[] = { | ||||
|     "Run it, m8", | ||||
|     "Lets GOOOO", | ||||
|     "Click it, buddy", | ||||
|     "I wanna play", | ||||
|     "Wtf is this?", | ||||
|     "Just do it", | ||||
|     "JUST DO IT!", | ||||
| }; | ||||
| @ -1,233 +0,0 @@ | ||||
| #include <gui/elements.h> | ||||
| #include "applications.h" | ||||
| #include "items_i.h" | ||||
| #include "emotes.h" | ||||
| #include <gui/icon_i.h> | ||||
| 
 | ||||
| const Item Food = { | ||||
|     .layer = 4, | ||||
|     .timeout = 100, | ||||
|     .pos = | ||||
|         { | ||||
|             .x = 0, | ||||
|             .y = 90, | ||||
|         }, | ||||
|     .width = 60, | ||||
|     .height = 50, | ||||
|     .draw = food_redraw, | ||||
|     .callback = food_callback}; | ||||
| 
 | ||||
| const Item Console = { | ||||
|     .layer = 4, | ||||
|     .timeout = 100, | ||||
|     .pos = | ||||
|         { | ||||
|             .x = 357, | ||||
|             .y = 190, | ||||
|         }, | ||||
|     .width = 40, | ||||
|     .height = 20, | ||||
|     .draw = console_redraw, | ||||
|     .callback = console_callback}; | ||||
| 
 | ||||
| const Item* Home[] = {&Food, &Console}; | ||||
| 
 | ||||
| const Item** Scenes[] = {Home}; | ||||
| 
 | ||||
| const Item** get_scene(SceneState* state) { | ||||
|     return Scenes[state->scene_id]; | ||||
| } | ||||
| 
 | ||||
| static void dolphin_scene_start_app(SceneState* state, const FlipperApplication* flipper_app) { | ||||
|     furi_assert(state); | ||||
|     furi_assert(flipper_app); | ||||
| 
 | ||||
|     state->scene_app_thread = furi_thread_alloc(); | ||||
| 
 | ||||
|     furi_assert(flipper_app->app); | ||||
|     furi_assert(flipper_app->name); | ||||
| 
 | ||||
|     furi_thread_set_name(state->scene_app_thread, flipper_app->name); | ||||
|     furi_thread_set_stack_size(state->scene_app_thread, flipper_app->stack_size); | ||||
|     furi_thread_set_callback(state->scene_app_thread, flipper_app->app); | ||||
|     furi_thread_start(state->scene_app_thread); | ||||
| } | ||||
| 
 | ||||
| uint16_t roll_new(uint16_t prev, uint16_t max) { | ||||
|     uint16_t val = 999; | ||||
|     while(val != prev) { | ||||
|         val = random() % max; | ||||
|         break; | ||||
|     } | ||||
|     return val; | ||||
| } | ||||
| 
 | ||||
| static void dolphin_scene_type_text( | ||||
|     Canvas* canvas, | ||||
|     SceneState* state, | ||||
|     uint8_t x, | ||||
|     uint8_t y, | ||||
|     const char* text) { | ||||
|     char dialog_str[64]; | ||||
|     char buf[64]; | ||||
| 
 | ||||
|     strcpy(dialog_str, (char*)text); | ||||
| 
 | ||||
|     if(state->dialog_progress <= strlen(dialog_str)) { | ||||
|         if(HAL_GetTick() / 10 % 2 == 0) state->dialog_progress++; | ||||
|         dialog_str[state->dialog_progress] = '\0'; | ||||
|         snprintf(buf, state->dialog_progress, dialog_str); | ||||
|     } else { | ||||
|         snprintf(buf, 64, dialog_str); | ||||
|     } | ||||
| 
 | ||||
|     canvas_draw_str_aligned(canvas, x, y, AlignCenter, AlignCenter, buf); | ||||
| } | ||||
| 
 | ||||
| const void scene_activate_item_callback(SceneState* state, Canvas* canvas) { | ||||
|     furi_assert(state); | ||||
|     furi_assert(canvas); | ||||
| 
 | ||||
|     const Item* near = is_nearby(state); | ||||
|     if(near && state->use_pending == true) { | ||||
|         state->action_timeout = near->timeout; | ||||
|         near->callback(canvas, state); | ||||
|         state->use_pending = false; | ||||
|     } else if(near) { | ||||
|         near->callback(canvas, state); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| const Vec2 item_get_pos(SceneState* state, ItemsEnum item) { | ||||
|     const Item** current = get_scene(state); | ||||
|     Vec2 rel_pos = {0, 0}; | ||||
| 
 | ||||
|     rel_pos.x = DOLPHIN_WIDTH / 2 + (current[item]->pos.x * PARALLAX(current[item]->layer)); | ||||
|     rel_pos.y = DOLPHIN_WIDTH / 4 + (current[item]->pos.y * PARALLAX(current[item]->layer)); | ||||
| 
 | ||||
|     return rel_pos; | ||||
| } | ||||
| 
 | ||||
| const Item* is_nearby(SceneState* state) { | ||||
|     furi_assert(state); | ||||
|     uint8_t item = 0; | ||||
|     bool found = false; | ||||
|     const Item** current = get_scene(state); | ||||
|     while(item < ItemsEnumTotal) { | ||||
|         int32_t rel_x = | ||||
|             (DOLPHIN_CENTER + DOLPHIN_WIDTH / 2 - | ||||
|              (current[item]->pos.x - state->player_global.x) * PARALLAX(current[item]->layer)); | ||||
| 
 | ||||
|         uint8_t item_height = current[item]->height; | ||||
|         uint8_t item_width = current[item]->width; | ||||
| 
 | ||||
|         int32_t rel_y = current[item]->pos.y - state->player_global.y; | ||||
| 
 | ||||
|         if(abs(rel_x) <= item_width && abs(rel_y) <= item_height) { | ||||
|             found = !found; | ||||
|             break; | ||||
|         } | ||||
|         ++item; | ||||
|     } | ||||
|     return found ? current[item] : NULL; | ||||
| } | ||||
| 
 | ||||
| void food_redraw(Canvas* canvas, void* s) { | ||||
|     furi_assert(s); | ||||
|     SceneState* state = s; | ||||
| 
 | ||||
|     const Icon* food_frames[] = { | ||||
|         &I_food1_61x98, | ||||
|         &I_food2_61x98, | ||||
|         &I_food3_61x98, | ||||
|         &I_food4_61x98, | ||||
|         &I_food5_61x98, | ||||
|         &I_food6_61x98, | ||||
|         &I_food7_61x98, | ||||
|         &I_food8_61x98, | ||||
|         &I_food9_61x98, | ||||
|         &I_food10_61x98, | ||||
|         &I_food11_61x98, | ||||
|         &I_food12_61x98, | ||||
|     }; | ||||
| 
 | ||||
|     uint8_t frame = ((HAL_GetTick() / 200) % SIZEOF_ARRAY(food_frames)); | ||||
| 
 | ||||
|     if(is_nearby(state) && (state->player_global.y > Food.pos.y)) { | ||||
|         dolphin_scene_type_text( | ||||
|             canvas, | ||||
|             state, | ||||
|             (Food.pos.x - state->player_global.x) * PARALLAX(Food.layer) + 90, | ||||
|             state->screen.y + 8, | ||||
|             console_emotes[state->emote_id]); | ||||
| 
 | ||||
|     } else { | ||||
|         state->dialog_progress = 0; | ||||
|         state->emote_id = roll_new(state->previous_emote, SIZEOF_ARRAY(console_emotes)); | ||||
|     } | ||||
| 
 | ||||
|     canvas_draw_icon( | ||||
|         canvas, | ||||
|         (Food.pos.x - state->player_global.x) * PARALLAX(Food.layer), | ||||
|         Food.pos.y - state->player_global.y, | ||||
|         food_frames[frame]); | ||||
| 
 | ||||
|     canvas_set_bitmap_mode(canvas, true); | ||||
| } | ||||
| 
 | ||||
| void food_callback(Canvas* canvas, void* s) { | ||||
|     furi_assert(s); | ||||
|     SceneState* state = s; | ||||
|     if(state->use_pending) { | ||||
|         dolphin_scene_start_app(state, &FLIPPER_SCENE_APPS[1]); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void console_redraw(Canvas* canvas, void* s) { | ||||
|     furi_assert(s); | ||||
|     SceneState* state = s; | ||||
| 
 | ||||
|     const Icon* console[] = { | ||||
|         &I_Console_74x67_0, | ||||
|         &I_Console_74x67_1, | ||||
|         &I_Console_74x67_2, | ||||
|         &I_Console_74x67_3, | ||||
|         &I_Console_74x67_4, | ||||
|         &I_Console_74x67_5, | ||||
|         &I_Console_74x67_6, | ||||
|         &I_Console_74x67_7, | ||||
|         &I_Console_74x67_8, | ||||
| 
 | ||||
|     }; | ||||
| 
 | ||||
|     uint8_t frame = ((HAL_GetTick() / 100) % SIZEOF_ARRAY(console)); | ||||
| 
 | ||||
|     canvas_draw_icon( | ||||
|         canvas, | ||||
|         (Console.pos.x - state->player_global.x) * PARALLAX(Console.layer), | ||||
|         Console.pos.y - state->player_global.y, | ||||
|         console[frame]); | ||||
| 
 | ||||
|     canvas_set_bitmap_mode(canvas, true); | ||||
| 
 | ||||
|     if(is_nearby(state)) { | ||||
|         dolphin_scene_type_text( | ||||
|             canvas, | ||||
|             state, | ||||
|             (Console.pos.x - state->player_global.x) * PARALLAX(Console.layer) - 25, | ||||
|             Console.pos.y - state->player_global.y + 14, | ||||
|             console_emotes[state->emote_id]); | ||||
| 
 | ||||
|     } else { | ||||
|         state->dialog_progress = 0; | ||||
|         state->emote_id = roll_new(state->previous_emote, SIZEOF_ARRAY(console_emotes)); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void console_callback(Canvas* canvas, void* s) { | ||||
|     furi_assert(s); | ||||
|     SceneState* state = s; | ||||
|     if(state->use_pending) { | ||||
|         dolphin_scene_start_app(state, &FLIPPER_SCENE_APPS[0]); | ||||
|     } | ||||
| } | ||||
| @ -1,14 +0,0 @@ | ||||
| #pragma once | ||||
| #include "dolphin/scenes/scene.h" | ||||
| 
 | ||||
| typedef enum { | ||||
|     ItemsFood, | ||||
|     ItemsConsole, | ||||
|     ItemsEnumTotal, | ||||
| } ItemsEnum; | ||||
| 
 | ||||
| uint16_t roll_new(uint16_t prev, uint16_t max); | ||||
| const Vec2 item_get_pos(SceneState* state, ItemsEnum item); | ||||
| const Item* is_nearby(SceneState* state); | ||||
| const Item** get_scene(SceneState* state); | ||||
| const void scene_activate_item_callback(SceneState* state, Canvas* canvas); | ||||
| @ -1,8 +0,0 @@ | ||||
| #pragma once | ||||
| #include "items.h" | ||||
| 
 | ||||
| void food_redraw(Canvas* canvas, void* state); | ||||
| void food_callback(Canvas* canvas, void* state); | ||||
| 
 | ||||
| void console_redraw(Canvas* canvas, void* state); | ||||
| void console_callback(Canvas* canvas, void* state); | ||||
| @ -1,276 +0,0 @@ | ||||
| #pragma once | ||||
| #include "dolphin/scenes/scene.h" | ||||
| 
 | ||||
| const DolphinFrame up = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_up1_73x61, | ||||
|                 .b = &I_black_up1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_up2_73x61, | ||||
|                 .b = &I_black_up2_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 2, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame up_down = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_updown1_73x61, | ||||
|                 .b = &I_black_updown1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_updown2_73x61, | ||||
|                 .b = &I_black_updown2_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_updown3_73x61, | ||||
|                 .b = &I_black_updown3_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 3, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame up_right = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_upright1_73x61, | ||||
|                 .b = &I_black_upright1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_upright2_73x61, | ||||
|                 .b = &I_black_upright2_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 2, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame up_left = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_upleft1_73x61, | ||||
|                 .b = &I_black_upleft1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_upleft2_73x61, | ||||
|                 .b = &I_black_upleft2_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 2, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame right = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_right1_73x61, | ||||
|                 .b = &I_black_right1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_right2_73x61, | ||||
|                 .b = &I_black_right2_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_right3_73x61, | ||||
|                 .b = &I_black_right3_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 3, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame right_up = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_rightup1_73x61, | ||||
|                 .b = &I_black_rightup1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_rightup2_73x61, | ||||
|                 .b = &I_black_rightup2_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 2, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame right_down = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_rightdown1_73x61, | ||||
|                 .b = &I_black_rightdown1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_rightdown2_73x61, | ||||
|                 .b = &I_black_rightdown2_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 2, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame right_left = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_rightleft1_73x61, | ||||
|                 .b = &I_black_rightleft1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_rightleft2_73x61, | ||||
|                 .b = &I_black_rightleft2_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 2, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame down = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_down1_73x61, | ||||
|                 .b = &I_black_down1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_down2_73x61, | ||||
|                 .b = &I_black_down2_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 2, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame down_up = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_downup1_73x61, | ||||
|                 .b = &I_black_downup1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_downup2_73x61, | ||||
|                 .b = &I_black_downup2_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_downup3_73x61, | ||||
|                 .b = &I_black_downup3_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 3, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame down_left = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_downleft1_73x61, | ||||
|                 .b = &I_black_downleft1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_downleft2_73x61, | ||||
|                 .b = &I_black_downleft2_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_downleft3_73x61, | ||||
|                 .b = &I_black_downleft3_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 3, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame down_right = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_downright1_73x61, | ||||
|                 .b = &I_black_downright1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_downright2_73x61, | ||||
|                 .b = &I_black_downright2_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_downright3_73x61, | ||||
|                 .b = &I_black_downright3_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 3, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame left = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_left1_73x61, | ||||
|                 .b = &I_black_left1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_left2_73x61, | ||||
|                 .b = &I_black_left2_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_left3_73x61, | ||||
|                 .b = &I_black_left3_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 3, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame left_up = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_leftup1_73x61, | ||||
|                 .b = &I_black_leftup1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_leftup2_73x61, | ||||
|                 .b = &I_black_leftup2_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 2, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame left_down = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_leftdown1_73x61, | ||||
|                 .b = &I_black_leftdown1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_leftdown2_73x61, | ||||
|                 .b = &I_black_leftdown2_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 2, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame left_right = { | ||||
|     .frames = | ||||
|         { | ||||
|             { | ||||
|                 .f = &I_rightleft1_73x61, | ||||
|                 .b = &I_black_rightleft1_73x61, | ||||
|             }, | ||||
|             { | ||||
|                 .f = &I_rightleft2_73x61, | ||||
|                 .b = &I_black_rightleft2_73x61, | ||||
|             }, | ||||
|         }, | ||||
|     .total = 2, | ||||
| }; | ||||
| 
 | ||||
| const DolphinFrame* frames[4][4] = { | ||||
|     [DirUp] = {[DirUp] = &up, [DirRight] = &up_right, [DirDown] = &up_down, [DirLeft] = &up_left}, | ||||
|     [DirRight] = | ||||
|         {[DirUp] = &right_up, [DirRight] = &right, [DirDown] = &right_down, [DirLeft] = &right_left}, | ||||
|     [DirDown] = | ||||
|         {[DirUp] = &down_up, [DirRight] = &down_right, [DirDown] = &down, [DirLeft] = &down_left}, | ||||
|     [DirLeft] = | ||||
|         {[DirUp] = &left_up, [DirRight] = &left_right, [DirDown] = &left_down, [DirLeft] = &left}, | ||||
| }; | ||||
| @ -1,151 +0,0 @@ | ||||
| #include <furi.h> | ||||
| #include <furi-hal.h> | ||||
| #include "scene.h" | ||||
| 
 | ||||
| static SceneAppGui* scene_app_gui = NULL; | ||||
| static ValueMutex* scene_state_mutex = NULL; | ||||
| 
 | ||||
| void dolphin_scene_redraw(Canvas* canvas, void* ctx) { | ||||
|     furi_assert(canvas); | ||||
|     furi_assert(ctx); | ||||
| 
 | ||||
|     SceneState* state = (SceneState*)acquire_mutex((ValueMutex*)ctx, 25); | ||||
|     if(state == NULL) return; // redraw fail
 | ||||
|     uint32_t t = xTaskGetTickCount(); | ||||
| 
 | ||||
|     canvas_clear(canvas); | ||||
|     dolphin_scene_render(state, canvas, t); | ||||
|     dolphin_scene_render_state(state, canvas); | ||||
|     release_mutex((ValueMutex*)ctx, state); | ||||
| } | ||||
| 
 | ||||
| void dolphin_scene_handle_input(SceneState* state, InputEvent* input) { | ||||
|     // printf("[kb] event: %02x %s\n", input->key, input->state ? "pressed" : "released");
 | ||||
|     dolphin_scene_handle_user_input(state, input); | ||||
| } | ||||
| 
 | ||||
| void dolphin_scene_tick_handler(SceneState* state, uint32_t t, uint32_t dt) { | ||||
|     // printf("t: %d, dt: %d\n", t, dt);
 | ||||
|     dolphin_scene_coordinates(state, dt); | ||||
|     dolphin_scene_update_state(state, t, dt); | ||||
| } | ||||
| 
 | ||||
| static void scene_engine_tick_callback(void* p) { | ||||
|     osMessageQueueId_t event_queue = p; | ||||
|     AppEvent event; | ||||
|     event.type = EventTypeTick; | ||||
|     osMessageQueuePut(event_queue, (void*)&event, 0, 0); | ||||
| } | ||||
| 
 | ||||
| static void scene_engine_input_callback(InputEvent* input_event, void* ctx) { | ||||
|     osMessageQueueId_t event_queue = ctx; | ||||
|     AppEvent event; | ||||
|     event.type = EventTypeKey; | ||||
|     event.value.input = *input_event; | ||||
|     osMessageQueuePut(event_queue, (void*)&event, 0, osWaitForever); | ||||
| } | ||||
| 
 | ||||
| void scene_alloc() { | ||||
|     printf("scene_alloc: start\r\n"); | ||||
|     furi_assert(scene_app_gui == NULL); | ||||
|     furi_assert(scene_state_mutex == NULL); | ||||
| 
 | ||||
|     // SceneAppGui
 | ||||
|     scene_app_gui = furi_alloc(sizeof(SceneAppGui)); | ||||
|     scene_app_gui->mqueue = osMessageQueueNew(8, sizeof(AppEvent), NULL); | ||||
|     scene_app_gui->gui = furi_record_open("gui"); | ||||
|     scene_app_gui->view_port = view_port_alloc(); | ||||
|     scene_app_gui->timer = | ||||
|         osTimerNew(scene_engine_tick_callback, osTimerPeriodic, scene_app_gui->mqueue, NULL); | ||||
|     printf("scene_alloc: timer %p\r\n", scene_app_gui->timer); | ||||
|     // Scene State
 | ||||
|     SceneState* scene_state = furi_alloc(sizeof(SceneState)); | ||||
|     scene_state->player.y = DOLPHIN_DEFAULT_Y; | ||||
|     scene_state->player.x = DOLPHIN_CENTER; | ||||
| 
 | ||||
|     scene_state->player_global.x = 160; | ||||
|     scene_state->player_global.y = WORLD_HEIGHT; | ||||
| 
 | ||||
|     scene_state->frame_group = DirRight; | ||||
|     scene_state->frame_type = DirRight; | ||||
|     scene_state->frame_pending = DirRight; | ||||
|     scene_state->last_group = DirRight; | ||||
| 
 | ||||
|     scene_state->screen.x = scene_state->player.x; | ||||
|     scene_state->screen.y = scene_state->player.y; | ||||
|     // scene_state->debug = true;
 | ||||
|     scene_state_mutex = furi_alloc(sizeof(ValueMutex)); | ||||
|     furi_check(init_mutex(scene_state_mutex, scene_state, sizeof(SceneState))); | ||||
| 
 | ||||
|     // Open GUI and register fullscreen view_port
 | ||||
|     view_port_draw_callback_set(scene_app_gui->view_port, dolphin_scene_redraw, scene_state_mutex); | ||||
|     view_port_input_callback_set( | ||||
|         scene_app_gui->view_port, scene_engine_input_callback, scene_app_gui->mqueue); | ||||
|     gui_add_view_port(scene_app_gui->gui, scene_app_gui->view_port, GuiLayerFullscreen); | ||||
|     view_port_enabled_set(scene_app_gui->view_port, true); | ||||
|     printf("scene_alloc: complete\r\n"); | ||||
| } | ||||
| 
 | ||||
| void scene_free() { | ||||
|     printf("scene_free: start\r\n"); | ||||
|     view_port_enabled_set(scene_app_gui->view_port, false); | ||||
|     gui_remove_view_port(scene_app_gui->gui, scene_app_gui->view_port); | ||||
| 
 | ||||
|     SceneState* scene_state = (SceneState*)acquire_mutex_block(scene_state_mutex); | ||||
|     furi_assert(scene_state); | ||||
|     free(scene_state); | ||||
|     release_mutex(scene_state_mutex, scene_state); | ||||
|     delete_mutex(scene_state_mutex); | ||||
|     free(scene_state_mutex); | ||||
|     scene_state_mutex = NULL; | ||||
| 
 | ||||
|     furi_check(osTimerDelete(scene_app_gui->timer) == osOK); | ||||
|     furi_record_close("gui"); | ||||
|     view_port_free(scene_app_gui->view_port); | ||||
|     furi_check(osMessageQueueDelete(scene_app_gui->mqueue) == osOK); | ||||
|     free(scene_app_gui); | ||||
|     scene_app_gui = NULL; | ||||
|     printf("scene_free: complete\r\n"); | ||||
| } | ||||
| 
 | ||||
| int32_t scene_app(void* p) { | ||||
|     furi_hal_power_insomnia_enter(); | ||||
|     scene_alloc(); | ||||
| 
 | ||||
|     osTimerStart(scene_app_gui->timer, 40); | ||||
| 
 | ||||
|     uint32_t t = xTaskGetTickCount(); | ||||
|     uint32_t prev_t = 0; | ||||
| 
 | ||||
|     while(1) { | ||||
|         AppEvent event; | ||||
|         if(osMessageQueueGet(scene_app_gui->mqueue, &event, 0, osWaitForever) == osOK) { | ||||
|             SceneState* scene_state = (SceneState*)acquire_mutex_block(scene_state_mutex); | ||||
|             if(event.type == EventTypeTick) { | ||||
|                 t = xTaskGetTickCount(); | ||||
|                 dolphin_scene_tick_handler(scene_state, t, (t - prev_t) % 1024); | ||||
|                 prev_t = t; | ||||
|             } else if(event.type == EventTypeKey) { | ||||
|                 if(event.value.input.key == InputKeyBack && | ||||
|                    event.value.input.type == InputTypeShort) { | ||||
|                     release_mutex(scene_state_mutex, scene_state); | ||||
|                     break; | ||||
| 
 | ||||
|                 } else { | ||||
|                     dolphin_scene_handle_input(scene_state, &event.value.input); | ||||
|                 } | ||||
|             } | ||||
|             release_mutex(scene_state_mutex, scene_state); | ||||
|             view_port_update(scene_app_gui->view_port); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     osTimerStop(scene_app_gui->timer); | ||||
| 
 | ||||
|     // CMSIS + FreeRTOS = Enterprise
 | ||||
|     osDelay(15); | ||||
| 
 | ||||
|     scene_free(); | ||||
|     furi_hal_power_insomnia_exit(); | ||||
|     return 0; | ||||
| } | ||||
| @ -1,138 +0,0 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #include <furi.h> | ||||
| #include <gui/gui_i.h> | ||||
| #include <u8g2/u8g2.h> | ||||
| 
 | ||||
| // global
 | ||||
| #define SCALE 32 | ||||
| // screen
 | ||||
| 
 | ||||
| #define SCREEN_WIDTH GUI_DISPLAY_WIDTH | ||||
| #define SCREEN_HEIGHT GUI_DISPLAY_HEIGHT | ||||
| #define BONDARIES_X_LEFT 40 | ||||
| #define BONDARIES_X_RIGHT 88 | ||||
| 
 | ||||
| // player
 | ||||
| #define DOLPHIN_WIDTH 32 | ||||
| #define DOLPHIN_HEIGHT 32 | ||||
| #define DOLPHIN_CENTER (SCREEN_WIDTH / 2 - DOLPHIN_WIDTH) | ||||
| #define SPEED_X 4 | ||||
| #define SPEED_Y 4 | ||||
| #define ACTIONS_NUM 4 | ||||
| #define DOLPHIN_DEFAULT_Y 2 | ||||
| #define MAX_FRAMES 3 | ||||
| 
 | ||||
| // world
 | ||||
| #define WORLD_WIDTH 256 | ||||
| #define WORLD_HEIGHT 192 | ||||
| 
 | ||||
| #define LAYERS 8 | ||||
| #define DOLPHIN_LAYER 6 | ||||
| #define PARALLAX_MOD 7 | ||||
| #define PARALLAX(layer) layer / PARALLAX_MOD - layer | ||||
| 
 | ||||
| #define DIALOG_PROGRESS 250 | ||||
| 
 | ||||
| enum Actions { IDLE = 0, EMOTE, INTERACT, MINDCONTROL }; | ||||
| 
 | ||||
| static const uint16_t default_timeout[] = | ||||
|     {[IDLE] = 100, [EMOTE] = 50, [INTERACT] = 10, [MINDCONTROL] = 50}; | ||||
| 
 | ||||
| typedef enum { | ||||
|     EventTypeTick, | ||||
|     EventTypeKey, | ||||
| } EventType; | ||||
| 
 | ||||
| typedef struct { | ||||
|     union { | ||||
|         InputEvent input; | ||||
|     } value; | ||||
|     EventType type; | ||||
| } AppEvent; | ||||
| 
 | ||||
| typedef struct { | ||||
|     int32_t x; | ||||
|     int32_t y; | ||||
| } Vec2; | ||||
| 
 | ||||
| typedef struct { | ||||
|     osMessageQueueId_t mqueue; | ||||
|     Gui* gui; | ||||
|     ViewPort* view_port; | ||||
|     osTimerId_t* timer; | ||||
| } SceneAppGui; | ||||
| 
 | ||||
| typedef struct { | ||||
|     uint8_t layer; | ||||
|     uint16_t timeout; | ||||
|     Vec2 pos; | ||||
| 
 | ||||
|     uint8_t width; | ||||
|     uint8_t height; | ||||
| 
 | ||||
|     void (*draw)(Canvas* canvas, void* model); | ||||
|     void (*callback)(Canvas* canvas, void* model); | ||||
| } Item; | ||||
| 
 | ||||
| typedef enum { | ||||
|     DirUp = 0, | ||||
|     DirRight, | ||||
|     DirDown, | ||||
|     DirLeft, | ||||
| } FrameDirectionEnum; | ||||
| 
 | ||||
| typedef struct { | ||||
|     const Icon* f; | ||||
|     const Icon* b; | ||||
| } DolphinGfxAsset; | ||||
| 
 | ||||
| typedef struct { | ||||
|     const DolphinGfxAsset frames[MAX_FRAMES]; | ||||
|     const uint8_t total; | ||||
| } DolphinFrame; | ||||
| 
 | ||||
| typedef struct { | ||||
|     Vec2 player; | ||||
|     Vec2 player_global; | ||||
|     Vec2 player_v; | ||||
|     Vec2 screen; | ||||
| 
 | ||||
|     FrameDirectionEnum frame_group; | ||||
|     FrameDirectionEnum last_group; | ||||
|     FrameDirectionEnum frame_pending; | ||||
|     FrameDirectionEnum frame_type; | ||||
| 
 | ||||
|     const DolphinFrame* current_frame; | ||||
| 
 | ||||
|     bool transition; | ||||
|     bool transition_pending; | ||||
|     bool use_pending; | ||||
|     bool debug; | ||||
| 
 | ||||
|     uint8_t player_anim; | ||||
|     uint8_t frame_idx; | ||||
| 
 | ||||
|     uint8_t scene_id; | ||||
|     uint8_t emote_id; | ||||
|     uint8_t previous_emote; | ||||
| 
 | ||||
|     uint8_t action; | ||||
|     uint8_t prev_action; | ||||
|     uint8_t action_timeout; | ||||
|     uint8_t dialog_progress; | ||||
| 
 | ||||
|     FuriThread* scene_app_thread; | ||||
| } SceneState; | ||||
| 
 | ||||
| void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t); | ||||
| void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas); | ||||
| void dolphin_scene_handle_user_input(SceneState* state, InputEvent* input); | ||||
| void dolphin_scene_coordinates(SceneState* state, uint32_t dt); | ||||
| 
 | ||||
| void dolphin_scene_render_state(SceneState* state, Canvas* canvas); | ||||
| void dolphin_scene_update_state(SceneState* state, uint32_t t, uint32_t dt); | ||||
| 
 | ||||
| void dolphin_scene_redraw(Canvas* canvas, void* ctx); | ||||
| void dolphin_scene_tick_handler(SceneState* state, uint32_t t, uint32_t dt); | ||||
| void dolphin_scene_handle_input(SceneState* state, InputEvent* input); | ||||
| @ -1,60 +0,0 @@ | ||||
| #include <furi.h> | ||||
| #include <gui/elements.h> | ||||
| #include "scene.h" | ||||
| 
 | ||||
| void dolphin_scene_handle_user_input(SceneState* state, InputEvent* input) { | ||||
|     furi_assert(state); | ||||
|     furi_assert(input); | ||||
| 
 | ||||
|     state->last_group = state->frame_group; | ||||
|     if(input->type == InputTypePress) { | ||||
|         state->action = MINDCONTROL; | ||||
|     } | ||||
| 
 | ||||
|     if(state->action == MINDCONTROL) { | ||||
|         if(input->type == InputTypePress) { | ||||
|             if(input->key == InputKeyRight) { | ||||
|                 state->player_v.y = 0; | ||||
|                 state->player_v.x = SPEED_X; | ||||
|             } else if(input->key == InputKeyLeft) { | ||||
|                 state->player_v.y = 0; | ||||
|                 state->player_v.x = -SPEED_X; | ||||
|             } else if(input->key == InputKeyUp) { | ||||
|                 state->player_v.x = 0; | ||||
|                 state->player_v.y = -SPEED_Y; | ||||
|             } else if(input->key == InputKeyDown) { | ||||
|                 state->player_v.x = 0; | ||||
|                 state->player_v.y = SPEED_Y; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if(input->type == InputTypeRelease) { | ||||
|             state->player_v.x = 0; | ||||
|             state->player_v.y = 0; | ||||
|         } else if(input->type == InputTypeShort) { | ||||
|             if(input->key == InputKeyOk) { | ||||
|                 state->prev_action = MINDCONTROL; | ||||
|                 state->action = INTERACT; | ||||
|                 state->use_pending = true; | ||||
|                 state->action_timeout = 0; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void dolphin_scene_coordinates(SceneState* state, uint32_t dt) { | ||||
|     furi_assert(state); | ||||
| 
 | ||||
|     // global pos
 | ||||
|     state->player_global.x = CLAMP(state->player_global.x + state->player_v.x, WORLD_WIDTH, 0); | ||||
|     state->player_global.y = CLAMP(state->player_global.y + state->player_v.y, WORLD_HEIGHT, 0); | ||||
| 
 | ||||
|     // nudge camera postition
 | ||||
|     if(state->player_global.x > 170) { | ||||
|         state->player.x = | ||||
|             CLAMP(state->player.x - state->player_v.x / 2, DOLPHIN_CENTER, -DOLPHIN_WIDTH / 2); | ||||
|     } else if(state->player_global.x < 70) { | ||||
|         state->player.x = | ||||
|             CLAMP(state->player.x - state->player_v.x / 2, DOLPHIN_WIDTH * 2, DOLPHIN_CENTER); | ||||
|     } | ||||
| } | ||||
| @ -1,47 +0,0 @@ | ||||
| #include <furi.h> | ||||
| #include "scene.h" | ||||
| #include "assets/items.h" | ||||
| 
 | ||||
| static void scene_proceed_action(SceneState* state) { | ||||
|     furi_assert(state); | ||||
|     state->prev_action = state->action; | ||||
|     state->action = roll_new(state->prev_action, ACTIONS_NUM); | ||||
|     state->action_timeout = default_timeout[state->action]; | ||||
| } | ||||
| 
 | ||||
| static void scene_action_handler(SceneState* state) { | ||||
|     furi_assert(state); | ||||
|     if(state->action == MINDCONTROL) { | ||||
|         if(state->player_v.x != 0 || state->player_v.y != 0) { | ||||
|             state->action_timeout = default_timeout[state->action]; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     if(state->action_timeout > 0) { | ||||
|         state->action_timeout--; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void dolphin_scene_update_state(SceneState* state, uint32_t t, uint32_t dt) { | ||||
|     furi_assert(state); | ||||
|     scene_action_handler(state); | ||||
| 
 | ||||
|     switch(state->action) { | ||||
|     case INTERACT: | ||||
|         if(state->action_timeout == 0) { | ||||
|             if(state->prev_action == MINDCONTROL) { | ||||
|                 state->action = MINDCONTROL; | ||||
|             } else { | ||||
|                 scene_proceed_action(state); | ||||
|             } | ||||
|         } | ||||
|         break; | ||||
| 
 | ||||
|     default: | ||||
| 
 | ||||
|         if(state->action_timeout == 0) { | ||||
|             scene_proceed_action(state); | ||||
|         } | ||||
|         break; | ||||
|     } | ||||
| } | ||||
| @ -1,121 +0,0 @@ | ||||
| #include <furi.h> | ||||
| #include "scene.h" | ||||
| #include "assets/items.h" | ||||
| #include "assets/meta.h" | ||||
| #include <gui/elements.h> | ||||
| 
 | ||||
| void dolphin_scene_transition_handler(SceneState* state) { | ||||
|     uint8_t speed_mod = (state->player_v.x || state->player_v.y || state->transition) ? 6 : 10; | ||||
| 
 | ||||
|     if(state->player_v.x < 0) { | ||||
|         state->frame_pending = DirLeft; | ||||
|     } else if(state->player_v.x > 0) { | ||||
|         state->frame_pending = DirRight; | ||||
|     } else if(state->player_v.y < 0) { | ||||
|         state->frame_pending = DirUp; | ||||
|     } else if(state->player_v.y > 0) { | ||||
|         state->frame_pending = DirDown; | ||||
|     } | ||||
|     state->transition_pending = state->frame_group != state->frame_pending; | ||||
| 
 | ||||
|     if(*&frames[state->frame_group][state->frame_type]->frames[state->frame_idx].f) { | ||||
|         state->current_frame = *&frames[state->frame_group][state->frame_type]; | ||||
|     } | ||||
| 
 | ||||
|     uint8_t total = state->current_frame->frames[2].f == NULL ? 2 : 3; | ||||
| 
 | ||||
|     if(state->transition_pending && !state->frame_idx) { | ||||
|         state->transition_pending = false; | ||||
|         state->transition = true; | ||||
|     } | ||||
| 
 | ||||
|     if(state->transition) { | ||||
|         state->frame_type = state->frame_pending; | ||||
|         state->frame_group = state->last_group; | ||||
|         state->transition = !(state->frame_idx == total - 1); | ||||
|     } else { | ||||
|         state->frame_group = state->frame_type; | ||||
|     } | ||||
| 
 | ||||
|     state->player_anim++; | ||||
| 
 | ||||
|     if(!(state->player_anim % speed_mod)) { | ||||
|         state->frame_idx = (state->frame_idx + 1) % total; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void dolphin_scene_render_dolphin(SceneState* state, Canvas* canvas) { | ||||
|     furi_assert(state); | ||||
|     furi_assert(canvas); | ||||
| 
 | ||||
|     dolphin_scene_transition_handler(state); | ||||
| 
 | ||||
|     canvas_set_bitmap_mode(canvas, true); | ||||
|     canvas_set_color(canvas, ColorWhite); | ||||
|     canvas_draw_icon( | ||||
|         canvas, state->player.x, state->player.y, state->current_frame->frames[state->frame_idx].b); | ||||
|     canvas_set_color(canvas, ColorBlack); | ||||
|     canvas_draw_icon( | ||||
|         canvas, state->player.x, state->player.y, state->current_frame->frames[state->frame_idx].f); | ||||
|     canvas_set_bitmap_mode(canvas, false); | ||||
| } | ||||
| 
 | ||||
| static bool item_screen_bounds_x(int32_t pos) { | ||||
|     return pos > -SCREEN_WIDTH && pos < (SCREEN_WIDTH * 2); | ||||
| } | ||||
| static bool item_screen_bounds_y(int32_t pos) { | ||||
|     return pos > -SCREEN_HEIGHT * 2 && pos < (SCREEN_HEIGHT * 2); | ||||
| } | ||||
| 
 | ||||
| void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t) { | ||||
|     furi_assert(state); | ||||
|     furi_assert(canvas); | ||||
| 
 | ||||
|     canvas_set_font(canvas, FontSecondary); | ||||
|     canvas_set_color(canvas, ColorBlack); | ||||
|     const Item** current_scene = get_scene(state); | ||||
| 
 | ||||
|     for(uint8_t l = 0; l < LAYERS; l++) { | ||||
|         for(uint8_t i = 0; i < ItemsEnumTotal; i++) { | ||||
|             int32_t item_pos_X = (current_scene[i]->pos.x - state->player_global.x); | ||||
|             int32_t item_pos_Y = (current_scene[i]->pos.y - state->player_global.y); | ||||
| 
 | ||||
|             if(item_screen_bounds_x(item_pos_X) && item_screen_bounds_y(item_pos_Y)) { | ||||
|                 if(l == current_scene[i]->layer) { | ||||
|                     if(current_scene[i]->draw) { | ||||
|                         current_scene[i]->draw(canvas, state); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if(l == DOLPHIN_LAYER) dolphin_scene_render_dolphin(state, canvas); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void dolphin_scene_render_state(SceneState* state, Canvas* canvas) { | ||||
|     furi_assert(state); | ||||
|     furi_assert(canvas); | ||||
| 
 | ||||
|     char buf[64]; | ||||
| 
 | ||||
|     canvas_set_font(canvas, FontSecondary); | ||||
|     canvas_set_color(canvas, ColorBlack); | ||||
| 
 | ||||
|     // dolphin_scene_debug
 | ||||
|     if(state->debug) { | ||||
|         sprintf( | ||||
|             buf, | ||||
|             "%d:%d %d/%dP%dL%d T%d-%d", | ||||
|             state->frame_idx, | ||||
|             state->current_frame->frames[2].f == NULL ? 2 : 3, | ||||
|             state->frame_group, | ||||
|             state->frame_type, | ||||
|             state->frame_pending, | ||||
|             state->last_group, | ||||
|             state->transition_pending, | ||||
|             state->transition); | ||||
|         canvas_draw_str(canvas, 0, 13, buf); | ||||
|     } | ||||
|     if(state->action == INTERACT) scene_activate_item_callback(state, canvas); | ||||
| } | ||||
| @ -289,7 +289,7 @@ bool file_select_fill_strings(FileSelect* file_select) { | ||||
|         storage_dir_close(directory); | ||||
|         storage_file_free(directory); | ||||
|         free(name); | ||||
|         return false; | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     while(1) { | ||||
| @ -350,7 +350,7 @@ bool file_select_fill_count(FileSelect* file_select) { | ||||
|         storage_dir_close(directory); | ||||
|         storage_file_free(directory); | ||||
|         free(name); | ||||
|         return false; | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     while(1) { | ||||
|  | ||||
| @ -74,6 +74,12 @@ static void irda_cli_print_usage(void) { | ||||
|         printf(" %s", irda_get_protocol_name((IrdaProtocol)i)); | ||||
|     } | ||||
|     printf("\r\n"); | ||||
|     printf("\tRaw format:\r\n"); | ||||
|     printf("\tir_tx RAW F:<frequency> DC:<duty_cycle> <sample0> <sample1>...\r\n"); | ||||
|     printf( | ||||
|         "\tFrequency (%d - %d), Duty cycle (0 - 100), max 512 samples\r\n", | ||||
|         IRDA_MIN_FREQUENCY, | ||||
|         IRDA_MAX_FREQUENCY); | ||||
| } | ||||
| 
 | ||||
| static bool parse_message(const char* str, IrdaMessage* message) { | ||||
| @ -115,6 +121,14 @@ static bool parse_signal_raw( | ||||
|     *duty_cycle = (float)atoi(duty_cycle_str) / 100; | ||||
|     str += strlen(frequency_str) + strlen(duty_cycle_str) + 10; | ||||
| 
 | ||||
|     if((*frequency > IRDA_MAX_FREQUENCY) || (*frequency < IRDA_MIN_FREQUENCY)) { | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     if((*duty_cycle <= 0) || (*duty_cycle > 1)) { | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     uint32_t timings_cnt_max = *timings_cnt; | ||||
|     *timings_cnt = 0; | ||||
| 
 | ||||
| @ -131,13 +145,15 @@ static bool parse_signal_raw( | ||||
|         ++*timings_cnt; | ||||
|     } | ||||
| 
 | ||||
|     printf("\r\nTransmit:"); | ||||
|     for(size_t i = 0; i < *timings_cnt; ++i) { | ||||
|         printf(" %ld", timings[i]); | ||||
|     if(*timings_cnt > 0) { | ||||
|         printf("\r\nTransmit:"); | ||||
|         for(size_t i = 0; i < *timings_cnt; ++i) { | ||||
|             printf(" %ld", timings[i]); | ||||
|         } | ||||
|         printf("\r\n"); | ||||
|     } | ||||
|     printf("\r\n"); | ||||
| 
 | ||||
|     return true; | ||||
|     return (parsed == 2) && (*timings_cnt > 0); | ||||
| } | ||||
| 
 | ||||
| static void irda_cli_start_ir_tx(Cli* cli, string_t args, void* context) { | ||||
| @ -150,8 +166,8 @@ static void irda_cli_start_ir_tx(Cli* cli, string_t args, void* context) { | ||||
|     const char* str = string_get_cstr(args); | ||||
|     uint32_t frequency; | ||||
|     float duty_cycle; | ||||
|     uint32_t* timings = (uint32_t*)furi_alloc(sizeof(uint32_t) * 1000); | ||||
|     uint32_t timings_cnt = 1000; | ||||
|     uint32_t* timings = (uint32_t*)furi_alloc(sizeof(uint32_t) * 512); | ||||
|     uint32_t timings_cnt = 512; | ||||
| 
 | ||||
|     if(parse_message(str, &message)) { | ||||
|         irda_send(&message, 1); | ||||
|  | ||||
| @ -1,8 +1,10 @@ | ||||
| #include "irda-app-brute-force.h" | ||||
| #include "irda/irda-app-file-parser.h" | ||||
| #include "m-string.h" | ||||
| #include <file-worker-cpp.h> | ||||
| 
 | ||||
| #include <memory> | ||||
| #include <m-string.h> | ||||
| #include <furi.h> | ||||
| #include <file-worker-cpp.h> | ||||
| 
 | ||||
| void IrdaAppBruteForce::add_record(int index, const char* name) { | ||||
|     records[name].index = index; | ||||
| @ -16,7 +18,7 @@ bool IrdaAppBruteForce::calculate_messages() { | ||||
|     file_parser = std::make_unique<IrdaAppFileParser>(); | ||||
|     fs_res = file_parser->open_irda_file_read(universal_db_filename); | ||||
|     if(!fs_res) { | ||||
|         file_parser.reset(nullptr); | ||||
|         file_parser.reset(); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
| @ -31,7 +33,7 @@ bool IrdaAppBruteForce::calculate_messages() { | ||||
|     } | ||||
| 
 | ||||
|     file_parser->close(); | ||||
|     file_parser.reset(nullptr); | ||||
|     file_parser.reset(); | ||||
| 
 | ||||
|     return true; | ||||
| } | ||||
| @ -43,7 +45,7 @@ void IrdaAppBruteForce::stop_bruteforce() { | ||||
|         furi_assert(file_parser); | ||||
|         current_record.clear(); | ||||
|         file_parser->close(); | ||||
|         file_parser.reset(nullptr); | ||||
|         file_parser.reset(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -81,7 +83,7 @@ bool IrdaAppBruteForce::start_bruteforce(int index, int& record_amount) { | ||||
|         file_parser = std::make_unique<IrdaAppFileParser>(); | ||||
|         result = file_parser->open_irda_file_read(universal_db_filename); | ||||
|         if(!result) { | ||||
|             (void)file_parser.reset(nullptr); | ||||
|             file_parser.reset(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -1,7 +1,8 @@ | ||||
| #pragma once | ||||
| #include "furi/check.h" | ||||
| #include <unordered_map> | ||||
| 
 | ||||
| #include "irda-app-file-parser.h" | ||||
| 
 | ||||
| #include <unordered_map> | ||||
| #include <memory> | ||||
| 
 | ||||
| class IrdaAppBruteForce { | ||||
|  | ||||
| @ -1,22 +1,16 @@ | ||||
| #include "irda-app-file-parser.h" | ||||
| #include "furi/check.h" | ||||
| #include "irda-app-remote-manager.h" | ||||
| #include "irda-app-signal.h" | ||||
| #include "m-string.h" | ||||
| 
 | ||||
| #include <m-string.h> | ||||
| #include <cstdio> | ||||
| #include <text-store.h> | ||||
| #include <irda.h> | ||||
| #include <cstdio> | ||||
| #include <stdint.h> | ||||
| #include <string> | ||||
| #include <string_view> | ||||
| #include <furi.h> | ||||
| #include <furi-hal-irda.h> | ||||
| #include <file-worker-cpp.h> | ||||
| 
 | ||||
| uint32_t const IrdaAppFileParser::max_line_length = ((9 + 1) * 512 + 100); | ||||
| const char* IrdaAppFileParser::irda_directory = "/any/irda"; | ||||
| const char* IrdaAppFileParser::irda_extension = ".ir"; | ||||
| uint32_t const IrdaAppFileParser::max_raw_timings_in_signal = 512; | ||||
| 
 | ||||
| bool IrdaAppFileParser::open_irda_file_read(const char* name) { | ||||
|     std::string full_filename; | ||||
|     if(name[0] != '/') | ||||
| @ -158,18 +152,41 @@ std::unique_ptr<IrdaAppFileParser::IrdaFileSignal> | ||||
|     IrdaProtocol protocol = irda_get_protocol_by_name(protocol_name); | ||||
| 
 | ||||
|     if(!irda_is_protocol_valid((IrdaProtocol)protocol)) { | ||||
|         size_t end_of_str = MIN(str.find_last_not_of(" \t\r\n") + 1, (size_t)30); | ||||
|         FURI_LOG_E( | ||||
|             "IrdaFileParser", | ||||
|             "Unknown protocol(\'%.*s...\'): \'%s\'", | ||||
|             end_of_str, | ||||
|             str.c_str(), | ||||
|             protocol_name); | ||||
|         return nullptr; | ||||
|     } | ||||
| 
 | ||||
|     int address_length = irda_get_protocol_address_length(protocol); | ||||
|     uint32_t address_mask = (1LU << (4 * address_length)) - 1; | ||||
|     if(address != (address & address_mask)) { | ||||
|         size_t end_of_str = MIN(str.find_last_not_of(" \t\r\n") + 1, (size_t)30); | ||||
|         FURI_LOG_E( | ||||
|             "IrdaFileParser", | ||||
|             "Signal(\'%.*s...\'): address is too long (mask for this protocol is 0x%08X): 0x%X", | ||||
|             end_of_str, | ||||
|             str.c_str(), | ||||
|             address_mask, | ||||
|             address); | ||||
|         return nullptr; | ||||
|     } | ||||
| 
 | ||||
|     int command_length = irda_get_protocol_command_length(protocol); | ||||
|     uint32_t command_mask = (1LU << (4 * command_length)) - 1; | ||||
|     if(command != (command & command_mask)) { | ||||
|         size_t end_of_str = MIN(str.find_last_not_of(" \t\r\n") + 1, (size_t)30); | ||||
|         FURI_LOG_E( | ||||
|             "IrdaFileParser", | ||||
|             "Signal(\'%.*s...\'): command is too long (mask for this protocol is 0x%08X): 0x%X", | ||||
|             end_of_str, | ||||
|             str.c_str(), | ||||
|             command_mask, | ||||
|             command); | ||||
|         return nullptr; | ||||
|     } | ||||
| 
 | ||||
| @ -195,34 +212,81 @@ const char* find_first_not_of(const char* str, char symbol) { | ||||
|     return str; | ||||
| } | ||||
| 
 | ||||
| static int remove_args32(std::string_view& str, size_t num) { | ||||
|     int removed_length = 0; | ||||
| 
 | ||||
|     while(num--) { | ||||
|         char buf[32]; | ||||
| 
 | ||||
|         size_t index = str.find_first_not_of(" \t"); | ||||
|         if(index == std::string_view::npos) break; | ||||
|         removed_length += index; | ||||
|         str.remove_prefix(index); | ||||
| 
 | ||||
|         if(str.empty()) break; | ||||
| 
 | ||||
|         int parsed = std::sscanf(str.data(), "%31s", buf); | ||||
|         if(!parsed) break; | ||||
| 
 | ||||
|         size_t len = strlen(buf); | ||||
|         if(!len) break; | ||||
|         removed_length += len; | ||||
|         str.remove_prefix(len); | ||||
| 
 | ||||
|         if(str.empty()) break; | ||||
|     } | ||||
| 
 | ||||
|     return removed_length; | ||||
| } | ||||
| 
 | ||||
| std::unique_ptr<IrdaAppFileParser::IrdaFileSignal> | ||||
|     IrdaAppFileParser::parse_signal_raw(const std::string& string) const { | ||||
|     uint32_t frequency; | ||||
|     uint32_t duty_cycle; | ||||
|     int str_len = string.size(); | ||||
|     std::string_view str(string.c_str()); | ||||
|     auto irda_file_signal = std::make_unique<IrdaFileSignal>(); | ||||
| 
 | ||||
|     int parsed = std::sscanf( | ||||
|         str.data(), "%31s RAW F:%ld DC:%ld", irda_file_signal->name, &frequency, &duty_cycle); | ||||
| 
 | ||||
|     if((parsed != 3) || (frequency > 42000) || (frequency < 32000) || (duty_cycle == 0) || | ||||
|        (duty_cycle >= 100)) { | ||||
|     if(parsed != 3) { | ||||
|         return nullptr; | ||||
|     } | ||||
| 
 | ||||
|     char dummy[100] = {0}; | ||||
|     int header_len = 0; | ||||
|     header_len = sniprintf( | ||||
|         dummy, | ||||
|         sizeof(dummy), | ||||
|         "%.31s RAW F:%ld DC:%ld", | ||||
|         irda_file_signal->name, | ||||
|         frequency, | ||||
|         duty_cycle); | ||||
|     if((frequency < IRDA_MIN_FREQUENCY) || (frequency > IRDA_MAX_FREQUENCY)) { | ||||
|         size_t end_of_str = MIN(string.find_last_not_of(" \t\r\n") + 1, (size_t)30); | ||||
|         FURI_LOG_E( | ||||
|             "IrdaFileParser", | ||||
|             "RAW signal(\'%.*s...\'): frequency is out of bounds (%ld-%ld): %ld", | ||||
|             end_of_str, | ||||
|             string.c_str(), | ||||
|             IRDA_MIN_FREQUENCY, | ||||
|             IRDA_MAX_FREQUENCY, | ||||
|             frequency); | ||||
|         return nullptr; | ||||
|     } | ||||
| 
 | ||||
|     furi_assert(header_len < str_len); | ||||
|     str.remove_prefix(header_len); | ||||
|     if((duty_cycle == 0) || (duty_cycle > 100)) { | ||||
|         size_t end_of_str = MIN(string.find_last_not_of(" \t\r\n") + 1, (size_t)30); | ||||
|         FURI_LOG_E( | ||||
|             "IrdaFileParser", | ||||
|             "RAW signal(\'%.*s...\'): duty cycle is out of bounds (0-100): %ld", | ||||
|             end_of_str, | ||||
|             string.c_str(), | ||||
|             duty_cycle); | ||||
|         return nullptr; | ||||
|     } | ||||
| 
 | ||||
|     int header_len = remove_args32(str, 4); | ||||
| 
 | ||||
|     size_t last_valid_ch = str.find_last_not_of(" \t\r\n"); | ||||
|     if(last_valid_ch != std::string_view::npos) { | ||||
|         str.remove_suffix(str.size() - last_valid_ch - 1); | ||||
|     } else { | ||||
|         FURI_LOG_E( | ||||
|             "IrdaFileParser", "RAW signal(\'%.*s\'): no timings", header_len, string.c_str()); | ||||
|         return nullptr; | ||||
|     } | ||||
| 
 | ||||
|     /* move allocated timings into raw signal object */ | ||||
|     IrdaAppSignal::RawSignal raw_signal = { | ||||
| @ -231,40 +295,59 @@ std::unique_ptr<IrdaAppFileParser::IrdaFileSignal> | ||||
| 
 | ||||
|     while(!str.empty()) { | ||||
|         char buf[10]; | ||||
|         size_t index = str.find_first_not_of(' ', 1); | ||||
|         size_t index = str.find_first_not_of(" \t", 1); | ||||
|         if(index == std::string_view::npos) { | ||||
|             break; | ||||
|         } | ||||
|         str.remove_prefix(index); | ||||
|         parsed = std::sscanf(str.data(), "%9s", buf); | ||||
|         if(parsed != 1) { | ||||
|             FURI_LOG_E( | ||||
|                 "IrdaFileParser", | ||||
|                 "RAW signal(\'%.*s...\'): failed on timing[%ld] \'%*s\'", | ||||
|                 header_len, | ||||
|                 string.c_str(), | ||||
|                 raw_signal.timings_cnt, | ||||
|                 str.size(), | ||||
|                 str.data()); | ||||
|             result = false; | ||||
|             furi_assert(0); | ||||
|             break; | ||||
|         } | ||||
|         str.remove_prefix(strlen(buf)); | ||||
| 
 | ||||
|         int value = atoi(buf); | ||||
|         if(value <= 0) { | ||||
|             FURI_LOG_E( | ||||
|                 "IrdaFileParser", | ||||
|                 "RAW signal(\'%.*s...\'): failed on timing[%ld] \'%s\'", | ||||
|                 header_len, | ||||
|                 string.c_str(), | ||||
|                 raw_signal.timings_cnt, | ||||
|                 buf); | ||||
|             result = false; | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         if(raw_signal.timings_cnt >= max_raw_timings_in_signal) { | ||||
|             FURI_LOG_E( | ||||
|                 "IrdaFileParser", | ||||
|                 "RAW signal(\'%.*s...\'): too much timings (max %ld)", | ||||
|                 header_len, | ||||
|                 string.c_str(), | ||||
|                 max_raw_timings_in_signal); | ||||
|             result = false; | ||||
|             furi_assert(0); | ||||
|             break; | ||||
|         } | ||||
|         raw_signal.timings[raw_signal.timings_cnt] = value; | ||||
|         ++raw_signal.timings_cnt; | ||||
|         result = true; | ||||
|         if(raw_signal.timings_cnt >= max_raw_timings_in_signal) { | ||||
|             result = false; | ||||
|             furi_assert(0); | ||||
|             break; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     if(result) { | ||||
|         /* copy timings instead of moving them to occupy less than max_raw_timings_in_signal */ | ||||
|         irda_file_signal->signal.copy_raw_signal(raw_signal.timings, raw_signal.timings_cnt); | ||||
|     } else { | ||||
|         (void)irda_file_signal.release(); | ||||
|         irda_file_signal.reset(); | ||||
|     } | ||||
|     delete[] raw_signal.timings; | ||||
|     return irda_file_signal; | ||||
| @ -306,13 +389,11 @@ bool IrdaAppFileParser::check_errors() { | ||||
| } | ||||
| 
 | ||||
| std::string IrdaAppFileParser::file_select(const char* selected) { | ||||
|     TextStore* filename_ts = new TextStore(128); | ||||
|     auto filename_ts = std::make_unique<TextStore>(IrdaAppRemoteManager::max_remote_name_length); | ||||
|     bool result; | ||||
| 
 | ||||
|     result = file_worker.file_select( | ||||
|         irda_directory, irda_extension, filename_ts->text, filename_ts->text_size, selected); | ||||
| 
 | ||||
|     delete filename_ts; | ||||
| 
 | ||||
|     return result ? std::string(filename_ts->text) : std::string(); | ||||
| } | ||||
|  | ||||
| @ -1,8 +1,12 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #include "irda-app-signal.h" | ||||
| 
 | ||||
| #include <irda.h> | ||||
| #include <file-worker-cpp.h> | ||||
| #include "irda-app-signal.h" | ||||
| #include <memory> | ||||
| #include <string> | ||||
| #include <cstdint> | ||||
| 
 | ||||
| class IrdaAppFileParser { | ||||
| public: | ||||
| @ -40,10 +44,11 @@ private: | ||||
|     std::unique_ptr<IrdaFileSignal> parse_signal_raw(const std::string& str) const; | ||||
|     std::string make_full_name(const std::string& name) const; | ||||
| 
 | ||||
|     static const char* irda_directory; | ||||
|     static const char* irda_extension; | ||||
|     static const uint32_t max_line_length; | ||||
|     static uint32_t const max_raw_timings_in_signal; | ||||
|     static inline const char* const irda_directory = "/any/irda"; | ||||
|     static inline const char* const irda_extension = ".ir"; | ||||
|     static inline const uint32_t max_raw_timings_in_signal = 512; | ||||
|     static inline const uint32_t max_line_length = | ||||
|         (9 + 1) * IrdaAppFileParser::max_raw_timings_in_signal + 100; | ||||
| 
 | ||||
|     FileWorkerCpp file_worker; | ||||
|     char file_buf[128]; | ||||
|  | ||||
| @ -1,15 +1,14 @@ | ||||
| #include "irda-app-remote-manager.h" | ||||
| #include <storage/storage.h> | ||||
| #include "furi.h" | ||||
| #include "furi/check.h" | ||||
| #include "gui/modules/button_menu.h" | ||||
| #include "irda.h" | ||||
| #include <cstdio> | ||||
| #include <stdint.h> | ||||
| #include <string> | ||||
| #include <utility> | ||||
| #include "irda-app-file-parser.h" | ||||
| 
 | ||||
| #include <utility> | ||||
| 
 | ||||
| #include <irda.h> | ||||
| #include <cstdio> | ||||
| #include <furi.h> | ||||
| #include <gui/modules/button_menu.h> | ||||
| #include <storage/storage.h> | ||||
| 
 | ||||
| static const std::string default_remote_name = "remote"; | ||||
| 
 | ||||
| std::string IrdaAppRemoteManager::find_vacant_remote_name(const std::string& name) { | ||||
|  | ||||
| @ -1,13 +1,15 @@ | ||||
| #pragma once | ||||
| #include <irda_worker.h> | ||||
| #include <stdint.h> | ||||
| #include <string> | ||||
| #include <vector> | ||||
| #include <memory> | ||||
| #include <irda.h> | ||||
| #include <storage/storage.h> | ||||
| 
 | ||||
| #include "irda-app-signal.h" | ||||
| 
 | ||||
| #include <irda_worker.h> | ||||
| #include <irda.h> | ||||
| 
 | ||||
| #include <cstdint> | ||||
| #include <string> | ||||
| #include <memory> | ||||
| #include <vector> | ||||
| 
 | ||||
| class IrdaAppRemoteButton { | ||||
|     friend class IrdaAppRemoteManager; | ||||
|     std::string name; | ||||
| @ -40,13 +42,13 @@ public: | ||||
| }; | ||||
| 
 | ||||
| class IrdaAppRemoteManager { | ||||
|     static const char* irda_directory; | ||||
|     static const char* irda_extension; | ||||
|     std::unique_ptr<IrdaAppRemote> remote; | ||||
|     std::string make_full_name(const std::string& remote_name) const; | ||||
|     std::string make_remote_name(const std::string& full_name) const; | ||||
| 
 | ||||
| public: | ||||
|     static inline const uint32_t max_button_name_length = 31; | ||||
|     static inline const uint32_t max_remote_name_length = 31; | ||||
|     bool add_remote_with_button(const char* button_name, const IrdaAppSignal& signal); | ||||
|     bool add_button(const char* button_name, const IrdaAppSignal& signal); | ||||
| 
 | ||||
|  | ||||
| @ -5,9 +5,9 @@ void IrdaAppSignal::copy_timings(const uint32_t* timings, size_t size) { | ||||
|     furi_assert(size); | ||||
|     furi_assert(timings); | ||||
| 
 | ||||
|     payload.raw.timings_cnt = size; | ||||
|     if(size) { | ||||
|         payload.raw.timings = new uint32_t[size]; | ||||
|         payload.raw.timings_cnt = size; | ||||
|         memcpy(payload.raw.timings, timings, size * sizeof(uint32_t)); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -48,6 +48,18 @@ int32_t IrdaApp::run(void* args) { | ||||
|     return 0; | ||||
| }; | ||||
| 
 | ||||
| IrdaApp::IrdaApp() { | ||||
|     furi_check(IrdaAppRemoteManager::max_button_name_length < get_text_store_size()); | ||||
|     notification = static_cast<NotificationApp*>(furi_record_open("notification")); | ||||
|     irda_worker = irda_worker_alloc(); | ||||
| } | ||||
| 
 | ||||
| IrdaApp::~IrdaApp() { | ||||
|     irda_worker_free(irda_worker); | ||||
|     furi_record_close("notification"); | ||||
|     for(auto& [key, scene] : scenes) delete scene; | ||||
| } | ||||
| 
 | ||||
| IrdaAppViewManager* IrdaApp::get_view_manager() { | ||||
|     return &view_manager; | ||||
| } | ||||
|  | ||||
| @ -88,19 +88,12 @@ public: | ||||
|     static void text_input_callback(void* context); | ||||
|     static void popup_callback(void* context); | ||||
| 
 | ||||
|     IrdaApp() { | ||||
|         notification = static_cast<NotificationApp*>(furi_record_open("notification")); | ||||
|         irda_worker = irda_worker_alloc(); | ||||
|     } | ||||
|     ~IrdaApp() { | ||||
|         irda_worker_free(irda_worker); | ||||
|         furi_record_close("notification"); | ||||
|         for(auto& it : scenes) delete it.second; | ||||
|     } | ||||
|     IrdaApp(); | ||||
|     ~IrdaApp(); | ||||
| 
 | ||||
| private: | ||||
|     static const uint8_t text_store_size = 128; | ||||
|     static const uint8_t text_store_max = 2; | ||||
|     static inline const uint8_t text_store_size = 128; | ||||
|     static inline const uint8_t text_store_max = 2; | ||||
|     char text_store[text_store_max][text_store_size + 1]; | ||||
|     bool learn_new_remote; | ||||
|     EditElement element; | ||||
|  | ||||
| @ -3,24 +3,31 @@ | ||||
| void IrdaAppSceneEditRename::on_enter(IrdaApp* app) { | ||||
|     IrdaAppViewManager* view_manager = app->get_view_manager(); | ||||
|     TextInput* text_input = view_manager->get_text_input(); | ||||
|     size_t enter_name_length = 0; | ||||
| 
 | ||||
|     auto remote_manager = app->get_remote_manager(); | ||||
|     if(app->get_edit_element() == IrdaApp::EditElement::Button) { | ||||
|         furi_assert(app->get_current_button() != IrdaApp::ButtonNA); | ||||
|         auto button_name = remote_manager->get_button_name(app->get_current_button()); | ||||
|         strncpy(app->get_text_store(0), button_name.c_str(), app->get_text_store_size()); | ||||
|         char* buffer_str = app->get_text_store(0); | ||||
|         size_t max_len = IrdaAppRemoteManager::max_button_name_length; | ||||
|         strncpy(buffer_str, button_name.c_str(), max_len); | ||||
|         buffer_str[max_len + 1] = 0; | ||||
|         enter_name_length = max_len; | ||||
|         text_input_set_header_text(text_input, "Name the key"); | ||||
|     } else { | ||||
|         auto remote_name = remote_manager->get_remote_name(); | ||||
|         strncpy(app->get_text_store(0), remote_name.c_str(), app->get_text_store_size()); | ||||
|         enter_name_length = IrdaAppRemoteManager::max_remote_name_length; | ||||
|         text_input_set_header_text(text_input, "Name the remote"); | ||||
|     } | ||||
| 
 | ||||
|     text_input_set_header_text(text_input, "Name the key"); | ||||
|     text_input_set_result_callback( | ||||
|         text_input, | ||||
|         IrdaApp::text_input_callback, | ||||
|         app, | ||||
|         app->get_text_store(0), | ||||
|         app->get_text_store_size(), | ||||
|         enter_name_length, | ||||
|         false); | ||||
| 
 | ||||
|     view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput); | ||||
|  | ||||
| @ -26,7 +26,7 @@ void IrdaAppSceneLearnEnterName::on_enter(IrdaApp* app) { | ||||
|         IrdaApp::text_input_callback, | ||||
|         app, | ||||
|         app->get_text_store(0), | ||||
|         app->get_text_store_size(), | ||||
|         IrdaAppRemoteManager::max_button_name_length, | ||||
|         false); | ||||
| 
 | ||||
|     view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput); | ||||
|  | ||||
| @ -151,9 +151,10 @@ void nfc_text_store_clear(Nfc* nfc) { | ||||
| 
 | ||||
| int32_t nfc_app(void* p) { | ||||
|     Nfc* nfc = nfc_alloc(); | ||||
|     char* args = p; | ||||
| 
 | ||||
|     // Check argument and run corresponding scene
 | ||||
|     if(p && nfc_device_load(&nfc->dev, p)) { | ||||
|     if((*args != '\0') && nfc_device_load(&nfc->dev, p)) { | ||||
|         scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid); | ||||
|     } else { | ||||
|         scene_manager_next_scene(nfc->scene_manager, NfcSceneStart); | ||||
|  | ||||
| @ -64,7 +64,7 @@ void nfc_cli_emulate(Cli* cli, string_t args, void* context) { | ||||
|     }; | ||||
| 
 | ||||
|     while(!cli_cmd_interrupt_received(cli)) { | ||||
|         if(furi_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, 100)) { | ||||
|         if(furi_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, false, 100)) { | ||||
|             printf("Reader detected\r\n"); | ||||
|             furi_hal_nfc_deactivate(); | ||||
|         } | ||||
|  | ||||
| @ -8,6 +8,7 @@ | ||||
| 
 | ||||
| static const char* nfc_app_folder = "/any/nfc"; | ||||
| static const char* nfc_app_extension = ".nfc"; | ||||
| static const char* nfc_app_shadow_extension = ".shd"; | ||||
| 
 | ||||
| static bool nfc_device_read_hex(string_t str, uint8_t* buff, uint16_t len) { | ||||
|     string_strim(str); | ||||
| @ -259,7 +260,11 @@ void nfc_device_set_name(NfcDevice* dev, const char* name) { | ||||
|     strlcpy(dev->dev_name, name, NFC_DEV_NAME_MAX_LEN); | ||||
| } | ||||
| 
 | ||||
| bool nfc_device_save(NfcDevice* dev, const char* dev_name) { | ||||
| static bool nfc_device_save_file( | ||||
|     NfcDevice* dev, | ||||
|     const char* dev_name, | ||||
|     const char* folder, | ||||
|     const char* extension) { | ||||
|     furi_assert(dev); | ||||
| 
 | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
| @ -275,7 +280,7 @@ bool nfc_device_save(NfcDevice* dev, const char* dev_name) { | ||||
|             break; | ||||
|         }; | ||||
|         // First remove nfc device file if it was saved
 | ||||
|         string_printf(dev_file_name, "%s/%s%s", nfc_app_folder, dev_name, nfc_app_extension); | ||||
|         string_printf(dev_file_name, "%s/%s%s", folder, dev_name, extension); | ||||
|         if(!file_worker_remove(file_worker, string_get_cstr(dev_file_name))) { | ||||
|             break; | ||||
|         }; | ||||
| @ -316,16 +321,42 @@ bool nfc_device_save(NfcDevice* dev, const char* dev_name) { | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool nfc_device_save(NfcDevice* dev, const char* dev_name) { | ||||
|     return nfc_device_save_file(dev, dev_name, nfc_app_folder, nfc_app_extension); | ||||
| } | ||||
| 
 | ||||
| bool nfc_device_save_shadow(NfcDevice* dev, const char* dev_name) { | ||||
|     dev->shadow_file_exist = true; | ||||
|     return nfc_device_save_file(dev, dev_name, nfc_app_folder, nfc_app_shadow_extension); | ||||
| } | ||||
| 
 | ||||
| static bool nfc_device_load_data(FileWorker* file_worker, string_t path, NfcDevice* dev) { | ||||
|     string_t temp_string; | ||||
|     string_init(temp_string); | ||||
|     bool parsed = false; | ||||
| 
 | ||||
|     do { | ||||
|         // Open key file
 | ||||
|         if(!file_worker_open(file_worker, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||
|         // Check existance of shadow file
 | ||||
|         size_t ext_start = string_search_str(path, nfc_app_extension); | ||||
|         string_set_n(temp_string, path, 0, ext_start); | ||||
|         string_cat_printf(temp_string, "%s", nfc_app_shadow_extension); | ||||
|         if(!file_worker_is_file_exist( | ||||
|                file_worker, string_get_cstr(temp_string), &dev->shadow_file_exist)) { | ||||
|             break; | ||||
|         } | ||||
|         // Open shadow file if it exists. If not - open original
 | ||||
|         if(dev->shadow_file_exist) { | ||||
|             if(!file_worker_open( | ||||
|                    file_worker, string_get_cstr(temp_string), FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||
|                 break; | ||||
|             } | ||||
|         } else { | ||||
|             if(!file_worker_open( | ||||
|                    file_worker, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         // Read and parse format from 1st line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_string, '\n')) { | ||||
|             break; | ||||
| @ -427,13 +458,61 @@ void nfc_device_clear(NfcDevice* dev) { | ||||
| bool nfc_device_delete(NfcDevice* dev) { | ||||
|     furi_assert(dev); | ||||
| 
 | ||||
|     bool result = false; | ||||
|     bool result = true; | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     string_t file_path; | ||||
|     string_init_printf(file_path, "%s/%s%s", nfc_app_folder, dev->dev_name, nfc_app_extension); | ||||
|     result = file_worker_remove(file_worker, string_get_cstr(file_path)); | ||||
| 
 | ||||
|     do { | ||||
|         // Delete original file
 | ||||
|         string_init_printf(file_path, "%s/%s%s", nfc_app_folder, dev->dev_name, nfc_app_extension); | ||||
|         if(!file_worker_remove(file_worker, string_get_cstr(file_path))) { | ||||
|             result = false; | ||||
|             break; | ||||
|         } | ||||
|         // Delete shadow file if it exists
 | ||||
|         if(dev->shadow_file_exist) { | ||||
|             string_clean(file_path); | ||||
|             string_printf( | ||||
|                 file_path, "%s/%s%s", nfc_app_folder, dev->dev_name, nfc_app_shadow_extension); | ||||
|             if(!file_worker_remove(file_worker, string_get_cstr(file_path))) { | ||||
|                 result = false; | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(file_path); | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
| bool nfc_device_restore(NfcDevice* dev) { | ||||
|     furi_assert(dev); | ||||
|     furi_assert(dev->shadow_file_exist); | ||||
| 
 | ||||
|     bool result = true; | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     string_t path; | ||||
| 
 | ||||
|     do { | ||||
|         string_init_printf( | ||||
|             path, "%s/%s%s", nfc_app_folder, dev->dev_name, nfc_app_shadow_extension); | ||||
|         if(!file_worker_remove(file_worker, string_get_cstr(path))) { | ||||
|             result = false; | ||||
|             break; | ||||
|         } | ||||
|         dev->shadow_file_exist = false; | ||||
|         string_clean(path); | ||||
|         string_printf(path, "%s/%s%s", nfc_app_folder, dev->dev_name, nfc_app_extension); | ||||
|         if(!nfc_device_load_data(file_worker, path, dev)) { | ||||
|             result = false; | ||||
|             break; | ||||
|         } | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(path); | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
|     return result; | ||||
| } | ||||
|  | ||||
| @ -59,12 +59,15 @@ typedef struct { | ||||
|     char dev_name[NFC_DEV_NAME_MAX_LEN]; | ||||
|     char file_name[NFC_FILE_NAME_MAX_LEN]; | ||||
|     NfcDeviceSaveFormat format; | ||||
|     bool shadow_file_exist; | ||||
| } NfcDevice; | ||||
| 
 | ||||
| void nfc_device_set_name(NfcDevice* dev, const char* name); | ||||
| 
 | ||||
| bool nfc_device_save(NfcDevice* dev, const char* dev_name); | ||||
| 
 | ||||
| bool nfc_device_save_shadow(NfcDevice* dev, const char* dev_name); | ||||
| 
 | ||||
| bool nfc_device_load(NfcDevice* dev, const char* file_path); | ||||
| 
 | ||||
| bool nfc_file_select(NfcDevice* dev); | ||||
| @ -72,3 +75,5 @@ bool nfc_file_select(NfcDevice* dev); | ||||
| void nfc_device_clear(NfcDevice* dev); | ||||
| 
 | ||||
| bool nfc_device_delete(NfcDevice* dev); | ||||
| 
 | ||||
| bool nfc_device_restore(NfcDevice* dev); | ||||
|  | ||||
| @ -143,7 +143,7 @@ void nfc_worker_detect(NfcWorker* nfc_worker) { | ||||
| void nfc_worker_emulate(NfcWorker* nfc_worker) { | ||||
|     NfcDeviceCommomData* data = &nfc_worker->dev_data->nfc_data; | ||||
|     while(nfc_worker->state == NfcWorkerStateEmulate) { | ||||
|         if(furi_hal_nfc_listen(data->uid, data->uid_len, data->atqa, data->sak, 100)) { | ||||
|         if(furi_hal_nfc_listen(data->uid, data->uid_len, data->atqa, data->sak, false, 100)) { | ||||
|             FURI_LOG_I(NFC_WORKER_TAG, "Reader detected"); | ||||
|         } | ||||
|         osDelay(10); | ||||
| @ -406,7 +406,7 @@ void nfc_worker_emulate_apdu(NfcWorker* nfc_worker) { | ||||
|         0x00, 0x00}; | ||||
| 
 | ||||
|     while(nfc_worker->state == NfcWorkerStateEmulateApdu) { | ||||
|         if(furi_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, 300)) { | ||||
|         if(furi_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, false, 300)) { | ||||
|             FURI_LOG_I(NFC_WORKER_TAG, "POS terminal detected"); | ||||
|             // Read data from POS terminal
 | ||||
|             err = furi_hal_nfc_data_exchange(NULL, 0, &rx_buff, &rx_len, false); | ||||
| @ -608,33 +608,52 @@ void nfc_worker_emulate_mifare_ul(NfcWorker* nfc_worker) { | ||||
|     uint8_t* rx_buff; | ||||
|     uint16_t* rx_len; | ||||
|     NfcDeviceData* data = nfc_worker->dev_data; | ||||
| 
 | ||||
|     MifareUlDevice mf_ul_emulate; | ||||
|     // Setup emulation parameters from mifare ultralight data structure
 | ||||
|     mf_ul_prepare_emulation(&mf_ul_emulate, &data->mf_ul_data); | ||||
|     while(nfc_worker->state == NfcWorkerStateEmulateMifareUl) { | ||||
|         if(furi_hal_nfc_listen( | ||||
|                data->nfc_data.uid, | ||||
|                data->nfc_data.uid_len, | ||||
|                data->nfc_data.atqa, | ||||
|                data->nfc_data.sak, | ||||
|                1000)) { | ||||
|             FURI_LOG_I(NFC_WORKER_TAG, "Hello my dudes"); | ||||
|             // Prepare version answer
 | ||||
|             tx_len = sizeof(data->mf_ul_data.version); | ||||
|             memcpy(tx_buff, &data->mf_ul_data.version, tx_len); | ||||
|             err = furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false); | ||||
|             if(err == ERR_NONE) { | ||||
|                 FURI_LOG_I(NFC_WORKER_TAG, "Received 1st message:"); | ||||
|                 for(uint16_t i = 0; i < *rx_len; i++) { | ||||
|                     printf("%02X ", rx_buff[i]); | ||||
|                true, | ||||
|                200)) { | ||||
|             FURI_LOG_D(NFC_WORKER_TAG, "Anticollision passed"); | ||||
|             if(furi_hal_nfc_get_first_frame(&rx_buff, &rx_len)) { | ||||
|                 // Data exchange loop
 | ||||
|                 while(nfc_worker->state == NfcWorkerStateEmulateMifareUl) { | ||||
|                     tx_len = mf_ul_prepare_emulation_response( | ||||
|                         rx_buff, *rx_len, tx_buff, &mf_ul_emulate); | ||||
|                     if(tx_len > 0) { | ||||
|                         err = | ||||
|                             furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false); | ||||
|                         if(err == ERR_NONE) { | ||||
|                             continue; | ||||
|                         } else { | ||||
|                             FURI_LOG_E(NFC_WORKER_TAG, "Communication error: %d", err); | ||||
|                             break; | ||||
|                         } | ||||
|                     } else { | ||||
|                         FURI_LOG_W(NFC_WORKER_TAG, "Not valid command: %02X", rx_buff[0]); | ||||
|                         furi_hal_nfc_deactivate(); | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
|                 printf("\r\n"); | ||||
|             } else { | ||||
|                 FURI_LOG_E(NFC_WORKER_TAG, "Error in 1st data exchange: select PPSE"); | ||||
|                 FURI_LOG_W(NFC_WORKER_TAG, "Error in 1st data exchange"); | ||||
|                 furi_hal_nfc_deactivate(); | ||||
|                 continue; | ||||
|             } | ||||
|         } | ||||
|         FURI_LOG_W(NFC_WORKER_TAG, "Hello my dudes"); | ||||
|         osDelay(10); | ||||
|         // Check if data was modified
 | ||||
|         if(mf_ul_emulate.data_changed) { | ||||
|             nfc_worker->dev_data->mf_ul_data = mf_ul_emulate.data; | ||||
|             if(nfc_worker->callback) { | ||||
|                 nfc_worker->callback(nfc_worker->context); | ||||
|             } | ||||
|         } | ||||
|         FURI_LOG_W(NFC_WORKER_TAG, "Can't find reader"); | ||||
|         osThreadYield(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -26,3 +26,4 @@ ADD_SCENE(nfc, run_emv_app_confirm, RunEmvAppConfirm) | ||||
| ADD_SCENE(nfc, read_emv_data, ReadEmvData) | ||||
| ADD_SCENE(nfc, read_emv_data_success, ReadEmvDataSuccess) | ||||
| ADD_SCENE(nfc, emulate_apdu_sequence, EmulateApduSequence) | ||||
| ADD_SCENE(nfc, restore_original, RestoreOriginal) | ||||
|  | ||||
| @ -1,38 +1,33 @@ | ||||
| #include "../nfc_i.h" | ||||
| 
 | ||||
| #define NFC_MF_UL_DATA_NOT_CHANGED (0UL) | ||||
| #define NFC_MF_UL_DATA_CHANGED (1UL) | ||||
| 
 | ||||
| void nfc_emulate_mifare_ul_worker_callback(void* context) { | ||||
|     Nfc* nfc = (Nfc*)context; | ||||
|     scene_manager_set_scene_state( | ||||
|         nfc->scene_manager, NfcSceneEmulateMifareUl, NFC_MF_UL_DATA_CHANGED); | ||||
| } | ||||
| 
 | ||||
| const void nfc_scene_emulate_mifare_ul_on_enter(void* context) { | ||||
|     Nfc* nfc = (Nfc*)context; | ||||
| 
 | ||||
|     // Setup view
 | ||||
|     Popup* popup = nfc->popup; | ||||
|     NfcDeviceCommomData* data = &nfc->dev.dev_data.nfc_data; | ||||
| 
 | ||||
|     if(strcmp(nfc->dev.dev_name, "")) { | ||||
|         nfc_text_store_set(nfc, "%s", nfc->dev.dev_name); | ||||
|     } else if(data->uid_len == 4) { | ||||
|         nfc_text_store_set( | ||||
|             nfc, "%02X %02X %02X %02X", data->uid[0], data->uid[1], data->uid[2], data->uid[3]); | ||||
|     } else if(data->uid_len == 7) { | ||||
|         nfc_text_store_set( | ||||
|             nfc, | ||||
|             "%02X %02X %02X %02X\n%02X %02X %02X", | ||||
|             data->uid[0], | ||||
|             data->uid[1], | ||||
|             data->uid[2], | ||||
|             data->uid[3], | ||||
|             data->uid[4], | ||||
|             data->uid[5], | ||||
|             data->uid[6]); | ||||
|     } | ||||
| 
 | ||||
|     popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61); | ||||
|     popup_set_header(popup, "Emulating Mf Ul", 56, 31, AlignLeft, AlignTop); | ||||
|     popup_set_text(popup, nfc->text_store, 56, 43, AlignLeft, AlignTop); | ||||
|     popup_set_header(popup, "Emulating\nMf Ultralight", 56, 31, AlignLeft, AlignTop); | ||||
| 
 | ||||
|     // Setup and start worker
 | ||||
| 
 | ||||
|     view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup); | ||||
|     nfc_worker_start(nfc->worker, NfcWorkerStateEmulateMifareUl, &nfc->dev.dev_data, NULL, nfc); | ||||
|     nfc_worker_start( | ||||
|         nfc->worker, | ||||
|         NfcWorkerStateEmulateMifareUl, | ||||
|         &nfc->dev.dev_data, | ||||
|         nfc_emulate_mifare_ul_worker_callback, | ||||
|         nfc); | ||||
| } | ||||
| 
 | ||||
| const bool nfc_scene_emulate_mifare_ul_on_event(void* context, SceneManagerEvent event) { | ||||
| @ -42,6 +37,17 @@ const bool nfc_scene_emulate_mifare_ul_on_event(void* context, SceneManagerEvent | ||||
|     if(event.type == SceneManagerEventTypeTick) { | ||||
|         notification_message(nfc->notifications, &sequence_blink_blue_10); | ||||
|         consumed = true; | ||||
|     } else if(event.type == SceneManagerEventTypeBack) { | ||||
|         // Stop worker
 | ||||
|         nfc_worker_stop(nfc->worker); | ||||
|         // Check if data changed and save in shadow file
 | ||||
|         if(scene_manager_get_scene_state(nfc->scene_manager, NfcSceneEmulateMifareUl) == | ||||
|            NFC_MF_UL_DATA_CHANGED) { | ||||
|             scene_manager_set_scene_state( | ||||
|                 nfc->scene_manager, NfcSceneEmulateMifareUl, NFC_MF_UL_DATA_NOT_CHANGED); | ||||
|             nfc_device_save_shadow(&nfc->dev, nfc->dev.dev_name); | ||||
|         } | ||||
|         consumed = false; | ||||
|     } | ||||
|     return consumed; | ||||
| } | ||||
| @ -49,9 +55,6 @@ const bool nfc_scene_emulate_mifare_ul_on_event(void* context, SceneManagerEvent | ||||
| const void nfc_scene_emulate_mifare_ul_on_exit(void* context) { | ||||
|     Nfc* nfc = (Nfc*)context; | ||||
| 
 | ||||
|     // Stop worker
 | ||||
|     nfc_worker_stop(nfc->worker); | ||||
| 
 | ||||
|     // Clear view
 | ||||
|     Popup* popup = nfc->popup; | ||||
|     popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom); | ||||
|  | ||||
| @ -38,7 +38,7 @@ const bool nfc_scene_mifare_ul_menu_on_event(void* context, SceneManagerEvent ev | ||||
|         } else if(event.event == SubmenuIndexEmulate) { | ||||
|             scene_manager_set_scene_state( | ||||
|                 nfc->scene_manager, NfcSceneMifareUlMenu, SubmenuIndexEmulate); | ||||
|             scene_manager_next_scene(nfc->scene_manager, NfcSceneNotImplemented); | ||||
|             scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareUl); | ||||
|             return true; | ||||
|         } | ||||
|     } else if(event.type == SceneManagerEventTypeBack) { | ||||
|  | ||||
							
								
								
									
										48
									
								
								applications/nfc/scenes/nfc_scene_restore_original.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,48 @@ | ||||
| #include "../nfc_i.h" | ||||
| 
 | ||||
| #define SCENE_RESTORE_ORIGINAL_CUSTOM_EVENT (0UL) | ||||
| 
 | ||||
| void nfc_scene_restore_original_popup_callback(void* context) { | ||||
|     Nfc* nfc = (Nfc*)context; | ||||
|     view_dispatcher_send_custom_event(nfc->view_dispatcher, SCENE_RESTORE_ORIGINAL_CUSTOM_EVENT); | ||||
| } | ||||
| 
 | ||||
| const void nfc_scene_restore_original_on_enter(void* context) { | ||||
|     Nfc* nfc = (Nfc*)context; | ||||
| 
 | ||||
|     // Setup view
 | ||||
|     Popup* popup = nfc->popup; | ||||
|     popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59); | ||||
|     popup_set_header(popup, "Original file\nrestored", 13, 22, AlignLeft, AlignBottom); | ||||
|     popup_set_timeout(popup, 1500); | ||||
|     popup_set_context(popup, nfc); | ||||
|     popup_set_callback(popup, nfc_scene_restore_original_popup_callback); | ||||
|     popup_enable_timeout(popup); | ||||
|     view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup); | ||||
| } | ||||
| 
 | ||||
| const bool nfc_scene_restore_original_on_event(void* context, SceneManagerEvent event) { | ||||
|     Nfc* nfc = (Nfc*)context; | ||||
|     bool consumed = false; | ||||
| 
 | ||||
|     if(event.type == SceneManagerEventTypeCustom) { | ||||
|         if(event.event == SCENE_RESTORE_ORIGINAL_CUSTOM_EVENT) { | ||||
|             consumed = scene_manager_previous_scene(nfc->scene_manager); | ||||
|         } | ||||
|     } | ||||
|     return consumed; | ||||
| } | ||||
| 
 | ||||
| const void nfc_scene_restore_original_on_exit(void* context) { | ||||
|     Nfc* nfc = (Nfc*)context; | ||||
| 
 | ||||
|     // Clear view
 | ||||
|     Popup* popup = nfc->popup; | ||||
|     popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom); | ||||
|     popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); | ||||
|     popup_set_icon(popup, 0, 0, NULL); | ||||
|     popup_set_callback(popup, NULL); | ||||
|     popup_set_context(popup, NULL); | ||||
|     popup_set_timeout(popup, 0); | ||||
|     popup_disable_timeout(popup); | ||||
| } | ||||
| @ -5,6 +5,7 @@ enum SubmenuIndex { | ||||
|     SubmenuIndexEdit, | ||||
|     SubmenuIndexDelete, | ||||
|     SubmenuIndexInfo, | ||||
|     SubmenuIndexRestoreOriginal, | ||||
| }; | ||||
| 
 | ||||
| void nfc_scene_saved_menu_submenu_callback(void* context, uint32_t index) { | ||||
| @ -29,36 +30,52 @@ const void nfc_scene_saved_menu_on_enter(void* context) { | ||||
|         submenu, "Info", SubmenuIndexInfo, nfc_scene_saved_menu_submenu_callback, nfc); | ||||
|     submenu_set_selected_item( | ||||
|         nfc->submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneSavedMenu)); | ||||
|     if(nfc->dev.shadow_file_exist) { | ||||
|         submenu_add_item( | ||||
|             submenu, | ||||
|             "Restore original", | ||||
|             SubmenuIndexRestoreOriginal, | ||||
|             nfc_scene_saved_menu_submenu_callback, | ||||
|             nfc); | ||||
|     } | ||||
| 
 | ||||
|     view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu); | ||||
| } | ||||
| 
 | ||||
| const bool nfc_scene_saved_menu_on_event(void* context, SceneManagerEvent event) { | ||||
|     Nfc* nfc = (Nfc*)context; | ||||
|     bool consumed = false; | ||||
| 
 | ||||
|     if(event.type == SceneManagerEventTypeCustom) { | ||||
|         scene_manager_set_scene_state(nfc->scene_manager, NfcSceneSavedMenu, event.event); | ||||
|         if(event.event == SubmenuIndexEmulate) { | ||||
|             scene_manager_set_scene_state( | ||||
|                 nfc->scene_manager, NfcSceneSavedMenu, SubmenuIndexEmulate); | ||||
|             scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid); | ||||
|             return true; | ||||
|             if(nfc->dev.format == NfcDeviceSaveFormatMifareUl) { | ||||
|                 scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareUl); | ||||
|             } else { | ||||
|                 scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid); | ||||
|             } | ||||
|             consumed = true; | ||||
|         } else if(event.event == SubmenuIndexEdit) { | ||||
|             scene_manager_set_scene_state(nfc->scene_manager, NfcSceneSavedMenu, SubmenuIndexEdit); | ||||
|             scene_manager_next_scene(nfc->scene_manager, NfcSceneSetUid); | ||||
|             return true; | ||||
|             consumed = true; | ||||
|         } else if(event.event == SubmenuIndexDelete) { | ||||
|             scene_manager_set_scene_state( | ||||
|                 nfc->scene_manager, NfcSceneSavedMenu, SubmenuIndexDelete); | ||||
|             scene_manager_next_scene(nfc->scene_manager, NfcSceneDelete); | ||||
|             return true; | ||||
|             consumed = true; | ||||
|         } else if(event.event == SubmenuIndexInfo) { | ||||
|             scene_manager_set_scene_state(nfc->scene_manager, NfcSceneSavedMenu, SubmenuIndexInfo); | ||||
|             scene_manager_next_scene(nfc->scene_manager, NfcSceneDeviceInfo); | ||||
|             return true; | ||||
|             consumed = true; | ||||
|         } else if(event.event == SubmenuIndexRestoreOriginal) { | ||||
|             if(!nfc_device_restore(&nfc->dev)) { | ||||
|                 scene_manager_search_and_switch_to_previous_scene( | ||||
|                     nfc->scene_manager, NfcSceneStart); | ||||
|             } else { | ||||
|                 scene_manager_next_scene(nfc->scene_manager, NfcSceneRestoreOriginal); | ||||
|             } | ||||
|             consumed = true; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     return false; | ||||
|     return consumed; | ||||
| } | ||||
| 
 | ||||
| const void nfc_scene_saved_menu_on_exit(void* context) { | ||||
|  | ||||
| @ -333,7 +333,7 @@ static bool notification_load_settings(NotificationApp* app) { | ||||
|             FURI_LOG_E( | ||||
|                 "notification", | ||||
|                 "version(%d != %d) mismatch", | ||||
|                 app->settings.version, | ||||
|                 settings.version, | ||||
|                 NOTIFICATION_SETTINGS_VERSION); | ||||
|         } else { | ||||
|             osKernelLock(); | ||||
|  | ||||
| @ -81,7 +81,7 @@ static void storage_settings_benchmark(StorageSettings* app) { | ||||
|         bench_data[i] = (uint8_t)i; | ||||
|     } | ||||
| 
 | ||||
|     uint16_t bench_size[BENCH_COUNT] = {1, 8, 32, 256, 1024, 4096}; | ||||
|     uint16_t bench_size[BENCH_COUNT] = {1, 8, 32, 256, 512, 1024}; | ||||
|     uint32_t bench_w_speed[BENCH_COUNT] = {0, 0, 0, 0, 0, 0}; | ||||
|     uint32_t bench_r_speed[BENCH_COUNT] = {0, 0, 0, 0, 0, 0}; | ||||
| 
 | ||||
|  | ||||
| @ -1,6 +1,7 @@ | ||||
| #include <furi.h> | ||||
| #include <cli/cli.h> | ||||
| #include <lib/toolbox/args.h> | ||||
| #include <lib/toolbox/md5.h> | ||||
| #include <storage/storage.h> | ||||
| #include <storage/storage-sd-api.h> | ||||
| #include <furi-hal-version.h> | ||||
| @ -25,32 +26,23 @@ void storage_cli_print_usage() { | ||||
|     printf("\tformat\t - format filesystem\r\n"); | ||||
|     printf("\tlist\t - list files and dirs\r\n"); | ||||
|     printf("\tremove\t - delete the file or directory\r\n"); | ||||
|     printf("\tread\t - read data from file and print file size and content to cli\r\n"); | ||||
|     printf("\tread\t - read text from file and print file size and content to cli\r\n"); | ||||
|     printf( | ||||
|         "\twrite\t - read data from cli and append it to file, <args> should contain how many bytes you want to write\r\n"); | ||||
|         "\tread_chunks\t - read data from file and print file size and content to cli, <args> should contain how many bytes you want to read in block\r\n"); | ||||
|     printf("\twrite\t - read text from cli and append it to file, stops by ctrl+c\r\n"); | ||||
|     printf( | ||||
|         "\twrite_chunk\t - read data from cli and append it to file, <args> should contain how many bytes you want to write\r\n"); | ||||
|     printf("\tcopy\t - copy file to new file, <args> must contain new path\r\n"); | ||||
|     printf("\trename\t - move file to new file, <args> must contain new path\r\n"); | ||||
|     printf("\tmkdir\t - creates a new directory\r\n"); | ||||
|     printf("\tmd5\t - md5 hash of the file\r\n"); | ||||
|     printf("\tstat\t - info about file or dir\r\n"); | ||||
| }; | ||||
| 
 | ||||
| void storage_cli_print_error(FS_Error error) { | ||||
|     printf("Storage error: %s\r\n", storage_error_get_desc(error)); | ||||
| } | ||||
| 
 | ||||
| void storage_cli_print_path_error(string_t path, FS_Error error) { | ||||
|     printf( | ||||
|         "Storage error for path \"%s\": %s\r\n", | ||||
|         string_get_cstr(path), | ||||
|         storage_error_get_desc(error)); | ||||
| } | ||||
| 
 | ||||
| void storage_cli_print_file_error(string_t path, File* file) { | ||||
|     printf( | ||||
|         "Storage error for path \"%s\": %s\r\n", | ||||
|         string_get_cstr(path), | ||||
|         storage_file_get_error_desc(file)); | ||||
| } | ||||
| 
 | ||||
| void storage_cli_info(Cli* cli, string_t path) { | ||||
|     Storage* api = furi_record_open("storage"); | ||||
| 
 | ||||
| @ -60,10 +52,10 @@ void storage_cli_info(Cli* cli, string_t path) { | ||||
|         FS_Error error = storage_common_fs_info(api, "/int", &total_space, &free_space); | ||||
| 
 | ||||
|         if(error != FSE_OK) { | ||||
|             storage_cli_print_path_error(path, error); | ||||
|             storage_cli_print_error(error); | ||||
|         } else { | ||||
|             printf( | ||||
|                 "Label: %s\r\nType: LittleFS\r\n%lu KB total\r\n%lu KB free\r\n", | ||||
|                 "Label: %s\r\nType: LittleFS\r\n%luKB total\r\n%luKB free\r\n", | ||||
|                 furi_hal_version_get_name_ptr() ? furi_hal_version_get_name_ptr() : "Unknown", | ||||
|                 (uint32_t)(total_space / 1024), | ||||
|                 (uint32_t)(free_space / 1024)); | ||||
| @ -73,10 +65,10 @@ void storage_cli_info(Cli* cli, string_t path) { | ||||
|         FS_Error error = storage_sd_info(api, &sd_info); | ||||
| 
 | ||||
|         if(error != FSE_OK) { | ||||
|             storage_cli_print_path_error(path, error); | ||||
|             storage_cli_print_error(error); | ||||
|         } else { | ||||
|             printf( | ||||
|                 "Label: %s\r\nType: %s\r\n%lu KB total\r\n%lu KB free\r\n", | ||||
|                 "Label: %s\r\nType: %s\r\n%luKB total\r\n%luKB free\r\n", | ||||
|                 sd_info.label, | ||||
|                 sd_api_get_fs_type_text(sd_info.fs_type), | ||||
|                 sd_info.kb_total, | ||||
| @ -91,7 +83,7 @@ void storage_cli_info(Cli* cli, string_t path) { | ||||
| 
 | ||||
| void storage_cli_format(Cli* cli, string_t path) { | ||||
|     if(string_cmp_str(path, "/int") == 0) { | ||||
|         storage_cli_print_path_error(path, FSE_NOT_IMPLEMENTED); | ||||
|         storage_cli_print_error(FSE_NOT_IMPLEMENTED); | ||||
|     } else if(string_cmp_str(path, "/ext") == 0) { | ||||
|         printf("Formatting SD card, all data will be lost. Are you sure (y/n)?\r\n"); | ||||
|         char answer = cli_getc(cli); | ||||
| @ -102,7 +94,7 @@ void storage_cli_format(Cli* cli, string_t path) { | ||||
|             FS_Error error = storage_sd_format(api); | ||||
| 
 | ||||
|             if(error != FSE_OK) { | ||||
|                 storage_cli_print_path_error(path, error); | ||||
|                 storage_cli_print_error(error); | ||||
|             } else { | ||||
|                 printf("SD card was successfully formatted.\r\n"); | ||||
|             } | ||||
| @ -142,7 +134,7 @@ void storage_cli_list(Cli* cli, string_t path) { | ||||
|                 printf("\tEmpty\r\n"); | ||||
|             } | ||||
|         } else { | ||||
|             storage_cli_print_file_error(path, file); | ||||
|             storage_cli_print_error(storage_file_get_error(file)); | ||||
|         } | ||||
| 
 | ||||
|         storage_dir_close(file); | ||||
| @ -172,7 +164,7 @@ void storage_cli_read(Cli* cli, string_t path) { | ||||
| 
 | ||||
|         free(data); | ||||
|     } else { | ||||
|         storage_cli_print_file_error(path, file); | ||||
|         storage_cli_print_error(storage_file_get_error(file)); | ||||
|     } | ||||
| 
 | ||||
|     storage_file_close(file); | ||||
| @ -181,52 +173,126 @@ void storage_cli_read(Cli* cli, string_t path) { | ||||
|     furi_record_close("storage"); | ||||
| } | ||||
| 
 | ||||
| void storage_cli_write(Cli* cli, string_t path, string_t args) { | ||||
| void storage_cli_write(Cli* cli, string_t path) { | ||||
|     Storage* api = furi_record_open("storage"); | ||||
|     File* file = storage_file_alloc(api); | ||||
| 
 | ||||
|     uint32_t size; | ||||
|     int parsed_count = sscanf(string_get_cstr(args), "%lu", &size); | ||||
|     const uint16_t buffer_size = 512; | ||||
|     uint8_t* buffer = furi_alloc(buffer_size); | ||||
| 
 | ||||
|     if(storage_file_open(file, string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) { | ||||
|         printf("Just write your text data. New line by Ctrl+Enter, exit by Ctrl+C.\r\n"); | ||||
| 
 | ||||
|         uint32_t readed_index = 0; | ||||
| 
 | ||||
|         while(true) { | ||||
|             uint8_t symbol = cli_getc(cli); | ||||
| 
 | ||||
|             if(symbol == CliSymbolAsciiETX) { | ||||
|                 uint16_t write_size = readed_index % buffer_size; | ||||
| 
 | ||||
|                 if(write_size > 0) { | ||||
|                     uint16_t writed_size = storage_file_write(file, buffer, write_size); | ||||
| 
 | ||||
|                     if(writed_size != write_size) { | ||||
|                         storage_cli_print_error(storage_file_get_error(file)); | ||||
|                     } | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             buffer[readed_index % buffer_size] = symbol; | ||||
|             printf("%c", buffer[readed_index % buffer_size]); | ||||
|             fflush(stdout); | ||||
|             readed_index++; | ||||
| 
 | ||||
|             if(((readed_index % buffer_size) == 0)) { | ||||
|                 uint16_t writed_size = storage_file_write(file, buffer, buffer_size); | ||||
| 
 | ||||
|                 if(writed_size != buffer_size) { | ||||
|                     storage_cli_print_error(storage_file_get_error(file)); | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         printf("\r\n"); | ||||
| 
 | ||||
|     } else { | ||||
|         storage_cli_print_error(storage_file_get_error(file)); | ||||
|     } | ||||
|     storage_file_close(file); | ||||
| 
 | ||||
|     free(buffer); | ||||
|     storage_file_free(file); | ||||
|     furi_record_close("storage"); | ||||
| } | ||||
| 
 | ||||
| void storage_cli_read_chunks(Cli* cli, string_t path, string_t args) { | ||||
|     Storage* api = furi_record_open("storage"); | ||||
|     File* file = storage_file_alloc(api); | ||||
| 
 | ||||
|     uint32_t buffer_size; | ||||
|     int parsed_count = sscanf(string_get_cstr(args), "%lu", &buffer_size); | ||||
| 
 | ||||
|     if(parsed_count == EOF || parsed_count != 1) { | ||||
|         storage_cli_print_usage(); | ||||
|     } else if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||
|         uint8_t* data = furi_alloc(buffer_size); | ||||
|         uint64_t file_size = storage_file_size(file); | ||||
| 
 | ||||
|         printf("Size: %lu\r\n", (uint32_t)file_size); | ||||
| 
 | ||||
|         while(file_size > 0) { | ||||
|             printf("\r\nReady?\r\n"); | ||||
|             cli_getc(cli); | ||||
| 
 | ||||
|             uint16_t readed_size = storage_file_read(file, data, buffer_size); | ||||
|             for(uint16_t i = 0; i < readed_size; i++) { | ||||
|                 putchar(data[i]); | ||||
|             } | ||||
|             file_size -= readed_size; | ||||
|         } | ||||
|         printf("\r\n"); | ||||
| 
 | ||||
|         free(data); | ||||
|     } else { | ||||
|         storage_cli_print_error(storage_file_get_error(file)); | ||||
|     } | ||||
| 
 | ||||
|     storage_file_close(file); | ||||
|     storage_file_free(file); | ||||
| 
 | ||||
|     furi_record_close("storage"); | ||||
| } | ||||
| 
 | ||||
| void storage_cli_write_chunk(Cli* cli, string_t path, string_t args) { | ||||
|     Storage* api = furi_record_open("storage"); | ||||
|     File* file = storage_file_alloc(api); | ||||
| 
 | ||||
|     uint32_t buffer_size; | ||||
|     int parsed_count = sscanf(string_get_cstr(args), "%lu", &buffer_size); | ||||
| 
 | ||||
|     if(parsed_count == EOF || parsed_count != 1) { | ||||
|         storage_cli_print_usage(); | ||||
|     } else { | ||||
|         if(storage_file_open(file, string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) { | ||||
|             const uint16_t write_size = 8; | ||||
|             uint32_t readed_index = 0; | ||||
|             uint8_t* data = furi_alloc(write_size); | ||||
|             printf("Ready\r\n"); | ||||
| 
 | ||||
|             while(true) { | ||||
|                 data[readed_index % write_size] = cli_getc(cli); | ||||
|                 printf("%c", data[readed_index % write_size]); | ||||
|                 fflush(stdout); | ||||
|                 readed_index++; | ||||
|             uint8_t* buffer = furi_alloc(buffer_size); | ||||
| 
 | ||||
|                 if(((readed_index % write_size) == 0)) { | ||||
|                     uint16_t writed_size = storage_file_write(file, data, write_size); | ||||
| 
 | ||||
|                     if(writed_size != write_size) { | ||||
|                         storage_cli_print_file_error(path, file); | ||||
|                         break; | ||||
|                     } | ||||
|                 } else if(readed_index == size) { | ||||
|                     uint16_t writed_size = storage_file_write(file, data, size % write_size); | ||||
| 
 | ||||
|                     if(writed_size != (size % write_size)) { | ||||
|                         storage_cli_print_file_error(path, file); | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|                 if(readed_index == size) { | ||||
|                     break; | ||||
|                 } | ||||
|             for(uint32_t i = 0; i < buffer_size; i++) { | ||||
|                 buffer[i] = cli_getc(cli); | ||||
|             } | ||||
|             printf("\r\n"); | ||||
| 
 | ||||
|             free(data); | ||||
|             uint16_t writed_size = storage_file_write(file, buffer, buffer_size); | ||||
| 
 | ||||
|             if(writed_size != buffer_size) { | ||||
|                 storage_cli_print_error(storage_file_get_error(file)); | ||||
|             } | ||||
| 
 | ||||
|             free(buffer); | ||||
|         } else { | ||||
|             storage_cli_print_file_error(path, file); | ||||
|             storage_cli_print_error(storage_file_get_error(file)); | ||||
|         } | ||||
|         storage_file_close(file); | ||||
|     } | ||||
| @ -235,6 +301,45 @@ void storage_cli_write(Cli* cli, string_t path, string_t args) { | ||||
|     furi_record_close("storage"); | ||||
| } | ||||
| 
 | ||||
| void storage_cli_stat(Cli* cli, string_t path) { | ||||
|     Storage* api = furi_record_open("storage"); | ||||
| 
 | ||||
|     if(string_cmp_str(path, "/") == 0) { | ||||
|         printf("Storage\r\n"); | ||||
|     } else if( | ||||
|         string_cmp_str(path, "/ext") == 0 || string_cmp_str(path, "/int") == 0 || | ||||
|         string_cmp_str(path, "/any") == 0) { | ||||
|         uint64_t total_space; | ||||
|         uint64_t free_space; | ||||
|         FS_Error error = | ||||
|             storage_common_fs_info(api, string_get_cstr(path), &total_space, &free_space); | ||||
| 
 | ||||
|         if(error != FSE_OK) { | ||||
|             storage_cli_print_error(error); | ||||
|         } else { | ||||
|             printf( | ||||
|                 "Storage, %luKB total, %luKB free\r\n", | ||||
|                 (uint32_t)(total_space / 1024), | ||||
|                 (uint32_t)(free_space / 1024)); | ||||
|         } | ||||
|     } else { | ||||
|         FileInfo fileinfo; | ||||
|         FS_Error error = storage_common_stat(api, string_get_cstr(path), &fileinfo); | ||||
| 
 | ||||
|         if(error == FSE_OK) { | ||||
|             if(fileinfo.flags & FSF_DIRECTORY) { | ||||
|                 printf("Directory\r\n"); | ||||
|             } else { | ||||
|                 printf("File, size: %lub\r\n", (uint32_t)(fileinfo.size)); | ||||
|             } | ||||
|         } else { | ||||
|             storage_cli_print_error(error); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     furi_record_close("storage"); | ||||
| } | ||||
| 
 | ||||
| void storage_cli_copy(Cli* cli, string_t old_path, string_t args) { | ||||
|     Storage* api = furi_record_open("storage"); | ||||
|     string_t new_path; | ||||
| @ -297,6 +402,43 @@ void storage_cli_mkdir(Cli* cli, string_t path) { | ||||
|     furi_record_close("storage"); | ||||
| } | ||||
| 
 | ||||
| void storage_cli_md5(Cli* cli, string_t path) { | ||||
|     Storage* api = furi_record_open("storage"); | ||||
|     File* file = storage_file_alloc(api); | ||||
| 
 | ||||
|     if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||
|         const uint16_t read_size = 512; | ||||
|         const uint8_t hash_size = 16; | ||||
|         uint8_t* data = malloc(read_size); | ||||
|         uint8_t* hash = malloc(sizeof(uint8_t) * hash_size); | ||||
|         md5_context* md5_ctx = malloc(sizeof(md5_context)); | ||||
| 
 | ||||
|         md5_starts(md5_ctx); | ||||
|         while(true) { | ||||
|             uint16_t readed_size = storage_file_read(file, data, read_size); | ||||
|             if(readed_size == 0) break; | ||||
|             md5_update(md5_ctx, data, readed_size); | ||||
|         } | ||||
|         md5_finish(md5_ctx, hash); | ||||
|         free(md5_ctx); | ||||
| 
 | ||||
|         for(uint8_t i = 0; i < hash_size; i++) { | ||||
|             printf("%02x", hash[i]); | ||||
|         } | ||||
|         printf("\r\n"); | ||||
| 
 | ||||
|         free(hash); | ||||
|         free(data); | ||||
|     } else { | ||||
|         storage_cli_print_error(storage_file_get_error(file)); | ||||
|     } | ||||
| 
 | ||||
|     storage_file_close(file); | ||||
|     storage_file_free(file); | ||||
| 
 | ||||
|     furi_record_close("storage"); | ||||
| } | ||||
| 
 | ||||
| void storage_cli(Cli* cli, string_t args, void* context) { | ||||
|     string_t cmd; | ||||
|     string_t path; | ||||
| @ -334,8 +476,18 @@ void storage_cli(Cli* cli, string_t args, void* context) { | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         if(string_cmp_str(cmd, "read_chunks") == 0) { | ||||
|             storage_cli_read_chunks(cli, path, args); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         if(string_cmp_str(cmd, "write") == 0) { | ||||
|             storage_cli_write(cli, path, args); | ||||
|             storage_cli_write(cli, path); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         if(string_cmp_str(cmd, "write_chunk") == 0) { | ||||
|             storage_cli_write_chunk(cli, path, args); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
| @ -359,6 +511,16 @@ void storage_cli(Cli* cli, string_t args, void* context) { | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         if(string_cmp_str(cmd, "md5") == 0) { | ||||
|             storage_cli_md5(cli, path); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         if(string_cmp_str(cmd, "stat") == 0) { | ||||
|             storage_cli_stat(cli, path); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         storage_cli_print_usage(); | ||||
|     } while(false); | ||||
| 
 | ||||
|  | ||||
| @ -307,43 +307,67 @@ static FS_Error storage_process_common_remove(Storage* app, const char* path) { | ||||
|     return ret; | ||||
| } | ||||
| 
 | ||||
| static FS_Error storage_process_common_mkdir(Storage* app, const char* path) { | ||||
|     FS_Error ret = FSE_OK; | ||||
|     StorageType type = storage_get_type_by_path(path); | ||||
| 
 | ||||
|     if(storage_type_is_not_valid(type)) { | ||||
|         ret = FSE_INVALID_NAME; | ||||
|     } else { | ||||
|         StorageData* storage = storage_get_storage_by_type(app, type); | ||||
|         FS_CALL(storage, common.mkdir(storage, remove_vfs(path))); | ||||
|     } | ||||
| 
 | ||||
|     return ret; | ||||
| } | ||||
| 
 | ||||
| static FS_Error storage_process_common_copy(Storage* app, const char* old, const char* new) { | ||||
|     FS_Error ret = FSE_INTERNAL; | ||||
|     File file_old; | ||||
|     File file_new; | ||||
| 
 | ||||
|     do { | ||||
|         if(!storage_process_file_open(app, &file_old, old, FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||
|             ret = storage_file_get_error(&file_old); | ||||
|             storage_process_file_close(app, &file_old); | ||||
|             break; | ||||
|     FileInfo fileinfo; | ||||
|     ret = storage_process_common_stat(app, old, &fileinfo); | ||||
| 
 | ||||
|     if(ret == FSE_OK) { | ||||
|         if(fileinfo.flags & FSF_DIRECTORY) { | ||||
|             ret = storage_process_common_mkdir(app, new); | ||||
|         } else { | ||||
|             do { | ||||
|                 if(!storage_process_file_open(app, &file_old, old, FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||
|                     ret = storage_file_get_error(&file_old); | ||||
|                     storage_process_file_close(app, &file_old); | ||||
|                     break; | ||||
|                 } | ||||
| 
 | ||||
|                 if(!storage_process_file_open(app, &file_new, new, FSAM_WRITE, FSOM_CREATE_NEW)) { | ||||
|                     ret = storage_file_get_error(&file_new); | ||||
|                     storage_process_file_close(app, &file_new); | ||||
|                     storage_process_file_close(app, &file_old); | ||||
|                     break; | ||||
|                 } | ||||
| 
 | ||||
|                 const uint16_t buffer_size = 64; | ||||
|                 uint8_t* buffer = malloc(buffer_size); | ||||
|                 uint16_t readed_size = 0; | ||||
|                 uint16_t writed_size = 0; | ||||
| 
 | ||||
|                 while(true) { | ||||
|                     readed_size = storage_process_file_read(app, &file_old, buffer, buffer_size); | ||||
|                     ret = storage_file_get_error(&file_old); | ||||
|                     if(readed_size == 0) break; | ||||
| 
 | ||||
|                     writed_size = storage_process_file_write(app, &file_new, buffer, readed_size); | ||||
|                     ret = storage_file_get_error(&file_new); | ||||
|                     if(writed_size < readed_size) break; | ||||
|                 } | ||||
| 
 | ||||
|                 free(buffer); | ||||
|                 storage_process_file_close(app, &file_old); | ||||
|                 storage_process_file_close(app, &file_new); | ||||
|             } while(false); | ||||
|         } | ||||
| 
 | ||||
|         if(!storage_process_file_open(app, &file_new, new, FSAM_WRITE, FSOM_CREATE_NEW)) { | ||||
|             ret = storage_file_get_error(&file_new); | ||||
|             storage_process_file_close(app, &file_new); | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         const uint16_t buffer_size = 64; | ||||
|         uint8_t* buffer = malloc(buffer_size); | ||||
|         uint16_t readed_size = 0; | ||||
|         uint16_t writed_size = 0; | ||||
| 
 | ||||
|         while(true) { | ||||
|             readed_size = storage_process_file_read(app, &file_old, buffer, buffer_size); | ||||
|             ret = storage_file_get_error(&file_old); | ||||
|             if(readed_size == 0) break; | ||||
| 
 | ||||
|             writed_size = storage_process_file_write(app, &file_new, buffer, readed_size); | ||||
|             ret = storage_file_get_error(&file_new); | ||||
|             if(writed_size < readed_size) break; | ||||
|         } | ||||
| 
 | ||||
|         free(buffer); | ||||
|         storage_process_file_close(app, &file_old); | ||||
|         storage_process_file_close(app, &file_new); | ||||
|     } while(false); | ||||
|     } | ||||
| 
 | ||||
|     return ret; | ||||
| } | ||||
| @ -370,20 +394,6 @@ static FS_Error storage_process_common_rename(Storage* app, const char* old, con | ||||
|     return ret; | ||||
| } | ||||
| 
 | ||||
| static FS_Error storage_process_common_mkdir(Storage* app, const char* path) { | ||||
|     FS_Error ret = FSE_OK; | ||||
|     StorageType type = storage_get_type_by_path(path); | ||||
| 
 | ||||
|     if(storage_type_is_not_valid(type)) { | ||||
|         ret = FSE_INVALID_NAME; | ||||
|     } else { | ||||
|         StorageData* storage = storage_get_storage_by_type(app, type); | ||||
|         FS_CALL(storage, common.mkdir(storage, remove_vfs(path))); | ||||
|     } | ||||
| 
 | ||||
|     return ret; | ||||
| } | ||||
| 
 | ||||
| static FS_Error storage_process_common_fs_info( | ||||
|     Storage* app, | ||||
|     const char* fs_path, | ||||
|  | ||||
| @ -6,7 +6,11 @@ const void subghz_scene_analyze_on_enter(void* context) { | ||||
| } | ||||
| 
 | ||||
| const bool subghz_scene_analyze_on_event(void* context, SceneManagerEvent event) { | ||||
|     // SubGhz* subghz = context;
 | ||||
|     SubGhz* subghz = context; | ||||
|     if(event.type == SceneManagerEventTypeTick) { | ||||
|         notification_message(subghz->notifications, &sequence_blink_blue_10); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -10,3 +10,4 @@ ADD_SCENE(subghz, static, Static) | ||||
| ADD_SCENE(subghz, test, Test) | ||||
| ADD_SCENE(subghz, test_carrier, TestCarrier) | ||||
| ADD_SCENE(subghz, test_packet, TestPacket) | ||||
| ADD_SCENE(subghz, set_type, SetType) | ||||
|  | ||||
| @ -25,6 +25,7 @@ const void subghz_scene_read_on_enter(void* context) { | ||||
|     //Start CC1101 rx
 | ||||
|     subghz_begin(FuriHalSubGhzPresetOokAsync); | ||||
|     subghz_rx(433920000); | ||||
| 
 | ||||
|     furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, subghz->worker); | ||||
|     subghz_worker_start(subghz->worker); | ||||
|     subghz_protocol_enable_dump(subghz->protocol, subghz_read_protocol_callback, subghz); | ||||
| @ -36,9 +37,13 @@ const bool subghz_scene_read_on_event(void* context, SceneManagerEvent event) { | ||||
|     SubGhz* subghz = context; | ||||
|     if(event.type == SceneManagerEventTypeCustom) { | ||||
|         if(event.event == GUBGHZ_READ_CUSTOM_EVENT) { | ||||
|             scene_manager_next_scene(subghz->scene_manager, SubGhzViewReceiver); | ||||
|             scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiver); | ||||
|             notification_message(subghz->notifications, &sequence_success); | ||||
|             return true; | ||||
|         } | ||||
|     } else if(event.type == SceneManagerEventTypeTick) { | ||||
|         notification_message(subghz->notifications, &sequence_blink_blue_10); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| @ -46,7 +51,7 @@ const bool subghz_scene_read_on_event(void* context, SceneManagerEvent event) { | ||||
| const void subghz_scene_read_on_exit(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
| 
 | ||||
|     //Stop CC1101
 | ||||
|     // Stop CC1101
 | ||||
|     subghz_worker_stop(subghz->worker); | ||||
|     furi_hal_subghz_stop_async_rx(); | ||||
|     subghz_end(); | ||||
|  | ||||
| @ -4,52 +4,6 @@ | ||||
| 
 | ||||
| #define SCENE_SAVE_NAME_CUSTOM_EVENT (0UL) | ||||
| 
 | ||||
| bool subghz_scene_save_data_to_file(void* context, const char* dev_name) { | ||||
|     SubGhz* subghz = context; | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     string_t dev_file_name; | ||||
|     string_init(dev_file_name); | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     bool saved = false; | ||||
| 
 | ||||
|     do { | ||||
|         // Create subghz folder directory if necessary
 | ||||
|         if(!file_worker_mkdir(file_worker, SUBGHZ_APP_FOLDER)) { | ||||
|             break; | ||||
|         } | ||||
|         // Create saved directory if necessary
 | ||||
|         if(!file_worker_mkdir(file_worker, SUBGHZ_APP_PATH_FOLDER)) { | ||||
|             break; | ||||
|         } | ||||
|         // First remove subghz device file if it was saved
 | ||||
|         string_printf( | ||||
|             dev_file_name, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, dev_name, SUBGHZ_APP_EXTENSION); | ||||
|         if(!file_worker_remove(file_worker, string_get_cstr(dev_file_name))) { | ||||
|             break; | ||||
|         } | ||||
|         // Open file
 | ||||
|         if(!file_worker_open( | ||||
|                file_worker, string_get_cstr(dev_file_name), FSAM_WRITE, FSOM_CREATE_ALWAYS)) { | ||||
|             break; | ||||
|         } | ||||
|         //Get string save
 | ||||
|         subghz->protocol_result->to_save_string(subghz->protocol_result, temp_str); | ||||
|         // Prepare and write data to file
 | ||||
|         if(!file_worker_write(file_worker, string_get_cstr(temp_str), string_size(temp_str))) { | ||||
|             break; | ||||
|         } | ||||
|         saved = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
|     string_clear(dev_file_name); | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
| 
 | ||||
|     return saved; | ||||
| } | ||||
| 
 | ||||
| void subghz_scene_save_name_text_input_callback(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
|     view_dispatcher_send_custom_event(subghz->view_dispatcher, SCENE_SAVE_NAME_CUSTOM_EVENT); | ||||
| @ -81,7 +35,7 @@ const bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent even | ||||
| 
 | ||||
|     if(event.type == SceneManagerEventTypeCustom) { | ||||
|         if(event.event == SCENE_SAVE_NAME_CUSTOM_EVENT) { | ||||
|             if(subghz_scene_save_data_to_file(subghz, subghz->text_store)) { | ||||
|             if(subghz_save_protocol_to_file(subghz, subghz->text_store)) { | ||||
|                 scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveSuccess); | ||||
|                 return true; | ||||
|             } else { | ||||
|  | ||||
| @ -1,77 +1,9 @@ | ||||
| #include "../subghz_i.h" | ||||
| 
 | ||||
| bool subghz_scene_saved_file_select(SubGhz* subghz) { | ||||
|     furi_assert(subghz); | ||||
| 
 | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     string_t protocol_file_name; | ||||
|     string_init(protocol_file_name); | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
| 
 | ||||
|     // Input events and views are managed by file_select
 | ||||
|     bool res = file_worker_file_select( | ||||
|         file_worker, | ||||
|         SUBGHZ_APP_PATH_FOLDER, | ||||
|         SUBGHZ_APP_EXTENSION, | ||||
|         subghz->text_store, | ||||
|         sizeof(subghz->text_store), | ||||
|         NULL); | ||||
| 
 | ||||
|     if(res) { | ||||
|         // Get key file path
 | ||||
|         string_printf( | ||||
|             protocol_file_name, | ||||
|             "%s/%s%s", | ||||
|             SUBGHZ_APP_PATH_FOLDER, | ||||
|             subghz->text_store, | ||||
|             SUBGHZ_APP_EXTENSION); | ||||
|     } else { | ||||
|         string_clear(temp_str); | ||||
|         string_clear(protocol_file_name); | ||||
| 
 | ||||
|         file_worker_close(file_worker); | ||||
|         file_worker_free(file_worker); | ||||
|         return res; | ||||
|     } | ||||
| 
 | ||||
|     do { | ||||
|         if(!file_worker_open( | ||||
|                file_worker, string_get_cstr(protocol_file_name), FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||
|             break; | ||||
|         } | ||||
|         // Read and parse name protocol from 1st line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         // strlen("Protocol: ") = 10
 | ||||
|         string_right(temp_str, 10); | ||||
|         subghz->protocol_result = | ||||
|             subghz_protocol_get_by_name(subghz->protocol, string_get_cstr(temp_str)); | ||||
|         if(subghz->protocol_result == NULL) { | ||||
|             file_worker_show_error(file_worker, "Cannot parse\nfile"); | ||||
|             break; | ||||
|         } | ||||
|         if(!subghz->protocol_result->to_load_protocol(file_worker, subghz->protocol_result)) { | ||||
|             file_worker_show_error(file_worker, "Cannot parse\nfile"); | ||||
|             break; | ||||
|         } | ||||
|         res = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
|     string_clear(protocol_file_name); | ||||
| 
 | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
| 
 | ||||
|     return res; | ||||
| } | ||||
| 
 | ||||
| const void subghz_scene_saved_on_enter(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
| 
 | ||||
|     if(subghz_scene_saved_file_select(subghz)) { | ||||
|     if(subghz_saved_protocol_select(subghz)) { | ||||
|         scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTransmitter); | ||||
|     } else { | ||||
|         scene_manager_search_and_switch_to_previous_scene(subghz->scene_manager, SubGhzSceneStart); | ||||
|  | ||||
							
								
								
									
										173
									
								
								applications/subghz/scenes/subghz_scene_set_type.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @ -0,0 +1,173 @@ | ||||
| #include "../subghz_i.h" | ||||
| #include "../lib/subghz/protocols/subghz_protocol_keeloq.h" | ||||
| 
 | ||||
| enum SubmenuIndex { | ||||
|     SubmenuIndexPricenton, | ||||
|     SubmenuIndexNiceFlo12bit, | ||||
|     SubmenuIndexNiceFlo24bit, | ||||
|     SubmenuIndexCAME12bit, | ||||
|     SubmenuIndexCAME24bit, | ||||
|     SubmenuIndexNeroSketch, | ||||
|     SubmenuIndexGateTX, | ||||
|     SubmenuIndexDoorHan, | ||||
| }; | ||||
| 
 | ||||
| bool subghz_scene_set_type_submenu_to_find_protocol(void* context, const char* protocol_name) { | ||||
|     SubGhz* subghz = context; | ||||
|     subghz->protocol_result = subghz_protocol_get_by_name(subghz->protocol, protocol_name); | ||||
|     if(subghz->protocol_result == NULL) { | ||||
|         //show error
 | ||||
|         return false; | ||||
|     } | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| void subghz_scene_set_type_submenu_callback(void* context, uint32_t index) { | ||||
|     SubGhz* subghz = context; | ||||
|     view_dispatcher_send_custom_event(subghz->view_dispatcher, index); | ||||
| } | ||||
| 
 | ||||
| const void subghz_scene_set_type_on_enter(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
| 
 | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, | ||||
|         "Pricenton", | ||||
|         SubmenuIndexPricenton, | ||||
|         subghz_scene_set_type_submenu_callback, | ||||
|         subghz); | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, | ||||
|         "Nice Flo 12bit", | ||||
|         SubmenuIndexNiceFlo12bit, | ||||
|         subghz_scene_set_type_submenu_callback, | ||||
|         subghz); | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, | ||||
|         "Nice Flo 24bit", | ||||
|         SubmenuIndexNiceFlo24bit, | ||||
|         subghz_scene_set_type_submenu_callback, | ||||
|         subghz); | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, | ||||
|         "CAME 12bit", | ||||
|         SubmenuIndexCAME12bit, | ||||
|         subghz_scene_set_type_submenu_callback, | ||||
|         subghz); | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, | ||||
|         "CAME 24bit", | ||||
|         SubmenuIndexCAME24bit, | ||||
|         subghz_scene_set_type_submenu_callback, | ||||
|         subghz); | ||||
|     // submenu_add_item(
 | ||||
|     //     subghz->submenu, "Nero Sketch", SubmenuIndexNeroSketch, subghz_scene_set_type_submenu_callback, subghz);
 | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, | ||||
|         "Gate TX", | ||||
|         SubmenuIndexGateTX, | ||||
|         subghz_scene_set_type_submenu_callback, | ||||
|         subghz); | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, | ||||
|         "DoorHan", | ||||
|         SubmenuIndexDoorHan, | ||||
|         subghz_scene_set_type_submenu_callback, | ||||
|         subghz); | ||||
| 
 | ||||
|     submenu_set_selected_item( | ||||
|         subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSetType)); | ||||
| 
 | ||||
|     view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewMenu); | ||||
| } | ||||
| 
 | ||||
| const bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { | ||||
|     SubGhz* subghz = context; | ||||
|     bool generated_protocol = false; | ||||
| 
 | ||||
|     if(event.type == SceneManagerEventTypeCustom) { | ||||
|         uint32_t key = subghz_random_serial(); | ||||
|         switch(event.event) { | ||||
|         case SubmenuIndexPricenton: | ||||
|             if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "Princeton")) { | ||||
|                 subghz->protocol_result->code_last_count_bit = 24; | ||||
|                 key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
 | ||||
|                 subghz->protocol_result->code_last_found = key; | ||||
|                 generated_protocol = true; | ||||
|             } | ||||
|             break; | ||||
|         case SubmenuIndexNiceFlo12bit: | ||||
|             if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "Nice FLO")) { | ||||
|                 subghz->protocol_result->code_last_count_bit = 12; | ||||
|                 key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4
 | ||||
|                 subghz->protocol_result->code_last_found = key; | ||||
|                 generated_protocol = true; | ||||
|             } | ||||
|             break; | ||||
|         case SubmenuIndexNiceFlo24bit: | ||||
|             if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "Nice FLO")) { | ||||
|                 subghz->protocol_result->code_last_count_bit = 24; | ||||
|                 key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
 | ||||
|                 subghz->protocol_result->code_last_found = key; | ||||
|                 generated_protocol = true; | ||||
|             } | ||||
|             break; | ||||
|         case SubmenuIndexCAME12bit: | ||||
|             if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "CAME")) { | ||||
|                 subghz->protocol_result->code_last_count_bit = 12; | ||||
|                 key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4
 | ||||
|                 subghz->protocol_result->code_last_found = key; | ||||
|                 generated_protocol = true; | ||||
|             } | ||||
|             break; | ||||
|         case SubmenuIndexCAME24bit: | ||||
|             if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "CAME")) { | ||||
|                 subghz->protocol_result->code_last_count_bit = 24; | ||||
|                 key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
 | ||||
|                 subghz->protocol_result->code_last_found = key; | ||||
|                 generated_protocol = true; | ||||
|             } | ||||
|             break; | ||||
|         // case SubmenuIndexNeroSketch:
 | ||||
|         //     /* code */
 | ||||
|         //     break;
 | ||||
|         case SubmenuIndexGateTX: | ||||
|             if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "GateTX")) { | ||||
|                 subghz->protocol_result->code_last_count_bit = 24; | ||||
|                 key = (key & 0x00F0FFFF) | 0xF << 16; //btn 0xF, 0xC, 0xA, 0x6
 | ||||
|                 subghz->protocol_result->code_last_found = subghz_protocol_common_reverse_key( | ||||
|                     key, subghz->protocol_result->code_last_count_bit); | ||||
|                 generated_protocol = true; | ||||
|             } | ||||
|             break; | ||||
|         case SubmenuIndexDoorHan: | ||||
|             if(subghz_scene_set_type_submenu_to_find_protocol(subghz, "KeeLoq")) { | ||||
|                 subghz->protocol_result->code_last_count_bit = 64; | ||||
|                 subghz->protocol_result->serial = key & 0x0FFFFFFF; | ||||
|                 subghz->protocol_result->btn = 0x2; //btn 0x1, 0x2, 0x4, 0x8
 | ||||
|                 subghz->protocol_result->cnt = 0x0003; | ||||
|                 subghz_protocol_keeloq_set_manufacture_name(subghz->protocol_result, "DoorHan"); | ||||
|                 subghz->protocol_result->code_last_found = | ||||
|                     subghz_protocol_keeloq_gen_key(subghz->protocol_result); | ||||
| 
 | ||||
|                 generated_protocol = true; | ||||
|             } | ||||
|             break; | ||||
| 
 | ||||
|         default: | ||||
|             return false; | ||||
|             break; | ||||
|         } | ||||
|         if(generated_protocol) { | ||||
|             scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName); | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| const void subghz_scene_set_type_on_exit(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
|     submenu_clean(subghz->submenu); | ||||
| } | ||||
| @ -6,6 +6,7 @@ enum SubmenuIndex { | ||||
|     SubmenuIndexSaved, | ||||
|     SubmenuIndexStatic, | ||||
|     SubmenuIndexTest, | ||||
|     SubmenuIndexAddManualy, | ||||
| }; | ||||
| 
 | ||||
| void subghz_scene_start_submenu_callback(void* context, uint32_t index) { | ||||
| @ -15,7 +16,9 @@ void subghz_scene_start_submenu_callback(void* context, uint32_t index) { | ||||
| 
 | ||||
| const void subghz_scene_start_on_enter(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
| 
 | ||||
|     if(subghz->state_notifications == NOTIFICATION_STARTING_STATE) { | ||||
|         subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|     } | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, | ||||
|         "Analyze", | ||||
| @ -26,6 +29,12 @@ const void subghz_scene_start_on_enter(void* context) { | ||||
|         subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz); | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, "Saved", SubmenuIndexSaved, subghz_scene_start_submenu_callback, subghz); | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, | ||||
|         "Add manually", | ||||
|         SubmenuIndexAddManualy, | ||||
|         subghz_scene_start_submenu_callback, | ||||
|         subghz); | ||||
|     submenu_add_item( | ||||
|         subghz->submenu, "Static", SubmenuIndexStatic, subghz_scene_start_submenu_callback, subghz); | ||||
|     submenu_add_item( | ||||
| @ -56,6 +65,11 @@ const bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) { | ||||
|                 subghz->scene_manager, SubGhzSceneStart, SubmenuIndexSaved); | ||||
|             scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved); | ||||
|             return true; | ||||
|         } else if(event.event == SubmenuIndexAddManualy) { | ||||
|             scene_manager_set_scene_state( | ||||
|                 subghz->scene_manager, SubGhzSceneStart, SubmenuIndexAddManualy); | ||||
|             scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetType); | ||||
|             return true; | ||||
|         } else if(event.event == SubmenuIndexStatic) { | ||||
|             scene_manager_set_scene_state( | ||||
|                 subghz->scene_manager, SubGhzSceneStart, SubmenuIndexStatic); | ||||
|  | ||||
| @ -1,28 +1,5 @@ | ||||
| #include "../subghz_i.h" | ||||
| #include "../views/subghz_transmitter.h" | ||||
| #include "lib/subghz/protocols/subghz_protocol_princeton.h" | ||||
| 
 | ||||
| void subghz_scene_transmitter_tx(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
|     SubGhzEncoderPrinceton* encoder = subghz_encoder_princeton_alloc(); | ||||
| 
 | ||||
|     subghz_encoder_princeton_reset(encoder, subghz->protocol_result->code_last_found, 4); | ||||
|     subghz_encoder_princeton_set_te(encoder, subghz->protocol_result); | ||||
| 
 | ||||
|     subghz_begin(FuriHalSubGhzPresetOokAsync); | ||||
|     subghz_tx(433920000); | ||||
| 
 | ||||
|     furi_hal_subghz_start_async_tx(subghz_encoder_princeton_yield, encoder); | ||||
| 
 | ||||
|     while(!furi_hal_subghz_is_async_tx_complete()) { | ||||
|         osDelay(20); | ||||
|     } | ||||
| 
 | ||||
|     //Stop tx
 | ||||
|     furi_hal_subghz_stop_async_tx(); | ||||
|     subghz_end(); | ||||
|     subghz_encoder_princeton_free(encoder); | ||||
| } | ||||
| 
 | ||||
| void subghz_scene_transmitter_callback(SubghzTransmitterEvent event, void* context) { | ||||
|     furi_assert(context); | ||||
| @ -35,24 +12,36 @@ const void subghz_scene_transmitter_on_enter(void* context) { | ||||
|     SubghzTransmitter* subghz_transmitter = subghz->subghz_transmitter; | ||||
| 
 | ||||
|     subghz_transmitter_set_callback(subghz_transmitter, subghz_scene_transmitter_callback, subghz); | ||||
| 
 | ||||
|     subghz_transmitter_set_protocol(subghz_transmitter, subghz->protocol_result); | ||||
| 
 | ||||
|     view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewTransmitter); | ||||
| 
 | ||||
|     subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
| } | ||||
| 
 | ||||
| const bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { | ||||
|     SubGhz* subghz = context; | ||||
| 
 | ||||
|     if(event.type == SceneManagerEventTypeCustom) { | ||||
|         if(event.event == SubghzTransmitterEventSend) { | ||||
|             //scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
 | ||||
|             subghz_scene_transmitter_tx(subghz); | ||||
|         if(event.event == SubghzTransmitterEventSendStart) { | ||||
|             subghz->state_notifications = NOTIFICATION_TX_STATE; | ||||
|             subghz_transmitter_tx_start(subghz); | ||||
|             return true; | ||||
|         } else if(event.event == SubghzTransmitterEventSendStop) { | ||||
|             subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|             subghz_transmitter_tx_stop(subghz); | ||||
|             return true; | ||||
|         } else if(event.event == SubghzTransmitterEventBack) { | ||||
|             subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
|             scene_manager_search_and_switch_to_previous_scene( | ||||
|                 subghz->scene_manager, SubGhzSceneStart); | ||||
|             return true; | ||||
|         } | ||||
|     } else if(event.type == SceneManagerEventTypeTick) { | ||||
|         if(subghz->state_notifications == NOTIFICATION_TX_STATE) { | ||||
|             notification_message(subghz->notifications, &sequence_blink_red_10); | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| @ -60,6 +49,6 @@ const bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent ev | ||||
| const void subghz_scene_transmitter_on_exit(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
|     SubghzTransmitter* subghz_transmitter = subghz->subghz_transmitter; | ||||
| 
 | ||||
|     subghz_transmitter_set_callback(subghz_transmitter, NULL, subghz); | ||||
|     subghz->state_notifications = NOTIFICATION_IDLE_STATE; | ||||
| } | ||||
|  | ||||
| @ -62,6 +62,9 @@ SubGhz* subghz_alloc() { | ||||
|     view_dispatcher_set_tick_event_callback( | ||||
|         subghz->view_dispatcher, subghz_tick_event_callback, 100); | ||||
| 
 | ||||
|     // Open Notification record
 | ||||
|     subghz->notifications = furi_record_open("notification"); | ||||
| 
 | ||||
|     // SubMenu
 | ||||
|     subghz->submenu = submenu_alloc(); | ||||
|     view_dispatcher_add_view( | ||||
| @ -196,6 +199,10 @@ void subghz_free(SubGhz* subghz) { | ||||
|     subghz_protocol_free(subghz->protocol); | ||||
|     subghz_worker_free(subghz->worker); | ||||
| 
 | ||||
|     // Notifications
 | ||||
|     furi_record_close("notification"); | ||||
|     subghz->notifications = NULL; | ||||
| 
 | ||||
|     // The rest
 | ||||
|     free(subghz); | ||||
| } | ||||
|  | ||||
| @ -4,6 +4,7 @@ | ||||
| #include <furi-hal.h> | ||||
| #include <stream_buffer.h> | ||||
| #include <lib/subghz/protocols/subghz_protocol.h> | ||||
| #include <lib/subghz/protocols/subghz_protocol_common.h> | ||||
| #include <lib/subghz/protocols/subghz_protocol_princeton.h> | ||||
| 
 | ||||
| #define SUBGHZ_FREQUENCY_RANGE_STR \ | ||||
| @ -129,25 +130,29 @@ void subghz_cli_command_tx(Cli* cli, string_t args, void* context) { | ||||
|         key, | ||||
|         repeat); | ||||
| 
 | ||||
|     SubGhzEncoderPrinceton* encoder = subghz_encoder_princeton_alloc(); | ||||
|     subghz_encoder_princeton_reset(encoder, key, repeat); | ||||
|     SubGhzDecoderPrinceton* protocol = subghz_decoder_princeton_alloc(); | ||||
|     protocol->common.code_last_found = key; | ||||
|     protocol->common.code_last_count_bit = 24; | ||||
| 
 | ||||
|     SubGhzProtocolEncoderCommon* encoder = subghz_protocol_encoder_common_alloc(); | ||||
|     encoder->repeat = repeat; | ||||
| 
 | ||||
|     subghz_protocol_princeton_send_key(protocol, encoder); | ||||
|     furi_hal_subghz_reset(); | ||||
|     furi_hal_subghz_load_preset(FuriHalSubGhzPresetOokAsync); | ||||
|     frequency = furi_hal_subghz_set_frequency_and_path(frequency); | ||||
|     furi_hal_subghz_start_async_tx(subghz_protocol_encoder_common_yield, encoder); | ||||
| 
 | ||||
|     furi_hal_subghz_start_async_tx(subghz_encoder_princeton_yield, encoder); | ||||
| 
 | ||||
|     while(!furi_hal_subghz_is_async_tx_complete()) { | ||||
|     while(!(furi_hal_subghz_is_async_tx_complete() || cli_cmd_interrupt_received(cli))) { | ||||
|         printf("."); | ||||
|         fflush(stdout); | ||||
|         osDelay(333); | ||||
|     } | ||||
| 
 | ||||
|     furi_hal_subghz_stop_async_tx(); | ||||
| 
 | ||||
|     furi_hal_subghz_sleep(); | ||||
|     subghz_encoder_princeton_free(encoder); | ||||
| 
 | ||||
|     subghz_decoder_princeton_free(protocol); | ||||
|     subghz_protocol_encoder_common_free(encoder); | ||||
| } | ||||
| 
 | ||||
| typedef struct { | ||||
|  | ||||
| @ -7,6 +7,7 @@ | ||||
| #include <gui/elements.h> | ||||
| #include <notification/notification-messages.h> | ||||
| #include "file-worker.h" | ||||
| #include "../notification/notification.h" | ||||
| 
 | ||||
| void subghz_begin(FuriHalSubGhzPreset preset) { | ||||
|     furi_hal_subghz_reset(); | ||||
| @ -39,6 +40,34 @@ void subghz_end(void) { | ||||
|     furi_hal_subghz_sleep(); | ||||
| } | ||||
| 
 | ||||
| void subghz_transmitter_tx_start(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
|     subghz->encoder = subghz_protocol_encoder_common_alloc(); | ||||
|     subghz->encoder->repeat = 200; //max repeat with the button held down
 | ||||
|     //get upload
 | ||||
|     if(subghz->protocol_result->get_upload_protocol) { | ||||
|         if(subghz->protocol_result->get_upload_protocol(subghz->protocol_result, subghz->encoder)) { | ||||
|             subghz_begin(FuriHalSubGhzPresetOokAsync); | ||||
|             subghz_tx(433920000); | ||||
|             //Start TX
 | ||||
|             furi_hal_subghz_start_async_tx(subghz_protocol_encoder_common_yield, subghz->encoder); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void subghz_transmitter_tx_stop(void* context) { | ||||
|     SubGhz* subghz = context; | ||||
|     //Stop TX
 | ||||
|     furi_hal_subghz_stop_async_tx(); | ||||
|     subghz_end(); | ||||
|     subghz_protocol_encoder_common_free(subghz->encoder); | ||||
|     //if protocol dynamic then we save the last upload
 | ||||
|     if(subghz->protocol_result->type_protocol == TYPE_PROTOCOL_DYNAMIC) { | ||||
|         subghz_save_protocol_to_file(subghz, subghz->text_store); | ||||
|     } | ||||
|     notification_message(subghz->notifications, &sequence_reset_red); | ||||
| } | ||||
| 
 | ||||
| bool subghz_key_load(SubGhz* subghz, const char* file_path) { | ||||
|     furi_assert(subghz); | ||||
|     furi_assert(file_path); | ||||
| @ -81,3 +110,127 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path) { | ||||
| 
 | ||||
|     return loaded; | ||||
| } | ||||
| 
 | ||||
| bool subghz_save_protocol_to_file(void* context, const char* dev_name) { | ||||
|     SubGhz* subghz = context; | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     string_t dev_file_name; | ||||
|     string_init(dev_file_name); | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
|     bool saved = false; | ||||
| 
 | ||||
|     do { | ||||
|         // Create subghz folder directory if necessary
 | ||||
|         if(!file_worker_mkdir(file_worker, SUBGHZ_APP_FOLDER)) { | ||||
|             break; | ||||
|         } | ||||
|         // Create saved directory if necessary
 | ||||
|         if(!file_worker_mkdir(file_worker, SUBGHZ_APP_PATH_FOLDER)) { | ||||
|             break; | ||||
|         } | ||||
|         // First remove subghz device file if it was saved
 | ||||
|         string_printf( | ||||
|             dev_file_name, "%s/%s%s", SUBGHZ_APP_PATH_FOLDER, dev_name, SUBGHZ_APP_EXTENSION); | ||||
|         if(!file_worker_remove(file_worker, string_get_cstr(dev_file_name))) { | ||||
|             break; | ||||
|         } | ||||
|         // Open file
 | ||||
|         if(!file_worker_open( | ||||
|                file_worker, string_get_cstr(dev_file_name), FSAM_WRITE, FSOM_CREATE_ALWAYS)) { | ||||
|             break; | ||||
|         } | ||||
|         //Get string save
 | ||||
|         subghz->protocol_result->to_save_string(subghz->protocol_result, temp_str); | ||||
|         // Prepare and write data to file
 | ||||
|         if(!file_worker_write(file_worker, string_get_cstr(temp_str), string_size(temp_str))) { | ||||
|             break; | ||||
|         } | ||||
|         saved = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
|     string_clear(dev_file_name); | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
| 
 | ||||
|     return saved; | ||||
| } | ||||
| 
 | ||||
| bool subghz_saved_protocol_select(SubGhz* subghz) { | ||||
|     furi_assert(subghz); | ||||
| 
 | ||||
|     FileWorker* file_worker = file_worker_alloc(false); | ||||
|     string_t protocol_file_name; | ||||
|     string_init(protocol_file_name); | ||||
|     string_t temp_str; | ||||
|     string_init(temp_str); | ||||
| 
 | ||||
|     // Input events and views are managed by file_select
 | ||||
|     bool res = file_worker_file_select( | ||||
|         file_worker, | ||||
|         SUBGHZ_APP_PATH_FOLDER, | ||||
|         SUBGHZ_APP_EXTENSION, | ||||
|         subghz->text_store, | ||||
|         sizeof(subghz->text_store), | ||||
|         NULL); | ||||
| 
 | ||||
|     if(res) { | ||||
|         // Get key file path
 | ||||
|         string_printf( | ||||
|             protocol_file_name, | ||||
|             "%s/%s%s", | ||||
|             SUBGHZ_APP_PATH_FOLDER, | ||||
|             subghz->text_store, | ||||
|             SUBGHZ_APP_EXTENSION); | ||||
|     } else { | ||||
|         string_clear(temp_str); | ||||
|         string_clear(protocol_file_name); | ||||
| 
 | ||||
|         file_worker_close(file_worker); | ||||
|         file_worker_free(file_worker); | ||||
|         return res; | ||||
|     } | ||||
|     res = false; | ||||
|     do { | ||||
|         if(!file_worker_open( | ||||
|                file_worker, string_get_cstr(protocol_file_name), FSAM_READ, FSOM_OPEN_EXISTING)) { | ||||
|             break; | ||||
|         } | ||||
|         // Read and parse name protocol from 1st line
 | ||||
|         if(!file_worker_read_until(file_worker, temp_str, '\n')) { | ||||
|             break; | ||||
|         } | ||||
|         // strlen("Protocol: ") = 10
 | ||||
|         string_right(temp_str, 10); | ||||
|         subghz->protocol_result = | ||||
|             subghz_protocol_get_by_name(subghz->protocol, string_get_cstr(temp_str)); | ||||
|         if(subghz->protocol_result == NULL) { | ||||
|             file_worker_show_error(file_worker, "Cannot parse\nfile"); | ||||
|             break; | ||||
|         } | ||||
|         if(!subghz->protocol_result->to_load_protocol(file_worker, subghz->protocol_result)) { | ||||
|             file_worker_show_error(file_worker, "Cannot parse\nfile"); | ||||
|             break; | ||||
|         } | ||||
|         res = true; | ||||
|     } while(0); | ||||
| 
 | ||||
|     string_clear(temp_str); | ||||
|     string_clear(protocol_file_name); | ||||
| 
 | ||||
|     file_worker_close(file_worker); | ||||
|     file_worker_free(file_worker); | ||||
| 
 | ||||
|     return res; | ||||
| } | ||||
| 
 | ||||
| uint32_t subghz_random_serial(void) { | ||||
|     static bool rand_generator_inited = false; | ||||
| 
 | ||||
|     if(!rand_generator_inited) { | ||||
|         srand(DWT->CYCCNT); | ||||
|         rand_generator_inited = true; | ||||
|     } | ||||
|     return (uint32_t)rand(); | ||||
| } | ||||
|  | ||||
| @ -13,6 +13,7 @@ | ||||
| #include <furi-hal.h> | ||||
| #include <gui/gui.h> | ||||
| #include <gui/scene_manager.h> | ||||
| #include <notification/notification-messages.h> | ||||
| #include <gui/view_dispatcher.h> | ||||
| #include <gui/modules/submenu.h> | ||||
| #include <gui/modules/dialog_ex.h> | ||||
| @ -27,16 +28,22 @@ | ||||
| 
 | ||||
| #define SUBGHZ_TEXT_STORE_SIZE 128 | ||||
| 
 | ||||
| #define NOTIFICATION_STARTING_STATE 0u | ||||
| #define NOTIFICATION_IDLE_STATE 1u | ||||
| #define NOTIFICATION_TX_STATE 2u | ||||
| 
 | ||||
| extern const uint32_t subghz_frequencies[]; | ||||
| extern const uint32_t subghz_frequencies_count; | ||||
| extern const uint32_t subghz_frequencies_433_92; | ||||
| 
 | ||||
| struct SubGhz { | ||||
|     Gui* gui; | ||||
|     NotificationApp* notifications; | ||||
| 
 | ||||
|     SubGhzWorker* worker; | ||||
|     SubGhzProtocol* protocol; | ||||
|     SubGhzProtocolCommon* protocol_result; | ||||
|     SubGhzProtocolEncoderCommon* encoder; | ||||
| 
 | ||||
|     SceneManager* scene_manager; | ||||
| 
 | ||||
| @ -47,6 +54,7 @@ struct SubGhz { | ||||
|     Popup* popup; | ||||
|     TextInput* text_input; | ||||
|     char text_store[SUBGHZ_TEXT_STORE_SIZE + 1]; | ||||
|     uint8_t state_notifications; | ||||
| 
 | ||||
|     SubghzAnalyze* subghz_analyze; | ||||
|     SubghzReceiver* subghz_receiver; | ||||
| @ -77,4 +85,9 @@ void subghz_rx(uint32_t frequency); | ||||
| void subghz_tx(uint32_t frequency); | ||||
| void subghz_idle(void); | ||||
| void subghz_end(void); | ||||
| bool subghz_key_load(SubGhz* subghz, const char* file_path); | ||||
| void subghz_transmitter_tx_start(void* context); | ||||
| void subghz_transmitter_tx_stop(void* context); | ||||
| bool subghz_key_load(SubGhz* subghz, const char* file_path); | ||||
| bool subghz_save_protocol_to_file(void* context, const char* dev_name); | ||||
| bool subghz_saved_protocol_select(SubGhz* subghz); | ||||
| uint32_t subghz_random_serial(void); | ||||
|  | ||||
| @ -47,7 +47,8 @@ void subghz_receiver_draw(Canvas* canvas, SubghzReceiverModel* model) { | ||||
|     elements_multiline_text(canvas, 0, 10, string_get_cstr(model->text)); | ||||
| 
 | ||||
|     elements_button_left(canvas, "Back"); | ||||
|     if(model->protocol && model->protocol->to_save_string) { | ||||
|     if(model->protocol && model->protocol->to_save_string && | ||||
|        strcmp(model->protocol->name, "KeeLoq")) { | ||||
|         elements_button_right(canvas, "Save"); | ||||
|     } | ||||
| } | ||||
| @ -61,7 +62,9 @@ bool subghz_receiver_input(InputEvent* event, void* context) { | ||||
|     bool can_be_saved = false; | ||||
|     with_view_model( | ||||
|         subghz_receiver->view, (SubghzReceiverModel * model) { | ||||
|             can_be_saved = (model->protocol && model->protocol->to_save_string); | ||||
|             can_be_saved = | ||||
|                 (model->protocol && model->protocol->to_save_string && | ||||
|                  strcmp(model->protocol->name, "KeeLoq")); | ||||
|             return false; | ||||
|         }); | ||||
| 
 | ||||
|  | ||||
| @ -89,7 +89,7 @@ bool subghz_static_input(InputEvent* event, void* context) { | ||||
|                     NotificationApp* notification = furi_record_open("notification"); | ||||
|                     notification_message_block(notification, &sequence_set_red_255); | ||||
| 
 | ||||
|                     subghz_encoder_princeton_reset( | ||||
|                     subghz_encoder_princeton_set( | ||||
|                         instance->encoder, subghz_static_keys[model->button], 20); | ||||
|                     furi_hal_subghz_start_async_tx( | ||||
|                         subghz_encoder_princeton_yield, instance->encoder); | ||||
|  | ||||
| @ -153,7 +153,7 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) { | ||||
|             if(model->status == SubghzTestPacketModelStatusRx) { | ||||
|                 furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance); | ||||
|             } else { | ||||
|                 subghz_encoder_princeton_reset(instance->encoder, 0x00AABBCC, 1000); | ||||
|                 subghz_encoder_princeton_set(instance->encoder, 0x00AABBCC, 1000); | ||||
|                 furi_hal_subghz_start_async_tx(subghz_encoder_princeton_yield, instance->encoder); | ||||
|             } | ||||
| 
 | ||||
|  | ||||
| @ -48,19 +48,31 @@ void subghz_transmitter_draw(Canvas* canvas, SubghzTransmitterModel* model) { | ||||
|     canvas_set_font(canvas, FontSecondary); | ||||
|     elements_multiline_text(canvas, 0, 10, string_get_cstr(model->text)); | ||||
| 
 | ||||
|     elements_button_center(canvas, "Send"); | ||||
|     if(model->protocol && model->protocol->get_upload_protocol) { | ||||
|         elements_button_center(canvas, "Send"); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| bool subghz_transmitter_input(InputEvent* event, void* context) { | ||||
|     furi_assert(context); | ||||
|     SubghzTransmitter* subghz_transmitter = context; | ||||
| 
 | ||||
|     if(event->type != InputTypeShort) return false; | ||||
|     bool can_be_send = false; | ||||
|     with_view_model( | ||||
|         subghz_transmitter->view, (SubghzTransmitterModel * model) { | ||||
|             can_be_send = (model->protocol && model->protocol->get_upload_protocol); | ||||
|             string_clean(model->text); | ||||
|             model->protocol->to_string(model->protocol, model->text); | ||||
|             return true; | ||||
|         }); | ||||
|     //if(event->type != InputTypeShort) return false;
 | ||||
| 
 | ||||
|     if(event->key == InputKeyBack) { | ||||
|         return false; | ||||
|     } else if(event->key == InputKeyOk) { | ||||
|         subghz_transmitter->callback(SubghzTransmitterEventSend, subghz_transmitter->context); | ||||
|     } else if(can_be_send && event->key == InputKeyOk && event->type == InputTypePress) { | ||||
|         subghz_transmitter->callback(SubghzTransmitterEventSendStart, subghz_transmitter->context); | ||||
|         return true; | ||||
|     } else if(can_be_send && event->key == InputKeyOk && event->type == InputTypeRelease) { | ||||
|         subghz_transmitter->callback(SubghzTransmitterEventSendStop, subghz_transmitter->context); | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -4,7 +4,8 @@ | ||||
| #include <lib/subghz/protocols/subghz_protocol_common.h> | ||||
| 
 | ||||
| typedef enum { | ||||
|     SubghzTransmitterEventSend, | ||||
|     SubghzTransmitterEventSendStart, | ||||
|     SubghzTransmitterEventSendStop, | ||||
|     SubghzTransmitterEventBack, | ||||
| } SubghzTransmitterEvent; | ||||
| 
 | ||||
|  | ||||
| @ -6,7 +6,9 @@ | ||||
| 
 | ||||
| # Compiling | ||||
| 
 | ||||
| 	make all | ||||
| ```bash | ||||
| make all | ||||
| ``` | ||||
| 
 | ||||
| # Asset naming rules | ||||
| 
 | ||||
|  | ||||
| @ -1,13 +1,6 @@ | ||||
| #pragma once | ||||
| #include <gui/icon.h> | ||||
| 
 | ||||
| extern const Icon A_FX_Sitting_40x27; | ||||
| extern const Icon A_MDIB_32x32; | ||||
| extern const Icon A_MDI_32x32; | ||||
| extern const Icon A_MDWLB_32x32; | ||||
| extern const Icon A_MDWL_32x32; | ||||
| extern const Icon A_MDWRB_32x32; | ||||
| extern const Icon A_MDWR_32x32; | ||||
| extern const Icon A_WatchingTV_128x64; | ||||
| extern const Icon A_Wink_128x64; | ||||
| extern const Icon I_dir_10px; | ||||
| @ -24,9 +17,6 @@ extern const Icon I_ButtonLeftSmall_3x5; | ||||
| extern const Icon I_Warning_30x23; | ||||
| extern const Icon I_ButtonRight_4x7; | ||||
| extern const Icon I_ButtonCenter_7x7; | ||||
| extern const Icon I_FX_SittingB_40x27; | ||||
| extern const Icon I_BigGames_24x24; | ||||
| extern const Icon I_BigProfile_24x24; | ||||
| extern const Icon I_DolphinOkay_41x43; | ||||
| extern const Icon I_DolphinFirstStart4_67x53; | ||||
| extern const Icon I_DolphinFirstStart2_59x51; | ||||
| @ -37,22 +27,7 @@ extern const Icon I_DolphinFirstStart1_59x53; | ||||
| extern const Icon I_DolphinFirstStart8_56x51; | ||||
| extern const Icon I_DolphinFirstStart7_61x51; | ||||
| extern const Icon I_Flipper_young_80x60; | ||||
| extern const Icon I_BigBurger_24x24; | ||||
| extern const Icon I_FX_Bang_32x6; | ||||
| extern const Icon I_DolphinFirstStart3_57x48; | ||||
| extern const Icon I_blackfish_25x17; | ||||
| extern const Icon I_blacklid_36x27; | ||||
| extern const Icon I_skeleton_25x17; | ||||
| extern const Icon I_letterB_10x10; | ||||
| extern const Icon I_shit_25x17; | ||||
| extern const Icon I_letterC_10x10; | ||||
| extern const Icon I_active_plate_48x18; | ||||
| extern const Icon I_fish_25x17; | ||||
| extern const Icon I_blackshit_25x17; | ||||
| extern const Icon I_lid_36x27; | ||||
| extern const Icon I_blackskeleton_25x17; | ||||
| extern const Icon I_letterA_10x10; | ||||
| extern const Icon I_plate_42x19; | ||||
| extern const Icon I_PassportBottom_128x17; | ||||
| extern const Icon I_DoorLeft_8x56; | ||||
| extern const Icon I_DoorLocked_10x56; | ||||
| @ -102,15 +77,6 @@ extern const Icon A_U2F_14; | ||||
| extern const Icon A_iButton_14; | ||||
| extern const Icon I_Medium_chip_22x21; | ||||
| extern const Icon I_EMV_Chip_14x11; | ||||
| extern const Icon I_passport_happy1_43x45; | ||||
| extern const Icon I_passport_bad3_43x45; | ||||
| extern const Icon I_passport_okay2_43x45; | ||||
| extern const Icon I_passport_bad2_43x45; | ||||
| extern const Icon I_passport_okay3_43x45; | ||||
| extern const Icon I_passport_bad1_43x45; | ||||
| extern const Icon I_passport_happy3_43x45; | ||||
| extern const Icon I_passport_happy2_43x45; | ||||
| extern const Icon I_passport_okay1_43x45; | ||||
| extern const Icon I_Health_16x16; | ||||
| extern const Icon I_FaceCharging_29x14; | ||||
| extern const Icon I_BatteryBody_52x28; | ||||
| @ -126,99 +92,6 @@ extern const Icon I_RFIDDolphinSend_97x61; | ||||
| extern const Icon I_RFIDDolphinReceive_97x61; | ||||
| extern const Icon I_SDQuestion_35x43; | ||||
| extern const Icon I_SDError_43x35; | ||||
| extern const Icon I_Console_74x67_4; | ||||
| extern const Icon I_Console_74x67_5; | ||||
| extern const Icon I_Console_74x67_7; | ||||
| extern const Icon I_Console_74x67_6; | ||||
| extern const Icon I_Console_74x67_2; | ||||
| extern const Icon I_Console_74x67_3; | ||||
| extern const Icon I_Console_74x67_1; | ||||
| extern const Icon I_Console_74x67_0; | ||||
| extern const Icon I_Console_74x67_8; | ||||
| extern const Icon I_food8_61x98; | ||||
| extern const Icon I_food5_61x98; | ||||
| extern const Icon I_food3_61x98; | ||||
| extern const Icon I_food9_61x98; | ||||
| extern const Icon I_food12_61x98; | ||||
| extern const Icon I_food4_61x98; | ||||
| extern const Icon I_food2_61x98; | ||||
| extern const Icon I_food7_61x98; | ||||
| extern const Icon I_food11_61x98; | ||||
| extern const Icon I_food1_61x98; | ||||
| extern const Icon I_food6_61x98; | ||||
| extern const Icon I_food10_61x98; | ||||
| extern const Icon I_rightdown2_73x61; | ||||
| extern const Icon I_black_upright2_73x61; | ||||
| extern const Icon I_black_leftup1_73x61; | ||||
| extern const Icon I_black_upleft1_73x61; | ||||
| extern const Icon I_black_down2_73x61; | ||||
| extern const Icon I_downleft3_73x61; | ||||
| extern const Icon I_down2_73x61; | ||||
| extern const Icon I_black_downright2_73x61; | ||||
| extern const Icon I_black_downleft2_73x61; | ||||
| extern const Icon I_up2_73x61; | ||||
| extern const Icon I_right1_73x61; | ||||
| extern const Icon I_black_up1_73x61; | ||||
| extern const Icon I_upright1_73x61; | ||||
| extern const Icon I_black_rightleft2_73x61; | ||||
| extern const Icon I_black_right3_73x61; | ||||
| extern const Icon I_upleft2_73x61; | ||||
| extern const Icon I_black_downup3_73x61; | ||||
| extern const Icon I_black_updown3_73x61; | ||||
| extern const Icon I_leftup2_73x61; | ||||
| extern const Icon I_leftdown2_73x61; | ||||
| extern const Icon I_downup1_73x61; | ||||
| extern const Icon I_updown1_73x61; | ||||
| extern const Icon I_rightup1_73x61; | ||||
| extern const Icon I_black_rightdown1_73x61; | ||||
| extern const Icon I_downleft2_73x61; | ||||
| extern const Icon I_downright1_73x61; | ||||
| extern const Icon I_black_downright3_73x61; | ||||
| extern const Icon I_black_downleft3_73x61; | ||||
| extern const Icon I_rightleft1_73x61; | ||||
| extern const Icon I_black_right2_73x61; | ||||
| extern const Icon I_black_rightup2_73x61; | ||||
| extern const Icon I_black_downup2_73x61; | ||||
| extern const Icon I_black_updown2_73x61; | ||||
| extern const Icon I_black_left1_73x61; | ||||
| extern const Icon I_black_leftdown2_73x61; | ||||
| extern const Icon I_left1_73x61; | ||||
| extern const Icon I_rightup2_73x61; | ||||
| extern const Icon I_black_rightdown2_73x61; | ||||
| extern const Icon I_downup2_73x61; | ||||
| extern const Icon I_updown2_73x61; | ||||
| extern const Icon I_right3_73x61; | ||||
| extern const Icon I_downright2_73x61; | ||||
| extern const Icon I_downleft1_73x61; | ||||
| extern const Icon I_black_rightup1_73x61; | ||||
| extern const Icon I_black_right1_73x61; | ||||
| extern const Icon I_rightleft2_73x61; | ||||
| extern const Icon I_left2_73x61; | ||||
| extern const Icon I_black_left2_73x61; | ||||
| extern const Icon I_black_downup1_73x61; | ||||
| extern const Icon I_black_updown1_73x61; | ||||
| extern const Icon I_black_leftdown1_73x61; | ||||
| extern const Icon I_downup3_73x61; | ||||
| extern const Icon I_updown3_73x61; | ||||
| extern const Icon I_black_leftup2_73x61; | ||||
| extern const Icon I_black_upright1_73x61; | ||||
| extern const Icon I_rightdown1_73x61; | ||||
| extern const Icon I_right2_73x61; | ||||
| extern const Icon I_black_downleft1_73x61; | ||||
| extern const Icon I_down1_73x61; | ||||
| extern const Icon I_black_downright1_73x61; | ||||
| extern const Icon I_up1_73x61; | ||||
| extern const Icon I_downright3_73x61; | ||||
| extern const Icon I_black_down1_73x61; | ||||
| extern const Icon I_black_upleft2_73x61; | ||||
| extern const Icon I_upleft1_73x61; | ||||
| extern const Icon I_black_rightleft1_73x61; | ||||
| extern const Icon I_black_up2_73x61; | ||||
| extern const Icon I_upright2_73x61; | ||||
| extern const Icon I_leftdown1_73x61; | ||||
| extern const Icon I_left3_73x61; | ||||
| extern const Icon I_leftup1_73x61; | ||||
| extern const Icon I_black_left3_73x61; | ||||
| extern const Icon I_BadUsb_9x8; | ||||
| extern const Icon I_PlaceholderR_30x13; | ||||
| extern const Icon I_Background_128x8; | ||||
|  | ||||
| Before Width: | Height: | Size: 369 B | 
| Before Width: | Height: | Size: 368 B | 
| @ -1 +0,0 @@ | ||||
| 10 | ||||
| Before Width: | Height: | Size: 359 B | 
| Before Width: | Height: | Size: 350 B | 
| Before Width: | Height: | Size: 350 B | 
| Before Width: | Height: | Size: 356 B | 
| @ -1 +0,0 @@ | ||||
| 10 | ||||
| Before Width: | Height: | Size: 382 B | 
| Before Width: | Height: | Size: 383 B | 
| Before Width: | Height: | Size: 383 B | 
| Before Width: | Height: | Size: 381 B | 
| @ -1 +0,0 @@ | ||||
| 10 | ||||
| Before Width: | Height: | Size: 356 B | 
| Before Width: | Height: | Size: 365 B | 
| Before Width: | Height: | Size: 363 B | 
| @ -1 +0,0 @@ | ||||
| 10 | ||||
| Before Width: | Height: | Size: 384 B | 
| Before Width: | Height: | Size: 390 B | 
| Before Width: | Height: | Size: 382 B | 
| @ -1 +0,0 @@ | ||||
| 10 | ||||
| Before Width: | Height: | Size: 357 B | 
| Before Width: | Height: | Size: 363 B | 
| Before Width: | Height: | Size: 366 B | 
| @ -1 +0,0 @@ | ||||
| 10 | ||||
| Before Width: | Height: | Size: 380 B | 
| Before Width: | Height: | Size: 389 B | 
| Before Width: | Height: | Size: 383 B | 
| @ -1 +0,0 @@ | ||||
| 10 | ||||
| Before Width: | Height: | Size: 356 B | 
 Aleksandr Kutuzov
						Aleksandr Kutuzov