Skip to content

Commit

Permalink
Rename value and name
Browse files Browse the repository at this point in the history
  • Loading branch information
RuffaloLavoisier committed Sep 15, 2024
1 parent cb09eae commit a3c0dab
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 37 deletions.
12 changes: 5 additions & 7 deletions src/apps/tools/OswAppDistStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <osw_hal.h>
#include <osw_pins.h>

#define WEEK 7

void OswAppDistStats::drawChart() {
OswHal* hal = OswHal::getInstance();
uint8_t chartStickHeight = 55;
Expand All @@ -21,18 +19,18 @@ void OswAppDistStats::drawChart() {
uint32_t dayOfMonth = 0;
hal->getLocalDate(&dayOfMonth, &weekDay);

for (uint8_t index = 0; index < WEEK; index++) {
uint32_t weekDayDist = OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsOnDay(index));
for (uint8_t indexOfWeek = 0; indexOfWeek < 7; indexOfWeek++) {
uint32_t weekDayDist = OswAppWatchfaceFitness::calculateDistance(hal->environment()->getStepsOnDay(indexOfWeek));
uint16_t chartStickValue = ((float)(weekDayDist > goalValue ? goalValue : weekDayDist) / goalValue) * chartStickHeight;

uint16_t barColor = (unsigned int) OswConfigAllKeys::distPerDay.get() <= weekDayDist ? ui->getSuccessColor() : changeColor(ui->getSuccessColor(),2.85);

chartStickValue = chartStickValue < 2 ? 0 : chartStickValue;

if (index == cursorPos) {
hal->gfx()->drawThickTick(60 + index * interval, 147, 0, chartStickHeight, 0, 5, ui->getForegroundColor());
if (indexOfWeek == cursorPos) {
hal->gfx()->drawThickTick(60 + indexOfWeek * interval, 147, 0, chartStickHeight, 0, 5, ui->getForegroundColor());
}
hal->gfx()->drawThickTick(60 + index * interval, 147, 0, chartStickValue, 0, 3, barColor, true);
hal->gfx()->drawThickTick(60 + indexOfWeek * interval, 147, 0, chartStickValue, 0, 3, barColor, true);
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/apps/tools/OswAppStepStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <osw_hal.h>
#include <osw_pins.h>

#define WEEK 7

void OswAppStepStats::drawChart() {
OswHal* hal = OswHal::getInstance();
uint8_t chartStickHeight = 55;
Expand All @@ -20,18 +18,18 @@ void OswAppStepStats::drawChart() {
uint32_t dayOfMonth = 0;
hal->getLocalDate(&dayOfMonth, &weekDay);

for (uint8_t index = 0; index < WEEK; index++) {
unsigned int weekDayStep = hal->environment()->getStepsOnDay(index);
for (uint8_t indexOfWeek = 0; indexOfWeek < 7; indexOfWeek++) {
unsigned int weekDayStep = hal->environment()->getStepsOnDay(indexOfWeek);
unsigned short chartStickValue = ((float)(weekDayStep > goalValue ? goalValue : weekDayStep) / goalValue) * chartStickHeight;

uint16_t barColor = (unsigned int) OswConfigAllKeys::stepsPerDay.get() <= weekDayStep ? ui->getSuccessColor() : changeColor(ui->getSuccessColor(), 2.85);

chartStickValue = chartStickValue < 2 ? 0 : chartStickValue;

if (index == cursorPos) {
hal->gfx()->drawThickTick(60 + index * interval, 147, 0, chartStickHeight, 0, 5, ui->getForegroundColor());
if (indexOfWeek == cursorPos) {
hal->gfx()->drawThickTick(60 + indexOfWeek * interval, 147, 0, chartStickHeight, 0, 5, ui->getForegroundColor());
}
hal->gfx()->drawThickTick(60 + index * interval, 147, 0, chartStickValue, 0, 3, barColor, true);
hal->gfx()->drawThickTick(60 + indexOfWeek * interval, 147, 0, chartStickValue, 0, 3, barColor, true);
}
}

Expand Down
15 changes: 6 additions & 9 deletions src/apps/watchfaces/OswAppWatchface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#define CENTER_X (DISP_W / 2)
#define CENTER_Y (DISP_H / 2)

#define WEEK 7

const char* OswAppWatchface::getAppId() {
return OswAppWatchface::APP_ID;
}
Expand All @@ -32,19 +30,18 @@ void OswAppWatchface::drawStepHistory(OswUI* ui, uint8_t posX, uint8_t posY, uin
OswUI::getInstance()->resetTextColors();
uint32_t weekDay = 0;
uint32_t dayOfMonth = 0;
uint8_t index = 0;
hal->getLocalDate(&dayOfMonth, &weekDay);
for (index = 0; index < WEEK; index++) {
uint32_t stepsCountOnDay = hal->environment()->getStepsOnDay(index);
for (uint8_t indexOfWeek = 0; indexOfWeek < 7; indexOfWeek++) {
uint32_t stepsCountOnDay = hal->environment()->getStepsOnDay(indexOfWeek);
uint16_t boxHeight = ((float)(stepsCountOnDay > max ? max : stepsCountOnDay) / max) * height;
boxHeight = boxHeight < 2 ? 0 : boxHeight; // minumum value is 2

// step bars
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);
hal->gfx()->fillFrame(posX + indexOfWeek * width, posY + (height - boxHeight), width, boxHeight, stepsCountBoxColor);
// bar frames
uint16_t frameLineColor = weekDay == index ? ui->getForegroundColor() : ui->getForegroundDimmedColor();
hal->gfx()->drawRFrame(posX + index * width, posY, width, height, 2, frameLineColor); // 2 is cornerRoundness
uint16_t frameLineColor = weekDay == indexOfWeek ? ui->getForegroundColor() : ui->getForegroundDimmedColor();
hal->gfx()->drawRFrame(posX + indexOfWeek * width, posY, width, height, 2, frameLineColor); // 2 is cornerRoundness

// labels
hal->gfx()->setTextCenterAligned(); // horiz.
Expand All @@ -54,7 +51,7 @@ void OswAppWatchface::drawStepHistory(OswUI* ui, uint8_t posX, uint8_t posY, uin

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

hal->gfx()->setTextCursor(CENTER_X, 221);
hal->gfx()->setTextCursor(CENTER_X, posY + 9 + width * 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
Expand Down
26 changes: 12 additions & 14 deletions src/hal/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#define PREFS_STEPS_STATS "S"
#define PREFS_STEPS_ALL "A"

#define WEEK 7

void OswHal::Environment::updateProviders() {
// In case we come from deepsleep (or whenever the available devices change), we should first scan the current available devices for possible providers...
#if OSW_PLATFORM_ENVIRONMENT_TEMPERATURE == 1
Expand Down Expand Up @@ -113,8 +111,8 @@ void OswHal::Environment::setupStepStatistics() {
assert(res);
if(prefs.getBytes(PREFS_STEPS_STATS, &this->_stepsCache, sizeof(this->_stepsCache)) != sizeof(this->_stepsCache)) {
// Uoh, the steps history is not initialized -> fill it with zero and do it now!
for(size_t i = 0; i < WEEK; i++)
this->_stepsCache[i] = 0;
for(size_t indexOfWeek = 0; indexOfWeek < 7; indexOfWeek++)
this->_stepsCache[indexOfWeek] = 0;
res = prefs.putBytes(PREFS_STEPS_STATS, &this->_stepsCache, sizeof(this->_stepsCache)) == sizeof(this->_stepsCache);
assert(res);
} else {
Expand Down Expand Up @@ -154,8 +152,8 @@ void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatis
if(currDoW > 0)
for(uint32_t i = currDoW; 0 < i; i--)
this->_stepsCache[i - 1] = 0;
for(uint32_t i = this->_stepsLastDoW + 1; i < WEEK; i++)
this->_stepsCache[i] = 0;
for(uint32_t indexOfWeek = this->_stepsLastDoW + 1; indexOfWeek < 7; indexOfWeek++)
this->_stepsCache[indexOfWeek] = 0;
}
}

Expand All @@ -180,13 +178,13 @@ void OswHal::Environment::commitStepStatistics(const bool& alwaysPrintStepStatis
#ifndef NDEBUG
if(changedDoW or alwaysPrintStepStatistics) {
String stepHistoryDbgMsg = "Current step history (day " + String(currDoW) + ", today " + String(OswHal::getInstance()->environment()->getStepsToday()) + ", sum " + String(this->_stepsSum) + ") is: {";
for(size_t i = 0; i < WEEK; i++) {
if(i > 0)
for(size_t indexOfWeek = 0; indexOfWeek < 7; indexOfWeek++) {
if(indexOfWeek > 0)
stepHistoryDbgMsg += ", ";
if(i == currDoW)
if(indexOfWeek == currDoW)
stepHistoryDbgMsg += "[";
stepHistoryDbgMsg += this->_stepsCache[i];
if(i == currDoW)
stepHistoryDbgMsg += this->_stepsCache[indexOfWeek];
if(indexOfWeek == currDoW)
stepHistoryDbgMsg += "]";
}
stepHistoryDbgMsg += "}";
Expand Down Expand Up @@ -228,11 +226,11 @@ uint32_t OswHal::Environment::getStepsTotalWeek() {
uint32_t sum = 0;
uint32_t currDoW = 0;
OswHal::getInstance()->getLocalDate(nullptr, &currDoW);
for (uint8_t index = 0; index < WEEK; index++) {
if (index == currDoW) {
for (uint8_t indexOfWeek = 0; indexOfWeek < 7; indexOfWeek++) {
if (indexOfWeek == currDoW) {
sum = sum + this->getStepsToday();
}
sum = sum + this->_stepsCache[index];
sum = sum + this->_stepsCache[indexOfWeek];
}
return sum;
#else
Expand Down

0 comments on commit a3c0dab

Please sign in to comment.