Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
sensor.cpp
- Committer:
- sbarzowski
- Date:
- 2017-01-17
- Revision:
- 33:d3cc00e39e6a
- Parent:
- 29:c2838405fa5c
- Child:
- 47:9e21b199c679
File content as of revision 33:d3cc00e39e6a:
#include "sensor.h"
Sensor::Sensor(SENSOR_TYPE id) : sensor_id_(id) {}
const float DigitalSensor::SEND_INTERVAL = 5.0;
DigitalSensor::DigitalSensor(SENSOR_TYPE id, PinName pin) :
Sensor(id), sensor_(DigitalIn(pin)),
last_state_(false), changes_counter_(0) {
sensor_.mode(PullDown);
}
void DigitalSensor::updateState() {
bool state = sensor_.read();
if (last_state_ != state) {
last_state_ = state;
changes_counter_++;
}
}
Data DigitalSensor::dataToSend() {
return Data(sensor_id_, changes_counter_);
}
void DigitalSensor::resetState() {
changes_counter_ = 0;
}
const float AnalogSensor::SEND_INTERVAL = 3.0;
AnalogSensor::AnalogSensor(SENSOR_TYPE id, PinName pin) :
Sensor(id), sensor_(AnalogIn(pin)) {
}
void AnalogSensor::updateState() {}
Data AnalogSensor::dataToSend() {
float data_read = sensor_.read();
return Data(sensor_id_, data_read);
}
void AnalogSensor::resetState() {}