diff options
author | panky-codes <pankaj.sarathy1992@gmail.com> | 2021-03-20 22:45:29 +0100 |
---|---|---|
committer | panky-codes <pankaj.sarathy1992@gmail.com> | 2021-03-20 22:45:29 +0100 |
commit | 534565088033221d29e968acf7267145ff10203b (patch) | |
tree | c93ae7c7aa7995204f56b979ff6524feba83763d /src/components | |
parent | 754ac233040af805ffa2e15b24539d5d02a876e5 (diff) | |
parent | a3ff2e46ca9e663af864a2bd04b9afa3efbddfb8 (diff) |
Merged upstream
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/datetime/DateTimeController.cpp | 120 | ||||
-rw-r--r-- | src/components/datetime/DateTimeController.h | 17 | ||||
-rw-r--r-- | src/components/gfx/Gfx.cpp | 14 | ||||
-rw-r--r-- | src/components/rle/RleDecoder.cpp | 39 | ||||
-rw-r--r-- | src/components/rle/RleDecoder.h | 33 | ||||
-rw-r--r-- | src/components/settings/Settings.cpp | 16 | ||||
-rw-r--r-- | src/components/settings/Settings.h | 30 |
7 files changed, 260 insertions, 9 deletions
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 30d9c13f..59982477 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -64,3 +64,123 @@ void DateTime::UpdateTime(uint32_t systickCounter) { second = time.seconds().count(); } +const char *DateTime::MonthShortToString() { + return DateTime::MonthsString[(uint8_t)month]; +} + +const char *DateTime::MonthShortToStringLow() { + return DateTime::MonthsStringLow[(uint8_t)month]; +} + +const char *DateTime::MonthsToStringLow() { + return DateTime::MonthsLow[(uint8_t)month]; +} + +const char *DateTime::DayOfWeekToString() { + return DateTime::DaysString[(uint8_t)dayOfWeek]; +} + +const char *DateTime::DayOfWeekShortToString() { + return DateTime::DaysStringShort[(uint8_t)dayOfWeek]; +} + +const char *DateTime::DayOfWeekToStringLow() { + return DateTime::DaysStringLow[(uint8_t)dayOfWeek]; +} + +const char *DateTime::DayOfWeekShortToStringLow() { + return DateTime::DaysStringShortLow[(uint8_t)dayOfWeek]; +} + + +char const *DateTime::DaysStringLow[] = { + "--", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + "Sunday" +}; + +char const *DateTime::DaysStringShortLow[] = { + "--", + "Mon", + "Tue", + "Wed", + "Thu", + "Fri", + "Sat", + "Sun" +}; + +char const *DateTime::DaysStringShort[] = { + "--", + "MON", + "TUE", + "WED", + "THU", + "FRI", + "SAT", + "SUN" +}; + +char const *DateTime::DaysString[] = { + "--", + "MONDAY", + "TUESDAY", + "WEDNESDAY", + "THURSDAY", + "FRIDAY", + "SATURDAY", + "SUNDAY" +}; + +char const *DateTime::MonthsString[] = { + "--", + "JAN", + "FEB", + "MAR", + "APR", + "MAY", + "JUN", + "JUL", + "AUG", + "SEP", + "OCT", + "NOV", + "DEC" +}; + +char const *DateTime::MonthsStringLow[] = { + "--", + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec" +}; + +char const *DateTime::MonthsLow[] = { + "--", + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December" +};
\ No newline at end of file diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h index d6020745..16bb59c9 100644 --- a/src/components/datetime/DateTimeController.h +++ b/src/components/datetime/DateTimeController.h @@ -20,6 +20,14 @@ namespace Pinetime { uint8_t Minutes() const { return minute; } uint8_t Seconds() const { return second; } + const char *MonthShortToString(); + const char *MonthShortToStringLow(); + const char *MonthsToStringLow(); + const char *DayOfWeekToString(); + const char *DayOfWeekShortToString(); + const char *DayOfWeekToStringLow(); + const char *DayOfWeekShortToStringLow(); + std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const { return currentDateTime; } std::chrono::seconds Uptime() const { return uptime; } private: @@ -34,6 +42,15 @@ namespace Pinetime { uint32_t previousSystickCounter = 0; std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime; std::chrono::seconds uptime {0}; + + static char const *DaysString[]; + static char const *DaysStringShort[]; + static char const *DaysStringLow[]; + static char const *DaysStringShortLow[]; + static char const *MonthsString[]; + static char const *MonthsStringLow[]; + static char const *MonthsLow[]; + }; } }
\ No newline at end of file diff --git a/src/components/gfx/Gfx.cpp b/src/components/gfx/Gfx.cpp index 59c1da9b..59fa8164 100644 --- a/src/components/gfx/Gfx.cpp +++ b/src/components/gfx/Gfx.cpp @@ -17,9 +17,8 @@ void Gfx::ClearScreen() { state.busy = true; state.action = Action::FillRectangle; state.taskToNotify = xTaskGetCurrentTaskHandle(); - - lcd.BeginDrawBuffer(0, 0, width, height); - lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(buffer), width * 2); + + lcd.DrawBuffer(0, 0, width, height, reinterpret_cast<const uint8_t *>(buffer), width * 2); WaitTransferFinished(); } @@ -34,8 +33,7 @@ void Gfx::FillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t col state.color = color; state.taskToNotify = xTaskGetCurrentTaskHandle(); - lcd.BeginDrawBuffer(x, y, w, h); - lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(buffer), width * 2); + lcd.DrawBuffer(x, y, w, h, reinterpret_cast<const uint8_t *>(buffer), width * 2); WaitTransferFinished(); } @@ -48,8 +46,7 @@ void Gfx::FillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t* b) state.color = 0x00; state.taskToNotify = xTaskGetCurrentTaskHandle(); - lcd.BeginDrawBuffer(x, y, w, h); - lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(b), width * 2); + lcd.DrawBuffer(x, y, w, h, reinterpret_cast<const uint8_t *>(b), width * 2); WaitTransferFinished(); } @@ -120,8 +117,7 @@ void Gfx::DrawChar(const FONT_INFO *font, uint8_t c, uint8_t *x, uint8_t y, uint state.color = color; state.taskToNotify = xTaskGetCurrentTaskHandle(); - lcd.BeginDrawBuffer(*x, y, bytes_in_line*8, font->height); - lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(&buffer), bytes_in_line*8*2); + 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; diff --git a/src/components/rle/RleDecoder.cpp b/src/components/rle/RleDecoder.cpp new file mode 100644 index 00000000..19a90fda --- /dev/null +++ b/src/components/rle/RleDecoder.cpp @@ -0,0 +1,39 @@ +#include "RleDecoder.h" + +using namespace Pinetime::Tools; + +RleDecoder::RleDecoder(const uint8_t *buffer, size_t size) : buffer{buffer}, size{size} { + +} + +RleDecoder::RleDecoder(const uint8_t *buffer, size_t size, uint16_t foregroundColor, uint16_t backgroundColor) : RleDecoder{buffer, size} { + this->foregroundColor = foregroundColor; + this->backgroundColor = backgroundColor; +} + + +void RleDecoder::DecodeNext(uint8_t *output, size_t maxBytes) { + for (;encodedBufferIndex<size; encodedBufferIndex++) { + uint8_t rl = buffer[encodedBufferIndex] - processedCount; + while (rl) { + output[bp] = color >> 8; + output[bp + 1] = color & 0xff; + bp += 2; + rl -= 1; + processedCount++; + + if (bp >= maxBytes) { + bp = 0; + y += 1; + return; + } + } + processedCount = 0; + + if (color == backgroundColor) + color = foregroundColor; + else + color = backgroundColor; + } +} + diff --git a/src/components/rle/RleDecoder.h b/src/components/rle/RleDecoder.h new file mode 100644 index 00000000..0f607fb8 --- /dev/null +++ b/src/components/rle/RleDecoder.h @@ -0,0 +1,33 @@ +#pragma once + +#include <cstdint> +#include <cstddef> + +namespace Pinetime { + namespace Tools { + /* 1-bit RLE decoder. Provide the encoded buffer to the constructor and then call DecodeNext() by + * specifying the output (decoded) buffer and the maximum number of bytes this buffer can handle. + * + * Code from https://github.com/daniel-thompson/wasp-bootloader by Daniel Thompson released under the MIT license. + */ + class RleDecoder { + public: + RleDecoder(const uint8_t* buffer, size_t size); + RleDecoder(const uint8_t* buffer, size_t size, uint16_t foregroundColor, uint16_t backgroundColor); + + void DecodeNext(uint8_t* output, size_t maxBytes); + + private: + const uint8_t* buffer; + size_t size; + + int encodedBufferIndex = 0; + int y = 0; + uint16_t bp = 0; + uint16_t foregroundColor = 0xffff; + uint16_t backgroundColor = 0; + uint16_t color = backgroundColor; + int processedCount = 0; + }; + } +} diff --git a/src/components/settings/Settings.cpp b/src/components/settings/Settings.cpp new file mode 100644 index 00000000..0c6cf610 --- /dev/null +++ b/src/components/settings/Settings.cpp @@ -0,0 +1,16 @@ +#include "Settings.h" + +using namespace Pinetime::Controllers; + + +// TODO (team): +// Read and write the settings to Flash +// +void Settings::Init() { + // default Clock face + clockFace = 0; + + clockType = ClockType::H24; + +} + diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h new file mode 100644 index 00000000..fa67f35e --- /dev/null +++ b/src/components/settings/Settings.h @@ -0,0 +1,30 @@ +#pragma once +#include <cstdint> + +namespace Pinetime { + namespace Controllers { + class Settings { + public: + enum class ClockType {H24, H12}; + + void Init(); + + void SetClockFace( uint8_t face ) { clockFace = face; }; + uint8_t GetClockFace() { return clockFace; }; + + void SetAppMenu( uint8_t menu ) { appMenu = menu; }; + uint8_t GetAppMenu() { return appMenu; }; + + void SetClockType( ClockType clocktype ) { clockType = clocktype; }; + ClockType GetClockType() { return clockType; }; + + + private: + uint8_t clockFace = 0; + uint8_t appMenu = 0; + + ClockType clockType = ClockType::H24; + + }; + } +}
\ No newline at end of file |