This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
YASMIN/sensors/dummy/RandomSensor.h
kazu 075d8bb633 a lot!!! of changes
added main menu
added debug display
many debug widgets for plotting live data
worked on android live sensors
added offline-data sensor feeding
some dummy data sensors
worked on the map display
added ui debug for grid-points, particles and weights
added a cool dude to display the estimation
added real filtering based on the Indoor components
c++11 fixes for android compilation
online and offline filtering support
new resampling technique for testing
map loading via dialog
2016-09-16 19:30:04 +02:00

57 lines
994 B
C++

#ifndef RANDOMSENSOR_H
#define RANDOMSENSOR_H
#include <thread>
#include <Indoor/data/Timestamp.h>
#include <Indoor/Assertions.h>
template <typename Element, typename BaseClass> class RandomSensor : public BaseClass {
private:
std::thread thread;
bool running = false;
Timestamp interval;
public:
RandomSensor(const Timestamp interval) : interval(interval) {
;
}
void start() override {
Assert::isFalse(running, "sensor allready running!");
running = true;
thread = std::thread(&RandomSensor::run, this);
}
void stop() override {
Assert::isTrue(running, "sensor not yet running!");
running = false;
thread.join();
}
protected:
/** subclasses must provide a random entry here */
virtual Element getRandomEntry() = 0;
private:
void run() {
while(running) {
const Element rnd = getRandomEntry();
Sensor<Element>::informListeners(rnd);
std::this_thread::sleep_for(std::chrono::milliseconds(interval.ms()));
}
}
};
#endif // RANDOMSENSOR_H