瀏覽代碼

Add malveke_gb_live_camera from https://github.com/EstebanFuentealba/MALVEKE-Flipper-Zero

git-subtree-dir: malveke_gb_live_camera
git-subtree-mainline: 29b23546ef05dcc4c35f067d75fe4db8d5df40fd
git-subtree-split: a8004cf68f5c467eb2ebe3c3b59f410ae8a331ba
Willy-JL 1 年之前
父節點
當前提交
b0451b137c

+ 191 - 0
malveke_gb_live_camera/.clang-format

@@ -0,0 +1,191 @@
+---
+Language:        Cpp
+AccessModifierOffset: -4
+AlignAfterOpenBracket: AlwaysBreak
+AlignArrayOfStructures: None
+AlignConsecutiveMacros: None
+AlignConsecutiveAssignments: None
+AlignConsecutiveBitFields: None
+AlignConsecutiveDeclarations: None
+AlignEscapedNewlines: Left
+AlignOperands:   Align
+AlignTrailingComments: false
+AllowAllArgumentsOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortEnumsOnASingleLine: true
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortLambdasOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: WithoutElse
+AllowShortLoopsOnASingleLine: true
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: Yes
+AttributeMacros:
+  - __capability
+BinPackArguments: false
+BinPackParameters: false
+BraceWrapping:
+  AfterCaseLabel:  false
+  AfterClass:      false
+  AfterControlStatement: Never
+  AfterEnum:       false
+  AfterFunction:   false
+  AfterNamespace:  false
+  AfterObjCDeclaration: false
+  AfterStruct:     false
+  AfterUnion:      false
+  AfterExternBlock: false
+  BeforeCatch:     false
+  BeforeElse:      false
+  BeforeLambdaBody: false
+  BeforeWhile:     false
+  IndentBraces:    false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeConceptDeclarations: true
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit:     99
+CommentPragmas:  '^ IWYU pragma:'
+QualifierAlignment: Leave
+CompactNamespaces: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DeriveLineEnding: true
+DerivePointerAlignment: false
+DisableFormat:   false
+EmptyLineAfterAccessModifier: Never
+EmptyLineBeforeAccessModifier: LogicalBlock
+ExperimentalAutoDetectBinPacking: false
+PackConstructorInitializers: BinPack
+BasedOnStyle:    ''
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+AllowAllConstructorInitializersOnNextLine: true
+FixNamespaceComments: false
+ForEachMacros:
+  - foreach
+  - Q_FOREACH
+  - BOOST_FOREACH
+IfMacros:
+  - KJ_IF_MAYBE
+IncludeBlocks:   Preserve
+IncludeCategories:
+  - Regex:           '.*'
+    Priority:        1
+    SortPriority:    0
+    CaseSensitive:   false
+  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
+    Priority:        3
+    SortPriority:    0
+    CaseSensitive:   false
+  - Regex:           '.*'
+    Priority:        1
+    SortPriority:    0
+    CaseSensitive:   false
+IncludeIsMainRegex: '(Test)?$'
+IncludeIsMainSourceRegex: ''
+IndentAccessModifiers: false
+IndentCaseLabels: false
+IndentCaseBlocks: false
+IndentGotoLabels: true
+IndentPPDirectives: None
+IndentExternBlock: AfterExternBlock
+IndentRequires:  false
+IndentWidth:     4
+IndentWrappedFunctionNames: true
+InsertTrailingCommas: None
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+LambdaBodyIndentation: Signature
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 4
+ObjCBreakBeforeNestedBlockParam: true
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakOpenParenthesis: 0
+PenaltyBreakString: 10
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+PenaltyIndentedWhitespace: 0
+PointerAlignment: Left
+PPIndentWidth:   -1
+ReferenceAlignment: Pointer
+ReflowComments:  false
+RemoveBracesLLVM: false
+SeparateDefinitionBlocks: Leave
+ShortNamespaceLines: 1
+SortIncludes:    Never
+SortJavaStaticImport: Before
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCaseColon: false
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: Never
+SpaceBeforeParensOptions:
+  AfterControlStatements: false
+  AfterForeachMacros: false
+  AfterFunctionDefinitionName: false
+  AfterFunctionDeclarationName: false
+  AfterIfMacros:   false
+  AfterOverloadedOperator: false
+  BeforeNonEmptyParentheses: false
+SpaceAroundPointerQualifiers: Default
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  Never
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInLineCommentPrefix:
+  Minimum:         1
+  Maximum:         -1
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpaceBeforeSquareBrackets: false
+BitFieldColonSpacing: Both
+Standard:        c++03
+StatementAttributeLikeMacros:
+  - Q_EMIT
+StatementMacros:
+  - Q_UNUSED
+  - QT_REQUIRE_VERSION
+TabWidth:        4
+UseCRLF:         false
+UseTab:          Never
+WhitespaceSensitiveMacros:
+  - STRINGIZE
+  - PP_STRINGIZE
+  - BOOST_PP_STRINGIZE
+  - NS_SWIFT_NAME
+  - CF_SWIFT_NAME
+...
+

+ 0 - 0
malveke_gb_live_camera/.flipcorg/.gitkeep


二進制
malveke_gb_live_camera/.flipcorg/banner.png


+ 0 - 0
malveke_gb_live_camera/.flipcorg/gallery/.gitkeep


二進制
malveke_gb_live_camera/.flipcorg/gallery/1.png


二進制
malveke_gb_live_camera/.flipcorg/gallery/2.png


二進制
malveke_gb_live_camera/.flipcorg/gallery/3.png


+ 1 - 0
malveke_gb_live_camera/.gitsubtree

@@ -0,0 +1 @@
+https://github.com/EstebanFuentealba/MALVEKE-Flipper-Zero main flipper_companion_apps/applications/external/malveke_gb_live_camera

+ 21 - 0
malveke_gb_live_camera/LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 Esteban Fuentealba
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 95 - 0
malveke_gb_live_camera/README.md

@@ -0,0 +1,95 @@
+# ***GAME BOY*** Live Camera MALVEKE
+
+<figure>
+    <img src="./docs/images/proto.png" />
+    <figcaption>MALVEKE Prototype V2.3</figcaption>
+</figure>
+
+<div align="center">
+
+https://github.com/EstebanFuentealba/MALVEKE-Flipper-Zero/assets/442927/8c11cb8a-2a05-47e2-a0e0-1d3a1fe386ea
+
+</div>
+
+## Introduction
+
+<div align="center">
+
+**Official** | **Unleashed** | **RogueMaster** | **Xtreme**
+:- | :- | :- | :- 
+[![FlipC.org](https://flipc.org/EstebanFuentealba/MALVEKE-Flipper-Zero/badge?branch=main&root=flipper_companion_apps%2Fapplications%2Fexternal%2Fmalveke_gb_live_camera&firmware=official)](https://flipc.org/EstebanFuentealba/MALVEKE-Flipper-Zero?branch=main&root=flipper_companion_apps%2Fapplications%2Fexternal%2Fmalveke_gb_live_camera&firmware=official)|[![FlipC.org](https://flipc.org/EstebanFuentealba/MALVEKE-Flipper-Zero/badge?branch=main&root=flipper_companion_apps%2Fapplications%2Fexternal%2Fmalveke_gb_live_camera&firmware=unleashed)](https://flipc.org/EstebanFuentealba/MALVEKE-Flipper-Zero?branch=main&root=flipper_companion_apps%2Fapplications%2Fexternal%2Fmalveke_gb_live_camera&firmware=unleashed)|[![FlipC.org](https://flipc.org/EstebanFuentealba/MALVEKE-Flipper-Zero/badge?branch=main&root=flipper_companion_apps%2Fapplications%2Fexternal%2Fmalveke_gb_live_camera&firmware=roguemaster)](https://flipc.org/EstebanFuentealba/MALVEKE-Flipper-Zero?branch=main&root=flipper_companion_apps%2Fapplications%2Fexternal%2Fmalveke_gb_live_camera&firmware=roguemaster)|[![FlipC.org](https://flipc.org/EstebanFuentealba/MALVEKE-Flipper-Zero/badge?branch=main&root=flipper_companion_apps%2Fapplications%2Fexternal%2Fmalveke_gb_live_camera&firmware=xtreme)](https://flipc.org/EstebanFuentealba/MALVEKE-Flipper-Zero?branch=main&root=flipper_companion_apps%2Fapplications%2Fexternal%2Fmalveke_gb_live_camera&firmware=xtreme)
+</div>
+
+<p align='center'>
+<a href="https://www.tindie.com/stores/efuentealba/?ref=offsite_badges&utm_source=sellers_efuentealba&utm_medium=badges&utm_campaign=badge_large"><img src="https://d2ss6ovg47m0r5.cloudfront.net/badges/tindie-larges.png" alt="I sell on Tindie" width="200" height="104"></a>
+</p>
+
+## Installation Directions
+
+This project is intended to be overlayed on top of an existing firmware repo,  in my case the **Release 0.79.1** version.
+
+- Clone the [Flipper Zero firmware repository](https://github.com/flipperdevices/flipperzero-firmware). Refer to [this tutorial](https://github.com/jamisonderek/flipper-zero-tutorials/tree/main/firmware/updating/README.md) for updating the firmware.
+- Copy the "malveke_gb_live_camera" folder into the `/applications_user/malveke_gb_live_camera` folder in your firmware.
+- Run the command `ufbt launch` to run it on your Flipper Zero.
+
+```
+./ufbt launch
+```
+
+- NOTE: If you only want to generate the fap file, you must run the following command.
+
+```bash
+./ufbt 
+```
+
+And use [**qFlipper**](https://flipperzero.one/update) to copy the generated **malveke_gb_live_camera.fap** file to the `SD Card/apps/GPIO` folder.
+
+<p align='center'>
+<img src="./docs/images/qFlipper.png" width="400" /><br />
+</p>
+
+## Instructions for use.
+
+These instructions assume that you are starting at the Flipper Zero desktop. Otherwise, press the Back button until you are at the desktop.
+
+- Press the `OK` button on the Flipper to open the main menu.
+- Choose `Applications` from the menu.
+- Choose `GPIO` from the submenu.
+- Choose `GAME BOY Live Camera MALVEKE`
+- The Flipper Zero will show the loading screen of the application. 
+
+    <p align='center'>
+        <br />
+        <img src="./docs/images/flipper-zero-flat-1.png" width="400" />
+        <br />
+    </p>
+
+- If the **MALVEKE** board and the **GAME BOY Camera** cartridge are connected, an image will be displayed.
+
+    <p align='center'>
+        <br />
+        <img src="./docs/images/flipper-zero-flat-2.gif" width="400" />
+        <br />
+    </p>
+
+- Press the `LEFT`/`RIGHT` buttons to change the exposure value.
+- Press the `OK` button to take a picture. The image will be saved in the `SD Card/apps_data/malveke/photos` folder. 
+
+
+
+
+## TODO
+- [ ] Add automatic exposure calculation.
+- [ ] Refactor Code
+
+## Acknowledgements
+- [**@AntonioND**](https://github.com/AntonioND/) for his documentation on [reverse engineering the Game Boy Camera](https://github.com/AntonioND/gbcam-rev-engineer/) and for his assistance in understanding some aspects.
+- [**@eried**](https://github.com/eried) for his implementation of [ESP32-Camera](https://github.com/eried/flipperzero-mayhem/tree/next/flipper_companion_apps/applications/external/esp32cam_camera) (This is based on it.)
+- [**@furrtek**](https://github.com/furrtek/) for his projects [GBCameraProjects](https://github.com/furrtek/GBCameraProjects)
+
+
+<p align='center'>
+<br />
+<br />
+From Talcahuano 🇨🇱 with ❤ 
+</p>

+ 21 - 0
malveke_gb_live_camera/README_catalog.md

@@ -0,0 +1,21 @@
+# MALVEKE **GAME BOY** Live Camera 
+
+## Introduction
+MALVEKE app, By inserting a GAME BOY Camera cartridge, you can use it as a camera and take snapshots from the Flipper Zero.
+
+## Instructions for use.
+
+These instructions assume that you are starting at the Flipper Zero desktop. Otherwise, press the Back button until you are at the desktop.
+
+- Press the **OK** button on the Flipper to open the main menu.
+- Choose **Applications** from the menu.
+- Choose **GPIO** from the submenu.
+- Choose **MALVEKE GB Live Camera**
+- The Flipper Zero will show the loading screen of the application. 
+- If the **MALVEKE** board and the **GAME BOY Camera** cartridge are connected, an image will be displayed.
+- Press the **LEFT**/**RIGHT** buttons to change the exposure value.
+- Press the **OK** button to take a picture. The image will be saved in the **SD Card/apps_data/malveke/photos** folder. 
+
+## TODO
+- Add automatic exposure calculation.
+- Refactor Code

+ 18 - 0
malveke_gb_live_camera/application.fam

@@ -0,0 +1,18 @@
+App(
+    appid="malveke_gb_live_camera",
+    name="GAME BOY Live Camera MALVEKE",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="gb_live_camera_app",
+    cdefines=["APP_CAMERA"],
+    requires=["gui"],
+    stack_size=8*1024,
+    order=1,
+    fap_version=[2,1],
+    fap_libs=["assets"],
+	fap_icon="icons/icon.png",
+    fap_icon_assets="icons",
+    fap_category="GPIO",
+	fap_description="Insert a GAME BOY Camera cartridge, you can use it as a camera and take snapshots from the Flipper Zero.",
+	fap_author="Esteban Fuentealba",
+	fap_weburl="https://github.com/EstebanFuentealba/MALVEKE-Flipper-Zero/"
+)

+ 19 - 0
malveke_gb_live_camera/docs/changelog.md

@@ -0,0 +1,19 @@
+# Changelog - Patch Notes
+
+## Version 2.1
+Fix FuriHalRtc: new datetime lib.
+
+## Version 2.0
+Implement new serial API with new module expansion protocol.
+
+## Version 1.0.0
+The initial version of the application encompasses functionalities to inserting a GAME BOY Camera cartridge, you can use it as a camera and take snapshots from the Flipper Zero.
+
+## Version 1.1
+Fix: backlight Flipper Zero refresh
+
+## Version 1.2
+Fix: Image capture with inverted colors has been resolved.
+
+## Version 1.3
+To improve the visibility of the application names, the names were changed by adding a 'MALVEKE' postfix.

二進制
malveke_gb_live_camera/docs/images/flipper-zero-flat-1.png


二進制
malveke_gb_live_camera/docs/images/flipper-zero-flat-2.gif


二進制
malveke_gb_live_camera/docs/images/proto.png


二進制
malveke_gb_live_camera/docs/images/qFlipper.png


二進制
malveke_gb_live_camera/docs/psd/gb_live_camera.psd


+ 377 - 0
malveke_gb_live_camera/gb_live_camera.c

@@ -0,0 +1,377 @@
+#include "gb_live_camera.h"
+#include <malveke_gb_live_camera_icons.h>
+
+static void gb_live_camera_view_draw_callback(Canvas* canvas, void* _model) {
+    UartDumpModel* model = _model;
+
+    // Prepare canvas
+    canvas_set_color(canvas, ColorBlack);
+    canvas_draw_frame(canvas, 0, 0, FRAME_WIDTH, FRAME_HEIGTH);
+
+    if(!model->initialized) {
+        canvas_set_font(canvas, FontPrimary);
+        canvas_draw_str(canvas, 8, 28, "GAME BOY");
+        canvas_draw_icon(canvas, 76, 8, &I_gbcam_48x49);
+        canvas_set_font(canvas, FontSecondary);
+        canvas_draw_str(canvas, 8, 18, "WAITING");
+        canvas_set_font(canvas, FontPrimary);
+        canvas_draw_str(canvas, 8, 38, "CAMERA...");
+        canvas_set_font(canvas, FontSecondary);
+        canvas_draw_str(canvas, 9, 47, "Insert Cartridge");
+        elements_button_center(canvas, "Ok");
+    } else {
+        for(size_t p = 0; p < FRAME_BUFFER_LENGTH; ++p) {
+            uint8_t x = p % ROW_BUFFER_LENGTH; // 0 .. 15
+            uint8_t y = p / ROW_BUFFER_LENGTH; // 0 .. 63
+
+            for(uint8_t i = 0; i < 8; ++i) {
+                if((model->pixels[p] & (1 << (7 - i))) == 0) {
+                    canvas_draw_dot(canvas, (x * 8) + i, y);
+                }
+            }
+        }
+    }
+}
+
+void get_timefilename(FuriString* name) {
+    DateTime datetime = {0};
+    furi_hal_rtc_get_datetime(&datetime);
+    furi_string_printf(
+        name,
+        "%s/%.4d%.2d%.2d-%.2d%.2d%.2d.bmp",
+        MALVEKE_APP_FOLDER_PHOTOS,
+        datetime.year,
+        datetime.month,
+        datetime.day,
+        datetime.hour,
+        datetime.minute,
+        datetime.second);
+}
+
+static void save_image(void* context) {
+    UartEchoApp* app = context;
+    furi_assert(app);
+
+    NotificationApp* notifications = furi_record_open(RECORD_NOTIFICATION);
+
+    // We need a storage struct (gain accesso to the filesystem API )
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+
+    // storage_file_alloc gives to us a File pointer using the Storage API.
+    File* file = storage_file_alloc(storage);
+
+    // if(storage_common_stat(storage, IMAGE_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {
+    //     storage_simply_mkdir(storage, IMAGE_FILE_DIRECTORY_PATH);
+    // }
+    //  Create MALVEKE dir
+    if(storage_common_stat(storage, MALVEKE_APP_FOLDER, NULL) == FSE_NOT_EXIST) {
+        storage_simply_mkdir(storage, MALVEKE_APP_FOLDER);
+    }
+    //  Create MALVEKE Photos dir
+    if(storage_common_stat(storage, MALVEKE_APP_FOLDER_PHOTOS, NULL) == FSE_NOT_EXIST) {
+        storage_simply_mkdir(storage, MALVEKE_APP_FOLDER_PHOTOS);
+    }
+
+    // create file name
+    FuriString* file_name = furi_string_alloc();
+    get_timefilename(file_name);
+
+    // this functions open a file, using write access and creates new file if not exist.
+    bool result =
+        storage_file_open(file, furi_string_get_cstr(file_name), FSAM_WRITE, FSOM_OPEN_ALWAYS);
+    //bool result = storage_file_open(file, EXT_PATH("DCIM/test.bmp"), FSAM_WRITE, FSOM_OPEN_ALWAYS);
+    furi_string_free(file_name);
+
+    if(result) {
+        storage_file_write(file, bitmap_header, BITMAP_HEADER_LENGTH);
+        with_view_model(
+            app->view,
+            UartDumpModel * model,
+            {
+                int8_t row_buffer[ROW_BUFFER_LENGTH];
+                for(size_t i = 64; i > 0; --i) {
+                    for(size_t j = 0; j < ROW_BUFFER_LENGTH; ++j) {
+                        row_buffer[j] = model->pixels[((i - 1) * ROW_BUFFER_LENGTH) + j];
+                    }
+                    storage_file_write(file, row_buffer, ROW_BUFFER_LENGTH);
+                }
+            },
+            false);
+    }
+
+    // Closing the "file descriptor"
+    storage_file_close(file);
+
+    // Freeing up memory
+    storage_file_free(file);
+
+    notification_message(notifications, result ? &sequence_success : &sequence_error);
+}
+
+static bool gb_live_camera_view_input_callback(InputEvent* event, void* context) {
+    UartEchoApp* instance = context;
+    if(event->type == InputTypePress) {
+        if(event->key == InputKeyUp) {
+            const char gblivecamera_command_enable_dithering[] = "gblivecamera -D\n";
+            furi_hal_serial_tx(
+                instance->serial_handle_uart,
+                (uint8_t*)gblivecamera_command_enable_dithering,
+                strlen(gblivecamera_command_enable_dithering));
+        } else if(event->key == InputKeyDown) {
+            const char gblivecamera_command_disable_dithering[] = "gblivecamera -d\n";
+            furi_hal_serial_tx(
+                instance->serial_handle_uart,
+                (uint8_t*)gblivecamera_command_disable_dithering,
+                strlen(gblivecamera_command_disable_dithering));
+        } else if(event->key == InputKeyRight) {
+            const char gblivecamera_command_increase_exposure[] = "gblivecamera -E\n";
+            furi_hal_serial_tx(
+                instance->serial_handle_uart,
+                (uint8_t*)gblivecamera_command_increase_exposure,
+                strlen(gblivecamera_command_increase_exposure));
+
+        } else if(event->key == InputKeyLeft) {
+            const char gblivecamera_command_decrease_exposure[] = "gblivecamera -e\n";
+            furi_hal_serial_tx(
+                instance->serial_handle_uart,
+                (uint8_t*)gblivecamera_command_decrease_exposure,
+                strlen(gblivecamera_command_decrease_exposure));
+        } else if(event->key == InputKeyOk) {
+            with_view_model(
+                instance->view,
+                UartDumpModel * model,
+                {
+                    if(!model->initialized) {
+                        // model->initialized = true; // We've successfully established the connection
+                        const char gblivecamera_command[] = "gblivecamera\n\n";
+                        furi_hal_serial_tx(
+                            instance->serial_handle_uart,
+                            (uint8_t*)gblivecamera_command,
+                            strlen(gblivecamera_command));
+
+                    } else {
+                        save_image(context);
+                    }
+                },
+                true);
+        }
+    }
+    return false;
+}
+
+static uint32_t gb_live_camera_exit(void* context) {
+    UartEchoApp* app = context;
+    const char stop_command[] = "stopgblivecamera\n";
+    // furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)stop_command, strlen(stop_command));
+    furi_hal_serial_tx(app->serial_handle_uart, (uint8_t*)stop_command, strlen(stop_command));
+    return VIEW_NONE;
+}
+
+static void gb_live_camera_on_irq_cb(
+    FuriHalSerialHandle* handle,
+    FuriHalSerialRxEvent event,
+    void* context) {
+    furi_assert(context);
+    UartEchoApp* app = context;
+
+    if(event == FuriHalSerialRxEventData) {
+        uint8_t data = furi_hal_serial_async_rx(handle);
+        furi_stream_buffer_send(app->rx_stream, &data, 1, 0);
+        furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventRx);
+    }
+}
+
+static void process_ringbuffer(UartDumpModel* model, uint8_t byte) {
+    //// 1. Phase: filling the ringbuffer
+    if(model->ringbuffer_index == 0 && byte != 'Y') { // First char has to be 'Y' in the buffer.
+        return;
+    }
+
+    if(model->ringbuffer_index == 1 &&
+       byte != ':') { // Second char has to be ':' in the buffer or reset.
+        model->ringbuffer_index = 0;
+        process_ringbuffer(model, byte);
+        return;
+    }
+
+    model->row_ringbuffer[model->ringbuffer_index] =
+        byte; // Assign current byte to the ringbuffer;
+    ++model->ringbuffer_index; // Increment the ringbuffer index
+
+    if(model->ringbuffer_index < RING_BUFFER_LENGTH) { // Let's wait 'till the buffer fills.
+        return;
+    }
+
+    //// 2. Phase: flushing the ringbuffer to the framebuffer
+    model->ringbuffer_index = 0; // Let's reset the ringbuffer
+    model->initialized = true; // We've successfully established the connection
+    size_t row_start_index =
+        model->row_ringbuffer[2] * ROW_BUFFER_LENGTH; // Third char will determine the row number
+
+    if(row_start_index > LAST_ROW_INDEX) { // Failsafe
+        row_start_index = 0;
+    }
+
+    for(size_t i = 0; i < ROW_BUFFER_LENGTH; ++i) {
+        model->pixels[row_start_index + i] =
+            model->row_ringbuffer[i + 3]; // Writing the remaining 16 bytes into the frame buffer
+    }
+}
+
+static int32_t gb_live_camera_worker(void* context) {
+    furi_assert(context);
+    UartEchoApp* app = context;
+
+    while(1) {
+        uint32_t events =
+            furi_thread_flags_wait(WORKER_EVENTS_MASK, FuriFlagWaitAny, FuriWaitForever);
+        furi_check((events & FuriFlagError) == 0);
+
+        if(events & WorkerEventStop) break;
+        if(events & WorkerEventRx) {
+            size_t length = 0;
+            do {
+                size_t intended_data_size = 64;
+                uint8_t data[intended_data_size];
+                length = furi_stream_buffer_receive(app->rx_stream, data, intended_data_size, 0);
+
+                if(length > 0) {
+                    with_view_model(
+                        app->view,
+                        UartDumpModel * model,
+                        {
+                            for(size_t i = 0; i < length; i++) {
+                                process_ringbuffer(model, data[i]);
+                            }
+                        },
+                        false);
+                }
+            } while(length > 0);
+
+            notification_message(app->notification, &sequence_notification);
+            with_view_model(
+                app->view, UartDumpModel * model, { UNUSED(model); }, true);
+        }
+    }
+
+    return 0;
+}
+
+static UartEchoApp* gb_live_camera_app_alloc() {
+    UartEchoApp* app = malloc(sizeof(UartEchoApp));
+
+    app->rx_stream = furi_stream_buffer_alloc(2048, 1);
+
+    // Gui
+    app->gui = furi_record_open(RECORD_GUI);
+    app->notification = furi_record_open(RECORD_NOTIFICATION);
+
+    // View dispatcher
+    app->view_dispatcher = view_dispatcher_alloc();
+    view_dispatcher_enable_queue(app->view_dispatcher);
+    view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
+
+    //  Turn backlight on
+    notification_message(app->notification, &sequence_display_backlight_enforce_on);
+
+    // Views
+    app->view = view_alloc();
+    view_set_context(app->view, app);
+    view_set_draw_callback(app->view, gb_live_camera_view_draw_callback);
+    view_set_input_callback(app->view, gb_live_camera_view_input_callback);
+    view_allocate_model(app->view, ViewModelTypeLocking, sizeof(UartDumpModel));
+
+    with_view_model(
+        app->view,
+        UartDumpModel * model,
+        {
+            for(size_t i = 0; i < FRAME_BUFFER_LENGTH; i++) {
+                model->pixels[i] = 0;
+            }
+        },
+        true);
+
+    view_set_previous_callback(app->view, gb_live_camera_exit);
+    view_dispatcher_add_view(app->view_dispatcher, 0, app->view);
+    view_dispatcher_switch_to_view(app->view_dispatcher, 0);
+
+    app->worker_thread = furi_thread_alloc_ex("UsbUartWorker", 2048, gb_live_camera_worker, app);
+    furi_thread_start(app->worker_thread);
+
+    // Enable uart listener (UART & UART1)
+    app->serial_handle_uart = furi_hal_serial_control_acquire(FuriHalSerialIdUsart);
+    if(!app->serial_handle_uart) {
+        furi_delay_ms(5000);
+    }
+    furi_check(app->serial_handle_uart);
+    furi_hal_serial_init(app->serial_handle_uart, BAUDRATE);
+
+    app->serial_handle_lp_uart = furi_hal_serial_control_acquire(FuriHalSerialIdLpuart);
+    if(!app->serial_handle_lp_uart) {
+        furi_delay_ms(5000);
+    }
+    furi_check(app->serial_handle_lp_uart);
+    furi_hal_serial_init(app->serial_handle_lp_uart, BAUDRATE);
+    furi_hal_serial_async_rx_start(
+        app->serial_handle_lp_uart, gb_live_camera_on_irq_cb, app, false);
+
+    // furi_hal_console_disable();
+    // furi_hal_uart_set_br(FuriHalUartIdUSART1, 115200);
+    // furi_hal_uart_init(FuriHalUartIdLPUART1, 115200);
+    // furi_hal_uart_set_br(FuriHalUartIdLPUART1, 115200);
+    // furi_hal_uart_set_irq_cb(FuriHalUartIdLPUART1, gb_live_camera_on_irq_cb, app);
+    // furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, gb_live_camera_on_irq_cb, app);
+    furi_hal_power_enable_otg();
+    furi_delay_ms(1);
+    return app;
+}
+
+static void gb_live_camera_app_free(UartEchoApp* app) {
+    furi_assert(app);
+
+    furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventStop);
+    furi_thread_join(app->worker_thread);
+    furi_thread_free(app->worker_thread);
+
+    furi_hal_serial_deinit(app->serial_handle_uart);
+    furi_hal_serial_control_release(app->serial_handle_uart);
+
+    furi_hal_serial_deinit(app->serial_handle_lp_uart);
+    furi_hal_serial_control_release(app->serial_handle_lp_uart);
+
+    notification_message(app->notification, &sequence_display_backlight_enforce_auto);
+    // Free views
+    view_dispatcher_remove_view(app->view_dispatcher, 0);
+
+    view_free(app->view);
+    view_dispatcher_free(app->view_dispatcher);
+
+    // Close gui record
+    furi_record_close(RECORD_GUI);
+    furi_record_close(RECORD_NOTIFICATION);
+    app->gui = NULL;
+
+    furi_stream_buffer_free(app->rx_stream);
+
+    // Free rest
+    free(app);
+}
+
+int32_t gb_live_camera_app(void* p) {
+    UNUSED(p);
+    // Disable expansion protocol to avoid interference with UART Handle
+    Expansion* expansion = furi_record_open(RECORD_EXPANSION);
+    expansion_disable(expansion);
+
+    UartEchoApp* app = gb_live_camera_app_alloc();
+    view_dispatcher_run(app->view_dispatcher);
+    gb_live_camera_app_free(app);
+
+    furi_hal_power_disable_otg();
+
+    // Return previous state of expansion
+    expansion_enable(expansion);
+    furi_record_close(RECORD_EXPANSION);
+
+    return 0;
+}

+ 114 - 0
malveke_gb_live_camera/gb_live_camera.h

@@ -0,0 +1,114 @@
+// TODO
+// (DONE) Fix performance when not being charged
+// (DONE) Add UART command parsing to Esp32
+// (DONE) Prepare application and icon on github
+// (DONE) Write snapshots to SD card
+// 5. Set a constant refresh rate to the Flipper's display
+// 6. Emulate grayscale
+// 7. Photo browser app
+
+#include <furi.h>
+#include <furi_hal.h>
+#include <gui/gui.h>
+#include <gui/icon_i.h>
+#include <notification/notification.h>
+#include <notification/notification_messages.h>
+#include <gui/elements.h>
+#include <gui/view_dispatcher.h>
+#include <gui/modules/dialog_ex.h>
+#include <storage/filesystem_api_defines.h>
+#include <storage/storage.h>
+#include <expansion/expansion.h>
+
+#define THREAD_ALLOC 2048
+#define BAUDRATE (115200UL)
+
+#define FRAME_WIDTH 128
+#define FRAME_HEIGTH 64
+#define FRAME_BIT_DEPTH 1
+#define FRAME_BUFFER_LENGTH \
+    (FRAME_WIDTH * FRAME_HEIGTH * FRAME_BIT_DEPTH / 8) // 128*64*1 / 8 = 1024
+#define ROW_BUFFER_LENGTH (FRAME_WIDTH / 8) // 128/8 = 16
+#define LAST_ROW_INDEX (FRAME_BUFFER_LENGTH - ROW_BUFFER_LENGTH) // 1024 - 16 = 1008
+#define RING_BUFFER_LENGTH (ROW_BUFFER_LENGTH + 3) // ROW_BUFFER_LENGTH + Header => 16 + 3 = 19
+#define BITMAP_HEADER_LENGTH 62
+
+#define MALVEKE_APP_FOLDER_USER "apps_data/malveke"
+#define MALVEKE_APP_FOLDER EXT_PATH(MALVEKE_APP_FOLDER_USER)
+#define MALVEKE_APP_FOLDER_PHOTOS MALVEKE_APP_FOLDER "/photos"
+
+// #define IMAGE_FILE_DIRECTORY_PATH EXT_PATH("DCIM")
+
+static const unsigned char bitmap_header[BITMAP_HEADER_LENGTH] = {
+    0x42, 0x4D, 0x3E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x28, 0x00,
+    0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00};
+static const unsigned char bitmap_header_gameboy_full[BITMAP_HEADER_LENGTH] = {
+    0x42, 0x4D, 0x80, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x28, 0x00,
+    0x00, 0x00, 0xA0, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x42, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+const uint8_t _I_DolphinCommon_56x48_0[] = {
+    0x01, 0x00, 0xdf, 0x00, 0x00, 0x1f, 0xfe, 0x0e, 0x05, 0x3f, 0x04, 0x06, 0x78, 0x06, 0x30, 0x20,
+    0xf8, 0x00, 0xc6, 0x12, 0x1c, 0x04, 0x0c, 0x0a, 0x38, 0x08, 0x08, 0x0c, 0x60, 0xc0, 0x21, 0xe0,
+    0x04, 0x0a, 0x18, 0x02, 0x1b, 0x00, 0x18, 0xa3, 0x00, 0x21, 0x90, 0x01, 0x8a, 0x20, 0x02, 0x19,
+    0x80, 0x18, 0x80, 0x64, 0x09, 0x20, 0x89, 0x81, 0x8c, 0x3e, 0x41, 0xe2, 0x80, 0x50, 0x00, 0x43,
+    0x08, 0x01, 0x0c, 0xfc, 0x68, 0x40, 0x61, 0xc0, 0x50, 0x30, 0x00, 0x63, 0xa0, 0x7f, 0x80, 0xc4,
+    0x41, 0x19, 0x07, 0xff, 0x02, 0x06, 0x18, 0x24, 0x03, 0x41, 0xf3, 0x2b, 0x10, 0x19, 0x38, 0x10,
+    0x30, 0x31, 0x7f, 0xe0, 0x34, 0x08, 0x30, 0x19, 0x60, 0x80, 0x65, 0x86, 0x0a, 0x4c, 0x0c, 0x30,
+    0x81, 0xb9, 0x41, 0xa0, 0x54, 0x08, 0xc7, 0xe2, 0x06, 0x8a, 0x18, 0x25, 0x02, 0x21, 0x0f, 0x19,
+    0x88, 0xd8, 0x6e, 0x1b, 0x01, 0xd1, 0x1b, 0x86, 0x39, 0x66, 0x3a, 0xa4, 0x1a, 0x50, 0x06, 0x48,
+    0x18, 0x18, 0xd0, 0x03, 0x01, 0x41, 0x98, 0xcc, 0x60, 0x39, 0x01, 0x49, 0x2d, 0x06, 0x03, 0x50,
+    0xf8, 0x40, 0x3e, 0x02, 0xc1, 0x82, 0x86, 0xc7, 0xfe, 0x0f, 0x28, 0x2c, 0x91, 0xd2, 0x90, 0x9a,
+    0x18, 0x19, 0x3e, 0x6d, 0x73, 0x12, 0x16, 0x00, 0x32, 0x49, 0x72, 0xc0, 0x7e, 0x5d, 0x44, 0xba,
+    0x2c, 0x08, 0xa4, 0xc8, 0x82, 0x06, 0x17, 0xe0, 0x81, 0x90, 0x2a, 0x40, 0x61, 0xe1, 0xa2, 0x44,
+    0x0c, 0x76, 0x2b, 0xe8, 0x89, 0x26, 0x43, 0x83, 0x31, 0x8c, 0x78, 0x0c, 0xb0, 0x48, 0x10, 0x1a,
+    0xe0, 0x00, 0x63,
+};
+const uint8_t* const _I_DolphinCommon_56x48[] = {_I_DolphinCommon_56x48_0};
+const Icon I_DolphinCommon_56x48 = {
+    .width = 56,
+    .height = 48,
+    .frame_count = 1,
+    .frame_rate = 0,
+    .frames = _I_DolphinCommon_56x48};
+
+typedef struct UartDumpModel UartDumpModel;
+
+typedef struct {
+    Gui* gui;
+    Storage* storage;
+    NotificationApp* notification;
+    ViewDispatcher* view_dispatcher;
+    View* view;
+    FuriThread* worker_thread;
+    FuriStreamBuffer* rx_stream;
+    FuriHalSerialHandle* serial_handle_uart;
+    FuriHalSerialHandle* serial_handle_lp_uart;
+} UartEchoApp;
+
+struct UartDumpModel {
+    uint8_t pixels[FRAME_BUFFER_LENGTH];
+
+    File* cameraSav;
+    bool initialized;
+    int page;
+    uint8_t row_ringbuffer[RING_BUFFER_LENGTH];
+    uint8_t ringbuffer_index;
+};
+
+typedef enum {
+    WorkerEventReserved = (1 << 0), // Reserved for StreamBuffer internal event
+    WorkerEventStop = (1 << 1),
+    WorkerEventRx = (1 << 2),
+} WorkerEventFlags;
+
+#define WORKER_EVENTS_MASK (WorkerEventStop | WorkerEventRx)
+
+const NotificationSequence sequence_notification = {
+    // &message_display_backlight_on,
+    &message_delay_10,
+    NULL,
+};

二進制
malveke_gb_live_camera/icons/_icon.png


二進制
malveke_gb_live_camera/icons/gbcam_48x49.png


二進制
malveke_gb_live_camera/icons/icon.png