This commit is contained in:
2022-03-02 22:20:00 +01:00
10 changed files with 321 additions and 49 deletions

73
.clang-format Normal file
View File

@@ -0,0 +1,73 @@
---
AccessModifierOffset: '-4'
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: 'true'
AlignConsecutiveAssignments: 'true'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlines: Left
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowAllArgumentsOnNextLine: 'false'
AllowAllConstructorInitializersOnNextLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: 'false'
AlwaysBreakTemplateDeclarations: 'Yes'
BinPackArguments: 'false'
BinPackParameters: 'false'
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: 'true'
CompactNamespaces: 'false'
ContinuationIndentWidth: '4'
Cpp11BracedListStyle: 'true'
FixNamespaceComments: 'true'
IncludeBlocks: Regroup
IndentCaseLabels: 'true'
IndentPPDirectives: AfterHash
IndentWidth: '4'
IndentWrappedFunctionNames: 'true'
Language: Cpp
MaxEmptyLinesToKeep: '1'
NamespaceIndentation: All
PointerAlignment: Left
ReflowComments: 'true'
SortUsingDeclarations: 'true'
SpaceAfterCStyleCast: 'false'
SpaceAfterLogicalNot: 'false'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCpp11BracedList: 'false'
SpaceBeforeCtorInitializerColon: 'true'
SpaceBeforeInheritanceColon: 'true'
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: 'true'
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInSquareBrackets: 'false'
Standard: Auto
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterStruct: true
BeforeCatch: true
AfterControlStatement: "Always"
AfterFunction: true
AfterNamespace: true
AfterUnion: true
SplitEmptyFunction: true
SplitEmptyNamespace: true
SplitEmptyRecord: true

47
.gitignore vendored
View File

@@ -32,48 +32,5 @@
*.out
*.app
build/.ninja_deps
build/.ninja_log
build/build.ninja
build/cmake_install.cmake
build/CMakeCache.txt
build/compile_commands.json
build/.cmake/api/v1/query/client-vscode/query.json
build/.cmake/api/v1/reply/cache-v2-8e3d784e6607879cd18c.json
build/.cmake/api/v1/reply/codemodel-v2-97bfd906ef366d86b34b.json
build/.cmake/api/v1/reply/index-2022-02-11T18-35-30-0824.json
build/.cmake/api/v1/reply/target-frame-Debug-7d0b6524a58d8e907a2f.json
build/.cmake/api/v1/reply/toolchains-v1-65972111b21e4388dc41.json
build/CMakeFiles/cmake.check_cache
build/CMakeFiles/CMakeOutput.log
build/CMakeFiles/rules.ninja
build/CMakeFiles/TargetDirectories.txt
build/CMakeFiles/3.20.21032501-MSVC_2/CMakeCCompiler.cmake
build/CMakeFiles/3.20.21032501-MSVC_2/CMakeCXXCompiler.cmake
build/CMakeFiles/3.20.21032501-MSVC_2/CMakeDetermineCompilerABI_C.bin
build/CMakeFiles/3.20.21032501-MSVC_2/CMakeDetermineCompilerABI_CXX.bin
build/CMakeFiles/3.20.21032501-MSVC_2/CMakeRCCompiler.cmake
build/CMakeFiles/3.20.21032501-MSVC_2/CMakeSystem.cmake
build/CMakeFiles/3.20.21032501-MSVC_2/CompilerIdC/CMakeCCompilerId.c
build/CMakeFiles/3.20.21032501-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.cpp
build/CMakeFiles/ShowIncludes/foo.h
build/CMakeFiles/ShowIncludes/main.c
build/frame/cmake_install.cmake
build/frame/frame.ilk
build/frame/frame.pdb
build/frame/CMakeFiles/frame.dir/embed.manifest
build/frame/CMakeFiles/frame.dir/intermediate.manifest
build/frame/CMakeFiles/frame.dir/manifest.rc
build/frame/CMakeFiles/frame.dir/manifest.res
build/frame/CMakeFiles/frame.dir/vc140.pdb
build/.cmake/api/v1/reply/cache-v2-dd95df14d5968b8bc03c.json
build/.cmake/api/v1/reply/index-2022-02-12T19-46-35-0149.json
.vscode/settings.json
build/.cmake/api/v1/reply/cache-v2-b08d9ee268491a48090a.json
build/.cmake/api/v1/reply/codemodel-v2-1315d454ed7a6fd4530a.json
build/.cmake/api/v1/reply/index-2022-02-12T20-17-15-0123.json
build/.cmake/api/v1/reply/target-bcm2835-Debug-370fe998a1b6bb8b7242.json
build/.cmake/api/v1/reply/target-frame-Debug-bbe37aa3d79fa8b439c0.json
build/.cmake/api/v1/reply/target-waveshare-Debug-223ca8c705d057f21abf.json
build/bcm2835/cmake_install.cmake
build/waveshare/cmake_install.cmake
build/*
.vscode/*

View File

@@ -1,6 +1,14 @@
set(target frame)
set(src
src/main.cpp
src/Image.hpp
src/Image.cpp
src/display/IDisplay.hpp
src/display/EPD_7in5_V2.hpp
src/display/EPD_7in5_V2.cpp
)
add_executable(${target} main.cpp)
add_executable(${target} ${src})
target_link_libraries(${target} PRIVATE waveshare)

33
frame/src/Image.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include "Image.hpp"
namespace frame
{
Image::Image(uint32_t pWidth, uint32_t pHeight)
: mWidth(pWidth)
, mHeight(pHeight)
, mBuffer(mWidth * mHeight)
{
}
Image::Image(Size size)
: Image(size.width, size.height)
{
}
uint8_t& Image::at(uint32_t x, uint32_t y)
{
return mBuffer.at(toInternal(x, y));
}
uint8_t const& Image::at(uint32_t x, uint32_t y) const
{
return mBuffer.at(toInternal(x, y));
}
uint8_t Image::toInternal(uint32_t x, uint32_t y) const
{
return x + mWidth * y;
}
} // namespace frame

35
frame/src/Image.hpp Normal file
View File

@@ -0,0 +1,35 @@
#pragma once
#include "Size.hpp"
#include <vector>
namespace frame
{
class Image
{
uint32_t mWidth;
uint32_t mHeight;
std::vector<uint8_t> mBuffer;
public:
Image(uint32_t pWidth, uint32_t pHeight);
Image(Size size);
uint8_t& at(uint32_t x, uint32_t y);
uint8_t const& at(uint32_t x, uint32_t y) const;
auto getWidth() const
{
return mWidth;
}
auto getHeight() const
{
return mHeight;
}
private:
uint8_t toInternal(uint32_t x, uint32_t y) const;
};
} // namespace frame

10
frame/src/Size.hpp Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
namespace frame
{
struct Size
{
uint32_t width;
uint32_t height;
};
} // namespace frame

View File

@@ -0,0 +1,69 @@
#include "EPD_7in5_V2.hpp"
#include <EPD_7in5_V2.h>
namespace frame::display
{
constexpr uint32_t mWidth = EPD_7IN5_V2_WIDTH;
constexpr uint32_t mHeight = EPD_7IN5_V2_HEIGHT;
EPD_7in5_V2::EPD_7in5_V2()
: IDisplay("EPD_7in5_V2", {mWidth, mHeight})
{
}
EPD_7in5_V2::~EPD_7in5_V2()
{
Sleep();
}
bool EPD_7in5_V2::Init()
{
return EPD_7IN5_V2_Init() == 0;
}
void EPD_7in5_V2::Clear(Color color)
{
if(color == Color::WHITE)
{
EPD_7IN5_V2_Clear()
} else
{
EPD_7IN5_V2_ClearBlack();
}
}
void EPD_7in5_V2::Display(Image const& image)
{
constexpr auto bytes_width = mWidth / 8;
std::vector<uint8_t> data(bytes_with * mHeight);
uint8_t bit_counter;
for(auto y = 0; y < mHeight; ++y)
{
for(auto x = 0; x < bytes_width; ++x)
{
uint8_t byte = 0;
for(auto bit = 0; bit < 8; ++bit)
{
if(image.at(x * 8 + bit, y) > 265 / 2)
{
byte ^= 1;
}
byte << 1;
}
data[bytes_width * y + x] = byte;
}
}
EPD_7IN5_V2_Display(data.data());
}
void EPD_7in5_V2::Sleep()
{
EPD_7IN5_V2_Sleep();
}
} // namespace frame::display

View File

@@ -0,0 +1,23 @@
#pragma once
#include "IDisplay.hpp"
namespace frame::display
{
class EPD_7in5_V2 : public IDisplay
{
public:
EPD_7in5_V2();
~EPD_7in5_V2();
bool Init() override;
void Clear(Color color) override;
void Display(Image const& image) override;
void Sleep() override;
};
} // namespace frame::display

View File

@@ -0,0 +1,35 @@
#pragma once
#include "../Image.hpp"
#include <string>
namespace frame::display
{
enum class Color { WHITE, BLACK };
class IDisplay
{
std::string mName;
Size mSize;
public:
IDisplay(std::string_view pName, Size pSize)
: mName(pName)
, mSize(pSize){};
virtual ~IDisplay() = default;
virtual bool Init() = 0;
virtual void Clear(Color color) = 0;
virtual void Display(Image const& image) = 0;
virtual void Sleep() = 0;
public:
Size const& getSize()
{
return size;
}
};
} // namespace frame::display

View File

@@ -1,10 +1,38 @@
#include <iostream>
#include <chrono>
#include <iostream>
#include <thread>
#include <vector>
using namespace std::chrono_literals;
#include "display/EPD_7in5_V2.hpp"
int main()
{
frame::display::EPD_7in5_V2 display{};
display.Init();
display.Clear(frame::display::Color::BLACK);
std::this_thread::sleep_for(2s);
display.Clear(frame::display::Color::WHITE);
std::this_thread::sleep_for(2s);
frame::Image image(display.getSize());
for(int x = 0; x < image.getWidth(); ++x)
{
image.at(x, 0) = 0xFF;
}
display.Display(image);
}
/*
#include <EPD_7in5_V2.h>
@@ -45,3 +73,4 @@ int main()
return 0;
}
*/