package com.uxxu.konashi.lib.action;

import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.util.SparseArray;

import com.uxxu.konashi.lib.Konashi;
import com.uxxu.konashi.lib.KonashiUUID;

import java.util.UUID;

import info.izumin.android.bletia.BleErrorType;
import info.izumin.android.bletia.BletiaException;
import info.izumin.android.bletia.action.ReadCharacteristicAction;
import info.izumin.android.bletia.wrapper.BluetoothGattWrapper;

/**
 * Created by izumin on 9/19/15.
 */
public class AioAnalogReadAction extends ReadCharacteristicAction {

    private static final SparseArray<UUID> sPin2Uuid = new SparseArray<UUID>() {{
        append(Konashi.AIO0, KonashiUUID.ANALOG_READ0_UUID);
        append(Konashi.AIO1, KonashiUUID.ANALOG_READ1_UUID);
        append(Konashi.AIO2, KonashiUUID.ANALOG_READ2_UUID);
    }};

    protected AioAnalogReadAction(BluetoothGattCharacteristic characteristic) {
        super(characteristic);
    }

    public AioAnalogReadAction(BluetoothGattService service, int pin) {
        this(service.getCharacteristic(sPin2Uuid.get(pin, null)));
    }

    @Override
    public void execute(BluetoothGattWrapper gattWrapper) {
        if (getCharacteristic() == null) {
            rejectIfParamsAreInvalid();
        } else {
            super.execute(gattWrapper);
        }
    }

    private void rejectIfParamsAreInvalid() {
        getDeferred().reject(new BletiaException(BleErrorType.INVALID_PARAMETER, getCharacteristic()));
    }
}

@@ -203,16 +203,62 @@
 onashi;%0A
+import com.uxxu.konashi.lib.KonashiErrorType;%0A
 import c
@@ -1520,19 +1520,23 @@
 ception(
-Ble
+Konashi
 ErrorTyp
@@ -1541,25 +1541,27 @@
 ype.
-INVALID_PARAME
+NULL_CHARAC
 TER
+ISTIC
 , ge

Modify AioAnalogReadAction