forked from runezor/PiArtFrame
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
96 lines (79 loc) · 2.34 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <stdlib.h> //exit()
#include <signal.h> //signal()
#include "EPD_Test.h" //Examples
#include "EPD_7in5_V2.h"
#include <time.h>
#include <iostream>
#include <chrono>
#include "mandelbrot.hpp"
using namespace std;
using namespace chrono;
static constexpr unsigned long SecondsBetweenImages = 25*60;
void Handler(int signo)
{
//System Exit
printf("\r\nHandler:exit\r\n");
DEV_Module_Exit();
exit(0);
}
int main(void)
{
// Exception handling:ctrl + c
signal(SIGINT, Handler);
if(DEV_Module_Init()!=0){
return -1;
}
printf("e-Paper Init...\r\n");
EPD_7IN5_V2_Init();
EPD_7IN5_V2_Clear();
DEV_Delay_ms(500);
// Compute image size
UWORD Imagesize = ((EPD_7IN5_V2_WIDTH % 8 == 0)? (EPD_7IN5_V2_WIDTH / 8 ): (EPD_7IN5_V2_WIDTH / 8 + 1)) * EPD_7IN5_V2_HEIGHT;
UBYTE* img = NULL;
// Allocate memory for image
if((img = (UBYTE *)malloc(Imagesize)) == NULL) {
printf("Failed to apply for image memory...\r\n");
return -1;
}
Paint_NewImage(img, EPD_7IN5_V2_WIDTH, EPD_7IN5_V2_HEIGHT, 0, WHITE);
Paint_SelectImage(img);
MandelbrotSet mandelbrot;
mandelbrot.InitMandelbrotSet();
mandelbrot.SetRender(img);
bool isFirstImage = true;
unsigned int numberOfZooms = 1;
while(true)
{
steady_clock::time_point beforeRender = steady_clock::now();
cout << "Starting render..." << endl;
mandelbrot.Render(EPD_7IN5_V2_WIDTH, EPD_7IN5_V2_HEIGHT);
cout << "Render complete!" << endl;
steady_clock::time_point afterRender = steady_clock::now();
if(isFirstImage)
{
isFirstImage = false;
}
else
{
while(duration_cast<std::chrono::seconds>(afterRender - beforeRender).count() < SecondsBetweenImages)
{
sleep(5);
afterRender = steady_clock::now();
}
}
cout << "Drawing image..." << endl;
EPD_7IN5_V2_Init();
EPD_7IN5_V2_Clear();
DEV_Delay_ms(500);
EPD_7IN5_V2_Display(img);
EPD_7IN5_V2_Sleep();
cout << "Draw completed!" << endl;
mandelbrot.ZoomOnInterestingArea();
if(numberOfZooms %50 == 0)
{
mandelbrot.InitMandelbrotSet();
}
numberOfZooms++;
}
return 0;
}