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
        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.º 3
0
 /**
  * <summary>
  *   Returns a YDisplayLayer object that can be used to draw on the specified
  *   layer.
  * <para>
  *   The content is displayed only when the layer is active on the
  *   screen (and not masked by other overlapping layers).
  * </para>
  * </summary>
  * <param name="layerId">
  *   the identifier of the layer (a number in range 0..layerCount-1)
  * </param>
  * <returns>
  *   an <c>YDisplayLayer</c> object
  * </returns>
  * <para>
  *   On failure, throws an exception or returns <c>null</c>.
  * </para>
  */
 public virtual YDisplayLayerProxy get_displayLayer(int layerId)
 {
     if (_func == null)
     {
         throw new YoctoApiProxyException("No Display connected");
     }
     return(new YDisplayLayerProxy(_func.get_displayLayer(layerId)));
 }
Exemplo n.º 4
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();
        }