-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sensors: add readme with examples #237
Open
niewim19
wants to merge
1
commit into
master
Choose a base branch
from
niewim19/sensormanager_readme
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Sensor manager | ||
|
||
Module provides a basic interface for a variety of sensors. | ||
|
||
Assumptions: | ||
- the client communicates with manager via messages to **/dev/sensors**, | ||
- there is an external library **libsensors** containing sensor structures and message events - external API for the client | ||
- sensors server takes sensors description as arguments list: <sensor_name:bus:others>; arguments might be specific for the sensor driver, | ||
- each sensor registers itself in a sensor manager via constructor, | ||
|
||
# Examples | ||
|
||
|
||
## Server usage | ||
``` sh | ||
sensors -s lsm9dsxx:/dev/spi1.0:argv -s lps25xx:/dev/i2c0` | ||
``` | ||
|
||
## Client app: | ||
|
||
```c | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <sys/ioctl.h> | ||
|
||
#include <libsensors.h> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int fd; | ||
sensors_data_t *data; | ||
unsigned char buff[0x400]; | ||
sensor_type_t types; | ||
sensors_ops_t ops = {0}; | ||
|
||
fd = open("/dev/sensors", O_RDWR); | ||
if (fd < 0) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
/* Get available sensor types */ | ||
ioctl(fd, SMIOC_SENSORSAVAIL, &types); | ||
|
||
/* Define sensor types request */ | ||
ops.types = (types & SENSOR_TYPE_BARO) | (types & SENSOR_TYPE_ACCEL) | (types & SENSOR_TYPE_GYRO); | ||
ioctl(fd, SMIOC_SENSORSSET, &ops); | ||
|
||
if ((ops.evtSz * sizeof(sensor_event_t) + sizeof(((sensors_data_t *)0)->size)) > sizeof(buff)) { | ||
fprintf(stderr, "Buff is too small\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
for (int i = 0; i < 15; ++i) { | ||
sleep(1); | ||
read(fd, buff, 0x600); | ||
|
||
data = (sensors_data_t *)buff; | ||
printf("Sz: %d\n", data->size); | ||
|
||
for (int j = 0; j < data->size; ++j) { | ||
switch (data->events[j].type) { | ||
case SENSOR_TYPE_ACCEL: | ||
printf("Accel, timestamp: %llu\n", data->events[j].timestamp); | ||
printf("acce - x: %u, y: %u, z: %u\n", data->events[j].accels.accelX, data->events[j].accels.accelY, data->events[j].accels.accelZ); | ||
break; | ||
|
||
case SENSOR_TYPE_BARO: | ||
printf("Baro, timestamp: %llu\n", data->events[j].timestamp); | ||
printf("baro - pressure: %u\n", data->events[j].baro.pressure); | ||
break; | ||
|
||
case SENSOR_TYPE_GYRO: | ||
printf("Gyro, timestamp: %llu\n", data->events[j].timestamp); | ||
printf("gyro - x: %u, y: %u, z: %u\n", data->events[j].gyro.gyroX, data->events[j].gyro.gyroY, data->events[j].gyro.gyroZ); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
close(fd); | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
``` | ||
</details> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bus icon has been appeared here ;d
Please escape it.