* Returns the array of samples rather than their sum.
* Hard coded to work with uint16_t samples.
- * 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 <smckown@gmail.com>
*/
#include <Msp430Adc12.h>
*
* @author R. Steve McKown <smckown@gmail.com>
*/
#include <Msp430Adc12.h>
-generic configuration MultiSampleC(typedef val_t @integer(), uint16_t count) {
+generic configuration MultiSampleC(uint16_t count) {
provides {
interface Get<uint16_t> as Count;
provides {
interface Get<uint16_t> as Count;
+ interface ReadRef<uint16_t>;
}
uses interface AdcConfigure<const msp430adc12_channel_config_t*>;
}
implementation {
}
uses interface AdcConfigure<const msp430adc12_channel_config_t*>;
}
implementation {
- components new MultiSampleP(val_t, count);
+ components new MultiSampleP(count);
+ ReadRef = MultiSampleP;
components new AdcReadStreamClientC();
AdcConfigure = AdcReadStreamClientC;
components new AdcReadStreamClientC();
AdcConfigure = AdcReadStreamClientC;
- * 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 <smckown@gmail.com>
*/
*
* @author R. Steve McKown <smckown@gmail.com>
*/
-generic module MultiSampleP(typedef val_t @integer(), uint16_t count) @safe()
+generic module MultiSampleP(uint16_t count) @safe()
{
provides {
interface Get<uint16_t> as Count;
{
provides {
interface Get<uint16_t> as Count;
+ interface ReadRef<uint16_t>;
}
uses interface ReadStream<uint16_t>;
}
implementation
{
}
uses interface ReadStream<uint16_t>;
}
implementation
{
- bool busy;
- uint16_t values[count];
command uint16_t Count.get()
{
return count;
}
command uint16_t Count.get()
{
return count;
}
- command error_t Read.read()
+ command error_t ReadRef.read(uint16_t* array)
- 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 SUCCESS;
}
void signalReadDone(error_t error)
{
return SUCCESS;
}
void signalReadDone(error_t error)
{
+ 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,
}
event void ReadStream.bufferDone(error_t error, uint16_t* buf,