Exemple #1
0
 public void assignRedButton(YAnButton button)
 {
     // we store a pointer to the current instance of ColorMixer into
     // the userData Field
     button.set_userData(this);
     // and we register our static method to change red color as callback
     button.registerValueCallback(redCallback);
 }
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YAnButton hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering AnButton callback");
     _func.registerValueCallback(valueChangeCallback);
 }
Exemple #3
0
        public HamsterButton(string hwid, PressedDelegate pressedDe)
        {
            _button = YAnButton.FindAnButton(hwid);
            if (!_button.isOnline())
            {
                throw new Exception("No anButton named " + hwid);
            }

            _pressedDe = pressedDe;
            _button.registerValueCallback(AnButtonListener);
        }
        async Task deviceArrival(YModule m)
        {
            string serial = await m.get_serialNumber();

            Output.Text += "Device arrival : " + serial + "\n";
            await m.registerLogCallback(deviceLog);

            await m.registerConfigChangeCallback(configChange);

            await m.registerBeaconCallback(beaconChange);

            // First solution: look for a specific type of function (eg. anButton)
            int fctcount = await m.functionCount();

            for (int i = 0; i < fctcount; i++)
            {
                string hardwareId = serial + "." + await m.functionId(i);

                if (hardwareId.IndexOf(".anButton") >= 0)
                {
                    Output.Text += "- " + hardwareId + "\n";
                    YAnButton anButton = YAnButton.FindAnButton(hardwareId);
                    await anButton.registerValueCallback(anButtonValueChangeCallBack);
                }
            }

            // Alternate solution: register any kind of sensor on the device
            YSensor sensor = YSensor.FirstSensor();

            while (sensor != null)
            {
                YModule module = await sensor.get_module();

                if (await module.get_serialNumber() == serial)
                {
                    string hardwareId = await sensor.get_hardwareId();

                    Output.Text += "- " + hardwareId + "\n";
                    string unit = await sensor.get_unit();

                    await sensor.set_userData(unit);

                    await sensor.registerValueCallback(sensorValueChangeCallBack);

                    await sensor.registerTimedReportCallback(sensorTimedReportCallBack);
                }

                sensor = sensor.nextSensor();
            }
        }
Exemple #5
0
        static void deviceArrival(YModule m)
        {
            string serial = m.get_serialNumber();

            Console.WriteLine("Device arrival : " + serial);
            m.registerLogCallback(deviceLog);
            m.registerConfigChangeCallback(configChange);
            m.registerBeaconCallback(beaconChange);

            // First solution: look for a specific type of function (eg. anButton)
            int fctcount = m.functionCount();

            for (int i = 0; i < fctcount; i++)
            {
                string hardwareId = serial + "." + m.functionId(i);
                if (hardwareId.IndexOf(".anButton") >= 0)
                {
                    Console.WriteLine("- " + hardwareId);
                    YAnButton anButton = YAnButton.FindAnButton(hardwareId);
                    anButton.registerValueCallback(anButtonValueChangeCallBack);
                }
            }

            // Alternate solution: register any kind of sensor on the device
            YSensor sensor = YSensor.FirstSensor();

            while (sensor != null)
            {
                if (sensor.get_module().get_serialNumber() == serial)
                {
                    string hardwareId = sensor.get_hardwareId();
                    Console.WriteLine("- " + hardwareId);
                    string unit = sensor.get_unit();
                    sensor.set_userData(unit);
                    sensor.registerValueCallback(sensorValueChangeCallBack);
                    sensor.registerTimedReportCallback(sensorTimedReportCallBack);
                }

                sensor = sensor.nextSensor();
            }
        }