Beispiel #1
0
        private static bool DisplayPotentiometerInfoAndCheckForCancel(MCP41X1_Base ldp, bool tryReadValue = false, int exWaitTime = -1)
        {
            Console.WriteLine(ldp.ToString());
            if (exWaitTime == -1)
            {
                TimePeriod.Sleep(waitTime * 10);
            }
            else
            if (exWaitTime > 0)
            {
                TimePeriod.Sleep(exWaitTime);
            }

            if (tryReadValue)
            {
                int val = ldp.Get();
            }
            if (Console.KeyAvailable)
            {
                var k = Console.ReadKey();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        static void OtherApiTests(MCP41X1_Base dp)
        {
            var quit = false;

            Console.Clear();
            try
            {
                var expectedValue = 0;
                dp.Set(0);
                for (var i = 0; i <= dp.MaxDigitalValue; i += _demoStep)
                {
                    expectedValue += _demoStep;
                    if (expectedValue > dp.MaxDigitalValue)
                    {
                        expectedValue = dp.MaxDigitalValue;
                    }
                    if (DisplayPotentiometerInfoAndCheckForCancel(dp))
                    {
                        quit = true; break;
                    }
                    dp.Increment(_demoStep);
                    var v = dp.Get();
                    if (expectedValue != v)
                    {
                        Console.WriteLine("Method Get() did not return expected result");
                    }
                }

                if (quit)
                {
                    return;
                }

                dp.Set(dp.MaxDigitalValue);
                DisplayPotentiometerInfoAndCheckForCancel(dp);

                expectedValue = dp.MaxDigitalValue;

                for (var i = dp.MaxDigitalValue; i > 0; i -= _demoStep)
                {
                    expectedValue -= _demoStep;
                    if (expectedValue < dp.MinDigitalValue)
                    {
                        expectedValue = dp.MinDigitalValue;
                    }
                    if (DisplayPotentiometerInfoAndCheckForCancel(dp))
                    {
                        quit = true; break;
                    }
                    dp.Decrement(_demoStep);
                    var v = dp.Get();
                    if (expectedValue != v)
                    {
                        Console.WriteLine("Method Get() did not return expected result");
                    }
                }
            }
            finally
            {
                dp.Set(0);
            }
        }