Ejemplo n.º 1
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é.");
            }
        }
Ejemplo n.º 2
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);
            YHumidity sensor = YHumidity.FirstHumidity();

            if (sensor is null)
            {
                throw new SensorNotDetectedException();
            }
            else if (!sensor.isOnline())
            {
                throw new SensorOfflineException();
            }
            else
            {
                return(sensor);
            }
        }
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YHumidity hwd = YHumidity.FindHumidity(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(YHumidity hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering Humidity callback");
     _func.registerValueCallback(valueChangeCallback);
 }
Ejemplo n.º 5
0
    // --- (end of YHumidity implementation)

    // --- (Humidity functions)

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

        if (_HumidityCache.ContainsKey(func))
        {
            return((YHumidity)_HumidityCache[func]);
        }
        res = new YHumidity(func);
        _HumidityCache.Add(func, res);
        return(res);
    }
        public static YHumidityProxy FindHumidity(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YHumidity      func = null;
            YHumidityProxy res  = (YHumidityProxy)YFunctionProxy.FindSimilarUnknownFunction("YHumidityProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YHumidityProxy)YFunctionProxy.FindSimilarKnownFunction("YHumidityProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YHumidity.FirstHumidity();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YHumidityProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YHumidity.FindHumidity(name);
                if (func.get_userData() != null)
                {
                    return((YHumidityProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YHumidityProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
        /**
         * <summary>
         *   Enumerates all functions of type Humidity 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>YHumidity.FindHumidity</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>();
            YHumidity     it  = YHumidity.FirstHumidity();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextHumidity();
            }
            return(res.ToArray());
        }
Ejemplo n.º 8
0
    /**
     * <summary>
     *   Retrieves a humidity 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 humidity sensor is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YHumidity.isOnline()</c> to test if the humidity sensor is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a humidity 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 humidity sensor
     * </param>
     * <returns>
     *   a <c>YHumidity</c> object allowing you to drive the humidity sensor.
     * </returns>
     */
    public static YHumidity FindHumidity(string func)
    {
        YHumidity obj;

        obj = (YHumidity)YFunction._FindFromCache("Humidity", func);
        if (obj == null)
        {
            obj = new YHumidity(func);
            YFunction._AddToCache("Humidity", func, obj);
        }
        return(obj);
    }
Ejemplo n.º 9
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());
        }
Ejemplo n.º 10
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;
		}


	}
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
 // --- (end of YHumidity implementation)
 // --- (Humidity functions)
 /**
    * <summary>
    *   Retrieves a humidity 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 humidity sensor is online at the time
    *   it is invoked. The returned object is nevertheless valid.
    *   Use the method <c>YHumidity.isOnline()</c> to test if the humidity sensor is
    *   indeed online at a given time. In case of ambiguity when looking for
    *   a humidity 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 humidity sensor
    * </param>
    * <returns>
    *   a <c>YHumidity</c> object allowing you to drive the humidity sensor.
    * </returns>
    */
 public static YHumidity FindHumidity(string func)
 {
     YHumidity res;
     if (_HumidityCache.ContainsKey(func))
       return (YHumidity)_HumidityCache[func];
     res = new YHumidity(func);
     _HumidityCache.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 = (YHumidity)hwd;
     base.base_init(hwd, instantiationName);
 }
        // property cache
        //--- (end of YHumidity definitions)

        //--- (YHumidity implementation)
        internal YHumidityProxy(YHumidity hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("Humidity " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;

            YHumidity    hsensor;
            YTemperature tsensor;
            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")
            {
                hsensor = YHumidity.FirstHumidity();
                tsensor = YTemperature.FirstTemperature();
                psensor = YPressure.FirstPressure();

                if ((hsensor == null) || (tsensor == null) || (psensor == null))
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                hsensor = YHumidity.FindHumidity(target + ".humidity");
                tsensor = YTemperature.FindTemperature(target + ".temperature");
                psensor = YPressure.FindPressure(target + ".pressure");
            }

            if (!hsensor.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            while (hsensor.isOnline())
            {
                Console.WriteLine("Current humidity:    " + hsensor.get_currentValue().ToString()
                                  + " %RH");
                Console.WriteLine("Current temperature: " + tsensor.get_currentValue().ToString()
                                  + " °C");
                Console.WriteLine("Current pressure:    " + psensor.get_currentValue().ToString()
                                  + " hPa");
                Console.WriteLine("  (press Ctrl-C to exit)");

                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Ejemplo n.º 16
0
 /**
  * <summary>
  *   Retrieves a humidity 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 humidity sensor is online at the time
  *   it is invoked. The returned object is nevertheless valid.
  *   Use the method <c>YHumidity.isOnline()</c> to test if the humidity sensor is
  *   indeed online at a given time. In case of ambiguity when looking for
  *   a humidity 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 humidity sensor
  * </param>
  * <returns>
  *   a <c>YHumidity</c> object allowing you to drive the humidity sensor.
  * </returns>
  */
 public static YHumidity FindHumidity(string func)
 {
     YHumidity obj;
     obj = (YHumidity) YFunction._FindFromCache("Humidity", func);
     if (obj == null) {
         obj = new YHumidity(func);
         YFunction._AddToCache("Humidity", func, obj);
     }
     return obj;
 }