writeBitReg method

Future<bool> writeBitReg(
  1. NfcTag tag,
  2. int address,
  3. int byte,
  4. int bit,
  5. int value,
)

Implementation

Future<bool> writeBitReg(
    NfcTag tag, int address, int byte, int bit, int value) async {
  Uint8List? receive;

  try {
    receive = await readReg(tag, address);
  } catch (e) {
    return false;
  }

  if (receive![0] != Sic431XFlag.B_ACK) {
    if (Platform.isIOS) {
      NfcManager.instance
          .stopSession(errorMessage: 'Read Register error !!!');
    }
    return false;
  }

  int position = receive[byte] & (~bit & 0xFF);
  int data = value & bit;
  int newRegData = (position | data);

  try {
    await sendCommand(tag, Uint8List.fromList([0xB6, address, newRegData]));
  } catch (e) {
    return false;
  }

  if (receive[0] != Sic431XFlag.B_ACK) {
    if (Platform.isIOS) {
      NfcManager.instance
          .stopSession(errorMessage: 'Read Register error !!!');
    }
    return false;
  }

  return true;
}