Tici light sensor (#2150)
* more generic sensor base class * add file sensor * light sensor working * correct sensor typepull/2153/head
parent
f02ec4c68e
commit
7cc5710974
8 changed files with 84 additions and 3 deletions
@ -0,0 +1,15 @@ |
||||
#include <iostream> |
||||
#include <string> |
||||
|
||||
#include "file_sensor.hpp" |
||||
|
||||
FileSensor::FileSensor(std::string filename) : file(filename) { |
||||
} |
||||
|
||||
int FileSensor::init() { |
||||
return file.is_open() ? 0 : 1; |
||||
} |
||||
|
||||
FileSensor::~FileSensor(){ |
||||
file.close(); |
||||
} |
@ -0,0 +1,19 @@ |
||||
#pragma once |
||||
|
||||
#include <fstream> |
||||
#include <string> |
||||
|
||||
#include "cereal/gen/cpp/log.capnp.h" |
||||
#include "sensors/sensor.hpp" |
||||
|
||||
|
||||
class FileSensor : public Sensor { |
||||
protected: |
||||
std::ifstream file; |
||||
|
||||
public: |
||||
FileSensor(std::string filename); |
||||
~FileSensor(); |
||||
int init(); |
||||
virtual void get_event(cereal::SensorEventData::Builder &event) = 0; |
||||
}; |
@ -0,0 +1,23 @@ |
||||
#include <iostream> |
||||
#include <string> |
||||
|
||||
#include "common/timing.h" |
||||
|
||||
#include "light_sensor.hpp" |
||||
#include "constants.hpp" |
||||
|
||||
void LightSensor::get_event(cereal::SensorEventData::Builder &event){ |
||||
uint64_t start_time = nanos_since_boot(); |
||||
file.clear(); |
||||
file.seekg(0); |
||||
|
||||
int value; |
||||
file >> value; |
||||
|
||||
event.setSource(cereal::SensorEventData::SensorSource::RPR0521); |
||||
event.setVersion(1); |
||||
event.setSensor(SENSOR_LIGHT); |
||||
event.setType(SENSOR_TYPE_LIGHT); |
||||
event.setTimestamp(start_time); |
||||
event.setLight(value); |
||||
} |
@ -0,0 +1,8 @@ |
||||
#pragma once |
||||
#include "file_sensor.hpp" |
||||
|
||||
class LightSensor : public FileSensor { |
||||
public: |
||||
LightSensor(std::string filename) : FileSensor(filename){}; |
||||
void get_event(cereal::SensorEventData::Builder &event); |
||||
}; |
@ -0,0 +1,9 @@ |
||||
#pragma once |
||||
|
||||
#include "cereal/gen/cpp/log.capnp.h" |
||||
|
||||
class Sensor { |
||||
public: |
||||
virtual int init() = 0; |
||||
virtual void get_event(cereal::SensorEventData::Builder &event) = 0; |
||||
}; |
Loading…
Reference in new issue