adxl345_driver/test_adxl345.c

36 lines
712 B
C

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
const
int main(){
int fd;
char buf[32];
size_t count = 1;
ssize_t ret_size;
if((fd = open("/dev/adxl345", O_RDWR)) == -1){
printf("/dev/adxl345 opening failed\n");
return(0);
}
else{
if((ret_size = read(fd, &buf, count)) < 0){
printf("Error while reading the device file.\n");
return(1);
}
else{
printf("Data read successfully. Asked %i byte, received %i byte\n",count, ret_size);
printf("Data:\n");
for(int i = 0; i<ret_size; i++){
printf("%i",buf[i]);
}
}
}
return(0);
}