-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
130 lines (110 loc) · 3.9 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
//
// Created by joek on 10/4/16.
//
#include <stdbool.h>
#include "BBB_P10.h"
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
bool Scanning = true;
const char *MSG = "BBB_P10 LED DISPLAY IS A LIBRARY FOR BEAGLEBONE BLACK.";
typedef struct {
pthread_mutex_t mutex;
pthread_t thread;
}threadstruct;
void *scan_thread(void *data){
threadstruct *threadstruct1 = (threadstruct*)data;
while(Scanning){
pthread_mutex_lock(&threadstruct1->mutex);
Scan_Panels();
pthread_mutex_unlock(&threadstruct1->mutex);
}
pthread_exit(NULL);
}
void *display_thread(void *data){
threadstruct *threadstruct1 = (threadstruct*)data;
while(Scanning){
pthread_mutex_lock(&threadstruct1->mutex);
movestring(MSG,Left,AlignCenter,50000);
pthread_mutex_unlock(&threadstruct1->mutex);
sleep(1);
pthread_mutex_lock(&threadstruct1->mutex);
movestring("SCROLLING RIGHT",Right,AlignCenter,50000);
pthread_mutex_unlock(&threadstruct1->mutex);
sleep(1);
pthread_mutex_lock(&threadstruct1->mutex);
movestring("SCROLLING LEFT",Left,AlignTop,10000);
pthread_mutex_unlock(&threadstruct1->mutex);
sleep(1);
pthread_mutex_lock(&threadstruct1->mutex);
Clear_Buffer(false);
drawBox(0,0,nPANEL*WIDTH-1,15);
drawmessage("LEFT TOP",AlignHLeft,AlignTop);
pthread_mutex_unlock(&threadstruct1->mutex);
sleep(1);
pthread_mutex_lock(&threadstruct1->mutex);
Clear_Buffer(false);
drawBox(0,0,nPANEL*WIDTH-1,15);
drawmessage("CENTER TOP",AlignHCenter,AlignTop);
pthread_mutex_unlock(&threadstruct1->mutex);
sleep(1);
pthread_mutex_lock(&threadstruct1->mutex);
Clear_Buffer(false);
drawBox(0,0,nPANEL*WIDTH-1,15);
drawmessage("RIGHT TOP",AlignHRight,AlignTop);
pthread_mutex_unlock(&threadstruct1->mutex);
sleep(1);
pthread_mutex_lock(&threadstruct1->mutex);
Clear_Buffer(false);
drawBox(0,0,nPANEL*WIDTH-1,15);
drawmessage("LEFT TOP",AlignHLeft,AlignTop);
pthread_mutex_unlock(&threadstruct1->mutex);
sleep(1);
pthread_mutex_lock(&threadstruct1->mutex);
Clear_Buffer(false);
drawBox(0,0,nPANEL*WIDTH-1,15);
drawmessage("CENTER CENTER",AlignHCenter,AlignCenter);
pthread_mutex_unlock(&threadstruct1->mutex);
sleep(1);
pthread_mutex_lock(&threadstruct1->mutex);
Clear_Buffer(false);
drawBox(0,0,nPANEL*WIDTH-1,15);
drawmessage("RIGHT BOTTOM",AlignHRight,AlignBottom);
pthread_mutex_unlock(&threadstruct1->mutex);
sleep(1);
pthread_mutex_lock(&threadstruct1->mutex);
Clear_Buffer(false);
flashmessage("FLASHING STRING",AlignHCenter,AlignCenter,350000,5);
pthread_mutex_unlock(&threadstruct1->mutex);
sleep(1);
}
//
pthread_exit(NULL);
}
int main(int argc, char *argv[]) {
int res;
Setup_Pins();
Clear_Buffer(false);
drawmessage(MSG,AlignHCenter,AlignCenter);
threadstruct *threadstruct1 = malloc(sizeof(threadstruct));
pthread_mutex_init(&(threadstruct1->mutex), NULL);
res = pthread_create(&threadstruct1->thread, NULL, scan_thread, threadstruct1);
if (res < 0) {
printf("failed to create thread %d\n", res);
return res;
}
threadstruct *threadstruct2 = malloc(sizeof(threadstruct));
pthread_mutex_init(&(threadstruct2->mutex), NULL);
res = pthread_create(&threadstruct2->thread, NULL, display_thread, threadstruct2);
if (res < 0) {
printf("failed to create thread %d\n", res);
return res;
}
pthread_join(threadstruct1->thread, NULL);
pthread_join(threadstruct2->thread, NULL);
pthread_mutex_destroy(&threadstruct1->mutex);
pthread_mutex_destroy(&threadstruct2->mutex);
Free_BBB_P10();
return 0 ;
}