Last active
December 14, 2015 18:49
-
-
Save johnliu/5132219 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
struct dev_orientation { | |
int azimuth; /* angle between the magnetic north and the Y axis, | |
around the Z axis (0 <= azimuth < 360) | |
0 = north, 90 = east, 180 = south, 270 = west */ | |
int pitch; /* rotation around the X-axis: -180 <= pitch <= 180 */ | |
int roll; /* rotation around the Y-axis: +Y == -roll, | |
-90 <= roll <= 90 */ | |
}; | |
struct orientation_range { | |
struct dev_orientation orient; /* device orientation */ | |
unsigned int azimuth_range; /* +/- degrees around Z axis */ | |
unsigned int pitch_range; /* +/- degrees around X axis */ | |
unsigned int roll_range; /* +/- degrees around Y axis */ | |
}; | |
/* The orientation range to set. */ | |
struct orientation_range range = { | |
.orient = { | |
.azimuth = 50, | |
.pitch = 30, | |
.roll = 25 | |
}, | |
.azimuth_range = 5, | |
.pitch_range = 5, | |
.roll_range = 5 | |
}; | |
int reader = 0; | |
int main(int argc, char **argv) { | |
int delay = 0; | |
char *name; | |
/* Get input from user for a name and reader/writer */ | |
if (argc == 3 || argc == 4) { | |
if (argv[1][0] == 'r') { | |
reader = 1; | |
} else if (argv[1][0] == 'w') { | |
reader = 0; | |
} else { | |
printf("usage: ./test [r|w] <name>\n"); | |
} | |
name = argv[2]; | |
if (argc == 4) { | |
delay = 1; | |
} | |
} else { | |
printf("usage: ./test [r|w] <name>\n"); | |
} | |
while (1) { | |
long error; | |
printf("%s about to acquire the lock.\n", name); | |
if (reader) syscall(363, &range); /* read lock */ | |
else syscall(364, &range); /* write lock */ | |
printf("%s acquired lock!\n", name); | |
sleep(2); | |
if (reader) syscall(365, &range); /* read unlock */ | |
else syscall(366, &range); /* write unlock */ | |
if (delay) sleep(2); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment