pack method
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() {
// resolution has a range 100..720 and must be even so just map resolution~/2 to a Uint16 over 2 bytes
int halfRes = _resolution ~/ 2;
int intHalfResolutionMsb = (halfRes >> 8) & 0xFF;
int intHalfResolutionLsb = halfRes & 0xFF;
// pan has a range -140..140 so add 140 and map it to a Uint16 over 2 bytes 0..280
int panShifted = _pan + 140;
int intPanShiftedMsb = (panShifted >> 8) & 0xFF;
int intPanShiftedLsb = panShifted & 0xFF;
// 6 bytes of camera capture 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,
intHalfResolutionMsb,
intHalfResolutionLsb,
intPanShiftedMsb,
intPanShiftedLsb,
_raw ? 0x01 : 0x00,
]);
}