-
Notifications
You must be signed in to change notification settings - Fork 1
/
display.c
87 lines (71 loc) · 2.6 KB
/
display.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <serdisplib/serdisp.h>
serdisp_CONN_t* conn_display;
serdisp_t* display;
long fgcolour = SD_COL_BLACK;
long bgcolour = SD_COL_WHITE;
/*
LDC connection essentials
*/
int connect_lcd() {
conn_display = SDCONN_open("USB:060C/04EB");
display = serdisp_init(conn_display, "ALPHACOOL", "");
return 0;
}
void disconnect() {
SDCONN_close(conn_display);
}
/*
Socket server functions
*/
int initialize_server(unsigned short port) {
int socket_fd, new_socket_fd;
struct sockaddr_in host_addr, client_addr;
socklen_t sin_size;
int recv_length=1, yes=1;
char buffer[1024];
host_addr.sin_family=AF_INET;
host_addr.sin_port=htons(port);
host_addr.sin_addr.s_addr=0;
memset(&(host_addr.sin_zero), '\0', 8);
if (((socket_fd = socket(PF_INET, SOCK_STREAM, 0)) == -1) ||
(setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) ||
(bind(socket_fd, (struct sockaddr*) &host_addr, sizeof(struct sockaddr)) == -1) ||
(listen(socket_fd, 5) == -1)) return -1;
return socket_fd;
}
/*
Adjuvative functions
*/
void draw_bar(serdisp_t* dd, int x, int y, int w, int h, int hor, int type, long colour) {
int i,j;
for (j = y; j < y + ((hor)? h : w); j += ((type) ? 2 : 1))
for (i = x; i < x + ((hor)? w : h); i += ((type) ? 2 : 1))
serdisp_setcolour(dd, i, j, colour);
}
void draw_digit(serdisp_t* dd, int x, int y, int digit, int segwidth, int thick, long colour) {
if (digit < 0 || digit > 9) return;
draw_bar(dd, x, y, segwidth, thick, 1, !(digit != 1 && digit != 4), colour);
draw_bar(dd, x, y + segwidth - thick, segwidth, thick, 1, !(digit != 1 && digit != 7 && digit != 0), colour);
draw_bar(dd, x, y + 2*(segwidth - thick), segwidth, thick, 1, !(digit != 1 && digit != 4 && digit != 7), colour);
draw_bar(dd, x, y, segwidth, thick, 0, !(digit == 4 || digit == 5 || digit == 6 || digit == 8 || digit == 9 || digit == 0), colour);
draw_bar(dd, x + segwidth - thick, y, segwidth, thick, 0, !(digit != 5 && digit != 6), colour);
draw_bar(dd, x, y + segwidth - thick, segwidth, thick, 0, !(digit == 2 || digit == 6 || digit == 8 || digit == 0), colour);
draw_bar(dd, x + segwidth - thick, y + segwidth - thick, segwidth, thick, 0, !(digit != 2), colour);
}
/*
Main function
*/
int main() {
printf("Hello, world!\n");
display = connect_lcd();
server = initialize_server(35367);
while (1) {
}
return 0;
}