Skip to content

Commit

Permalink
Remove unused code and rename param
Browse files Browse the repository at this point in the history
  • Loading branch information
RuffaloLavoisier committed Sep 15, 2024
1 parent f1dd0c4 commit cb09eae
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion include/apps/watchfaces/OswAppWatchface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OswAppWatchface : public OswAppV2 {
void onButton(Button id, bool up, ButtonStateNames state) override;

#ifdef OSW_FEATURE_STATS_STEPS
static void drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint32_t max);
static void drawStepHistory(OswUI* ui, uint8_t posX, uint8_t posY, uint8_t width, uint8_t height, uint32_t max);
#endif
static void addButtonDefaults(std::array<ButtonStateNames, BTN_NUMBER>& knownButtonStates);
static bool onButtonDefaults(OswAppV2& app, Button id, bool up, ButtonStateNames state);
Expand Down
20 changes: 10 additions & 10 deletions src/apps/watchfaces/OswAppWatchface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const char* OswAppWatchface::getAppName() {
}

#ifdef OSW_FEATURE_STATS_STEPS
void OswAppWatchface::drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint32_t max) {
void OswAppWatchface::drawStepHistory(OswUI* ui, uint8_t posX, uint8_t posY, uint8_t width, uint8_t height, uint32_t max) {
OswHal* hal = OswHal::getInstance();
OswUI::getInstance()->resetTextColors();
uint32_t weekDay = 0;
Expand All @@ -36,25 +36,25 @@ void OswAppWatchface::drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w
hal->getLocalDate(&dayOfMonth, &weekDay);
for (index = 0; index < WEEK; index++) {
uint32_t stepsCountOnDay = hal->environment()->getStepsOnDay(index);
uint16_t boxHeight = ((float)(stepsCountOnDay > max ? max : stepsCountOnDay) / max) * h;
boxHeight = boxHeight < 2 ? 0 : boxHeight;
uint16_t boxHeight = ((float)(stepsCountOnDay > max ? max : stepsCountOnDay) / max) * height;
boxHeight = boxHeight < 2 ? 0 : boxHeight; // minumum value is 2

// step bars
uint16_t c = (unsigned int) OswConfigAllKeys::stepsPerDay.get() <= stepsCountOnDay ? ui->getSuccessColor() : ui->getPrimaryColor();
hal->gfx()->fillFrame(x + index * w, y + (h - boxHeight), w, boxHeight, c);
uint16_t stepsCountBoxColor = (unsigned int) OswConfigAllKeys::stepsPerDay.get() <= stepsCountOnDay ? ui->getSuccessColor() : ui->getPrimaryColor();
hal->gfx()->fillFrame(posX + index * width, posY + (height - boxHeight), width, boxHeight, stepsCountBoxColor);
// bar frames
uint16_t f = weekDay == index ? ui->getForegroundColor() : ui->getForegroundDimmedColor();
hal->gfx()->drawRFrame(x + index * w, y, w, h, 2, f);
uint16_t frameLineColor = weekDay == index ? ui->getForegroundColor() : ui->getForegroundDimmedColor();
hal->gfx()->drawRFrame(posX + index * width, posY, width, height, 2, frameLineColor); // 2 is cornerRoundness

// labels
hal->gfx()->setTextCenterAligned(); // horiz.
hal->gfx()->setTextBottomAligned();
hal->gfx()->setTextSize(1);
hal->gfx()->setTextCursor(CENTER_X, y - 1);
hal->gfx()->setTextCursor(CENTER_X, posY - 1);

hal->gfx()->print(hal->environment()->getStepsToday() + (OswConfigAllKeys::settingDisplayStepsGoal.get() ? String("/") + max:""));

hal->gfx()->setTextCursor(CENTER_X, y + 1 + 8 + w * 4);
hal->gfx()->setTextCursor(CENTER_X, 221);
hal->gfx()->setTextColor(ui->getForegroundColor()); // Let's make the background transparent.
// See : https://github.com/Open-Smartwatch/open-smartwatch-os/issues/194
// font : WHITE / bg : None
Expand All @@ -73,7 +73,7 @@ void OswAppWatchface::drawWatch() {
#if OSW_PLATFORM_ENVIRONMENT_ACCELEROMETER == 1
uint32_t steps = hal->environment()->getStepsToday();
uint32_t stepsTarget = OswConfigAllKeys::stepsPerDay.get();
hal->gfx()->drawArc(CENTER_X, CENTER_Y, 0, 360.0f * (float)(steps % stepsTarget) / (float)stepsTarget, 90, 93, 6,
hal->gfx()->drawArc(CENTER_X, CENTER_Y, 0, (float) (360.0f / stepsTarget * (steps % stepsTarget)), 90, 93, 6,
steps > stepsTarget ? ui->getSuccessColor() : ui->getInfoColor(), true);
#endif

Expand Down
7 changes: 3 additions & 4 deletions src/apps/watchfaces/OswAppWatchfaceDual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ void OswAppWatchfaceDual::drawProgressBar(OswUI* ui,uint8_t cx, uint8_t cy, uint
void OswAppWatchfaceDual::drawAnimSec() {
OswHal* hal = OswHal::getInstance();
uint8_t barWidth = 140;
uint32_t Hs, Ms, Ss = 0;
hal->getLocalTime(&Hs,&Ms,&Ss);
uint32_t onlySecond = Ss;
uint16_t barValue = ((float)onlySecond / 60) * barWidth;
uint32_t seconds = 0;
hal->getLocalTime(nullptr, nullptr, &seconds);
uint16_t barValue = ((float)seconds / 60) * barWidth;
barValue = barValue < 2 ? 0 : barValue;
uint8_t coordX = (DISP_W - barWidth) / 2;
uint8_t levelY = DISP_H / 2;
Expand Down
40 changes: 30 additions & 10 deletions src/hal/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,54 @@ void OswHal::updateTimeProvider() {
void OswHal::getUTCTime(uint32_t* hour, uint32_t* minute, uint32_t* second) {
RtcDateTime d = RtcDateTime();
d.InitWithUnix32Time(this->getUTCTime());
*hour = d.Hour();
*minute = d.Minute();
*second = d.Second();
if (hour != nullptr){
*hour = d.Hour();
}
if (minute != nullptr){
*minute = d.Minute();
}
if (second != nullptr){
*second = d.Second();
}
}

void OswHal::getTime(time_t& offset, uint32_t* hour, uint32_t* minute, uint32_t* second, bool* afterNoon) {
RtcDateTime d = RtcDateTime();
d.InitWithUnix32Time(this->getTime(offset));
if (!OswConfigAllKeys::timeFormat.get()) {
if (d.Hour() > 12) {
*hour = d.Hour() - 12;
if(hour != nullptr){
*hour = d.Hour() - 12;
}
if (afterNoon != nullptr) *afterNoon = true;
} else if (d.Hour() == 0) {
*hour = 12;
if(hour != nullptr){
*hour = 12;
}
if (afterNoon != nullptr) *afterNoon = false;
} else if (d.Hour() == 12) {
*hour = d.Hour();
if(hour != nullptr){
*hour = d.Hour();
}
if (afterNoon != nullptr) *afterNoon = true;
} else {
*hour = d.Hour();
if(hour != nullptr){
*hour = d.Hour();
}
if (afterNoon != nullptr) *afterNoon = false;
}
} else {
*hour = d.Hour();
if(hour != nullptr){
*hour = d.Hour();
}
if (afterNoon != nullptr) *afterNoon = false;
}
*minute = d.Minute();
*second = d.Second();
if (minute != nullptr){
*minute = d.Minute();
}
if (second != nullptr){
*second = d.Second();
}
}

/**
Expand Down

0 comments on commit cb09eae

Please sign in to comment.