recuperation des sample par l'application de test
This commit is contained in:
parent
506893ab2b
commit
a9a94282f8
2 changed files with 46 additions and 12 deletions
58
adxl345.c
58
adxl345.c
|
@ -81,29 +81,63 @@ static struct Sample fifo_pop(struct Fifo *f) {
|
||||||
// Fonctions ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
// Fonctions ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
ssize_t adxl345_read(struct file *file, char __user *buf, size_t count, loff_t *f_pos){
|
ssize_t adxl345_read(struct file *file, char __user *buf, size_t count, loff_t *f_pos){
|
||||||
|
|
||||||
|
char nsample;
|
||||||
|
char rest;
|
||||||
|
unsigned char res[count];
|
||||||
|
int i=0;
|
||||||
|
int16_t direction_sample;
|
||||||
|
struct Sample sample;
|
||||||
|
|
||||||
// TODO: permetre de choisir l'axe de lecture
|
// TODO: permetre de choisir l'axe de lecture
|
||||||
pr_info("In adxl345_read function\n");
|
//pr_info("In adxl345_read function\n");
|
||||||
|
|
||||||
// Recuperation de la structure adxl345
|
// Recuperation de la structure adxl345
|
||||||
struct adxl345_device *d = container_of(file->private_data,struct adxl345_device,miscdev);
|
struct adxl345_device *d = container_of(file->private_data,struct adxl345_device,miscdev);
|
||||||
pr_info("Got pointer to adxl345_device structure\n");
|
//pr_info("Got pointer to adxl345_device structure\n");
|
||||||
|
|
||||||
int nsample = fifo_len(&(d->fifo));
|
// Compute the number of complete samples (6 bytes) to get
|
||||||
pr_info("Got %i sample in the FIFO\n",nsample);
|
nsample = count/6;
|
||||||
|
rest = count%6;
|
||||||
struct Sample sample;
|
// Adjust what to get depending on the number of sample in the fifo
|
||||||
int i;
|
if(fifo_len(&(d->fifo))<=nsample){
|
||||||
for(i=count; i<0; i--){
|
nsample = fifo_len(&(d->fifo));
|
||||||
sample = fifo_pop(&(d->fifo));
|
rest = 0;
|
||||||
pr_info("Sample %i: (%i,%i,%i)\n",i,sample.x,sample.y,sample.z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pr_info("%i sample in fifo\nGetting %i full sample ans %i more bytes\n",fifo_len(&(d->fifo)),nsample,rest);
|
||||||
|
|
||||||
|
// Get the full samples
|
||||||
|
for(i=0;i<nsample;i++){
|
||||||
|
//pr_info("Getting sample %i\n",i);
|
||||||
|
sample = fifo_pop(&(d->fifo));
|
||||||
|
res[i*6+1] = (unsigned char) (sample.x>>8);
|
||||||
|
res[i*6+0] = (unsigned char) (sample.x & 0x00ff);
|
||||||
|
res[i*6+3] = (unsigned char) (sample.y>>8);
|
||||||
|
res[i*6+2] = (unsigned char) (sample.y & 0x00ff);
|
||||||
|
res[i*6+5] = (unsigned char) (sample.z>>8);
|
||||||
|
res[i*6+4] = (unsigned char) (sample.z & 0x00ff);
|
||||||
|
//pr_info("%i %i %i\n",sample.x,sample.y,sample.z);
|
||||||
|
//pr_info("%x %x %x %x\n",res[i], res[i+1], res[i+2],res[i+3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the rest
|
||||||
|
sample = fifo_pop(&(d->fifo));
|
||||||
|
for(i=nsample*6;i<nsample*6+rest;i++){
|
||||||
|
//pr_info("Getting Byte %i/%i\n",i,nsample*6+rest);
|
||||||
|
// Get the correct direction
|
||||||
|
if(i-nsample*6<2){direction_sample = sample.x;} // X
|
||||||
|
else if(i-nsample*6<4){direction_sample = sample.y;} // Y
|
||||||
|
else{direction_sample = sample.z;} // Z
|
||||||
|
// Extract the correct byte from the direction sample
|
||||||
|
res[i] = direction_sample & (0xff<<(i%2)*2);
|
||||||
|
}
|
||||||
|
|
||||||
// Ecriture du resultat dans le buffer de retour
|
// Ecriture du resultat dans le buffer de retour
|
||||||
//copy_to_user(buf, response, 1);
|
//pr_info("%x %x %x %x\n",res[3], res[2], res[1],res[0]);
|
||||||
|
copy_to_user(buf, res, nsample*6+rest);
|
||||||
|
|
||||||
return (ssize_t)1;
|
return (ssize_t)nsample*6+rest;
|
||||||
}
|
}
|
||||||
|
|
||||||
irq_handler_t adxl345_int(int irq, struct adxl345_device * d){
|
irq_handler_t adxl345_int(int irq, struct adxl345_device * d){
|
||||||
|
|
BIN
test_adxl345
Executable file
BIN
test_adxl345
Executable file
Binary file not shown.
Loading…
Reference in a new issue