Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NuttX RTOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
f4grx
NuttX RTOS
Commits
7ba44586
Commit
7ba44586
authored
8 years ago
by
Gregory Nutt
Browse files
Options
Downloads
Patches
Plain Diff
KXJT9: In read(), return multiple samples if the user-provided buffer will hold multiple samples.
parent
c7b917f3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
drivers/sensors/kxjt9.c
+25
-10
25 additions, 10 deletions
drivers/sensors/kxjt9.c
with
25 additions
and
10 deletions
drivers/sensors/kxjt9.c
+
25
−
10
View file @
7ba44586
...
...
@@ -497,17 +497,23 @@ static int kxjt9_close(FAR struct file *filep)
****************************************************************************/
static
ssize_t
kxjt9_read
(
FAR
struct
file
*
filep
,
FAR
char
*
buffer
,
size_t
buflen
)
size_t
buflen
)
{
FAR
struct
inode
*
inode
;
FAR
struct
kxjt9_dev_s
*
priv
;
size_t
nsamples
;
size_t
i
;
int
ret
;
/* If the provided buffer is not large enough to return a sample, then
* return an error.
/* How many samples will fit in the buffer? */
nsamples
=
buflen
/
sizeof
(
struct
kxtj9_sensor_data
);
/* If the provided buffer is not large enough to return a single sample,
* then return an error.
*/
if
(
buf
le
n
<
sizeof
(
struct
kxtj9_sensor_data
)
)
if
(
nsamp
le
s
<
1
)
{
snerr
(
"ERROR: Bufer too small %lu < %u
\n
"
,
buflen
,
sizeof
(
struct
kxtj9_sensor_data
));
...
...
@@ -520,16 +526,25 @@ static ssize_t kxjt9_read(FAR struct file *filep, FAR char *buffer,
priv
=
(
FAR
struct
kxjt9_dev_s
*
)
inode
->
i_private
;
DEBUGASSERT
(
priv
!=
NULL
&&
priv
->
i2c
!=
NULL
);
/*
G
et the sample
data
*/
/*
R
et
urn all of
the sample
s that will fit in the user-provided buffer
*/
ret
=
kxtj9_read_sensor_data
(
priv
,
(
FAR
struct
kxtj9_sensor_data
*
)
buffer
);
if
(
ret
<
0
)
for
(
i
=
0
;
i
<
nsamples
;
i
++
)
{
snerr
(
"ERROR: kxtj9_read_sensor_data failed: %d
\n
"
,
ret
);
return
(
ssize_t
)
ret
;
/* Get the next sample data */
ret
=
kxtj9_read_sensor_data
(
priv
,
(
FAR
struct
kxtj9_sensor_data
*
)
buffer
);
if
(
ret
<
0
)
{
snerr
(
"ERROR: kxtj9_read_sensor_data failed: %d
\n
"
,
ret
);
return
(
ssize_t
)
ret
;
}
/* Set up for the next sample */
buffer
+=
sizeof
(
struct
kxtj9_sensor_data
);
}
return
(
ssize_t
)
sizeof
(
struct
kxtj9_sensor_data
);
return
(
ssize_t
)
(
nsamples
*
sizeof
(
struct
kxtj9_sensor_data
)
)
;
}
/****************************************************************************
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment