Simplification

This commit is contained in:
Bertrand Songis
2019-03-28 19:07:50 +01:00
parent 95fe5c59bb
commit 1bd94029e7
4 changed files with 29 additions and 22 deletions
-2
View File
@@ -126,10 +126,8 @@ enum CurveType {
#if defined(PCBHORUS)
#define NUM_RECEIVERS 10
#define MAX_RECEIVERS_PER_MODULE 5
#else
#define NUM_RECEIVERS 4
#define MAX_RECEIVERS_PER_MODULE 4
#endif
#if defined(PCBTARANIS) || defined(PCBSKY9X) || defined(PCBHORUS)
+9 -12
View File
@@ -416,10 +416,7 @@ PACK(struct TrainerModuleData {
*/
PACK(struct ReceiverData {
uint8_t used:1;
uint8_t telemetry:1;
uint8_t dirty:6;
char name[PXX2_LEN_RX_NAME];
char name[PXX2_LEN_RX_NAME];
});
/*
@@ -930,25 +927,25 @@ static inline void check_struct()
#if defined(PCBXLITES)
CHKSIZE(RadioData, 858);
CHKSIZE(ModelData, 5940);
CHKSIZE(ModelData, 5936);
#elif defined(PCBXLITE)
CHKSIZE(RadioData, 852);
CHKSIZE(ModelData, 5940);
CHKSIZE(ModelData, 5936);
#elif defined(PCBX7)
CHKSIZE(RadioData, 858);
CHKSIZE(ModelData, 5940);
CHKSIZE(ModelData, 5936);
#elif defined(PCBX9E)
CHKSIZE(RadioData, 960);
CHKSIZE(ModelData, 6435);
#elif defined(PCBX9D)
CHKSIZE(ModelData, 6431);
#elif defined(PCBX9D) || defined(PCBX9DP)
CHKSIZE(RadioData, 880);
CHKSIZE(ModelData, 6422);
CHKSIZE(ModelData, 6418);
#elif defined(PCBSKY9X)
CHKSIZE(RadioData, 735);
CHKSIZE(ModelData, 5101);
CHKSIZE(ModelData, 5097);
#elif defined(PCBHORUS)
CHKSIZE(RadioData, 855);
CHKSIZE(ModelData, 9771);
CHKSIZE(ModelData, 9761);
#endif
#undef CHKSIZE
+18 -6
View File
@@ -400,9 +400,23 @@ inline bool isDefaultModelRegistrationID()
uint8_t findEmptyReceiverSlot()
{
for (uint8_t slot=0; slot<NUM_RECEIVERS; slot++) {
if (!g_model.receiverData[slot].used) {
return slot + 1;
for (uint8_t slot = 1; slot <= NUM_RECEIVERS; slot++) {
bool used = false;
for (uint8_t module = 0; module < NUM_MODULES; module++) {
if (isModulePXX2(module)) {
for (uint8_t receiver = 0; receiver < PXX2_MAX_RECEIVERS_PER_MODULE; receiver++) {
if (g_model.moduleData[module].pxx2.getReceiverSlot(receiver) == slot) {
used = true;
break;
}
}
if (used) {
break;
}
}
}
if (!used) {
return slot;
}
}
return 0;
@@ -1273,7 +1287,7 @@ void menuModelSetup(event_t event)
if (receiverSlot) {
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, STR_DEL_BUTTON, attr);
if (attr && s_editMode > 0) {
g_model.moduleData[moduleIdx].pxx2.receivers = (g_model.moduleData[moduleIdx].pxx2.receivers & BF_MASK<uint16_t>(0, receiverIdx * 3)) | ((g_model.moduleData[moduleIdx].pxx2.receivers & BF_MASK<uint16_t>((receiverIdx + 1) * 3, (MAX_RECEIVERS_PER_MODULE - 1 - receiverIdx) * 3)) >> 3);
g_model.moduleData[moduleIdx].pxx2.receivers = (g_model.moduleData[moduleIdx].pxx2.receivers & BF_MASK<uint16_t>(0, receiverIdx * 3)) | ((g_model.moduleData[moduleIdx].pxx2.receivers & BF_MASK<uint16_t>((receiverIdx + 1) * 3, (PXX2_MAX_RECEIVERS_PER_MODULE - 1 - receiverIdx) * 3)) >> 3);
memclear(&g_model.receiverData[receiverSlot - 1], sizeof(ReceiverData));
s_editMode = 0;
killEvents(event);
@@ -1288,8 +1302,6 @@ void menuModelSetup(event_t event)
uint8_t slot = findEmptyReceiverSlot();
if (slot > 0) {
g_model.moduleData[moduleIdx].pxx2.receivers |= (slot << (receiverIdx * 3));
--slot;
g_model.receiverData[slot].used = 1;
storageDirty(EE_MODEL);
}
}
+2 -2
View File
@@ -67,13 +67,13 @@ void menuRadioModulesVersion(event_t event)
if (isModulePXX2(INTERNAL_MODULE) && IS_INTERNAL_MODULE_ON()) {
reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE].current = PXX2_HW_INFO_TX_ID;
reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE].maximum = MAX_RECEIVERS_PER_MODULE - 1;
reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE].maximum = PXX2_MAX_RECEIVERS_PER_MODULE - 1;
moduleSettings[INTERNAL_MODULE].mode = MODULE_MODE_GET_HARDWARE_INFO;
}
if (isModulePXX2(EXTERNAL_MODULE) && IS_EXTERNAL_MODULE_ON()) {
reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE].current = PXX2_HW_INFO_TX_ID;
reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE].maximum = MAX_RECEIVERS_PER_MODULE - 1;
reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE].maximum = PXX2_MAX_RECEIVERS_PER_MODULE - 1;
moduleSettings[EXTERNAL_MODULE].mode = MODULE_MODE_GET_HARDWARE_INFO;
}