bcm #1

Merged
Kaonnull merged 8 commits from bcm into master 2022-03-03 18:31:07 +01:00
7 changed files with 43 additions and 17 deletions
Showing only changes of commit f09c4700ba - Show all commits

View File

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

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "Size.hpp" #include "Size.hpp"
#include <cstdint>
#include <vector> #include <vector>
namespace frame namespace frame
@@ -29,7 +30,7 @@ namespace frame
} }
private: 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 #pragma once
#include <cstdint>
namespace frame namespace frame
{ {
struct Size struct Size

View File

@@ -19,6 +19,9 @@ namespace frame::display
bool EPD_7in5_V2::Init() bool EPD_7in5_V2::Init()
{ {
if(DEV_Module_Init()!=0)
return false;
return EPD_7IN5_V2_Init() == 0; return EPD_7IN5_V2_Init() == 0;
} }
@@ -26,17 +29,17 @@ namespace frame::display
{ {
if(color == Color::WHITE) if(color == Color::WHITE)
{ {
EPD_7IN5_V2_Clear() EPD_7IN5_V2_Clear();
} else } else
{ {
EPD_7IN5_V2_ClearBlack(); 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; 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; uint8_t bit_counter;
@@ -44,15 +47,17 @@ namespace frame::display
{ {
for(auto x = 0; x < bytes_width; ++x) for(auto x = 0; x < bytes_width; ++x)
{ {
uint8_t byte = 0; uint8_t byte = 0xFF;
for(auto bit = 0; bit < 8; ++bit) for(auto bit = 0; bit < 8; ++bit)
{ {
byte <<= 1;
if(image.at(x * 8 + bit, y) > 265 / 2) if(image.at(x * 8 + bit, y) > 265 / 2)
{ {
byte ^= 1; byte ^= 1;
} }
byte << 1;
} }
byte = ~ byte;
data[bytes_width * y + x] = byte; data[bytes_width * y + x] = byte;
} }

View File

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

View File

@@ -22,14 +22,14 @@ namespace frame::display
virtual void Clear(Color color) = 0; 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; virtual void Sleep() = 0;
public: public:
Size const& getSize() 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()); 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); display.Display(image);
std::this_thread::sleep_for(10s);
display.Clear(frame::display::Color::WHITE);
} }
/* /*