1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-26 01:35:16 +03:00

OTA update continued

This commit is contained in:
Bertrand Songis 2019-04-24 17:23:28 +02:00
parent 1cd8c93455
commit bae1131a1b
6 changed files with 85 additions and 21 deletions

View file

@ -292,7 +292,7 @@ void onPXX2R9MBindModeMenu(const char * result)
reusableBuffer.moduleSetup.bindInformation.step = BIND_OK; reusableBuffer.moduleSetup.bindInformation.step = BIND_OK;
POPUP_INFORMATION(STR_BIND_OK); POPUP_INFORMATION(STR_BIND_OK);
#else #else
reusableBuffer.moduleSetup.bindInformation.step = BIND_OPTIONS_SELECTED; reusableBuffer.moduleSetup.bindInformation.step = BIND_START;
#endif #endif
} }
@ -323,7 +323,7 @@ void onPXX2BindMenu(const char * result)
reusableBuffer.moduleSetup.bindInformation.step = BIND_OK; reusableBuffer.moduleSetup.bindInformation.step = BIND_OK;
POPUP_INFORMATION(STR_BIND_OK); POPUP_INFORMATION(STR_BIND_OK);
#else #else
reusableBuffer.moduleSetup.bindInformation.step = BIND_OPTIONS_SELECTED; reusableBuffer.moduleSetup.bindInformation.step = BIND_START;
#endif #endif
} }
} }
@ -1419,7 +1419,7 @@ void menuModelSetup(event_t event)
} }
if (moduleState[moduleIdx].mode == MODULE_MODE_BIND) { if (moduleState[moduleIdx].mode == MODULE_MODE_BIND) {
if (reusableBuffer.moduleSetup.bindInformation.step == BIND_START && reusableBuffer.moduleSetup.bindInformation.candidateReceiversCount > 0) { if (reusableBuffer.moduleSetup.bindInformation.step == BIND_INIT && reusableBuffer.moduleSetup.bindInformation.candidateReceiversCount > 0) {
popupMenuItemsCount = min<uint8_t>(reusableBuffer.moduleSetup.bindInformation.candidateReceiversCount, PXX2_MAX_RECEIVERS_PER_MODULE); popupMenuItemsCount = min<uint8_t>(reusableBuffer.moduleSetup.bindInformation.candidateReceiversCount, PXX2_MAX_RECEIVERS_PER_MODULE);
for (uint8_t i=0; i<popupMenuItemsCount; i++) { for (uint8_t i=0; i<popupMenuItemsCount; i++) {
popupMenuItems[i] = reusableBuffer.moduleSetup.bindInformation.candidateReceiversNames[i]; popupMenuItems[i] = reusableBuffer.moduleSetup.bindInformation.candidateReceiversNames[i];

View file

@ -87,6 +87,24 @@ void onSdFormatConfirm(const char * result)
} }
} }
void onUpdateConfirmation(const char * result)
{
if (result == STR_OK) {
// TODO OTA Update
}
else {
moduleState[EXTERNAL_MODULE].mode = MODULE_MODE_NORMAL;
}
}
void onBindStateChanged()
{
if (reusableBuffer.sdManager.otaInformation.step == BIND_INFO_REQUEST) {
POPUP_CONFIRMATION(PXX2receiversModels[reusableBuffer.sdManager.otaInformation.receiverInformation.modelID], onUpdateConfirmation);
// SET_WARNING_INFO(STR_MODEL_STILL_POWERED, sizeof(TR_MODEL_STILL_POWERED), 0);
}
}
void onSdManagerMenu(const char * result) void onSdManagerMenu(const char * result)
{ {
TCHAR lfn[_MAX_LFN+1]; TCHAR lfn[_MAX_LFN+1];
@ -176,8 +194,7 @@ void onSdManagerMenu(const char * result)
} }
else if (result == STR_FLASH_RECEIVER_OTA) { else if (result == STR_FLASH_RECEIVER_OTA) {
getSelectionFullPath(lfn); getSelectionFullPath(lfn);
moduleState[EXTERNAL_MODULE].startBind(&reusableBuffer.sdManager.otaInformation); moduleState[EXTERNAL_MODULE].startBind(&reusableBuffer.sdManager.otaInformation, onBindStateChanged);
} }
#endif #endif
#if defined(LUA) #if defined(LUA)
@ -188,6 +205,22 @@ void onSdManagerMenu(const char * result)
#endif #endif
} }
void onUpdateReceiverSelection(const char * result)
{
if (result != STR_EXIT) {
reusableBuffer.sdManager.otaInformation.selectedReceiverIndex = (result - reusableBuffer.sdManager.otaInformation.candidateReceiversNames[0]) / sizeof(reusableBuffer.sdManager.otaInformation.candidateReceiversNames[0]);
reusableBuffer.sdManager.otaInformation.step = BIND_INFO_REQUEST;
#if defined(SIMU)
reusableBuffer.sdManager.otaInformation.receiverInformation.modelID = 0x01;
onBindStateChanged();
#endif
}
else {
// the user pressed [Exit]
moduleState[EXTERNAL_MODULE].mode = MODULE_MODE_NORMAL;
}
}
void menuRadioSdManager(event_t _event) void menuRadioSdManager(event_t _event)
{ {
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
@ -434,6 +467,17 @@ void menuRadioSdManager(event_t _event)
} }
} }
if (moduleState[EXTERNAL_MODULE].mode == MODULE_MODE_BIND) {
if (reusableBuffer.sdManager.otaInformation.step == BIND_INIT && reusableBuffer.sdManager.otaInformation.candidateReceiversCount > 0) {
popupMenuItemsCount = min<uint8_t>(reusableBuffer.sdManager.otaInformation.candidateReceiversCount, PXX2_MAX_RECEIVERS_PER_MODULE);
for (uint8_t i=0; i<popupMenuItemsCount; i++) {
popupMenuItems[i] = reusableBuffer.sdManager.otaInformation.candidateReceiversNames[i];
}
popupMenuTitle = STR_PXX2_SELECT_RX;
POPUP_MENU_START(onUpdateReceiverSelection);
}
}
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
const char * ext = getFileExtension(reusableBuffer.sdManager.lines[index]); const char * ext = getFileExtension(reusableBuffer.sdManager.lines[index]);
if (ext && isExtensionMatching(ext, BITMAPS_EXT)) { if (ext && isExtensionMatching(ext, BITMAPS_EXT)) {

View file

@ -131,8 +131,11 @@ struct BindInformation {
uint8_t rxUid; uint8_t rxUid;
uint8_t lbtMode; uint8_t lbtMode;
uint8_t flexMode; uint8_t flexMode;
PXX2HardwareInformation receiverInformation;
}; };
typedef void (* ModuleCallback)();
PACK(struct ModuleState { PACK(struct ModuleState {
uint8_t protocol:4; uint8_t protocol:4;
uint8_t mode:4; uint8_t mode:4;
@ -144,9 +147,12 @@ PACK(struct ModuleState {
ModuleSettings * moduleSettings; ModuleSettings * moduleSettings;
BindInformation * bindInformation; BindInformation * bindInformation;
}; };
void startBind(BindInformation * destination) ModuleCallback callback;
void startBind(BindInformation * destination, ModuleCallback bindCallback = nullptr)
{ {
bindInformation = destination; bindInformation = destination;
callback = bindCallback;
mode = MODULE_MODE_BIND; mode = MODULE_MODE_BIND;
#if defined(SIMU) #if defined(SIMU)
bindInformation->candidateReceiversCount = 2; bindInformation->candidateReceiversCount = 2;

View file

@ -228,14 +228,20 @@ void Pxx2Pulses::setupBindFrame(uint8_t module)
if (get_tmr10ms() > destination->timeout) { if (get_tmr10ms() > destination->timeout) {
moduleState[module].mode = MODULE_MODE_NORMAL; moduleState[module].mode = MODULE_MODE_NORMAL;
destination->step = BIND_OK; destination->step = BIND_OK;
POPUP_INFORMATION(STR_BIND_OK); POPUP_INFORMATION(STR_BIND_OK); // TODO rather use the new callback
} }
return; return;
} }
addFrameType(PXX2_TYPE_C_MODULE, PXX2_TYPE_ID_BIND); addFrameType(PXX2_TYPE_C_MODULE, PXX2_TYPE_ID_BIND);
if (destination->step == BIND_OPTIONS_SELECTED) { if (destination->step == BIND_INFO_REQUEST) {
Pxx2Transport::addByte(0x02);
for (uint8_t i=0; i<PXX2_LEN_RX_NAME; i++) {
Pxx2Transport::addByte(destination->candidateReceiversNames[destination->selectedReceiverIndex][i]);
}
}
else if (destination->step == BIND_START) {
Pxx2Transport::addByte(0x01); Pxx2Transport::addByte(0x01);
for (uint8_t i=0; i<PXX2_LEN_RX_NAME; i++) { for (uint8_t i=0; i<PXX2_LEN_RX_NAME; i++) {
Pxx2Transport::addByte(destination->candidateReceiversNames[destination->selectedReceiverIndex][i]); Pxx2Transport::addByte(destination->candidateReceiversNames[destination->selectedReceiverIndex][i]);

View file

@ -115,25 +115,21 @@ enum PXX2Variant {
}; };
enum PXX2RegisterSteps { enum PXX2RegisterSteps {
REGISTER_START, REGISTER_INIT,
REGISTER_RX_NAME_RECEIVED, REGISTER_RX_NAME_RECEIVED,
REGISTER_RX_NAME_SELECTED, REGISTER_RX_NAME_SELECTED,
REGISTER_OK REGISTER_OK
}; };
enum PXX2BindSteps { enum PXX2BindSteps {
BIND_START, BIND_INIT,
BIND_RX_NAME_SELECTED, BIND_RX_NAME_SELECTED,
BIND_OPTIONS_SELECTED, BIND_INFO_REQUEST,
BIND_START,
BIND_WAIT, BIND_WAIT,
BIND_OK BIND_OK
}; };
enum PXX2ResetSteps {
RESET_START,
RESET_OK
};
enum PXX2ReceiverStatus { enum PXX2ReceiverStatus {
PXX2_HARDWARE_INFO, PXX2_HARDWARE_INFO,
PXX2_SETTINGS_READ, PXX2_SETTINGS_READ,
@ -220,8 +216,6 @@ class Pxx2Pulses: public PxxPulses<Pxx2Transport> {
void addFrameType(uint8_t type_c, uint8_t type_id) void addFrameType(uint8_t type_c, uint8_t type_id)
{ {
// TYPE_C + TYPE_ID // TYPE_C + TYPE_ID
// TODO optimization ? Pxx2Transport::addByte(0x26); // This one is CRC-ed on purpose
Pxx2Transport::addByte(type_c); Pxx2Transport::addByte(type_c);
Pxx2Transport::addByte(type_id); Pxx2Transport::addByte(type_id);
} }

View file

@ -109,7 +109,7 @@ void processRegisterFrame(uint8_t module, uint8_t * frame)
switch(frame[3]) { switch(frame[3]) {
case 0x00: case 0x00:
if (reusableBuffer.moduleSetup.pxx2.registerStep == REGISTER_START) { if (reusableBuffer.moduleSetup.pxx2.registerStep == REGISTER_INIT) {
// RX_NAME follows, we store it for the next step // RX_NAME follows, we store it for the next step
str2zchar(reusableBuffer.moduleSetup.pxx2.registerRxName, (const char *)&frame[4], PXX2_LEN_RX_NAME); str2zchar(reusableBuffer.moduleSetup.pxx2.registerRxName, (const char *)&frame[4], PXX2_LEN_RX_NAME);
reusableBuffer.moduleSetup.pxx2.registerLoopIndex = frame[12]; reusableBuffer.moduleSetup.pxx2.registerLoopIndex = frame[12];
@ -141,7 +141,7 @@ void processBindFrame(uint8_t module, uint8_t * frame)
switch(frame[3]) { switch(frame[3]) {
case 0x00: case 0x00:
if (destination->step == BIND_START) { if (destination->step == BIND_INIT) {
bool found = false; bool found = false;
for (uint8_t i=0; i<destination->candidateReceiversCount; i++) { for (uint8_t i=0; i<destination->candidateReceiversCount; i++) {
if (memcmp(destination->candidateReceiversNames[i], &frame[4], PXX2_LEN_RX_NAME) == 0) { if (memcmp(destination->candidateReceiversNames[i], &frame[4], PXX2_LEN_RX_NAME) == 0) {
@ -151,12 +151,15 @@ void processBindFrame(uint8_t module, uint8_t * frame)
} }
if (!found && destination->candidateReceiversCount < PXX2_MAX_RECEIVERS_PER_MODULE) { if (!found && destination->candidateReceiversCount < PXX2_MAX_RECEIVERS_PER_MODULE) {
memcpy(destination->candidateReceiversNames[destination->candidateReceiversCount++], &frame[4], PXX2_LEN_RX_NAME); memcpy(destination->candidateReceiversNames[destination->candidateReceiversCount++], &frame[4], PXX2_LEN_RX_NAME);
if (moduleState[module].callback) {
moduleState[module].callback();
}
} }
} }
break; break;
case 0x01: case 0x01:
if (destination->step == BIND_OPTIONS_SELECTED) { if (destination->step == BIND_START) {
if (memcmp(&destination->candidateReceiversNames[destination->selectedReceiverIndex], &frame[4], PXX2_LEN_RX_NAME) == 0) { if (memcmp(&destination->candidateReceiversNames[destination->selectedReceiverIndex], &frame[4], PXX2_LEN_RX_NAME) == 0) {
memcpy(g_model.moduleData[module].pxx2.receiverName[destination->rxUid], &frame[4], PXX2_LEN_RX_NAME); memcpy(g_model.moduleData[module].pxx2.receiverName[destination->rxUid], &frame[4], PXX2_LEN_RX_NAME);
storageDirty(EE_MODEL); storageDirty(EE_MODEL);
@ -165,6 +168,17 @@ void processBindFrame(uint8_t module, uint8_t * frame)
} }
} }
break; break;
case 0x02:
if (destination->step == BIND_INFO_REQUEST) {
if (memcmp(&destination->candidateReceiversNames[destination->selectedReceiverIndex], &frame[4], PXX2_LEN_RX_NAME) == 0) {
memcpy(&destination->receiverInformation, &frame[12], sizeof(PXX2HardwareInformation));
if (moduleState[module].callback) {
moduleState[module].callback();
}
}
}
break;
} }
} }