Bläddra i källkod

Update camera view.

Cody Tolene 1 år sedan
förälder
incheckning
dfd0e5c351
5 ändrade filer med 50 tillägg och 29 borttagningar
  1. 1 0
      application.fam
  2. 0 0
      assets/.gitkeep
  3. 22 1
      camera_suite.h
  4. 25 26
      views/camera_suite_view_camera.c
  5. 2 2
      views/camera_suite_view_camera.h

+ 1 - 0
application.fam

@@ -7,6 +7,7 @@ App(
     fap_category="GPIO",
     fap_category="GPIO",
     fap_description="A camera suite application for the Flipper Zero ESP32-CAM module.",
     fap_description="A camera suite application for the Flipper Zero ESP32-CAM module.",
     fap_icon="icons/camera_suite.png",
     fap_icon="icons/camera_suite.png",
+    fap_icon_assets="assets",
     fap_libs=["assets"],
     fap_libs=["assets"],
     fap_version="1.6",
     fap_version="1.6",
     fap_weburl="https://github.com/CodyTolene/Flipper-Zero-Cam",
     fap_weburl="https://github.com/CodyTolene/Flipper-Zero-Cam",

+ 0 - 0
assets/.gitkeep


+ 22 - 1
camera_suite.h

@@ -16,11 +16,32 @@
 #include "views/camera_suite_view_guide.h"
 #include "views/camera_suite_view_guide.h"
 #include "views/camera_suite_view_start.h"
 #include "views/camera_suite_view_start.h"
 #include "views/camera_suite_view_camera.h"
 #include "views/camera_suite_view_camera.h"
-
 #include "helpers/camera_suite_storage.h"
 #include "helpers/camera_suite_storage.h"
 
 
+#include <assets_icons.h>
+
 #define TAG "Camera Suite"
 #define TAG "Camera Suite"
 
 
+#ifdef xtreme_settings
+/**
+ * Enable the following line for "Xtreme Firmware" & "Xtreme Apps" (Flipper-XFW).
+ * 
+ * @see https://github.com/Flipper-XFW/Xtreme-Firmware
+ * @see https://github.com/Flipper-XFW/Xtreme-Apps
+*/
+#define UART_CH (xtreme_settings.uart_esp_channel)
+#elif momentum_settings
+/**
+ * Enable the following line for "Momentum Firmware" & "Momentum Apps".
+ * 
+ * @see https://github.com/Next-Flip/Momentum-Firmware
+ * @see https://github.com/Next-Flip/Momentum-Apps
+*/
+#define UART_CH (momentum_settings.uart_esp_channel)
+#else
+#define UART_CH (FuriHalSerialIdUsart)
+#endif
+
 typedef struct {
 typedef struct {
     Gui* gui;
     Gui* gui;
     NotificationApp* notification;
     NotificationApp* notification;

+ 25 - 26
views/camera_suite_view_camera.c

@@ -1,8 +1,6 @@
 #include "../camera_suite.h"
 #include "../camera_suite.h"
 #include <furi.h>
 #include <furi.h>
 #include <furi_hal.h>
 #include <furi_hal.h>
-#include <furi_hal_serial.h>
-#include <furi_hal_serial_control.h>
 #include <input/input.h>
 #include <input/input.h>
 #include <gui/elements.h>
 #include <gui/elements.h>
 #include <dolphin/dolphin.h>
 #include <dolphin/dolphin.h>
@@ -181,7 +179,7 @@ static void save_image_to_flipper_sd_card(void* model) {
     FuriString* file_name = furi_string_alloc();
     FuriString* file_name = furi_string_alloc();
 
 
     // Get the current date and time.
     // Get the current date and time.
-    FuriHalRtcDateTime datetime = {0};
+    DateTime datetime = {0};
     furi_hal_rtc_get_datetime(&datetime);
     furi_hal_rtc_get_datetime(&datetime);
 
 
     // Create the file name.
     // Create the file name.
@@ -283,7 +281,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
                     UNUSED(model);
                     UNUSED(model);
 
 
                     // Stop camera stream.
                     // Stop camera stream.
-                    furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'s'}, 1);
+                    furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'s'}, 1);
                     furi_delay_ms(50);
                     furi_delay_ms(50);
 
 
                     // Go back to the main menu.
                     // Go back to the main menu.
@@ -304,13 +302,13 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
 
 
                     if(model->is_inverted) {
                     if(model->is_inverted) {
                         // Camera: Set invert to false on the ESP32-CAM.
                         // Camera: Set invert to false on the ESP32-CAM.
-                        furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'i'}, 1);
+                        furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'i'}, 1);
                         furi_delay_ms(50);
                         furi_delay_ms(50);
 
 
                         model->is_inverted = false;
                         model->is_inverted = false;
                     } else {
                     } else {
                         // Camera: Set invert to true on the ESP32-CAM.
                         // Camera: Set invert to true on the ESP32-CAM.
-                        furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'I'}, 1);
+                        furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'I'}, 1);
                         furi_delay_ms(50);
                         furi_delay_ms(50);
 
 
                         model->is_inverted = true;
                         model->is_inverted = true;
@@ -333,13 +331,13 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
 
 
                     if(model->is_dithering_enabled) {
                     if(model->is_dithering_enabled) {
                         // Camera: Disable dithering.
                         // Camera: Disable dithering.
-                        furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'d'}, 1);
+                        furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'d'}, 1);
                         furi_delay_ms(50);
                         furi_delay_ms(50);
 
 
                         model->is_dithering_enabled = false;
                         model->is_dithering_enabled = false;
                     } else {
                     } else {
                         // Camera: Enable dithering.
                         // Camera: Enable dithering.
-                        furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'D'}, 1);
+                        furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'D'}, 1);
                         furi_delay_ms(50);
                         furi_delay_ms(50);
 
 
                         model->is_dithering_enabled = true;
                         model->is_dithering_enabled = true;
@@ -363,7 +361,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
                     camera_suite_led_set_rgb(instance->context, 0, 0, 255);
                     camera_suite_led_set_rgb(instance->context, 0, 0, 255);
 
 
                     // Camera: Increase contrast.
                     // Camera: Increase contrast.
-                    furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'C'}, 1);
+                    furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'C'}, 1);
                     furi_delay_ms(50);
                     furi_delay_ms(50);
 
 
                     instance->callback(CameraSuiteCustomEventSceneCameraUp, instance->context);
                     instance->callback(CameraSuiteCustomEventSceneCameraUp, instance->context);
@@ -384,7 +382,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
                     camera_suite_led_set_rgb(instance->context, 0, 0, 255);
                     camera_suite_led_set_rgb(instance->context, 0, 0, 255);
 
 
                     // Camera: Reduce contrast.
                     // Camera: Reduce contrast.
-                    furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'c'}, 1);
+                    furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'c'}, 1);
                     furi_delay_ms(50);
                     furi_delay_ms(50);
 
 
                     instance->callback(CameraSuiteCustomEventSceneCameraDown, instance->context);
                     instance->callback(CameraSuiteCustomEventSceneCameraDown, instance->context);
@@ -403,7 +401,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
                     camera_suite_led_set_rgb(instance->context, 0, 0, 255);
                     camera_suite_led_set_rgb(instance->context, 0, 0, 255);
 
 
                     // @todo - Save picture directly to ESP32-CAM.
                     // @todo - Save picture directly to ESP32-CAM.
-                    // furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'P'}, 1);
+                    // furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'P'}, 1);
 
 
                     // Save currently displayed image to the Flipper Zero SD card.
                     // Save currently displayed image to the Flipper Zero SD card.
                     save_image_to_flipper_sd_card(model);
                     save_image_to_flipper_sd_card(model);
@@ -437,22 +435,22 @@ static void camera_suite_view_camera_enter(void* context) {
     CameraSuite* instance_context = instance->context;
     CameraSuite* instance_context = instance->context;
 
 
     // Start camera stream.
     // Start camera stream.
-    furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'S'}, 1);
+    furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'S'}, 1);
     furi_delay_ms(50);
     furi_delay_ms(50);
 
 
     // Get/set dither type.
     // Get/set dither type.
     uint8_t dither_type = instance_context->dither;
     uint8_t dither_type = instance_context->dither;
-    furi_hal_uart_tx(FuriHalUartIdUSART1, &dither_type, 1);
+    furi_hal_serial_tx(instance->serial_handle, &dither_type, 1);
     furi_delay_ms(50);
     furi_delay_ms(50);
 
 
     // Make sure the camera is not inverted.
     // Make sure the camera is not inverted.
-    furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'i'}, 1);
+    furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'i'}, 1);
     furi_delay_ms(50);
     furi_delay_ms(50);
 
 
     // Toggle flash on or off based on the current state. If the user has this
     // Toggle flash on or off based on the current state. If the user has this
     // on the flash will stay on the entire time the user is in the camera view.
     // on the flash will stay on the entire time the user is in the camera view.
     uint8_t flash_state = instance_context->flash ? 'F' : 'f';
     uint8_t flash_state = instance_context->flash ? 'F' : 'f';
-    furi_hal_uart_tx(FuriHalUartIdUSART1, &flash_state, 1);
+    furi_hal_serial_tx(instance->serial_handle, &flash_state, 1);
     furi_delay_ms(50);
     furi_delay_ms(50);
 
 
     with_view_model(
     with_view_model(
@@ -462,17 +460,16 @@ static void camera_suite_view_camera_enter(void* context) {
         true);
         true);
 }
 }
 
 
-static void camera_on_irq_cb(UartIrqEvent uartIrqEvent, uint8_t data, void* context) {
-    furi_assert(uartIrqEvent);
-    furi_assert(data);
+static void
+    camera_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent event, void* context) {
+    furi_assert(handle);
     furi_assert(context);
     furi_assert(context);
 
 
     // Cast `context` to `CameraSuiteViewCamera*` and store it in `instance`.
     // Cast `context` to `CameraSuiteViewCamera*` and store it in `instance`.
     CameraSuiteViewCamera* instance = context;
     CameraSuiteViewCamera* instance = context;
 
 
-    // If `uartIrqEvent` is `UartIrqEventRXNE`, send the data to the
-    // `camera_rx_stream` and set the `WorkerEventRx` flag.
-    if(uartIrqEvent == UartIrqEventRXNE) {
+    if(event == FuriHalSerialRxEventData) {
+        uint8_t data = furi_hal_serial_async_rx(handle);
         furi_stream_buffer_send(instance->camera_rx_stream, &data, 1, 0);
         furi_stream_buffer_send(instance->camera_rx_stream, &data, 1, 0);
         furi_thread_flags_set(furi_thread_get_id(instance->camera_worker_thread), WorkerEventRx);
         furi_thread_flags_set(furi_thread_get_id(instance->camera_worker_thread), WorkerEventRx);
     }
     }
@@ -609,11 +606,12 @@ CameraSuiteViewCamera* camera_suite_view_camera_alloc() {
     instance->camera_worker_thread = thread;
     instance->camera_worker_thread = thread;
     furi_thread_start(instance->camera_worker_thread);
     furi_thread_start(instance->camera_worker_thread);
 
 
-    // Disable console.
-    furi_hal_console_disable();
+    // Allocate the serial handle for the camera.
+    instance->serial_handle = furi_hal_serial_control_acquire(UART_CH);
+    furi_check(instance->serial_handle);
 
 
     // 115200 is the default baud rate for the ESP32-CAM.
     // 115200 is the default baud rate for the ESP32-CAM.
-    furi_hal_uart_set_br(FuriHalUartIdUSART1, 230400);
+    furi_hal_serial_init(instance->serial_handle, 230400);
 
 
     // Enable UART1 and set the IRQ callback.
     // Enable UART1 and set the IRQ callback.
     furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, camera_on_irq_cb, instance);
     furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, camera_on_irq_cb, instance);
@@ -633,8 +631,9 @@ void camera_suite_view_camera_free(CameraSuiteViewCamera* instance) {
     // Free the allocated stream buffer.
     // Free the allocated stream buffer.
     furi_stream_buffer_free(instance->camera_rx_stream);
     furi_stream_buffer_free(instance->camera_rx_stream);
 
 
-    // Re-enable the console.
-    // furi_hal_console_enable();
+    // Deinitialize the serial handle and release the control.
+    furi_hal_serial_deinit(instance->serial_handle);
+    furi_hal_serial_control_release(instance->serial_handle);
 
 
     with_view_model(
     with_view_model(
         instance->view, UartDumpModel * model, { UNUSED(model); }, true);
         instance->view, UartDumpModel * model, { UNUSED(model); }, true);

+ 2 - 2
views/camera_suite_view_camera.h

@@ -46,9 +46,9 @@ typedef void (*CameraSuiteViewCameraCallback)(CameraSuiteCustomEvent event, void
 
 
 typedef struct CameraSuiteViewCamera {
 typedef struct CameraSuiteViewCamera {
     CameraSuiteViewCameraCallback callback;
     CameraSuiteViewCameraCallback callback;
+    FuriStreamBuffer* camera_rx_stream;
     FuriHalSerialHandle* serial_handle;
     FuriHalSerialHandle* serial_handle;
-    FuriStreamBuffer* rx_stream;
-    FuriThread* worker_thread;
+    FuriThread* camera_worker_thread;
     NotificationApp* notification;
     NotificationApp* notification;
     View* view;
     View* view;
     void* context;
     void* context;