Sfoglia il codice sorgente

Move flash set_control and v4l functions to util.c

Kristian Vos 5 mesi fa
parent
commit
e14ec3f3db
3 ha cambiato i file con 63 aggiunte e 66 eliminazioni
  1. 0 64
      src/flash.c
  2. 59 1
      src/util.c
  3. 4 1
      src/util.h

+ 0 - 64
src/flash.c

@@ -1,72 +1,8 @@
 #include <libmegapixels.h>
-
-#include <fcntl.h>
-#include <inttypes.h>
-#include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <string.h>
-#include <linux/media.h>
-#include <linux/v4l2-subdev.h>
-
 #include "flash.h"
 #include "util.h"
-#include "log.h"
-
-// Copied from drivers/media/v4l2-core/v4l2-ctrls-defs.c, trimmed down
-const char
-*v4l2_ctrl_get_name(unsigned int id)
-{
-    switch (id) {
-    case V4L2_CID_FLASH_LED_MODE:		return "LED Mode";
-    case V4L2_CID_FLASH_STROBE_SOURCE:	return "Strobe Source";
-    case V4L2_CID_FLASH_STROBE:		    return "Strobe";
-    default:                            return "Unknown";
-    }
-}
-
-// Copied from drivers/media/v4l2-core/v4l2-ctrls-defs.c, trimmed down and slightly modified
-const char
-*v4l2_ctrl_get_menu_value(unsigned int id, signed int val)
-{
-    static const char * const flash_led_mode[] = {
-		"Off",
-		"Flash",
-		"Torch",
-		NULL,
-	};
-    static const char * const flash_strobe_source[] = {
-		"Software",
-		"External",
-		NULL,
-	};
-
-    switch (id) {
-    case V4L2_CID_FLASH_LED_MODE:
-		return flash_led_mode[val];
-    case V4L2_CID_FLASH_STROBE_SOURCE:
-		return flash_strobe_source[val];
-    default:
-        return "None/Unknown";
-    }
-}
-
-// Set a control value, but ignore if it fails
-void
-set_control(int flash_fd, unsigned int ctrl_id, signed int ctrl_val)
-{
-    struct v4l2_control ctrl;
-    ctrl.id = ctrl_id;
-    ctrl.value = ctrl_val;
-    int res = xioctl(flash_fd, VIDIOC_S_CTRL, &ctrl);
-    if (res == -1) {
-        log_debug(
-            "Failed to set %s to %s for flash.\n",
-            v4l2_ctrl_get_name(ctrl_id),
-            v4l2_ctrl_get_menu_value(ctrl_id, ctrl_val)
-        );
-    }
-}
 
 // Flash path is used for both the V4L path, and the LED path, and can be overwritten by a later stage, so memory is first freed
 void

+ 59 - 1
src/util.c

@@ -1,6 +1,9 @@
 #include <sys/ioctl.h>
 #include <errno.h>
+#include <linux/v4l2-subdev.h>
+#include <stdio.h>
 #include "util.h"
+#include "log.h"
 
 int
 xioctl(int fd, int request, void *arg)
@@ -10,4 +13,59 @@ xioctl(int fd, int request, void *arg)
 		r = ioctl(fd, request, arg);
 	} while (r == -1 && errno == EINTR);
 	return r;
-}
+}
+
+// Copied from drivers/media/v4l2-core/v4l2-ctrls-defs.c, trimmed down
+const char
+*v4l2_ctrl_get_name(unsigned int id)
+{
+    switch (id) {
+    case V4L2_CID_FLASH_LED_MODE:		return "LED Mode";
+    case V4L2_CID_FLASH_STROBE_SOURCE:	return "Strobe Source";
+    case V4L2_CID_FLASH_STROBE:		    return "Strobe";
+    default:                            return "Unknown";
+    }
+}
+
+// Copied from drivers/media/v4l2-core/v4l2-ctrls-defs.c, trimmed down and slightly modified
+const char
+*v4l2_ctrl_get_menu_value(unsigned int id, signed int val)
+{
+    static const char * const flash_led_mode[] = {
+		"Off",
+		"Flash",
+		"Torch",
+		NULL,
+	};
+    static const char * const flash_strobe_source[] = {
+		"Software",
+		"External",
+		NULL,
+	};
+
+    switch (id) {
+    case V4L2_CID_FLASH_LED_MODE:
+		return flash_led_mode[val];
+    case V4L2_CID_FLASH_STROBE_SOURCE:
+		return flash_strobe_source[val];
+    default:
+        return "None/Unknown";
+    }
+}
+
+// Set a control value, but ignore if it fails
+void
+set_control(int flash_fd, unsigned int ctrl_id, signed int ctrl_val)
+{
+    struct v4l2_control ctrl;
+    ctrl.id = ctrl_id;
+    ctrl.value = ctrl_val;
+    int res = xioctl(flash_fd, VIDIOC_S_CTRL, &ctrl);
+    if (res == -1) {
+        log_debug(
+            "Failed to set %s to %s for flash.\n",
+            v4l2_ctrl_get_name(ctrl_id),
+            v4l2_ctrl_get_menu_value(ctrl_id, ctrl_val)
+        );
+    }
+}

+ 4 - 1
src/util.h

@@ -1,4 +1,7 @@
 #pragma once
 
 int
-xioctl(int fd, int request, void *arg);
+xioctl(int fd, int request, void *arg);
+
+void
+set_control(int flash_fd, unsigned int ctrl_id, signed int ctrl_val);