This commit is contained in:
2022-03-02 23:54:26 +01:00
parent bd87b1c074
commit f09c4700ba
7 changed files with 43 additions and 17 deletions

View File

@@ -1,12 +1,14 @@
#include "Image.hpp"
#include <stdint.h>
namespace frame
{
Image::Image(uint32_t pWidth, uint32_t pHeight)
: mWidth(pWidth)
, mHeight(pHeight)
, mBuffer(mWidth * mHeight)
, mBuffer(mWidth * mHeight, 0)
{
}
@@ -25,7 +27,7 @@ namespace frame
return mBuffer.at(toInternal(x, y));
}
uint8_t Image::toInternal(uint32_t x, uint32_t y) const
size_t Image::toInternal(uint32_t x, uint32_t y) const
{
return x + mWidth * y;
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include "Size.hpp"
#include <cstdint>
#include <vector>
namespace frame
@@ -29,7 +30,7 @@ namespace frame
}
private:
uint8_t toInternal(uint32_t x, uint32_t y) const;
size_t toInternal(uint32_t x, uint32_t y) const;
};
} // namespace frame
} // namespace frame

View File

@@ -1,5 +1,7 @@
#pragma once
#include <cstdint>
namespace frame
{
struct Size

View File

@@ -19,6 +19,9 @@ namespace frame::display
bool EPD_7in5_V2::Init()
{
if(DEV_Module_Init()!=0)
return false;
return EPD_7IN5_V2_Init() == 0;
}
@@ -26,17 +29,17 @@ namespace frame::display
{
if(color == Color::WHITE)
{
EPD_7IN5_V2_Clear()
EPD_7IN5_V2_Clear();
} else
{
EPD_7IN5_V2_ClearBlack();
}
}
void EPD_7in5_V2::Display(Image const& image)
void EPD_7in5_V2::Display(Image const& image, bool invert)
{
constexpr auto bytes_width = mWidth / 8;
std::vector<uint8_t> data(bytes_with * mHeight);
std::vector<uint8_t> data(bytes_width * mHeight);
uint8_t bit_counter;
@@ -44,15 +47,17 @@ namespace frame::display
{
for(auto x = 0; x < bytes_width; ++x)
{
uint8_t byte = 0;
uint8_t byte = 0xFF;
for(auto bit = 0; bit < 8; ++bit)
{
byte <<= 1;
if(image.at(x * 8 + bit, y) > 265 / 2)
{
byte ^= 1;
}
byte << 1;
}
byte = ~ byte;
data[bytes_width * y + x] = byte;
}
@@ -66,4 +71,4 @@ namespace frame::display
EPD_7IN5_V2_Sleep();
}
} // namespace frame::display
} // namespace frame::display

View File

@@ -15,7 +15,7 @@ namespace frame::display
void Clear(Color color) override;
void Display(Image const& image) override;
void Display(Image const& image, bool invert = false) override;
void Sleep() override;
};

View File

@@ -22,14 +22,14 @@ namespace frame::display
virtual void Clear(Color color) = 0;
virtual void Display(Image const& image) = 0;
virtual void Display(Image const& image, bool invert = false) = 0;
virtual void Sleep() = 0;
public:
Size const& getSize()
{
return size;
return mSize;
}
};
} // namespace frame::display
} // namespace frame::display

View File

@@ -24,12 +24,28 @@ int main()
frame::Image image(display.getSize());
for(int x = 0; x < image.getWidth(); ++x)
for(int y = 0; y < 1; ++y)
{
image.at(x, 0) = 0xFF;
for(int x = 0; x < image.getWidth(); ++x)
{
image.at(x, y) = 0xFF;
}
}
for(int y = image.getHeight() - 1; y < image.getHeight(); ++y)
{
for(int x = 0; x < image.getWidth(); ++x)
{
image.at(x, y) = 0xFF;
}
}
display.Display(image);
std::this_thread::sleep_for(10s);
display.Clear(frame::display::Color::WHITE);
}
/*
@@ -73,4 +89,4 @@ int main()
return 0;
}
*/
*/