blob: 75b2032c0785c90ac8a7b3fb6ba7a1be1e4e0d68 (
plain)
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
|
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>
#include "fonts.h"
#include "input_gadgets.h"
#include "multiplexer.h"
void drop_privileges();
int main(int argc, char **argv)
{
pthread_t thread_id;
t_display_data display_data;
int ret_val;
#define TEXT_BUFFER_LENGTH 42
unsigned char *text_buffer;
t_scroll_buffer scroll_buffers[2];
// Set up gpi pointer for direct register access
ret_val = multiplexer_setup_root();
if (ret_val)
exit(ret_val);
// Drop root privileges
drop_privileges();
/************************************************************************\
* You are about to change the GPIO settings of your computer. *
* Mess this up and it will stop working! *
* It might be a good idea to 'sync' before running this program *
* so at least you still have your code changes written to the SD-card! *
\************************************************************************/
// configure the gpio pins and start the multiplexer thread
thread_id = multiplexer_setup_non_root(&display_data);
int i,j;
text_buffer = malloc(TEXT_BUFFER_LENGTH);
if (text_buffer == NULL) {
fprintf(stderr, "malloc failed to allocate 24 bytes\n");
exit(EXIT_FAILURE);
}
memset(text_buffer, 0, TEXT_BUFFER_LENGTH);
ret_val = gadgets_retrieve_temperature(text_buffer,TEXT_BUFFER_LENGTH);
if (ret_val) {
free(text_buffer);
exit(ret_val);
}
scroll_buffers[0].scroll_len = render(text_buffer, TEXT_BUFFER_LENGTH, scroll_buffers[0].buf, sizeof(scroll_buffers[0].buf), 1);
for (i=0; i<250; i++) {
usleep(100000);
for (j=0; j<40; j++)
display_data.buf[(display_data.should_buf+1)%3][j] = scroll_buffers[0].buf[(i+j) % scroll_buffers[0].scroll_len];
display_data.should_buf = (display_data.should_buf+1)%3;
}
free(text_buffer);
display_data.keep_running = 0;
pthread_join(thread_id, NULL);
return 0;
} // main
//
// Drop (root) privileges
//
void drop_privileges()
{
/* Drop superuser privileges in correct order */
if (setgid(99) == -1) {
perror("can't drop group privileges");
exit(-1);
}
if (setuid(99) == -1) {
perror("can't drop user privileges");
exit(-1);
}
} // drop_root
|