示例#1
0
        public static void Main()
        {
            InterruptPort button =
                new InterruptPort((Cpu.Pin) 0, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLevelHigh); //Button Declaration.
            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
            {
                if (button.Read() == true)                                                                                    //if button click
                {
                    //Turn on red and blue led, turn off orange and green led
                    led.Write(true);
                    led0.Write(true);
                    led1.Write(false);
                    led2.Write(false);
                }
                else
                {
                    //Turn on orange and green led, turn off red and blue led
                    led.Write(false);
                    led0.Write(false);
                    led1.Write(true);
                    led2.Write(true);
                }
            }
        }
        public UltrasonicDistance(Cpu.Pin trigger, Cpu.Pin echo)
        {
            Trigger = new OutputPort(trigger, false);

            Echo              = new InterruptPort(echo, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeBoth);
            Echo.OnInterrupt += Echo_OnInterrupt;
        }
示例#3
0
        public static void Main()
        {
            try
            {
                //Mqtt configuration

                //_client = new MqttClient("192.168.1.102");
                _client = new MqttClient("gnatmqsample.cloudapp.net");

                _client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

                _client.Connect(Guid.NewGuid().ToString());
                _client.Subscribe(new[] { "sensor/s1" }, new[] { MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE });

                //Board configuration
                _ledPort = new OutputPort(Pins.ONBOARD_LED, false);
                InterruptPort switchPort = new InterruptPort(Pins.ONBOARD_SW1,
                                                             false,
                                                             Port.ResistorMode.Disabled,
                                                             Port.InterruptMode.InterruptEdgeBoth);

                switchPort.OnInterrupt += SwitchPortOnOnInterrupt;

                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }
        }
示例#4
0
 /// <summary>
 ///     Configure the interrupts for the ADXL362.
 /// </summary>
 /// <remark>
 ///     Set the interrupt mask for interrupt pins 1 and 2 and connect Netduino
 ///     pins to the interrupt pins on the ADXL362 if requested.
 ///
 ///     Interrupts can be disabled by passing 0 for the interrupt maps.  It is also
 ///     possible to disconnect the Netduino and ADXL362 by setting the interrupt pin
 ///     to GPIO_NONE.
 /// </remark>
 /// <param name="interruptMap1">Bit mask for interrupt pin 1</param>
 /// <param name="interruptPin1">Pin connected to interrupt pin 1 on the ADXL362.</param>
 /// <param name="interruptMap2">Bit mask for interrupt pin 2</param>
 /// <param name="interruptPin2">Pin connected to interrupt pin 2 on the ADXL362.</param>
 public void ConfigureInterrupts(byte interruptMap1, Cpu.Pin interruptPin1, byte interruptMap2 = 0, Cpu.Pin interruptPin2 = Cpu.Pin.GPIO_NONE)
 {
     _interrupt1?.Dispose();
     _interrupt2?.Dispose();
     _adxl362.WriteBytes(new byte[] { Command.WriteRegister, interruptMap1, interruptMap2 });
     if (interruptPin1 != Cpu.Pin.GPIO_NONE)
     {
         _interrupt1 = new InterruptPort(interruptPin1, false, MapResistorMode((interruptMap1 & 0xf0) > 0),
                                         MapInterruptMode((interruptMap1 & 0xf0) > 0));
         _interrupt1.OnInterrupt += SensorInterrupt;
     }
     else
     {
         _interrupt1 = null;
     }
     if (interruptPin2 != Cpu.Pin.GPIO_NONE)
     {
         _interrupt2 = new InterruptPort(interruptPin1, false, MapResistorMode((interruptMap2 & 0xf0) > 0),
                                         MapInterruptMode((interruptMap2 & 0xf0) > 0));
         _interrupt2.OnInterrupt += SensorInterrupt;
     }
     else
     {
         _interrupt2 = null;
     }
 }
示例#5
0
        /// <summary>
        /// Disables the key functionality.
        /// </summary>
        public static void Disable()
        {
            if (!Key.IsEnabled)
            {
                return;
            }

            Key.Left.Dispose();
            Key.Left = null;
            Key.Right.Dispose();
            Key.Right = null;
            Key.Up.Dispose();
            Key.Up = null;
            Key.Down.Dispose();
            Key.Down = null;
            Key.A.Dispose();
            Key.A = null;
            Key.B.Dispose();
            Key.B = null;
            Key.C.Dispose();
            Key.C = null;
            Key.Power.Dispose();
            Key.Power = null;
            Key.Start.Dispose();
            Key.Start = null;

            Key.Enabled = false;
        }
示例#6
0
        /// <summary>
        ///     Default constructor
        /// </summary>
        /// <param name="socket">The socket in which the USB UART click board is inserted into.</param>
        /// <param name="baudRate">Baud Rate enumeration of usable baud rates (ones that actually work), see <see cref="System.IO.Ports.SerialPort.BaudRate"/></param>
        /// <param name="handshake">Optional - Handshake, defaults to None, see <see cref="System.IO.Ports.Handshake"/>. <see cref="System.IO.Ports.Handshake.RequestToSend "/> is not functional and will be set to <see cref="Handshake.None"/>.</param>
        /// <exception cref="PinInUseException">A <see cref="PinInUseException"/> will be thrown if the Tx, Rx, Rst, Int, Cs, Pwm are used in a stacked module arrangement.</exception>
        public USBUARTClick(Hardware.Socket socket, BaudRate baudRate, Handshake handshake)
        {
            try
            {
                // Rst Pin is connected to FT232RL CTS Pin, Int Pin is connected to FT232RL RTS Pin, Pwm Pin is connected to FT232RL CBUS3 Pin (USB Power), Cs Pin is connected to FT232RL CBUS4 Pin (USB Sleep/Suspend)
                Hardware.CheckPins(socket, socket.Tx, socket.Rx, socket.Rst, socket.Int, socket.Cs, socket.Pwm);
                _serial = new SimpleSerial(socket.ComPort, (int)baudRate)
                {
                    Handshake = handshake == Handshake.RequestToSend ? Handshake.None : handshake
                };

                _serial.DataReceived  += _serial_DataReceived;
                _serial.ErrorReceived += _serial_ErrorReceived;
                _serial.Open();

                _powerPin = new InterruptPort(socket.Pwm, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
                _sleepPin = new InterruptPort(socket.Cs, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

                _powerPin.OnInterrupt += powerPin_OnInterrupt;
                _sleepPin.OnInterrupt += sleepPin_OnInterrupt;

                _powerPin.EnableInterrupt();
                _sleepPin.EnableInterrupt();
            }
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }
        }
示例#7
0
            public static void OnPress(Cpu.Pin pin, Action callback)
            {
                var btn = new InterruptPort(pin, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

                btn.OnInterrupt += (s, e, t) => callback();
                buttons.Add(btn);
            }
示例#8
0
        public static void Main()
        {
            _outLed  = new OutputPort(Pins.ONBOARD_LED, false);
            _outDig1 = new OutputPort(Pins.GPIO_PIN_D0, false);
            _isOn    = false;


            InterruptPort mySwicht = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

            mySwicht.OnInterrupt += new NativeEventHandler(mySwicht_OnInterrupt);

            while (true)
            {
                if (_isOn)
                {
                    _outLed.Write(true);
                    _outDig1.Write(false);
                    Thread.Sleep(500);
                    _outLed.Write(false);
                    _outDig1.Write(true);
                    Thread.Sleep(500);
                }
                else
                {
                    _outLed.Write(false);
                    _outDig1.Write(false);
                }
            }
        }
示例#9
0
        public static void Main()
        {
            //set current date and time + 1 or 2 minutes
            var newDateTime = new DateTime(2012, 09, 04, 21, 30, 45);

            Debug.Print("Wait for " + newDateTime);

            using (var userButton = new InterruptPort(Stm32F4Discovery.ButtonPins.User,
                                                      false, Port.ResistorMode.PullDown,
                                                      Port.InterruptMode.InterruptEdgeLow))
            {
                var ds1307    = new DS1307();
                var storeData = Reflection.Serialize(newDateTime, typeof(DateTime));
                ds1307.WriteRam(storeData);

                //push userbutton when time comes
                userButton.OnInterrupt += (d1, d2, t) =>
                {
                    ds1307.SetDateTime(newDateTime);
                    Debug.Print("Initialized");
                };

                Thread.Sleep(Timeout.Infinite);
            }
        }
示例#10
0
        private static void Init()
        {
            // WiFi //
            WiFi       = new WiFiClient(Defines.HOST_IP, Defines.HOST_PORT);
            WiFiThread = new Thread(WiFi.Run);
            WiFiThread.Start();

            // Roomba //
            roomba = new RoombaSerial(SerialPorts.COM1, Pins.GPIO_PIN_D4);

            // SDCard //
            SDCard = new Logger(Defines.LOG_FILENAME);

            // Session ID //
            int    sid         = GetRandomNumber();
            string SessionID   = sid.ToString("X4");
            string new_session = "--- NEW SESSION {" + SessionID + "} VERSION {" + VERSION + "}---";

            FifoBuffer.Push(new_session);
            SDCard.Log(new_session);

            // Pushbutton //
            PushButton              = new InterruptPort(Pins.ONBOARD_BTN, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
            PushButton.OnInterrupt += new NativeEventHandler(OnPushButton);
        }
示例#11
0
 public override void ButtonEvent(Buttons button, InterruptPort port, ButtonDirection direction, DateTime time)
 {
     if ((ButtonDirection)Program.ButtonStates[Buttons.MiddleRight] == ButtonDirection.Down)
     {
         Program.StateManager.ChangeState(MainMenuState.Instance);
     }
 }
示例#12
0
        private StorageManager()
        {
            _usbStorages = new Hashtable();

            _sdDetectPort              = new InterruptPort(EMX.Pin.IO24, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
            _sdDetectPort.OnInterrupt += new NativeEventHandler(_sdDetectPort_OnInterrupt);

            try
            {
                MountCardStorage();
            }
            catch (Exception)
            {
                //TODO: emulator throws exception
                return;
            }

            USBHostController.DeviceConnectedEvent    += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceConnectedEvent);
            USBHostController.DeviceDisconnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceDisconnectedEvent);

            USBH_Device[] connectedDevices = USBHostController.GetDevices();
            foreach (USBH_Device connected in connectedDevices)
            {
                USBHostController_DeviceConnectedEvent(connected);
            }
        }
        public OnOffDigitalSensorMgr(GHI.Processor.DeviceType deviceType, int socketNumber, int pDstOffset, string pDstStart, string pDstEnd, string pSensorLabel = "undef", string pSensorLocation = "undef", string pMeasuredQuantity = "undef", string pDestinationTable = "undef", string pChannel = "000")
        {
            if ((deviceType != GHI.Processor.DeviceType.EMX) && (deviceType != GHI.Processor.DeviceType.G120E))
            {
                throw new NotSupportedException("Mainboard is not supported");
            }

            dstOffset = pDstOffset;
            dstStart  = pDstStart;
            dstEnd    = pDstEnd;

            SensorLabel      = pSensorLabel;
            SensorLocation   = pSensorLocation;
            MeasuredQuantity = pMeasuredQuantity;
            DestinationTable = pDestinationTable;
            Channel          = pChannel;


            input = new InterruptPort(deviceType == GHI.Processor.DeviceType.EMX ? GHI.Pins.FEZSpider.Socket4.Pin4 : GHI.Pins.FEZSpiderII.Socket4.Pin3, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);

            input.ClearInterrupt();
            input.DisableInterrupt();
            _stopped         = true;
            ReadBurnerThread = new Thread(runReadBurnerThread);
            ReadBurnerThread.Start();
        }
示例#14
0
        void Initialize(GoSocket socket)
        {
            // now try to bind to the socket (and verify our module's uniqueId)
            if (!base.BindSocket(socket, _moduleGuid))
            {
                throw new ArgumentException();
            }

            // get socket's physical pins and SPI bus
            Cpu.Pin        socketGpioPin;
            SPI.SPI_module socketSpiModule;
            Cpu.Pin        socketSpiSlaveSelectPin;
            //
            socket.GetPhysicalResources(out socketGpioPin, out socketSpiModule, out socketSpiSlaveSelectPin);

            _spiConfig = new SPI.Configuration(socketSpiSlaveSelectPin, false, 0, 0, false, false, 500, socketSpiModule);
            _spi       = new SPI(_spiConfig);

            // wire up event handlers
            _interruptPort              = new InterruptPort((Cpu.Pin)socketGpioPin, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
            _interruptPort.OnInterrupt += _interruptPort_OnInterrupt;

            // read initial button state
            _isPressed = !_interruptPort.Read();
        }
示例#15
0
 protected void Dispose(bool disposing)
 {
     if (null != _fifoPort)
     {
         _fifoPort.Dispose(); _fifoPort = null;
     }
     if (null != _fifopInterrupt)
     {
         _fifopInterrupt.Dispose(); _fifopInterrupt = null;
     }
     if (null != _sfdInterrupt)
     {
         _sfdInterrupt.Dispose(); _sfdInterrupt = null;
     }
     if (null != _resetPort)
     {
         _resetPort.Dispose(); _resetPort = null;
     }
     if (null != _ccaPort)
     {
         _ccaPort.Dispose(); _ccaPort = null;
     }
     if (null != _powerPort)
     {
         _powerPort.Dispose(); _powerPort = null;
     }
     if (null != _spi)
     {
         lock (_spi)
         {
             _spi.Dispose();
             _spi = null;
         }
     }
 }
示例#16
0
        public static void Main()
        {
            switch (SystemUpdate.GetMode())
            {
            case SystemUpdate.SystemUpdateMode.NonFormatted:
                SystemUpdate.EnableBootloader();
                break;

            case SystemUpdate.SystemUpdateMode.Bootloader:
                throw new InvalidOperationException("We must be in application mode!");
            }

            SystemUpdate.AlwaysRunBootloader(true);

            _led = new Led(LedPin);

            Debug.Print("App v1.0");
            _led.BlinkOn(1500);

            //Debug.Print("App v2.0");
            //_led.BlinkOn(500);

            _ldrButton              = new InterruptPort(LdrPin, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            _ldrButton.OnInterrupt += (d1, d2, t) => SystemUpdate.AccessBootloader();

            Thread.Sleep(Timeout.Infinite);
        }
示例#17
0
        /// <summary>Constructs a new instance.</summary>

        //public ButtonNETMF(Cpu.Pin intPort, Cpu.Pin buttonLED)

        /*
         * public ButtonNETMF(GHI.Processor.DeviceType deviceType, int socketNumber)
         * {
         *  this.currentMode = LedMode.Off;
         *
         *  Cpu.Pin _inputPort = Cpu.Pin.GPIO_Pin13;
         *  Cpu.Pin _outputPort = Cpu.Pin.GPIO_Pin14;
         *
         *  this.input = new InterruptPort(_inputPort, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
         *  this.led = new OutputPort(_outputPort, false);
         *
         *  switch (deviceType)
         *  {
         *      case GHI.Processor.DeviceType.G120E:
         *          {
         *              switch (socketNumber)
         *              {
         *                  case 12:
         *                      {
         *                          _inputPort = FEZSpiderII.Socket12.Pin3;
         *                          _outputPort = FEZSpiderII.Socket12.Pin4;
         *                      }
         *                      break;
         *
         *                  default:
         *                      {
         *                          throw new NotSupportedException("Socket not supported");
         *                          break;
         *                      }
         *
         *              }
         *          }
         *          break;
         *      default:
         *          {
         *              throw new NotSupportedException("Mainboard not supported");
         *              break;
         *          }
         *  }
         *
         *
         *
         *  /*
         *  if (deviceType == DeviceType.G120E)
         *  {
         *      _inputPort = FEZSpiderII.Socket12.Pin3;
         *      _outputPort = FEZSpiderII.Socket12.Pin4;
         *  }
         */

        //this.input = new InterruptPort(FEZSpiderII.Socket12.Pin3, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
        //this.input = new InterruptPort(_inputPort, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
        //this.led = new OutputPort(_outputPort, false);



        //this.input = new InterruptPort(FEZSpiderII.Socket12.Pin3, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
        //this.led = new OutputPort(FEZSpiderII.Socket12.Pin4, false);



        /*
         * switch (deviceType)
         * {
         *  case GHI.Processor.DeviceType.G120E:
         *  {
         *      switch (socketNumber)
         *      {
         *          case 12:
         *              {
         *                  this.input = new InterruptPort(_inputPort, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
         *                  this.led = new OutputPort(_outputPort, false);
         *              }
         *              break;
         *              default:
         *              {
         *                  throw new NotSupportedException("Socket not supported");
         *              }
         *      }
         *  }
         *  break;
         *  case GHI.Processor.DeviceType.EMX:
         *  {
         *      switch (socketNumber)
         *      {
         *          case 12:
         *              {
         *                  this.input = new InterruptPort(FEZSpider.Socket12.Pin3, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
         *                  this.led = new OutputPort(GHI.Pins.FEZSpider.Socket12.Pin4, false);
         *              }
         *              break;
         *          default:
         *              {
         *                  throw new NotSupportedException("Socket not supported");
         *              }
         *      }
         *  }
         *  break;
         *
         *
         *  default:
         *  {
         *      throw new NotSupportedException("Mainboard not supported");
         *  }
         * }
         */


        // this.input.OnInterrupt += input_OnInterrupt;
        // }



        public ButtonNETMF(Cpu.Pin intPort, Cpu.Pin buttonLED)
        {
            this.currentMode        = LedMode.Off;
            this.input              = new InterruptPort(intPort, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
            this.led                = new OutputPort(buttonLED, false);
            this.input.OnInterrupt += input_OnInterrupt;
        }
示例#18
0
        public NRFC(Hardware.Socket socket)
        {
            Hardware.CheckPins(socket, socket.Miso, socket.Mosi, socket.Cs, socket.Sck, socket.Rst, socket.Int);

            _spiConfig = new SPI.Configuration(socket.Cs, false, 0, 0, false, true, 2000, socket.SpiModule);
            if (Hardware.SPIBus == null)
            {
                Hardware.SPIBus = new SPI(_spiConfig);
            }

            // Initialize IRQ Port
            _irqPin              = new InterruptPort(socket.Int, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            _irqPin.OnInterrupt += HandleInterrupt;

            // Initialize Chip Enable Port
            _cePin = new OutputPort(socket.Rst, false);

            // Module reset time
            Thread.Sleep(100);

            _initialized = true;

            _transmitSuccessFlag = new ManualResetEvent(false);
            _transmitFailedFlag  = new ManualResetEvent(false);
        }
示例#19
0
        public static void Main()
        {
            #region Butonlar
            InterruptPort butonUst = new InterruptPort(Cpu.Pin.GPIO_Pin2, false,
                                                       Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeHigh);
            InterruptPort butonAlt = new InterruptPort(Cpu.Pin.GPIO_Pin4, false,
                                                       Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeHigh);
            InterruptPort butonSag = new InterruptPort(Cpu.Pin.GPIO_Pin1, false,
                                                       Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeHigh);
            InterruptPort butonSol = new InterruptPort(Cpu.Pin.GPIO_Pin0, false,
                                                       Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeHigh);
            InterruptPort butonOrta = new InterruptPort(Cpu.Pin.GPIO_Pin3, false,
                                                        Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeHigh);

            butonUst.OnInterrupt  += new NativeEventHandler(butonUst_OnInterrupt);
            butonAlt.OnInterrupt  += new NativeEventHandler(butonAlt_OnInterrupt);
            butonSag.OnInterrupt  += new NativeEventHandler(butonSag_OnInterrupt);
            butonSol.OnInterrupt  += new NativeEventHandler(butonSol_OnInterrupt);
            butonOrta.OnInterrupt += new NativeEventHandler(butonOrta_OnInterrupt);
            #endregion

            YenidenBasla();

            tmr = new Timer(new TimerCallback(Oyna), null, 0, 200);

            Thread.Sleep(Timeout.Infinite);
        }
示例#20
0
文件: RHT03.cs 项目: valoni/NETMF44
        /// <summary>
        /// Initializes a new instance of the <see cref="RHT03"/> class.
        /// </summary>
        /// <param name="socket">The <see cref="Hardware.Socket"/> that the RHT03 Sensor is connected to.</param>
        public RHT03(Hardware.Socket socket)
        {
            try
            {
                Hardware.CheckPins(socket, socket.Rst, socket.Int);

                _portIn              = new InterruptPort(socket.Rst, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
                _portIn.OnInterrupt += portIn_OnInterrupt;
                _portIn.DisableInterrupt(); // Enabled automatically in the previous call

                _portOut = new TristatePort(socket.Int, false, false, Port.ResistorMode.PullUp);
            }
            catch (PinInUseException ex)
            {
                throw new PinInUseException(ex.Message);
            }

            _pollingTimer = new Timer(UpdateReadings, null, Timeout.Infinite, Timeout.Infinite);

            InitSensor();

            if (SensorError != null)
            {
                SensorError(this, "RHT03 Sensor Initialization is complete.");
            }
        }
示例#21
0
        public static void Main()
        {
            #region Second Step

#if SecondStep
            InterruptPort btnOnboard = new InterruptPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            btnOnboard.OnInterrupt += btnOnboard_OnInterrupt;
            timer = new Timer(_ => TimerOnCallBack(), null, Timeout.Infinite, Timeout.Infinite);
            while (true)
            {
            }
#endif
            #endregion

            #region First Step

#if FirstStep
            while (true)
            {
                pin8.Write(step == 0);
                pin10.Write(step == 1);
                pin9.Write(step == 2);
                pin11.Write(step == 3);

                step = (step + 1) % 4;
                Thread.Sleep(interval);
            }
#endif
            #endregion
        }
示例#22
0
        public static void Main()
        {
            var intButton =
                new InterruptPort(Stm32F4Discovery.ButtonPins.User, true,
                                  Port.ResistorMode.PullDown,
                                  Port.InterruptMode.InterruptEdgeBoth);

            intButton.OnInterrupt += IntButton_OnInterrupt;

            Pause();

            var accelerometerThread = new Thread(AccelerometerThread);

            accelerometerThread.Start();
            Debug.Print("accelerometerThread Started");

            var pwmThreadHandler = new Thread(PWMThread);

            pwmThreadHandler.Start();
            Debug.Print("PWMThread Started");

            UnPause();

            Thread.Sleep(Timeout.Infinite);
        }
示例#23
0
        public static void Main()
        {
            Thread.Sleep(STARTUP_DELAY);

            // Init //
            roomba                  = new RoombaSerial(SerialPorts.COM1, Pins.GPIO_PIN_D4);
            PushButton              = new InterruptPort(Pins.ONBOARD_BTN, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
            PushButton.OnInterrupt += new NativeEventHandler(OnPushButton);

            while (true)
            {
                Thread.Sleep(POLLING_PERIOD_MS);


                if (ButtonPressed)
                {
                    TRACE("Main", "Handling Button.");
                    ButtonPressed = false;
                    roomba.ResetSerialPort();

                    Thread.Sleep(POLLING_PERIOD_MS);
                    roomba.StartRommbaCommunication();

                    Thread.Sleep(POLLING_PERIOD_MS);
                    TRACE("Main", roomba.ReadSensors(RoombaSerial.SensorData.All));
                }
                else
                {
                    TRACE("Main", "Tick.");
                }
            }
        }
示例#24
0
            private long minTicks = 0;  // System latency, subtracted off ticks to find actual sound travel time

            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="pinTrig">Netduino pin connected to the HC-SR04 Trig pin</param>
            /// <param name="pinEcho">Netduino pin connected to the HC-SR04 Echo pin</param>
            public HC_SR04(Cpu.Pin pinTrig, Cpu.Pin pinEcho)
            {
                portOut              = new OutputPort(pinTrig, false);
                interIn              = new InterruptPort(pinEcho, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
                interIn.OnInterrupt += new NativeEventHandler(interIn_OnInterrupt);
                minTicks             = 4000L;
            }
示例#25
0
        /// <summary>
        /// Enables the key functionality if it was disabled.
        /// </summary>
        public static void Enable()
        {
            if (Key.IsEnabled)
            {
                return;
            }

            Key.Up    = new InterruptPort(Key.UP_PIN, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);
            Key.Left  = new InterruptPort(Key.LEFT_PIN, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);
            Key.Down  = new InterruptPort(Key.DOWN_PIN, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);
            Key.Right = new InterruptPort(Key.RIGHT_PIN, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);

            Key.A     = new InterruptPort(Key.A_PIN, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);
            Key.B     = new InterruptPort(Key.B_PIN, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);
            Key.C     = new InterruptPort(Key.C_PIN, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);
            Key.Power = new InterruptPort(Key.POWER_PIN, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);
            Key.Start = new InterruptPort(Key.START_PIN, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);

            Key.Up.OnInterrupt    += new NativeEventHandler(OnKeyPress);
            Key.Left.OnInterrupt  += new NativeEventHandler(OnKeyPress);
            Key.Down.OnInterrupt  += new NativeEventHandler(OnKeyPress);
            Key.Right.OnInterrupt += new NativeEventHandler(OnKeyPress);

            Key.A.OnInterrupt     += new NativeEventHandler(OnKeyPress);
            Key.B.OnInterrupt     += new NativeEventHandler(OnKeyPress);
            Key.C.OnInterrupt     += new NativeEventHandler(OnKeyPress);
            Key.Power.OnInterrupt += new NativeEventHandler(OnKeyPress);
            Key.Start.OnInterrupt += new NativeEventHandler(OnKeyPress);

            Key.Enabled = true;
        }
示例#26
0
        public static void Run()
        {
            var servo = new ServoController(Pins.GPIO_PIN_D9, 600, 3000);

            var button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

            button.OnInterrupt += (data1, data2, time) =>
            {
                //servo.Duration = 1500;
                if (data2 == 1)
                {
                    servo.Rotate(100);
                }
                else
                {
                    servo.Rotate(0);
                }
            };

            while (Debugger.IsAttached)
            {
                Thread.Sleep(1000);
            }

            button.Dispose();
            servo.Dispose();
        }
示例#27
0
 /// <summary>
 /// Initiates a rotary encoder
 /// </summary>
 /// <param name="PinA">Pin A</param>
 /// <param name="PinB">Pin B</param>
 public RotaryEncoder(Cpu.Pin PinA, Cpu.Pin PinB)
 {
     this._PinA              = new InterruptPort(PinA, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
     this._PinB              = new InterruptPort(PinB, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
     this._PinA.OnInterrupt += new NativeEventHandler(_Pin_OnInterrupt);
     this._PinB.OnInterrupt += new NativeEventHandler(_Pin_OnInterrupt);
 }
示例#28
0
        public CapTouchDriver(I2CDevice sharedBus)
        {
            display = new DisplayNhd5(sharedBus);

            //LCDbacklight = new OutputPort(GHI.Pins.G120.P1_19, true);
            //LCDbacklight.Write(true);
            msBacklightTime  = 0;           // Default is off
            msDisplayTimeout = 0;

            display.TouchUp   += display_TouchUp;
            display.TouchDown += display_TouchDown;
            display.ZoomIn    += display_ZoomIn;
            display.ZoomOut   += display_ZoomOut;

            touches    = new Microsoft.SPOT.Touch.TouchInput[1];
            touches[0] = new TouchInput();
            //
            // Using interrupt (for G120)
            //
            //touchPin = new InterruptPort(GHI.Pins.G120.P0_25, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

            touchPin              = new InterruptPort(GHI.Pins.G120.P2_21, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            touchPin.OnInterrupt += touchPin_OnInterrupt;
            //
            // Create thread the handle the backlight timeout
            //
            Thread threadBacklight = new Thread(backlightHandler);

            threadBacklight.Start();
        }
示例#29
0
        public static void Main()
        {
            InterruptPort button = new InterruptPort(Pins.ONBOARD_BTN,
                                                     false,
                                                     Port.ResistorMode.Disabled,
                                                     Port.InterruptMode.InterruptEdgeLow);

            button.OnInterrupt += new NativeEventHandler(button_OnInterrupt);

            InterruptPort hr = new InterruptPort(Pins.GPIO_PIN_D2,
                                                 false,
                                                 Port.ResistorMode.Disabled,
                                                 Port.InterruptMode.InterruptEdgeLow);

            hr.OnInterrupt += new NativeEventHandler(hr_OnInterrupt);



            Thread.Sleep(Timeout.Infinite);
            //var led = new OutputPort(Pins.ONBOARD_LED, false);
            //var rotatary = new AnalogInput(AnalogChannels.ANALOG_PIN_A0);

            //while (true)
            //{
            //    led.Write(!led.Read());

            //    Thread.Sleep((int) rotatary.ReadRaw());
            //}
        }
示例#30
0
        public LidarReader(double setNoVehicle, double sensitivy, double trigger_sensetivity)
        {
            Debug.Print("== LidarReader constructor");
            _sensitivy = sensitivy;
            _minValue  = setNoVehicle * 0.7;
            _noVehicleDistanceRange = _minValue * 3.2; // distance with no vehicle , if we get more than that , we just ignore the value.
            _mLidarStartTime        = 0;
            LidarInitialized        = true;
            _lastTriggerDistance    = 0;
            _triggerSensetivity     = trigger_sensetivity;
            _stoppedVehicleHappened = false;
            _distanceValueLocation  = null;
            _interruptDisableCount  = 0;

            // assign port , but disable interrupts , will be enabled in the start function
            _oport  = new OutputPort(Pins.GPIO_PIN_D2, true);
            _inport = new InterruptPort(Pins.GPIO_PIN_D1, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);


            /*
             * // Manualy set interrupot c**t before
             * lock (_inport)
             * {
             *  _interruptDisableCount++;
             *  _inport.DisableInterrupt();
             *  Debug.Print("lr" + " Disable: " + _interruptDisableCount);
             * }
             */
        }