Skip to content

Commit

Permalink
Add exception catch code for std array
Browse files Browse the repository at this point in the history
  • Loading branch information
RuffaloLavoisier committed Oct 17, 2024
1 parent d644e50 commit 586b004
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
8 changes: 6 additions & 2 deletions src/apps/tools/OswAppStepStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ void OswAppStepStats::drawInfoPanel(OswUI* ui, uint32_t pos, uint32_t lastWeekDa
hal->gfx()->setTextCursor(DISP_W / 2, 170);
OswDate oswDate = { };
hal->getLocalDate(oswDate);
const char* weekday = hal->getWeekDay[oswDate.weekDay];
hal->gfx()->print(weekday);
try {
const char* weekday = hal->getWeekDay.at(oswDate.weekDay);
hal->gfx()->print(weekday);
} catch (const std::out_of_range& ignore) {
OSW_LOG_E("getWeekDay is out of range: ", ignore.what());
}
hal->gfx()->setTextCursor(DISP_W / 2, 190);
hal->gfx()->print(String(lastWeekData)); // lastweek(before 7 day)
hal->gfx()->setTextCursor(DISP_W / 2, 215);
Expand Down
9 changes: 6 additions & 3 deletions src/apps/watchfaces/OswAppWatchfaceDigital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,24 @@ void OswAppWatchfaceDigital::dateOutput(uint32_t yearInt, uint32_t monthInt, uin
}

static void drawDate(time_t timeZone, uint8_t fontSize, uint8_t CoordY) {
const char* weekday = nullptr;
OswDate oswDate = { };
OswHal* hal = OswHal::getInstance();

hal->getDate(timeZone, oswDate);

weekday = hal->getWeekDay[oswDate.weekDay];
// we want to output a value like "Wed, 05/02/2021"

hal->gfx()->setTextSize(fontSize);
hal->gfx()->setTextMiddleAligned();
hal->gfx()->setTextLeftAligned();
hal->gfx()->setTextCursor(120 - hal->gfx()->getTextOfsetColumns(6.9f), CoordY);

OswAppWatchfaceDigital::displayWeekDay3(weekday);
try {
const char* weekday = hal->getWeekDay.at(oswDate.weekDay);
OswAppWatchfaceDigital::displayWeekDay3(weekday);
} catch (const std::out_of_range& ignore) {
OSW_LOG_E("getWeekDay is out of range: ", ignore.what());
}

// The GFX library has an alignment bug, causing single letters to "float", therefore the workaround above is used to still utilize the correct string printing.
//hal->gfx()->print(weekday[0]);
Expand Down
10 changes: 6 additions & 4 deletions src/apps/watchfaces/OswAppWatchfaceFitness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ void dateDisplay() {

OswDate oswDate = { };
hal->getLocalDate(oswDate);
const char* weekday = hal->getWeekDay[oswDate.weekDay];


hal->gfx()->setTextSize(2);
hal->gfx()->setTextMiddleAligned();
hal->gfx()->setTextRightAligned();
hal->gfx()->setTextCursor(205, 90);

OswAppWatchfaceDigital::displayWeekDay3(weekday);
try {
const char* weekday = hal->getWeekDay.at(oswDate.weekDay);
OswAppWatchfaceDigital::displayWeekDay3(weekday);
} catch (const std::out_of_range& ignore) {
OSW_LOG_E("getWeekDay is out of range: ", ignore.what());
}

// Date
hal->gfx()->setTextSize(2);
Expand Down
8 changes: 6 additions & 2 deletions src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,16 @@ void OswAppWatchfaceFitnessAnalog::drawWatchFace(OswHal* hal, uint32_t hour, uin
void OswAppWatchfaceFitnessAnalog::drawDateFace(OswHal* hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon) {
OswDate oswDate = { };
hal->getLocalDate(oswDate);
const char* weekday = hal->getWeekDay[oswDate.weekDay];

hal->gfx()->setTextSize(2);
hal->gfx()->setTextRightAligned();
hal->gfx()->setTextCursor(205, 75);
OswAppWatchfaceDigital::displayWeekDay3(weekday);
try {
const char* weekday = hal->getWeekDay.at(oswDate.weekDay);
OswAppWatchfaceDigital::displayWeekDay3(weekday);
} catch (const std::out_of_range& ignore) {
OSW_LOG_E("getWeekDay is out of range: ", ignore.what());
}

hal->gfx()->setTextSize(3);
hal->gfx()->setTextLeftAligned();
Expand Down
9 changes: 6 additions & 3 deletions src/apps/watchfaces/OswAppWatchfaceMix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ void OswAppWatchfaceMix::dateDisplay() {

OswDate oswDate = { };
hal->getLocalDate(oswDate);
const char* weekday = hal->getWeekDay[oswDate.weekDay];

hal->gfx()->setTextSize(1);
hal->gfx()->setTextMiddleAligned();
hal->gfx()->setTextLeftAligned();
hal->gfx()->setTextCursor(DISP_W / 2 - OFF_SET_DATE_DIGITAL_WATCH_X_COORD, 75);

OswAppWatchfaceDigital::displayWeekDay3(weekday);
try {
const char* weekday = hal->getWeekDay.at(oswDate.weekDay);
OswAppWatchfaceDigital::displayWeekDay3(weekday);
} catch (const std::out_of_range& ignore) {
OSW_LOG_E("getWeekDay is out of range: ", ignore.what());
}

hal->gfx()->print(", ");

Expand Down
9 changes: 6 additions & 3 deletions src/apps/watchfaces/OswAppWatchfaceNumerals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ void OswAppWatchfaceNumerals::drawWatch() {
hal->gfx()->setTextColor(ui->getDangerColor());
hal->gfx()->setTextCursor(120, 85);
hal->gfx()->print(oswDate.day);

const char* weekday = hal->getWeekDay[oswDate.weekDay];
hal->gfx()->setTextCursor(120, 70);
OswAppWatchfaceDigital::displayWeekDay3(weekday);
try {
const char* weekday = hal->getWeekDay.at(oswDate.weekDay);
OswAppWatchfaceDigital::displayWeekDay3(weekday);
} catch (const std::out_of_range& ignore) {
OSW_LOG_E("getWeekDay is out of range: ", ignore.what());
}

#if OSW_PLATFORM_ENVIRONMENT_ACCELEROMETER == 1
uint32_t steps = hal->environment()->getStepsToday();
Expand Down

0 comments on commit 586b004

Please sign in to comment.