Example #1
0
        private void WaitForConnect()
        {
            _led.Write(true);
            _nrf.Connect(15, 32);

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

                if (nrfEvent == null)
                {
                    continue;
                }

                if (nrfEvent.EventType == Nrf8001EventType.PipeStatus && _nrf.OpenPipesBitmap > 1)
                {
                    _led.Write(false);
                    return;
                }
                else if (nrfEvent.EventType == Nrf8001EventType.Disconnected)
                {
                    _nrf.Connect(15, 32);
                }
            }
        }
Example #2
0
        public static void Main()
        {
            meadowLogo = Resources.GetBytes(Resources.BinaryResources.meadow_logo);

            InitDisplays();

            UpdateDisplays();

            Debug.Print("Network Clock");

            UpdateOled("No IP address", "Connecting ...");

            Thread.Sleep(200);

            Netduino.Foundation.Network.Initializer.NetworkConnected += Initializer_NetworkConnected;

            Netduino.Foundation.Network.Initializer.InitializeNetwork(updName);

            var led = new OutputPort(Pins.ONBOARD_LED, false);

            Debug.Print("InitializeNetwork()");

            while (true)
            {
                count++;
                led.Write(true);
                Thread.Sleep(BlinkRate);
                led.Write(false);
                Thread.Sleep(BlinkRate);
                UpdateDisplays();
            }

            Thread.Sleep(-1);
        }
Example #3
0
        /// <summary>
        /// Blink the time: hours, pause, ten minutes, pause, one minutes.
        /// </summary>
        /// <param name="led"></param>
        private static void RederTime(OutputPort led)
        {
            var now       = DateTime.Now;
            var hour      = now.Hour % 12;
            var tenMinute = now.Minute / 10;
            var rMinute   = now.Minute % 10;
            var segments  = new[] { hour, tenMinute, rMinute };

            foreach (var segment in segments)
            {
                if (segment == 0)
                {
                    led.Write(true);
                    Thread.Sleep(1500);
                    led.Write(false);
                }
                for (int i = 0; i < segment; i++)
                {
                    led.Write(true);
                    Thread.Sleep(500);
                    led.Write(false);
                    Thread.Sleep(250);
                }
                Thread.Sleep(1000);
            }
        }
 public void ListenForRequest()
 {
     while (true)
     {
         using (Socket clientSocket = socket.Accept())
         {
             //Get clients IP
             IPEndPoint clientIP       = clientSocket.RemoteEndPoint as IPEndPoint;
             EndPoint   clientEndPoint = clientSocket.RemoteEndPoint;
             //int byteCount = cSocket.Available;
             int bytesReceived = clientSocket.Available;
             if (bytesReceived > 0)
             {
                 //Get request
                 byte[] buffer    = new byte[bytesReceived];
                 int    byteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None);
                 string request   = new string(Encoding.UTF8.GetChars(buffer));
                 Debug.Print(request);
                 //Compose a response
                 string response = "Hello World from HelloWorldWebServer!";
                 string header   = "HTTP/1.0 200 OK\r\nContent-Type: text; charset=utf-8\r\nContent-Length: " + response.Length.ToString() + "\r\nConnection: close\r\n\r\n";
                 clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);
                 clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);
                 //Blink the onboard LED
                 led.Write(true);
                 Thread.Sleep(150);
                 led.Write(false);
             }
         }
     }
 }
Example #5
0
 private void MoveIn()
 {
     _lastPosition = CurrentPosition;
     _megaMotoPWMA.Write(false);
     _megaMotoPWMB.Write(true);
     _megaMotoEnable.Write(true);
 }
        public static void Main()
        {
            // write your code here

            //PWM led1 = new PWM(PWMChannels.PWM_PIN_D3, 500, .5, false);
            //led1.Start();
            //led1.DutyCycle = .05;

            OutputPort led = new OutputPort(Pins.GPIO_PIN_D13, false);



            //A while-loop will make our code loop indefinitely
            while (true)
            {
                led.Write(false);
                Thread.Sleep(1000);

                led.Write(true);
                Thread.Sleep(1000);
            }



            /*
             * OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
             * while (true)
             * {
             *  led.Write(true); // turn on the LED
             *  Thread.Sleep(250); // sleep for 250ms
             *  led.Write(false); // turn off the LED
             *  Thread.Sleep(250); // sleep for 250ms
             * }
             */
        }
            public virtual void Start()
            {
                int currentTickCount;
                int endTickCount;
                int blinkRate;

                while (true)
                {
                    blink.WaitOne();
                    running = true;

                    currentTickCount = Environment.TickCount;
                    endTickCount     = currentTickCount + blinkMilliseconds;
                    blinkRate        = blinkRateMilliseconds;

                    while (currentTickCount < endTickCount)
                    {
                        led.Write(ledOn = !ledOn);
                        Util.Delay(blinkRate);
                        currentTickCount = Environment.TickCount;
                    }
                    led.Write(false);
                    running = false;
                }
            }
Example #8
0
        public static void Main()
        {
            OutputPort led  = new OutputPort((Cpu.Pin) 63, false); //Blue led
            OutputPort led0 = new OutputPort((Cpu.Pin) 62, false); //Red led
            OutputPort led1 = new OutputPort((Cpu.Pin) 61, false); //Orange led
            OutputPort led2 = new OutputPort((Cpu.Pin) 60, false); //Green led

            while (true)                                           //Control loop
            {
                //Turn on all leds
                led.Write(true);
                led0.Write(true);
                led1.Write(true);
                led2.Write(true);
                for (int i = 0; i < 100000; i++)
                {
                }                                   //Simple wait loop
                //Turn off all leds
                led.Write(false);
                led0.Write(false);
                led1.Write(false);
                led2.Write(false);
                for (int i = 0; i < 100000; i++)
                {
                }                                   //Simple wait loop
            }
        }
 static void AnimateLed(int sleepTime)
 {
     led.Write(true);
     Thread.Sleep(sleepTime);
     led.Write(false);
     Thread.Sleep(sleepTime);
 }
Example #10
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);
                }
            }
        }
 public void Reset()
 {
     Debug.Print("Resetting...");
     pin_RESET.Write(true);
     Thread.Sleep(500);
     pin_RESET.Write(false);
 }
Example #12
0
        private static void ControlLED()
        {
            while (true)
            {
                switch (state)
                {
                case LEDState.Initializing:
                    ledPort.Write(true);
                    Thread.Sleep(1000);
                    ledPort.Write(false);
                    Thread.Sleep(1000);
                    break;

                case LEDState.Ready:
                    if (!ledPort.Read())
                    {
                        ledPort.Write(true);
                    }
                    Thread.Sleep(50);
                    break;

                case LEDState.Playing:
                    ledPort.Write(true);
                    Thread.Sleep(500);
                    ledPort.Write(false);
                    Thread.Sleep(500);
                    break;

                default:
                    break;
                }
            }
        }
Example #13
0
        private WebResponse ProcessWebRequest(string request)
        {
            var response = new WebResponse {
                HttpStatusCode = 200
            };


            if (request != null)
            {
                request = request.ToLower();
                if (request.IndexOf("led=on") > 0)
                {
                    led.Write(true);
                    response = new WebResponse {
                        HttpStatusCode = 303, RedirectUrl = "/"
                    };
                }
                else if (request.IndexOf("led=off") > 0)
                {
                    led.Write(false);
                    response = new WebResponse {
                        HttpStatusCode = 303, RedirectUrl = "/"
                    };
                }
                else
                {
                    response.Content = GetStatusPage();
                }
            }
            else
            {
                response.Content = "";
            }
            return(response);
        }
Example #14
0
        // This method is run when the mainboard is powered up or reset.
        void ProgramStarted()
        {
            //update display
            characterDisplay.Clear();
            characterDisplay.Print("INIT LORA RADIO");

            //LORA init
            _loraSerial = new SimpleSerial(GHI.Pins.FEZSpiderII.Socket4.SerialPortName, 57600);
            _loraSerial.Open();
            _loraSerial.DataReceived += _loraSerial_DataReceived;
            //reset lora
            _restPort.Write(false);
            Thread.Sleep(1000);
            _restPort.Write(true);
            Thread.Sleep(1000);
            //setup lora for point to point
            //get lora version
            _loraSerial.WriteLine("sys get ver");
            Thread.Sleep(1000);
            //pause join
            _loraSerial.WriteLine("mac pause");
            Thread.Sleep(1000);
            //set antena power
            _loraSerial.WriteLine("radio set pwr 14");
            Thread.Sleep(1000);

            new Thread(SendData).Start();
        }
Example #15
0
        public static void Main()
        {
            //removed the button from the original MotorTest project
            //var switchButton = new InterruptPort(Pins.GPIO_PIN_A1, true, Port.ResistorMode.PullUp,
            //                                     Port.InterruptMode.InterruptEdgeLow);
            //switchButton.OnInterrupt += switchButton_OnInterrupt;


            //set the speed to 0 to start
            rightDrive.SetSpeed(0);
            leftDrive.SetSpeed(0);

            //set the direction of the motor
            rightDrive.Run(MotorDirection.Forward);
            leftDrive.Run(MotorDirection.Forward);
            onboardLed.Write(true);

            //wait for the IRSensors to stabilize
            Thread.Sleep(60000);

            frontSensor.SensorTriggered += FrontSensorTriggered;
            rearSensor.SensorTriggered  += RearSensorTriggered;

            while (true)
            {
                //turn off the LED to let you know it is ready.
                onboardLed.Write(false);

                //when the front or rear sensor is triggered switch directions
                RunCurrentProgram();
            }
            // ReSharper disable FunctionNeverReturns
        }
Example #16
0
        public static void Main()
        {
            //OutputPort reset = new OutputPort(Pins.GPIO_PIN_D9, true);
            OutputPort chipSelect = null;
            //chipSelect = new OutputPort(Pins.GPIO_PIN_D10, true);
            //SPI spiPort = new SPI(new SPI.Configuration(Pins.GPIO_NONE, false, 0, 0, true, true, 500, SPI.SPI_module.SPI1));
            SPI spiPort = new SPI(new SPI.Configuration(Pins.GPIO_PIN_D10, false, 0, 0, false, true, 500, SPI.SPI_module.SPI1));

            Thread.Sleep(100);

            while (true)
            {
                //byte[] writeBuffer = new byte[] { 0x42 }; // RegVersion exptecing 0x12
                byte[] writeBuffer = new byte[] { 0x06 }; // RegFreqMsb expecting 0x6C
                //byte[] writeBuffer = new byte[] { 0x07 }; // RegFreqMid expecting 0x80
                //byte[] writeBuffer = new byte[] { 0x08 }; // RegFreqLsb expecting 0x00
                byte[] readBuffer = new byte[1];

                if (chipSelect != null)
                {
                    chipSelect.Write(false);
                }
                spiPort.WriteRead(writeBuffer, readBuffer, 1);
                if (chipSelect != null)
                {
                    chipSelect.Write(true);
                }

                Debug.Print("Value = 0x" + BytesToHexString(readBuffer));

                Thread.Sleep(1000);
            }
        }
Example #17
0
        public void Set(string presence)
        {
            redLed.Write(invertedPins);
            yellowLed.Write(invertedPins);
            greenLed.Write(invertedPins);

            switch (presence)
            {
            case "DoNotDisturb":
            case "Busy":
                redLed.Write(!invertedPins);
                return;

            case "TemporarilyAway":
            case "Away":
                yellowLed.Write(!invertedPins);
                return;

            case "Free":
                greenLed.Write(!invertedPins);
                return;

            default:
                return;
            }
        }
                /// <summary>
                /// Set pins MS1 and MS2
                /// </summary>
                /// <param name="mode">Full, Half, Quarter, or OneEighth step</param>
                private void ChangeStepMode(Mode mode)
                {
                    if (_StepModePinOne != null & _StepModePinTwo != null)
                    {
                        switch (mode)
                        {
                        case Mode.Full:
                            _StepModePinOne.Write(false);
                            _StepModePinTwo.Write(false);
                            break;

                        case Mode.Half:
                            _StepModePinOne.Write(true);
                            _StepModePinTwo.Write(false);
                            break;

                        case Mode.Quarter:
                            _StepModePinOne.Write(false);
                            _StepModePinTwo.Write(true);
                            break;

                        case Mode.OneEighth:
                            _StepModePinOne.Write(true);
                            _StepModePinTwo.Write(true);
                            break;
                        }
                    }
                }
Example #19
0
 private void Reset()
 {
     _resetPin.Write(false);
     Thread.Sleep(300);
     _resetPin.Write(true);
     Thread.Sleep(1000);
 }
Example #20
0
        static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
//            throw new NotImplementedException();
            byte[] bytes = new byte[serial.BytesToRead];
            serial.Read(bytes, 0, bytes.Length);
            //
            //  "a" received, move the servo and start
            //  recording
            //
            if (bytes[0] == 97)
            {
                red.Write(false);
                green.Write(false);
                Thread.Sleep(waitTime);
                red.Write(true);
                flex.Duration = relPos;
                collectData();
                green.Write(true);
                red.Write(false);
                flex.Duration = armPos;
            }
            //
            //  "b" received, write the data to the port
            //
            else if (bytes[0] == 98)
            {
                for (int i = 0; i < nSamples; i++)
                {
                    byte[] send = System.Text.Encoding.UTF8.GetBytes(readTime[i].ToString() + " " + reading[i].ToString() + "\n");
                    serial.Write(send, 0, send.Length);
                    red.Write(true);
                    green.Write(true);
                }
            }
        }
Example #21
0
 private static void reset()
 {
     _reset.Write(false);
     Thread.Sleep(20);
     _reset.Write(true);
     Thread.Sleep(200);
 }
Example #22
0
 /// <returns>Number of ticks it takes to get back sonic pulse</returns>
 public long Ping()
 {
     // Reset Sensor
     portOut.Write(true);
     Thread.Sleep(1);
     // Start Clock
     endTick   = 0L;
     beginTick = System.DateTime.Now.Ticks;
     // Trigger Sonic Pulse
     portOut.Write(false);
     // Wait 1/20 second (this could be set as a variable instead of constant)
     Thread.Sleep(50);
     if (endTick > 0L)
     {
         // Calculate Difference
         long elapsed = endTick - beginTick;
         // Subtract out fixed overhead (interrupt lag, etc.)
         elapsed -= minTicks;
         if (elapsed < 0L)
         {
             elapsed = 0L;
         }
         // Return elapsed ticks
         return(elapsed);
     }
     // Sonic pulse wasn't detected within 1/20 second
     return(-1L);
 }
Example #23
0
        /// <summary>
        /// Sets the state of the latch on the motor shield
        /// </summary>
        /// <param name="latchState">A byte representing the new pin state on the latch</param>
        internal void latch_tx(byte latchState)
        {
            //LATCH_PORT &= ~_BV(LATCH);
            motorLatch.Write(false);

            //SER_PORT &= ~_BV(SER);
            motorData.Write(false);

            for (int i = 0; i < 8; i++)
            {
                //CLK_PORT &= ~_BV(CLK);
                motorClock.Write(false);

                int mask = (1 << (7 - i));
                if ((latchState & mask) != 0)
                {
                    //SER_PORT |= _BV(SER);
                    motorData.Write(true);
                }
                else
                {
                    //SER_PORT &= ~_BV(SER);
                    motorData.Write(false);
                }
                //CLK_PORT |= _BV(CLK);
                motorClock.Write(true);
            }
            //LATCH_PORT |= _BV(LATCH);
            motorLatch.Write(true);
        }
Example #24
0
        static void buttonInterruptPort_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            switch (_counter % 4)
            {
            case 0:
                RedPort.Write(true);
                BluePort.Write(false);
                OrangePort.Write(false);
                GreenPort.Write(false);
                break;

            case 1:
                RedPort.Write(false);
                BluePort.Write(true);
                OrangePort.Write(false);
                GreenPort.Write(false);
                break;

            case 2:
                RedPort.Write(false);
                BluePort.Write(false);
                OrangePort.Write(false);
                GreenPort.Write(true);
                break;

            case 3:
                RedPort.Write(false);
                BluePort.Write(false);
                OrangePort.Write(true);
                GreenPort.Write(false);
                break;
            }
            ++_counter;
        }
Example #25
0
        public static void Main()
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            while (true)
            {
                foreach (char t in "HELLO WORLD")
                {
                    for (int i = ",ETIANMSURWDKGOHVF,L,PJBXCYZQ,,54,3,,,2,,,,,,,16,,,,,,,7,,,8,90".IndexOf(t); i > 0; i /= 2)
                    {
                        led.Write(true);
                        if ("-."[i-- % 2] == '.')
                        {
                            Thread.Sleep(100);
                        }
                        else
                        {
                            Thread.Sleep(300);
                        }
                        led.Write(false);
                        Thread.Sleep(100);
                    }
                    Thread.Sleep(300);
                    if (t.Equals(' '))
                    {
                        Thread.Sleep(400);
                    }
                }

                Thread.Sleep(1400);
            }
        }
        private void Initialize()
        {
            _reset.Write(false);
            Thread.Sleep(10);
            _reset.Write(true);

            SendCommand(0xF4, 0x90, 0xB3, 0xA0, 0xD0,
                        0xF0, 0xE2, 0xD4, 0x70, 0x66, 0xB2, 0xBA, 0xA1, 0xA3, 0xAB, 0x94, 0x95,
                        0x95, 0x95, 0xF5, 0x90, 0xF1, 0x00, 0x10, 0x22, 0x30, 0x45, 0x50, 0x68,
                        0x70, 0x8A, 0x90, 0xAC, 0xB0, 0xCE, 0xD0, 0xF2, 0x0F, 0x10, 0x20, 0x30,
                        0x43, 0x50, 0x66, 0x70, 0x89, 0x90, 0xAB, 0xB0, 0xCD, 0xD0, 0xF3, 0x0E,
                        0x10, 0x2F, 0x30, 0x40, 0x50, 0x64, 0x70, 0x87, 0x90, 0xAA, 0xB0, 0xCB,
                        0xD0, 0xF4, 0x0D, 0x10, 0x2E, 0x30, 0x4F, 0x50, 0xF5, 0x91, 0xF1, 0x01,
                        0x11, 0x22, 0x31, 0x43, 0x51, 0x64, 0x71, 0x86, 0x91, 0xA8, 0xB1, 0xCB,
                        0xD1, 0xF2, 0x0F, 0x11, 0x21, 0x31, 0x42, 0x51, 0x63, 0x71, 0x85, 0x91,
                        0xA6, 0xB1, 0xC8, 0xD1, 0xF3, 0x0B, 0x11, 0x2F, 0x31, 0x41, 0x51, 0x62,
                        0x71, 0x83, 0x91, 0xA4, 0xB1, 0xC6, 0xD1, 0xF4, 0x08, 0x11, 0x2B, 0x31,
                        0x4F, 0x51, 0x80, 0x94, 0xF5, 0xA2, 0xF4, 0x60, 0xF0, 0x40, 0x50, 0xC0,
                        0xF4, 0x70);

            Thread.Sleep(10);

            SendCommand(0xF0, 0x81,
                        0xF4, 0xB3, 0xA0,
                        0xF0, 0x06, 0x10, 0x20, 0x30,
                        0xF5, 0x0F, 0x1C, 0x2F, 0x34);
        }
Example #27
0
        // This method is run when the mainboard is powered up or reset.
        void ProgramStarted()
        {
            Display.Populate(Display.GHIDisplay.DisplayT35);

            if (Display.Save())
            {
                PowerState.RebootDevice(false);
            }



            //LORA init
            _loraSerial = new SimpleSerial(GHI.Pins.FEZRaptor.Socket1.SerialPortName, 57600);
            _loraSerial.Open();
            _loraSerial.DataReceived += _loraSerial_DataReceived;
            //reset lora
            _restPort.Write(false);
            Thread.Sleep(1000);
            _restPort.Write(true);
            Thread.Sleep(1000);
            //setup lora for point to point
            //get lora version


            _loraSerial.WriteLine("sys get ver");
            Thread.Sleep(1000);
            //pause join
            _loraSerial.WriteLine("mac pause");
            Thread.Sleep(1000);
            //set antena power
            _loraSerial.WriteLine("radio set pwr 14");
            Thread.Sleep(1000);

            new Thread(SendData).Start();
        }
Example #28
0
        public static void Upload(PageCollection pageCollection)
        {
            OutputPort onboardLed = new OutputPort(ShieldConfiguration.CurrentConfiguration.OnboardLedPin, true);

            SPI.Configuration spiConfig = new SPI.Configuration(
                ShieldConfiguration.CurrentConfiguration.SpiChipSelectPin,
                false,
                100,
                100,
                false,
                true,
                1000,
                ShieldConfiguration.CurrentConfiguration.SpiModule
                );
            var spi      = new SpotSpi(spiConfig);
            var uploader = new Uploader(spi);

            if (uploader.IsShieldInBootloaderMode())
            {
                var uploadStatusIndicator = new UploadStatusIndicator(
                    spi
                    );

                try
                {
                    //var securityRegisterData = uploader.SecurityRegisterRead();
                    //var userData = new byte[Constants.SecurityRegisterUserFieldLength];
                    //Array.Copy(securityRegisterData, 4, userData, 0, userData.Length);
                    //var userDataString = new string(System.Text.Encoding.UTF8.GetChars(userData));
                    //Debug.Print("Programming \"" + userDataString + "\"");
                    uploadStatusIndicator.Status = UploadStatusIndicator.UploadStatus.Uploading;
                    uploader.UploadBitstream(pageCollection);
                    uploadStatusIndicator.Status = UploadStatusIndicator.UploadStatus.Succeeded;
                }
                catch
                {
                    // Any exception is a failed upload

                    uploadStatusIndicator.Status = UploadStatusIndicator.UploadStatus.Failed;
                    throw;
                }
                finally
                {
                    onboardLed.Write(false);
                }
            }
            else
            {
                // Flash the onboard LED to indicate upload failure due to
                // not being in bootstrapping mode

                Thread.Sleep(500);
                onboardLed.Write(false);
                Thread.Sleep(500);
                onboardLed.Write(true);
                Thread.Sleep(500);
                onboardLed.Write(false);
            }
        }
Example #29
0
        public static void Main()
        {
            const int STATE_GOING_DOWN     = 0;
            const int STATE_GOING_UP       = 1;
            const int FREQUENCY            = 2; //Frequency in Hz
            const int ONE_SECOND_IN_MS     = 1000;
            const int PERCENT_TO_INCREMENT = 10;

            int CyclicalReport            = ONE_SECOND_IN_MS / FREQUENCY;
            int percentOfCyclicalReport   = CyclicalReport / PERCENT_TO_INCREMENT;
            int oneSecondPassedForCounter = FREQUENCY - 1;

            int tUp   = 0;
            int tDown = CyclicalReport;
            int state = STATE_GOING_UP;
            int counterToOneSecond = 0;

            OutputPort LedSpider = new OutputPort(GHICard.DebugLed, false);

            //Main loop
            while (true)
            {
                //Turn on and of the led
                LedSpider.Write(true);
                Thread.Sleep(tUp);
                LedSpider.Write(false);
                Thread.Sleep(tDown);

                //Look if one second passed or not
                if (counterToOneSecond == oneSecondPassedForCounter)
                {
                    counterToOneSecond = 0;
                    if (state == STATE_GOING_UP)
                    {
                        tUp   += percentOfCyclicalReport;
                        tDown -= percentOfCyclicalReport;
                    }
                    else if (state == STATE_GOING_DOWN)
                    {
                        tUp   -= percentOfCyclicalReport;
                        tDown += percentOfCyclicalReport;
                    }

                    //State management
                    if (tUp == 0 && tDown == CyclicalReport)
                    {
                        state = STATE_GOING_UP;
                    }
                    else if (tUp == CyclicalReport && tDown == 0)
                    {
                        state = STATE_GOING_DOWN;
                    }
                }
                else
                {
                    counterToOneSecond++;
                }
            }
        }
        public static void Main()
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            App app = new App();

            app.Run();

            BMP180 bmp180 = new BMP180();

            bmp180.begin();

            Socket     serverSocket     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint listenerEndPoint = new IPEndPoint(IPAddress.Any, 80);

            serverSocket.Bind(listenerEndPoint);
            serverSocket.Listen(1);

            Debug.Print("Waiting for HTTP connections (port 80)");
            while (true)
            {
                Thread.Sleep(500);
                var clientSocket = serverSocket.Accept();

                led.Write(true);

                Debug.Print("Got HTTP connection.");

                double temp, pressure;
                unsafe
                {
                    int delay = bmp180.startTemperature();
                    Thread.Sleep(delay);
                    bmp180.getTemperature(&temp);

                    delay = bmp180.startPressure(3);
                    Thread.Sleep(delay);
                    bmp180.getPressure(&pressure, temp);
                }

                double normalizedPressure = bmp180.sealevel(pressure, 350 /* meters */);

                Debug.Print("Temp: " + temp);
                Debug.Print("Absolute Pressure: " + pressure);
                Debug.Print("Normalized (sea level) Pressure: " + normalizedPressure);

                string response = "{\n"
                                  + "\t\"temperature\": " + temp + ",\n"
                                  + "\t\"absolute pressure\": " + pressure + ",\n"
                                  + "\t\"normalized (sea level) pressure\": " + normalizedPressure + "\n"
                                  + "}";
                string header = "HTTP/1.0 200 OK\r\nContent-Type: text; charset=utf-8\r\nContent-Length: " + response.Length.ToString() + "\r\nConnection: close\r\n\r\n";
                clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);
                clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);

                Debug.Print("Sent response: " + response);
                led.Write(false);
            }
        }