diff --git a/adxl345.c b/adxl345.c index f1f8317..1615d24 100644 --- a/adxl345.c +++ b/adxl345.c @@ -81,29 +81,63 @@ static struct Sample fifo_pop(struct Fifo *f) { // Fonctions ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 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 - pr_info("In adxl345_read function\n"); + //pr_info("In adxl345_read function\n"); // Recuperation de la structure adxl345 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)); - pr_info("Got %i sample in the FIFO\n",nsample); - - struct Sample sample; - int i; - for(i=count; i<0; i--){ - sample = fifo_pop(&(d->fifo)); - pr_info("Sample %i: (%i,%i,%i)\n",i,sample.x,sample.y,sample.z); + // Compute the number of complete samples (6 bytes) to get + nsample = count/6; + rest = count%6; + // Adjust what to get depending on the number of sample in the fifo + if(fifo_len(&(d->fifo))<=nsample){ + nsample = fifo_len(&(d->fifo)); + rest = 0; } + //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;ififo)); + 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