Merge branch 'main' into wb/wadokei-merge
This commit is contained in:
@@ -357,6 +357,8 @@ void DfuService::DfuImage::Init(size_t chunkSize, size_t totalSize, uint16_t exp
|
||||
this->totalSize = totalSize;
|
||||
this->expectedCrc = expectedCrc;
|
||||
this->ready = true;
|
||||
totalWriteIndex = 0;
|
||||
bufferWriteIndex = 0;
|
||||
}
|
||||
|
||||
void DfuService::DfuImage::Append(uint8_t* data, size_t size) {
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#define min // workaround: nimble's min/max macros conflict with libstdc++
|
||||
#define max
|
||||
#include <host/ble_gap.h>
|
||||
#include <atomic>
|
||||
#undef max
|
||||
#undef min
|
||||
#include <atomic>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Controllers {
|
||||
|
||||
@@ -120,3 +120,7 @@ void MotionService::UnsubscribeNotification(uint16_t attributeHandle) {
|
||||
else if (attributeHandle == motionValuesHandle)
|
||||
motionValuesNoficationEnabled = false;
|
||||
}
|
||||
|
||||
bool MotionService::IsMotionNotificationSubscribed() const {
|
||||
return motionValuesNoficationEnabled;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace Pinetime {
|
||||
|
||||
void SubscribeNotification(uint16_t attributeHandle);
|
||||
void UnsubscribeNotification(uint16_t attributeHandle);
|
||||
bool IsMotionNotificationSubscribed() const;
|
||||
|
||||
private:
|
||||
NimbleController& nimble;
|
||||
|
||||
@@ -158,3 +158,16 @@ bool SimpleWeatherService::CurrentWeather::operator==(const SimpleWeatherService
|
||||
this->maxTemperature == other.maxTemperature && this->minTemperature == other.maxTemperature &&
|
||||
std::strcmp(this->location.data(), other.location.data()) == 0;
|
||||
}
|
||||
|
||||
bool SimpleWeatherService::Forecast::Day::operator==(const SimpleWeatherService::Forecast::Day& other) const {
|
||||
return this->iconId == other.iconId && this->maxTemperature == other.maxTemperature && this->minTemperature == other.maxTemperature;
|
||||
}
|
||||
|
||||
bool SimpleWeatherService::Forecast::operator==(const SimpleWeatherService::Forecast& other) const {
|
||||
for (int i = 0; i < this->nbDays; i++) {
|
||||
if (this->days[i] != other.days[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return this->timestamp == other.timestamp && this->nbDays == other.nbDays;
|
||||
}
|
||||
|
||||
@@ -96,9 +96,13 @@ namespace Pinetime {
|
||||
int16_t minTemperature;
|
||||
int16_t maxTemperature;
|
||||
Icons iconId;
|
||||
|
||||
bool operator==(const Day& other) const;
|
||||
};
|
||||
|
||||
std::array<Day, MaxNbForecastDays> days;
|
||||
|
||||
bool operator==(const Forecast& other) const;
|
||||
};
|
||||
|
||||
std::optional<CurrentWeather> Current() const;
|
||||
|
||||
@@ -115,8 +115,8 @@ const char* DateTime::MonthShortToStringLow(Months month) {
|
||||
return MonthsStringLow[static_cast<uint8_t>(month)];
|
||||
}
|
||||
|
||||
const char* DateTime::DayOfWeekShortToStringLow() const {
|
||||
return DaysStringShortLow[static_cast<uint8_t>(DayOfWeek())];
|
||||
const char* DateTime::DayOfWeekShortToStringLow(Days day) {
|
||||
return DaysStringShortLow[static_cast<uint8_t>(day)];
|
||||
}
|
||||
|
||||
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
|
||||
@@ -129,7 +129,7 @@ std::string DateTime::FormattedTime() {
|
||||
auto hour = Hours();
|
||||
auto minute = Minutes();
|
||||
// Return time as a string in 12- or 24-hour format
|
||||
char buff[9];
|
||||
char buff[11];
|
||||
if (settingsController.GetClockType() == ClockType::H12) {
|
||||
uint8_t hour12;
|
||||
const char* amPmStr;
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace Pinetime {
|
||||
const char* MonthShortToString() const;
|
||||
const char* DayOfWeekShortToString() const;
|
||||
static const char* MonthShortToStringLow(Months month);
|
||||
const char* DayOfWeekShortToStringLow() const;
|
||||
static const char* DayOfWeekShortToStringLow(Days day);
|
||||
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const {
|
||||
return currentDateTime;
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
#include "components/gfx/Gfx.h"
|
||||
#include "drivers/St7789.h"
|
||||
using namespace Pinetime::Components;
|
||||
|
||||
Gfx::Gfx(Pinetime::Drivers::St7789& lcd) : lcd {lcd} {
|
||||
}
|
||||
|
||||
void Gfx::Init() {
|
||||
}
|
||||
|
||||
void Gfx::ClearScreen() {
|
||||
SetBackgroundColor(0x0000);
|
||||
|
||||
state.remainingIterations = 240 + 1;
|
||||
state.currentIteration = 0;
|
||||
state.busy = true;
|
||||
state.action = Action::FillRectangle;
|
||||
state.taskToNotify = xTaskGetCurrentTaskHandle();
|
||||
|
||||
lcd.DrawBuffer(0, 0, width, height, reinterpret_cast<const uint8_t*>(buffer), width * 2);
|
||||
WaitTransferFinished();
|
||||
}
|
||||
|
||||
void Gfx::FillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t color) {
|
||||
SetBackgroundColor(color);
|
||||
|
||||
state.remainingIterations = h;
|
||||
state.currentIteration = 0;
|
||||
state.busy = true;
|
||||
state.action = Action::FillRectangle;
|
||||
state.color = color;
|
||||
state.taskToNotify = xTaskGetCurrentTaskHandle();
|
||||
|
||||
lcd.DrawBuffer(x, y, w, h, reinterpret_cast<const uint8_t*>(buffer), width * 2);
|
||||
|
||||
WaitTransferFinished();
|
||||
}
|
||||
|
||||
void Gfx::FillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t* b) {
|
||||
state.remainingIterations = h;
|
||||
state.currentIteration = 0;
|
||||
state.busy = true;
|
||||
state.action = Action::FillRectangle;
|
||||
state.color = 0x00;
|
||||
state.taskToNotify = xTaskGetCurrentTaskHandle();
|
||||
|
||||
lcd.DrawBuffer(x, y, w, h, reinterpret_cast<const uint8_t*>(b), width * 2);
|
||||
|
||||
WaitTransferFinished();
|
||||
}
|
||||
|
||||
void Gfx::DrawString(uint8_t x, uint8_t y, uint16_t color, const char* text, const FONT_INFO* p_font, bool wrap) {
|
||||
if (y > (height - p_font->height)) {
|
||||
// Not enough space to write even single char.
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t current_x = x;
|
||||
uint8_t current_y = y;
|
||||
|
||||
for (size_t i = 0; text[i] != '\0'; i++) {
|
||||
if (text[i] == '\n') {
|
||||
current_x = x;
|
||||
current_y += p_font->height + p_font->height / 10;
|
||||
} else {
|
||||
DrawChar(p_font, (uint8_t) text[i], ¤t_x, current_y, color);
|
||||
}
|
||||
|
||||
uint8_t char_idx = text[i] - p_font->startChar;
|
||||
uint16_t char_width = text[i] == ' ' ? (p_font->height / 2) : p_font->charInfo[char_idx].widthBits;
|
||||
|
||||
if (current_x > (width - char_width)) {
|
||||
if (wrap) {
|
||||
current_x = x;
|
||||
current_y += p_font->height + p_font->height / 10;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if (y > (height - p_font->height)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Gfx::DrawChar(const FONT_INFO* font, uint8_t c, uint8_t* x, uint8_t y, uint16_t color) {
|
||||
uint8_t char_idx = c - font->startChar;
|
||||
uint16_t bytes_in_line = CEIL_DIV(font->charInfo[char_idx].widthBits, 8);
|
||||
uint16_t bg = 0x0000;
|
||||
|
||||
if (c == ' ') {
|
||||
*x += font->height / 2;
|
||||
return;
|
||||
}
|
||||
|
||||
// Build first line
|
||||
for (uint16_t j = 0; j < bytes_in_line; j++) {
|
||||
for (uint8_t k = 0; k < 8; k++) {
|
||||
if ((1 << (7 - k)) & font->data[font->charInfo[char_idx].offset + j]) {
|
||||
buffer[(j * 8) + k] = color;
|
||||
} else {
|
||||
buffer[(j * 8) + k] = bg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.remainingIterations = font->height + 0;
|
||||
state.currentIteration = 0;
|
||||
state.busy = true;
|
||||
state.action = Action::DrawChar;
|
||||
state.font = const_cast<FONT_INFO*>(font);
|
||||
state.character = c;
|
||||
state.color = color;
|
||||
state.taskToNotify = xTaskGetCurrentTaskHandle();
|
||||
|
||||
lcd.DrawBuffer(*x, y, bytes_in_line * 8, font->height, reinterpret_cast<const uint8_t*>(&buffer), bytes_in_line * 8 * 2);
|
||||
WaitTransferFinished();
|
||||
|
||||
*x += font->charInfo[char_idx].widthBits + font->spacePixels;
|
||||
}
|
||||
|
||||
void Gfx::pixel_draw(uint8_t x, uint8_t y, uint16_t color) {
|
||||
lcd.DrawPixel(x, y, color);
|
||||
}
|
||||
|
||||
void Gfx::Sleep() {
|
||||
lcd.Sleep();
|
||||
}
|
||||
|
||||
void Gfx::Wakeup() {
|
||||
lcd.Wakeup();
|
||||
}
|
||||
|
||||
void Gfx::SetBackgroundColor(uint16_t color) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
buffer[i] = color;
|
||||
}
|
||||
}
|
||||
|
||||
bool Gfx::GetNextBuffer(uint8_t** data, size_t& size) {
|
||||
if (!state.busy)
|
||||
return false;
|
||||
state.remainingIterations = state.remainingIterations - 1;
|
||||
if (state.remainingIterations == 0) {
|
||||
state.busy = false;
|
||||
NotifyEndOfTransfer(state.taskToNotify);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state.action == Action::FillRectangle) {
|
||||
*data = reinterpret_cast<uint8_t*>(buffer);
|
||||
size = width * 2;
|
||||
} else if (state.action == Action::DrawChar) {
|
||||
uint16_t bg = 0x0000;
|
||||
uint8_t char_idx = state.character - state.font->startChar;
|
||||
uint16_t bytes_in_line = CEIL_DIV(state.font->charInfo[char_idx].widthBits, 8);
|
||||
|
||||
for (uint16_t j = 0; j < bytes_in_line; j++) {
|
||||
for (uint8_t k = 0; k < 8; k++) {
|
||||
if ((1 << (7 - k)) & state.font->data[state.font->charInfo[char_idx].offset + ((state.currentIteration + 1) * bytes_in_line) + j]) {
|
||||
buffer[(j * 8) + k] = state.color;
|
||||
} else {
|
||||
buffer[(j * 8) + k] = bg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*data = reinterpret_cast<uint8_t*>(buffer);
|
||||
size = bytes_in_line * 8 * 2;
|
||||
}
|
||||
|
||||
state.currentIteration = state.currentIteration + 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Gfx::NotifyEndOfTransfer(TaskHandle_t task) {
|
||||
if (task != nullptr) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
vTaskNotifyGiveFromISR(task, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
|
||||
void Gfx::WaitTransferFinished() const {
|
||||
ulTaskNotifyTake(pdTRUE, 500);
|
||||
}
|
||||
|
||||
void Gfx::SetScrollArea(uint16_t topFixedLines, uint16_t scrollLines, uint16_t bottomFixedLines) {
|
||||
lcd.VerticalScrollDefinition(topFixedLines, scrollLines, bottomFixedLines);
|
||||
}
|
||||
|
||||
void Gfx::SetScrollStartLine(uint16_t line) {
|
||||
lcd.VerticalScrollStartAddress(line);
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
#pragma once
|
||||
#include <FreeRTOS.h>
|
||||
#include <nrf_font.h>
|
||||
#include <task.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "drivers/BufferProvider.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Drivers {
|
||||
class St7789;
|
||||
}
|
||||
|
||||
namespace Components {
|
||||
class Gfx : public Pinetime::Drivers::BufferProvider {
|
||||
public:
|
||||
explicit Gfx(Drivers::St7789& lcd);
|
||||
void Init();
|
||||
void ClearScreen();
|
||||
void DrawString(uint8_t x, uint8_t y, uint16_t color, const char* text, const FONT_INFO* p_font, bool wrap);
|
||||
void DrawChar(const FONT_INFO* font, uint8_t c, uint8_t* x, uint8_t y, uint16_t color);
|
||||
void FillRectangle(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint16_t color);
|
||||
void FillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t* b);
|
||||
void SetScrollArea(uint16_t topFixedLines, uint16_t scrollLines, uint16_t bottomFixedLines);
|
||||
void SetScrollStartLine(uint16_t line);
|
||||
|
||||
void Sleep();
|
||||
void Wakeup();
|
||||
bool GetNextBuffer(uint8_t** buffer, size_t& size) override;
|
||||
void pixel_draw(uint8_t x, uint8_t y, uint16_t color);
|
||||
|
||||
private:
|
||||
static constexpr uint8_t width = 240;
|
||||
static constexpr uint8_t height = 240;
|
||||
|
||||
enum class Action { None, FillRectangle, DrawChar };
|
||||
|
||||
struct State {
|
||||
State() : busy {false}, action {Action::None}, remainingIterations {0}, currentIteration {0} {
|
||||
}
|
||||
|
||||
volatile bool busy;
|
||||
volatile Action action;
|
||||
volatile uint16_t remainingIterations;
|
||||
volatile uint16_t currentIteration;
|
||||
volatile FONT_INFO* font;
|
||||
volatile uint16_t color;
|
||||
volatile uint8_t character;
|
||||
volatile TaskHandle_t taskToNotify = nullptr;
|
||||
};
|
||||
|
||||
volatile State state;
|
||||
|
||||
uint16_t buffer[width]; // 1 line buffer
|
||||
Drivers::St7789& lcd;
|
||||
|
||||
void SetBackgroundColor(uint16_t color);
|
||||
void WaitTransferFinished() const;
|
||||
void NotifyEndOfTransfer(TaskHandle_t task);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -40,15 +40,15 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
|
||||
service->OnNewStepCountValue(nbSteps);
|
||||
}
|
||||
|
||||
if (service != nullptr && (this->x != x || yHistory[0] != y || zHistory[0] != z)) {
|
||||
if (service != nullptr && (xHistory[0] != x || yHistory[0] != y || zHistory[0] != z)) {
|
||||
service->OnNewMotionValues(x, y, z);
|
||||
}
|
||||
|
||||
lastTime = time;
|
||||
time = xTaskGetTickCount();
|
||||
|
||||
lastX = this->x;
|
||||
this->x = x;
|
||||
xHistory++;
|
||||
xHistory[0] = x;
|
||||
yHistory++;
|
||||
yHistory[0] = y;
|
||||
zHistory++;
|
||||
@@ -67,20 +67,26 @@ MotionController::AccelStats MotionController::GetAccelStats() const {
|
||||
AccelStats stats;
|
||||
|
||||
for (uint8_t i = 0; i < AccelStats::numHistory; i++) {
|
||||
stats.xMean += xHistory[histSize - i];
|
||||
stats.yMean += yHistory[histSize - i];
|
||||
stats.zMean += zHistory[histSize - i];
|
||||
stats.prevXMean += xHistory[1 + i];
|
||||
stats.prevYMean += yHistory[1 + i];
|
||||
stats.prevZMean += zHistory[1 + i];
|
||||
}
|
||||
stats.xMean /= AccelStats::numHistory;
|
||||
stats.yMean /= AccelStats::numHistory;
|
||||
stats.zMean /= AccelStats::numHistory;
|
||||
stats.prevXMean /= AccelStats::numHistory;
|
||||
stats.prevYMean /= AccelStats::numHistory;
|
||||
stats.prevZMean /= AccelStats::numHistory;
|
||||
|
||||
for (uint8_t i = 0; i < AccelStats::numHistory; i++) {
|
||||
stats.xVariance += (xHistory[histSize - i] - stats.xMean) * (xHistory[histSize - i] - stats.xMean);
|
||||
stats.yVariance += (yHistory[histSize - i] - stats.yMean) * (yHistory[histSize - i] - stats.yMean);
|
||||
stats.zVariance += (zHistory[histSize - i] - stats.zMean) * (zHistory[histSize - i] - stats.zMean);
|
||||
}
|
||||
stats.xVariance /= AccelStats::numHistory;
|
||||
stats.yVariance /= AccelStats::numHistory;
|
||||
stats.zVariance /= AccelStats::numHistory;
|
||||
|
||||
@@ -93,7 +99,7 @@ bool MotionController::ShouldRaiseWake() const {
|
||||
constexpr int16_t yThresh = -64;
|
||||
constexpr int16_t rollDegreesThresh = -45;
|
||||
|
||||
if (x < -xThresh || x > xThresh) {
|
||||
if (std::abs(stats.xMean) > xThresh) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -107,8 +113,9 @@ bool MotionController::ShouldRaiseWake() const {
|
||||
|
||||
bool MotionController::ShouldShakeWake(uint16_t thresh) {
|
||||
/* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */
|
||||
int32_t speed =
|
||||
std::abs(zHistory[0] - zHistory[histSize - 1] + (yHistory[0] - yHistory[histSize - 1]) / 2 + (x - lastX) / 4) * 100 / (time - lastTime);
|
||||
int32_t speed = std::abs(zHistory[0] - zHistory[histSize - 1] + (yHistory[0] - yHistory[histSize - 1]) / 2 +
|
||||
(xHistory[0] - xHistory[histSize - 1]) / 4) *
|
||||
100 / (time - lastTime);
|
||||
// (.2 * speed) + ((1 - .2) * accumulatedSpeed);
|
||||
accumulatedSpeed = speed / 5 + accumulatedSpeed * 4 / 5;
|
||||
|
||||
@@ -116,6 +123,11 @@ bool MotionController::ShouldShakeWake(uint16_t thresh) {
|
||||
}
|
||||
|
||||
bool MotionController::ShouldLowerSleep() const {
|
||||
if ((stats.xMean > 887 && DegreesRolled(stats.xMean, stats.zMean, stats.prevXMean, stats.prevZMean) > 30) ||
|
||||
(stats.xMean < -887 && DegreesRolled(stats.xMean, stats.zMean, stats.prevXMean, stats.prevZMean) < -30)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (stats.yMean < 724 || DegreesRolled(stats.yMean, stats.zMean, stats.prevYMean, stats.prevZMean) < 30) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Pinetime {
|
||||
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
|
||||
|
||||
int16_t X() const {
|
||||
return x;
|
||||
return xHistory[0];
|
||||
}
|
||||
|
||||
int16_t Y() const {
|
||||
@@ -62,6 +62,10 @@ namespace Pinetime {
|
||||
this->service = service;
|
||||
}
|
||||
|
||||
Pinetime::Controllers::MotionService* GetService() const {
|
||||
return service;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t nbSteps = 0;
|
||||
uint32_t currentTripSteps = 0;
|
||||
@@ -72,11 +76,14 @@ namespace Pinetime {
|
||||
struct AccelStats {
|
||||
static constexpr uint8_t numHistory = 2;
|
||||
|
||||
int16_t xMean = 0;
|
||||
int16_t yMean = 0;
|
||||
int16_t zMean = 0;
|
||||
int16_t prevXMean = 0;
|
||||
int16_t prevYMean = 0;
|
||||
int16_t prevZMean = 0;
|
||||
|
||||
uint32_t xVariance = 0;
|
||||
uint32_t yVariance = 0;
|
||||
uint32_t zVariance = 0;
|
||||
};
|
||||
@@ -85,9 +92,8 @@ namespace Pinetime {
|
||||
|
||||
AccelStats stats = {};
|
||||
|
||||
int16_t lastX = 0;
|
||||
int16_t x = 0;
|
||||
static constexpr uint8_t histSize = 8;
|
||||
Utility::CircularBuffer<int16_t, histSize> xHistory = {};
|
||||
Utility::CircularBuffer<int16_t, histSize> yHistory = {};
|
||||
Utility::CircularBuffer<int16_t, histSize> zHistory = {};
|
||||
int32_t accumulatedSpeed = 0;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Pinetime {
|
||||
namespace Controllers {
|
||||
class Settings {
|
||||
public:
|
||||
enum class ClockType : uint8_t { H24, H12, Fuzzy };
|
||||
enum class ClockType : uint8_t { H24, H12, FUZZY };
|
||||
enum class WeatherFormat : uint8_t { Metric, Imperial };
|
||||
enum class Notification : uint8_t { On, Off, Sleep };
|
||||
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
|
||||
@@ -329,7 +329,7 @@ namespace Pinetime {
|
||||
uint16_t shakeWakeThreshold = 150;
|
||||
|
||||
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
|
||||
Location location = {(int16_t)0,(int16_t)0,(int8_t)0};
|
||||
Location location = {(int16_t)44,(int16_t)-123,(int8_t)-8};
|
||||
};
|
||||
|
||||
SettingsData settings;
|
||||
|
||||
Reference in New Issue
Block a user