-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
205 lines (162 loc) · 3.99 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* @brief Display Driver for Wide.HK OLED 20x4 I2C Text Mode Display
*
* This module implements Text output and positioning for the Wide.HK
* 20x4 OLED Character display found online at the listing shown on the
* <A HREF="https://www.ebay.com/itm/IIC-I2C-2004-20x4-Green-OLED-Module-Display-For-Arduino-PIC-AVR-ARM/162406508569"> Wide.HK Ebay Store</a>
*
* Reference:
*
* @copyright
* Copyright (C) 2016 Real Flight Systems
* @author James F Dougherty <[email protected]>
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <sys/select.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <errno.h>
#include "ssd13xx_20x4_oled.h"
extern int serial_open(char* device, int highspeed) ; /* i2c.c */
extern void ms_delay(unsigned int usecs); /* time.c */
int i2c_fd = -1;
int main(int argc, char* argv[])
{
int i = 0, c = 0, j = 0, k = 0;
unsigned char buf[256];
unsigned char ubuf[256];
/* Compass arrows */
unsigned char arrows[] = { 222, 23, 223, 25, 224, 24, 225, 22};
if (argc != 2) {
printf ("usage: %s <comport> (e.g. /dev/i2c-1) \n", argv[0]);
exit(1);
}
if ((i2c_fd = serial_open(argv[1],0)) < 0) {
printf("error: could not open [%s]\n", argv[1]);
exit(2);
}
lcd_init();
lcd_startup_banner();
while(1){
lcd_cls();
strcpy((char*)ubuf, " Wide.HK ");
lcd_write(ubuf,20);
strcpy((char*)ubuf, " 20x4 OLED Diplay ");
lcd_write(ubuf,20);
for (k = 0; k < 3; k++)
for (j = 0; j < 8; j++) {
ubuf[0] = arrows[j];
lcd_goto(0,0);
lcd_write(ubuf,1);
ms_delay(50);
}
/* Loop through second character set - Dancing vertical bars */
lcd_define_vbar_symbol();
for (j = 0; j < 10; j++) {
lcd_goto(0,2);
for (i = 0; i < 20; i++)
ubuf[i] = random() % 9 ;
lcd_write(ubuf,20);
for (i = 0; i < 20; i++) {
lcd_goto(i, 3);
ubuf[0] = 7;
lcd_write(ubuf,1);
lcd_goto(i, 3);
ubuf[0] = ' ';
lcd_write(ubuf, 1);
}
for (i = 19; i >= 0; i--) {
lcd_goto(i, 3);
ubuf[0] = 7;
lcd_write(ubuf,1);
lcd_goto(i, 3);
ubuf[0] = ' ';
lcd_write(ubuf, 1);
}
}
ms_delay(1000);
/* Loop through first character set - nav symbols */
lcd_define_nav_symbols();
for (j = 0; j < 8; j++) {
for (i = 0; i < 20; i++) {
ubuf[i] = j;
}
lcd_goto(0,0);
lcd_write(ubuf,20);
lcd_write(ubuf,20);
lcd_write(ubuf,20);
lcd_write(ubuf,20);
ms_delay(100);
}
/* Load vertical bar charset -then make Dancing vertical bars */
lcd_define_vbar_symbol();
for (j = 0; j < 100; j++) {
lcd_goto(0,0);
for (i = 0; i < 20; i++)
ubuf[i] = random() % 9;
lcd_write(ubuf,20);
for (i = 0; i < 20; i++)
ubuf[i] = random() % 9;
lcd_write(ubuf,20);
for (i = 0; i < 20; i++)
ubuf[i] = random() % 9;
lcd_write(ubuf,20);
for (i = 0; i < 20; i++)
ubuf[i] = random() % 9;
lcd_write(ubuf,20);
}
/* clear screen */
lcd_cls();
/* Cylon/Nightrider display - back and forth each line */
for(j = 0; j < 4; j++) {
for (k = 0; k < 3; k++) {
for (i = 0; i < 20; i++) {
lcd_goto(i, j);
ubuf[0] = 7;
lcd_write(ubuf,1);
ms_delay(10);
lcd_goto(i, j);
ubuf[0] = ' ';
lcd_write(ubuf, 1);
ms_delay(10);
}
for (i = 19; i >= 0; i--) {
lcd_goto(i, j);
ubuf[0] = 7;
lcd_write(ubuf,1);
ms_delay(10);
lcd_goto(i, j);
ubuf[0] = ' ';
lcd_write(ubuf, 1);
ms_delay(10);
}
}
}
/* Clear screen */
lcd_cls();
/* Load character set and display each character */
for (c = 0; c <= 255; c++) {
for (i = 0; i < 20; i++) {
ubuf[i] = c;
}
lcd_goto(0,0);
lcd_write(ubuf, 20);
lcd_goto(0,1);
lcd_write(ubuf, 20);
lcd_goto(0,2);
lcd_write(ubuf, 20);
sprintf(buf, "Text %03d ", c);
buf[20] = 0;
lcd_goto(0,3);
lcd_puts(buf);
ms_delay(200);
}
}
return 0;
}