-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
116 lines (96 loc) · 2.11 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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include "controlDevices.h"
#include "inputcommander.h"
struct Devices *pdeviceHead = NULL;
struct InputCommander *pCommandHead = NULL;
struct Devices* findDeviceByName(char *name,struct Devices *phead)
{
struct Devices *tmp = phead;
if(phead = NULL)
{
return NULL;
}else{
while(tmp != NULL){
if(strcmp(tmp -> deviceName,name) == 0){
return tmp;
}
tmp = tmp->next;
}
return NULL;
}
}
struct InputCommander* findCommandByName(char *name,struct InputCommander *phead)
{
struct InputCommander *tmp = phead;
if(phead = NULL)
{
return NULL;
}else{
while(tmp != NULL){
if(strcmp(tmp -> commandName,name) == 0){
return tmp;
}
tmp = tmp->next;
}
return NULL;
}
}
void *Imu_thread(void *dates)
{
int nread;
struct InputCommander *Imu;
Imu = findCommandByName("Imu",pCommandHead);
printf("thread...\n");
if(Imu == NULL)
{
printf("find Imu error\n");
// return NULL
}else{
if(Imu -> Init(Imu,NULL,NULL) < 0)
{
printf("Init init\n");
}
while(1){
nread = Imu ->getCommand(Imu);
if(nread == 0)
{
printf("nodata from Imu\n");
}else{
printf("Imu get data : %s \n",Imu->command);
}
}
}
}
void *socket_thread(void *dates)
{
}
int main()
{
// 初始化
// char *name = "bathroomLight";
int pthread;
char name [128];
struct Devices *tmp = NULL;
pthread_t ImuThread;
pthread_t socketThread;
if( -1 == wiringPiSetup())
{
printf("error\n");
return -1 ;
}
// 基础控制灯
printf("try...\n");
// pdeviceHead = addredLightToDeviceLink(pdeviceHead);
pCommandHead = addimuContrlToInputCommandLink(pCommandHead);
// 线程
pthread = pthread_create(&ImuThread,NULL,Imu_thread,NULL);
//pthread_create(&socketThread,NULL,socket_thread,NULL);
if(pthread == 0) { printf("create thread successful\n");}
else{printf("create thread error\n");}
// 线程创立
pthread_join(ImuThread,NULL);
return 0;
}