Beispiel #1
0
        public void t6(PigpiodIf pigpiodIf, CancellationToken ct)
        {
            PigpiodIf.Callback callback = null;
            try
            {
                int tp, t, p;

                Console.WriteLine("\r\nTrigger tests.");

                pigpiodIf.gpio_write(GPIO, PigpiodIf.PI_LOW);

                tp = 0;

                int    t6_count   = 0;
                int    t6_on      = 0;
                UInt32 t6_on_tick = 0;
                callback = pigpiodIf.callback(GPIO, PigpiodIf.EITHER_EDGE, (gpio, level, tick, user) =>
                {
                    if (level == 1)
                    {
                        t6_on_tick = tick;
                        t6_count++;
                    }
                    else
                    {
                        if (t6_on_tick != 0)
                        {
                            t6_on += (int)(tick - t6_on_tick);
                        }
                    }
                });

                pigpiodIf.time_sleep(0.2);

                for (t = 0; t < 5; t++)
                {
                    pigpiodIf.time_sleep(0.1);
                    p   = 10 + (t * 10);
                    tp += p;
                    pigpiodIf.gpio_trigger(GPIO, (UInt32)p, 1);
                }

                pigpiodIf.time_sleep(0.5);

                CHECK(6, 1, t6_count, 5, 0, "gpio trigger count", ct);

                CHECK(6, 2, t6_on, tp, 25, "gpio trigger pulse length", ct);
            }
            finally
            {
                pigpiodIf.callback_cancel(callback);
            }
        }