Esempio n. 1
0
 public void Stop()
 {
     if (_thread == null)
     {
         throw new ApplicationException("_thread");
     }
     _geigerCounter.DisableInterrupt();
     _thread.Abort();
     _thread.Join();
 }
Esempio n. 2
0
        /// <summary>
        /// Retrieves measured data from the sensor.
        /// </summary>
        /// <returns>
        /// <c>true</c> if the operation succeeds and the data is valid, otherwise <c>false</c>.
        /// </returns>
        public bool Read()
        {
            if (disposed)
            {
                throw new ObjectDisposedException();
            }
            // The 'bitMask' also serves as edge counter: data bit edges plus
            // extra ones at the beginning of the communication (presence pulse).
            bitMask = 1L << 41;

            data = 0;
            // lastTicks = 0; // This is not really needed, we measure duration
            // between edges and the first three values are ignored anyway.

            // Initiate communication
            portOut.Active = true;
            portOut.Write(false);       // Pull bus low
            Thread.Sleep(StartDelay);
            portIn.EnableInterrupt();   // Turn on the receiver
            portOut.Active = false;     // Release bus

            bool dataValid = false;

            // Now the interrupt handler is getting called on each falling edge.
            // The communication takes up to 5 ms, but the interrupt handler managed
            // code takes longer to execute than is the duration of sensor pulse
            // (interrupts are queued), so we must wait for the last one to finish
            // and signal completion. 20 ms should be enough, 50 ms is safe.
            if (dataReceived.WaitOne(50, false))
            {
                // TODO: Use two short-s ?
                bytes[0] = (byte)((data >> 32) & 0xFF);
                bytes[1] = (byte)((data >> 24) & 0xFF);
                bytes[2] = (byte)((data >> 16) & 0xFF);
                bytes[3] = (byte)((data >> 8) & 0xFF);

                byte checksum = (byte)(bytes[0] + bytes[1] + bytes[2] + bytes[3]);
                if (checksum == (byte)(data & 0xFF))
                {
                    dataValid = true;
                    Convert(bytes);
                }
                else
                {
                    Debug.Print("DHT sensor data has invalid checksum.");
                }
            }
            else
            {
                portIn.DisableInterrupt();               // Stop receiver
                Debug.Print("DHT sensor data timeout."); // TODO: TimeoutException?
            }
            return(dataValid);
        }
Esempio n. 3
0
        protected void AciSend(AciOpCode opCode, params byte[] data)
        {
            if (data.Length > 30)
            {
                throw new ArgumentOutOfRangeException("data", "The maximum amount of data bytes is 30.");
            }

            // Create ACI packet
            var packet = new byte[data.Length + 2];

            packet[0] = (byte)(data.Length + 1);
            packet[1] = (byte)opCode;
            Array.Copy(data, 0, packet, 2, data.Length);

            // Request transfer
            _rdy.DisableInterrupt();
            _req.Write(false);

            // Wait for RDY to go low
            while (_rdy.Read())
            {
                ;
            }

            _spi.WriteLsb(packet);

            _req.Write(true);

            // Wait for RDY to go high
            while (!_rdy.Read())
            {
                ;
            }
            _rdy.EnableInterrupt();
        }
Esempio n. 4
0
 //===========================MOTION SENSOR=========================
 static void motion_OnInterrupt(uint data1, uint data2, DateTime time)
 {
     try
     {
         port.EnableInterrupt();
         port.DisableInterrupt();
         DateTime startTime = DateTime.Now;
         // Some execution process
         DateTime endTime        = DateTime.Now;
         TimeSpan totalTimeTaken = endTime.Subtract(startTime);
         Debug.Print("Motion detected! Alarm sounding");
         sendDataUsingCOMPort("MOTION STATUS=" + "MOTION DETECTED FOR " + totalTimeTaken + "s ");
         //spUART.Flush();
         port.EnableInterrupt();
         //Thread.Sleep(5000);
         //uint duration1 = 1000, duration2 = 1000;
         //speaker.SetPulse(duration1 * 2, duration1);
         //speaker.SetPulse(duration2 * 2, duration2);
         //Thread.Sleep(250);
         //speaker.SetDutyCycle(0);
         //MovementDetected = true;
         Debug.Print("Alarm sounding");
         //OutputPort redLED = new OutputPort(Pins.GPIO_PIN_D9, false);
         //for (int i = 0; i < 3; i++)
         // {
         //   redLED.Write(true);
         //   Thread.Sleep(300);
         //   redLED.Write(false);
         //}
     }
     catch (Exception ex)
     {
         Debug.Print(ex.Message);
     }
 }
        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();
        }
Esempio n. 6
0
        /// <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.");
            }
        }
Esempio n. 7
0
        private void portIn_OnInterrupt(uint pin, uint state, DateTime time)
        {
            long ticks = time.Ticks;

            if ((ticks - _lastTicks) > BitThreshold)
            {
                // If the time between edges exceeds threshold, it is bit '1'
                _sensorData |= _bitMask;
            }
            if ((_bitMask >>= 1) == 0)
            {
                // Received the last edge, stop and signal completion
                _portIn.DisableInterrupt();
                _dataReceived.Set();
            }
            _lastTicks = ticks;
        }
Esempio n. 8
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();
        }
Esempio n. 9
0
 protected override void Dispose(bool disposing = true)
 {
     Irq.DisableInterrupt();
     Spi.Dispose();
     ReceiveContext.Dispose();
     SetSocketPowerState(false);
     base.Dispose(disposing);
 }
Esempio n. 10
0
 static void pushBtn_OnInterrupt(uint data1, uint data2, DateTime time)
 {
     pushBtn.DisableInterrupt();
     // hold = (data2 == 1) ? true : false;
     inside += 1;
     hold    = !hold;
     pushBtn.EnableInterrupt();
 }
Esempio n. 11
0
 public void disableInterrupt(string s)
 {
     lock (_inport)
     {
         _interruptDisableCount++;
         _inport.DisableInterrupt();
         // Debug.Print(s+" Disable: " + _interruptDisableCount);
     }
 }
Esempio n. 12
0
        void ILinkLayer.Stop()
        {
            // we are now un-initializing
            _isInitialized = false;

            // disable our interrupt pin
            _interruptPin.DisableInterrupt();

            // power down our network chip
            EnterPowerDownMode();
        }
Esempio n. 13
0
        // pin1 > The identifier for the sensor's data bus port
        // pin2 > The identifier for the sensor's data bus port


        public DHT11Sensor(Cpu.Pin pin1, Cpu.Pin pin2, Port.ResistorMode resistormode) // : base(pin1, pin2, pullUp)
        {
            var resistorMode = resistormode;                                           // Use Disabled for External Pullup

            portIn              = new InterruptPort(pin2, false, resistorMode, Port.InterruptMode.InterruptEdgeLow);
            portIn.OnInterrupt += new NativeEventHandler(portIn_OnInterrupt);
            portIn.DisableInterrupt();  // Enabled automatically in the previous call
            portOut = new TristatePort(pin1, true, false, resistorMode);

            if (!CheckPins())
            {
                throw new InvalidOperationException("DHT sensor pins are not connected together.");
            }
        }
Esempio n. 14
0
        // Instantiated via derived class
        protected DhtSensor(Cpu.Pin pin1, Cpu.Pin pin2, PullUpResistor pullUp)
        {
            var resistorMode = (Port.ResistorMode)pullUp;

            portIn              = new InterruptPort(pin2, false, resistorMode, Port.InterruptMode.InterruptEdgeLow);
            portIn.OnInterrupt += new NativeEventHandler(portIn_OnInterrupt);
            portIn.DisableInterrupt(); // Enabled automatically in the previous call

            portOut = new TristatePort(pin1, true, false, resistorMode);

            if (!CheckPins())
            {
                throw new InvalidOperationException("DHT sensor pins are not connected together.");
            }
        }
Esempio n. 15
0
        private void port_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            _port.DisableInterrupt();

            if (data2 > 0)
            {
                OnPressed();
            }
            else
            {
                OnReleased();
            }

            _port.EnableInterrupt();
            _port.ClearInterrupt();
        }
 /// <summary>
 /// Sends a reset pulse on the daisylink chain.  This resets all DaisyLink nodes to INIT state, that is, waiting for a DaisyLink message.
 /// </summary>
 /// <remarks>
 /// It is recommended to reboot the mainboard after calling this method because communication to the DaisyLink nodes will fail.
 /// </remarks>
 internal void SendResetPulse()
 {
     lock (portLock)
     {
         if (daisyLinkInterruptPort != null)
         {
             daisyLinkInterruptPort.DisableInterrupt();
             daisyLinkInterruptPort.Dispose();       // Ask hardware drivers to unreserve this pin
             daisyLinkInterruptPort = null;
         }
         if (daisyLinkResetPort == null)
         {
             daisyLinkResetPort = new TristatePort(daisyLinkCpuPin, false, false, Port.ResistorMode.PullUp);
         }
         daisyLinkResetPort.Active = true;       // Should drive the neighbor bus high
         Thread.Sleep(2);                        // 2 milliseconds is definitely more than 1 ms
         daisyLinkResetPort.Active = false;      // Pull-downs should take the neighbor bus back low
         daisyLinkResetPort.Dispose();           // Remove this pin from the hardware's reserved pin list
         daisyLinkResetPort = null;
     }
 }
Esempio n. 17
0
        public AX88796C(SPI.SPI_module spiBusID, Cpu.Pin csPinID, Cpu.Pin intPinID, Cpu.Pin resetPinID, Cpu.Pin wakeupPinID)
        {
            // create our chip select pin and SPI bus objects
            _chipSelectPin = new OutputPort(csPinID, true);
            _spi           = new SPI(new SPI.Configuration(Cpu.Pin.GPIO_NONE, false, 0, 0, false, true, 40000, spiBusID));

            // wire up our interrupt, for future use
            _interruptPin = new InterruptPort(intPinID, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            _interruptPin.DisableInterrupt();
            _interruptPin.OnInterrupt += _interruptPin_OnInterrupt;

            // save our reset pin ID (which we will use to control the reset pin a bit later on)
            _resetPinID = resetPinID;

            // save our wakeup pin ID (which we can use to create an InterruptPort right before we go to sleep)
            _wakeupPinID = wakeupPinID;

            // create our _sendPacketTxPagesFreeEvent
            _sendPacketTxPagesFreeEvent = new System.Threading.AutoResetEvent(false);

            // we are not initialized; we will initialize when we are started.
            _isInitialized = false;
        }
Esempio n. 18
0
 /// <summary>
 /// Stops the interrupt pin scanning
 /// </summary>
 /// <example> This sample shows how to call the StopIRQ() method.
 /// <code language="C#">
 ///             // ThunderClick board is inserted in Socket 1
 ///             _thunder = new ThunderClick(Hardware.SocketOne);
 ///
 ///             // Start scanning IRQ
 ///             _thunder.StartIRQ();
 ///
 ///             Thread.Sleep(30000);    // Wait 30 sec
 ///             _thunder.StopIRQ();     // Stop scanning IRQ. No more events will be generated
 /// </code>
 /// </example>
 public void StopIRQ()
 {
     IRQ.DisableInterrupt();
 }
Esempio n. 19
0
 private void SetDisabled()
 {
     _cePin.Write(false);
     _irqPin.DisableInterrupt();
 }