controlLedBuzzer method

Future<LedState> controlLedBuzzer({
  1. bool? redFinalState,
  2. bool? greenFinalState,
  3. required bool redInitialState,
  4. required bool greenInitialState,
  5. bool redBlinking = false,
  6. bool greenBlinking = false,
  7. required int t1Duration,
  8. required int t2Duration,
  9. required int repetitions,
  10. bool buzzerT1 = false,
  11. bool buzzerT2 = false,
})

Controls the LED and buzzer behavior on the RFID reader.

This method enables detailed customization of the RFID reader's LED and buzzer behaviors, allowing for adjustments to the initial and final states of LEDs, controlling LED blinking, defining the duration for blinking cycles, and managing buzzer sounds during specific intervals.

Parameters

  • redFinalState: Optional final state of the red LED (on/off). If null, the state remains unchanged.
  • greenFinalState: Optional final state of the green LED (on/off). If null, the state remains unchanged.
  • redInitialState: The initial state of the red LED (on/off) before any blinking occurs.
  • greenInitialState: The initial state of the green LED (on/off) before any blinking occurs.
  • redBlinking: Determines whether the red LED should blink.
  • greenBlinking: Determines whether the green LED should blink.
  • t1Duration: The duration of the first part of the blinking cycle in milliseconds. Must be a multiple of 100ms.
  • t2Duration: The duration of the second part of the blinking cycle in milliseconds. Must be a multiple of 100ms.
  • repetitions: The number of blinking cycles to repeat.
  • buzzerT1: Indicates whether the buzzer should be activated during the first part of the blinking cycle.
  • buzzerT2: Indicates whether the buzzer should be activated during the second part of the blinking cycle.

Returns

An LedState object reflecting the final states of the red and green LEDs.

Throws

  • Exception if the t1Duration, t2Duration, or repetitions parameters fall outside their acceptable ranges.

Example

var ledState = await controlLedBuzzer(
  redInitialState: true,
  greenInitialState: false,
  t1Duration: 500,
  t2Duration: 500,
  repetitions: 3,
  buzzerT1: true,
  buzzerT2: false,
);
print('Red LED final state: ${ledState.red}');
print('Green LED final state: ${ledState.green}');

Note: Utilize this method to provide precise control over the visual and auditory feedback mechanisms of the RFID reader, enhancing the interactive experience for users.

Implementation

Future<LedState> controlLedBuzzer({
  bool? redFinalState,
  bool? greenFinalState,
  required bool redInitialState,
  required bool greenInitialState,
  bool redBlinking = false,
  bool greenBlinking = false,
  required int t1Duration,
  required int t2Duration,
  required int repetitions,
  bool buzzerT1 = false,
  bool buzzerT2 = false,
}) async {
  if (t1Duration < 0 || 0xFF < t1Duration / 100) {
    throw Exception('Invalid t1Duration. Must be between 0ms and 25500ms');
  }

  if (t1Duration % 100 != 0) {
    throw Exception('Invalid t1Duration. Must be a multiple of 100ms');
  }

  if (t2Duration < 0 || 0xFF < t2Duration / 100) {
    throw Exception('Invalid t2Duration. Must be between 0ms and 25500ms');
  }

  if (t2Duration % 100 != 0) {
    throw Exception('Invalid t2Duration. Must be a multiple of 100ms');
  }

  if (repetitions < 0 || 0xFF < repetitions) {
    throw Exception('Invalid repetitions. Must be between 0 and 255');
  }

  final ledControlByte = int.parse(
    [
      greenBlinking ? '1' : '0',
      redBlinking ? '1' : '0',
      greenInitialState ? '1' : '0',
      redInitialState ? '1' : '0',
      greenFinalState != null ? '1' : '0',
      redFinalState != null ? '1' : '0',
      greenFinalState == true ? '1' : '0',
      redFinalState == true ? '1' : '0',
    ].join(''),
    radix: 2,
  );

  final buzzerControlByte = int.parse(
    [
      buzzerT2 ? '1' : '0',
      buzzerT1 ? '1' : '0',
    ].join(''),
    radix: 2,
  );

  final result = await transmitApdu(
    ApduHeader(
      classNumber: 0xFF,
      instruction: 0x00,
      p1: 0x40,
      p2: ledControlByte,
    ),
    data: [
      t1Duration ~/ 100,
      t2Duration ~/ 100,
      repetitions,
      buzzerControlByte,
    ],
  );

  return LedState(
    red: result.sw2 & 0x01 == 0x01,
    green: result.sw2 & 0x02 == 0x02,
  );
}