Compare commits

..

2 Commits

Author SHA1 Message Date
827decfcbd Implement integer text scaling 2022-06-04 19:44:25 +02:00
d23814fefc Reset memory layout after drawing text 2022-06-04 18:56:50 +02:00

View File

@@ -164,9 +164,6 @@ class Eink {
template <typename RleImage> template <typename RleImage>
static void draw(const RleImage &rleImage) static void draw(const RleImage &rleImage)
{ {
setRamXPos();
setRamYPos();
constexpr auto sendImageChannel = [](const auto command, const auto &image) { constexpr auto sendImageChannel = [](const auto command, const auto &image) {
using image_t = std::remove_cvref_t<decltype(image)>; using image_t = std::remove_cvref_t<decltype(image)>;
@@ -189,9 +186,6 @@ class Eink {
static void clear(const Color color = Color::WHITE) static void clear(const Color color = Color::WHITE)
{ {
setRamXPos();
setRamYPos();
constexpr auto getFillData = [](const auto &color) -> std::pair<std::uint8_t, std::uint8_t> { constexpr auto getFillData = [](const auto &color) -> std::pair<std::uint8_t, std::uint8_t> {
switch (color) { switch (color) {
case Color::BLACK: case Color::BLACK:
@@ -217,7 +211,8 @@ class Eink {
} }
static void drawText(const std::pair<std::uint8_t, std::uint8_t> &pos, const char *text, static void drawText(const std::pair<std::uint8_t, std::uint8_t> &pos, const char *text,
const Color textColor = Color::BLACK, const Color backgroundColor = Color::WHITE) const Color textColor = Color::BLACK, const Color backgroundColor = Color::WHITE,
const std::uint8_t scaling = 1)
{ {
const auto textLength = std::strlen(text); const auto textLength = std::strlen(text);
@@ -266,9 +261,9 @@ class Eink {
const auto sendChannel = [&](const auto command) { const auto sendChannel = [&](const auto command) {
for (auto i = std::size_t{0}; i < textLength; ++i) { for (auto i = std::size_t{0}; i < textLength; ++i) {
const auto posX = pos.first + i * 8; const auto posX = pos.first + i * 8 * scaling;
const auto screenPosX = getXScreenCoordinates(posX); const auto screenPosX = getXScreenCoordinates(posX);
setRamRange({screenPosX, screenPosX}, {pos.second, pos.second + 7}); setRamRange({screenPosX, screenPosX - (scaling - 1)}, {pos.second, pos.second + 8 * scaling - 1});
setRamXPos(screenPosX); setRamXPos(screenPosX);
setRamYPos(pos.second); setRamYPos(pos.second);
@@ -277,13 +272,32 @@ class Eink {
const auto fontByte = flash::loadLike<decltype(FONT_8X8)>(FONT_8X8.value[text[i]][j]); const auto fontByte = flash::loadLike<decltype(FONT_8X8)>(FONT_8X8.value[text[i]][j]);
static_assert(std::is_same_v<std::remove_cvref_t<decltype(fontByte)>, std::uint8_t>); static_assert(std::is_same_v<std::remove_cvref_t<decltype(fontByte)>, std::uint8_t>);
const auto dataByte = adjustColor(flipEndianness(fontByte), command); const auto dataByte = adjustColor(flipEndianness(fontByte), command);
sendData(dataByte);
auto scaledByte = std::uint8_t{0};
auto bitCounter = 0;
for (auto sy = std::uint8_t{0}; sy < scaling; ++sy) {
for (auto b = std::uint8_t{0}; b < 8; ++b) {
const auto currentBit = dataByte >> (8 - b - 1) & 1;
for (auto sx = std::uint8_t{0}; sx < scaling; ++sx) {
scaledByte |= currentBit << (8 - bitCounter - 1);
if (++bitCounter == 8) {
sendData(scaledByte);
scaledByte = 0;
bitCounter = 0;
}
}
}
}
} }
} }
}; };
sendChannel(Cmd::WRITE_RAM_BLACK); sendChannel(Cmd::WRITE_RAM_BLACK);
sendChannel(Cmd::WRITE_RAM_RED); sendChannel(Cmd::WRITE_RAM_RED);
setRamRange();
setRamXPos();
setRamYPos();
} }
template <typename Lut> template <typename Lut>