Пример #1
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YLightSensor sensor;

                if (Target.ToLower() == "any")
                {
                    sensor = YLightSensor.FirstLightSensor();
                    if (sensor == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    sensor = YLightSensor.FindLightSensor(Target + ".lightSensor");
                }

                while (await sensor.isOnline())
                {
                    WriteLine("Ambient light: " + await sensor.get_currentValue() + " lx");
                    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);
        }
Пример #2
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YLightSensor hwd = YLightSensor.FindLightSensor(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
Пример #3
0
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YLightSensor hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering LightSensor callback");
     _func.registerValueCallback(valueChangeCallback);
 }
Пример #4
0
        static void Main(string[] args)
        {
            string       errmsg = "";
            string       target;
            YLightSensor ir, al;
            YProximity   p;

            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")
            {
                p = YProximity.FirstProximity();
                if (p == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                target = p.get_module().get_serialNumber();
            }
            else
            {
                p = YProximity.FindProximity(target + ".proximity1");
            }

            if (!p.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            al = YLightSensor.FindLightSensor(target + ".lightSensor1");
            ir = YLightSensor.FindLightSensor(target + ".lightSensor2");

            while (p.isOnline())
            {
                Console.Write(" Proximity: " + p.get_currentValue().ToString());
                Console.Write(" Ambiant: " + al.get_currentValue().ToString());
                Console.Write(" IR: " + ir.get_currentValue().ToString());

                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Пример #5
0
        static void Main(string[] args)
        {
            string       errmsg = "";
            string       target;
            YRangeFinder rf;
            YLightSensor ir;
            YTemperature tmp;

            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")
            {
                rf = YRangeFinder.FirstRangeFinder();
                if (rf == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                target = rf.get_module().get_serialNumber();
            }
            else
            {
                rf = YRangeFinder.FindRangeFinder(target + ".rangefinder1");
            }

            if (!rf.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            ir  = YLightSensor.FindLightSensor(target + ".lightSensor1");
            tmp = YTemperature.FindTemperature(target + ".temperature1");

            while (rf.isOnline())
            {
                Console.WriteLine("Distance    : " + rf.get_currentValue().ToString());
                Console.WriteLine("Ambiant IR  : " + ir.get_currentValue().ToString());
                Console.WriteLine("Temperature : " + tmp.get_currentValue().ToString());
                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Пример #6
0
        private void OnDeviceConnected(YModule module)
        {
            var found = YLightSensor.FirstLightSensor();

            Interlocked.Exchange(ref this.sensor, found);

            if (this.IsOnline)
            {
                this.IsOnlineChanged?.Invoke(this, true);
                this.EnabledChanged?.Invoke(this, this.Enabled);
            }
        }
    /**
     * <summary>
     *   Retrieves a light 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 light sensor is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YLightSensor.isOnline()</c> to test if the light sensor is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a light 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 light sensor
     * </param>
     * <returns>
     *   a <c>YLightSensor</c> object allowing you to drive the light sensor.
     * </returns>
     */
    public static YLightSensor FindLightSensor(string func)
    {
        YLightSensor obj;

        obj = (YLightSensor)YFunction._FindFromCache("LightSensor", func);
        if (obj == null)
        {
            obj = new YLightSensor(func);
            YFunction._AddToCache("LightSensor", func, obj);
        }
        return(obj);
    }
Пример #8
0
        public static YLightSensorProxy FindLightSensor(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YLightSensor      func = null;
            YLightSensorProxy res  = (YLightSensorProxy)YFunctionProxy.FindSimilarUnknownFunction("YLightSensorProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YLightSensorProxy)YFunctionProxy.FindSimilarKnownFunction("YLightSensorProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YLightSensor.FirstLightSensor();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YLightSensorProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YLightSensor.FindLightSensor(name);
                if (func.get_userData() != null)
                {
                    return((YLightSensorProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YLightSensorProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Пример #9
0
        /**
         * <summary>
         *   Enumerates all functions of type LightSensor 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>YLightSensor.FindLightSensor</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>();
            YLightSensor  it  = YLightSensor.FirstLightSensor();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextLightSensor();
            }
            return(res.ToArray());
        }
Пример #10
0
    // --- (end of YLightSensor implementation)

    // --- (LightSensor functions)

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

        if (_LightSensorCache.ContainsKey(func))
        {
            return((YLightSensor)_LightSensorCache[func]);
        }
        res = new YLightSensor(func);
        _LightSensorCache.Add(func, res);
        return(res);
    }
Пример #11
0
        static void Main(string[] args)
        {
            string       errmsg = "";
            string       target;
            YLightSensor sensor;

            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")
            {
                sensor = YLightSensor.FirstLightSensor();
                if (sensor == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                sensor = YLightSensor.FindLightSensor(target + ".lightSensor");
            }

            if (!sensor.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            while (sensor.isOnline())
            {
                Console.WriteLine("Current ambient light: " + sensor.get_currentValue().ToString()
                                  + " lx");
                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Пример #12
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YRangeFinder rf;
                YLightSensor ir;
                YTemperature tmp;

                if (Target.ToLower() == "any")
                {
                    rf = YRangeFinder.FirstRangeFinder();
                    if (rf == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

                    Target = await(await rf.get_module()).get_serialNumber();
                }
                else
                {
                    rf = YRangeFinder.FindRangeFinder(Target + ".rangefinder1");
                }

                ir  = YLightSensor.FindLightSensor(Target + ".lightSensor1");
                tmp = YTemperature.FindTemperature(Target + ".temperature1");

                while (await rf.isOnline())
                {
                    WriteLine("Distance    : " + await rf.get_currentValue());
                    WriteLine("Ambiant IR  : " + await ir.get_currentValue());
                    WriteLine("Temperature : " + await tmp.get_currentValue());
                    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);
        }
Пример #13
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YLightSensor ir, al;
                YProximity   p;

                if (Target.ToLower() == "any")
                {
                    p = YProximity.FirstProximity();
                    if (p == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

                    Target = await(await p.get_module()).get_serialNumber();
                }
                else
                {
                    p = YProximity.FindProximity(Target + ".proximity1");
                }

                al = YLightSensor.FindLightSensor(Target + ".lightSensor1");
                ir = YLightSensor.FindLightSensor(Target + ".lightSensor2");

                while (await p.isOnline())
                {
                    Write("Proximity: " + await p.get_currentValue());
                    Write("\tAmbiant: " + await al.get_currentValue());
                    WriteLine("\tIR: " + await ir.get_currentValue());
                    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);
        }
Пример #14
0
        public List <AmbientLightSensor> GetSensors(bool forceUpdate = false)
        {
            if (_sensors != null && !forceUpdate)
            {
                return(_sensors);
            }

            _sensors = new List <AmbientLightSensor>();
            var sensor = YLightSensor.FirstSensor();

            while (sensor != null)
            {
                if (sensor.get_functionId() == "lightSensor")
                {
                    _sensors.Add(new AmbientLightSensor(sensor));
                }

                sensor = sensor.nextSensor();
            }

            return(_sensors);
        }
Пример #15
0
        //--- (end of YLightSensor definitions)

        //--- (YLightSensor implementation)
        internal YLightSensorProxy(YLightSensor hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("LightSensor " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }
 /**
  * <summary>
  *   Retrieves a light 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 light sensor is online at the time
  *   it is invoked. The returned object is nevertheless valid.
  *   Use the method <c>YLightSensor.isOnline()</c> to test if the light sensor is
  *   indeed online at a given time. In case of ambiguity when looking for
  *   a light 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 light sensor
  * </param>
  * <returns>
  *   a <c>YLightSensor</c> object allowing you to drive the light sensor.
  * </returns>
  */
 public static YLightSensor FindLightSensor(string func)
 {
     YLightSensor obj;
     obj = (YLightSensor) YFunction._FindFromCache("LightSensor", func);
     if (obj == null) {
         obj = new YLightSensor(func);
         YFunction._AddToCache("LightSensor", func, obj);
     }
     return obj;
 }
Пример #17
0
        /*setup timers, connections and variables*/
        public UI_NetStatusPanel()
        {
            string errmsg = "";

            InitializeComponent();


            //Setup scalers and controls that must be scaled
            UIsetup();


            _cmdUpdate  = Update_CommandUI;
            _iofeedback = Update_IO_Displays;

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                set_display1("error: " + errmsg);
                Logging.Add("Cant initiaet Yocto API, do you have another instance running?");
            }
            else
            {
                Logging.Add("Yapi Initiated");
            }

            //Set Sensors 1 and 2
            sensor1 = YLightSensor.FindLightSensor("L1" + ".lightSensor");
            if (sensor1 == null)
            {
                set_display1("no L1 sensor");
            }
            else
            {
                set_display1("L1 Ok");
            }

            sensor2 = YLightSensor.FindLightSensor("L2" + ".lightSensor");
            if (sensor2 == null)
            {
                set_display2("no L2 sensor"); Logging.Add("L1 not connected");
            }
            else
            {
                set_display2("L2 Ok");
            }

            /*delegates for ui updates*/
            _updatedisplay1 = (set_display1);
            _updatedisplay2 = (set_display2);
            _updatefeedback = (Update_feedback);
            _ipConfig       = Update_IP_Config;

            Logic.Initialise_Cameras();


            Servlet.Userinterface = this; ///assigning treference to ui for the servlets to conduct updates. This needs to be changed!

            Logic.Start();

            //start a timer
            _UsbLightReading = new System.Threading.Timer(Lsensor_Tick, null, 0, 1000);

            //start a timer
            _NetworkTimer = new System.Threading.Timer(Nmanager.Tick, null, 0, 1000);
        }
Пример #18
0
 // --- (end of YLightSensor implementation)
 // --- (LightSensor functions)
 /**
    * <summary>
    *   Retrieves a light 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 light sensor is online at the time
    *   it is invoked. The returned object is nevertheless valid.
    *   Use the method <c>YLightSensor.isOnline()</c> to test if the light sensor is
    *   indeed online at a given time. In case of ambiguity when looking for
    *   a light 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 light sensor
    * </param>
    * <returns>
    *   a <c>YLightSensor</c> object allowing you to drive the light sensor.
    * </returns>
    */
 public static YLightSensor FindLightSensor(string func)
 {
     YLightSensor res;
     if (_LightSensorCache.ContainsKey(func))
       return (YLightSensor)_LightSensorCache[func];
     res = new YLightSensor(func);
     _LightSensorCache.Add(func, res);
     return res;
 }
Пример #19
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 = (YLightSensor)hwd;
     base.base_init(hwd, instantiationName);
 }