Add the ability to reset a mixer group. Report the remaining buffer size from load_from_buf.

This commit is contained in:
px4dev
2012-12-29 12:58:10 -08:00
parent d5da457e29
commit 6ede0e2f18
2 changed files with 23 additions and 11 deletions
+8 -2
View File
@@ -233,6 +233,11 @@ public:
*/
void add_mixer(Mixer *mixer);
/**
* Remove all the mixers from the group.
*/
void reset();
/**
* Adds mixers to the group based on a text description in a buffer.
*
@@ -269,10 +274,11 @@ public:
* R: <geometry> <roll scale> <pitch scale> <yaw scale> <deadband>
*
* @param buf The mixer configuration buffer.
* @param buflen The length of the buffer.
* @param buflen The length of the buffer, updated to reflect
* bytes as they are consumed.
* @return Zero on successful load, nonzero otherwise.
*/
int load_from_buf(const char *buf, unsigned buflen);
int load_from_buf(const char *buf, unsigned &buflen);
private:
Mixer *_first; /**< linked list of mixers */
+15 -9
View File
@@ -64,14 +64,7 @@ MixerGroup::MixerGroup(ControlCallback control_cb, uintptr_t cb_handle) :
MixerGroup::~MixerGroup()
{
Mixer *mixer;
/* discard sub-mixers */
while (_first != nullptr) {
mixer = _first;
_first = mixer->_next;
delete mixer;
}
reset();
}
void
@@ -88,6 +81,19 @@ MixerGroup::add_mixer(Mixer *mixer)
mixer->_next = nullptr;
}
void
MixerGroup::reset()
{
Mixer *mixer;
/* discard sub-mixers */
while (_first != nullptr) {
mixer = _first;
_first = mixer->_next;
delete mixer;
}
}
unsigned
MixerGroup::mix(float *outputs, unsigned space)
{
@@ -114,7 +120,7 @@ MixerGroup::groups_required(uint32_t &groups)
}
int
MixerGroup::load_from_buf(const char *buf, unsigned buflen)
MixerGroup::load_from_buf(const char *buf, unsigned &buflen)
{
int ret = -1;
const char *end = buf + buflen;