private void ThreadTest() { this.isRunning = true; var i2cController = I2cController.FromName(SC20260.I2cBus.I2c1); try { var ov9655 = new Ov9655Controller(i2cController); read_id: try { var id = ov9655.ReadId(); } catch { goto read_id; } byte[] data = null; UnmanagedBuffer unmangedBuffer = null; if (Memory.UnmanagedMemory.FreeBytes != 0) { unmangedBuffer = new UnmanagedBuffer(640 * 480 * 2); data = unmangedBuffer.Bytes; } else { data = new byte[640 * 480 * 2]; } ov9655.SetResolution(Ov9655Controller.Resolution.Vga); var displayController = Display.DisplayController; while (this.isRunning) { try { ov9655.Capture(data, 500); displayController.DrawBuffer(0, this.TopBar.ActualHeight, 0, 0, 480, 272 - this.TopBar.ActualHeight, 640, data, 0); } catch { } Thread.Sleep(10); } if (unmangedBuffer != null) { unmangedBuffer.Dispose(); } } catch { } this.isRunning = false; return; }
private void ThreadTest() { this.isRunning = true; var i2cController = I2cController.FromName(SC20260.I2cBus.I2c1); Ov9655Controller ov9655 = null; var retries = 2; // some camera may failed to initialize after reset first time for (var i = 0; i < retries; i++) { try { ov9655 = new Ov9655Controller(i2cController); ov9655.SetResolution(Ov9655Controller.Resolution.Vga); i = retries; } catch { } } if (ov9655 == null) { return; } var displayController = Display.DisplayController; while (this.isRunning) { try { ov9655.Capture(); displayController.DrawBuffer(0, this.TopBar.ActualHeight, 0, 0, 480, 272 - this.TopBar.ActualHeight, 640, ov9655.Buffer, 0); } catch { } Thread.Sleep(10); } this.isRunning = false; return; }
private bool DoTestCamera() { this.UpdateStatusText(" Press Next button to start camera test...", true); this.UpdateStatusText(" After tested camera, press any buttons (LDR, APP or MOD)", false); this.UpdateStatusText(" to move next test.", false); this.AddNextButton(); while (this.doNext == false && this.isRunning) { Thread.Sleep(100); } this.RemoveNextButton(); if (this.isRunning == false) { return(false); } var i2cController = I2cController.FromName(SC20260.I2cBus.I2c1); var gpioController = GpioController.GetDefault(); var ldrButton = gpioController.OpenPin(SC20260.GpioPin.PE3); var appButton = gpioController.OpenPin(SC20260.GpioPin.PB7); var modeButton = gpioController.OpenPin(SC20260.GpioPin.PD7); ldrButton.SetDriveMode(GpioPinDriveMode.InputPullUp); appButton.SetDriveMode(GpioPinDriveMode.InputPullUp); modeButton.SetDriveMode(GpioPinDriveMode.InputPullUp); try { var ov9655 = new Ov9655Controller(i2cController); var id = ov9655.ReadId(); byte[] data = null; UnmanagedBuffer unmangedBuffer = null; if (Memory.UnmanagedMemory.FreeBytes != 0) { unmangedBuffer = new UnmanagedBuffer(640 * 480 * 2); data = unmangedBuffer.Bytes; } else { data = new byte[640 * 480 * 2]; } ov9655.SetResolution(Ov9655Controller.Resolution.Vga); var displayController = Display.DisplayController; while (ldrButton.Read() == GpioPinValue.High && appButton.Read() == GpioPinValue.High && modeButton.Read() == GpioPinValue.High && this.isRunning) { try { ov9655.Capture(data, 500); displayController.DrawBuffer(0, this.TopBar.ActualHeight, 0, 0, 480, 272 - this.TopBar.ActualHeight, 640, data, 0); } catch { } Thread.Sleep(10); } if (unmangedBuffer != null) { unmangedBuffer.Dispose(); } } catch { this.UpdateStatusText("Failed. Trying to connect to camera...", true); } ldrButton.Dispose(); appButton.Dispose(); modeButton.Dispose(); return(true); }
private bool DoTestCamera() { this.UpdateStatusText(" Press Next button to start camera test...", true); this.UpdateStatusText(" After tested camera, press any buttons (LDR, APP or MOD)", false); this.UpdateStatusText(" to move next test.", false); this.AddNextButton(); while (this.doNext == false && this.isRunning) { Thread.Sleep(100); } this.RemoveNextButton(); if (this.isRunning == false) { return(false); } var i2cController = I2cController.FromName(SC20260.I2cBus.I2c1); var gpioController = GpioController.GetDefault(); var ldrButton = gpioController.OpenPin(SC20260.GpioPin.PE3); var appButton = gpioController.OpenPin(SC20260.GpioPin.PB7); var modeButton = gpioController.OpenPin(SC20260.GpioPin.PD7); ldrButton.SetDriveMode(GpioPinDriveMode.InputPullUp); appButton.SetDriveMode(GpioPinDriveMode.InputPullUp); modeButton.SetDriveMode(GpioPinDriveMode.InputPullUp); try { Ov9655Controller ov9655 = null; var retries = 2; // some camera may failed to initialize after reset first time for (var i = 0; i < retries; i++) { try { ov9655 = new Ov9655Controller(i2cController); ov9655.SetResolution(Ov9655Controller.Resolution.Vga); i = retries; } catch { } } if (ov9655 == null) { return(false); } var displayController = Display.DisplayController; while (ldrButton.Read() == GpioPinValue.High && appButton.Read() == GpioPinValue.High && modeButton.Read() == GpioPinValue.High && this.isRunning) { try { ov9655.Capture(); displayController.DrawBuffer(0, this.TopBar.ActualHeight, 0, 0, 480, 272 - this.TopBar.ActualHeight, 640, ov9655.Buffer, 0); } catch { } Thread.Sleep(10); } } catch { this.UpdateStatusText("Failed. Trying to connect to camera...", true); } ldrButton.Dispose(); appButton.Dispose(); modeButton.Dispose(); return(true); }