mirror of
https://github.com/richardghirst/PiBits.git
synced 2025-02-20 14:54:14 +01:00
Add dev_read() function to driver to allow it to report current settings
for each of the 8 PWMs via /dev/servoblaster.
This commit is contained in:
parent
da669a303d
commit
fd2d771d1e
@ -323,7 +323,55 @@ static int dev_open(struct inode *inod,struct file *fil)
|
||||
|
||||
static ssize_t dev_read(struct file *filp,char *buf,size_t count,loff_t *f_pos)
|
||||
{
|
||||
#if 0
|
||||
int servo;
|
||||
static int idx=0;
|
||||
// Allow 10 chars per line:
|
||||
static char returnedData[NUM_SERVOS * 10] = {0};
|
||||
|
||||
if (0 == *f_pos)
|
||||
{
|
||||
// Get fresh data
|
||||
for (servo=0, idx=0; servo < NUM_SERVOS; ++servo)
|
||||
{
|
||||
if (wait_for_servo(servo))
|
||||
return -EINTR;
|
||||
|
||||
idx += snprintf(returnedData+idx, sizeof(returnedData)-idx,
|
||||
"%i %lu\n",
|
||||
servo,
|
||||
ctl->cb[servo*4+1].length / sizeof(uint32_t)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (*f_pos >= idx)
|
||||
{
|
||||
//EOF
|
||||
return 0;
|
||||
}
|
||||
else if ( (*f_pos + count) < idx )
|
||||
{
|
||||
// Sufficient data to fulfil request
|
||||
if (copy_to_user(buf,returnedData+fpos,count) {
|
||||
return -EFAULT;
|
||||
}
|
||||
*f_pos+=count;
|
||||
return count;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return all the data we have
|
||||
const int nBytes = idx-*f_pos;
|
||||
if (copy_to_user(buf,returnedData+*f_pos, nBytes) {
|
||||
return -EFAULT;
|
||||
}
|
||||
*f_pos+=nBytes;
|
||||
return nBytes;
|
||||
}
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static ssize_t dev_write(struct file *filp,const char *buf,size_t count,loff_t *f_pos)
|
||||
|
Loading…
x
Reference in New Issue
Block a user