package com.uxxu.konashi.lib.action;

import android.bluetooth.BluetoothGattService;

import com.uxxu.konashi.lib.KonashiUUID;
import com.uxxu.konashi.lib.store.I2cStore;
import com.uxxu.konashi.lib.util.I2cUtils;

import java.util.UUID;

/**
 * Created by izumin on 9/21/15.
 */
public class I2cWriteAction extends I2cAction {

    private static final UUID UUID = KonashiUUID.I2C_WRITE_UUID;

    private final byte mAddress;
    private final byte[] mData;

    public I2cWriteAction(BluetoothGattService service, byte address, byte[] data, I2cStore store) {
        super(service, UUID, store, false);
        mAddress = address;
        mData = data;
    }

    @Override
    protected void setValue() {
        byte[] value = new byte[20];
        value[0] = (byte) mData.length;
        value[1] = (byte) ((mAddress << 1) & 0xfe);
        System.arraycopy(mData, 0, value, 2, mData.length);
        getCharacteristic().setValue(value);
    }

    @Override
    protected boolean hasValidParams() {
        return I2cUtils.isValidDataLength(mData.length);
    }
}

@@ -739,16 +739,82 @@
 te%5B20%5D;%0A
+        if(mData.length %3C 20) value = new byte%5BmData.length + 2%5D;%0A
         
@@ -831,16 +831,17 @@
  (byte) 
+(
 mData.le
@@ -844,16 +844,21 @@
 a.length
+ + 1)
 ;%0A      

Fix value length