/// <summary>
        ///     Write and read a single byte.
        /// </summary>
        /// <remarks>
        ///     This internal method assumes that CS has been asserted correctly
        ///     before it is called.
        /// </remarks>
        /// <param name="value">Value to write.</param>
        /// <returns>Byte read from the SPI interface.</returns>
        private byte WriteRead(byte value)
        {
            byte result = 0;
            byte mask   = 0x80;
            var  clock  = _phase;

            for (var index = 0; index < 8; index++)
            {
                _mosi.Write((value & mask) > 0);
                bool data = false;
                if (!_phase)
                {
                    data = _miso.Read();
                }
                _clock.Write(!clock);
                if (_phase)
                {
                    data = _miso.Read();
                }
                _clock.Write(clock);
                if (data)
                {
                    result |= mask;
                }
                mask >>= 1;
            }
            return(result);
        }
Exemple #2
0
        public static string GetMessage(InputPort digitalIn)
        {
            var      message = "";
            DateTime startTime;

            if (!digitalIn.Read())
            {
                message += "1";
            }
            else
            {
                message += "0";
            }

            Thread.Sleep(sleep);

            if (!digitalIn.Read())
            {
                message += "1";
            }
            else
            {
                message += "0";
            }
            Thread.Sleep(sleep);
            if (message == "11" || message == "00")
            {
                state   = TokenState.LISTEN;
                message = "";
                return("");
            }

            state = TokenState.ENDBYTE;
            return(message);
        }
        public static void Main()
        {
            var BUTTON_0     = new InputPort(BUTTON_0_PIN, false, Port.ResistorMode.PullUp);
            var buttonState  = true;
            var payloadState = "";

            using (var serial = new SerialDataHelper(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One))
            {
                //Whenever we receive a payload from the computer, save it to our variable
                serial.PayloadReceived += new PayloadReceivedEventHandler((src, e) =>
                {
                    payloadState = new string(Encoding.UTF8.GetChars(e.Payload));
                });

                //We are polling the input for now because we're already using the pin with interrupt support.
                while (true)
                {
                    //If the button reads low and the button state is high
                    if (!BUTTON_0.Read() && buttonState)
                    {
                        serial.SendPayload(Encoding.UTF8.GetBytes("BUTTON WAS PUSHED! Last message received: " + payloadState));
                    }
                    buttonState = BUTTON_0.Read();
                }
            }
        }
Exemple #4
0
        public static void Main()
        {
            AnalogInput capt        = new AnalogInput((Cpu.AnalogChannel)Cpu.AnalogChannel.ANALOG_0);
            OutputPort  dir         = new OutputPort(FEZSpider.Socket8.Pin9, true);
            InputPort   microswitch = new InputPort(FEZSpider.Socket4.Pin3, false, Port.ResistorMode.PullDown);

            double frequence       = 38000; // Période en microseconde
            double rapportCyclique = 0.5;   // Période en microseconde

            PWM motorDriver = new PWM(FEZSpider.Socket8.Pwm7, frequence, rapportCyclique, false);

            motorDriver.Stop();


            while (true)
            {
                if (microswitch.Read())
                {
                    motorDriver.Stop();
                }

                Debug.Print("Distance : " + capt.Read().ToString());

                Debug.Print(microswitch.Read().ToString());
                Thread.Sleep(50);
            }
        }
Exemple #5
0
        static void SDMountThread()
        {
            SDCard    SD        = null;
            const int POLL_TIME = 500; // check every 500 millisecond

            bool sdExists;

            while (true)
            {
                try // If SD card was removed while mounting, it may throw exceptions
                {
                    sdExists = !sdCardDetect.Read();

                    // make sure it is fully inserted and stable
                    if (sdExists)
                    {
                        Thread.Sleep(50);
                        sdExists = !sdCardDetect.Read();
                    }

                    if (sdExists && SD == null)
                    {
                        SD = new SDCard();
                        SD.Mount();
                    }
                    else if (!sdExists && SD != null)
                    {
                        SD.Unmount();
                        SD.Dispose();
                        SD = null;
                    }
                    else if (sdExists && SD != null)
                    {
                        if (sdCardWriteProtect.Read() == true)
                        {
                            ReadyWrite = false;
                            //Debug.Print("ReadyWrite: false");
                        }
                        else
                        {
                            ReadyWrite = true;
                            //Debug.Print("ReadyWrite: true. Flushing!");
                            volume_info.FlushAll();
                        }
                    }
                }
                catch
                {
                    if (SD != null)
                    {
                        SD.Dispose();
                        SD = null;
                    }
                }

                Thread.Sleep(POLL_TIME);
            }
        }
Exemple #6
0
        public static void Test()
        {
            // Create new Thread that runs the ExampleThreadFunction
            Thread ExampleThread = new Thread(new ThreadStart(ExampleThreadFunction));

            // SD stuff is in
            PersistentStorage sdPS = new PersistentStorage("SD");

            // Led stuff is in
            OutputPort LED;

            LED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);

            // Button stuff in
            InputPort Button;

            Button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.LDR, false,
                                   Port.ResistorMode.PullUp);


            while (true)
            {
                //Led status at the beginning is off
                LED.Write(false);

                if (Button.Read())
                {
                    while (Button.Read())
                    {
                        ;                     // wait while busy
                    }
                    //Led is on
                    LED.Write(true);

                    // Mount
                    sdPS.MountFileSystem();

                    // Start our new Thread
                    ExampleThread.Start();

                    while (Button.Read())
                    {
                        ;                     // wait while busy
                    }
                    //Led is off
                    LED.Write(true);

                    // Abort our new Thread
                    ExampleThread.Abort();

                    // Unmount
                    sdPS.UnmountFileSystem();
                }
            }
        }
Exemple #7
0
        public static void Main()
        {
            // write your code here
            var led   = new OutputPort(Pins.ONBOARD_LED, false);
            var input = new InputPort(Pins.GPIO_PIN_D7, true, Port.ResistorMode.Disabled);

            while (true)
            {
                Debug.Print("input=" + input.Read().ToString());
                led.Write(!input.Read());
                Thread.Sleep(100);
            }
        }
        public static void Main()
        {
            Random rnd = new Random();

            while (true)
            {
                #region for-leds
                //for (int i = 0; i <= 6; i++)
                //{
                //    leds[i].Write(true);
                //    Thread.Sleep(250);
                //    leds[i].Write(false);
                //    Thread.Sleep(250);
                //}
                #endregion

                int random   = rnd.Next(25);
                int decision = rnd.Next(1);

                showSignal(random);

                if (decision == 1)
                {
                    showLetter(random);
                }
                else
                {
                    showLetter(rnd.Next(25));
                }

                while (true)
                {
                    if ((!trueSwitch.Read() && decision == 1) || (!falseSwitch.Read() && decision == 0))
                    {
                        greenLed.Write(false);
                        break;
                    }
                    else if (!trueSwitch.Read() || !falseSwitch.Read())
                    {
                        redLed.Write(false);
                        break;
                    }
                }
                Thread.Sleep(3000);
                resetLeds();
                Thread.Sleep(1000);
            }
        }
        private static void ProcessButtonForLeftAid2()
        {
            buttonPressed5 = !inD6.Read();

            if (buttonPressed5 && firstPress5)
            {
                // If there are any programmers on, clear all aids except the other side
                if (AreAnyProgrammersOn())
                {
                    if (b5)
                    {
                        ClearAidState(Aid.LeftAid2);
                    }
                }

                firstPress5 = false;
                b5          = !b5;
                outA4.Write(b5);
                Thread.Sleep(200);
            }
            else if (!buttonPressed5)
            {
                firstPress5 = true;
            }
        }
Exemple #10
0
        public static void Main3()
        {
            // configure an output port for us to "write" to the LED
            var led = new OutputPort(Pins.ONBOARD_LED, false);

            // 1.) Configure an input port for us to read the state of the button
            // 2.) Glitch Filter is set to false, only needed to prevent switch "bounce", and is not needed here
            // 3.) ResistorMode is set to Disabled as the netduino has a pulldown resistor
            // 4.) Switch will change from HIGH to LOW when pressed/released
            var button = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled);

            bool buttonState = false;

            // 1.) Continuous loop to look for state changes
            while (true)
            {
                var newState = button.Read();

                if (buttonState != newState)
                {
                    buttonState = newState;
                    led.Write(buttonState);
                }
            }
        }
Exemple #11
0
        public static void Main()
        {
            bool       start     = false;
            OutputPort LedSpider = new OutputPort(FEZSpiderII.DebugLed, false);
            InputPort  btn1      = new InputPort(G120.P2_13, true, Port.ResistorMode.Disabled);
            InputPort  btn2      = new InputPort(FEZSpiderII.Socket14.Pin3, true, Port.ResistorMode.Disabled);

            while (true)
            {
                if (!btn1.Read() == true)
                {
                    start = true;
                }
                if (!btn2.Read() == true)
                {
                    start = false;
                }
                if (start == true)
                {
                    LedSpider.Write(true);
                    Thread.Sleep(125);
                    LedSpider.Write(false);
                    Thread.Sleep(125);
                }
                if (start == false)
                {
                    LedSpider.Write(false);
                }
            }
        }
Exemple #12
0
        public void Run()
        {
            InitializePeripherals();

            UpdateDisplay();

            greenLed.StartPulse(1000, 0.8f, 0.05f);

            //thread to detect touches
            var thread = new Thread(() =>
            {
                while (true)
                {
                    if (isPlaying && tree.Read() == false)
                    {
                        OnTouched();
                    }
                    Thread.Sleep(10);
                }
            });

            thread.Start();

            ResetGame();
        }
Exemple #13
0
        public void Run()
        {
            bool triggerState = _trigger.Read();
            bool reloadState  = _reload.Read();

            // Setup device
            if (!DoSetup())
            {
                Debugger.Break();
            }

            // Wait for a connection
            WaitForConnect();

            while (true)
            {
                var nrfEvent = _nrf.HandleEvent();

                if (nrfEvent != null)
                {
                    if (nrfEvent.EventType == Nrf8001EventType.Disconnected)
                    {
                        WaitForConnect();
                    }
                }

                // Notify peer device of trigger state change
                NotifyButtonState(_trigger, TriggerStatePipeId, ref triggerState);

                // Notify peer device of reload state change
                NotifyButtonState(_reload, ReloadStatePipeId, ref reloadState);
            }
        }
Exemple #14
0
 protected virtual void WaitUntilIdle()
 {
     while (busyPort.Read() == false)
     {
         DelayMs(50);
     }
 }
        private static void ProcessButtonForRightAid2()
        {
            buttonPressed7 = !inD8.Read();

            if (buttonPressed7 && firstPress7)
            {
                // If there are any programmers on, clear all aids except the other side
                if (AreAnyProgrammersOn())
                {
                    if (b7)
                    {
                        ClearAidState(Aid.RightAid2);
                    }
                }

                firstPress7 = false;
                b7          = !b7;
                outD0.Write(b7);
                Thread.Sleep(200);
            }
            else if (!buttonPressed7)
            {
                firstPress7 = true;
            }
        }
Exemple #16
0
        /// <summary>
        /// Blocking method for input pulse measuring
        /// </summary>
        /// <param name="port">Input port</param>
        /// <param name="state">State to measure length</param>
        /// <returns>Pulse length in ticks</returns>
        private long PulseIn(InputPort port, bool state)
        {
            DateTime startTime;
            TimeSpan delta;

            while (port.Read() != state)
            {
            }
            startTime = DateTime.Now;
            while (port.Read() == state)
            {
            }
            delta = DateTime.Now - startTime;

            return(delta.Ticks);
        }
        private static void ProcessButtonForLeftAid1()
        {
            buttonPressed4 = !inD5.Read();

            if (buttonPressed4 && firstPress4)
            {
                // If there are any programmers on, clear all aids except the other side
                if (AreAnyProgrammersOn())
                {
                    // If this aid is being turned on
                    if (b4)
                    {
                        ClearAidState(Aid.LeftAid1);
                    }
                }

                firstPress4 = false;
                b4          = !b4;
                outA3.Write(b4);
                Thread.Sleep(200);
            }
            else if (!buttonPressed4)
            {
                firstPress4 = true;
            }
        }
Exemple #18
0
        public bool Read()
        {
            ThrowIfDisposed();
            bool value = _input.Read();

            return(InvertReading ? !value : value);
        }
        private static void ProcessButtonForRightAid1()
        {
            buttonPressed6 = !inD7.Read();

            if (buttonPressed6 && firstPress6)
            {
                // If there are any programmers on, clear all aids except the other side
                if (AreAnyProgrammersOn())
                {
                    if (b6)
                    {
                        ClearAidState(Aid.RightAid1);
                    }
                }

                firstPress6 = false;
                b6          = !b6;
                outA5.Write(b6);
                Thread.Sleep(200);
            }
            else if (!buttonPressed6)
            {
                firstPress6 = true;
            }
        }
Exemple #20
0
        static void SendFridgeReport()
        {
            // Generate egg positions
            string eggPositions = ((eggReader0.Read() == true) ? "1" : "0") + ","
                                  + ((eggReader1.Read() == true) ? "1" : "0") + ","
                                  + ((eggReader2.Read() == true) ? "1" : "0") + ","
                                  + ((eggReader3.Read() == true) ? "1" : "0") + ","
                                  + ((eggReader4.Read() == true) ? "1" : "0") + ","
                                  + ((eggReader5.Read() == true) ? "1" : "0");

            // Read weights
            //double weightReader0 = 0.745;
            //double weightReader1 = 0.00000;

            weights[0] = CalculateWeight(weightReader0.Read());
            weights[1] = CalculateWeight(weightReader1.Read());


#if CreatingJson
            JsonObject jo = new JsonObject();

            jo.Add("eggs", eggPositions);
            jo.Add("fridgeid", fridgeId.ToString());
            jo.Add("slot1weight", weights[0].ToString());
            jo.Add("slot2weight", weights[1].ToString());

            Debug.Print(jo.ToString());
#endif

#if SendingToSparkfun
            // https://data.sparkfun.com/input/*********
            try
            {
                byte[] postData = Encoding.UTF8.GetBytes(jo.ToString());

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://data.sparkfun.com/input/********");
                request.Method = "POST";
                request.Headers.Add("Phant-Private-Key", "xxxxxxxxxxxxxx");
                request.ContentType   = "application/json";
                request.ContentLength = postData.Length;
                request.KeepAlive     = false;

                Debug.Print("request set");

                Stream postDataStream = request.GetRequestStream();
                postDataStream.Write(postData, 0, postData.Length);
                postDataStream.Close();

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                request.Dispose();
                Debug.Print(response.StatusCode.ToString());

                Debug.Print("response done");
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message.ToString());
            }
#endif
        }
Exemple #21
0
        // waits for the chip to be ready and returns a reading
        public int Read()
        {
            // wait for the chip to become ready
            while (!Ready)
            {
            }

            var data = new byte[3];

            // pulse the clock pin 24 times to read the data
            for (byte j = 3; j-- != 0;)
            {
                data[j] = 0;
                for (byte i = 8; i-- != 0;)
                {
                    _pdSck.Write(true);
                    var  bit      = _dOut.Read();
                    byte bitValue = bit ? (byte)1 : (byte)0;
                    data[j] |= (byte)(bitValue << i);
                    _pdSck.Write(false);
                }
            }

            // set the channel and the gain factor for the next reading using the clock pin
            for (int i = 0; i < _gain; ++i)
            {
                _pdSck.Write(true);
                _pdSck.Write(false);
            }
            data[2] ^= 0x80;
            int result = (data[2] << 16) | (data[1] << 8) | data[0];

            return(result);
        }
Exemple #22
0
                public void InitPresenceCheck(PortDefinition port)
                {
                    switch (port.id)
                    {
                    case 1:
                    {
                        resetPin      = new InputPort(IO.Port1.Pin6, false, Port.ResistorMode.PullDown);
                        GPIO          = new InputPort(IO.Port1.Pin3, false, Port.ResistorMode.PullDown);
                        modulePresent = resetPin.Read();
                        break;
                    }

                    case 4:
                    {
                        resetPin      = new InputPort(IO.Port4.Pin6, false, Port.ResistorMode.PullDown);
                        GPIO          = new InputPort(IO.Port4.Pin3, false, Port.ResistorMode.PullDown);
                        modulePresent = resetPin.Read();
                        break;
                    }

                    case 6:
                    {
                        resetPin      = new InputPort(IO.Port6.Pin6, false, Port.ResistorMode.PullDown);
                        GPIO          = new InputPort(IO.Port6.Pin3, false, Port.ResistorMode.PullDown);
                        modulePresent = resetPin.Read();
                        break;
                    }

                    default: break;
                    }
                }
Exemple #23
0
        public void Go()
        {
            // turn of Netduino devices that we don't need
            PowerManagement.SetPeripheralState(Peripheral.Ethernet, false);
            PowerManagement.SetPeripheralState(Peripheral.PowerLED, false);
            PowerManagement.SetPeripheralState(Peripheral.SDCard, false);

            // initalize the serial ports
            m_serialPort = new SerialPort("COM1", 38400, Parity.None, 8, StopBits.One);
            m_serialPort.Open();

            m_nmeaInputPort = new NmeaInputPort(m_serialPort);

            m_oled = new Newhaven25664OledDriver(
                chipSelect: Pins.GPIO_PIN_D10,
                reset: Pins.GPIO_PIN_D9,
                dc: Pins.GPIO_PIN_D8);
            m_oled.Initialize();
            m_oled.ClearDisplay();
            m_oled.TestPattern();
            Thread.Sleep(1000);
            m_oled.ClearDisplay();

            InputPort leftButton = new InputPort(Pins.GPIO_PIN_D7, false, Port.ResistorMode.PullUp);

            if (!leftButton.Read())
            {
                // debug mode
                //m_nmeaInputPort.RawDataDebugEvent += new NmeaInputDebugEventHandler(m_nmeaInputPort_RawDataDebugEvent);
                m_nmeaInputPort.ParsedDataDebugEvent += new NmeaInputParsedDebugEventHandler(m_nmeaInputPort_ParsedDataDebugEvent);
                m_debugFont = new OledFont(SailboatComputer.Properties.Resources.BinaryResources.fixed5x7);
                m_nmeaInputPort.Initialize();
                while (true)
                {
                    Thread.Sleep(Int16.MaxValue);
                }
            }
            else
            {
                leftButton.Dispose();
                leftButton = null;
                DebugLog.WriteLine("free memory (before fonts) = " + Microsoft.SPOT.Debug.GC(true));

                m_ui = new SimpleUserInterface(m_oled, Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D6);

                DebugLog.WriteLine("free memory (after fonts) = " + Microsoft.SPOT.Debug.GC(true));

                // hook up NMEA events
                m_nmeaInputPort.WindEvent   += new NmeaWindEventHandler(m_nmeaInputPort_WindEvent);
                m_nmeaInputPort.COGSOGEvent += new NmeaCOGSOGEventHandler(m_nmeaInputPort_CogSogEvent);
                m_nmeaInputPort.DepthEvent  += new NmeaDepthEventHandler(m_nmeaInputPort_DepthEvent);
                m_nmeaInputPort.Initialize();

                while (true)
                {
                    Thread.Sleep(Int16.MaxValue);
                }
            }
        }
Exemple #24
0
        public static void Main()
        {
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // !  W A R N I N G   W A R N I N G   W A R N I N G    W A R N I N G   W A R N I N G   W A R N I N G  !
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // ! The Joystick Shield analog ports are connected to 5V since it's originally designed for Arduino. !
            // ! The Netduino analog inputs work on 3.3V. Herefor a modification to the shield is required.       !
            // ! See http://netmftoolbox.codeplex.com/wikipage?title=Joystick%20Shield  for more details.         !
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            // The thumb joystick is connected to analog pins 0 and 1, and digital pin 2
            // On the Joystick shield, the thumb stick is rotated by 90° so we need to invert the horizontal value
            ThumbJoystick Joystick = new ThumbJoystick(new Netduino.ADC(Pins.GPIO_PIN_A0), new Netduino.ADC(Pins.GPIO_PIN_A1), Pins.GPIO_PIN_D2, true);

            // The other buttons are connected to digital pins 3, 4, 5 and 6
            // The shield doesn't have pull-up resistors so we use the internal ones from the Netduino
            InputPort ButtonRight = new InputPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.PullUp);
            InputPort ButtonUp    = new InputPort(Pins.GPIO_PIN_D4, false, Port.ResistorMode.PullUp);
            InputPort ButtonDown  = new InputPort(Pins.GPIO_PIN_D5, false, Port.ResistorMode.PullUp);
            InputPort ButtonLeft  = new InputPort(Pins.GPIO_PIN_D6, false, Port.ResistorMode.PullUp);

            // Infinite loop; so far Analog ports can't handle interrupts, so the Joystick driver can't as well
            while (true)
            {
                // Lets start with an empty string
                string OutputText = "";
                // Add the values of the thumb stick
                OutputText  = "Horizontal: " + Joystick.HorizontalValue.ToString();
                OutputText += " Vertical: " + Joystick.VerticalValue.ToString();
                if (Joystick.PushValue)
                {
                    OutputText += " Thumbstick pushed";
                }

                // Add button states to the output text (inverted with the ! because of the pull-up resistor)
                if (!ButtonDown.Read())
                {
                    OutputText += " Button Down";
                }
                if (!ButtonUp.Read())
                {
                    OutputText += " Button Up";
                }
                if (!ButtonLeft.Read())
                {
                    OutputText += " Button Left";
                }
                if (!ButtonRight.Read())
                {
                    OutputText += " Button Right";
                }

                // Displays the output text to the debug window
                Debug.Print(OutputText);

                // Wait 100ms to read the pins again
                Thread.Sleep(100);
            }
        }
 /// <summary>
 /// Returns a new sample.
 /// If the sensor is not open, Open is called first.
 /// Postconditions
 ///     (Result == null) || (Result is bool)
 /// </summary>
 public object HandleGet()
 {
     if (port == null)
     {
         Open();
     }
     return(port.Read());     // bool converted to object
 }
Exemple #26
0
 public static void GetEndByte(InputPort digitalIn)
 {
     //Better be a 0
     if (digitalIn.Read())
     {
         Thread.Sleep(sleep);
         //And still a 0
         if (digitalIn.Read())
         {
             Thread.Sleep(sleep);
             state = TokenState.READ;
             return;
         }
         state = TokenState.LISTEN;
     }
     state = TokenState.LISTEN;
 }
Exemple #27
0
 public static void GetListenByte(InputPort digitalIn)
 {
     while (true)
     {
         //Found our first one...now wait for a 0
         if (!digitalIn.Read())
         {
             while (digitalIn.Read())
             {
                 //noop
             }
         }
         state = TokenState.STARTBYTE;
         Thread.Sleep(sleep);
         break;
     }
 }
Exemple #28
0
 public static void GetStartByte(InputPort digitalIn)
 {
     //Better be a 1
     if (!digitalIn.Read())
     {
         Thread.Sleep(sleep);
         //And still a 1
         if (!digitalIn.Read())
         {
             Thread.Sleep(sleep);
             state = TokenState.MESSAGE;
             return;
         }
         state = TokenState.LISTEN;
     }
     state = TokenState.LISTEN;
 }
Exemple #29
0
 public static void GetListenByte(InputPort digitalIn)
 {
     while (true)
     {
         //Found our first one...now wait for a 0
         if (!digitalIn.Read())
         {
             var d = DateTime.Now;
             while (digitalIn.Read() && d.AddMilliseconds(500) < DateTime.Now)
             {
                 //noop
             }
         }
         state = TokenState.STARTBYTE;
         Thread.Sleep(sleep);
         break;
     }
 }
Exemple #30
0
 private void Run()
 {
     lastValue = encoder.Read();
     while (true)
     {
         bool actualValue = encoder.Read();
         if (actualValue == lastValue)
         {
             continue;
         }
         else
         {
             _distance += stepmm;
             lastValue  = actualValue;
             Debug.Print("PIN: " + this.encoder.Id.ToString() + " - Distance: " + _distance.ToString());
         }
     }
 }
Exemple #31
0
 /// <summary>
 /// Read a single expression from the input port.
 /// </summary>
 /// <param name="inp">The input port to read from.</param>
 /// <returns>The object that was read.</returns>
 private static SchemeObject UnsafeRead(InputPort inp)
 {
     return inp.Read();
 }
Exemple #32
0
        /// <summary>
        /// Read from the input port and evaluate whatever is there.
        /// Done for the side effect, not the result.
        /// Since the result is never tested, asynchronous suspensions do not prevent the rest
        /// of the file from being loaded.
        /// </summary>
        /// <param name="inp">The input port.</param>
        /// <param name="outp">If not null, input and results are written here.</param>
        /// <returns>Undefined instance.</returns>
        internal SchemeObject Load(InputPort inp, OutputPort outp)
        {
            while (true)
            {
                SchemeObject input;
                if ((input = inp.Read()) is Eof)
                {
                    inp.Close();
                    return Undefined.Instance;
                }

                if (outp != null)
                {
                    outp.WriteLine("> " + input);
                }

                var res = this.Eval(input);
                if (outp != null)
                {
                    outp.WriteLine(res.ToString());
                }
            }
        }