Skip to content

Commit

Permalink
Address review comment: Use new OswDate/OswTime in watchfaces
Browse files Browse the repository at this point in the history
Signed-off-by: simonmicro <[email protected]>
  • Loading branch information
simonmicro committed Jan 14, 2025
1 parent a6ba489 commit 9478a8e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 64 deletions.
4 changes: 2 additions & 2 deletions include/apps/watchfaces/OswAppWatchfaceDigital.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class OswAppWatchfaceDigital: public OswAppV2 {
static void refreshDateFormatCache();
static void drawSteps();
static void digitalWatch(short timeZone, uint8_t fontSize, uint8_t dateCoordY, uint8_t timeCoordY);
static void timeOutput(uint8_t hour, uint8_t minute, uint8_t second, bool showSecond = true);
static void dateOutput(uint16_t year, uint8_t month, uint8_t day);
static void timeOutput(const OswTime& oswTime, bool showSecond = true);
static void dateOutput(const OswDate& oswDate);
static void displayWeekDay3(const char* weekday);

private:
Expand Down
10 changes: 2 additions & 8 deletions include/apps/watchfaces/OswAppWatchfaceFitnessAnalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,15 @@ class OswAppWatchfaceFitnessAnalog : public OswAppV2 {

static uint32_t calculateDistance(uint32_t steps);

void timeDisplay(OswHal* hal, uint32_t hour, uint32_t minute, uint32_t second);
void timeDisplay(OswHal* hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon);
void dateDisplay(OswHal* hal, uint32_t hour, uint32_t minute, uint32_t second, bool afterNoon);

void test();

~OswAppWatchfaceFitnessAnalog() {}

private:
time_t lastTime = 0;
unsigned screen = 0;

void showFitnessTracking(OswHal* hal);
void drawWatchFace(OswHal* hal, uint8_t hour, uint8_t minute, uint8_t second, bool afterNoon);
void drawDateFace(OswHal* hal, uint8_t hour, uint8_t minute, uint8_t second, bool afterNoon);
void drawWatchFace(OswHal* hal, const OswTime& oswTime);
void drawDateFace(OswHal* hal, const OswDate& oswDate, const OswTime& oswTime);

#ifdef GIF_BG
OswAppGifPlayer* bgGif = nullptr;
Expand Down
38 changes: 19 additions & 19 deletions src/apps/watchfaces/OswAppWatchfaceDigital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,36 @@ void OswAppWatchfaceDigital::displayWeekDay3(const char* weekday) {
hal->gfx()->print(weekday3);
}

void OswAppWatchfaceDigital::dateOutput(uint16_t year, uint8_t month, uint8_t day) {
void OswAppWatchfaceDigital::dateOutput(const OswDate& oswDate) {
OswHal* hal = OswHal::getInstance();
switch (OswAppWatchfaceDigital::getDateFormat()) {
case 0:
hal->gfx()->printDecimal(month, 2);
hal->gfx()->printDecimal(oswDate.month, 2);
hal->gfx()->print("/");
hal->gfx()->printDecimal(day, 2);
hal->gfx()->printDecimal(oswDate.day, 2);
hal->gfx()->print("/");
hal->gfx()->print(year);
hal->gfx()->print(oswDate.year);
break;
case 1:
hal->gfx()->printDecimal(day, 2);
hal->gfx()->printDecimal(oswDate.day, 2);
hal->gfx()->print(".");
hal->gfx()->printDecimal(month, 2);
hal->gfx()->printDecimal(oswDate.month, 2);
hal->gfx()->print(".");
hal->gfx()->print(year);
hal->gfx()->print(oswDate.year);
break;
case 2:
hal->gfx()->print(year);
hal->gfx()->print(oswDate.year);
hal->gfx()->print(".");
hal->gfx()->printDecimal(month, 2);
hal->gfx()->printDecimal(oswDate.month, 2);
hal->gfx()->print("/");
hal->gfx()->printDecimal(day, 2);
hal->gfx()->printDecimal(oswDate.day, 2);
break;
case 3:
hal->gfx()->printDecimal(day, 2);
hal->gfx()->printDecimal(oswDate.day, 2);
hal->gfx()->print("/");
hal->gfx()->printDecimal(month, 2);
hal->gfx()->printDecimal(oswDate.month, 2);
hal->gfx()->print("/");
hal->gfx()->print(year);
hal->gfx()->print(oswDate.year);
break;
}
}
Expand Down Expand Up @@ -109,17 +109,17 @@ static void drawDate(time_t timeZone, uint8_t fontSize, uint8_t CoordY) {

// i really would want the date to be dynamic based on what's in the config, but the most efficient thing to do right
// now is simply three if statements covering the 3 common conditions.
OswAppWatchfaceDigital::dateOutput(oswDate.year, oswDate.month, oswDate.day);
OswAppWatchfaceDigital::dateOutput(oswDate);
}

void OswAppWatchfaceDigital::timeOutput(uint8_t hour, uint8_t minute, uint8_t second,bool showSecond) {
void OswAppWatchfaceDigital::timeOutput(const OswTime& oswTime, bool showSecond) {
OswHal* hal = OswHal::getInstance();
hal->gfx()->printDecimal(hour, 2);
hal->gfx()->printDecimal(oswTime.hour, 2);
hal->gfx()->print(":");
hal->gfx()->printDecimal(minute, 2);
hal->gfx()->printDecimal(oswTime.minute, 2);
if (showSecond) {
hal->gfx()->print(":");
hal->gfx()->printDecimal(second, 2);
hal->gfx()->printDecimal(oswTime.second, 2);
}
}

Expand All @@ -135,7 +135,7 @@ static void drawTime(time_t timeZone,uint8_t CoordY) {
hal->gfx()->setTextCursor(120 - hal->gfx()->getTextOfsetColumns(OswConfigAllKeys::timeFormat.get() ? 4 : 5.5),CoordY );

hal->getTime(timeZone, oswTime);
OswAppWatchfaceDigital::timeOutput(oswTime.hour, oswTime.minute, oswTime.second);
OswAppWatchfaceDigital::timeOutput(oswTime);
if (!OswConfigAllKeys::timeFormat.get()) {
hal->gfx()->print(" ");
if (oswTime.afterNoon) {
Expand Down
32 changes: 16 additions & 16 deletions src/apps/watchfaces/OswAppWatchfaceFitness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ uint32_t OswAppWatchfaceFitness::calculateKcalorie(uint32_t steps) {
// effects by marking fewer calories than they actually consumed.
}

void dateDisplay() {
static void dateDisplay(const OswDate& oswDate) {
OswHal* hal = OswHal::getInstance();

OswDate oswDate = { };
hal->getLocalDate(oswDate);

hal->gfx()->setTextSize(2);
hal->gfx()->setTextMiddleAligned();
hal->gfx()->setTextRightAligned();
Expand All @@ -46,23 +42,23 @@ void dateDisplay() {
hal->gfx()->setTextMiddleAligned();
hal->gfx()->setTextLeftAligned();
hal->gfx()->setTextCursor(DISP_W / 2 - 30 + hal->gfx()->getTextOfsetColumns(1), 150);
OswAppWatchfaceDigital::dateOutput(oswDate.year, oswDate.month, oswDate.day);
OswAppWatchfaceDigital::dateOutput(oswDate);
}

void timeDisplay(uint32_t hour, uint32_t minute, uint32_t second) {
static void timeDisplay(const OswTime& oswTime) {
OswHal* hal = OswHal::getInstance();
hal->gfx()->printDecimal(hour, 2);
hal->gfx()->printDecimal(oswTime.hour, 2);
hal->gfx()->print(":");
hal->gfx()->printDecimal(minute, 2);
hal->gfx()->printDecimal(oswTime.minute, 2);

hal->gfx()->setTextSize(1);
hal->gfx()->setTextMiddleAligned();
hal->gfx()->setTextLeftAligned();
hal->gfx()->setTextCursor(215, DISP_H / 2);
hal->gfx()->printDecimal(second,2);
hal->gfx()->printDecimal(oswTime.second,2);
}

void digitalWatchDisplay() {
static void digitalWatchDisplay(const OswTime& oswTime) {
char am[] = "AM";
char pm[] = "PM";
OswHal* hal = OswHal::getInstance();
Expand All @@ -71,10 +67,8 @@ void digitalWatchDisplay() {
hal->gfx()->setTextMiddleAligned();
hal->gfx()->setTextLeftAligned();
hal->gfx()->setTextCursor(DISP_W / 2 - 30, DISP_W / 2);
OswTime oswTime = { };
hal->getLocalTime(oswTime);

timeDisplay(oswTime.hour, oswTime.minute, oswTime.second);
timeDisplay(oswTime);
if (!OswConfigAllKeys::timeFormat.get()) {
hal->gfx()->setTextCursor(215, 130);
if (oswTime.afterNoon) {
Expand All @@ -84,6 +78,7 @@ void digitalWatchDisplay() {
}
}
}

void OswAppWatchfaceFitness::showFitnessTracking() {
OswHal* hal = OswHal::getInstance();

Expand Down Expand Up @@ -158,8 +153,13 @@ void OswAppWatchfaceFitness::onLoop() {
void OswAppWatchfaceFitness::onDraw() {
OswAppV2::onDraw();

dateDisplay();
digitalWatchDisplay();
OswDate oswDate = { };
OswTime oswTime = { };
hal->getLocalDate(oswDate);
hal->getLocalTime(oswTime);

dateDisplay(oswDate);
digitalWatchDisplay(oswTime);

#if OSW_PLATFORM_ENVIRONMENT_ACCELEROMETER == 1
showFitnessTracking();
Expand Down
33 changes: 16 additions & 17 deletions src/apps/watchfaces/OswAppWatchfaceFitnessAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,27 @@ void OswAppWatchfaceFitnessAnalog::showFitnessTracking(OswHal* hal) {
hal->gfx()->print(LANG_WATCHFACE_FITNESS_DISTANCE);
}

void OswAppWatchfaceFitnessAnalog::drawWatchFace(OswHal* hal, uint8_t hour, uint8_t minute, uint8_t second, bool afterNoon) {
void OswAppWatchfaceFitnessAnalog::drawWatchFace(OswHal* hal, const OswTime& oswTime) {
// Indices
hal->gfx()->drawMinuteTicks(CENTER_X, CENTER_Y, 116, 112, ui->getForegroundDimmedColor(), true);
hal->gfx()->drawHourTicks(CENTER_X, CENTER_Y, 117, 107, ui->getForegroundColor(), true);

// Hours
hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 0, 16, (int)(360.0f / 12.0f * (hour + minute / 60.0f)), 3, ui->getForegroundColor(), true, STRAIGHT_END);
hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 16, 60, (int)(360.0f / 12.0f * (hour + minute / 60.0f)), 7, ui->getForegroundColor(), true);
hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 0, 16, (int)(360.0f / 12.0f * (oswTime.hour + oswTime.minute / 60.0f)), 3, ui->getForegroundColor(), true, STRAIGHT_END);
hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 16, 60, (int)(360.0f / 12.0f * (oswTime.hour + oswTime.minute / 60.0f)), 7, ui->getForegroundColor(), true);

// Minutes
hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 0, 16, (int)(360.0f / 60.0f * (minute + second / 60.0f)), 3, ui->getForegroundColor(), true, STRAIGHT_END);
hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 16, 105, (int)(360.0f / 60.0f * (minute + second / 60.0f)), 7, ui->getForegroundColor(), true);
hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 0, 16, (int)(360.0f / 60.0f * (oswTime.minute + oswTime.second / 60.0f)), 3, ui->getForegroundColor(), true, STRAIGHT_END);
hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, 16, 105, (int)(360.0f / 60.0f * (oswTime.minute + oswTime.second / 60.0f)), 7, ui->getForegroundColor(), true);

#ifndef GIF_BG
// Seconds
hal->gfx()->fillCircleAA(CENTER_X, CENTER_Y, 6, ui->getDangerColor());
hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, -16, 110, 360 / 60 * second, 3, ui->getDangerColor(), true);
hal->gfx()->drawThickTick(CENTER_X, CENTER_Y, -16, 110, 360 / 60 * oswTime.second, 3, ui->getDangerColor(), true);
#endif
}

void OswAppWatchfaceFitnessAnalog::drawDateFace(OswHal* hal, uint8_t hour, uint8_t minute, uint8_t second, bool afterNoon) {
OswDate oswDate = { };
hal->getLocalDate(oswDate);

void OswAppWatchfaceFitnessAnalog::drawDateFace(OswHal* hal, const OswDate& oswDate, const OswTime& oswTime) {
hal->gfx()->setTextSize(2);
hal->gfx()->setTextRightAligned();
hal->gfx()->setTextCursor(205, 75);
Expand All @@ -127,26 +124,26 @@ void OswAppWatchfaceFitnessAnalog::drawDateFace(OswHal* hal, uint8_t hour, uint8
hal->gfx()->setTextSize(3);
hal->gfx()->setTextLeftAligned();
hal->gfx()->setTextCursor(CENTER_X - 70, 170);
OswAppWatchfaceDigital::dateOutput(oswDate.year, oswDate.month, oswDate.day);
OswAppWatchfaceDigital::dateOutput(oswDate);

hal->gfx()->setTextSize(4);
hal->gfx()->setTextLeftAligned();
hal->gfx()->setTextCursor(CENTER_X - 35, CENTER_Y);

hal->gfx()->printDecimal(hour, 2);
hal->gfx()->printDecimal(oswTime.hour, 2);
hal->gfx()->print(":");
hal->gfx()->printDecimal(minute, 2);
hal->gfx()->printDecimal(oswTime.minute, 2);

hal->gfx()->setTextSize(2);
hal->gfx()->setTextLeftAligned();
hal->gfx()->setTextCursor(215, CENTER_Y);
hal->gfx()->printDecimal(second,2);
hal->gfx()->printDecimal(oswTime.second,2);

if (!OswConfigAllKeys::timeFormat.get()) {
const char am[] = "AM";
const char pm[] = "PM";
hal->gfx()->setTextCursor(215, 130);
if (afterNoon) {
if (oswTime.afterNoon) {
hal->gfx()->print(pm);
} else {
hal->gfx()->print(am);
Expand Down Expand Up @@ -203,17 +200,19 @@ void OswAppWatchfaceFitnessAnalog::onDraw() {

OswHal* hal = OswHal::getInstance();

OswDate oswDate = { };
OswTime oswTime = { };
hal->getLocalDate(oswDate);
hal->getLocalTime(oswTime);

if (this->screen == 0) {
#if OSW_PLATFORM_ENVIRONMENT_ACCELEROMETER == 1
showFitnessTracking(hal);
#endif

drawWatchFace(hal, oswTime.hour, oswTime.minute, oswTime.second, oswTime.afterNoon);
drawWatchFace(hal, oswTime);
} else if (this->screen == 1) {
drawDateFace(hal, oswTime.hour, oswTime.minute, oswTime.second, oswTime.afterNoon);
drawDateFace(hal, oswDate, oswTime);

static int wait_time = 1;
if (wait_time >= 0)
Expand Down
4 changes: 2 additions & 2 deletions src/apps/watchfaces/OswAppWatchfaceMix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void OswAppWatchfaceMix::dateDisplay() {
hal->gfx()->setTextLeftAligned();
hal->gfx()->setTextCursor(DISP_W / 2 - OFF_SET_DATE_DIGITAL_WATCH_X_COORD, 90);

OswAppWatchfaceDigital::dateOutput(oswDate.year, oswDate.month, oswDate.day);
OswAppWatchfaceDigital::dateOutput(oswDate);
}

void OswAppWatchfaceMix::digitalWatchDisplay() {
Expand All @@ -86,7 +86,7 @@ void OswAppWatchfaceMix::digitalWatchDisplay() {

OswTime oswTime = { };
hal->getLocalTime(oswTime);
OswAppWatchfaceDigital::timeOutput(oswTime.hour, oswTime.minute, oswTime.second, false);
OswAppWatchfaceDigital::timeOutput(oswTime, false);
if (!OswConfigAllKeys::timeFormat.get()) {
hal->gfx()->setTextSize(1);
hal->gfx()->setTextMiddleAligned();
Expand Down

0 comments on commit 9478a8e

Please sign in to comment.