-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSensorComs.c
More file actions
58 lines (46 loc) · 1.19 KB
/
SensorComs.c
File metadata and controls
58 lines (46 loc) · 1.19 KB
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
#include "SensorComs.h"
#include "Lab4Photo.h"
#include "Lab4Clock.h"
#include <pthread.h>
#include <ctype.h>
#include <stdio.h>
const int SENS_THREAD_DELAY = 0;
struct SensorInfo {
bool run;
char cmd;
int resp;
char timeStamp[7];
};
void SensorComThread(pthread_mutex_t *sensorComsMutexPt, SensorInfo *sensorDataPt){
printf("What the fuck.\n");
/* This function acts as a main thread for interacting with the sensor */
//initialize I2C
initI2C();
//Set clock
int clockHandle = openClockInterface();
setClock(clockHandle);
int mutexCheck;
while(1){
//lock mutex to check if there is a new command to run
mutexCheck = pthread_mutex_lock(sensorComsMutexPt);
if (mutexCheck != 0){
exit(-6);
}
//check if there is a new command
if( sensorDataPt->run == 0){
printf("Recieved new command, cap'n\n");
//if there is run it
sensorDataPt->cmd = tolower(sensorDataPt->cmd);
sensorDataPt->resp = cmdRun(sensorDataPt->cmd);
//update timestamp
getClock(clockHandle, sensorDataPt->timeStamp);
//update as cmd run
sensorDataPt->run = 1;
}
//unlock mutex
mutexCheck = pthread_mutex_unlock(sensorComsMutexPt);
if (mutexCheck != 0){
exit(-6);
}
}
}