本文整理汇总了C++中Sensor::read方法的典型用法代码示例。如果您正苦于以下问题:C++ Sensor::read方法的具体用法?C++ Sensor::read怎么用?C++ Sensor::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sensor
的用法示例。
在下文中一共展示了Sensor::read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
float threshold = 2.5;
unsigned int numSamples = 10000;
Sensor * s = new Sensor(threshold);
s->read(numSamples);
delete s;
return 0;
}
示例2:
/**
* Record data from a single Sensor; to be run in a seperate thread
* @param arg - Cast to Sensor* - Sensor that the thread will handle
* @returns NULL (void* required to use the function with pthreads)
*/
void * Sensor_Loop(void * arg)
{
Sensor * s = (Sensor*)(arg);
Log(LOGDEBUG, "Sensor %d starts", s->id);
// Until the sensor is stopped, record data points
while (s->activated)
{
bool success = s->read(s->user_id, &(s->current_data.value));
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
s->current_data.time_stamp = TIMEVAL_DIFF(t, *Control_GetStartTime());
if (success)
{
if (s->sanity != NULL)
{
if (!s->sanity(s->user_id, s->current_data.value))
{
Fatal("Sensor %s (%d,%d) reads unsafe value", s->name, s->id, s->user_id);
}
}
s->averaged_data.time_stamp += s->current_data.time_stamp;
s->averaged_data.value = s->current_data.value;
if (++(s->num_read) >= s->averages)
{
s->averaged_data.time_stamp /= s->averages;
s->averaged_data.value /= s->averages;
Data_Save(&(s->data_file), &(s->averaged_data), 1); // Record it
s->num_read = 0;
s->averaged_data.time_stamp = 0;
s->averaged_data.value = 0;
}
}
else
{
// Silence because strain sensors fail ~50% of the time :S
//Log(LOGWARN, "Failed to read sensor %s (%d,%d)", s->name, s->id,s->user_id);
}
clock_nanosleep(CLOCK_MONOTONIC, 0, &(s->sample_time), NULL);
}
// Needed to keep pthreads happy
Log(LOGDEBUG, "Sensor %s (%d,%d) finished", s->name,s->id,s->user_id);
return NULL;
}
示例3: readSensors
void Aquaduino::readSensors() {
int8_t sensorIdx;
Sensor* currentSensor;
for (sensorIdx = 0; sensorIdx < MAX_SENSORS; sensorIdx++) {
currentSensor = m_Sensors.get(sensorIdx);
if (currentSensor) {
m_SensorReadings[sensorIdx] = currentSensor->read();
m_XiveleyDatastreams[sensorIdx]->setFloat(
m_SensorReadings[sensorIdx]);
} else {
m_SensorReadings[sensorIdx] = 0.0;
m_XiveleyDatastreams[sensorIdx]->setFloat(0.0);
}
}
}