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
        static void Main(string[] args)
        {
            Console.WriteLine("Console dotNET Application 0.1.0");
            Console.WriteLine("--------------------------------");
            Console.WriteLine("");

            Console.WriteLine("Using Yoctopuce lib " + YAPI.GetAPIVersion());
            string errsmg = "";

            if (YAPI.RegisterHub("usb", ref errsmg) != YAPI.SUCCESS)
            {
                Console.WriteLine("Unable to register the USB port :" + errsmg);
                return;
            }

            YSensor sensor = YSensor.FirstSensor();

            if (sensor == null)
            {
                Console.WriteLine("No Yoctopuce sensor find on USB.");
                return;
            }

            YDisplay display = YDisplay.FirstDisplay();

            if (display == null)
            {
                Console.WriteLine("No Yoctopuce display find on USB.");
                return;
            }

            // display clean up
            display.resetAll();

            YDisplayLayer l1 = display.get_displayLayer(1);

            l1.hide();    // L1 is hidden, l2 stay visible
            int w = display.get_displayWidth();
            int h = display.get_displayHeight();


            while (sensor.isOnline() && display.isOnline())
            {
                string value = sensor.get_currentValue() + " " + sensor.get_unit();
                string name  = sensor.get_friendlyName();
                // display a text in the middle of the screen
                l1.clear();
                l1.selectFont("Large.yfm");
                l1.drawText(w / 2, h / 2, YDisplayLayer.ALIGN.CENTER, value);
                l1.selectFont("Small.yfm");
                l1.drawText(w - 1, h - 1, YDisplayLayer.ALIGN.BOTTOM_RIGHT, name);
                display.swapLayerContent(0, 1);
                Console.WriteLine(name + " ->" + value);
                YAPI.Sleep(500, ref errsmg);
            }
            YAPI.FreeAPI();
        }
Exemplo n.º 4
0
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YDisplay hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering Display callback");
     _func.registerValueCallback(valueChangeCallback);
 }
Exemplo n.º 5
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.º 6
0
        /**
         * <summary>
         *   Enumerates all functions of type Display available on the devices
         *   currently reachable by the library, and returns their unique hardware ID.
         * <para>
         *   Each of these IDs can be provided as argument to the method
         *   <c>YDisplay.FindDisplay</c> to obtain an object that can control the
         *   corresponding device.
         * </para>
         * </summary>
         * <returns>
         *   an array of strings, each string containing the unique hardwareId
         *   of a device function currently connected.
         * </returns>
         */
        public static new string[] GetSimilarFunctions()
        {
            List <string> res = new List <string>();
            YDisplay      it  = YDisplay.FirstDisplay();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextDisplay();
            }
            return(res.ToArray());
        }
Exemplo n.º 7
0
        private async void onLoad(object sender, RoutedEventArgs e)
        {
            try {
                await YAPI.RegisterHub("usb");

                sensor = YWeighScale.FirstWeighScale();
                if (sensor == null)
                {
                    await FatalError("No WeighScale connected");
                }

                display = YDisplay.FirstDisplay();
                if (display != null)
                {
                    //clean up
                    await display.resetAll();

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

                    h = await display.get_displayHeight();

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

                    l1 = await display.get_displayLayer(1);

                    // display a text in the middle of the screen
                    await l0.selectFont("Large.yfm");
                }
                await sensor.set_excitation(YWeighScale.EXCITATION_AC);

                await YAPI.Sleep(3000);

                await sensor.tare();

                unit = await sensor.get_unit();

                await sensor.registerValueCallback(sensorValueChangeCallBack);
            } catch (YAPI_Exception ex) {
                await FatalError(ex.Message);
            }

            timer          = new NonReentrantDispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            timer.TickTask = async() => { await dispatcherTimer_Tick(); };
            timer.Start();
        }
Exemplo n.º 8
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.º 9
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.º 10
0
 //--- (end of generated code: YDisplayLayer definitions)
 public YDisplayLayer(YDisplay parent, string id)
 {
     this._display = parent;
     this._id = Convert.ToInt32(id);
     //--- (generated code: YDisplayLayer attributes initialization)
     //--- (end of generated code: YDisplayLayer attributes initialization)
 }
Exemplo n.º 11
0
        //--- (end of YDisplay definitions)

        //--- (YDisplay implementation)
        internal YDisplayProxy(YDisplay hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("Display " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }
Exemplo n.º 12
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.º 13
0
 /**
  * <summary>
  *   Retrieves a display for a given identifier.
  * <para>
  *   The identifier can be specified using several formats:
  * </para>
  * <para>
  * </para>
  * <para>
  *   - FunctionLogicalName
  * </para>
  * <para>
  *   - ModuleSerialNumber.FunctionIdentifier
  * </para>
  * <para>
  *   - ModuleSerialNumber.FunctionLogicalName
  * </para>
  * <para>
  *   - ModuleLogicalName.FunctionIdentifier
  * </para>
  * <para>
  *   - ModuleLogicalName.FunctionLogicalName
  * </para>
  * <para>
  * </para>
  * <para>
  *   This function does not require that the display is online at the time
  *   it is invoked. The returned object is nevertheless valid.
  *   Use the method <c>YDisplay.isOnline()</c> to test if the display is
  *   indeed online at a given time. In case of ambiguity when looking for
  *   a display by logical name, no error is notified: the first instance
  *   found is returned. The search is performed first by hardware name,
  *   then by logical name.
  * </para>
  * </summary>
  * <param name="func">
  *   a string that uniquely characterizes the display
  * </param>
  * <returns>
  *   a <c>YDisplay</c> object allowing you to drive the display.
  * </returns>
  */
 public static YDisplay FindDisplay(string func)
 {
     YDisplay obj;
     obj = (YDisplay) YFunction._FindFromCache("Display", func);
     if (obj == null) {
         obj = new YDisplay(func);
         YFunction._AddToCache("Display", func, obj);
     }
     return obj;
 }
Exemplo n.º 14
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.º 15
0
 // perform the initial setup that may be done without a YoctoAPI object (hwd can be null)
 internal override void base_init(YFunction hwd, string instantiationName)
 {
     _func = (YDisplay)hwd;
     base.base_init(hwd, instantiationName);
 }
Exemplo n.º 16
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.º 17
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);
        }