void DrawBoard() { var board = _snakeService.Board; var score = _snakeService.CurrentScore; var bitmap = Bitmap.CreateBitmap(SIZE, SIZE, Bitmap.Config.Argb8888); using (var canvas = new Canvas(bitmap)) { foreach (var pos in board) { canvas.DrawPoint(pos.x, pos.y, GetPaint(pos.state)); } using (var ledMatrix = new LedMatrix()) { ledMatrix.Draw(bitmap); } } RunOnUiThread(() => { SnakeView.SetImageBitmap(Bitmap.CreateScaledBitmap(bitmap, 200, 200, false)); bitmap.Dispose(); ScoreView.Text = $"Current score: {_snakeService.CurrentScore}"; }); Task.Run(async() => await _cloudService.SendSnakeMove(board, score)); }
private int OnExecute() { var options = new LedMatrixOptions() { Brightness = (byte)Brightness, }; // Check if we have only extreme colors if (Brightness == 100 && FullSaturation(Color) && FullSaturation(BackgroundColor) ) { options.PwmBits = 1; } var matrix = new LedMatrix(options); var canvas = matrix.CreateOffscreenCanvas(); var font = new BdfFont(Font); while (!Console.KeyAvailable) { var text = DateTime.UtcNow.ToString(Format); canvas.Fill(BackgroundColor); canvas.DrawText(font, XOrigin, YOrigin + font.Baseline, Color, text, Spacing); matrix.SwapOnVsync(canvas); Thread.Sleep(TimeSpan.FromMilliseconds(250)); } return(0); }
/// <inheritdoc/> public void Dispose() { if (_shouldDispose) { _i2cBus?.Dispose(); } else { LedMatrix?.Dispose(); LedMatrix = null !; Joystick?.Dispose(); Joystick = null !; Gyroscope?.Dispose(); Gyroscope = null !; Magnetometer?.Dispose(); Magnetometer = null !; TemperatureAndHumidity?.Dispose(); TemperatureAndHumidity = null !; PressureAndTemperature?.Dispose(); PressureAndTemperature = null !; } _i2cBus = null !; }
private async Task StartLedMatrix() { //return async () => { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/StoreLogo.png")); var inputStream = await file.OpenSequentialReadAsync(); var binaryReader = new BinaryReader(inputStream.AsStreamForRead()); var buffer = new byte[14]; binaryReader.Read(buffer, 0, 14); var ledMatrix = new LedMatrix(); await ledMatrix.InitializeAsync(64); //ledMatrix.Clean(); //ledMatrix.Write(0, 100, 00, 0); //ledMatrix.Write(8, 0, 100, 0); //ledMatrix.Write(16, 0, 0, 100); //ledMatrix.RefreshLeds(); Random random = new Random(); while (true) { ledMatrix.Clean(); ledMatrix.Write(random.Next(0, 63), (byte)random.Next(0, 50), (byte)random.Next(0, 50), (byte)random.Next(0, 50)); ledMatrix.Write(random.Next(0, 63), (byte)random.Next(0, 50), (byte)random.Next(0, 50), (byte)random.Next(0, 50)); ledMatrix.Write(random.Next(0, 63), (byte)random.Next(0, 50), (byte)random.Next(0, 50), (byte)random.Next(0, 50)); ledMatrix.Write(random.Next(0, 63), (byte)random.Next(0, 50), (byte)random.Next(0, 50), (byte)random.Next(0, 50)); ledMatrix.RefreshLeds(); Thread.Sleep(1); } } }
private void ReInitializeMatrix() { this.CloseMatrix(); this.m_matrix = new LedMatrix(this.m_options); this.m_threadDisplay = new Thread(this.Display); this.m_threadDisplay.Name = "matrix_display"; this.m_threadDisplay.Start(); }
public MainWindow() : base(Gtk.WindowType.Toplevel) { Build(); entry_address.ModifyBase(StateType.Normal, new Gdk.Color(255, 0, 0)); led_matrix = new LedMatrix("0.0.0.0"); led_matrix_thread = new Thread(led_matrix.Runner); winamp = new Winamp_httpQ(); rss = new RssPlugin(); no_tray_icon = false; IPEndPoint mpc_endpoint; led_matrix.rss = rss; mpc_plugin = new Mpc(); mpd_timer = new System.Timers.Timer(); mpd_timer.Elapsed += new ElapsedEventHandler(mpd_timer_elapsed); mpd_timer.Interval = 1000; //1s mpd_timer.Start(); try { tray_icon = new StatusIcon(new Gdk.Pixbuf("icon.png")); } catch (Exception) { no_tray_icon = true; } if (no_tray_icon == false) { tray_icon.Visible = true; tray_icon.Tooltip = "LedMatrix Control"; tray_icon.Activate += delegate { this.Visible = !this.Visible; }; } loadConfig(); led_matrix.connection_status_changed_handler += led_matrix_connection_changed; led_matrix_thread.Start(); winamp.title_changed_handler += led_matrix.setWinampPlaylisttitle; winamp.connection_changed_handler += winamp_connection_changed; try { //mpc_endpoint = new IPEndPoint(Dns.GetHostAddresses("dockstar-bo-hdd")[0], 6600); mpc_endpoint = new IPEndPoint(Dns.GetHostAddresses(entry_mpd.Text)[0], 6600); mpc_con = new MpcConnection(mpc_endpoint); mpc_plugin.Connection = mpc_con; mpc_plugin.Connection.AutoConnect = true; } catch (Exception) { } user_lines_table = new userLinesTable(ref treeview2, ref led_matrix); }
public userLinesTable(ref Gtk.TreeView treeview, ref LedMatrix led) { user_lines = new ArrayList(); loop_timer = new System.Timers.Timer(); loop_timer.Elapsed += new ElapsedEventHandler(loop_timer_elapsed); led_matrix = led; treeview2 = treeview; load_config(); treeView_lines_setup(); }
public MainWindow() : base(Gtk.WindowType.Toplevel) { Build (); entry_address.ModifyBase(StateType.Normal, new Gdk.Color(255,0,0)); led_matrix = new LedMatrix("0.0.0.0"); led_matrix_thread = new Thread(led_matrix.Runner); winamp = new Winamp_httpQ(); rss = new RssPlugin(); no_tray_icon = false; IPEndPoint mpc_endpoint; led_matrix.rss = rss; mpc_plugin = new Mpc(); mpd_timer = new System.Timers.Timer(); mpd_timer.Elapsed += new ElapsedEventHandler(mpd_timer_elapsed); mpd_timer.Interval = 1000; //1s mpd_timer.Start(); try { tray_icon = new StatusIcon(new Gdk.Pixbuf("icon.png")); } catch(Exception) { no_tray_icon = true; } if(no_tray_icon == false) { tray_icon.Visible = true; tray_icon.Tooltip = "LedMatrix Control"; tray_icon.Activate += delegate { this.Visible = !this.Visible; }; } loadConfig(); led_matrix.connection_status_changed_handler += led_matrix_connection_changed; led_matrix_thread.Start(); winamp.title_changed_handler += led_matrix.setWinampPlaylisttitle; winamp.connection_changed_handler += winamp_connection_changed; try { //mpc_endpoint = new IPEndPoint(Dns.GetHostAddresses("dockstar-bo-hdd")[0], 6600); mpc_endpoint = new IPEndPoint(Dns.GetHostAddresses(entry_mpd.Text)[0], 6600); mpc_con = new MpcConnection(mpc_endpoint); mpc_plugin.Connection = mpc_con; mpc_plugin.Connection.AutoConnect = true; } catch(Exception) { } user_lines_table = new userLinesTable(ref treeview2, ref led_matrix); }
public SenseHat( LedMatrix ledMatrix, Joystick joystick, TemparatureSensor temparatureSensor) { Guard.ObjectNotNull(() => ledMatrix); Guard.ObjectNotNull(() => joystick); Guard.ObjectNotNull(() => temparatureSensor); LedMatrix = ledMatrix; Joystick = joystick; TemparatureSensor = temparatureSensor; }
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)); }); }
async Task ShowScore(int score) { var text = $"Your score: {score}"; RunOnUiThread(() => ScoreView.Text = text); foreach (var character in text) { using (var ledMatrix = new LedMatrix()) { ledMatrix.Draw(character, Color.Argb(100, 255, 255, 255), Color.Argb(255, 0, 50, 0)); } await Task.Delay(800); } }
public static int Main(string[] args) { var matrix = new LedMatrix(new LedMatrixOptions(), args); var canvas = matrix.CreateOffscreenCanvas(); var maxBrightness = matrix.Brightness; var count = 0; const int c = 255; while (!Console.KeyAvailable) { if (matrix.Brightness < 1) { matrix.Brightness = maxBrightness; count += 1; } else { matrix.Brightness -= 1; } switch (count % 4) { case 0: canvas.Fill(new Color(c, 0, 0)); break; case 1: canvas.Fill(new Color(0, c, 0)); break; case 2: canvas.Fill(new Color(0, 0, c)); break; case 3: canvas.Fill(new Color(c, c, c)); break; } canvas = matrix.SwapOnVsync(canvas); Thread.Sleep(20); } return(0); }
public LEDInteractionManager(LedMatrix emulator, IInteractionInput input) { this.emulator = emulator; this.input = input; emulatorBounds = emulator.getLedBound(); arrow = GameObject.Find("Arrow").transform; GameObject ring = GameObject.Find("RingPro"); pos = new Vector3(emulatorBounds.center.x, 0, emulatorBounds.center.z); for (int i = 0; i < rings.Length; i++) { rings[i] = GameObject.Instantiate(ring, pos, Quaternion.identity) as GameObject; rings[i].name = "InteractionRing" + i; } ring.SetActive(false); r = emulatorBounds.extents.x * 1.414f / 100f; r0 = r + 0.5f; r1 = r + 4f; r2 = r + 6f; rings[0].transform.localScale = Vector3.one * r0; rings[1].transform.localScale = Vector3.one * r1; rings[2].transform.localScale = Vector3.one * r2; float near = r0 * 100f; float far = r2 * 100f; //GameObject woman = GameObject.Find("Human_Women"); models[0] = (GameObject)GameObject.Instantiate(Resources.Load("Human_Woman"), Vector3.zero, Quaternion.identity); models[1] = (GameObject)GameObject.Instantiate(Resources.Load("Human_Girl"), Vector3.zero, Quaternion.identity); models[2] = (GameObject)GameObject.Instantiate(Resources.Load("Human_Man"), Vector3.zero, Quaternion.identity); models[3] = (GameObject)GameObject.Instantiate(Resources.Load("Human_Boy"), Vector3.zero, Quaternion.identity); foreach (GameObject m in models) { m.SetActive(false); } for (int i = 0; i < peopleCountOnStartup; i++) { emitPeople(); } }
private int OnExecute() { var matrix = new LedMatrix(new LedMatrixOptions()); var canvas = matrix.CreateOffscreenCanvas(); var font = new BdfFont(Font); canvas.DrawText(font, XOrigin, YOrigin + font.Baseline, new Color(0, 255, 0), Text, Spacing); matrix.SwapOnVsync(canvas); while (!Console.KeyAvailable) { Thread.Sleep(250); } return(0); }
public SenseHat Create() { _devicePythonFileFactory.AssureInitialized(); var ledMatrixScriptPath = _devicePythonFileFactory.CreateScriptFile(typeof(LedMatrix)); var led = new LedMatrix(_pythonExecutor, ledMatrixScriptPath); var joystickScriptPath = _devicePythonFileFactory.CreateScriptFile(typeof(Joystick)); var joystick = new Joystick(_pythonExecutor, joystickScriptPath); var temparatureSensorScriptPath = _devicePythonFileFactory.CreateScriptFile(typeof(TemparatureSensor)); var tempSensor = new TemparatureSensor(_pythonExecutor, temparatureSensorScriptPath); var senseHat = new SenseHat(led, joystick, tempSensor); return(senseHat); }
private static int RunApplication(IServiceProvider svc) { //TODO put in config const int camNumber = 0; IBcmHost host = svc.GetRequiredService <IBcmHost>(); LedMatrix matrix = svc.GetRequiredService <LedMatrix>(); 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(); while (true) { //TODO : capture image matrix.UpdateCanvas(canvas => { //TODO : put image to canvas }); } } app.Error.WriteLine("Camera capture not implemented"); return(-1); }
public static int Main(string[] args) { var matrix = new LedMatrix(new LedMatrixOptions(), args); var canvas = matrix.CreateOffscreenCanvas(); for (var i = 0; i < 1000; ++i) { for (var y = 0; y < canvas.Height; ++y) { for (var x = 0; x < canvas.Width; ++x) { canvas.SetPixel(x, y, new Color(i & 0xff, x, y)); } } canvas.DrawCircle(canvas.Width / 2, canvas.Height / 2, 6, new Color(0, 0, 255)); canvas.DrawLine(canvas.Width / 2 - 3, canvas.Height / 2 - 3, canvas.Width / 2 + 3, canvas.Height / 2 + 3, new Color(0, 0, 255)); canvas.DrawLine(canvas.Width / 2 - 3, canvas.Height / 2 + 3, canvas.Width / 2 + 3, canvas.Height / 2 - 3, new Color(0, 0, 255)); canvas = matrix.SwapOnVsync(canvas); } return(0); }
/// <summary> /// Constructs a new set of eyes. /// </summary> public EyesDisplay() { // mind that you can use the separate application called EyeDesigner (also in this repository) to calculate the desired byte values // the first eight byte values are used for the left eye and the second eight byte values for the right eye expressions = new Dictionary <Emotions, byte[]> { { Emotions.Anger, new byte[] { 0x00, 0x07, 0x8F, 0x99, 0xB1, 0xB1, 0x1F, 0x00, 0x00, 0x38, 0x7C, 0x66, 0x63, 0x63, 0x3E, 0x00 } }, { Emotions.Contempt, new byte[] { 0x00, 0x00, 0xBF, 0xA3, 0xA3, 0xBF, 0x1F, 0x00, 0x00, 0x00, 0x7F, 0x47, 0x47, 0x7F, 0x3E, 0x00 } }, { Emotions.Disgust, new byte[] { 0x00, 0x1F, 0xBF, 0xA3, 0xA3, 0xBF, 0x1F, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x71, 0x3E, 0x00, 0x00 } }, { Emotions.Fear, new byte[] { 0x00, 0x1F, 0xBF, 0xB1, 0xB1, 0xB1, 0x1F, 0x00, 0x00, 0x3E, 0x7F, 0x63, 0x63, 0x63, 0x3E, 0x00 } }, { Emotions.Happiness, new byte[] { 0x0E, 0x1F, 0xBF, 0xB1, 0xB1, 0xBF, 0x1F, 0x00, 0x1C, 0x3E, 0x7F, 0x63, 0x63, 0x7F, 0x3E, 0x00 } }, { Emotions.Neutral, new byte[] { 0x00, 0x1F, 0xBF, 0xB1, 0xB1, 0xBF, 0x1F, 0x00, 0x00, 0x3E, 0x7F, 0x63, 0x63, 0x7F, 0x3E, 0x00 } }, { Emotions.Sadness, new byte[] { 0x00, 0x00, 0xBF, 0xBF, 0xB1, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x63, 0x3E, 0x00, 0x00 } }, { Emotions.Surprise, new byte[] { 0x0E, 0x1F, 0xB1, 0xB1, 0xB1, 0xB1, 0x1F, 0x0E, 0x1C, 0x3E, 0x63, 0x63, 0x63, 0x63, 0x3E, 0x1C } }, { Emotions.Sleep, new byte[] { 0x00, 0x00, 0x00, 0x00, 0xA1, 0xBF, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x7F, 0x1E, 0x00 } }, { Emotions.Blink, new byte[] { 0x00, 0x00, 0x00, 0xBF, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x00, 0x00, 0x00 } } }; leftEye = new LedMatrix(0x71); rightEye = new LedMatrix(0x72); currentExpression = Emotions.Neutral; SetEmotion(currentExpression); }
// Use this for initialization void Start() { Debug.Log("Start"); Loom.Initialize(); //touchControlThread = new Thread(touchControl); //touchControlThread.Start(); //sonicControlThread = new Thread(sonicControl); //sonicControlThread.Start(); //gestureControlThread = new Thread(gestureControl); //gestureControlThread.Start(); giraffe = GameObject.Find("/Giraffe"); dolphin = GameObject.Find("/dolphin"); fish = GameObject.Find("transformFizzBait"); fishanimator = GameObject.Find("/fish"); sth = GameObject.Find("/sth"); glow = GameObject.Find("/Glow"); glowps = glow.GetComponent <ParticleSystem>(); ripple = GameObject.Find("/Ripple"); rippleps = ripple.GetComponent <ParticleSystem>(); bubble = GameObject.Find("/bubble"); buddy = GameObject.Find("U_Char"); face = GameObject.Find("Bruce_Willis_Face"); stag = GameObject.Find("STAG/STAG"); GameObject test = GameObject.Find("/test"); GameObject mermaid = GameObject.Find("/Mermaid/Mermaid"); Animator aa = null; if (fishanimator != null) { aa = fishanimator.GetComponent <Animator>(); aa.speed = 0.4f; } //objectsWorld = new Bounds(new Vector3(0, 11.5f, 0), new Vector3(7, 11.5f, 7) * 2); //particlesWorld = new Bounds(new Vector3(0, 36, 0), new Vector3(18, 36, 18) * 2); objectsWorld = new Bounds(new Vector3(0, 9f, 0), new Vector3(18, 9f, 18) * 2); //particlesWorld = new Bounds(new Vector3(0, 18, 0), new Vector3(27, 18, 27) * 2); particlesWorld = new Bounds(new Vector3(0, 18, 0), new Vector3(27, 18, 27) * 2); //ParticleSystem p = GameObject.Find("/FireworksGood").GetComponent<ParticleSystem>(); HashSet <IParticleObject> pos = new HashSet <IParticleObject> { //new ParticleSystemObject(particlesWorld, rippleps, new Vector2()) }; objs = new HashSet <IMeshObject> { //new VoxObject { // gameObject = GameObject.Find("11_Hand_Right"), // mode = MeshMode.MeshFilterMode, // transform = GameObject.Find("11_Hand_Right").transform, //}, //new VoxObject { // gameObject = GameObject.Find("07_Hand_Left"), // mode = MeshMode.MeshFilterMode, // transform = GameObject.Find("07_Hand_Left").transform, //}, //new VoxObject { // gameObject = face, // mode = MeshMode.SkinnedMeshRendererMode, // transform = face.transform, //}, //new VoxObject { // gameObject = buddy, // mode = MeshMode.SkinnedMeshRendererMode, // transform = buddy.transform, //}, //new VoxObject{ // gameObject = dd, // mode = MeshMode.MeshFilterMode, // transform = dd.transform //}, }; //extract(new Transform[] //{ // //GameObject.Find("/flower01").transform, // //GameObject.Find("/flower02").transform, // //GameObject.Find("/flower03").transform, // //GameObject.Find("/flower05").transform, // //GameObject.Find("/rose").transform, // //GameObject.Find("/flower06").transform, //}, objs); //CubeLedSeq s = new CubeLedSeq(21, 33, 21); //CylinderLeqSeq s = new CylinderLeqSeq(56, 12, 7, 7, 5, 7); CylinderLeqSeq s = new CylinderLeqSeq(25, 8, 15f, 15f, 6f, 8.5f); //CylinderLeqSeq s = new CylinderLeqSeq(40, 12, 15f, 15f, 6f, 8.5f); //CylinderLeqSeq s = new CylinderLeqSeq(32, 2, 15, 15, 6, 0); //CylinderLeqSeq s = new CylinderLeqSeq(80, 18, 15, 15, 6, 0); ledseq = s; //s.open("C:\\Users\\yqf\\Desktop\\test.ledseq", 30 * 20); //vox = new CubeMeshVox(s, objs, objectsWorld); //vox = new CylinderMeshVox(s, objectsWorld, objs); vox.Start(); MeshVox.setGradientColor(false, 1, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff); MeshVox.setSolidFill(true); //MeshVox.setFillColor(0x7f7f7f00); pvox = new CylinderParticleVox(s, particlesWorld, pos); //matrix = new CubeLedMatrix(s); matrix = new CylinderLedMatrix(s); //bridge = new CylinderBigLedBridge(s); ledWorld = matrix.getLedBound(); }
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); } }
private void Show() { var pixels = new Pixels(ImmutableList.CreateRange(_currentStatuses)); LedMatrix.SetPixels(pixels); }
/// <summary> /// Write colors to LED matrix /// </summary> /// <param name="colors">Buffer of colors</param> public void Write(ReadOnlySpan <Color> colors) => LedMatrix.Write(colors);
/// <summary> /// Sets color on specified pixel on LED matrix /// </summary> /// <param name="x">X coordinate of the pixel</param> /// <param name="y">Y coordinate of the pixel</param> /// <param name="color">Color to set the pixel to</param> public void SetPixel(int x, int y, Color color) => LedMatrix.SetPixel(x, y, color);
// Use this for initialization void Start() { UnityEngine.Debug.Log("Start"); Loom.Initialize(); initWorkers(workers); foreach (Thread w in workers) { w.Start(); } Vector3 ratio = ledseq.getRatio(); objectsWorld = new Bounds(objectWorldCenter, 2 * objectWorldExtend * ratio); particlesWorld = new Bounds(particlesWorldCenter, 2 * particlesWorldExtend * ratio); if (NeedSaveSeq) { ledseq.open(SeqName, SeqFrames); } if (NeedObjectVox) { initVoxObjects(objs); initMeshListeners(liss); vox = initMeshVox(ledseq, objectsWorld, objs); vox.Start(); MeshVox.setGradientColor(NeedGradientColor, 1, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff); MeshVox.setSolidFill(NeedSolidFill); MeshVox.setFillColor(fillColor); } if (NeedParticleVox) { initParticleObjects(pos); initParticleListeners(pliss); pvox = initParticleVox(ledseq, particlesWorld, pos); } if (NeedClickRipple) { glow = GameObject.Find("/Glow"); glowps = glow.GetComponent <ParticleSystem>(); ripple = GameObject.Find("/Ripple"); rippleps = ripple.GetComponent <ParticleSystem>(); if (ripple.GetComponent <IParticleObject>() != null) { pos.Add(ripple.GetComponent <IParticleObject>()); } } if (NeedEmulator) { emulator = initEmulator(ledseq); ledWorld = emulator.getLedBound(); GameObject marker = new GameObject("Marker"); marker.transform.position = ledWorld.center; } if (NeedInteraction) { interaction = new LEDInteractionManager(emulator, this); } if (NeedBridge) { bridge = initBridge(ledseq); } }
private static int RunApp() { app.Out.WriteLine("Hello World!"); if (String.IsNullOrEmpty(image.Value)) { app.ShowHelp(); return(-1); } if (!File.Exists(image.Value)) { app.Error.WriteLine("File not found"); return(-1); } int brightnessValue = 0; 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); } } Stopwatch swatch = Stopwatch.StartNew(); using (LedMatrixOptions options = new LedMatrixOptions() { chain_length = 2, rows = 64, led_rgb_sequence = "RBG", brightness = brightnessValue, }) using (Image <Rgba32> gif = Image.Load(image.Value)) //using (LedMatrix matrix = new LedMatrix(rows: 64, chained: 2, parallel: 1)) using (LedMatrix matrix = new LedMatrix(options)) { Size size = new Size(matrix.CanvasWidth, matrix.CanvasHeight); int framesCount = gif.Frames.Count; Console.WriteLine("Canvas size: {0}x{1}", size.Width, size.Height); gif.Mutate(ops => { ops.Resize(size); }); //string path = Path.Combine(Environment.CurrentDirectory, "block64.gif"); //Console.WriteLine("Saving path={0}", path); //using (var output = File.Create(path)) //{ // gif.SaveAsGif(output); //} bool run = true; Console.CancelKeyPress += (s, e) => { if (run) { run = false; e.Cancel = true; } }; while (run) { for (int i = 0; i < framesCount; i++) { long cur = swatch.ElapsedMilliseconds; var frame = gif.Frames[i]; matrix.UpdateCanvas(canvas => { for (int x = 0; x < size.Width; x++) { for (int y = 0; y < size.Height; y++) { Rgba32 pix = frame[x, y]; canvas.SetPixel(x, y, pix.R, pix.G, pix.B); } } Console.Write("."); }); //matrix.UpdateCanvasAsImageSharp(canvasImage => //{ // canvasImage.DrawImage(frames[i].Image, 1, size, Point.Empty); //}); long elapsed = swatch.ElapsedMilliseconds - cur; long wait = frame.MetaData.FrameDelay * 10 - elapsed; if (wait > 0) { Thread.Sleep((int)wait); } } } } return(0); }
// LED Matrix /// <summary> /// Fills LED matrix with specified color /// </summary> /// <param name="color">Color to fill LED matrix with</param> public void Fill(Color color = default(Color)) => LedMatrix.Fill(color);
public static int Main(string[] args) { var matrix = new LedMatrix(new LedMatrixOptions(), args); var canvas = matrix.CreateOffscreenCanvas(); var rnd = new Random(); var points = new List <Point>(); var recycled = new Stack <Point>(); int frame = 0; var stopwatch = new Stopwatch(); while (!Console.KeyAvailable) { stopwatch.Restart(); frame++; if (frame % FRAME_STEP == 0) { if (recycled.Count == 0) { points.Add(new Point(rnd.Next(0, canvas.Width), 0)); } else { var point = recycled.Pop(); point.X = rnd.Next(0, canvas.Width); point.Y = 0; point.Recycled = false; } } canvas.Clear(); foreach (var point in points) { if (!point.Recycled) { point.Y++; if (point.Y - MAX_HEIGHT > canvas.Height) { point.Recycled = true; recycled.Push(point); } for (var i = 0; i < MAX_HEIGHT; i++) { canvas.SetPixel(point.X, point.Y - i, new Color(0, 255 - i * COLOR_STEP, 0)); } } } canvas = matrix.SwapOnVsync(canvas); // force 30 FPS var elapsed = stopwatch.ElapsedMilliseconds; if (elapsed < 33) { Thread.Sleep(33 - (int)elapsed); } } return(0); }