IRC Ghost 12 bit support
This commit is contained in:
committed by
Raphael Coeffic
parent
a177264759
commit
77386e6391
+54
-44
@@ -24,59 +24,73 @@
|
||||
uint8_t createGhostMenuControlFrame(uint8_t * frame, int16_t * pulses)
|
||||
{
|
||||
uint8_t * buf = frame;
|
||||
#if SPORT_MAX_BAUDRATE < 400000
|
||||
*buf++ = g_eeGeneral.telemetryBaudrate == GHST_TELEMETRY_RATE_400K ? GHST_ADDR_MODULE_SYM : GHST_ADDR_MODULE_ASYM;
|
||||
#else
|
||||
*buf++ = GHST_ADDR_MODULE_SYM;
|
||||
#endif
|
||||
|
||||
*buf++ = GHST_UL_RC_CHANS_SIZE;
|
||||
uint8_t * crc_start = buf;
|
||||
*buf++ = GHST_UL_MENU_CTRL;
|
||||
*buf++ = getGhostModuleAddr(); // addr
|
||||
*buf++ = GHST_UL_RC_CHANS_SIZE; // length
|
||||
const uint8_t * crc_start = buf;
|
||||
*buf++ = GHST_UL_MENU_CTRL; // type
|
||||
|
||||
// payload
|
||||
*buf++ = reusableBuffer.ghostMenu.buttonAction; // Joystick states, Up, Down, Left, Right, Press
|
||||
*buf++ = reusableBuffer.ghostMenu.menuAction; // menu control, open, close, etc.
|
||||
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
*buf++ = 0; // padding to make this the same size as the pulses packet
|
||||
}
|
||||
|
||||
// crc
|
||||
*buf++ = crc8(crc_start, GHST_UL_RC_CHANS_SIZE - 1);
|
||||
|
||||
return buf - frame;
|
||||
}
|
||||
|
||||
// Range for pulses (channels output) is [-1024:+1024]
|
||||
uint8_t createGhostChannelsFrame(uint8_t * frame, int16_t * pulses)
|
||||
uint8_t createGhostChannelsFrame(uint8_t * frame, int16_t * pulses, bool raw12bits)
|
||||
{
|
||||
static uint8_t lastGhostFrameId = GHST_UL_RC_CHANS_HS4_5TO8;
|
||||
static uint8_t lastGhostFrameId = 0;
|
||||
uint8_t ghostUpper4Offset = 0;
|
||||
|
||||
switch (lastGhostFrameId) {
|
||||
case GHST_UL_RC_CHANS_HS4_5TO8:
|
||||
ghostUpper4Offset = 0;
|
||||
break;
|
||||
case GHST_UL_RC_CHANS_HS4_9TO12:
|
||||
case GHST_UL_RC_CHANS_HS4_12_5TO8:
|
||||
lastGhostFrameId = raw12bits ? GHST_UL_RC_CHANS_HS4_12_9TO12 : GHST_UL_RC_CHANS_HS4_9TO12;
|
||||
ghostUpper4Offset = 4;
|
||||
break;
|
||||
case GHST_UL_RC_CHANS_HS4_13TO16:
|
||||
break;
|
||||
|
||||
case GHST_UL_RC_CHANS_HS4_9TO12:
|
||||
case GHST_UL_RC_CHANS_HS4_12_9TO12:
|
||||
lastGhostFrameId = raw12bits ? GHST_UL_RC_CHANS_HS4_12_13TO16 : GHST_UL_RC_CHANS_HS4_13TO16;
|
||||
ghostUpper4Offset = 8;
|
||||
break;
|
||||
|
||||
case GHST_UL_RC_CHANS_HS4_13TO16:
|
||||
case GHST_UL_RC_CHANS_HS4_12_13TO16:
|
||||
lastGhostFrameId = raw12bits ? GHST_UL_RC_CHANS_HS4_12_5TO8 : GHST_UL_RC_CHANS_HS4_5TO8;
|
||||
ghostUpper4Offset = 0;
|
||||
break;
|
||||
|
||||
default: // We don't have known previous state so init
|
||||
lastGhostFrameId = raw12bits ? GHST_UL_RC_CHANS_HS4_12_5TO8 : GHST_UL_RC_CHANS_HS4_5TO8;
|
||||
ghostUpper4Offset = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t * buf = frame;
|
||||
#if SPORT_MAX_BAUDRATE < 400000
|
||||
*buf++ = g_eeGeneral.telemetryBaudrate == GHST_TELEMETRY_RATE_400K ? GHST_ADDR_MODULE_SYM : GHST_ADDR_MODULE_ASYM;
|
||||
#else
|
||||
*buf++ = GHST_ADDR_MODULE_SYM;
|
||||
#endif
|
||||
*buf++ = GHST_UL_RC_CHANS_SIZE;
|
||||
*buf++ = getGhostModuleAddr(); // addr
|
||||
*buf++ = GHST_UL_RC_CHANS_SIZE; // len
|
||||
uint8_t * crc_start = buf;
|
||||
*buf++ = lastGhostFrameId;
|
||||
*buf++ = lastGhostFrameId; // type
|
||||
|
||||
// payload
|
||||
// first 4 high speed, 12 bit channels (11 relevant bits with openTx)
|
||||
uint32_t bits = 0;
|
||||
uint8_t bitsavailable = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
uint32_t value = limit(0, GHST_RC_CTR_VAL_12BIT + (((pulses[i] + 2 * PPM_CH_CENTER(i) - 2 * PPM_CENTER) << 3) / 5), 2 * GHST_RC_CTR_VAL_12BIT);
|
||||
uint32_t value;
|
||||
if(raw12bits) {
|
||||
value = limit(0, (1024 + (pulses[i] + 2 * PPM_CH_CENTER(i) - 2 * PPM_CENTER)) << 1, 0xFFF);
|
||||
} else {
|
||||
value = limit(0, GHST_RC_CTR_VAL_12BIT + (((pulses[i] + 2 * PPM_CH_CENTER(i) - 2 * PPM_CENTER) << 3) / 5), 2 * GHST_RC_CTR_VAL_12BIT);
|
||||
}
|
||||
bits |= value << bitsavailable;
|
||||
bitsavailable += GHST_CH_BITS_12;
|
||||
while (bitsavailable >= 8) {
|
||||
@@ -89,23 +103,18 @@ uint8_t createGhostChannelsFrame(uint8_t * frame, int16_t * pulses)
|
||||
// second 4 lower speed, 8 bit channels
|
||||
for (int i = 4; i < 8; ++i) {
|
||||
uint8_t channelIndex = i + ghostUpper4Offset;
|
||||
*buf++ = limit(0, GHST_RC_CTR_VAL_8BIT + (((pulses[channelIndex] + 2 * PPM_CH_CENTER(channelIndex) - 2 * PPM_CENTER) >> 1) / 5), 2 * GHST_RC_CTR_VAL_8BIT);
|
||||
uint8_t value;
|
||||
if(raw12bits) {
|
||||
value = limit(0, 128 + ((pulses[channelIndex] + 2 * PPM_CH_CENTER(channelIndex) - 2 * PPM_CENTER) >> 3), 0xFF);
|
||||
} else {
|
||||
value = limit(0, GHST_RC_CTR_VAL_8BIT + (((pulses[channelIndex] + 2 * PPM_CH_CENTER(channelIndex) - 2 * PPM_CENTER) >> 1) / 5), 2 * GHST_RC_CTR_VAL_8BIT);
|
||||
}
|
||||
*buf++ = value;
|
||||
}
|
||||
|
||||
// crc
|
||||
*buf++ = crc8(crc_start, GHST_UL_RC_CHANS_SIZE - 1);
|
||||
|
||||
switch (lastGhostFrameId) {
|
||||
case GHST_UL_RC_CHANS_HS4_5TO8:
|
||||
lastGhostFrameId = GHST_UL_RC_CHANS_HS4_9TO12;
|
||||
break;
|
||||
case GHST_UL_RC_CHANS_HS4_9TO12:
|
||||
lastGhostFrameId = GHST_UL_RC_CHANS_HS4_13TO16;
|
||||
break;
|
||||
case GHST_UL_RC_CHANS_HS4_13TO16:
|
||||
lastGhostFrameId = GHST_UL_RC_CHANS_HS4_5TO8;
|
||||
break;
|
||||
}
|
||||
|
||||
return buf - frame;
|
||||
}
|
||||
|
||||
@@ -113,11 +122,12 @@ void setupPulsesGhost()
|
||||
{
|
||||
if (telemetryProtocol == PROTOCOL_TELEMETRY_GHOST) {
|
||||
uint8_t * pulses = extmodulePulsesData.ghost.pulses;
|
||||
if (moduleState[EXTERNAL_MODULE].counter == GHST_MENU_CONTROL)
|
||||
extmodulePulsesData.ghost.length = createGhostMenuControlFrame(pulses, &channelOutputs[g_model.moduleData[EXTERNAL_MODULE].channelsStart]);
|
||||
else
|
||||
extmodulePulsesData.ghost.length = createGhostChannelsFrame(pulses, &channelOutputs[g_model.moduleData[EXTERNAL_MODULE].channelsStart]);
|
||||
|
||||
auto & module = g_model.moduleData[EXTERNAL_MODULE];
|
||||
if (moduleState[EXTERNAL_MODULE].counter == GHST_MENU_CONTROL) {
|
||||
extmodulePulsesData.ghost.length = createGhostMenuControlFrame(pulses, &channelOutputs[module.channelsStart]);
|
||||
} else {
|
||||
extmodulePulsesData.ghost.length = createGhostChannelsFrame(pulses, &channelOutputs[module.channelsStart], module.ghost.raw12bits);
|
||||
}
|
||||
moduleState[EXTERNAL_MODULE].counter = GHST_FRAME_CHANNEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user