239 lines
6.0 KiB
C++
239 lines
6.0 KiB
C++
#include <chrono>
|
|
#include <cmath>
|
|
#include <iostream>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
#include "ScreenManager.hpp"
|
|
#include "display/Display.hpp"
|
|
#include "font/FontRegistry.hpp"
|
|
//#include "render/RenderTarget.hpp"
|
|
//#include "widgets/clock/Analog.hpp"
|
|
#include "widgets/WidgetRegistry.hpp"
|
|
|
|
int main()
|
|
{
|
|
auto display = frame::display::Create();
|
|
|
|
if(!display)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
display->Init();
|
|
|
|
frame::font::LoadFont("Fira Code");
|
|
|
|
frame::ScreenManager screen(std::move(display));
|
|
|
|
auto const& widgets = frame::Service::get<frame::widgets::WidgetRegistry>();
|
|
|
|
screen.setRoot(widgets->Create("AnalogClock"));
|
|
|
|
screen.MainLoop();
|
|
}
|
|
|
|
/*
|
|
int main()
|
|
{
|
|
constexpr double pi = 3.14159;
|
|
|
|
auto font = frame::font::Font::LoadFromFile("Fira Code.json");
|
|
|
|
auto display = frame::display::Create();
|
|
|
|
if(!display)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
display->Init();
|
|
|
|
display->Clear(frame::display::Color::WHITE);
|
|
|
|
frame::render::RenderTarget target(display->getSize());
|
|
|
|
frame::Vector const center = (display->getSize() / 2);
|
|
|
|
target.DrawPixel({10, 10}, frame::BLACK);
|
|
target.DrawLine({10, 12}, {100, 12}, frame::BLACK);
|
|
|
|
for(int i = 0; i < 360; i += 15)
|
|
{
|
|
auto end = center;
|
|
|
|
double const x = std::cos(i * pi / 180.f) * 200.f;
|
|
double const y = std::sin(i * pi / 180.f) * 200.f;
|
|
|
|
end.x += (int)x;
|
|
end.y += (int)y;
|
|
|
|
target.DrawLine(center, end);
|
|
}
|
|
target.DrawCircle(center, 200);
|
|
target.DrawCircle(center, 210);
|
|
target.DrawCircle(center, 220);
|
|
|
|
target.DrawCircle(center, 230);
|
|
target.DrawCircle(center, 231);
|
|
|
|
target.DrawRectFilled({100, 100}, {202, 202});
|
|
target.DrawCircle({151, 151}, 50, frame::WHITE);
|
|
target.DrawCircle({151, 151}, 40, frame::WHITE);
|
|
target.DrawCircle({151, 151}, 30, frame::WHITE);
|
|
target.DrawCircle({151, 151}, 20, frame::WHITE);
|
|
target.DrawCircle({151, 151}, 10, frame::WHITE);
|
|
target.DrawCircle({151, 151}, 1, frame::WHITE);
|
|
|
|
target.DrawRect({10, (int)display->getSize().height - 110},
|
|
{110, (int)display->getSize().height - 10},
|
|
5);
|
|
|
|
target.DrawText("Hallo Welt!", {100, 50}, *font, 14);
|
|
target.DrawText("Hallo Welt!", {50, 100}, *font, 30);
|
|
|
|
display->Display(target.getImage());
|
|
|
|
std::this_thread::sleep_for(10s);
|
|
|
|
target.Clear();
|
|
|
|
frame::Vector pos = display->getSize() / 2;
|
|
|
|
auto text = "10:30";
|
|
|
|
pos.x -= font->getLength(text, 250) / 2;
|
|
pos.y += font->getHeight(text, 250) / 2;
|
|
pos.y -= font->getMaxYOffset(text, 250) + font->getHeight(text, 250);
|
|
|
|
// target.DrawTextGlyphBounds(text, pos, *font, 250);
|
|
// target.DrawLine({0, (int32_t)pos.y},
|
|
// {(int32_t)display->getSize().width, pos.y});
|
|
|
|
auto rect = frame::Rect{0,
|
|
0,
|
|
(int)display->getSize().width,
|
|
(int)display->getSize().height};
|
|
|
|
target.DrawText(rect, text, *font, 250);
|
|
display->Display(target.getImage());
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
target.Clear();
|
|
target.DrawText(rect, text, *font, 250, frame::AlignHorizontal::CENTER);
|
|
display->Display(target.getImage());
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
target.Clear();
|
|
target.DrawText(rect, text, *font, 250, frame::AlignHorizontal::RIGHT);
|
|
display->Display(target.getImage());
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
target.Clear();
|
|
target.DrawText(rect,
|
|
text,
|
|
*font,
|
|
250,
|
|
frame::AlignHorizontal::LEFT,
|
|
frame::AlignVertical::CENTER);
|
|
display->Display(target.getImage());
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
target.Clear();
|
|
target.DrawText(rect,
|
|
text,
|
|
*font,
|
|
250,
|
|
frame::AlignHorizontal::CENTER,
|
|
frame::AlignVertical::CENTER);
|
|
display->Display(target.getImage());
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
target.Clear();
|
|
target.DrawText(rect,
|
|
text,
|
|
*font,
|
|
250,
|
|
frame::AlignHorizontal::RIGHT,
|
|
frame::AlignVertical::CENTER);
|
|
display->Display(target.getImage());
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
target.Clear();
|
|
target.DrawText(rect,
|
|
text,
|
|
*font,
|
|
250,
|
|
frame::AlignHorizontal::LEFT,
|
|
frame::AlignVertical::BOTTOM);
|
|
display->Display(target.getImage());
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
target.Clear();
|
|
target.DrawText(rect,
|
|
text,
|
|
*font,
|
|
250,
|
|
frame::AlignHorizontal::CENTER,
|
|
frame::AlignVertical::BOTTOM);
|
|
display->Display(target.getImage());
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
target.Clear();
|
|
target.DrawText(rect,
|
|
text,
|
|
*font,
|
|
250,
|
|
frame::AlignHorizontal::RIGHT,
|
|
frame::AlignVertical::BOTTOM);
|
|
display->Display(target.getImage());
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
display->Clear(frame::display::Color::WHITE);
|
|
}
|
|
*/
|
|
/*
|
|
#include <EPD_7in5_V2.h>
|
|
|
|
|
|
int main()
|
|
{
|
|
std::cout << "Hallo Welt" << std::endl;
|
|
|
|
EPD_7IN5_V2_Init();
|
|
|
|
EPD_7IN5_V2_ClearBlack();
|
|
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
EPD_7IN5_V2_Clear();
|
|
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
std::vector<uint8_t> image;
|
|
image.resize(EPD_7IN5_V2_HEIGHT * EPD_7IN5_V2_WIDTH);
|
|
|
|
uint8_t color = 0;
|
|
for(int x = 0; x < EPD_7IN5_V2_WIDTH; ++x)
|
|
{
|
|
for(int y = 0; y < EPD_7IN5_V2_HEIGHT; ++y)
|
|
{
|
|
image[EPD_7IN5_V2_WIDTH * y + x] = color;
|
|
}
|
|
|
|
color = ~color;
|
|
}
|
|
|
|
EPD_7IN5_V2_Display(image.data());
|
|
|
|
std::this_thread::sleep_for(10s);
|
|
|
|
EPD_7IN5_V2_Clear();
|
|
EPD_7IN5_V2_Sleep();
|
|
|
|
return 0;
|
|
}
|
|
*/
|