Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Jan 16, 2025
1 parent 98fbc8c commit bad1b96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
21 changes: 15 additions & 6 deletions VortexEngine/src/Menus/MenuList/EditorConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,20 @@ bool EditorConnection::backupDuoModes()
// done
return true;
}
// read or just use defaults?
if (!m_backupModes || !UPDI::readMode(m_backupModeNum, m_duoModeBackups[m_backupModeNum])) {
// if not backing up, or backup failed, then store the default mode data in the backup
// because we will always write out the backups after flashing
m_duoModeBackups[m_backupModeNum].init(duo_default_mode_sizes[m_backupModeNum], duo_default_modes[m_backupModeNum]);
// may use the defaults if backing up fails, default is whether backup is enabled
bool useDefault = !m_backupModes;
if (m_backupModes) {
ByteStream &cur = m_modeBackups[m_backupModeNum];
// if the mode cannot be loaded, or if it's CRC is bad then just use the default
if (!UPDI::readMode(m_backupModeNum, cur) || !cur.checkCRC() || !cur.size()) {
useDefault = true;
}
}
if (useDefault) {
// if not backing up, or backup failed, then store the default mode data in
// the backup because we will always write out the backups after flashing
m_modeBackups[m_backupModeNum].init(duo_default_sizes[m_backupModeNum],
duo_default_modes[m_backupModeNum]);
}
// go to next mode
m_backupModeNum++;
Expand All @@ -601,7 +610,7 @@ bool EditorConnection::restoreDuoModes()
return true;
}
// each pass write out the backups, these may be the defaults
UPDI::writeMode(m_backupModeNum, m_duoModeBackups[m_backupModeNum]);
UPDI::writeMode(m_backupModeNum, m_modeBackups[m_backupModeNum]);
// go to next mode
m_backupModeNum++;
return false;
Expand Down
2 changes: 1 addition & 1 deletion VortexEngine/src/Menus/MenuList/EditorConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class EditorConnection : public Menu
// whether to backup duo modes on firmware update
bool m_backupModes;
// backups of duo modes when flashing firmware
ByteStream m_duoModeBackups[9];
ByteStream m_modeBackups[9];
// counter for reading/writing modes during firmware flash
uint8_t m_backupModeNum;
};
Expand Down
9 changes: 3 additions & 6 deletions VortexEngine/src/UPDI/updi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ bool UPDI::readHeader(ByteStream &header)
if (!header.init(DUO_HEADER_SIZE)) {
return false;
}
Leds::holdAll(RGB_PURPLE);
if (!enterProgrammingMode()) {
return false;
}
Leds::holdAll(RGB_YELLOW);
uint8_t *ptr = (uint8_t *)header.rawData();
uint16_t addr = DUO_EEPROM_BASE;
stptr_p((const uint8_t *)&addr, 2);
Expand All @@ -119,7 +117,6 @@ bool UPDI::readHeader(ByteStream &header)
if (!size) {
return false;
}
Leds::holdAll(RGB_BLUE);
// more than 30 is old old duo where header is combined with save
if (size > 30) {
return readHeaderLegacy2(header);
Expand All @@ -128,7 +125,6 @@ bool UPDI::readHeader(ByteStream &header)
if (size < 6) {
return readHeaderLegacy1(header);
}
Leds::holdAll(RGB_GREEN0);
// modern duo header is 27 total and separate from modes
stptr_p((const uint8_t *)&addr, 2);
for (uint16_t i = 0; i < header.rawSize(); ++i) {
Expand Down Expand Up @@ -759,8 +755,9 @@ bool UPDI::enterProgrammingMode()
uint8_t status = ldcs(ASI_Key_Status);
if (status != 0x10) {
ERROR_LOGF("Bad prog key status: 0x%02x", status);
sendBreak();
uint8_t status = ldcs(Status_B);
reset();
//sendBreak();
//uint8_t status = ldcs(Status_B);
continue;
}
reset();
Expand Down

0 comments on commit bad1b96

Please sign in to comment.