Просмотр исходного кода

Remove dithering type from center button and add to options.

Cody Tolene 2 лет назад
Родитель
Сommit
500bad1959

+ 1 - 0
src-fap/camera_suite.c

@@ -44,6 +44,7 @@ CameraSuite* camera_suite_app_alloc() {
 
     // Set defaults, in case no config loaded
     app->orientation = 0; // Orientation is "portrait", zero degrees by default.
+    app->dither = 0; // Dither algorithm is "Floyd Steinberg" by default.
     app->haptic = 1; // Haptic is on by default
     app->speaker = 1; // Speaker is on by default
     app->led = 1; // LED is on by default

+ 7 - 0
src-fap/camera_suite.h

@@ -30,6 +30,7 @@ typedef struct {
     CameraSuiteViewCamera* camera_suite_view_camera;
     CameraSuiteViewGuide* camera_suite_view_guide;
     uint32_t orientation;
+    uint32_t dither;
     uint32_t haptic;
     uint32_t speaker;
     uint32_t led;
@@ -51,6 +52,12 @@ typedef enum {
     CameraSuiteOrientation270,
 } CameraSuiteOrientationState;
 
+typedef enum {
+    CameraSuiteDitherFloydSteinberg,
+    CameraSuiteDitherStucki,
+    CameraSuiteDitherJarvisJudiceNinke,
+} CameraSuiteDitherState;
+
 typedef enum {
     CameraSuiteHapticOff,
     CameraSuiteHapticOn,

+ 6 - 6
src-fap/helpers/camera_suite_storage.c

@@ -47,10 +47,9 @@ void camera_suite_save_settings(void* context) {
     }
 
     // Store Settings
-    flipper_format_write_header_cstr(
-        fff_file, BOILERPLATE_SETTINGS_HEADER, BOILERPLATE_SETTINGS_FILE_VERSION);
-    flipper_format_write_uint32(
-        fff_file, BOILERPLATE_SETTINGS_KEY_ORIENTATION, &app->orientation, 1);
+    flipper_format_write_header_cstr(fff_file, BOILERPLATE_SETTINGS_HEADER, BOILERPLATE_SETTINGS_FILE_VERSION);
+    flipper_format_write_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_ORIENTATION, &app->orientation, 1);
+    flipper_format_write_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_DITHER, &app->dither, 1);
     flipper_format_write_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
     flipper_format_write_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
     flipper_format_write_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_LED, &app->led, 1);
@@ -100,8 +99,9 @@ void camera_suite_read_settings(void* context) {
         return;
     }
 
-    flipper_format_read_uint32(
-        fff_file, BOILERPLATE_SETTINGS_KEY_ORIENTATION, &app->orientation, 1);
+    // Read settings
+    flipper_format_read_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_ORIENTATION, &app->orientation, 1);
+    flipper_format_read_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_DITHER, &app->dither, 1);
     flipper_format_read_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
     flipper_format_read_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
     flipper_format_read_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_LED, &app->led, 1);

+ 1 - 0
src-fap/helpers/camera_suite_storage.h

@@ -10,6 +10,7 @@
 #define BOILERPLATE_SETTINGS_SAVE_PATH_TMP BOILERPLATE_SETTINGS_SAVE_PATH ".tmp"
 #define BOILERPLATE_SETTINGS_HEADER "Camera Suite Config File"
 #define BOILERPLATE_SETTINGS_KEY_ORIENTATION "Orientation"
+#define BOILERPLATE_SETTINGS_KEY_DITHER "Dither"
 #define BOILERPLATE_SETTINGS_KEY_HAPTIC "Haptic"
 #define BOILERPLATE_SETTINGS_KEY_LED "Led"
 #define BOILERPLATE_SETTINGS_KEY_SPEAKER "Speaker"

+ 32 - 0
src-fap/scenes/camera_suite_scene_settings.c

@@ -16,6 +16,19 @@ const uint32_t orientation_value[4] = {
     CameraSuiteOrientation270,
 };
 
+// Possible dithering types for the camera.
+const char* const dither_text[28] = {
+    "Floyd-Steinberg",
+    "Stucki",
+    "Jarvis-Judice-Ninke",
+};
+
+const uint32_t dither_value[4] = {
+    CameraSuiteDitherFloydSteinberg,
+    CameraSuiteDitherStucki,
+    CameraSuiteDitherJarvisJudiceNinke,
+};
+
 const char* const haptic_text[2] = {
     "OFF",
     "ON",
@@ -54,6 +67,14 @@ static void camera_suite_scene_settings_set_camera_orientation(VariableItem* ite
     app->orientation = orientation_value[index];
 }
 
+static void camera_suite_scene_settings_set_camera_dither(VariableItem* item) {
+    CameraSuite* app = variable_item_get_context(item);
+    uint8_t index = variable_item_get_current_value_index(item);
+
+    variable_item_set_current_value_text(item, dither_text[index]);
+    app->dither = dither_value[index];
+}
+
 static void camera_suite_scene_settings_set_haptic(VariableItem* item) {
     CameraSuite* app = variable_item_get_context(item);
     uint8_t index = variable_item_get_current_value_index(item);
@@ -97,6 +118,17 @@ void camera_suite_scene_settings_on_enter(void* context) {
     variable_item_set_current_value_index(item, value_index);
     variable_item_set_current_value_text(item, orientation_text[value_index]);
 
+    // Camera Dither Type
+    item = variable_item_list_add(
+        app->variable_item_list,
+        "Dithering Type:",
+        3,
+        camera_suite_scene_settings_set_camera_dither,
+        app);
+    value_index = value_index_uint32(app->dither, dither_value, 3);
+    variable_item_set_current_value_index(item, value_index);
+    variable_item_set_current_value_text(item, dither_text[value_index]);
+
     // Haptic FX ON/OFF
     item = variable_item_list_add(
         app->variable_item_list, "Haptic FX:", 2, camera_suite_scene_settings_set_haptic, app);

+ 22 - 2
src-fap/views/camera_suite_view_camera.c

@@ -250,8 +250,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
                 true);
             break;
         case InputKeyOk:
-            // Switch dithering types.
-            // data[0] = 'D';
+            // Camera: Initialize take picture mode.
             data[0] = 'P';
             // Initialize the ESP32-CAM onboard torch immediately.
             furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
@@ -295,6 +294,27 @@ static void camera_suite_view_camera_enter(void* context) {
 
     uint8_t data[1];
     data[0] = 'S'; // Uppercase `S` to start the camera
+
+    // Send `data` to the ESP32-CAM
+    furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
+
+    // Delay for 50ms to make sure the camera is started before sending any other commands.
+    furi_delay_ms(50);
+
+    // Initialize the camera with the selected dithering option from options.
+    CameraSuite* instanceContext = instance->context;
+    switch(instanceContext->dither) {
+        case 0: // Floyd Steinberg
+            data[0] = '0';
+            break;
+        case 1: // Stucki
+            data[0] = '1';
+            break;
+        case 2: // Jarvis Judice Ninke
+            data[0] = '2';
+            break;
+    }
+
     // Send `data` to the ESP32-CAM
     furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
 

+ 8 - 2
src-firmware/esp32_cam_uart_stream/esp32_cam_uart_stream.ino

@@ -112,8 +112,14 @@ void handleSerialInput() {
       case 's': // Stop stream
         stopStream = true;
         break;
-      case 'D': // Change dithering algorithm.
-        ditherAlgorithm = static_cast<DitheringAlgorithm>((ditherAlgorithm + 1) % 3);
+      case '0': // Use Floyd Steinberg dithering.
+        ditherAlgorithm = FLOYD_STEINBERG;
+        break;
+      case '1': // Use Jarvis Judice dithering.
+        ditherAlgorithm = JARVIS_JUDICE_NINKE;
+        break;
+      case '2': // Use Stucki dithering.
+        ditherAlgorithm = STUCKI;
         break;
       default:
         // Do nothing.