static void Main(string[] args) { //Console.WriteLine(Marshal.SizeOf<MMAL.Interop.MMAL_ES_FORMAT_T>()); Console.WriteLine(Marshal.SizeOf <IntPtr>()); Console.WriteLine(Marshal.SizeOf <MMAL.Interop.MMAL_COMPONENT_T>()); Console.WriteLine("Raspberry pi image capture sample program"); int camNumber = 0; using (BcmHost host = new BcmHost()) { Console.WriteLine("Host created"); //set_sensor_defaults CameraInfo camInfo; using (var camInfoComp = host.MMAL.ComponentCreateCameraInfo()) { Console.WriteLine("Getting camera info"); camInfo = camInfoComp.GetCameraInfo(camNumber); } Console.WriteLine($"Camera name='{camInfo.Name}' res={camInfo.Width}x{camInfo.Height}"); //create_camera_component using (var camera = host.MMAL.ComponentCreateCamera()) { create_camera_component(camera, camNumber); //camera.Enable(); } } Console.WriteLine("Tadaaa !"); }
static void Main(string[] args) { using (BcmHost host = new BcmHost()) using (Display disp = host.Dispman.DisplayOpen(Screen.MAIN_LCD)) { int pitch = ALIGN_UP(2 * disp.Width, 32); VC_IMAGE_TYPE_T type = VC_IMAGE_TYPE_T.VC_IMAGE_RGB565; using (Resource res = host.Dispman.CreateResource(type, disp.Width, disp.Height)) { Console.WriteLine("snapshot"); disp.Snapshot(res, DISPMANX_TRANSFORM_T.DISPMANX_NO_ROTATE); Console.WriteLine("readdata"); Rectangle rect = new Rectangle(0, 0, disp.Width, disp.Height); byte[] image = new byte[pitch * disp.Height]; res.ReadData(rect, image, disp.Width * 2); Console.WriteLine("jpg"); using (var img = Image.LoadPixelData <Bgr565>(new Span <byte>(image), rect.Width, rect.Height)) using (MemoryStream ms = new MemoryStream()) { img.SaveAsJpeg(ms); } Console.WriteLine("ok"); } } }
public Camera() { BcmHost.Initialize(); _camera = new MmalCameraComponent(); _cameraDisposables = new List <IDisposable>(); CurrentState = new CurrentState(_camera); }
public static ScopedElement Create(BcmHost host, Display display, Resource resource, Rectangle destRect, Rectangle srcRect) { var update = host.Dispman.UpdateStart(0); Element element = host.Dispman.ElementAdd(update, display, 0, destRect, resource, srcRect, Protection.None, null, null, DISPMANX_TRANSFORM_T.DISPMANX_NO_ROTATE); update.SubmitSync(); return(new ScopedElement(host, element)); }
private MMALCamera() { BcmHost.bcm_host_init(); MMALLog.ConfigureLogger(); this.Camera = new MMALCameraComponent(); }
public DispmanCapture(BcmHost host) { this.m_host = host; this.m_display = this.m_host.Dispman.DisplayOpen(Screen.MAIN_LCD); this.m_pitch = ALIGN_UP(2 * this.m_display.Width, 32); this.m_image = new byte[this.m_pitch * this.m_display.Height]; this.m_resource = this.m_host.Dispman.CreateResource(VC_IMAGE_TYPE_T.VC_IMAGE_RGB565, this.m_display.Width, this.m_display.Height); this.m_screenRect = new Rectangle(0, 0, this.m_display.Width, this.m_display.Height); }
public void Dispose() { var tempList = new List <MmalDownstreamComponent>(MmalBootstrapper.DownstreamComponents); tempList.ForEach(c => c.Dispose()); _camera.Dispose(); BcmHost.Uninitialize(); }
private MMALCamera() { BcmHost.bcm_host_init(); MMALLog.ConfigureLogger(); this.Camera = new MMALCameraComponent(); this.DownstreamComponents = new List <MMALDownstreamComponent>(); }
/// <summary> /// Cleans up any unmanaged resources. It is intended for this method to be run when no more activity is to be done with MMAL. /// </summary> public void Cleanup() { MMALLog.Logger.LogDebug("Destroying final components"); var tempList = new List <MMALDownstreamComponent>(MMALBootstrapper.DownstreamComponents); tempList.ForEach(c => c.Dispose()); BcmHost.bcm_host_deinit(); }
private static void PiInit() { deinit = PiDeinit; BcmHost.Init(); if (BcmHost.Devices == null || BcmHost.Devices.Count < 0) { throw new Exception("No dispmanx display available"); } PiGameSharp.EGL.EGL.InitDispmanx(BcmHost.Devices[0], EglApi.OpenVG); PiGameSharp.Sound.ALSA.Init(); PiGameSharp.Sound.PCM.play = PiGameSharp.Sound.ALSA.Play; }
static void Main(string[] args) { Console.WriteLine("Hello World!"); using (BcmHost host = new BcmHost()) { Console.WriteLine("host ok"); IntPtr display = eglGetDisplay(0); Console.WriteLine("Display ptr {0}", display); } }
public static void AddBcm(this IServiceCollection services) { services.AddSingleton <BcmHost>(svc => { svc.GetRequiredService <ILogger <Program> >().LogDebug("Initializing BcmHost"); return(new BcmHost()); }); services.AddSingleton <Resource>(svc => { BcmHost host = svc.GetRequiredService <BcmHost>(); LedMatrix matrix = svc.GetRequiredService <LedMatrix>(); svc.GetRequiredService <ILogger <Program> >().LogDebug("Initializing Resource"); return(host.Dispman.CreateResource(VC_IMAGE_TYPE_T.VC_IMAGE_RGB888, matrix.CanvasWidth, matrix.CanvasHeight)); }); services.AddSingleton <Display>(svc => { BcmHost host = svc.GetRequiredService <BcmHost>(); //Resource target = svc.GetRequiredService<Resource>(); svc.GetRequiredService <ILogger <Program> >().LogDebug("Initializing Display"); //return host.Dispman.DisplayOpenOffscreen(target, DISPMANX_TRANSFORM_T.DISPMANX_NO_ROTATE); return(host.Dispman.DisplayOpen(Screen.MAIN_LCD)); }); services.AddSingleton <Element>(svc => { BcmHost host = svc.GetRequiredService <BcmHost>(); Display display = svc.GetRequiredService <Display>(); LedMatrix matrix = svc.GetRequiredService <LedMatrix>(); //Resource resource = svc.GetRequiredService<Resource>(); Rectangle srcRect = new Rectangle(0, 0, matrix.CanvasWidth, matrix.CanvasHeight); Rectangle dstRect = new Rectangle(0, 0, matrix.CanvasWidth << 16, matrix.CanvasHeight << 16); Update update = host.Dispman.UpdateStart(0); svc.GetRequiredService <ILogger <Program> >().LogDebug("Initializing Element"); Element element = host.Dispman.ElementAdd(update, display, 0, dstRect, null, srcRect, Protection.None, null, null, DISPMANX_TRANSFORM_T.DISPMANX_NO_ROTATE); update.SubmitSync(); return(element); }); services.AddSingleton <INativeWindow>(svc => { LedMatrix matrix = svc.GetRequiredService <LedMatrix>(); Element element = svc.GetRequiredService <Element>(); svc.GetRequiredService <ILogger <Program> >().LogDebug("Initializing DispmanWindow"); return(new DispmanWindow(element, matrix.CanvasWidth, matrix.CanvasHeight)); }); }
public static IServiceCollection AddDispmanSpy(this IServiceCollection services) { return(services .AddSingleton <BcmHost>() .AddSingleton <IScreenCapture>(svc => { try { BcmHost host = svc.GetRequiredService <BcmHost>(); return new DispmanCapture(host); } catch (DllNotFoundException) { return new FakeCapture(); } }) .AddSingleton <DispmanCapture>() .AddSingleton <ImageGrabberService>() .AddSingleton <IHostedService>(svc => svc.GetRequiredService <ImageGrabberService>()) .AddTransient <IScreenSpyImageProvider, SpyImageProvider>() ); }
public static void Main(string[] args) { try { using (BcmHost host = new BcmHost()) using (Display display = host.Dispman.DisplayOpen(Screen.MAIN_LCD)) using (DispmanVncServerDisplay src = new DispmanVncServerDisplay(host, display)) { src.Run(); } Console.WriteLine("ok"); Console.ReadLine(); } catch (Exception ex) { do { Console.WriteLine(ex.GetType().FullName + ": " + ex.Message); Console.WriteLine(ex.StackTrace); }while ((ex = ex.InnerException) != null); Console.ReadLine(); } }
private MMALStandalone() { BcmHost.bcm_host_init(); }
private static int RunApp() { app.Out.WriteLine("Hello World!"); int brightnessValue = 100; if (brightness.HasValue()) { if (int.TryParse(brightness.Value(), out brightnessValue)) { if (brightnessValue < 1 || brightnessValue > 100) { app.Error.WriteLine("Brightness value outside allowed values"); return(-1); } } else { app.Error.WriteLine("Invalid brightness value"); return(-1); } } //long uid = UnixUserInfo.GetRealUserId(); //if (uid != 0) //{ // app.Out.WriteLine("You must run this app as root."); // return -1; //} //ServiceCollection serviceConfig = new ServiceCollection(); //serviceConfig.AddLogging(); //serviceConfig.AddOptions(); //serviceConfig.AddBcm(); //serviceConfig.AddOpenGl(); //serviceConfig.AddLedMatrix(); //using (ServiceProvider services = serviceConfig.BuildServiceProvider()) //{ // services.GetRequiredService<ILoggerFactory>().AddConsole(LogLevel.Information); // return RunApp(services); //} using (LedMatrixOptions options = new LedMatrixOptions() { chain_length = 2, parallel = 1, rows = 64, led_rgb_sequence = "RBG", pwm_bits = 8, show_refresh_rate = 1, brightness = brightnessValue, }) using (LedMatrix matrix = new LedMatrix(options.rows, options.chain_length, options.parallel)) using (BcmHost host = new BcmHost()) using (Resource target = host.Dispman.CreateResource(VC_IMAGE_TYPE_T.VC_IMAGE_RGB888, matrix.CanvasWidth, matrix.CanvasHeight)) using (Display display = host.Dispman.DisplayOpenOffscreen(target, DISPMANX_TRANSFORM_T.DISPMANX_NO_ROTATE)) //using (Display display = host.Dispman.DisplayOpen(Screen.MAIN_LCD)) using (ScopedElement element = ScopedElement.Create(host, display, null, destRect: display.Rectangle, srcRect: Rescale(display.Rectangle))) using (DispmanWindow window = new DispmanWindow(element, display.Width, display.Height)) using (EglDisplay eglDisp = new EglDisplay()) using (EglContext ctx = new EglContext(eglDisp)) using (EglSurface surface = new EglSurface(eglDisp, window)) using (Data data = new Data()) { Rectangle rect = display.Rectangle; app.Out.WriteLine("Ready to go, screen is {0}x{1}", display.Width, display.Height); Stopwatch swatch = Stopwatch.StartNew(); app.Out.WriteLine("Initializing 3D context"); ctx.MakeCurrent(surface); app.Out.WriteLine("init_ogl"); init_ogl(); app.Out.WriteLine("init_model_proj"); init_model_proj(rect, data); app.Out.WriteLine("init_textures"); init_textures(data); app.Out.WriteLine("Initializing buffer"); //int bufferLength = rect.Width * rect.Height * 3; //byte[] buffer = new byte[bufferLength]; app.Out.WriteLine("Init complete, starting loop"); //Render loop bool run = true; Console.CancelKeyPress += (s, e) => { if (run) { run = false; e.Cancel = true; } }; Console.TreatControlCAsInput = true; int pitch = Utils.ALIGN_UP(3 * display.Width, 32); byte[] image = new byte[pitch * display.Height]; app.Out.WriteLine("Buffer size: {0}", image.Length); while (run) { if (Console.KeyAvailable) { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.C && key.Modifiers == ConsoleModifiers.Control) { run = false; Console.TreatControlCAsInput = false; continue; } if (key.Key == ConsoleKey.Add || key.Key == ConsoleKey.Subtract) { int newB; if (key.Key == ConsoleKey.Add) { newB = Math.Min(options.brightness + 1, 100); } else { newB = Math.Max(options.brightness - 1, 0); } if (options.brightness != newB) { options.brightness = newB; app.Out.WriteLine("New brightness: {0}%", newB); if (!matrix.UpdateOptions(options)) { app.Out.WriteLine("Update option failed"); } } } } update_model(); redraw_scene(surface); //extract data to buffer //target.WriteData(1, buffer, rect); target.ReadData(rect, image, pitch); //Display image to matrix matrix.UpdateCanvas(canvas => { for (int x = 0; x < canvas.Width; x++) { for (int y = 0; y < canvas.Height; y++) { int baseAddr = (x * canvas.Width + y) * 3; try { byte r = image[baseAddr + 0]; byte g = image[baseAddr + 1]; byte b = image[baseAddr + 2]; canvas.SetPixel(x, y, r, g, b); } catch (IndexOutOfRangeException ex) { app.Out.WriteLine("X={0} Y={1} baseAddre={2} pitch={3}", x, y, baseAddr, pitch); System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw(); } } } }); app.Out.Write("."); } return(0); } }
static void Main(string[] args) { Alpha alpha = new Alpha { Flags = DISPMANX_FLAGS_ALPHA_T.DISPMANX_FLAGS_ALPHA_FROM_SOURCE | DISPMANX_FLAGS_ALPHA_T.DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS, Opacity = 120, Mask = null }; Screen screen = Screen.MAIN_LCD; short width = WIDTH; short height = HEIGHT; short pitch = ALIGN_UP((short)(width * 2), (short)32); short aligned_height = ALIGN_UP(height, (short)16); VC_IMAGE_TYPE_T type = VC_IMAGE_TYPE_T.VC_IMAGE_RGB565; try { using (BcmHost host = new BcmHost()) { Console.WriteLine("Open display {0}", screen); using (Display display = host.Dispman.DisplayOpen(screen)) { Console.WriteLine("Display is: {0} {1}x{2}", display.DisplayNum, display.Width, display.Height); byte[] image = new byte[pitch * height]; GCHandle imageHandle = GCHandle.Alloc(image, GCHandleType.Pinned); try { FillRect(type, image, pitch, aligned_height, 0, 0, width, height, unchecked ((short)0xFFFF)); FillRect(type, image, pitch, aligned_height, 0, 0, width, height, unchecked ((short)0xF800)); FillRect(type, image, pitch, aligned_height, 20, 20, (short)(width - 40), (short)(height - 40), unchecked ((short)0x07E0)); FillRect(type, image, pitch, aligned_height, 40, 40, (short)(width - 80), (short)(height - 80), unchecked ((short)0x001F)); } finally { imageHandle.Free(); } using (Resource resource = host.Dispman.CreateResource(type, width, height)) { Rectangle dst_rect = new Rectangle(0, 0, width, height); resource.WriteData(pitch, image, dst_rect); Update update = host.Dispman.UpdateStart(10); Rectangle src_rect = new Rectangle(0, 0, width << 16, height << 16); dst_rect = new Rectangle((display.Width - width) / 2, (display.Height - height) / 2, width, height); Element element = host.Dispman.ElementAdd(update, display, 2000 /*layer*/, dst_rect, resource, src_rect, Protection.None, alpha, null /*clamp*/, DISPMANX_TRANSFORM_T.DISPMANX_NO_ROTATE); update.SubmitSync(); Console.WriteLine("Sleeping for 10 seconds..."); Thread.Sleep(TimeSpan.FromSeconds(10)); update = host.Dispman.UpdateStart(10); host.Dispman.ElementRemove(update, element); update.SubmitSync(); } } } } catch (Exception ex) { Console.WriteLine(ex.GetType().FullName + ": " + ex.Message); Console.WriteLine(ex.StackTrace); } }
private ScopedElement(BcmHost host, Element e) { this.m_e = e; this.m_host = host; }
private MMALCamera() { BcmHost.bcm_host_init(); this.Camera = new MMALCameraComponent(); }
public DispmanVncServerDisplay(BcmHost host, Display display) { this.m_host = host; this.m_display = display; this.m_swatch = new System.Diagnostics.Stopwatch(); }
private MMALStandalone() { BcmHost.bcm_host_init(); MMALLog.ConfigureLogger(); }
private static void PiDeinit() { PiGameSharp.Sound.ALSA.Deinit(); BcmHost.Deinit(); }