mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 09:37:21 +02:00
Add distance sensor, rewrite OLED to use new i2c library
This commit is contained in:
@@ -30,6 +30,18 @@ SerializedMessage SensorMessageBuilder::build_sensor_message(std::vector<sensor_
|
||||
auto text_offset = builder_.CreateString(t.text);
|
||||
values_vec.push_back(Messaging::CreateCurrentText(builder_, text_offset).Union());
|
||||
sensor_values_vec.push_back(Messaging::SensorValue_CurrentText);
|
||||
},
|
||||
[&](distance d) {
|
||||
values_vec.push_back(Messaging::CreateDistance(builder_, d.distance).Union());
|
||||
sensor_values_vec.push_back(Messaging::SensorValue_Distance);
|
||||
},
|
||||
[&](temperature t) {
|
||||
values_vec.push_back(Messaging::CreateTemperature(builder_, t.temperature).Union());
|
||||
sensor_values_vec.push_back(Messaging::SensorValue_Temperature);
|
||||
},
|
||||
[&](position p) {
|
||||
values_vec.push_back(Messaging::CreatePosition(builder_, p.heading, p.pitch, p.roll).Union());
|
||||
sensor_values_vec.push_back(Messaging::SensorValue_Temperature);
|
||||
}
|
||||
},
|
||||
v);
|
||||
|
||||
@@ -19,7 +19,21 @@ struct target_text {
|
||||
std::string text;
|
||||
};
|
||||
|
||||
typedef std::variant<target_angle, current_angle, target_text> sensor_value;
|
||||
struct distance {
|
||||
float distance;
|
||||
};
|
||||
|
||||
struct temperature {
|
||||
float temperature;
|
||||
};
|
||||
|
||||
struct position {
|
||||
float heading;
|
||||
float pitch;
|
||||
float roll;
|
||||
};
|
||||
|
||||
typedef std::variant<target_angle, current_angle, target_text, distance, temperature, position> sensor_value;
|
||||
|
||||
class SensorMessageBuilder {
|
||||
public:
|
||||
|
||||
@@ -24,6 +24,15 @@ struct CurrentTextBuilder;
|
||||
struct CurrentAngle;
|
||||
struct CurrentAngleBuilder;
|
||||
|
||||
struct Distance;
|
||||
struct DistanceBuilder;
|
||||
|
||||
struct Temperature;
|
||||
struct TemperatureBuilder;
|
||||
|
||||
struct Position;
|
||||
struct PositionBuilder;
|
||||
|
||||
struct SensorMessage;
|
||||
struct SensorMessageBuilder;
|
||||
|
||||
@@ -32,33 +41,42 @@ enum SensorValue : uint8_t {
|
||||
SensorValue_TargetAngle = 1,
|
||||
SensorValue_CurrentAngle = 2,
|
||||
SensorValue_CurrentText = 3,
|
||||
SensorValue_Distance = 4,
|
||||
SensorValue_Temperature = 5,
|
||||
SensorValue_Position = 6,
|
||||
SensorValue_MIN = SensorValue_NONE,
|
||||
SensorValue_MAX = SensorValue_CurrentText
|
||||
SensorValue_MAX = SensorValue_Position
|
||||
};
|
||||
|
||||
inline const SensorValue (&EnumValuesSensorValue())[4] {
|
||||
inline const SensorValue (&EnumValuesSensorValue())[7] {
|
||||
static const SensorValue values[] = {
|
||||
SensorValue_NONE,
|
||||
SensorValue_TargetAngle,
|
||||
SensorValue_CurrentAngle,
|
||||
SensorValue_CurrentText
|
||||
SensorValue_CurrentText,
|
||||
SensorValue_Distance,
|
||||
SensorValue_Temperature,
|
||||
SensorValue_Position
|
||||
};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char * const *EnumNamesSensorValue() {
|
||||
static const char * const names[5] = {
|
||||
static const char * const names[8] = {
|
||||
"NONE",
|
||||
"TargetAngle",
|
||||
"CurrentAngle",
|
||||
"CurrentText",
|
||||
"Distance",
|
||||
"Temperature",
|
||||
"Position",
|
||||
nullptr
|
||||
};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameSensorValue(SensorValue e) {
|
||||
if (::flatbuffers::IsOutRange(e, SensorValue_NONE, SensorValue_CurrentText)) return "";
|
||||
if (::flatbuffers::IsOutRange(e, SensorValue_NONE, SensorValue_Position)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesSensorValue()[index];
|
||||
}
|
||||
@@ -79,6 +97,18 @@ template<> struct SensorValueTraits<Messaging::CurrentText> {
|
||||
static const SensorValue enum_value = SensorValue_CurrentText;
|
||||
};
|
||||
|
||||
template<> struct SensorValueTraits<Messaging::Distance> {
|
||||
static const SensorValue enum_value = SensorValue_Distance;
|
||||
};
|
||||
|
||||
template<> struct SensorValueTraits<Messaging::Temperature> {
|
||||
static const SensorValue enum_value = SensorValue_Temperature;
|
||||
};
|
||||
|
||||
template<> struct SensorValueTraits<Messaging::Position> {
|
||||
static const SensorValue enum_value = SensorValue_Position;
|
||||
};
|
||||
|
||||
bool VerifySensorValue(::flatbuffers::Verifier &verifier, const void *obj, SensorValue type);
|
||||
bool VerifySensorValueVector(::flatbuffers::Verifier &verifier, const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values, const ::flatbuffers::Vector<uint8_t> *types);
|
||||
|
||||
@@ -215,6 +245,149 @@ inline ::flatbuffers::Offset<CurrentAngle> CreateCurrentAngle(
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct Distance FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef DistanceBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_VALUE = 4
|
||||
};
|
||||
float value() const {
|
||||
return GetField<float>(VT_VALUE, 0.0f);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<float>(verifier, VT_VALUE, 4) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct DistanceBuilder {
|
||||
typedef Distance Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_value(float value) {
|
||||
fbb_.AddElement<float>(Distance::VT_VALUE, value, 0.0f);
|
||||
}
|
||||
explicit DistanceBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<Distance> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<Distance>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<Distance> CreateDistance(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
float value = 0.0f) {
|
||||
DistanceBuilder builder_(_fbb);
|
||||
builder_.add_value(value);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct Temperature FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef TemperatureBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_VALUE = 4
|
||||
};
|
||||
float value() const {
|
||||
return GetField<float>(VT_VALUE, 0.0f);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<float>(verifier, VT_VALUE, 4) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct TemperatureBuilder {
|
||||
typedef Temperature Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_value(float value) {
|
||||
fbb_.AddElement<float>(Temperature::VT_VALUE, value, 0.0f);
|
||||
}
|
||||
explicit TemperatureBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<Temperature> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<Temperature>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<Temperature> CreateTemperature(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
float value = 0.0f) {
|
||||
TemperatureBuilder builder_(_fbb);
|
||||
builder_.add_value(value);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct Position FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef PositionBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_HEADING = 4,
|
||||
VT_PITCH = 6,
|
||||
VT_ROLL = 8
|
||||
};
|
||||
float heading() const {
|
||||
return GetField<float>(VT_HEADING, 0.0f);
|
||||
}
|
||||
float pitch() const {
|
||||
return GetField<float>(VT_PITCH, 0.0f);
|
||||
}
|
||||
float roll() const {
|
||||
return GetField<float>(VT_ROLL, 0.0f);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<float>(verifier, VT_HEADING, 4) &&
|
||||
VerifyField<float>(verifier, VT_PITCH, 4) &&
|
||||
VerifyField<float>(verifier, VT_ROLL, 4) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct PositionBuilder {
|
||||
typedef Position Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_heading(float heading) {
|
||||
fbb_.AddElement<float>(Position::VT_HEADING, heading, 0.0f);
|
||||
}
|
||||
void add_pitch(float pitch) {
|
||||
fbb_.AddElement<float>(Position::VT_PITCH, pitch, 0.0f);
|
||||
}
|
||||
void add_roll(float roll) {
|
||||
fbb_.AddElement<float>(Position::VT_ROLL, roll, 0.0f);
|
||||
}
|
||||
explicit PositionBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<Position> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<Position>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<Position> CreatePosition(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
float heading = 0.0f,
|
||||
float pitch = 0.0f,
|
||||
float roll = 0.0f) {
|
||||
PositionBuilder builder_(_fbb);
|
||||
builder_.add_roll(roll);
|
||||
builder_.add_pitch(pitch);
|
||||
builder_.add_heading(heading);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct SensorMessage FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef SensorMessageBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
@@ -298,6 +471,18 @@ inline bool VerifySensorValue(::flatbuffers::Verifier &verifier, const void *obj
|
||||
auto ptr = reinterpret_cast<const Messaging::CurrentText *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
case SensorValue_Distance: {
|
||||
auto ptr = reinterpret_cast<const Messaging::Distance *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
case SensorValue_Temperature: {
|
||||
auto ptr = reinterpret_cast<const Messaging::Temperature *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
case SensorValue_Position: {
|
||||
auto ptr = reinterpret_cast<const Messaging::Position *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user