Esempio n. 1
0
 public LEDOUT(int pin, int pwm)
 {
     Pi.Init <BootstrapWiringPi>();
     ledPin         = (GpioPin)Pi.Gpio[pin];
     ledPin.PinMode = GpioPinDriveMode.Output;
     WiringPi.SoftPwmCreate(pin, pwm, 10);
 }
Esempio n. 2
0
 public Servo(int pin)
 {
     mServoPin         = Pi.Gpio[pin];
     mServoPin.PinMode = GpioPinDriveMode.Output;
     WiringPi.SoftPwmCreate(mServoPin.BcmPinNumber, 0, maxServoPwmVal);
     WiringPi.SoftPwmWrite(mServoPin.BcmPinNumber, 16);
 }
Esempio n. 3
0
        /// <summary>
        /// Registers the interrupt callback on the pin. Pin mode has to be set to Input.
        ///
        /// </summary>
        /// <param name="edgeDetection">The edge detection.</param>
        /// <param name="callback">The callback.</param>
        /// <exception cref="System.ArgumentException">callback</exception>
        /// <exception cref="System.InvalidOperationException">
        /// An interrupt callback was already registered.
        /// or
        /// RegisterInterruptCallback
        /// </exception>
        /// <exception cref="System.InvalidProgramException"></exception>
        public void RegisterInterruptCallback(EdgeDetection edgeDetection, InterrputServiceRoutineCallback callback)
        {
            if (callback == null)
            {
                throw new ArgumentException($"{nameof(callback)} cannot be null");
            }

            if (InterruptCallback != null)
            {
                throw new InvalidOperationException("An interrupt callback was already registered.");
            }

            if (PinMode != GpioPinDriveMode.Input)
            {
                throw new InvalidOperationException($"Unable to {nameof(RegisterInterruptCallback)} for pin {PinNumber} because operating mode is {PinMode}."
                                                    + $" Calling {nameof(RegisterInterruptCallback)} is only allowed if {nameof(PinMode)} is set to {GpioPinDriveMode.Input}");
            }

            lock (_syncLock)
            {
                var registerResult = WiringPi.wiringPiISR(PinNumber, (int)edgeDetection, callback);
                if (registerResult == 0)
                {
                    InterruptEdgeDetection = edgeDetection;
                    InterruptCallback      = callback;
                }
                else
                {
                    HardwareException.Throw(nameof(GpioPin), nameof(RegisterInterruptCallback));
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Starts the software based PWM on this pin.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="range">The range.</param>
        /// <exception cref="System.NotSupportedException"></exception>
        /// <exception cref="System.InvalidOperationException">StartSoftPwm
        /// or</exception>
        public void StartSoftPwm(int value, int range)
        {
            lock (_syncLock)
            {
                if (Capabilities.Contains(PinCapability.GP) == false)
                {
                    throw new NotSupportedException($"Pin {PinNumber} does not support software PWM");
                }

                if (IsInSoftPwmMode)
                {
                    throw new InvalidOperationException($"{nameof(StartSoftPwm)} has already been called.");
                }

                var startResult = WiringPi.softPwmCreate(PinNumber, value, range);
                if (startResult == 0)
                {
                    m_SoftPwmValue = value;
                    m_SoftPwmRange = range;
                }
                else
                {
                    throw new InvalidOperationException($"Could not start software based PWM on pin {PinNumber}. Error code: {startResult}");
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// This initializes the I2C system with your given device identifier.
 /// The ID is the I2C number of the device and you can use the i2cdetect program to find this out.
 /// wiringPiI2CSetup() will work out which revision Raspberry Pi you have and open the appropriate device in /dev.
 /// The return value is the standard Linux filehandle, or -1 if any error – in which case, you can consult errno as usual.
 /// </summary>
 /// <param name="deviceId">The device identifier.</param>
 /// <returns></returns>
 private static int SetupFileDescriptor(int deviceId)
 {
     lock (SyncRoot)
     {
         return(WiringPi.wiringPiI2CSetup(deviceId));
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Converts the Wirings Pi pin number to the BCM pin number.
 /// </summary>
 /// <param name="wiringPiPinNumber">The wiring pi pin number.</param>
 /// <returns>The converted pin</returns>
 internal static int WiringPiToBcmPinNumber(int wiringPiPinNumber)
 {
     lock (SyncRoot)
     {
         return(WiringPi.WpiPinToGpio(wiringPiPinNumber));
     }
 }
Esempio n. 7
0
 /// <summary>
 /// This sets the “strength” of the pad drivers for a particular group of pins.
 /// There are 3 groups of pins and the drive strength is from 0 to 7.
 /// Do not use this unless you know what you are doing.
 /// </summary>
 /// <param name="group">The group.</param>
 /// <param name="value">The value.</param>
 public void SetPadDrive(int group, int value)
 {
     lock (SyncRoot)
     {
         WiringPi.SetPadDrive(group, value);
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Converts the Physical (Header) pin number to BCM pin number.
 /// </summary>
 /// <param name="headerPinNumber">The header pin number.</param>
 /// <returns>The converted pin</returns>
 internal static int HaderToBcmPinNumber(int headerPinNumber)
 {
     lock (SyncRoot)
     {
         return(WiringPi.PhysPinToGpio(headerPinNumber));
     }
 }
Esempio n. 9
0
        public Gpio(NumberingMode mode)
        {
            int output = -1;

            switch (mode)
            {
            default:
            case NumberingMode.Internal:
                output = WiringPi.WiringPiSetup();
                break;

            case NumberingMode.Physical:
                output = WiringPi.WiringPiSetupPhys();
                break;

            case NumberingMode.System:
                output = WiringPi.WiringPiSetupSys();
                break;
            }

            PinNumberingMode = mode;

            if (output < 0)
            {
                throw new WiringPiNotAvailableException();
            }
        }
Esempio n. 10
0
        public void changePinState(int pin, bool state)
        {
            switch (pin)
            {
            case 1:
                WiringPi.SoftPwmWrite(enableA.BcmPinNumber, mSpeed);
                WiringPi.SoftPwmWrite(enableB.BcmPinNumber, mSpeed);
                motor1.Write(state);
                break;

            case 2:
                WiringPi.SoftPwmWrite(enableA.BcmPinNumber, mSpeed);
                WiringPi.SoftPwmWrite(enableB.BcmPinNumber, mSpeed);
                motor2.Write(state);
                break;

            case 3:
                WiringPi.SoftPwmWrite(enableA.BcmPinNumber, mSpeed);
                WiringPi.SoftPwmWrite(enableB.BcmPinNumber, mSpeed);
                motor3.Write(state);
                break;

            case 4:
                WiringPi.SoftPwmWrite(enableA.BcmPinNumber, mSpeed);
                WiringPi.SoftPwmWrite(enableB.BcmPinNumber, mSpeed);
                motor4.Write(state);
                break;

            default:
                MessageBox.Show("Invalid pin!", "Error");
                break;
            }
        }
Esempio n. 11
0
 public void setENA2(int value)
 {
     if (value <= maxPwmVal && value >= 0)
     {
         ENA2Pwm = value;
         WiringPi.SoftPwmWrite(enableB.BcmPinNumber, value);
     }
 }
Esempio n. 12
0
 public void TestClock()
 {
     rpi.StartGPIOClock();
     rpi.StartWatcher();
     WiringPi.Delay(1000);
     rpi.StopGPIOClock();
     rpi.StopWatcher();
 }
Esempio n. 13
0
 public void setServoPwm(int value)
 {
     if (value <= maxServoPwmVal && value >= minServoPwmVal)
     {
         servoPwmVal = value;
         WiringPi.SoftPwmWrite(mServoPin.BcmPinNumber, value);
     }
 }
Esempio n. 14
0
        internal I2CtoSPI(int deviceId, int fileDescriptor)
        {
            //Console.WriteLine(MethodInfo.GetCurrentMethod().Name);
            DeviceId       = deviceId;
            FileDescriptor = fileDescriptor;

            WiringPi.WiringPiSPISetup(0, 976000);
        }
Esempio n. 15
0
 public void Stop()
 {
     WiringPi.SoftPwmWrite(enableA.BcmPinNumber, 0);
     WiringPi.SoftPwmWrite(enableB.BcmPinNumber, 0);
     motor1.Write(false);
     motor2.Write(false);
     motor3.Write(false);
     motor4.Write(false);
 }
Esempio n. 16
0
        public void WriteAddressWord(int address, ushort data)
        {
            var result = WiringPi.WiringPiI2CWriteReg16(FileDescriptor, address, data);

            if (result < 0)
            {
                throw new Exception($"I2C {DeviceID} 의 쓰기 작업에 실패하였습니다. Error Code: {result}.");
            }
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            WiringPi.WiringPiSetup();

            blinkaj(10);

            //Ne radi - callback
            WiringPi.WiringPiISR(BUTTON, 2, Callback);
        }
Esempio n. 18
0
 public void Left()
 {
     WiringPi.SoftPwmWrite(enableA.BcmPinNumber, mTurnSpeed);
     WiringPi.SoftPwmWrite(enableB.BcmPinNumber, mTurnSpeed);
     motor1.Write(false);
     motor2.Write(true);
     motor3.Write(false);
     motor4.Write(true);
 }
Esempio n. 19
0
 public void Backward()
 {
     WiringPi.SoftPwmWrite(enableA.BcmPinNumber, ENA1Pwm);
     WiringPi.SoftPwmWrite(enableB.BcmPinNumber, ENA2Pwm);
     motor1.Write(true);
     motor2.Write(false);
     motor3.Write(false);
     motor4.Write(true);
 }
Esempio n. 20
0
 public void ON()
 {
     if (isPWM != true)
     {
         isOn  = true;
         isPWM = true;
         WiringPi.SoftPwmCreate(pin, 10, 10);
     }
 }
Esempio n. 21
0
        public void TestInterrupts()
        {
            rpi.StopGPIOClock();

            rpi.SetInterrupt();
            rpi.StartGPIOClock();
            WiringPi.Delay(2000); //Let see how many times interrupts in a second.
            rpi.StopGPIOClock();
        }
Esempio n. 22
0
        public void Write(byte[] data)
        {
            //Console.WriteLine(MethodInfo.GetCurrentMethod().Name + " 2");

            lock (syncLock)
            {
                var result = WiringPi.WiringPiSPIDataRW(0, data, data.Length);
            }
        }
Esempio n. 23
0
 public void BackwardRight()
 {
     WiringPi.SoftPwmWrite(enableA.BcmPinNumber, Speed / turnDivider);
     WiringPi.SoftPwmWrite(enableB.BcmPinNumber, Speed);
     motor1.Write(true);
     motor2.Write(false);
     motor3.Write(false);
     motor4.Write(true);
 }
Esempio n. 24
0
        private void SetMode(PinMode mode)
        {
            if ((mode == PinMode.GpioClock && !HasCapability(PinCapability.GPCLK)) || (mode == PinMode.PwmOutput && !HasCapability(PinCapability.PWM)) || (mode == PinMode.Input && !HasCapability(PinCapability.GP)) || (mode == PinMode.Output && !HasCapability(PinCapability.GP)))
            {
                throw new NotSupportedException($"{PinNumber}번 핀은 {mode} 모드를 지원하지 않습니다");
            }

            WiringPi.PinMode(GpioNumber, (int)mode);
            Mode = mode;
        }
Esempio n. 25
0
 static void  blinkaj(int trajanje)
 {
     for (int i = 0; i < trajanje; i++)
     {
         WiringPi.DigitalWrite(LED, 1);
         Thread.Sleep(200);
         WiringPi.DigitalWrite(LED, 0);
         Thread.Sleep(200);
     }
 }
Esempio n. 26
0
        public byte Read()
        {
            var result = WiringPi.WiringPiI2CRead(FileDescriptor);

            if (result < 0)
            {
                throw new Exception($"I2C {DeviceID} 의 읽기 작업에 실패하였습니다. Error Code: {result}.");
            }
            return((byte)result);
        }
Esempio n. 27
0
        public void TestSetup()
        {
            rpi = new RPIDriver();
            Console.WriteLine(rpi.ReadAllPins());

            rpi.Log.Add("PiBoard rev. = " + WiringPi.PiBoardRev().ToString());
            //Test GPIO readall

            Console.WriteLine(rpi.ReadAllPins());
        }
Esempio n. 28
0
        /// <summary>
        /// This attempts to shift your program (or thread in a multi-threaded program) to a higher priority and
        /// enables a real-time scheduling. The priority parameter should be from 0 (the default) to 99 (the maximum).
        /// This won’t make your program go any faster, but it will give it a bigger slice of time when other programs
        /// are running. The priority parameter works relative to others – so you can make one program priority 1 and
        /// another priority 2 and it will have the same effect as setting one to 10 and the other to 90
        /// (as long as no other programs are running with elevated priorities).
        /// </summary>
        /// <param name="priority">The priority.</param>
        public void SetThreadPriority(int priority)
        {
            priority = priority.Clamp(0, 99);
            var result = WiringPi.PiHiPri(priority);

            if (result < 0)
            {
                HardwareException.Throw(nameof(Timing), nameof(SetThreadPriority));
            }
        }
Esempio n. 29
0
 /// <summary>
 /// These write an 8 or 16-bit data value into the device register indicated.
 /// </summary>
 /// <param name="address">The register.</param>
 /// <param name="data">The data.</param>
 public void WriteAddressWord(int address, ushort data)
 {
     lock (SyncLock)
     {
         var result = WiringPi.wiringPiI2CWriteReg16(FileDescriptor, address, data);
         if (result < 0)
         {
             HardwareException.Throw(nameof(I2CDevice), nameof(WriteAddressWord));
         }
     }
 }
Esempio n. 30
0
 /// <summary>
 /// Writes a byte of data the specified file descriptor.
 /// </summary>
 /// <param name="data">The data.</param>
 public void Write(byte data)
 {
     lock (SyncLock)
     {
         var result = WiringPi.wiringPiI2CWrite(FileDescriptor, data);
         if (result < 0)
         {
             HardwareException.Throw(nameof(I2CDevice), nameof(Write));
         }
     }
 }