-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.c
95 lines (83 loc) · 2.43 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
#include "pico/stdlib.h"
#include <sharpdisp/sharpdisp.h>
#include <sharpdisp/doublebuffer.h>
#include <sharpdisp/bitmap.h>
#include <sharpdisp/bitmapimage.h>
#include <sharpdisp/metrics.h>
#include <sharpdisp/bitmaptext.h>
#include <fonts/liberation_mono_12.h>
#include "map.h"
#define WIDTH 400
#define HEIGHT 240
#define SLEEP_MS 16
uint8_t disp_buffer[BITMAP_SIZE(WIDTH, HEIGHT)];
uint8_t disp_buffer2[BITMAP_SIZE(WIDTH, HEIGHT)];
char printf_buffer[256];
struct SharpDisp sd;
struct DoubleBuffer dub_buff;
struct SharpMetrics metrics;
struct BitmapText text;
struct BitmapImages bi;
static void init_metrics() {
// Metric makes this example a bit more complex than needed, but
// it is useful/interesting to show FPS and draw time as
// a demonstration of the effecitveness of the method.
metrics_init(&metrics);
text_init(&text, liberation_mono_12, &dub_buff.bitmap);
text.printf_buffer = printf_buffer;
}
static void draw_metrics(void) {
text.x = 8;
text.y = HEIGHT - 18;
if (metrics.frame_index > 0) {
const uint8_t old_mode = dub_buff.bitmap.mode;
dub_buff.bitmap.mode = BITMAP_INVERSE;
text_printf(
&text,
"Draw: %2u ms FPS: %u",
metrics_draw_ms(&metrics),
1000 / metrics_total_ms(&metrics));
dub_buff.bitmap.mode = old_mode;
}
}
int main() {
sleep_ms(100); // allow voltage to stabilize
// Initailize
sharpdisp_init_default(&sd, disp_buffer, WIDTH, HEIGHT, 0xFF);
doublebuffer_init(&dub_buff, &sd, disp_buffer2, SLEEP_MS);
image_init(&bi, map, &dub_buff.bitmap);
init_metrics();
const int16_t xmin = WIDTH - image_width_tiled(
&bi, MAP_IMG_0_0, MAP_IMG_COLUMNS);
const int16_t xmax = 0;
const int16_t ymin = HEIGHT - image_height_tiled(
&bi, MAP_IMG_0_0, MAP_IMG_COLUMNS, MAP_IMG_ROWS);
const int16_t ymax = 0;
int16_t x = 0;
int16_t y = 0;
int16_t xv = -1;
int16_t yv = -1;
while (!bi.error) {
metrics_start(&metrics);
bitmap_clear(&dub_buff.bitmap);
image_draw_tiled(&bi, MAP_IMG_0_0, MAP_IMG_COLUMNS, MAP_IMG_ROWS, x, y);
draw_metrics();
metrics_prerefresh(&metrics);
doublebuffer_swap(&dub_buff);
metrics_postrefresh(&metrics, 0);
x += xv;
if ((x < xmin) || (x > xmax)) {
xv = -xv;
x += xv;
}
y += yv;
if ((y < ymin) || (y > ymax)) {
yv = -yv;
y += yv;
}
}
// an error occurred. If you don't see images, add some debug messages here
while (1) {
sleep_ms(1000);
}
}