Skip to content

Commit

Permalink
Initial FW updater code complete and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
sweetlilmre committed Mar 18, 2022
1 parent f6b3fb1 commit c5dc8bb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
1 change: 1 addition & 0 deletions auto_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@
print ("Unable to generate version header!", file=sys.stderr)
env.Exit(1)

print("Building for version: " + version + ", build: " + str(build_no))
4 changes: 3 additions & 1 deletion include/Lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ namespace TapuinoNext
const char S_UPDATE[] = "Update FW";

// Update related strings
const char S_UPDATE_UPDATING[] = "FW updating";
const char S_UPDATE_NOT_FOUND[] = "FW not found!";
const char S_UPDATE_TOO_SMALL[] = "FW too small!";
const char S_UPDATE_WRITTEN_OK[] = "FW write OK";
const char S_UPDATE_UNDERWRITE[] = "FW under write!";
const char S_UPDATE_WRITTEN[] = "FW written";
const char S_UPDATE_SUCCESS[] = "Update success!";
const char S_UPDATE_STARTED[] = "Update started!";
const char S_UPDATE_REBOOT[] = "Rebooting...!";
const char S_UPDATE_INCOMPLETE[] = "Upd incomplete!";
const char S_UPDATE_FAILED[] = "Update failed!";
const char S_NO_UPDATE_SPACE[] = "No FW space!";
const char S_UPDATE_NO_SPACE[] = "No FW space!";

// Option related strings
const char S_BTN_CLICK_TIME[] = "Btn Click Time";
Expand Down
1 change: 1 addition & 0 deletions include/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ namespace TapuinoNext
FileLoader* fileLoader;

void PerformUpdate();
void OnProgress(size_t progress, size_t size);
};
} // namespace TapuinoNext
6 changes: 3 additions & 3 deletions include/Version.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#ifndef FW_BUILD_NUMBER
#define FW_BUILD_NUMBER "13"
#define FW_BUILD_NUMBER "38"
#endif
#ifndef FW_VERSION
#define FW_VERSION "0.0.1-alpha+13"
#define FW_VERSION "0.0.1-alpha+38"
#endif
#ifndef FW_BUILD_TIME
#define FW_BUILD_TIME "2022-03-17 15:28:06.130329"
#define FW_BUILD_TIME "2022-03-18 15:12:16.635465"
#endif
39 changes: 28 additions & 11 deletions src/Updater.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include "Updater.h"
#include "Menu.h"
#include "Lang.h"
Expand All @@ -15,53 +16,67 @@ Updater::Updater(LCDUtils* lcdUtils, InputHandler* inputHandler, FileLoader* fil
this->fileLoader = fileLoader;
}

void Updater::OnProgress(size_t progress, size_t size)
{
float prog = ((float) progress / (float) size) * 100;
char buf[I2C_DISP_COLS + 1];
snprintf(buf, I2C_DISP_COLS + 1, "progress: %d%%", (int) prog);
lcdUtils->Status(buf);
}

// perform the actual update from a given stream
void Updater::PerformUpdate()
{
File updateFile;
if (ErrorCodes::OK != fileLoader->OpenFile("/update.bin", updateFile))
{
lcdUtils->Error(S_UPDATE_MENU, S_UPDATE_NOT_FOUND);
lcdUtils->Error(S_UPDATE_UPDATING, S_UPDATE_NOT_FOUND);
return;
}

Update.onProgress(std::bind(&Updater::OnProgress, this, std::placeholders::_1, std::placeholders::_2));

size_t updateSize = updateFile.size();
if (updateSize == 0)
{
lcdUtils->Error(S_UPDATE_MENU, S_UPDATE_TOO_SMALL);
lcdUtils->Error(S_UPDATE_UPDATING, S_UPDATE_TOO_SMALL);
}
else if (Update.begin(updateSize))
{
lcdUtils->Error(S_UPDATE_UPDATING, S_UPDATE_STARTED);
if (Update.writeStream(updateFile) == updateSize)
{
lcdUtils->Error(S_UPDATE_MENU, S_UPDATE_WRITTEN_OK);
lcdUtils->Error(S_UPDATE_UPDATING, S_UPDATE_WRITTEN_OK);
}
else
{
lcdUtils->Error(S_UPDATE_MENU, S_UPDATE_UNDERWRITE);
lcdUtils->Error(S_UPDATE_UPDATING, S_UPDATE_UNDERWRITE);
}
if (Update.end())
{
lcdUtils->Error(S_UPDATE_MENU, S_UPDATE_WRITTEN);
lcdUtils->Error(S_UPDATE_UPDATING, S_UPDATE_WRITTEN);
if (Update.isFinished())
{
lcdUtils->Error(S_UPDATE_MENU, S_UPDATE_SUCCESS);
lcdUtils->Error(S_UPDATE_MENU, S_UPDATE_REBOOT);
lcdUtils->Error(S_UPDATE_UPDATING, S_UPDATE_SUCCESS);
lcdUtils->Error(S_UPDATE_UPDATING, S_UPDATE_REBOOT);
delay(1000);
ESP.restart();
delay(1000);
}
else
{
lcdUtils->Error(S_UPDATE_MENU, S_UPDATE_INCOMPLETE);
lcdUtils->Error(S_UPDATE_UPDATING, S_UPDATE_INCOMPLETE);
}
}
else
{
lcdUtils->Error(S_UPDATE_MENU, S_UPDATE_FAILED);
lcdUtils->Error(S_UPDATE_UPDATING, S_UPDATE_FAILED);
Serial.println("Error Occurred. Error #: " + String(Update.getError()));
}
}
else
{
lcdUtils->Error(S_UPDATE_MENU, S_NO_UPDATE_SPACE);
lcdUtils->Error(S_UPDATE_UPDATING, S_UPDATE_NO_SPACE);
}
updateFile.close();
}
Expand All @@ -74,7 +89,7 @@ void Updater::OnAction()
{MenuEntryType::IndexEntry, S_EXIT, NULL},
{MenuEntryType::IndexEntry, S_UPDATE, NULL},
};
TheMenu inPlayMenu = {S_UPDATE_MENU, (MenuEntry*) inPlayEntries, 3, 0, NULL};
TheMenu inPlayMenu = {S_UPDATE, (MenuEntry*) inPlayEntries, 2, 0, NULL};

while (true)
{
Expand All @@ -88,6 +103,8 @@ void Updater::OnAction()
// Seek
case 1:
{
PerformUpdate();
return;
}
// Abort (-1)
default:
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1-alpha+13
0.0.1-alpha+38

0 comments on commit c5dc8bb

Please sign in to comment.