diff options
author | px4dev <px4@purgatory.org> | 2012-08-05 16:30:28 -0700 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2012-08-05 16:30:28 -0700 |
commit | 59962bc3da97a102117e3d4e5c90b9062beb7180 (patch) | |
tree | cef041b92b6da8216e305e54298f3a0ba24b464e /apps/systemlib/mixer.c | |
parent | ae91f8338d227325e93098abf46b3ce9ef85e909 (diff) | |
download | px4-firmware-59962bc3da97a102117e3d4e5c90b9062beb7180.tar.gz px4-firmware-59962bc3da97a102117e3d4e5c90b9062beb7180.tar.bz2 px4-firmware-59962bc3da97a102117e3d4e5c90b9062beb7180.zip |
Add a sample mixer definition and documentation.
Add support for comments in mixer definitions.
Diffstat (limited to 'apps/systemlib/mixer.c')
-rw-r--r-- | apps/systemlib/mixer.c | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/apps/systemlib/mixer.c b/apps/systemlib/mixer.c index 8b1dcc054..25cf80160 100644 --- a/apps/systemlib/mixer.c +++ b/apps/systemlib/mixer.c @@ -163,29 +163,43 @@ mixer_mix(struct mixer_s *mixer, float **controls) static int mixer_getline(int fd, char *line, unsigned maxlen) { - int ret; - char c; - - while (--maxlen) { - ret = read(fd, &c, 1); - - if (ret <= 0) - return ret; - - if (c == '\r') - continue; - - if (c == '\n') { - *line = '\0'; - return 1; + /* reduce line budget by 1 to account for terminal NUL */ + maxlen--; + + /* loop looking for a non-comment line */ + for (;;) { + int ret; + char c; + char *p = line; + + /* loop reading characters for this line */ + for (;;) { + ret = read(fd, &c, 1); + + /* on error or EOF, return same */ + if (ret <= 0) + return ret; + + /* ignore carriage returns */ + if (c == '\r') + continue; + + /* line termination */ + if (c == '\n') { + /* ignore malformed lines */ + if (line[1] != ':') + break; + + /* terminate line as string and return */ + *p = '\0'; + return 1; + } + + /* if we have space, accumulate the byte and go on */ + if ((p - line) < maxlen) + *p++ = c; } - - *line++ = c; } - - /* line too long */ - puts("line too long"); - return -1; } static int @@ -214,7 +228,7 @@ mixer_load(int fd, struct mixer_s **mp) { int ret, result = -1; struct mixer_s *mixer = NULL; - char buf[100]; + char buf[60]; unsigned scalers; ret = mixer_getline(fd, buf, sizeof(buf)); |