30 lines
681 B
C++
30 lines
681 B
C++
#include "TouchSensor.h"
|
|
|
|
namespace RoboidControl {
|
|
|
|
TouchSensor::TouchSensor(Thing* parent) : Thing(Type::TouchSensor, parent) {
|
|
this->name = "Touch sensor";
|
|
}
|
|
|
|
void TouchSensor::PrepareForUpdate() {
|
|
this->touchedSomething = this->externalTouch;
|
|
}
|
|
|
|
void TouchSensor::Update(bool recursive) {
|
|
Thing::Update(recursive);
|
|
}
|
|
|
|
int TouchSensor::GenerateBinary(char* bytes, unsigned char* ix) {
|
|
bytes[(*ix)++] = this->touchedSomething ? 1 : 0;
|
|
return 1;
|
|
}
|
|
|
|
void TouchSensor::ProcessBinary(char* bytes) {
|
|
this->externalTouch = (bytes[0] == 1);
|
|
if (this->externalTouch)
|
|
std::cout << "touching!\n";
|
|
else
|
|
std::cout << "not touching\n";
|
|
}
|
|
|
|
} // namespace RoboidControl
|