示例#1
0
def poolData(timeout):
    buf = bytearray()
    buf.append(rrpi.NRF_POOL_DATA)
    rrpi.intArrayToBuffer(struct.pack("f", timeout), buf)
    _rrpi.send(buf)
    res = _rrpi.recvBool()

    if DEBUG:
        print(">> sent NRF_POOL_DATA, got " + str(res))
    return res
示例#2
0
def initNRF(spiBus, spiDevice, packetSize, address, channel):
    global _rrpi

    _rrpi = rrpi.RRPi()
    buf = bytearray()
    buf.append(rrpi.NRF_INIT)
    buf.append(spiBus)
    buf.append(spiDevice)
    buf.append(packetSize)
    rrpi.intArrayToBuffer(address, buf)
    buf.append(channel)
    _rrpi.send(buf)

    if DEBUG:
        print(">> sent NRF_INIT")
示例#3
0
def sendAndReceive(data, timeout):
    buf = bytearray()
    buf.append(rrpi.NRF_SEND_AND_RECEIVE)
    rrpi.intArrayToBuffer(struct.pack("f", timeout), buf)
    size = len(data)
    buf.append(size)
    _rrpi.send(rrpi.intArrayToBuffer(data, buf))
    time.sleep(0.001)
    recieved = _rrpi.recv(size)
    res = rrpi.bytesToIntArray(recieved)

    if DEBUG:
        print(">> sent NRF_SEND_AND_RECEIVE; set= " + str(data) + ", " +
              str(timeout) + ", got= " + str(res))
    return res
示例#4
0
def setWritePipeAddress(address):
    buf = bytearray()
    buf.append(rrpi.NRF_SET_WRITE_PIPE_ADR)
    _rrpi.send(rrpi.intArrayToBuffer(address, buf))

    if DEBUG:
        print(">> sent NRF_SET_WRITE_PIPE_ADR " + str(address))
示例#5
0
def setReadPipeAddress(pipeNumber, address):
    buf = bytearray()
    buf.append(rrpi.NRF_SET_READ_PIPE_ADR)
    buf.append(pipeNumber)

    _rrpi.send(rrpi.intArrayToBuffer(address, buf))

    if DEBUG:
        print(">> sent NRF_SET_READ_PIPE_ADR " + str(pipeNumber) + ", " +
              str(address))
示例#6
0
def sendData(data):
    buf = bytearray()
    buf.append(rrpi.NRF_SEND)
    buf.append(len(data))
    _rrpi.send(rrpi.intArrayToBuffer(data, buf))

    res = _rrpi.recvBool()

    if DEBUG:
        print(">> sent NRF_SEND, get " + str(res))
    return res
示例#7
0
    def xfer(self, data, speed_hz=0, delay_usec=0, bits_per_word=8):
        b = bytearray()
        b.append(rrpi.SPI_XFER)
        b.append(len(data) & 255)
        b.append(len(data) >> 8 & 255)

        self._rrpi.send(rrpi.intArrayToBuffer(data, b))

        rec = self._rrpi.recv(len(data))

        resp = []
        for bb in rec:
            resp.append(bb)

        return resp