Пример #1
0
 public void Connect(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);
     Reset();
 }
Пример #2
0
        public static void Main()
        {
            _outDig0 = new OutputPort(Pins.GPIO_PIN_D0, false);
            _outDig1 = new OutputPort(Pins.GPIO_PIN_D1, false);
            _outDig2 = new OutputPort(Pins.GPIO_PIN_D2, false);

            _isOn = false;
            _count = 0;

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

            while (true)
            {
                if( (_isOn) && (_count < 8))
                {
                    SetLights(ToBinary(_count));
                    Thread.Sleep(1000);
                    _count++;
                }
                else
                {
                    _outDig0.Write(false);
                    _outDig1.Write(false);
                    _outDig2.Write(false);
                    _count = 0;
                }
            }
        }
Пример #3
0
        public IrReceiver(Cpu.Pin pin)
        {
            _timeoutTimer = new Timer(ReceiverTimeout, null, Timeout.Infinite, Timeout.Infinite);

            _interrputPort = new InterruptPort(pin, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            _interrputPort.OnInterrupt += interrputPort_OnInterrupt;
        }
Пример #4
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();
        }
Пример #5
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();
                byte[] 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);
            }
        }
Пример #6
0
        public Remote()
        {
            _button0 = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di12, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            _button1 = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di13, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            _button2 = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di2, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            _button3 = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di3, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            _button0.OnInterrupt += OnButtonPush;
            _button1.OnInterrupt += OnButtonPush;
            _button2.OnInterrupt += OnButtonPush;
            _button3.OnInterrupt += OnButtonPush;
            Cpu.GlitchFilterTime = new TimeSpan(TimeSpan.TicksPerSecond / 2);

            _leftJoystick = new AnalogJoystick((Cpu.Pin)FEZ_Pin.AnalogIn.An1, (Cpu.Pin)FEZ_Pin.AnalogIn.An0, -100, 100);
            _leftJoystick.YCalibration.EndPoints.Low = -4;
            _leftJoystick.YCalibration.EndPoints.High = 7;
            _leftJoystick.XCalibration.EndPoints.Low = 0;
            _leftJoystick.XCalibration.EndPoints.High = 3;
            _leftJoystick.AngularCalibration = new Angle(Angle.ConvertDegreesToRadians(-90));
            _rightJoystick = new AnalogJoystick((Cpu.Pin)FEZ_Pin.AnalogIn.An3, (Cpu.Pin)FEZ_Pin.AnalogIn.An2, -100, 100);
            _rightJoystick.YCalibration.EndPoints.Low = -6;
            _rightJoystick.YCalibration.EndPoints.High = 6;
            _rightJoystick.XCalibration.EndPoints.Low = 0;
            _rightJoystick.XCalibration.EndPoints.High = 9;
            _rightJoystick.AngularCalibration = new Angle(Angle.ConvertDegreesToRadians(-90));

            // ReSharper disable RedundantArgumentDefaultValue
            _radio = new RCRadio("OM1", "COM1", 115200, Parity.None, 8, StopBits.One)
                         {Id = "OM1", PartnerId = "OC1", SendFrequency = 200};
            // ReSharper restore RedundantArgumentDefaultValue
            _radio.DataReceived += OnRadioDataReceived;
        }
Пример #7
0
 public Window(Cpu.Pin pin, bool pulseOnClose, string name)
 {
     _pulseOnClose = pulseOnClose;
     Name = name;
     _port = new InterruptPort(pin, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
     _port.OnInterrupt += PortOnInterrupt;
 }
Пример #8
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.InterruptEdgeBoth);
     this._PinB = new InterruptPort(PinB, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
     this._PinA.OnInterrupt += new NativeEventHandler(_Pin_OnInterrupt);
     this._PinB.OnInterrupt += new NativeEventHandler(_Pin_OnInterrupt);
 }
Пример #9
0
        public ContactSensor(Cpu.Pin sensorPin)
        {
            this.sensorPin = sensorPin;

            sensorPort = new InterruptPort(sensorPin, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLevelLow);
            sensorPort.OnInterrupt += new NativeEventHandler(OnInterrupt);
        }
Пример #10
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;
        }
Пример #11
0
        // Use IButton (interface of button) as the type of the passed button in constructor
        public LightTrigger(int clicks)
        {
            this.TriggerAfter = clicks;

            Led = new OutputPort(Pins.ONBOARD_LED, false);

            // In larger applications, create a class that encapsulates the hardware components. It should
            // configure the hardware once and behind the scenes so that the rest of the program doesn't have those details.
            // (E.g. set what pins are being used). Also, it makes for sense for the rest of the program to
            // refer to a "button" object instead of an InterruptPort object
            // Define a button interface, create a class for a particular button, instantiate button in main and pass it to
            // the constructor of the managing class (Dependency injection)
            // Configuration is done up top, passed into the application
            Button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

            // PullUp resistor setting causes netduino to create a voltage at the pin
            // PullDown resistor setting is used when you supply a voltage to the pin
            Reset = new InterruptPort(Pins.GPIO_PIN_D13, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

            //Type typeOfOutputPort = led.GetType();

            // Hold an instance of this delegate in a name so you can subscribre or unsubscribe easily and neatly
            // Set handler for trigger button
            var handlerDelegate = new NativeEventHandler(button_onInterrupt);
            // NativeEventHandler h = button_onInterrupt;

            Button.OnInterrupt += handlerDelegate;

            // Set handler for reset button
            var del = new NativeEventHandler(reset_onInterrupt);
            Reset.OnInterrupt += del;
        }
Пример #12
0
        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;
        }
 public PIRSens(Cpu.Pin kojPin, Predmet stoPred)
 {
     _kakovSum = TipSenzor.PIR;
     _kadeSum = stoPred;
     pirSens  = new InterruptPort(kojPin, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
     pirSens.OnInterrupt += new NativeEventHandler(NekojVleze);
 }
Пример #14
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());
            //}
        }
Пример #15
0
        public static void Main()
        {
            // Setup GoBus ports
            led1 = new NetduinoGo.RgbLed(GoSockets.Socket8);
            led2 = new NetduinoGo.RgbLed(GoSockets.Socket7);
            led3 = new NetduinoGo.RgbLed(GoSockets.Socket6);
            button1 = new NetduinoGo.Button(GoSockets.Socket1);
            button2 = new NetduinoGo.Button(GoSockets.Socket3);
            InterruptPort settingButton = new InterruptPort(Pins.Button, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
            settingButton.OnInterrupt += new NativeEventHandler(settingButton_OnInterrupt);
            OutputPort powerlight = new OutputPort(Pins.PowerLed, false);

            #if !mute
            buzzer = new NetduinoGo.PiezoBuzzer();
            #endif

            // Set Scale
            SetScale();

            // Register Buttons
            button1.ButtonPressed += new NetduinoGo.Button.ButtonEventHandler(button1_ButtonPressed);
            button2.ButtonPressed += new NetduinoGo.Button.ButtonEventHandler(button2_ButtonPressed);
            led2.SetColor(0, 0, 255);
            // Main thread sleep time
            Thread.Sleep(Timeout.Infinite);
        }
Пример #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputPin"></param>
        /// <param name="type"></param>
        /// <param name="debounceDuration">in milliseconds</param>
        public PushButton(H.Cpu.Pin inputPin, CircuitTerminationType type, int debounceDuration = 20)
        {
            this.DebounceDuration = new TimeSpan(0, 0, 0, 0, debounceDuration);

            // if we terminate in ground, we need to pull the port high to test for circuit completion, otherwise down.
            H.Port.ResistorMode resistorMode = H.Port.ResistorMode.Disabled;
            switch (type)
            {
            case CircuitTerminationType.CommonGround:
                resistorMode = H.Port.ResistorMode.PullUp;
                break;

            case CircuitTerminationType.High:
                resistorMode = H.Port.ResistorMode.PullDown;
                break;

            case CircuitTerminationType.Floating:
                resistorMode = H.Port.ResistorMode.Disabled;
                break;
            }

            // create the interrupt port from the pin and resistor type
            this.DigitalIn = new H.InterruptPort(inputPin, true, resistorMode, H.Port.InterruptMode.InterruptEdgeBoth);

            // wire up the interrupt handler
            this.DigitalIn.OnInterrupt += DigitalIn_OnInterrupt;
        }
Пример #17
0
 public InputList(int count)
 {
     _syncRoot = new object();
     _array = new InterruptPort[count];
     _currentMax = count;
     _currentIndex = 0;
 }
Пример #18
0
        public static void Main()
        {
            // write your code here
            InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            button.OnInterrupt += new NativeEventHandler(button_OnInterrupt);

            PulseLed();

            // Create a new I2C bus instance at startup.
            I2CBus i2cBus = I2CBus.GetInstance();

            _BlinkM = new BlinkM(0x09);
            _ds1621 = new DS1621(0x48);
            // write something to a register.
            //_exampleSensor.WriteSomethingToSpecificRegister();
            ShiftRegister _74HC595 = new ShiftRegister(Pins.GPIO_PIN_D2, Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1);
            //_74HC595.WriteMap(1, 255);
            _74HC595.WriteByte(0);
            _74HC595.WriteByte(0);
            _74HC595.ClockStorage();
            _74HC595.WriteByte(255);
            _74HC595.WriteByte(1);
            _74HC595.ClockStorage();
            while (true)
            {
                for (int j = 1; j <= 128; j = j * 2)
                {
                    for (int i = 1; i <= 128; i = i * 2)
                    {
                        //Debug.Print("i[" + i + "]  j[" + j);
                        _74HC595.WriteByte(0,false);
                        _74HC595.WriteByte(0,true);

                        _74HC595.WriteByte(i, false);
                        _74HC595.WriteByte(j, true);
                        _74HC595.ClockStorage();
                        Thread.Sleep(100);
                    }
                }
                /*
                for (int j = 1; j <= 128; j = j * 2)
                {
                    for (int i = 1; i <= 128; i = i * 2)
                    {
                        Debug.Print("i[" + i + "]  j[" + j);
                        _74HC595.WriteByte(i);
                        _74HC595.WriteByte(j);
                        _74HC595.ClockStorage();
                        Thread.Sleep(200);
                    }
                }
                 * */
            }
            //Bresenhams.Algorithms.Line(0,0,4,7,SetPixel);

            //Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableStaticIP("10.0.0.222", "255.255.255.0", "10.0.0.4");
            //Debug.Print("IP=" + Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress);
            Thread.Sleep(Timeout.Infinite);
        }
Пример #19
0
        public IRReceiver(Cpu.Pin pin)
        {
            _receiverPort = new InterruptPort(pin, false,
                                              Port.ResistorMode.PullUp,
                                              Port.InterruptMode.InterruptEdgeBoth);

            _receiverPort.OnInterrupt += PortInterrupt;
        }
 //private double version;
 /// <summary>
 /// Sets up the HC-SR04 distance sensor with the Trig and Echo pins
 /// </summary>
 /// <param name="pinTrig"></param>
 /// <param name="pinEcho"></param>
 public DistanceSensor(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 = 6200L;
     inchConversion = 1440.0;
 }
Пример #21
0
        public UltraSonicSensor(Cpu.Pin echoPin, Cpu.Pin triggerPin)
        {
            _echoPin = new InterruptPort(echoPin, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
            _triggerPin = new OutputPort(triggerPin, false);

            _echoPin.OnInterrupt += port_OnInterrupt;
            _echoPin.DisableInterrupt();
        }
Пример #22
0
 static void Current_OnButtonPress(Buttons button, InterruptPort port, ButtonDirection direction, DateTime time)
 {
     if (direction == ButtonDirection.Up)
     {
         _buttonHitList.Add(button);
         clickTimer.Change(MaxClickWaitTime, Timeout.Infinite);
     }
 }
Пример #23
0
        public static void Main()
        {
            // write your code here
            InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
            button.OnInterrupt += new NativeEventHandler(button_OnInterrupt);

            Thread.Sleep(Timeout.Infinite);
        }
Пример #24
0
 public TapDecoder(int reqDigits, Cpu.Pin tapSensePin)
 {
     requiredDigits = reqDigits;
     tapSensePort = new InterruptPort(tapSensePin, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
     tapSensePort.OnInterrupt += new NativeEventHandler(port_OnInterrupt);
     intrTimer = new Timer(new TimerCallback(intr_OnTimer), null, -1, -1);
     Reset();
 }
            // Construct the object. Set this class to handle the emulated
            // hardware's button interrupts.
            public ButtonPad(GPIOButtonInputProvider sink, Button button, Cpu.Pin pin)
            {
                this.sink = sink;
                this.button = button;

                // When this GPIO pin is true, call the Interrupt method.
                port = new InterruptPort(pin, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
                port.OnInterrupt += new GPIOInterruptEventHandler(this.Interrupt);
            }
Пример #26
0
        /// <summary>
        /// Costruttore
        /// </summary>
        /// <param name="encPin">pin dell' encoder</param>
        public Encoder(FEZ_Pin.Interrupt encPin)
        {
            //Dichiarazione e creazione dell'encoder.
            Encoder = new InterruptPort((Cpu.Pin)encPin, true,
            Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);

            //Abilita l'interrupt sul pin del segnale tachimetrico
            Encoder.OnInterrupt += Encoder_OnInterrupt;
        }
Пример #27
0
 /// <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 = 6200L;
     mmConversion = 58;
     version = 1.1;
 }
Пример #28
0
 public FlowSensor(InterruptPort port, OutputPort light, IHttpMessageWriter httpMessageWriter, string tapId, PulseConfig pulseConfig)
 {
     _port = port;
     _light = light;
     _port.OnInterrupt += FlowDetected;
     _httpMessageWriter = httpMessageWriter;
     _tapId = tapId;
     _pulseConfig = pulseConfig;
 }
 public NecRemoteControlDecoder(Cpu.Pin irReceiverPin)
 {
     _irReceiverPin = irReceiverPin;
     pulses = new long[200];
     currentPulseIndex = 0;
     irReceiverPort = new InterruptPort(irReceiverPin, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
     irReceiverPort.OnInterrupt += new NativeEventHandler(irReceiverPort_OnInterrupt);
     irPulseTimeOutTimer = new Timer(new TimerCallback(IrPulseTimeOut), null, Timeout.Infinite, Timeout.Infinite);
 }
Пример #30
0
 private CapacitiveTouchController(Cpu.Pin portId)
 {
     transactions = new I2CDevice.I2CTransaction[2];
     resultBuffer = new byte[1];
     addressBuffer = new byte[1];
     i2cBus = new I2CDevice(new I2CDevice.Configuration(0x38, 400));
     touchInterrupt = new InterruptPort(portId, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
     touchInterrupt.OnInterrupt += (a, b, c) => this.OnTouchEvent();
 }
Пример #31
0
        public static void Main()
        {
            //tidy up
            File.Delete("\\SD\\Data.csv");

            try
            {
                //retrive and set device time via NTP
                var networkTime = NtpClient.GetNetworkTime();
                Utility.SetLocalTime(networkTime);

                _macAddress = GetMAC();
                _blobClient = new BlobClient(AccountName, AccountKey);
                _tableClient = new TableClient(AccountName, AccountKey);
                _tableClient.CreateTable("netmfdata");

                _onBoardButton = new InterruptPort(Pins.ONBOARD_SW1, true,
                                                                Port.ResistorMode.Disabled,
                                                                Port.InterruptMode.InterruptEdgeHigh);
                _onBoardButton.OnInterrupt += onBoardButton_OnInterrupt;

                _analogInput = new AnalogInput(AnalogChannels.ANALOG_PIN_A0);

            }
            catch(Exception ex)
            {
                Debug.Print("Error setting up Device: " + ex.ToString());
            }

            int counter = 0;
            while (true)
            {
                counter++;
                var data = _analogInput.Read() * 40D;
                _tableClient.AddTableEntityForTemperature("netmfdata", _macAddress, counter.ToString(), DateTime.Now, data, "UK");

                lock (Padlock)
                {
                    using (FileStream fs = File.Open("\\SD\\Data.csv", FileMode.Append, FileAccess.Write))
                    {
                        Debug.Print(data.ToString());
                        var dataBytes = Encoding.UTF8.GetBytes(
                            StringUtility.Format("{0}, {1}, {2}\r\n",
                                                 _macAddress, DateTime.Now.ToString(),
                                                 data)
                            );

                        fs.Write(dataBytes, 0, dataBytes.Length);
                        fs.Flush();
                    }
                }

                Thread.Sleep(1000);
                Debug.Print("Working");
            }
        }
Пример #32
0
        public RotaryEncoder(H.Cpu.Pin aPhasePin, H.Cpu.Pin bPhasePin)
        {
            this._aPhasePin = new H.InterruptPort(aPhasePin, true, H.Port.ResistorMode.PullUp, H.Port.InterruptMode.InterruptEdgeBoth);
            this._bPhasePin = new H.InterruptPort(bPhasePin, true, H.Port.ResistorMode.PullUp, H.Port.InterruptMode.InterruptEdgeBoth);

            // both events go to the same event handler because we need to read both
            // pins to determine current orientation
            this._aPhasePin.OnInterrupt += PhasePin_OnInterrupt;
            this._bPhasePin.OnInterrupt += PhasePin_OnInterrupt;
        }
        public NativeInterruptInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, InterruptMode interruptMode, Module module, Hardware.Cpu.Pin cpuPin)
        {
            if (cpuPin == Hardware.Cpu.Pin.GPIO_NONE)
            {
                // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check
                throw Socket.InvalidSocketException.FunctionalityException(socket, "InterruptInput");
            }

            _port = new Hardware.InterruptPort(cpuPin, glitchFilterMode == GlitchFilterMode.On, (Hardware.Port.ResistorMode)resistorMode, (Hardware.Port.InterruptMode)interruptMode);
        }
Пример #34
0
        /// <summary>
        ///     Turn interrupts on or off and set the conversion trigger count.
        /// </summary>
        /// <remarks>
        ///     The conversion count is the number of conversions that must be outside
        ///     of the upper and lower limits before and interrupt is generated.
        ///     See Interrupt Control Register on page 15 and 16 of the datasheet.
        /// </remarks>
        /// <param name="mode"></param>
        /// <param name="conversionCount">
        ///     Number of conversions that must be outside of the threshold before an interrupt is
        ///     generated.
        /// </param>
        /// <param name="pin">GPIO pin connected to the TSL2561 interrupt pin.  Set to null to use the previously supplied pin.</param>
        public void SetInterruptMode(InterruptMode mode, byte conversionCount,
                                     Spot.Cpu.Pin pin = Spot.Cpu.Pin.GPIO_NONE)
        {
            if (conversionCount > 15)
            {
                throw new ArgumentOutOfRangeException("conversionCount",
                                                      "Conversion count must be in the range 0-15 inclusive.");
            }
            //
            //  Attach the interrupt event before we turn on interrupts.
            //
            if (pin != Spot.Cpu.Pin.GPIO_NONE)
            {
                if (_interruptPin != null)
                {
                    _interruptPin.Dispose();
                }
                _interruptPin = new Spot.InterruptPort(pin, false, Spot.Port.ResistorMode.PullUp,
                                                       Spot.Port.InterruptMode.InterruptEdgeLow);
                _interruptPin.OnInterrupt += _interruptPin_OnInterrupt;
            }
            else
            {
                if (_interruptPin == null)
                {
                    throw new ArgumentException("Interrupt pin must be supplied");
                }
            }
            //
            // Put interrupt control in bits 4 & 5 of the Interrupt Control Register.
            // Using the enum above makes sure that mode is in the range 0-3 inclusive.
            //
            var registerValue = (byte)mode;

            registerValue <<= 4;
            //
            // conversionCount is known to be 0-15, put this in the lower four bits of
            // the Interrupt Control Register.
            //
            registerValue |= conversionCount;
            //
            //  Clear the interrupt bit before we turn them on.
            //
            ClearInterrupt();
            _tsl2561.WriteRegister(Registers.InterruptControl, registerValue);
        }
Пример #35
0
        //static bool roverHeadLights = false;
        //static bool roverTakePicture = false;

        public static void Main()
        {
            #region Newhaven 3.5" Display Graphic Setup

            /*
             *  var lcdConfig3 = new Configuration.LCD.Configurations();
             *
             *  lcdConfig3.Width = 320;
             *  lcdConfig3.Height = 240;
             *
             *  lcdConfig3.OutputEnableIsFixed = true;
             *  lcdConfig3.OutputEnablePolarity = true;
             *
             *  lcdConfig3.HorizontalSyncPolarity = false;
             *  lcdConfig3.VerticalSyncPolarity = false;
             *  lcdConfig3.PixelPolarity = true;
             *
             *  lcdConfig3.HorizontalSyncPulseWidth = 68;
             *  lcdConfig3.HorizontalBackPorch = 2;
             *  lcdConfig3.HorizontalFrontPorch = 18;
             *  lcdConfig3.VerticalSyncPulseWidth = 10;
             *  lcdConfig3.VerticalBackPorch = 3;
             *  lcdConfig3.VerticalFrontPorch = 10;
             *
             *  lcdConfig3.PixelClockRateKHz = 6400;
             *
             *  Configuration.LCD.Set(lcdConfig3);
             *
             */
            //if (Configuration.LCD.Set(lcdConfig3)) PowerState.RebootDevice(false);


            //Initialiazing and hooking to events
            var display = new DisplayNhd5(new Microsoft.SPOT.Hardware.I2CDevice(new Microsoft.SPOT.Hardware.I2CDevice.Configuration(0x38, 400)));
            //display.TouchUp += (sender, e) => Debug.Print("Finger " + e.FingerNumber + " up!");
            display.TouchUp += new TouchEventHandler(display_TouchUp);
            //display.TouchDown += (sender, e) => Debug.Print("Finger " + e.FingerNumber + " down!");
            display.TouchDown += new TouchEventHandler(display_TouchDown);
            display.ZoomIn    += (sender, e) => Debug.Print("Zoom in");
            display.ZoomOut   += (sender, e) => Debug.Print("Zoom out");

            /*
             * //Method one: polling manually. Uncomment the while cycle to use it.
             *
             * //while (true) {
             * // display.ReadAndProcessTouchData();
             * // Thread.Sleep(50);
             * //}
             */

            //Method two: using interrupt (for G120).
            var touchPin = new Microsoft.SPOT.Hardware.InterruptPort(GHI.Hardware.G120.Pin.P0_25, false, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp, Microsoft.SPOT.Hardware.Port.InterruptMode.InterruptEdgeLow);
            var wakePin  = new Microsoft.SPOT.Hardware.InputPort(GHI.Hardware.G120.Pin.P0_24, false, Microsoft.SPOT.Hardware.Port.ResistorMode.Disabled);
            //var touchPin = new Microsoft.SPOT.Hardware.InterruptPort(GHI.Hardware.G120.Pin.P0_23, false, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp, Microsoft.SPOT.Hardware.Port.InterruptMode.InterruptEdgeLow); //I DID THIS
            touchPin.OnInterrupt += (data1, data2, time) => display.ReadAndProcessTouchData();

            #endregion

            #region LAIRD XCVR SETUP

            //lairdWirelss.Configure(9600, GT.Interfaces.Serial.SerialParity.None, GT.Interfaces.Serial.SerialStopBits.One, 7);
            lairdComPort = new SerialPort("COM2", 115200); //TX2 = P2.0, RX2 = P0.16
            //lairdComPort = new SerialPort("COM2", 9600);

            lairdComPort.Open();

            lairdReset = new Microsoft.SPOT.Hardware.OutputPort(lairdResetPin, true);
            lairdCts   = new Microsoft.SPOT.Hardware.OutputPort(lairdCtsPin, false);
            //lairdRts = new Microsoft.SPOT.Hardware.InputPort(lairdRtsPin, false, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
            lairdRange = new Microsoft.SPOT.Hardware.InputPort(lairdRangePin, false, Microsoft.SPOT.Hardware.Port.ResistorMode.Disabled);

            /*
             * lairdCtsPin = GT.Socket.GetSocket(5, true, null, null).CpuPins[6];
             * //lairdRtsPin = GT.Socket.GetSocket(5, true, null, null).CpuPins[7];
             * lairdResetPin = GT.Socket.GetSocket(5, true, null, null).CpuPins[3];
             * lairdRangePin = GT.Socket.GetSocket(5, true, null, null).CpuPins[8];
             */

            lairdWirelessBuffer = new SerialBuffer(72);

            #endregion

            #region QUAD POWER SETUP

            quadPowerComPort = new SerialPort("COM3", 9600);
            quadPowerComPort.Open();
            quadPowerBuffer = new SerialBuffer(36);

            #endregion

            // Load the window
            _mainWindow = GlideLoader.LoadWindow(OakhillLandroverController.Resources.GetString(OakhillLandroverController.Resources.StringResources.wndMain));
            //pictureWindow = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Picture_Window));
            outputsWindow = new OutputsWindow();//gndEfxWindow = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.GroundEfx_Window));
            ecoCamWindow  = new EcoCamWindow();
            setupWindow   = new SetupWindow();

            // Activate touch
            //GlideTouch.Initialize();

            // Initialize the windows.
            initMainWindow(_mainWindow);

            // Assigning a window to MainWindow flushes it to the screen.
            // This also starts event handling on the window.
            Glide.MainWindow = _mainWindow;

            //bool mybool = SDCard.sdCardDetect;
            //bool yourBool  = batChargeState.Read();
            //lcdBacklight.Write(false); //turn lcd screen off
            //onBoardLed.Write(true);

            picCounter = -1;
            //Glide.MessageBoxManager.Show("SD Card not found.", "SD Card");

            UpdateMainWindowTimer     = new Timer(new TimerCallback(UpdateMainWindowTimer_Tick), null, 0, UpdateMainWindowTimerPeriod);
            PictureViewerTimer        = new Timer(new TimerCallback(PictureViewerTimer_Tick), null, -1, PictureViewerTimerPeriod);
            RoverJoystickControlTimer = new Timer(new TimerCallback(RoverJoystickControlTimer_Tick), null, 0, RoverJoystickTimerPeriod);

            //display_T35.SimpleGraphics.DisplayImage(SD_ROOT_DIRECTORY + @"\roverPic17.jpg", Bitmap.BitmapImageType.Jpeg, 0, 0);

            Thread.Sleep(-1);
        }