/**
   * Writes the account data to the SHAiButton. First, this function asserts that the account page
   * number is known. The account data is copied from dataBuffer starting at the offset. If there
   * are less than 32 bytes available to copy, this function only copies the bytes that are
   * available.
   *
   * @param dataBuffer the buffer to copy the account data from
   * @param offset the index into the buffer where copying should begin
   * @return whether or not the data write succeeded
   * @throws OneWireIOException on a 1-Wire communication error such as reading an incorrect CRC
   *     from a 1-Wire device. This could be caused by a physical interruption in the 1-Wire Network
   *     due to shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.
   * @throws OneWireException on a communication or setup error with the 1-Wire adapter
   */
  public synchronized boolean writeAccountData(byte[] dataBuffer, int offset)
      throws OneWireException, OneWireIOException {
    // init local vars
    OneWireContainer18 ibcL = this.ibc;

    // make sure account info is properly setup
    if (!checkAccountPageInfo(ibcL)) return false;

    int numBytes = Math.min(32, dataBuffer.length - offset);
    System.arraycopy(dataBuffer, offset, this.accountData, 0, numBytes);
    if (ibcL.writeDataPage(this.accountPageNumber, this.accountData)) {
      if (this.writeCycleCounter >= 0) this.writeCycleCounter++;
      return true;
    }

    // if write failed, we don't know what the write cycle counter is
    this.writeCycleCounter = -1;
    // and this cache should be marked dirty
    this.accountData[0] = 0;
    return false;
  }