Пример #1
0
        /// <summary>
        /// Disable processing on a component
        /// </summary>
        public void Disable()
        {
            var status = MMALNativeMethods.ComponentDisable(this.m_handle);

            if (status != MMAL_STATUS_T.MMAL_SUCCESS)
            {
                throw new MMALException(status);
            }
        }
        /// <summary>
        /// Set camera sensor mode. See forum/doc https://www.raspberrypi.org/documentation/raspbian/applications/camera.md
        /// </summary>
        /// <param name="mode">0 = auto</param>
        public void SetSensorMode(int mode)
        {
            MMAL_STATUS_T status = MMALNativeMethods.PortParameterSet(this.HandleWrapper.control, MMALParameterId.MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG, mode);

            if (status != MMAL_STATUS_T.MMAL_SUCCESS)
            {
                throw new MMALException(status);
            }
        }
 public void SetCameraNum(int camNumber)
 {
     using (MMAL_PARAMETER_INT32_T_Wrapper param = new MMAL_PARAMETER_INT32_T_Wrapper())
     {
         param.hdr.id = MMALParameterId.MMAL_PARAMETER_CAMERA_NUM;
         param.value  = camNumber;
         MMAL_STATUS_T status = MMALNativeMethods.PortParameterSet(this.HandleWrapper.control, param);
         if (status != MMAL_STATUS_T.MMAL_SUCCESS)
         {
             throw new MMALException(status);
         }
     }
 }
Пример #4
0
        private /*MMAL_COMPONENT_T*/ IntPtr CreateComponentHandle(MMALComponentName componentName)
        {
            Console.WriteLine("Creating component " + componentName.Value);
            //var status = NativeMethods.ComponentCreate(componentName.Value, out MMAL_COMPONENT_T handle);
            //if (status != MMAL_STATUS_T.MMAL_SUCCESS)
            //    throw new MMALException(status);

            //handle.DumpFields();

            //return handle;

            var status = MMALNativeMethods.ComponentCreate(componentName.Value, out IntPtr handle);

            if (status != MMAL_STATUS_T.MMAL_SUCCESS)
            {
                throw new MMALException(status);
            }
            return(handle);

            //Console.WriteLine($"Ptr={handle}");
            //for (int i = 1; i <= 100; i++)
            //{
            //    byte b = Marshal.ReadByte(handle, i - 1);
            //    Console.Write("{0:X2} ", b);
            //    if (i % 16 == 0)
            //        Console.WriteLine();
            //    else if (i % 8 == 0)
            //        Console.Write("  ");

            //}
            //IntPtr namePtr = Marshal.ReadIntPtr(handle, Marshal.SizeOf<IntPtr>() * 2);
            //Console.WriteLine($"namePtr={namePtr}");
            //string name = Marshal.PtrToStringAnsi(namePtr);
            //Console.WriteLine($"name={name}");

            //MMAL_COMPONENT_T comp = Marshal.PtrToStructure<MMAL_COMPONENT_T>(handle);

            //comp.DumpFields();

            ////throw new NotImplementedException();
            //return comp;
        }
        public void SetStereoscopicMode(int channel, StereoScopicMode mode)
        {
            using (MMAL_PARAMETER_STEREOSCOPIC_MODE_T_Wrapper stereo = new MMAL_PARAMETER_STEREOSCOPIC_MODE_T_Wrapper())
            {
                stereo.hdr.id = MMALParameterId.MMAL_PARAMETER_STEREOSCOPIC_MODE;
                stereo.mode   = mode.Mode;
                if (mode.Mode != MMAL_STEREOSCOPIC_MODE_T.MMAL_STEREOSCOPIC_MODE_NONE)
                {
                    stereo.decimate  = mode.Decimate;
                    stereo.swap_eyes = mode.SwapEyes;
                }

                MMAL_STATUS_T status = MMALNativeMethods.PortParameterSet(this.HandleWrapper.output[channel], stereo);
                //MMAL_STATUS_T status = NativeMethods.PortParameterSet(this.HandleWrapper.GetOutput()[channel], stereo);
                if (status != MMAL_STATUS_T.MMAL_SUCCESS)
                {
                    throw new MMALException(status);
                }
            }
        }
        public CameraInfo GetCameraInfo(int cameraNum)
        {
            if (this.m_infoCache.ContainsKey(cameraNum))
            {
                return(this.m_infoCache[cameraNum]);
            }

            CameraInfo info = new CameraInfo();

            using (MMAL_PARAMETER_CAMERA_INFO_T_Wrapper param = new MMAL_PARAMETER_CAMERA_INFO_T_Wrapper())
            {
                //param.hdr.DumpOffsets();

                //MMAL_PARAMETER_CAMERA_INFO_T param = new MMAL_PARAMETER_CAMERA_INFO_T();
                //param.hdr = new MMAL_PARAMETER_HEADER_T();
                param.hdr.id = MMALParameterId.MMAL_PARAMETER_CAMERA_INFO;
                uint size = param.hdr.size;
                param.hdr.size = size - 4u;  // Deliberately undersize to check firmware veresion
                //param.hdr.size = (uint)(MMAL_PARAMETER_CAMERA_INFO_T.Size - 4);

                MMAL_STATUS_T status = MMALNativeMethods.PortParameterGet(this.HandleWrapper.control, param);
                if (status != MMAL_STATUS_T.MMAL_SUCCESS)
                {
                    // Running on newer firmware
                    param.hdr.size = size;
                    //param.hdr.size = (uint)(MMAL_PARAMETER_CAMERA_INFO_T.Size);
                    status = MMALNativeMethods.PortParameterGet(this.HandleWrapper.control, param);
                    if (status == MMAL_STATUS_T.MMAL_SUCCESS && param.num_cameras > cameraNum)
                    {
                        info.Width  = param.cameras[cameraNum].max_width;
                        info.Height = param.cameras[cameraNum].max_height;
                        info.Name   = param.cameras[cameraNum].camera_name;

                        //info.DumpProperties();
                    }
                    else
                    {
                        Console.WriteLine($"Cannot read camera info, keeping the defaults for OV5647. status={status} param.num_cameras={param.num_cameras}");
                        //vcos_log_error("Cannot read camera info, keeping the defaults for OV5647");
                    }
                }
                else
                {
                    // Older firmware
                    // Nothing to do here, keep the defaults for OV5647
                    Console.WriteLine("Older firmware, keeping the defaults for OV5647");
                }
            }


            //Assume defaults
            if (string.IsNullOrEmpty(info.Name))
            {
                info.Name = "OV5647";
            }
            if (info.Width == 0)
            {
                info.Width = 2592;
            }
            if (info.Height == 0)
            {
                info.Height = 1944;
            }

            this.m_infoCache.Add(cameraNum, info);

            return(info);
        }
Пример #7
0
 /// <summary>
 /// Destroy a previously created component
 /// Release an acquired reference on a component. Only actually destroys the component when
 /// the last reference is being released.
 /// </summary>
 public void Dispose()
 {
     MMALNativeMethods.ComponentDestroy(this.m_handle);
 }
Пример #8
0
 /// <summary>
 /// Acquire a reference on a component.
 /// Acquiring a reference on a component will prevent a component from being destroyed until
 /// the acquired reference is released(by a call to Dispose).
 /// References are internally counted so all acquired references need a matching call to
 /// release them.
 /// </summary>
 public void Acquire()
 {
     MMALNativeMethods.ComponentAcquire(this.m_handle);
 }