Refactoring. CAUTION: ERASE your EEPROM again!

This commit is contained in:
Bertrand Songis
2019-02-22 13:15:23 +01:00
parent 62f8e36d90
commit e567643652
12 changed files with 197 additions and 146 deletions
+15 -21
View File
@@ -446,8 +446,6 @@ PACK(struct ModuleData {
} r9m; } r9m;
}; };
int16_t failsafeChannels[MAX_OUTPUT_CHANNELS];
union { union {
struct { struct {
int8_t delay:6; int8_t delay:6;
@@ -569,24 +567,10 @@ PACK(struct CustomScreenData {
// TODO other boards could have their custom screens here as well // TODO other boards could have their custom screens here as well
#endif #endif
#if defined(PCBX12S) #if defined(PCBHORUS) || defined(PCBTARANIS)
#define MODELDATA_EXTRA NOBACKUP(uint8_t spare:6); NOBACKUP(uint8_t potsWarnMode:2); ModuleData moduleData[NUM_MODULES]; TrainerModuleData trainerData; NOBACKUP(ScriptData scriptsData[MAX_SCRIPTS]); NOBACKUP(char inputNames[MAX_INPUTS][LEN_INPUT_NAME]); NOBACKUP(uint8_t potsWarnEnabled); NOBACKUP(int8_t potsWarnPosition[NUM_POTS+NUM_SLIDERS]); #define SCRIPTS_DATA NOBACKUP(ScriptData scriptsData[MAX_SCRIPTS]);
#elif defined(PCBX10)
#define MODELDATA_EXTRA NOBACKUP(uint8_t spare:3); NOBACKUP(uint8_t trainerMode:3); NOBACKUP(uint8_t potsWarnMode:2); ModuleData moduleData[NUM_MODULES]; TrainerModuleData trainerData; NOBACKUP(ScriptData scriptsData[MAX_SCRIPTS]); NOBACKUP(char inputNames[MAX_INPUTS][LEN_INPUT_NAME]); NOBACKUP(uint8_t potsWarnEnabled); NOBACKUP(int8_t potsWarnPosition[NUM_POTS+NUM_SLIDERS]); NOBACKUP(uint8_t potsWarnSpares[NUM_DUMMY_ANAS]);
#elif defined(PCBTARANIS)
#define MODELDATA_EXTRA \
uint8_t spare:6; \
uint8_t potsWarnMode:2; \
ModuleData moduleData[NUM_MODULES]; \
TrainerModuleData trainerData; \
ScriptData scriptsData[MAX_SCRIPTS]; \
char inputNames[MAX_INPUTS][LEN_INPUT_NAME]; \
uint8_t potsWarnEnabled; \
int8_t potsWarnPosition[NUM_POTS+NUM_SLIDERS];
#elif defined(PCBSKY9X)
#define MODELDATA_EXTRA uint8_t spare:6; uint8_t potsWarnMode:2; ModuleData moduleData[NUM_MODULES+1]; char inputNames[MAX_INPUTS][LEN_INPUT_NAME]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[NUM_POTS+NUM_SLIDERS]; uint8_t rxBattAlarms[2];
#else #else
#define MODELDATA_EXTRA #define SCRIPTS_DATA
#endif #endif
PACK(struct ModelData { PACK(struct ModelData {
@@ -624,7 +608,17 @@ PACK(struct ModelData {
TELEMETRY_DATA TELEMETRY_DATA
MODELDATA_EXTRA NOBACKUP(uint8_t spare:6);
NOBACKUP(uint8_t potsWarnMode:2);
ModuleData moduleData[NUM_MODULES];
int16_t failsafeChannels[MAX_OUTPUT_CHANNELS];
TrainerModuleData trainerData;
SCRIPTS_DATA
NOBACKUP(char inputNames[MAX_INPUTS][LEN_INPUT_NAME]);
NOBACKUP(uint8_t potsWarnEnabled);
NOBACKUP(int8_t potsWarnPosition[NUM_POTS+NUM_SLIDERS+NUM_DUMMY_ANAS]);
NOBACKUP(TelemetrySensor telemetrySensors[MAX_TELEMETRY_SENSORS];) NOBACKUP(TelemetrySensor telemetrySensors[MAX_TELEMETRY_SENSORS];)
@@ -804,7 +798,7 @@ PACK(struct RadioData {
#undef SWITCHES_WARNING_DATA #undef SWITCHES_WARNING_DATA
#undef MODEL_GVARS_DATA #undef MODEL_GVARS_DATA
#undef TELEMETRY_DATA #undef TELEMETRY_DATA
#undef MODELDATA_EXTRA #undef SCRIPTS_DATA
#undef CUSTOM_SCREENS_DATA #undef CUSTOM_SCREENS_DATA
#undef SPLASH_MODE #undef SPLASH_MODE
#undef EXTRA_GENERAL_FIELDS #undef EXTRA_GENERAL_FIELDS
+14 -11
View File
@@ -303,7 +303,7 @@ void runPopupRegister(event_t event)
if (menuVerticalPosition != 2) { if (menuVerticalPosition != 2) {
break; break;
} }
else if (menuHorizontalPosition == 0) { else if (reusableBuffer.moduleSetup.pxx2.registerStep >= REGISTER_RX_NAME_RECEIVED && menuHorizontalPosition == 0) {
// [Enter] pressed // [Enter] pressed
reusableBuffer.moduleSetup.pxx2.registerStep = REGISTER_RX_NAME_SELECTED; reusableBuffer.moduleSetup.pxx2.registerStep = REGISTER_RX_NAME_SELECTED;
backupEditMode = EDIT_MODIFY_FIELD; // so that the [Register] button blinks and the REGISTER process can continue backupEditMode = EDIT_MODIFY_FIELD; // so that the [Register] button blinks and the REGISTER process can continue
@@ -322,7 +322,7 @@ void runPopupRegister(event_t event)
} }
if (warningText) { if (warningText) {
const uint8_t dialogRows[] = { 0, 0, 1}; const uint8_t dialogRows[] = { 0, uint8_t(reusableBuffer.moduleSetup.pxx2.registerStep < REGISTER_RX_NAME_RECEIVED ? READONLY_ROW : 0), uint8_t(reusableBuffer.moduleSetup.pxx2.registerStep < REGISTER_RX_NAME_RECEIVED ? 0 : 1)};
check(event, 0, nullptr, 0, dialogRows, 2, 2); check(event, 0, nullptr, 0, dialogRows, 2, 2);
drawMessageBox(); drawMessageBox();
@@ -330,21 +330,24 @@ void runPopupRegister(event_t event)
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y - 3, STR_REG_ID); lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y - 3, STR_REG_ID);
editName(WARNING_LINE_X + 8*FW, WARNING_LINE_Y - 3, g_model.modelRegistrationID, PXX2_LEN_REGISTRATION_ID, event, menuVerticalPosition == 0); editName(WARNING_LINE_X + 8*FW, WARNING_LINE_Y - 3, g_model.modelRegistrationID, PXX2_LEN_REGISTRATION_ID, event, menuVerticalPosition == 0);
if (reusableBuffer.moduleSetup.pxx2.registerStep >= REGISTER_RX_NAME_RECEIVED) { if (reusableBuffer.moduleSetup.pxx2.registerStep < REGISTER_RX_NAME_RECEIVED) {
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y - 2 + FH, "Waiting ...");
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+2*FH + 2, TR_EXIT, menuVerticalPosition == 2 ? INVERS : 0);
}
else {
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y - 2 + FH, STR_RX_NAME); lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y - 2 + FH, STR_RX_NAME);
editName(WARNING_LINE_X + 8*FW, WARNING_LINE_Y - 2 + FH, reusableBuffer.moduleSetup.pxx2.registerRxName, PXX2_LEN_RX_NAME, event, menuVerticalPosition == 1); editName(WARNING_LINE_X + 8*FW, WARNING_LINE_Y - 2 + FH, reusableBuffer.moduleSetup.pxx2.registerRxName, PXX2_LEN_RX_NAME, event, menuVerticalPosition == 1);
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+2*FH + 2, TR_ENTER, menuVerticalPosition == 2 && menuHorizontalPosition == 0 ? INVERS : 0); lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+2*FH + 2, TR_ENTER, menuVerticalPosition == 2 && menuHorizontalPosition == 0 ? INVERS : 0);
lcdDrawText(WARNING_LINE_X + 8*FW, WARNING_LINE_Y+2*FH + 2, TR_EXIT, menuVerticalPosition == 2 && menuHorizontalPosition == 1 ? INVERS : 0);
} }
lcdDrawText(WARNING_LINE_X + 8*FW, WARNING_LINE_Y+2*FH + 2, TR_EXIT, menuVerticalPosition == 2 && menuHorizontalPosition == 1 ? INVERS : 0);
reusableBuffer.moduleSetup.pxx2.registerPopupVerticalPosition = menuVerticalPosition; reusableBuffer.moduleSetup.pxx2.registerPopupVerticalPosition = menuVerticalPosition;
reusableBuffer.moduleSetup.pxx2.registerPopupHorizontalPosition = menuHorizontalPosition; reusableBuffer.moduleSetup.pxx2.registerPopupHorizontalPosition = menuHorizontalPosition;
reusableBuffer.moduleSetup.pxx2.registerPopupEditMode = s_editMode; reusableBuffer.moduleSetup.pxx2.registerPopupEditMode = s_editMode;
} }
menuVerticalPosition = ITEM_MODEL_INTERNAL_MODULE_PXX2_RANGE_REGISTER + HEADER_LINE; menuVerticalPosition = ITEM_MODEL_INTERNAL_MODULE_PXX2_RANGE_REGISTER + HEADER_LINE;
menuHorizontalPosition = 1; menuHorizontalPosition = 0;
menuVerticalOffset = backupVerticalOffset; menuVerticalOffset = backupVerticalOffset;
s_editMode = backupEditMode; s_editMode = backupEditMode;
} }
@@ -1172,12 +1175,12 @@ void menuModelSetup(event_t event)
if (attr) { if (attr) {
if (moduleSettings[moduleIdx].mode == MODULE_MODE_NORMAL && s_editMode > 0) { if (moduleSettings[moduleIdx].mode == MODULE_MODE_NORMAL && s_editMode > 0) {
if (menuHorizontalPosition == 0 && event == EVT_KEY_FIRST(KEY_ENTER)) { if (menuHorizontalPosition == 0 && event == EVT_KEY_FIRST(KEY_ENTER)) {
moduleSettings[moduleIdx].mode = MODULE_MODE_REGISTER;
reusableBuffer.moduleSetup.pxx2.registerStep = REGISTER_START; reusableBuffer.moduleSetup.pxx2.registerStep = REGISTER_START;
memcpy(reusableBuffer.moduleSetup.pxx2.registrationID, g_model.modelRegistrationID, PXX2_LEN_REGISTRATION_ID); memcpy(reusableBuffer.moduleSetup.pxx2.registrationID, g_model.modelRegistrationID, PXX2_LEN_REGISTRATION_ID);
reusableBuffer.moduleSetup.pxx2.registerPopupVerticalPosition = 0; reusableBuffer.moduleSetup.pxx2.registerPopupVerticalPosition = 0;
reusableBuffer.moduleSetup.pxx2.registerPopupHorizontalPosition = 0; reusableBuffer.moduleSetup.pxx2.registerPopupHorizontalPosition = 0;
reusableBuffer.moduleSetup.pxx2.registerPopupEditMode = 0; reusableBuffer.moduleSetup.pxx2.registerPopupEditMode = 0;
moduleSettings[moduleIdx].mode = MODULE_MODE_REGISTER;
s_editMode = 0; s_editMode = 0;
POPUP_INPUT("", runPopupRegister); POPUP_INPUT("", runPopupRegister);
} }
@@ -1780,11 +1783,11 @@ void menuModelFailsafe(event_t event)
if (menuVerticalPosition < sentModuleChannels(g_moduleIdx)) { if (menuVerticalPosition < sentModuleChannels(g_moduleIdx)) {
if (s_editMode > 0) { if (s_editMode > 0) {
g_model.moduleData[g_moduleIdx].failsafeChannels[menuVerticalPosition] = channelOutputs[menuVerticalPosition+channelStart]; g_model.failsafeChannels[menuVerticalPosition] = channelOutputs[menuVerticalPosition+channelStart];
s_editMode = 0; s_editMode = 0;
} }
else { else {
int16_t & failsafe = g_model.moduleData[g_moduleIdx].failsafeChannels[menuVerticalPosition]; int16_t & failsafe = g_model.failsafeChannels[menuVerticalPosition];
if (failsafe < FAILSAFE_CHANNEL_HOLD) if (failsafe < FAILSAFE_CHANNEL_HOLD)
failsafe = FAILSAFE_CHANNEL_HOLD; failsafe = FAILSAFE_CHANNEL_HOLD;
else if (failsafe == FAILSAFE_CHANNEL_HOLD) else if (failsafe == FAILSAFE_CHANNEL_HOLD)
@@ -1816,7 +1819,7 @@ void menuModelFailsafe(event_t event)
// Channels // Channels
for (; line < 8; line++) { for (; line < 8; line++) {
const int32_t channelValue = channelOutputs[ch+channelStart]; const int32_t channelValue = channelOutputs[ch+channelStart];
int32_t failsafeValue = g_model.moduleData[g_moduleIdx].failsafeChannels[ch]; int32_t failsafeValue = g_model.failsafeChannels[ch];
//Channel //Channel
putsChn(x+1, y, ch+1, SMLSIZE); putsChn(x+1, y, ch+1, SMLSIZE);
@@ -1831,7 +1834,7 @@ void menuModelFailsafe(event_t event)
} }
else { else {
flags |= BLINK; flags |= BLINK;
CHECK_INCDEC_MODELVAR(event, g_model.moduleData[g_moduleIdx].failsafeChannels[ch], -lim, +lim); CHECK_INCDEC_MODELVAR(event, g_model.failsafeChannels[ch], -lim, +lim);
} }
} }
} }
+4 -1
View File
@@ -199,7 +199,10 @@ void runHWPopupRegister(event_t event)
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y - 3, STR_REG_ID); lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y - 3, STR_REG_ID);
editName(WARNING_LINE_X + 8*FW, WARNING_LINE_Y - 3, g_model.modelRegistrationID, PXX2_LEN_REGISTRATION_ID, event, menuVerticalPosition == 0); editName(WARNING_LINE_X + 8*FW, WARNING_LINE_Y - 3, g_model.modelRegistrationID, PXX2_LEN_REGISTRATION_ID, event, menuVerticalPosition == 0);
if (reusableBuffer.moduleSetup.pxx2.registerStep >= REGISTER_RX_NAME_RECEIVED) { if (reusableBuffer.moduleSetup.pxx2.registerStep < REGISTER_RX_NAME_RECEIVED) {
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y - 2 + FH, "Waiting for receiver ...");
}
else {
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y - 2 + FH, STR_RX_NAME); lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y - 2 + FH, STR_RX_NAME);
editName(WARNING_LINE_X + 8*FW, WARNING_LINE_Y - 2 + FH, reusableBuffer.moduleSetup.pxx2.registerRxName, PXX2_LEN_RX_NAME, event, menuVerticalPosition == 1); editName(WARNING_LINE_X + 8*FW, WARNING_LINE_Y - 2 + FH, reusableBuffer.moduleSetup.pxx2.registerRxName, PXX2_LEN_RX_NAME, event, menuVerticalPosition == 1);
} }
+3 -3
View File
@@ -337,10 +337,10 @@ void setCustomFailsafe(uint8_t moduleIndex)
if (moduleIndex < NUM_MODULES) { if (moduleIndex < NUM_MODULES) {
for (int ch=0; ch<MAX_OUTPUT_CHANNELS; ch++) { for (int ch=0; ch<MAX_OUTPUT_CHANNELS; ch++) {
if (ch < g_model.moduleData[moduleIndex].channelsStart || ch >= sentModuleChannels(moduleIndex) + g_model.moduleData[moduleIndex].channelsStart) { if (ch < g_model.moduleData[moduleIndex].channelsStart || ch >= sentModuleChannels(moduleIndex) + g_model.moduleData[moduleIndex].channelsStart) {
g_model.moduleData[moduleIndex].failsafeChannels[ch] = 0; g_model.failsafeChannels[ch] = 0;
} }
else if (g_model.moduleData[moduleIndex].failsafeChannels[ch] < FAILSAFE_CHANNEL_HOLD) { else if (g_model.failsafeChannels[ch] < FAILSAFE_CHANNEL_HOLD) {
g_model.moduleData[moduleIndex].failsafeChannels[ch] = channelOutputs[ch]; g_model.failsafeChannels[ch] = channelOutputs[ch];
} }
} }
} }
-101
View File
@@ -1,101 +0,0 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
template <class PxxTransport>
void PxxPulses<PxxTransport>::addChannels(uint8_t port, uint8_t sendFailsafe, uint8_t sendUpperChannels)
{
uint16_t pulseValue = 0;
uint16_t pulseValueLow = 0;
for (int8_t i=0; i<8; i++) {
if (sendFailsafe) {
if (g_model.moduleData[port].failsafeMode == FAILSAFE_HOLD) {
pulseValue = (i < sendUpperChannels ? 4095 : 2047);
}
else if (g_model.moduleData[port].failsafeMode == FAILSAFE_NOPULSES) {
pulseValue = (i < sendUpperChannels ? 2048 : 0);
}
else {
if (i < sendUpperChannels) {
int16_t failsafeValue = g_model.moduleData[port].failsafeChannels[8+i];
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
pulseValue = 4095;
}
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
pulseValue = 2048;
}
else {
failsafeValue += 2*PPM_CH_CENTER(8+g_model.moduleData[port].channelsStart+i) - 2*PPM_CENTER;
pulseValue = limit(2049, (failsafeValue * 512 / 682) + 3072, 4094);
}
}
else {
int16_t failsafeValue = g_model.moduleData[port].failsafeChannels[i];
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
pulseValue = 2047;
}
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
pulseValue = 0;
}
else {
failsafeValue += 2*PPM_CH_CENTER(g_model.moduleData[port].channelsStart+i) - 2*PPM_CENTER;
pulseValue = limit(1, (failsafeValue * 512 / 682) + 1024, 2046);
}
}
}
}
else {
if (i < sendUpperChannels) {
int channel = 8 + g_model.moduleData[port].channelsStart + i;
int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
pulseValue = limit(2049, (value * 512 / 682) + 3072, 4094);
}
else if (i < sentModuleChannels(port)) {
int channel = g_model.moduleData[port].channelsStart + i;
int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
pulseValue = limit(1, (value * 512 / 682) + 1024, 2046);
}
else {
pulseValue = 1024;
}
}
if (i & 1) {
PxxTransport::addByte(pulseValueLow); // Low byte of channel
PxxTransport::addByte(((pulseValueLow >> 8) & 0x0F) | (pulseValue << 4)); // 4 bits each from 2 channels
PxxTransport::addByte(pulseValue >> 4); // High byte of channel
}
else {
pulseValueLow = pulseValue;
}
}
}
#if defined(PXX1)
template class PxxPulses<StandardPxx1Transport<PwmPxxBitTransport> >;
template class PxxPulses<StandardPxx1Transport<SerialPxxBitTransport> >;
template class PxxPulses<UartPxx1Transport>;
#endif
#if defined(PXX2)
template class PxxPulses<Pxx2Transport>;
#endif
+71 -1
View File
@@ -110,6 +110,76 @@ void Pxx1Pulses<PxxTransport>::addExtraFlags(uint8_t module)
PxxTransport::addByte(extra_flags); PxxTransport::addByte(extra_flags);
} }
template <class PxxTransport>
void Pxx1Pulses<PxxTransport>::addChannels(uint8_t port, uint8_t sendFailsafe, uint8_t sendUpperChannels)
{
uint16_t pulseValue = 0;
uint16_t pulseValueLow = 0;
for (int8_t i=0; i<8; i++) {
if (sendFailsafe) {
if (g_model.moduleData[port].failsafeMode == FAILSAFE_HOLD) {
pulseValue = (i < sendUpperChannels ? 4095 : 2047);
}
else if (g_model.moduleData[port].failsafeMode == FAILSAFE_NOPULSES) {
pulseValue = (i < sendUpperChannels ? 2048 : 0);
}
else {
if (i < sendUpperChannels) {
int16_t failsafeValue = g_model.failsafeChannels[8+i];
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
pulseValue = 4095;
}
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
pulseValue = 2048;
}
else {
failsafeValue += 2*PPM_CH_CENTER(8+g_model.moduleData[port].channelsStart+i) - 2*PPM_CENTER;
pulseValue = limit(2049, (failsafeValue * 512 / 682) + 3072, 4094);
}
}
else {
int16_t failsafeValue = g_model.failsafeChannels[i];
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
pulseValue = 2047;
}
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
pulseValue = 0;
}
else {
failsafeValue += 2*PPM_CH_CENTER(g_model.moduleData[port].channelsStart+i) - 2*PPM_CENTER;
pulseValue = limit(1, (failsafeValue * 512 / 682) + 1024, 2046);
}
}
}
}
else {
if (i < sendUpperChannels) {
int channel = 8 + g_model.moduleData[port].channelsStart + i;
int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
pulseValue = limit(2049, (value * 512 / 682) + 3072, 4094);
}
else if (i < sentModuleChannels(port)) {
int channel = g_model.moduleData[port].channelsStart + i;
int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
pulseValue = limit(1, (value * 512 / 682) + 1024, 2046);
}
else {
pulseValue = 1024;
}
}
if (i & 1) {
PxxTransport::addByte(pulseValueLow); // Low byte of channel
PxxTransport::addByte(((pulseValueLow >> 8) & 0x0F) | (pulseValue << 4)); // 4 bits each from 2 channels
PxxTransport::addByte(pulseValue >> 4); // High byte of channel
}
else {
pulseValueLow = pulseValue;
}
}
}
template <class PxxTransport> template <class PxxTransport>
void Pxx1Pulses<PxxTransport>::add8ChannelsFrame(uint8_t module, uint8_t sendUpperChannels) void Pxx1Pulses<PxxTransport>::add8ChannelsFrame(uint8_t module, uint8_t sendUpperChannels)
{ {
@@ -128,7 +198,7 @@ void Pxx1Pulses<PxxTransport>::add8ChannelsFrame(uint8_t module, uint8_t sendUpp
PxxTransport::addByte(0); PxxTransport::addByte(0);
// Channels // Channels
PxxPulses<PxxTransport>::addChannels(module, flag1 & PXX_SEND_FAILSAFE, sendUpperChannels); addChannels(module, flag1 & PXX_SEND_FAILSAFE, sendUpperChannels);
// Extra flags // Extra flags
addExtraFlags(module); addExtraFlags(module);
+1 -1
View File
@@ -156,7 +156,7 @@ class Pxx1Pulses: public PxxPulses<PxxTransport>
uint8_t addFlag1(uint8_t port); uint8_t addFlag1(uint8_t port);
void addExtraFlags(uint8_t port); void addExtraFlags(uint8_t port);
void addChannels(uint8_t port, uint8_t sendFailsafe, uint8_t sendUpperChannels);
void add8ChannelsFrame(uint8_t port, uint8_t sendUpperChannels); void add8ChannelsFrame(uint8_t port, uint8_t sendUpperChannels);
}; };
+52 -2
View File
@@ -39,6 +39,50 @@ void Pxx2Pulses::addFlag1(uint8_t module)
Pxx2Transport::addByte(flag1); Pxx2Transport::addByte(flag1);
} }
void Pxx2Pulses::addChannels(uint8_t module, uint8_t sendFailsafe, uint8_t firstChannel)
{
uint16_t pulseValue = 0;
uint16_t pulseValueLow = 0;
for (int8_t i=0; i<8; i++) {
uint8_t channel = firstChannel + i;
if (sendFailsafe) {
if (g_model.moduleData[module].failsafeMode == FAILSAFE_HOLD) {
pulseValue = 2047;
}
else if (g_model.moduleData[module].failsafeMode == FAILSAFE_NOPULSES) {
pulseValue = 0;
}
else {
int16_t failsafeValue = g_model.failsafeChannels[channel];
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
pulseValue = 2047;
}
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
pulseValue = 0;
}
else {
failsafeValue += 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
pulseValue = limit(1, (failsafeValue * 512 / 682) + 1024, 2046);
}
}
}
else {
int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
pulseValue = limit(1, (value * 512 / 682) + 1024, 2046);
}
if (i & 1) {
Pxx2Transport::addByte(pulseValueLow); // Low byte of channel
Pxx2Transport::addByte(((pulseValueLow >> 8) & 0x0F) | (pulseValue << 4)); // 4 bits each from 2 channels
Pxx2Transport::addByte(pulseValue >> 4); // High byte of channel
}
else {
pulseValueLow = pulseValue;
}
}
}
void Pxx2Pulses::setupChannelsFrame(uint8_t module) void Pxx2Pulses::setupChannelsFrame(uint8_t module)
{ {
addFrameType(PXX2_TYPE_C_MODULE, PXX2_TYPE_ID_CHANNELS); addFrameType(PXX2_TYPE_C_MODULE, PXX2_TYPE_ID_CHANNELS);
@@ -50,8 +94,14 @@ void Pxx2Pulses::setupChannelsFrame(uint8_t module)
addFlag1(module); addFlag1(module);
// Channels // Channels
addChannels(module, flag0 & PXX2_FLAG0_FAILSAFE, 0); uint8_t channelsCount = sentModuleChannels(module);
addChannels(module, flag0 & PXX2_FLAG0_FAILSAFE, 1); addChannels(module, flag0 & PXX2_FLAG0_FAILSAFE, g_model.moduleData[module].channelsStart);
if (channelsCount > 8) {
addChannels(module, flag0 & PXX2_FLAG0_FAILSAFE, g_model.moduleData[module].channelsStart + 8);
if (channelsCount > 16) {
addChannels(module, flag0 & PXX2_FLAG0_FAILSAFE, g_model.moduleData[module].channelsStart + 16);
}
}
} }
bool Pxx2Pulses::setupRegisterFrame(uint8_t module) bool Pxx2Pulses::setupRegisterFrame(uint8_t module)
+2
View File
@@ -132,6 +132,8 @@ class Pxx2Pulses: public PxxPulses<Pxx2Transport> {
void addFlag1(uint8_t module); void addFlag1(uint8_t module);
void addChannels(uint8_t module, uint8_t sendFailsafe, uint8_t firstChannel);
void addCrc() void addCrc()
{ {
Pxx2Transport::addByteWithoutCrc(Pxx2CrcMixin::crc >> 8); Pxx2Transport::addByteWithoutCrc(Pxx2CrcMixin::crc >> 8);
+31 -2
View File
@@ -486,6 +486,34 @@ PACK(typedef struct {
uint8_t ppmPulsePol; uint8_t ppmPulsePol;
}) ModuleData_v216; }) ModuleData_v216;
PACK(typedef struct {
uint8_t type:4;
int8_t rfProtocol:4;
uint8_t channelsStart;
int8_t channelsCount; // 0=8 channels
union {
struct {
uint8_t failsafeMode:4; // only 3 bits used
uint8_t subType:3;
uint8_t invertedSerial:1; // telemetry serial inverted from standard
};
struct {
uint8_t failsafeMode:4; // only 3 bits used
uint8_t freq:2;
uint8_t region:2;
} r9m;
};
int16_t failsafeChannels[MAX_OUTPUT_CHANNELS];
union {
struct {
int8_t delay:6;
uint8_t pulsePol:1;
uint8_t outputType:1; // false = open drain, true = push pull
int8_t frameLength;
} ppm;
};
}) ModuleData_v217;
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
#define MODELDATA_EXTRA_216 \ #define MODELDATA_EXTRA_216 \
uint8_t externalModule; \ uint8_t externalModule; \
@@ -511,7 +539,7 @@ PACK(typedef struct {
uint8_t spare:3; \ uint8_t spare:3; \
uint8_t trainerMode:3; \ uint8_t trainerMode:3; \
uint8_t potsWarnMode:2; \ uint8_t potsWarnMode:2; \
ModuleData moduleData[NUM_MODULES+1]; \ ModuleData_v217 moduleData[NUM_MODULES+1]; \
char curveNames[MAX_CURVES][6]; \ char curveNames[MAX_CURVES][6]; \
ScriptData scriptsData[MAX_SCRIPTS]; \ ScriptData scriptsData[MAX_SCRIPTS]; \
char inputNames[MAX_INPUTS][LEN_INPUT_NAME]; \ char inputNames[MAX_INPUTS][LEN_INPUT_NAME]; \
@@ -1205,7 +1233,8 @@ void ConvertModel_217_to_218(ModelData & model)
} }
} }
for (int i=0; i<NUM_MODULES+1; i++) { for (int i=0; i<NUM_MODULES+1; i++) {
newModel.moduleData[i] = oldModel.moduleData[i]; // newModel.moduleData[i] = oldModel.moduleData[i];
#warning "Conversion from v217 to v218 is broken"
} }
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
newModel.trainerData.mode = oldModel.trainerMode; newModel.trainerData.mode = oldModel.trainerMode;
@@ -9,8 +9,6 @@ option(TRACE_AUDIO "Traces audio enabled" OFF)
option(DEBUG_TRACE_BUFFER "Debug Trace Screen" OFF) option(DEBUG_TRACE_BUFFER "Debug Trace Screen" OFF)
option(MULTIMODULE "DIY Multiprotocol TX Module (https://github.com/pascallanger/DIY-Multiprotocol-TX-Module)" OFF) option(MULTIMODULE "DIY Multiprotocol TX Module (https://github.com/pascallanger/DIY-Multiprotocol-TX-Module)" OFF)
option(CROSSFIRE "Crossfire TX Module" OFF) option(CROSSFIRE "Crossfire TX Module" OFF)
option(PXX1 "PXX1 protocol support" OFF)
option(PXX2 "PXX2 protocol support" ON)
option(SUPPORT_D16_EU_ONLY "XJT module only supports D16-EU and LR12-EU" OFF) # TODO rename to XJT_EU_ONLY option(SUPPORT_D16_EU_ONLY "XJT module only supports D16-EU and LR12-EU" OFF) # TODO rename to XJT_EU_ONLY
option(DEBUG_INTERRUPTS "Count interrupts" OFF) option(DEBUG_INTERRUPTS "Count interrupts" OFF)
option(DEBUG_USB_INTERRUPTS "Count individual USB interrupts" OFF) option(DEBUG_USB_INTERRUPTS "Count individual USB interrupts" OFF)
@@ -185,7 +183,6 @@ set(PULSES_SRC
${PULSES_SRC} ${PULSES_SRC}
pulses.cpp pulses.cpp
ppm.cpp ppm.cpp
pxx.cpp
dsm2.cpp dsm2.cpp
sbus.cpp sbus.cpp
) )
+4
View File
@@ -144,6 +144,8 @@ elseif(PCB STREQUAL XLITES)
endif() endif()
if(PCB STREQUAL XLITE OR PCB STREQUAL XLITES OR PCB STREQUAL X3) if(PCB STREQUAL XLITE OR PCB STREQUAL XLITES OR PCB STREQUAL X3)
option(PXX1 "PXX1 protocol support" OFF)
option(PXX2 "PXX2 protocol support" ON)
add_definitions(-DINTERNAL_MODULE_SERIAL) add_definitions(-DINTERNAL_MODULE_SERIAL)
if(PXX_FREQUENCY STREQUAL HIGH) if(PXX_FREQUENCY STREQUAL HIGH)
add_definitions(-DPXX_FREQUENCY_HIGH) add_definitions(-DPXX_FREQUENCY_HIGH)
@@ -156,6 +158,8 @@ if(PCB STREQUAL XLITE OR PCB STREQUAL XLITES OR PCB STREQUAL X3)
../common/arm/stm32/intmodule_serial_driver.cpp ../common/arm/stm32/intmodule_serial_driver.cpp
) )
else() else()
set(PXX1 YES)
option(PXX2 "PXX2 protocol support" ON)
set(TARGET_SRC set(TARGET_SRC
${TARGET_SRC} ${TARGET_SRC}
intmodule_pulses_driver.cpp intmodule_pulses_driver.cpp