Ejemplo n.º 1
0
 public byte[] Write(IDigitalOut DeviceSelect, byte[] Data, int DataLength)
 {
     DeviceSelect.SetOutput(false);
     byte[] DataReturn = RaspberryPi.SPIRW(BusNum, Data, DataLength);
     DeviceSelect.SetOutput(true);
     return(DataReturn);
 }
Ejemplo n.º 2
0
 private void CheckDev(byte Address)
 {
     if (this.DeviceIDs[Address] < 1)
     {
         this.DeviceIDs[Address] = RaspberryPi.I2CSetup(Address);
     }
 }
Ejemplo n.º 3
0
 public UARTBusPi(byte Device, int Baud)
 {
     if (Device == 0)
     {
         RaspberryPi.SetPinMode(8, RaspberryPi.PinMode.OUTPUT);
         RaspberryPi.SetPinMode(10, RaspberryPi.PinMode.INPUT);
     }
     this.DeviceID = RaspberryPi.SerialOpen(Device, Baud);
 }
Ejemplo n.º 4
0
 /// <summary> Selects the register in the given device, then writes the given data. </summary>
 /// <param name="Address"> The address of the device to write data to. </param>
 /// <param name="Register"> The register to start writing data at. </param>
 /// <param name="Data"> The 8-bit data to write. If more than 1 byte, subsequent registers are written. </param>
 public void WriteRegister(byte Address, byte Register, byte[] Data)
 {
     CheckDev(Address);
     lock (this.BusLock)
     {
         for (int i = 0; i < Data.Length; i++)
         {
             RaspberryPi.I2CWriteRegister8(this.DeviceIDs[Address], (byte)(Register + i), Data[i]);
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary> Writes the data as given to the device at the specified address. </summary>
 /// <param name="Address"> The address of the device to write data to. </param>
 /// <param name="Data"> The 8-bit data to write to the device. </param>
 public void Write(byte Address, byte[] Data)
 {
     CheckDev(Address);
     lock (this.BusLock)
     {
         foreach (byte Byte in Data)
         {
             RaspberryPi.I2CWrite(this.DeviceIDs[Address], Byte);
         }
     }
 }
Ejemplo n.º 6
0
 public void Write(byte Address, byte[] Data)
 {
     if (this.DeviceIDs[Address] < 1)
     {
         this.DeviceIDs[Address] = RaspberryPi.I2CSetup(Address);
     }
     foreach (byte Byte in Data)
     {
         RaspberryPi.I2CWrite(this.DeviceIDs[Address], Byte);
     }
 }
Ejemplo n.º 7
0
 /// <summary> Requests 8-bit data from the given device at the specified register. </summary>
 /// <param name="Address"> The address of the device to read from. </param>
 /// <param name="Register"> The register to start reading data from. </param>
 /// <param name="DataLength"> How many bytes to read. If more than 1, subsequent registers are polled. </param>
 public byte[] ReadRegister(byte Address, byte Register, int DataLength)
 {
     CheckDev(Address);
     byte[] Data = new byte[DataLength];
     lock (this.BusLock)
     {
         for (int i = 0; i < DataLength; i++)
         {
             Data[i] = RaspberryPi.I2CReadRegister8(this.DeviceIDs[Address], (byte)(Register + i));
         }
     }
     return(Data);
 }
Ejemplo n.º 8
0
 /// <summary> Reads 8-bit data from the device at the given address. </summary>
 /// <param name="Address"> The address of the device to read from. </param>
 /// <param name="DataLength"> How many bytes to read. </param>
 public byte[] Read(byte Address, int DataLength)
 {
     CheckDev(Address);
     byte[] Buffer = new byte[DataLength];
     lock (this.BusLock)
     {
         for (int i = 0; i < DataLength; i++)
         {
             Buffer[i] = RaspberryPi.I2CRead(this.DeviceIDs[Address]);
         }
     }
     return(Buffer);
 }
Ejemplo n.º 9
0
 public byte[] Read(byte Address, int DataLength)
 {
     if (this.DeviceIDs[Address] < 1)
     {
         this.DeviceIDs[Address] = RaspberryPi.I2CSetup(Address);
     }
     byte[] Buffer = new byte[DataLength];
     for (int i = 0; i < DataLength; i++)
     {
         Buffer[i] = RaspberryPi.I2CRead(this.DeviceIDs[Address]);
     }
     return(Buffer);
 }
Ejemplo n.º 10
0
        public byte[] Read(int Length)
        {
            List <byte> Data  = new List <byte>();
            int         Avail = RaspberryPi.SerialDataAvailable(this.DeviceID);

            if (Avail < Length)
            {
                Length = Avail;
            }
            for (int i = 0; i < Length; i++)
            {
                Data.Add(RaspberryPi.SerialGetChar(this.DeviceID));
            }
            return(Data.ToArray());
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Registers an interrupt handler for the specified interrupt type.
        /// </summary>
        public void RegisterInterruptHandler(EventHandler <InputInterrupt> Handler, InterruptType Type)
        {
            switch (Type)
            {
            case InterruptType.RISING_EDGE:
            {
                if (!this.RisingInit)
                {
                    RaspberryPi.AddInterrupt(this.PinNumber, 2, this.InterruptRising);
                    this.RisingInit = true;
                }
                this.RisingHandlers += Handler;
                return;
            }

            case InterruptType.FALLING_EDGE:
            {
                if (!this.FallingInit)
                {
                    RaspberryPi.AddInterrupt(this.PinNumber, 1, this.InterruptFalling);
                    this.FallingInit = true;
                }
                this.FallingHandlers += Handler;
                return;
            }

            case InterruptType.ANY_EDGE:
            {
                if (!this.AnyInit)
                {
                    RaspberryPi.AddInterrupt(this.PinNumber, 3, this.InterruptAny);
                    this.AnyInit = true;
                }
                this.AnyHandlers += Handler;
                return;
            }
            }
        }
Ejemplo n.º 12
0
 /// <summary> Reads data from a 16-bit register. </summary>
 /// <param name="Address"> The address of the device to read from. </param>
 /// <param name="Register"> The register to read from. </param>
 /// <returns> The 16-bit data in the register. </returns>
 public ushort ReadRegister16(byte Address, byte Register)
 {
     CheckDev(Address);
     lock (this.BusLock) { return(RaspberryPi.I2CReadRegister16(this.DeviceIDs[Address], Register)); }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Gets the current logic-level input.
 /// </summary>
 public bool GetInput()
 {
     return(RaspberryPi.DigitalRead(this.PinNumber));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Sets the input to either have a ~50KΩ pullup resistor, pulldown resistor, or no resistor.
 /// </summary>
 public void SetResistor(ResistorState Resistor)
 {
     RaspberryPi.SetResistor(this.PinNumber, Resistor);
 }
Ejemplo n.º 15
0
 public DigitalInPi(int PinNumber)
 {
     this.PinNumber = PinNumber;
     RaspberryPi.SetPinMode(this.PinNumber, (int)RaspberryPi.PinMode.INPUT);
 }
Ejemplo n.º 16
0
 /// <summary> Writes data to a 16-bit register. </summary>
 /// <param name="Address"> The address of the device to write to. </param>
 /// <param name="Register"> The register to write data to. </param>
 /// <param name="Data"> The 16-bit data to write to the register. </param>
 public void WriteRegister16(byte Address, byte Register, ushort Data)
 {
     CheckDev(Address);
     lock (this.BusLock) { RaspberryPi.I2CWriteRegister16(this.DeviceIDs[Address], Register, Data); }
 }
Ejemplo n.º 17
0
 public void SetBusSpeed(int Speed)
 {
     RaspberryPi.SPISetup(BusNum, Speed);
 }
Ejemplo n.º 18
0
 public void Write(byte[] Data)
 {
     RaspberryPi.SerialPut(this.DeviceID, Data);
 }
Ejemplo n.º 19
0
 public SPIBusPi(int Bus)
 {
     BusNum = Bus;
     RaspberryPi.SPISetup(Bus, DEFAULT_SPEED);
 }