Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apps/widget: add widget piece for watchfaces and tools, other #412

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/apps/widget/OswAppWidgets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <osw_hal.h>
#include <osw_ui.h>

class OswAppWidget {
public:
#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);
#endif
};
3 changes: 2 additions & 1 deletion src/apps/watchfaces/OswAppWatchfaceDigital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "./apps/watchfaces/OswAppWatchface.h"
#include "./apps/watchfaces/OswAppWatchfaceDigital.h"
#include "./apps/widget/OswAppWidgets.h"
#include OSW_TARGET_PLATFORM_HEADER

uint8_t OswAppWatchfaceDigital::dateFormatCache = 42;
Expand Down Expand Up @@ -137,7 +138,7 @@ const char* OswAppWatchfaceDigital::getAppName() {
void OswAppWatchfaceDigital::drawSteps() {
#ifdef OSW_FEATURE_STATS_STEPS
uint8_t w = 8;
OswAppWatchface::drawStepHistory(OswUI::getInstance(), (DISP_W / 2) - w * 3.5f, 180, w, w * 4, OswConfigAllKeys::stepsPerDay.get());
OswAppWidget::drawStepHistory(OswUI::getInstance(), (DISP_W / 2) - w * 3.5f, 180, w, w * 4, OswConfigAllKeys::stepsPerDay.get());
#else
OswHal* hal = OswHal::getInstance();
uint32_t steps = hal->environment()->getStepsToday();
Expand Down
44 changes: 44 additions & 0 deletions src/apps/widget/OswAppWidgets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <gfx_util.h>
#include <osw_config.h>
#include <osw_config_keys.h>
#include <osw_hal.h>
#include "./apps/widget/OswAppWidgets.h"
#include OSW_TARGET_PLATFORM_HEADER

#ifdef OSW_FEATURE_STATS_STEPS
void OswAppWidget::drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint32_t max) {
OswHal* hal = OswHal::getInstance();
OswUI::getInstance()->resetTextColors();

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

for (uint8_t i = 0; i < 7; i++) {
uint32_t s = hal->environment()->getStepsOnDay(i);
uint16_t boxHeight = ((float)(s > max ? max : s) / max) * h;
boxHeight = boxHeight < 2 ? 0 : boxHeight;

// step bars
uint16_t c = (unsigned int) OswConfigAllKeys::stepsPerDay.get() <= s ? ui->getSuccessColor() : ui->getPrimaryColor();
hal->gfx()->fillFrame(x + i * w, y + (h - boxHeight), w, boxHeight, c);
// bar frames
uint16_t f = oswDate.weekDay == i ? ui->getForegroundColor() : ui->getForegroundDimmedColor();
hal->gfx()->drawRFrame(x + i * w, y, w, h, 2, f);

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

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

hal->gfx()->setTextCursor(DISP_W / 2, y + 1 + 8 + w * 4);
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
hal->gfx()->print(hal->environment()->getStepsTotal());
hal->gfx()->setTextColor(ui->getForegroundColor(), ui->getBackgroundColor()); // restore. font : WHITE / bg : BLACK
}
}
#endif
Loading