pack method

  1. @override
Uint8List pack()
override

pack() should produce a message data payload that can be parsed by a corresponding parser in the frameside application (Lua) TxMsg needs to know its own message code, but it is not included in the payload bytes returned by pack; the 0x01 data byte and the msgCode byte are prepended to each bluetooth write() call by the sendDataRaw method, followed by the maximum amount of payload data that will fit until the whole message is sent.

Implementation

@override
Uint8List pack() {
  // several doubles in the range 0 to 1, so map that to an unsigned byte 0..255
  // by multiplying by 255 and rounding
  int intExp = (_exposure * 255).round() & 0xFF;
  int intExpSpeed = (_exposureSpeed * 255).round() & 0xFF;
  int intWhiteBalanceSpeed = (_whiteBalanceSpeed * 255).round() & 0xFF;

  // shutter limit has a range 4..16384 so just map it to a Uint16 over 2 bytes
  int intShutLimMsb = (_shutterLimit >> 8) & 0xFF;
  int intShutLimLsb = _shutterLimit & 0xFF;

  // manual shutter has a range 4..16384 so just map it to a Uint16 over 2 bytes
  int intManShutterMsb = (_manualShutter >> 8) & 0xFF;
  int intManShutterLsb = _manualShutter & 0xFF;

  // manual color gains have a range 0..1023 so just map them to a Uint16 over 2 bytes
  int intManRedGainMsb = (_manualRedGain >> 8) & 0x03;
  int intManRedGainLsb = _manualRedGain & 0xFF;
  int intManGreenGainMsb = (_manualGreenGain >> 8) & 0x03;
  int intManGreenGainLsb = _manualGreenGain & 0xFF;
  int intManBlueGainMsb = (_manualBlueGain >> 8) & 0x03;
  int intManBlueGainLsb = _manualBlueGain & 0xFF;



  // 19 bytes of camera settings. sendMessage will prepend the data byte, msgCode to each packet
  // and the Uint16 payload length to the first packet
  return Uint8List.fromList([
    _qualityIndex & 0xFF,
    _autoExpGainTimes & 0xFF,
    _autoExpInterval & 0xFF,
    _meteringIndex & 0xFF,
    intExp,
    intExpSpeed,
    intShutLimMsb,
    intShutLimLsb,
    _analogGainLimit & 0xFF,
    intWhiteBalanceSpeed,
    intManShutterMsb,
    intManShutterLsb,
    _manualAnalogGain & 0xFF,
    intManRedGainMsb,
    intManRedGainLsb,
    intManGreenGainMsb,
    intManGreenGainLsb,
    intManBlueGainMsb,
    intManBlueGainLsb,
  ]);
}