-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssd1306_test.c
More file actions
106 lines (84 loc) · 1.99 KB
/
ssd1306_test.c
File metadata and controls
106 lines (84 loc) · 1.99 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
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <wiringPi.h>
#include "oled_lib.h"
#define OLED_SPI_CS 0
#define OLED_GPIO_RST 12
#define OLED_GPIO_DC 16
/* Show help */
void help(char *progname)
{
printf("Usage:\n\t%s string0 ... stringN\n\n", progname);
puts("Where:");
puts("\tstringN\t - text to display on row N");
}
/* ********** */
/* * MAIN * */
/* ********** */
int main(int argc, char *argv[])
{
int fd;
int i, a;
wiringPiSetupGpio();
fd = OLED_initSPI(ADAFRUIT_SSD1306_128_64, OLED_SPI_CS, OLED_GPIO_RST,
OLED_GPIO_DC);
if (fd < 0)
{
fprintf(stderr, "Unable to open SPI device: %s\n",
strerror (errno));
exit(-1);
}
if (argc > 1 && !strcmp(argv[1], "--?")) {
help(argv[0]);
exit(0);
}
a = argc - 1;
if (a) {
if (a > 8)
a = 8;
OLED_powerOn(fd);
OLED_clearDisplay(fd);
for(i = 0; i < a; i++)
OLED_putString(fd, OLED_DEFAULT_FONT, 0, i, 0,
argv[i + 1]);
}
else {
/* no arguments - predefined test procedures */
puts("Powering on display.");
OLED_powerOn(fd);
puts("OK, waiting 5 seconds...");
sleep(5);
puts("Zeroing video memory.");
OLED_clearDisplay(fd);
puts("OK, waiting 5 seconds...");
sleep(5);
for(i = 0; i < 6; i++) {
printf("Test pattern %d.\n", i);
OLED_testPattern(fd, i);
puts("OK, waiting 5 seconds...");
sleep(5);
}
puts("Test font.");
OLED_testFont(fd, 0);
puts("OK, waiting 5 seconds...");
sleep(5);
puts("Displaying some characters.");
OLED_clearDisplay(fd);
for(i = 0; i < 8; i++) {
OLED_putChar(fd, OLED_DEFAULT_FONT, 0 + (i << 3), i, i & 1, 'T');
OLED_putChar(fd, OLED_DEFAULT_FONT, 6 + (i << 3), i, i & 1, 'e');
OLED_putChar(fd, OLED_DEFAULT_FONT, 12 + (i << 3), i, i & 1, 's');
OLED_putChar(fd, OLED_DEFAULT_FONT, 18 + (i << 3), i, i & 1, 't');
}
puts("OK, waiting 5 seconds...");
sleep(5);
puts("Powering off display.");
OLED_powerOff(fd);
}
return 0;
}