Oled implementation (#1)

This commit is contained in:
2026-02-07 15:05:45 -05:00
committed by GitHub
parent 048e39016a
commit 33c3ebad53
46 changed files with 1790 additions and 1260 deletions

View File

@@ -14,15 +14,15 @@
namespace Flatbuffers {
class AngleControlMessageBuilder {
public:
AngleControlMessageBuilder() : builder_(256) {
}
public:
AngleControlMessageBuilder() : builder_(256) {}
SerializedMessage build_angle_control_message(int16_t angle);
static const Messaging::AngleControlMessage *parse_angle_control_message(const uint8_t *buffer);
SerializedMessage build_angle_control_message(int16_t angle);
static const Messaging::AngleControlMessage *
parse_angle_control_message(const uint8_t *buffer);
private:
flatbuffers::FlatBufferBuilder builder_;
private:
flatbuffers::FlatBufferBuilder builder_;
};
} // namespace Flatbuffers

View File

@@ -12,33 +12,32 @@
namespace Flatbuffers {
struct ModuleInstance {
uint8_t id;
ModuleType type;
int angle;
uint8_t id;
ModuleType type;
int angle;
};
struct ModuleConnectionInstance {
uint8_t from_module_id;
uint8_t to_module_id;
uint8_t from_socket;
uint8_t to_socket;
Orientation orientation;
uint8_t from_module_id;
uint8_t to_module_id;
uint8_t from_socket;
uint8_t to_socket;
Orientation orientation;
};
class RobotConfigurationBuilder {
public:
RobotConfigurationBuilder() : builder_(1024) {
}
public:
RobotConfigurationBuilder() : builder_(1024) {}
SerializedMessage
build_robot_configuration(const std::vector<ModuleInstance> &modules,
const std::vector<ModuleConnectionInstance> &connections);
SerializedMessage build_robot_configuration(
const std::vector<ModuleInstance> &modules,
const std::vector<ModuleConnectionInstance> &connections);
static const Frontend::RobotConfiguration *
parse_robot_configuration(const std::uint8_t *buffer);
static const Frontend::RobotConfiguration *
parse_robot_configuration(const std::uint8_t *buffer);
private:
flatbuffers::FlatBufferBuilder builder_;
private:
flatbuffers::FlatBufferBuilder builder_;
};
} // namespace Flatbuffers

View File

@@ -5,6 +5,7 @@
#ifndef SENSORMESSAGEBUILDER_H
#define SENSORMESSAGEBUILDER_H
#include <string>
#include <variant>
#include "flatbuffers_generated/SensorMessage_generated.h"
@@ -12,42 +13,52 @@
namespace Flatbuffers {
struct target_angle {
int16_t angle;
int16_t angle;
};
struct current_angle {
int16_t angle;
int16_t angle;
};
typedef std::variant<target_angle, current_angle> sensor_value;
struct current_text {
std::string text;
};
typedef std::variant<target_angle, current_angle, current_text> sensor_value;
class SensorMessageBuilder {
public:
SensorMessageBuilder() : builder_(1024) {
public:
SensorMessageBuilder() : builder_(1024) {}
static const Messaging::SensorMessage *
parse_sensor_message(const std::uint8_t *buffer);
template <typename T>
static std::optional<sensor_value>
build_sensor_value(Messaging::SensorValue type, T value) {
switch (type) {
case Messaging::SensorValue_TargetAngle: {
const Messaging::TargetAngle *target =
static_cast<const Messaging::TargetAngle *>(value);
return target_angle{target->value()};
}
static const Messaging::SensorMessage *parse_sensor_message(const std::uint8_t *buffer);
template <typename T>
static std::optional<sensor_value> build_sensor_value(Messaging::SensorValue type, T value) {
switch (type) {
case Messaging::SensorValue_TargetAngle: {
const Messaging::TargetAngle *target =
static_cast<const Messaging::TargetAngle *>(value);
return target_angle{target->value()};
}
case Messaging::SensorValue_CurrentAngle: {
const Messaging::CurrentAngle *current =
static_cast<const Messaging::CurrentAngle *>(value);
return current_angle{current->value()};
}
default:
return std::nullopt;
}
case Messaging::SensorValue_CurrentAngle: {
const Messaging::CurrentAngle *current =
static_cast<const Messaging::CurrentAngle *>(value);
return current_angle{current->value()};
}
case Messaging::SensorValue_CurrentText: {
const Messaging::CurrentText *current =
static_cast<const Messaging::CurrentText *>(value);
return current_text{current->value()->str()};
}
default:
return std::nullopt;
}
}
private:
flatbuffers::FlatBufferBuilder builder_;
private:
flatbuffers::FlatBufferBuilder builder_;
};
} // namespace Flatbuffers

View File

@@ -9,8 +9,8 @@
namespace Flatbuffers {
struct SerializedMessage {
void *data;
size_t size;
void *data;
size_t size;
};
} // namespace Flatbuffers

View File

@@ -0,0 +1,27 @@
//
// Created by Johnathon Slightham on 2025-06-30.
//
#ifndef TEXTCONTROLMESSAGEBUILDER_H_
#define TEXTCONTROLMESSAGEBUILDER_H_
#include <string>
#include <vector>
#include "SerializedMessage.h"
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers_generated/TextControlMessage_generated.h"
namespace Flatbuffers {
class TextControlMessageBuilder {
public:
TextControlMessageBuilder() : builder_(256) {}
SerializedMessage build_text_control_message(std::string &t);
private:
flatbuffers::FlatBufferBuilder builder_;
};
} // namespace Flatbuffers
#endif

View File

@@ -12,20 +12,21 @@
namespace Flatbuffers {
class TopologyMessageBuilder {
public:
TopologyMessageBuilder() : builder_(1024) {
}
public:
TopologyMessageBuilder() : builder_(1024) {}
SerializedMessage build_topology_message(uint8_t module_id, ModuleType module_type,
const std::vector<uint8_t> &channel_to_module,
const std::vector<int8_t> &orientation_to_module);
SerializedMessage
build_topology_message(uint8_t module_id, ModuleType module_type,
const std::vector<uint8_t> &channel_to_module,
const std::vector<int8_t> &orientation_to_module);
static const Messaging::TopologyMessage *parse_topology_message(const uint8_t *buffer);
static const Messaging::TopologyMessage *
parse_topology_message(const uint8_t *buffer);
static bool is_valid_topology_message(const uint8_t *buffer, size_t size);
static bool is_valid_topology_message(const uint8_t *buffer, size_t size);
private:
flatbuffers::FlatBufferBuilder builder_;
private:
flatbuffers::FlatBufferBuilder builder_;
};
} // namespace Flatbuffers