Example #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            string errmsg = "";

            if (hardwaredetect == 0)
            {
                YAPI.UpdateDeviceList(ref errmsg);
            }
            hardwaredetect = (hardwaredetect + 1) % 20;
            YAPI.HandleEvents(ref errmsg);
            if (sensor == null)
            {
                sensor = YSensor.FirstSensor();
            }
            if (sensor != null)
            {
                if (sensor.isOnline())
                {
                    label1.Text = sensor.get_friendlyName();
                    label2.Text = sensor.get_currentValue() + " " + sensor.get_unit();
                }
                else
                {
                    label1.Text = "OFFLINE";
                    label2.Text = "Sensor is offline";
                    sensor      = null;
                }
            }
        }
Example #2
0
        async Task dispatcherTimer_Tick()
        {
            try {
                if (hardwaredetect == 0)
                {
                    await YAPI.UpdateDeviceList();
                }

                hardwaredetect = (hardwaredetect + 1) % 20;
                await YAPI.HandleEvents();

                if (sensor == null)
                {
                    sensor = YSensor.FirstSensor();
                }
                if (sensor != null)
                {
                    HwIdTextBox.Text = await sensor.get_friendlyName();

                    TempTextBox.Text = await sensor.get_currentValue() + await sensor.get_unit();
                }
            } catch (YAPI_Exception ex) {
                HwIdTextBox.Text = "Sensor is offline";
                TempTextBox.Text = "OFFLINE";
                sensor           = null;
            }
        }
Example #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();
        }
Example #4
0
 protected override void moduleConfigHasChanged()
 {
     base.moduleConfigHasChanged();
     _currentValue = _func.get_currentValue();
     if (_currentValue == YAPI.INVALID_DOUBLE)
     {
         _currentValue = Double.NaN;
     }
     _unit            = _func.get_unit();
     _updateFrequency = _func.get_reportFrequency();
     if (_updateFrequency == "OFF")
     {
         _updateFrequency = "auto";
     }
     _logFrequency    = _func.get_logFrequency();
     _reportFrequency = _func.get_reportFrequency();
     _advMode         = _func.get_advMode() + 1;
     _resolution      = _func.get_resolution();
 }
Example #5
0
        private void DisplayValue(YSensor fct)
        {
            double value      = fct.get_currentValue();
            double rawvalue   = fct.get_currentRawValue();
            double resolution = fct.get_resolution();
            string valunit    = fct.get_unit();

            // displays the sensor value on the ui
            ValueDisplayUnits.Text = valunit;

            if (resolution != YSensor.RESOLUTION_INVALID)
            {  // if resolution is available on the device the use it to  round the value
                string format = "F" + ((int)-Math.Round(Math.Log10(resolution))).ToString();

                RawValueDisplay.Text = "(raw value: " + (resolution * Math.Round(rawvalue / resolution)).ToString(format) + ")";
                ValueDisplay.Text    = (resolution * Math.Round(value / resolution)).ToString(format);
            }
            else
            {
                ValueDisplay.Text    = value.ToString();
                RawValueDisplay.Text = "";
            }
        }