-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
144 lines (119 loc) · 3.5 KB
/
main.c
File metadata and controls
144 lines (119 loc) · 3.5 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
#include "usec_dev.h"
/* stb_image */
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
/* definitions */
#define DEMO_OK 0
#define DEMO_ERR 1
/* prototypes */
static uint8_t screen_cleanup (usec_ctx *ctx);
static uint8_t demo_image_fullscreen (usec_ctx *ctx, const char *img_path);
/******************************************************************************/
/*
* main()
*/
int
main (void)
{
usec_ctx *ctx;
uint8_t status;
uint8_t usec_temp;
uint16_t usec_vcom;
/* initialize controller */
ctx = usec_init();
if (ctx == NULL)
{
printf ("[error] cannot initialize e-ink controller\n\r");
return EXIT_FAILURE;
}
/* read temperature value */
status = usec_get_temp (ctx, &usec_temp);
if (status != USEC_DEV_OK)
{
printf ("[error] cannot read temperature value\n\r");
usec_deinit (ctx);
return EXIT_FAILURE;
}
printf ("[status] screen temperature: %d [degC]\n\r", usec_temp);
/* read vcom value */
status = usec_get_vcom (ctx, &usec_vcom);
if (status != USEC_DEV_OK)
{
printf ("[error] cannot read VCOM value\n\r");
usec_deinit (ctx);
return EXIT_FAILURE;
}
printf ("[status] screen VCOM: -%.2f [V]\n\r", (float) usec_vcom / 1000);
/* cleanup screen - fullscreen update with UPDATE_MODE_INIT mode */
screen_cleanup (ctx);
/* fullscreen updates with UPDATE_MODE_GC16 mode */
demo_image_fullscreen (ctx, "images/img_1.png");
sleep(2); /* only for demo purposes */
demo_image_fullscreen (ctx, "images/img_2.png");
sleep(2); /* only for demo purposes */
demo_image_fullscreen (ctx, "images/img_3.png");
sleep(2); /* only for demo purposes */
/* screen cleanup */
screen_cleanup (ctx);
/* cleanup */
usec_deinit (ctx);
ctx = NULL;
return EXIT_SUCCESS;
}
/******************************************************************************/
/*
* screen_cleanup()
*/
static uint8_t
screen_cleanup (usec_ctx *ctx)
{
return usec_img_update (ctx, UPDATE_MODE_INIT, 0);
}
/******************************************************************************/
/*
* demo_image_fullscreen()
*/
static uint8_t
demo_image_fullscreen (usec_ctx *ctx,
const char *img_path)
{
uint8_t *img_data;
uint8_t status;
int img_res_x, img_res_y, img_ch_num;
/* load BMP image - convert to grayscale (1 channel) */
img_data = stbi_load (img_path, &img_res_x, &img_res_y, (int*)&img_ch_num, 1);
if (img_data == NULL)
{
printf ("[error] cannot load '%s' image\n\r", img_path);
return DEMO_ERR;
}
/* show image info */
printf ("[demo] input image resolution: %dx%d\n\r", img_res_x, img_res_y);
/* upload and display image */
printf ("[demo] uploading '%s' image\n\r", img_path);
status = usec_img_upload (ctx, img_data, img_res_x * img_res_y * 1);
if (status != USEC_DEV_OK)
{
printf ("[error] cannot upload '%s' image\n\r", img_path);
stbi_image_free (img_data);
return DEMO_ERR;
}
/* fullscreen update with UPDATE_MODE_GC16 */
printf ("[demo] displaying '%s' image\n\r", img_path);
status = usec_img_update (ctx, UPDATE_MODE_GC16, 0);
if (status != USEC_DEV_OK)
{
printf ("[error] cannot display '%s' image\n\r", img_path);
stbi_image_free (img_data);
return DEMO_ERR;
}
/* cleanup */
stbi_image_free (img_data);
return DEMO_OK;
}
/******************************************************************************/