Esempio n. 1
0
        // Methods

        /// <summary>
        /// Get sensor
        /// </summary>
        /// <returns></returns>
        protected override YSensor GetSensor()
        {
            string errmsg = "";

            if (hardwaredetect == 0)
            {
                YAPI.UpdateDeviceList(ref errmsg);
            }
            hardwaredetect = (hardwaredetect + 1) % 20;
            YAPI.HandleEvents(ref errmsg);
            YSensor sensor = YPressure.FirstPressure();

            if (sensor is null)
            {
                throw new SensorNotDetectedException();
            }
            else if (!sensor.isOnline())
            {
                throw new SensorOfflineException();
            }
            else
            {
                return(sensor);
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            YModule m;
            string  errmsg = "";

            if (YAPI.RegisterHub("usb", ref errmsg) == YAPI.SUCCESS)
            {
                notifyIcon1.ShowBalloonTip(5, "PsymonWeather Beta", "Connection effectuée", ToolTipIcon.Info);
                timer1.Enabled             = true;
                btnConnexion.Enabled       = false;
                btnDeco.Enabled            = true;
                toolStripStatusLabel1.Text = "Connecté : Oui";
                m = YModule.FindModule("PsymonWeather");
                lblSerial.Text       = m.get_firmwareRelease().ToString();
                progressTemp.Minimum = 0;
                progressTemp.Maximum = 40;
                YTemperature temp = YTemperature.FindTemperature("temperature");
                progressTemp.Value = (int)temp.get_currentValue();
                lblTemp.Text       = string.Format("{0} °C", temp.get_currentValue());
                YHumidity humid = YHumidity.FindHumidity("humidity");
                lblHumid.Text = string.Format("{0} % d'humidité", humid.get_currentValue());
                YPressure pressure = YPressure.FindPressure("pressure");
                lblPressure.Text = string.Format("{0} Bar", pressure.get_currentValue());
                notifyIcon1.Text = string.Format("PsymonWeather Beta\nTemp. : {0}\nHumid. : {1}\nPress. : {2}", temp.get_currentValue(), humid.get_currentValue(), pressure.get_currentValue());
            }
            else
            {
                toolStripStatusLabel1.Text = "Connecté : Erreur";
                MessageBox.Show("Le module n'est pas branché.");
            }
        }
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YPressure hwd = YPressure.FindPressure(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YPressure hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering Pressure callback");
     _func.registerValueCallback(valueChangeCallback);
 }
    /**
     * <summary>
     *   Retrieves a pressure sensor 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 pressure sensor is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YPressure.isOnline()</c> to test if the pressure sensor is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a pressure sensor 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 pressure sensor
     * </param>
     * <returns>
     *   a <c>YPressure</c> object allowing you to drive the pressure sensor.
     * </returns>
     */
    public static YPressure FindPressure(string func)
    {
        YPressure obj;

        obj = (YPressure)YFunction._FindFromCache("Pressure", func);
        if (obj == null)
        {
            obj = new YPressure(func);
            YFunction._AddToCache("Pressure", func, obj);
        }
        return(obj);
    }
Esempio n. 6
0
    // --- (end of YPressure implementation)

    // --- (Pressure functions)

    /**
     * <summary>
     *   Retrieves a pressure sensor 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 pressure sensor is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YPressure.isOnline()</c> to test if the pressure sensor is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a pressure sensor 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 pressure sensor
     * </param>
     * <returns>
     *   a <c>YPressure</c> object allowing you to drive the pressure sensor.
     * </returns>
     */
    public static YPressure FindPressure(string func)
    {
        YPressure res;

        if (_PressureCache.ContainsKey(func))
        {
            return((YPressure)_PressureCache[func]);
        }
        res = new YPressure(func);
        _PressureCache.Add(func, res);
        return(res);
    }
        /**
         * <summary>
         *   Enumerates all functions of type Pressure 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>YPressure.FindPressure</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>();
            YPressure     it  = YPressure.FirstPressure();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextPressure();
            }
            return(res.ToArray());
        }
        public static YPressureProxy FindPressure(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YPressure      func = null;
            YPressureProxy res  = (YPressureProxy)YFunctionProxy.FindSimilarUnknownFunction("YPressureProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YPressureProxy)YFunctionProxy.FindSimilarKnownFunction("YPressureProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YPressure.FirstPressure();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YPressureProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YPressure.FindPressure(name);
                if (func.get_userData() != null)
                {
                    return((YPressureProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YPressureProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;

            YPressure psensor;

            if (args.Length < 1)
            {
                usage();
            }
            target = args[0].ToUpper();

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                psensor = YPressure.FirstPressure();

                if (psensor == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                psensor = YPressure.FindPressure(target + ".pressure");
            }

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

            while (psensor.isOnline())
            {
                Console.WriteLine("Current pressure: " + psensor.get_currentValue().ToString()
                                  + " mbar");
                Console.WriteLine("  (press Ctrl-C to exit)");

                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Esempio n. 10
0
        public void reloadInfos()
        {
            YTemperature temp = YTemperature.FindTemperature("temperature");

            progressTemp.Value = (int)temp.get_currentValue();
            lblTemp.Text       = string.Format("{0} °C", temp.get_currentValue());
            YHumidity humid = YHumidity.FindHumidity("humidity");

            lblHumid.Text = string.Format("{0} % d'humidité", humid.get_currentValue());
            YPressure pressure = YPressure.FindPressure("pressure");

            lblPressure.Text = string.Format("{0} Bar", pressure.get_currentValue());
            notifyIcon1.Text = string.Format("PsymonWeather Beta\nTemp. : {0} °C\nHumid. : {1}\nPress. : {2} Bar", temp.get_currentValue(), humid.get_currentValue(), pressure.get_currentValue());
        }
Esempio n. 11
0
	// Use this for initialization
	void Start ()
	{
		string version;
		if (IntPtr.Size == 4) {
			version = "Unity: 32 bits";
		} else {
			version = "Unity: 64 bits";
		}
		version += " / Yoctopuce:" + YAPI.GetAPIVersion ();
		versionText.text = version;
		string msg = "";
		if (YAPI.RegisterHub ("usb", ref msg) != YAPI.SUCCESS) {
			state = State.ERROR;
			errmsg = msg;
			return;
		}
		YModule module = YModule.FirstModule ();
		while (module!=null) {
			string product = module.get_productName ();
			string serial = module.get_serialNumber ();
			if (product == "Yocto-Meteo") {
				meteoSerial = serial;
				temperatureSensor = YTemperature.FindTemperature (serial + ".temperature");
				humiditySensor = YHumidity.FindHumidity (serial + ".humidity");
				pressureSensor = YPressure.FindPressure (serial + ".pressure");
			} else if (product == "Yocto-Color") {
				colorSerial = serial;
				led1 = YColorLed.FindColorLed (serial + ".colorLed1");
				led2 = YColorLed.FindColorLed (serial + ".colorLed2");
			}				 
			module = module.nextModule ();
		}
		if (meteoSerial == null) {
			errmsg = "No Yocto-Meteo detected";
			state = State.ERROR;
		} else if (colorSerial == null) {
			errmsg = "No Yocto-color detected";
			state = State.ERROR;
		} else {
			state = State.HOME;
		}


	}
Esempio n. 12
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YHumidity    hsensor;
                YTemperature tsensor;
                YPressure    psensor;

                if (Target.ToLower() == "any")
                {
                    hsensor = YHumidity.FirstHumidity();
                    tsensor = YTemperature.FirstTemperature();
                    psensor = YPressure.FirstPressure();

                    if ((hsensor == null) || (tsensor == null) || (psensor == null))
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    hsensor = YHumidity.FindHumidity(Target + ".humidity");
                    tsensor = YTemperature.FindTemperature(Target + ".temperature");
                    psensor = YPressure.FindPressure(Target + ".pressure");
                }

                while (await hsensor.isOnline())
                {
                    WriteLine("Humidity:    " + await hsensor.get_currentValue() + " %RH");
                    WriteLine("Temperature: " + await tsensor.get_currentValue() + " °C");
                    WriteLine("Pressure:    " + await psensor.get_currentValue() + " hPa");
                    await YAPI.Sleep(1000);
                }

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

            YAPI.FreeAPI();
            return(0);
        }
Esempio n. 13
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YPressure psensor;

                if (Target.ToLower() == "any")
                {
                    psensor = YPressure.FirstPressure();

                    if (psensor == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    psensor = YPressure.FindPressure(Target + ".pressure");
                }

                while (await psensor.isOnline())
                {
                    WriteLine("Pressure: " + await psensor.get_currentValue() + " mbar");
                    await YAPI.Sleep(1000);
                }

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

            YAPI.FreeAPI();
            return(0);
        }
        // property cache
        //--- (end of YPressure definitions)

        //--- (YPressure implementation)
        internal YPressureProxy(YPressure hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("Pressure " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }
 /**
  * <summary>
  *   Retrieves a pressure sensor 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 pressure sensor is online at the time
  *   it is invoked. The returned object is nevertheless valid.
  *   Use the method <c>YPressure.isOnline()</c> to test if the pressure sensor is
  *   indeed online at a given time. In case of ambiguity when looking for
  *   a pressure sensor 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 pressure sensor
  * </param>
  * <returns>
  *   a <c>YPressure</c> object allowing you to drive the pressure sensor.
  * </returns>
  */
 public static YPressure FindPressure(string func)
 {
     YPressure obj;
     obj = (YPressure) YFunction._FindFromCache("Pressure", func);
     if (obj == null) {
         obj = new YPressure(func);
         YFunction._AddToCache("Pressure", func, obj);
     }
     return obj;
 }
Esempio n. 16
0
 // --- (end of YPressure implementation)
 // --- (Pressure functions)
 /**
    * <summary>
    *   Retrieves a pressure sensor 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 pressure sensor is online at the time
    *   it is invoked. The returned object is nevertheless valid.
    *   Use the method <c>YPressure.isOnline()</c> to test if the pressure sensor is
    *   indeed online at a given time. In case of ambiguity when looking for
    *   a pressure sensor 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 pressure sensor
    * </param>
    * <returns>
    *   a <c>YPressure</c> object allowing you to drive the pressure sensor.
    * </returns>
    */
 public static YPressure FindPressure(string func)
 {
     YPressure res;
     if (_PressureCache.ContainsKey(func))
       return (YPressure)_PressureCache[func];
     res = new YPressure(func);
     _PressureCache.Add(func, res);
     return res;
 }
 // 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 = (YPressure)hwd;
     base.base_init(hwd, instantiationName);
 }