adafruit / Adafruit_BluefruitLE_nRF51

Arduino library for nRF51822-based Adafruit Bluefruit LE modules
197 stars 122 forks source link

Adafruit_BluefruitLE_SPI::write(const uint8_t *buf, size_t size) returns the wrong result. #11

Closed corbinstreehouse closed 8 years ago

corbinstreehouse commented 8 years ago

Howdy! The code below is wrong; it clearly returns 0 when the in BLUEFRUIT_MODE_DATA, but should return the amount written.

      while(size)
      {
        size_t len = min(size, SDEP_MAX_PACKETSIZE);
        size -= len;

        sendPacket(SDEP_CMDTYPE_BLE_UARTTX, buf, (uint8_t) len, size ? 1 : 0);
        buf += len;
      }
      getResponse();
    }

    return size;

It should be more like this:

    if (size > 0) {
      size_t amountLeft = size;
      while(amountLeft)
      {
        size_t len = min(amountLeft, SDEP_MAX_PACKETSIZE);
        amountLeft -= len;

        sendPacket(SDEP_CMDTYPE_BLE_UARTTX, buf, (uint8_t) len, amountLeft ? 1 : 0);
        buf += len;
      }

      getResponse();
    }

    return size;

I fixed it on my branch..but I have tons of other hacks that you probably don't want..

hathach commented 8 years ago

holy cow, that is a stupid mistake thanks for reporting :+1: