From 924c646126a4cc643fdf90dce88e98e487bcf9eb Mon Sep 17 00:00:00 2001 From: smckown Date: Mon, 9 Nov 2009 19:30:53 +0000 Subject: [PATCH] Changes to MultiSampleC * Returns the array of samples rather than their sum. * Hard coded to work with uint16_t samples. --- tos/platforms/tmirws/sensors/MultiSampleC.nc | 12 +++---- tos/platforms/tmirws/sensors/MultiSampleP.nc | 37 ++++++++------------ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/tos/platforms/tmirws/sensors/MultiSampleC.nc b/tos/platforms/tmirws/sensors/MultiSampleC.nc index 50069c86..ac9c3c4c 100644 --- a/tos/platforms/tmirws/sensors/MultiSampleC.nc +++ b/tos/platforms/tmirws/sensors/MultiSampleC.nc @@ -28,25 +28,25 @@ */ /** - * A generic component that multiply samples via the ADC, returning the sum of - * ADC sample values. + * A generic component that multiply samples via the ADC, returning an array + * of ADC results. * * @author R. Steve McKown */ #include -generic configuration MultiSampleC(typedef val_t @integer(), uint16_t count) { +generic configuration MultiSampleC(uint16_t count) { provides { interface Get as Count; - interface Read; + interface ReadRef; } uses interface AdcConfigure; } implementation { - components new MultiSampleP(val_t, count); + components new MultiSampleP(count); Count = MultiSampleP; - Read = MultiSampleP; + ReadRef = MultiSampleP; components new AdcReadStreamClientC(); AdcConfigure = AdcReadStreamClientC; diff --git a/tos/platforms/tmirws/sensors/MultiSampleP.nc b/tos/platforms/tmirws/sensors/MultiSampleP.nc index 031f4ba2..79714ad8 100644 --- a/tos/platforms/tmirws/sensors/MultiSampleP.nc +++ b/tos/platforms/tmirws/sensors/MultiSampleP.nc @@ -28,56 +28,49 @@ */ /** - * A generic component that multiply samples via the ADC, returning the sum of - * ADC sample values. + * A generic component that multiply samples via the ADC, returning an array + * of ADC results. * * @author R. Steve McKown */ -generic module MultiSampleP(typedef val_t @integer(), uint16_t count) @safe() +generic module MultiSampleP(uint16_t count) @safe() { provides { interface Get as Count; - interface Read; + interface ReadRef; } uses interface ReadStream; } implementation { - bool busy; - uint16_t values[count]; + uint16_t* m_array; command uint16_t Count.get() { return count; } - command error_t Read.read() + command error_t ReadRef.read(uint16_t* array) { - if (busy) + if (m_array) return EBUSY; - if (call ReadStream.postBuffer(values, count) != SUCCESS || - call ReadStream.read(0) != SUCCESS) + m_array = array; + if (call ReadStream.postBuffer(m_array, count) != SUCCESS || + call ReadStream.read(0) != SUCCESS) { + m_array = NULL; return FAIL; - - busy = TRUE; + } return SUCCESS; } void signalReadDone(error_t error) { - val_t sum = 0; + uint16_t* tmp = m_array; - if (error == SUCCESS) { - uint16_t i; - - /* Average all the incoming readings */ - for (i = 0; i < count; i++) - sum += values[i]; - } - busy = FALSE; - signal Read.readDone(error, sum); + m_array = NULL; + signal ReadRef.readDone(error, tmp); } event void ReadStream.bufferDone(error_t error, uint16_t* buf, -- 2.39.2