Exemplo n.º 1
0
        public HamsterScreen(string hwid, bool useImperial)
        {
            if (hwid == "")
            {
                _display = YDisplay.FirstDisplay();
                if (_display == null)
                {
                    throw new Exception("No Yocto-Display connected");
                }
            }
            else
            {
                _display = YDisplay.FindDisplay(hwid);
                if (!_display.isOnline())
                {
                    throw new Exception("No Yocto-Display named " + hwid + "found");
                }
            }

            _useImperial = useImperial;
            _display.resetAll();
            _w       = _display.get_displayWidth();
            _h       = _display.get_displayHeight();
            _fgLayer = _display.get_displayLayer(2);
            _bgLayer = _display.get_displayLayer(1);
        }
Exemplo n.º 2
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YDisplay hwd = YDisplay.FindDisplay(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
Exemplo n.º 3
0
        public static YDisplayProxy FindDisplay(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YDisplay      func = null;
            YDisplayProxy res  = (YDisplayProxy)YFunctionProxy.FindSimilarUnknownFunction("YDisplayProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YDisplayProxy)YFunctionProxy.FindSimilarKnownFunction("YDisplayProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YDisplay.FirstDisplay();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YDisplayProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YDisplay.FindDisplay(name);
                if (func.get_userData() != null)
                {
                    return((YDisplayProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YDisplayProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            string        errmsg = "";
            string        target;
            YDisplay      disp;
            YDisplayLayer l1, l2;

            if (args.Length < 1)
            {
                usage();
            }

            target = args[0].ToUpper();

            // API init
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            // find the display according to command line parameters
            if (target == "ANY")
            {
                disp = YDisplay.FirstDisplay();
                if (disp == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                disp = YDisplay.FindDisplay(target + ".display");
            }


            if (!disp.isOnline())
            {
                Console.WriteLine("Module not connected (check identification and USB cable) ");
                Environment.Exit(0);
            }

            // display clean up
            disp.resetAll();

            l1 = disp.get_displayLayer(1);
            l2 = disp.get_displayLayer(2);
            l1.hide(); // L1 is hidden, l2 stay visible
            double centerX = disp.get_displayWidth() / 2;
            double centerY = disp.get_displayHeight() / 2;
            double radius  = disp.get_displayHeight() / 2;
            double a       = 0;

            while (true)
            {
                // we draw in the hidden layer
                l1.clear();
                for (int i = 0; i < 3; i++)
                {
                    recursiveLine(l1, centerX + radius * Math.Cos(a + i * 2.094),
                                  centerY + radius * Math.Sin(a + i * 2.094),
                                  centerX + radius * Math.Cos(a + (i + 1) * 2.094),
                                  centerY + radius * Math.Sin(a + (i + 1) * 2.094), 2);
                }
                // then we swap contents with the visible layer

                disp.swapLayerContent(1, 2);
                // change the flake angle
                a += 0.1257;
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            string        errmsg = "";
            string        target;
            YDisplay      disp;
            YDisplayLayer l0;
            int           count = 8;

            if (args.Length < 1)
            {
                usage();
            }

            target = args[0].ToUpper();

            // API init
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            // find the display according to command line parameters
            if (target == "ANY")
            {
                disp = YDisplay.FirstDisplay();
                if (disp == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                disp = YDisplay.FindDisplay(target + ".display");
            }


            if (!disp.isOnline())
            {
                Console.WriteLine("Module not connected (check identification and USB cable) ");
                Environment.Exit(0);
            }

            disp.resetAll();
            // retreive the display size

            int w = disp.get_displayWidth();
            int h = disp.get_displayHeight();

            //reteive the first layer
            l0 = disp.get_displayLayer(0);

            int[] coord = new int[2 * count + 1];

            // precompute the "leds" position
            int ledwidth = (w / count);

            for (int i = 0; i < count; i++)
            {
                coord[i] = i * ledwidth;
                coord[2 * count - i - 2] = coord[i];
            }

            int framesCount = 2 * count - 2;

            // start recording
            disp.newSequence();

            // build one loop for recording
            for (int i = 0; i < framesCount; i++)
            {
                l0.selectColorPen(0);
                l0.drawBar(coord[(i + framesCount - 1) % framesCount], h - 1,
                           coord[(i + framesCount - 1) % framesCount] + ledwidth, h - 4);
                l0.selectColorPen(0xffffff);
                l0.drawBar(coord[i], h - 1, coord[i] + ledwidth, h - 4);
                disp.pauseSequence(100); // records a 50ms pause.
            }
            // self-call : causes an endless looop
            disp.playSequence("K2000.seq");
            // stop recording and save to device filesystem
            disp.saveSequence("K2000.seq");

            // play the sequence
            disp.playSequence("K2000.seq");

            Console.WriteLine("This animation is running in background.");
        }
Exemplo n.º 6
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YDisplay      disp;
                YDisplayLayer l0, l1;
                int           h, w, y, x, vx, vy;

                // find the display according to command line parameters
                if (Target.ToLower() == "any")
                {
                    disp = YDisplay.FirstDisplay();
                    if (disp == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    disp = YDisplay.FindDisplay(Target + ".display");
                }

                if (!await disp.isOnline())
                {
                    WriteLine("Module not connected (check identification and USB cable) ");
                    return(-1);
                }

                //clean up
                await disp.resetAll();

                // retreive the display size
                w = await disp.get_displayWidth();

                h = await disp.get_displayHeight();

                // reteive the first layer
                l0 = await disp.get_displayLayer(0);

                // display a text in the middle of the screen
                await l0.drawText(w / 2, h / 2, YDisplayLayer.ALIGN.CENTER, Message);

                // visualize each corner
                await l0.moveTo(0, 5);

                await l0.lineTo(0, 0);

                await l0.lineTo(5, 0);

                await l0.moveTo(0, h - 6);

                await l0.lineTo(0, h - 1);

                await l0.lineTo(5, h - 1);

                await l0.moveTo(w - 1, h - 6);

                await l0.lineTo(w - 1, h - 1);

                await l0.lineTo(w - 6, h - 1);

                await l0.moveTo(w - 1, 5);

                await l0.lineTo(w - 1, 0);

                await l0.lineTo(w - 6, 0);

                // draw a circle in the top left corner of layer 1
                l1 = await disp.get_displayLayer(1);

                await l1.clear();

                await l1.drawCircle(h / 8, h / 8, h / 8);

                // and animate the layer
                x  = 0;
                y  = 0;
                vx = 1;
                vy = 1;
                while (await disp.isOnline())
                {
                    x += vx;
                    y += vy;
                    if ((x < 0) || (x > w - (h / 4)))
                    {
                        vx = -vx;
                    }
                    if ((y < 0) || (y > h - (h / 4)))
                    {
                        vy = -vy;
                    }
                    await l1.setLayerPosition(x, y, 0);

                    await YAPI.Sleep(5);
                }

                WriteLine("Module not connected (check identification and USB cable) ");
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            string        errmsg = "";
            string        target;
            YDisplay      disp;
            YDisplayLayer l0, l1;
            int           h, w, y, x, vx, vy;

            if (args.Length < 1)
            {
                usage();
            }

            target = args[0].ToUpper();

            // API init
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            // find the display according to command line parameters
            if (target == "ANY")
            {
                disp = YDisplay.FirstDisplay();
                if (disp == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                disp = YDisplay.FindDisplay(target + ".display");
            }

            if (!disp.isOnline())
            {
                Console.WriteLine("Module not connected (check identification and USB cable) ");
                Environment.Exit(0);
            }

            //clean up
            disp.resetAll();

            // retreive the display size
            w = disp.get_displayWidth();
            h = disp.get_displayHeight();

            // reteive the first layer
            l0 = disp.get_displayLayer(0);

            // display a text in the middle of the screen
            l0.drawText(w / 2, h / 2, YDisplayLayer.ALIGN.CENTER, "Hello world!");

            // visualize each corner
            l0.moveTo(0, 5);
            l0.lineTo(0, 0);
            l0.lineTo(5, 0);
            l0.moveTo(0, h - 6);
            l0.lineTo(0, h - 1);
            l0.lineTo(5, h - 1);
            l0.moveTo(w - 1, h - 6);
            l0.lineTo(w - 1, h - 1);
            l0.lineTo(w - 6, h - 1);
            l0.moveTo(w - 1, 5);
            l0.lineTo(w - 1, 0);
            l0.lineTo(w - 6, 0);

            // draw a circle in the top left corner of layer 1
            l1 = disp.get_displayLayer(1);
            l1.clear();
            l1.drawCircle(h / 8, h / 8, h / 8);

            // and animate the layer
            Console.WriteLine("Use Ctrl-C to stop");
            x  = 0;
            y  = 0;
            vx = 1;
            vy = 1;
            while (disp.isOnline())
            {
                x += vx;
                y += vy;
                if ((x < 0) || (x > w - (h / 4)))
                {
                    vx = -vx;
                }
                if ((y < 0) || (y > h - (h / 4)))
                {
                    vy = -vy;
                }
                l1.setLayerPosition(x, y, 0);
                YAPI.Sleep(5, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            string        errmsg = "";
            string        target;
            YDisplay      disp;
            YDisplayLayer l0;

            if (args.Length < 1)
            {
                usage();
            }

            target = args[0].ToUpper();

            // API init
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            // find the display according to command line parameters
            if (target == "ANY")
            {
                disp = YDisplay.FirstDisplay();
                if (disp == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                disp = YDisplay.FindDisplay(target + ".display");
            }


            if (!disp.isOnline())
            {
                Console.WriteLine("Module not connected (check identification and USB cable) ");
                Environment.Exit(0);
            }

            disp.resetAll();
            // retreive the display size
            int w = disp.get_displayWidth();
            int h = disp.get_displayHeight();

            // reteive the first layer
            l0 = disp.get_displayLayer(0);
            int bytesPerLines = w / 8;

            byte[] data = new byte[h * bytesPerLines];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = 0;
            }

            int    max_iteration = 50;
            int    iteration;
            double xtemp;
            double centerX = 0;
            double centerY = 0;
            double targetX = 0.834555980181972;
            double targetY = 0.204552998862566;
            double x, y, x0, y0;
            double zoom     = 1;
            double distance = 1;

            while (true)
            {
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = 0;
                }
                distance      = distance * 0.95;
                centerX       = targetX * (1 - distance);
                centerY       = targetY * (1 - distance);
                max_iteration = (int)Math.Round(max_iteration + Math.Sqrt(zoom));
                if (max_iteration > 1500)
                {
                    max_iteration = 1500;
                }
                for (int j = 0; j < h; j++)
                {
                    for (int i = 0; i < w; i++)
                    {
                        x0 = (((i - w / 2.0) / (w / 8)) / zoom) - centerX;
                        y0 = (((j - h / 2.0) / (w / 8)) / zoom) - centerY;

                        x = 0;
                        y = 0;

                        iteration = 0;

                        while ((x * x + y * y < 4) && (iteration < max_iteration))
                        {
                            xtemp      = x * x - y * y + x0;
                            y          = 2 * x * y + y0;
                            x          = xtemp;
                            iteration += 1;
                        }

                        if (iteration >= max_iteration)
                        {
                            data[j * bytesPerLines + (i >> 3)] |= (byte)(128 >> (i % 8));
                        }
                    }
                }

                l0.drawBitmap(0, 0, w, data, 0);
                zoom = zoom / 0.95;
            }
        }
Exemplo n.º 9
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YDisplay      disp;
                YDisplayLayer l0;

                // find the display according to command line parameters
                if (Target.ToLower() == "any")
                {
                    disp = YDisplay.FirstDisplay();
                    if (disp == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    disp = YDisplay.FindDisplay(Target + ".display");
                }

                if (!await disp.isOnline())
                {
                    WriteLine("Module not connected (check identification and USB cable) ");
                    return(-1);
                }

                WriteLine("Loot at the Yoctopuce display");

                //clean up
                await disp.resetAll();

                // retreive the display size
                int w = await disp.get_displayWidth();

                int h = await disp.get_displayHeight();

                // reteive the first layer
                l0 = await disp.get_displayLayer(0);

                int bytesPerLines = w / 8;

                byte[] data = new byte[h * bytesPerLines];
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = 0;
                }

                int    max_iteration = 50;
                int    iteration;
                double xtemp;
                double centerX = 0;
                double centerY = 0;
                double targetX = 0.834555980181972;
                double targetY = 0.204552998862566;
                double x, y, x0, y0;
                double zoom     = 1;
                double distance = 1;

                while (true)
                {
                    for (int i = 0; i < data.Length; i++)
                    {
                        data[i] = 0;
                    }
                    distance      = distance * 0.95;
                    centerX       = targetX * (1 - distance);
                    centerY       = targetY * (1 - distance);
                    max_iteration = (int)Math.Round(max_iteration + Math.Sqrt(zoom));
                    if (max_iteration > 1500)
                    {
                        max_iteration = 1500;
                    }
                    for (int j = 0; j < h; j++)
                    {
                        for (int i = 0; i < w; i++)
                        {
                            x0 = (((i - w / 2.0) / (w / 8)) / zoom) - centerX;
                            y0 = (((j - h / 2.0) / (w / 8)) / zoom) - centerY;

                            x = 0;
                            y = 0;

                            iteration = 0;

                            while ((x * x + y * y < 4) && (iteration < max_iteration))
                            {
                                xtemp      = x * x - y * y + x0;
                                y          = 2 * x * y + y0;
                                x          = xtemp;
                                iteration += 1;
                            }

                            if (iteration >= max_iteration)
                            {
                                data[j * bytesPerLines + (i >> 3)] |= (byte)(128 >> (i % 8));
                            }
                        }
                    }

                    await l0.drawBitmap(0, 0, w, data, 0);

                    zoom = zoom / 0.95;
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }