Пример #1
0
        public override void ReadBuffer(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                if (ReadBegin != null)
                {
                    ReadBegin(this, e);
                }

                if (e.Length == 1)
                {
                    e.Buffer.buffer[e.Offset] = BCM2835Managed.GPIOExtras.read_bitbang_byte(port);
                }
                else
                {
                    var segment = new ArraySegment <byte>(e.Buffer.buffer, e.Offset, e.Length);
                    BCM2835Managed.GPIOExtras.read_bitbang_buffer(port, segment);
                }

                if (ReadEnd != null)
                {
                    ReadEnd(this, e);
                }
            });
        }
Пример #2
0
        public unsafe override void WriteBuffer(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                if (WriteBegin != null)
                {
                    WriteBegin(this, e);
                }

                if (e.Length == 1)
                {
                    RaspExtern.Ports.writeNibbleByte(e.Buffer.buffer[e.Offset], dataPin0, dataPin1, dataPin2, dataPin3, clockPin, polarity, lowCycle, highCycle);
                }
                else
                {
                    fixed(byte *bData = e.Buffer.buffer)
                    RaspExtern.Ports.writeNibbleBuffer(bData + e.Offset, (uint)e.Length, dataPin0, dataPin1, dataPin2, dataPin3, clockPin, polarity, lowCycle, highCycle);
                }

                if (WriteEnd != null)
                {
                    WriteEnd(this, e);
                }
            });
        }
Пример #3
0
        public override void TransferBuffer(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                if (TransferBegin != null)
                {
                    TransferBegin(this, e);
                }

                for (int buc = e.Offset; buc < e.Offset + e.Length; buc++)
                {
                    BCM2835Managed.GPIOExtras.write_nibble_byte(port, rs, e.Buffer.buffer[buc], false);
                }

                for (int buc = e.Offset; buc < e.Offset + e.Length; buc++)
                {
                    e.Buffer.buffer[buc] = BCM2835Managed.GPIOExtras.read_nibble_byte(port, rs);
                }

                if (TransferEnd != null)
                {
                    TransferEnd(this, e);
                }
            });
        }
Пример #4
0
        public void Input(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                bool newState = true;

                if (e.Buffer.Size - (offset + e.Offset) >= value.Length)
                {
                    for (int buc = e.Offset + offset; buc < e.Offset + offset + value.Length; buc++)
                    {
                        if (e.Buffer.buffer[buc] != value[buc - offset])
                        {
                            newState = false;
                            break;
                        }
                    }
                }
                else
                {
                    newState = false;
                }

                newState = valueIsHigh ? newState : !newState;

                if (newState != outputState && Output != null)
                {
                    outputState = newState;
                    Output(this, new SignalEventArgs {
                        Signal = newState
                    });
                }
            });
        }
Пример #5
0
        public unsafe override void ReadBuffer(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                if (ReadBegin != null)
                {
                    ReadBegin(this, e);
                }

                if (e.Length == 1)
                {
                    e.Buffer.buffer[e.Offset] = RaspExtern.Ports.readBitBangByte(dataPin, clockPin, polarity, lowCycle, highCycle);
                }
                else
                {
                    fixed(byte *bData = e.Buffer.buffer)
                    RaspExtern.Ports.readBitBangBuffer(bData + e.Offset, (uint)e.Length, dataPin, clockPin, polarity, lowCycle, highCycle);
                }

                if (ReadEnd != null)
                {
                    ReadEnd(this, e);
                }
            });
        }
Пример #6
0
        public unsafe override void TransferBuffer(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                if (TransferBegin != null)
                {
                    TransferBegin(this, e);
                }

                if (e.Length == 1)
                {
                    RaspExtern.Ports.writeOctetByte(e.Buffer.buffer[e.Offset], pinList, clockPin, polarity, lowCycle, highCycle);
                    e.Buffer.buffer[e.Offset] = RaspExtern.Ports.readOctetByte(pinList, clockPin, polarity, lowCycle, highCycle);
                }
                else
                {
                    fixed(byte *bData = e.Buffer.buffer)
                    {
                        RaspExtern.Ports.writeOctetBuffer(bData + e.Offset, (uint)e.Length, pinList, clockPin, polarity, lowCycle, highCycle);
                        RaspExtern.Ports.readOctetBuffer(bData + e.Offset, (uint)e.Length, pinList, clockPin, polarity, lowCycle, highCycle);
                    }
                }

                if (TransferEnd != null)
                {
                    TransferEnd(this, e);
                }
            });
        }
Пример #7
0
 public void Reset(object sender, SignalEventArgs e)
 {
     if (e.Signal == clockPolarity)
     {
         inputA = null;
         inputB = null;
     }
 }
Пример #8
0
        public void CopyTo(object sender, BufferEventArgs e)
        {
            Buffer.BlockCopy(buffer, 0, e.Buffer.buffer, e.Offset, Math.Min((int)(buffer.Length - e.Offset), e.Length));

            if (CopiedTo != null)
            {
                CopiedTo(this, e);
            }
        }
Пример #9
0
 private void Input(BufferEventArgs e, byte ChannelNumber)
 {
     Runner.AddTask((o) =>
     {
         if (currentInput == ChannelNumber)
         {
             Output(this, e);
         }
     });
 }
Пример #10
0
 public void Input(object sender, BufferEventArgs e)
 {
     Runner.AddTask((o) =>
     {
         if (currentOutput != null)
         {
             currentOutput(this, e);
         }
     });
 }
Пример #11
0
        public void CopyFrom(object sender, BufferEventArgs e)
        {
            Buffer.BlockCopy(e.Buffer.buffer, 0, buffer, e.Offset, Math.Min((int)(buffer.Length - e.Offset), e.Length));

            if (CopiedFrom != null)
            {
                CopiedFrom(this, new BufferEventArgs {
                    Buffer = this, Length = e.Length, Offset = e.Offset
                });
            }
        }
Пример #12
0
 public void Input(object sender, BufferEventArgs e)
 {
     Runner.AddTask((o) =>
     {
         if (Output != null)
         {
             Output(this, new ByteEventArgs {
                 Value = e.Buffer.buffer[offset]
             });
         }
     });
 }
Пример #13
0
        public void Input(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                BCM2835Managed.bcm2835_delayMicroseconds(delay);

                if (Output != null)
                {
                    Output(this, e);
                }
            });
        }
Пример #14
0
        public void Input(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                e.Offset = offset;
                e.Length = length;

                if (Output != null)
                {
                    Output(this, e);
                }
            });
        }
Пример #15
0
        public void Input(object sender, BufferEventArgs e)
        {
            ulong start = RaspExtern.Timers.bcm2835_st_read();

            Runner.AddTask((o) =>
            {
                RaspExtern.Timers.bcm2835_st_delay(start, delay);

                if (Output != null)
                {
                    Output(this, e);
                }
            });
        }
Пример #16
0
        public override unsafe void TransferBuffer(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                if (TransferBegin != null)
                {
                    TransferBegin(this, e);
                }

                fixed(byte *bData = &e.Buffer.buffer[e.Offset])
                RaspExtern.SPI.bcm2835_spi_transfern(bData, (uint)e.Length);

                if (TransferEnd != null)
                {
                    TransferEnd(this, e);
                }
            });
        }
Пример #17
0
        public override unsafe void WriteBuffer(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                if (WriteBegin != null)
                {
                    WriteBegin(this, e);
                }

                fixed(byte *bData = &e.Buffer.buffer[e.Offset])
                RaspExtern.I2C.bcm2835_i2c_write(bData, (uint)e.Length);

                if (WriteEnd != null)
                {
                    WriteEnd(this, e);
                }
            });
        }
Пример #18
0
        public override unsafe void TransferBuffer(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                if (TransferBegin != null)
                {
                    TransferBegin(this, e);
                }

                ArraySegment <byte> seg = new ArraySegment <byte>(e.Buffer.buffer, e.Offset, e.Length);
                BCM2835Managed.bcm2835_spi_transfern(seg);

                if (TransferEnd != null)
                {
                    TransferEnd(this, e);
                }
            });
        }
Пример #19
0
        public override unsafe void WriteBuffer(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                if (WriteBegin != null)
                {
                    WriteBegin(this, e);
                }

                ArraySegment <byte> seg = new ArraySegment <byte>(e.Buffer.buffer, e.Offset, e.Length);
                BCM2835Managed.bcm2835_i2c_write(seg);

                if (WriteEnd != null)
                {
                    WriteEnd(this, e);
                }
            });
        }
Пример #20
0
        public void Input(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                var val = e.Buffer.buffer[offset + e.Offset];

                if (val != outputState)
                {
                    outputState = val;

                    if (Output != null)
                    {
                        Output(this, new ByteEventArgs {
                            Value = val
                        });
                    }
                }
            });
        }
Пример #21
0
        public void WriteHalfBuffer(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                if (WriteBegin != null)
                {
                    WriteBegin(this, e);
                }

                for (int buc = e.Offset; buc < e.Offset + e.Length; buc++)
                {
                    BCM2835Managed.GPIOExtras.write_nibble_byte(port, rs, e.Buffer.buffer[buc], true);
                }

                if (WriteEnd != null)
                {
                    WriteEnd(this, e);
                }
            });
        }
Пример #22
0
        public void Input(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                int count = Math.Min(e.Length - offset, 4);
                int value = 0;
                int pos   = 0;

                if (order == ByteOrder.MSB)
                {
                    for (int buc = e.Offset + offset + count - 1; buc >= e.Offset; buc--)
                    {
                        value |= e.Buffer.buffer[buc] << (pos * 8);
                        pos++;
                    }
                }
                else
                {
                    for (int buc = e.Offset + offset; buc < e.Offset + offset + count; buc++)
                    {
                        value |= e.Buffer.buffer[buc] << (pos * 8);
                        pos++;
                    }
                }

                if (outputValue != value)
                {
                    outputValue = value;

                    if (Output != null)
                    {
                        Output(this, new IntegerEventArgs {
                            Value = outputValue
                        });
                    }
                }
            });
        }
Пример #23
0
        public void Input(object sender, BufferEventArgs e)
        {
            Runner.AddTask((o) =>
            {
                bool newOutput = false;

                switch (condition)
                {
                case BufferConditionType.Equal:

                    if (e.Buffer == null && compareValue == null)
                    {
                        newOutput = true;
                    }
                    else if (e.Buffer == null || compareValue == null)
                    {
                        newOutput = false;
                    }
                    else
                    {
                        if (e.Length != compareValue.Size)
                        {
                            newOutput = false;
                        }
                        else
                        {
                            newOutput = true;

                            for (int buc = 0; buc < e.Length; buc++)
                            {
                                if (e.Buffer.buffer[buc + e.Offset] != compareValue.buffer[buc])
                                {
                                    newOutput = false;
                                    break;
                                }
                            }
                        }
                    }
                    break;

                case BufferConditionType.NotEqual:

                    if (e.Buffer == null && compareValue == null)
                    {
                        newOutput = false;
                    }
                    else if (e.Buffer == null || compareValue == null)
                    {
                        newOutput = true;
                    }
                    else
                    {
                        if (e.Length != compareValue.Size)
                        {
                            newOutput = false;
                        }
                        else
                        {
                            newOutput = false;

                            for (int buc = 0; buc < e.Length; buc++)
                            {
                                if (e.Buffer.buffer[buc + e.Offset] != compareValue.buffer[buc])
                                {
                                    newOutput = true;
                                    break;
                                }
                            }
                        }
                    }

                    break;
                }

                if (newOutput != currentOutput)
                {
                    currentOutput = newOutput;

                    if (Output != null)
                    {
                        Output(this, new SignalEventArgs {
                            Signal = currentOutput
                        });
                    }
                }
            });
        }
Пример #24
0
 public void InputB(object sender, BufferEventArgs e)
 {
     inputB = e;
 }
Пример #25
0
 public abstract void ReadBuffer(object sender, BufferEventArgs e);
Пример #26
0
 public abstract void WriteBuffer(object sender, BufferEventArgs e);
Пример #27
0
 public void Input7(object sender, BufferEventArgs e)
 {
     Input(e, 8);
 }
Пример #28
0
 public abstract void TransferBuffer(object sender, BufferEventArgs e);