コード例 #1
0
        public void t7(PigpiodIf pigpiodIf, CancellationToken ct)
        {
            PigpiodIf.Callback callback = null;
            try
            {
                int c, oc;

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

                int t7_count = 0;
                /* type of edge shouldn't matter for watchdogs */
                callback = pigpiodIf.callback(GPIO, PigpiodIf.FALLING_EDGE, (gpio, level, tick, user) =>
                {
                    if (level == PigpiodIf.PI_TIMEOUT)
                    {
                        t7_count++;
                    }
                });

                pigpiodIf.set_watchdog(GPIO, 50);                 /* 50 ms, 20 per second */
                pigpiodIf.time_sleep(0.5);
                oc = t7_count;
                pigpiodIf.time_sleep(2);
                c = t7_count - oc;
                CHECK(7, 1, c, 39, 5, "set watchdog on count", ct);

                pigpiodIf.set_watchdog(GPIO, 0);                 /* 0 switches watchdog off */
                pigpiodIf.time_sleep(0.5);
                oc = t7_count;
                pigpiodIf.time_sleep(2);
                c = t7_count - oc;
                CHECK(7, 2, c, 0, 1, "set watchdog off count", ct);
            }
            finally
            {
                pigpiodIf.callback_cancel(callback);
            }
        }