mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 17:47:21 +02:00
Display control code
This commit is contained in:
@@ -17,7 +17,7 @@ else()
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS ${ALL_SRCS}
|
||||
PRIV_REQUIRES esp_psram spi_flash nvs_flash esp_event rpc constants config rmt esp_driver_gptimer dataLink flatbuffers esp_driver_ledc
|
||||
PRIV_REQUIRES esp_psram spi_flash nvs_flash esp_event rpc constants config rmt esp_driver_gptimer dataLink flatbuffers esp_driver_ledc oled
|
||||
INCLUDE_DIRS "include")
|
||||
|
||||
if(DEFINED SRC_BOARD AND SRC_BOARD)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "control/ActuatorFactory.h"
|
||||
#include "control/DCMotorActuator.h"
|
||||
#include "control/Servo1Actuator.h"
|
||||
#include "control/OledActuator.h"
|
||||
#include "flatbuffers_generated/RobotModule_generated.h"
|
||||
|
||||
std::unique_ptr<IActuator>
|
||||
@@ -18,6 +19,8 @@ ActuatorFactory::create_actuator(const ModuleType type) {
|
||||
return std::make_unique<Servo1Actuator>();
|
||||
case ModuleType_DC_MOTOR:
|
||||
return std::make_unique<DCMotorActuator>();
|
||||
case ModuleType_DISPLAY:
|
||||
return std::make_unique<OledActuator>();
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -101,6 +101,8 @@ void DCMotorActuator::setup_encoder() {
|
||||
}
|
||||
|
||||
void DCMotorActuator::actuate(uint8_t *cmd) {
|
||||
// todo: Do we want to verify flatbuffers here?
|
||||
// Will introduce latency, and means that we need to also send the size to the actuate function.
|
||||
const auto *angleControlCmd =
|
||||
Flatbuffers::AngleControlMessageBuilder::parse_angle_control_message(cmd);
|
||||
this->m_target_angle = angleControlCmd->angle();
|
||||
|
||||
33
main/control/OledActuator.cpp
Normal file
33
main/control/OledActuator.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-07-15.
|
||||
//
|
||||
|
||||
#include "control/OledActuator.h"
|
||||
#include "TextControlMessageBuilder.h"
|
||||
#include "SensorMessageBuilder.h"
|
||||
#include "constants/module.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "flatbuffers_generated/SensorMessage_generated.h"
|
||||
#include "util/number_utils.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
void OledActuator::actuate(uint8_t *cmd) {
|
||||
// todo: Do we want to verify flatbuffers here?
|
||||
// Will introduce latency, and means that we need to also send the size to the actuate function.
|
||||
|
||||
const auto *text_control_message = Flatbuffers::TextControlMessageBuilder::parse_text_control_message(cmd);
|
||||
const auto new_str = text_control_message->message()->str();
|
||||
|
||||
if (m_display_str != new_str) {
|
||||
m_display_str = new_str;
|
||||
|
||||
m_oled->clear_display();
|
||||
if (m_display_str != "") {
|
||||
m_oled->display_text(m_display_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Flatbuffers::sensor_value> OledActuator::get_sensor_data() {
|
||||
return {Flatbuffers::target_text{m_display_str}};
|
||||
}
|
||||
@@ -39,6 +39,8 @@ Servo1Actuator::Servo1Actuator() {
|
||||
}
|
||||
|
||||
void Servo1Actuator::actuate(uint8_t *cmd) {
|
||||
// todo: Do we want to verify flatbuffers here?
|
||||
// Will introduce latency, and means that we need to also send the size to the actuate function.
|
||||
const auto *angleControlCmd =
|
||||
Flatbuffers::AngleControlMessageBuilder::parse_angle_control_message(cmd);
|
||||
const auto newDuty =
|
||||
|
||||
24
main/include/control/OledActuator.h
Normal file
24
main/include/control/OledActuator.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// Oled module
|
||||
|
||||
#ifndef OLED_ACTUATOR_H
|
||||
#define OLED_ACTUATOR_H
|
||||
|
||||
#include "IActuator.h"
|
||||
#include "ISensor.h"
|
||||
#include "Oled.h"
|
||||
#include "constants/module.h"
|
||||
#include <cstdint>
|
||||
|
||||
class OledActuator final : public IActuator {
|
||||
public:
|
||||
OledActuator() : m_oled(std::make_unique<Oled>(OLED_SDA, OLED_SCL)) {};
|
||||
~OledActuator() override = default;
|
||||
void actuate(std::uint8_t *cmd) override;
|
||||
std::vector<Flatbuffers::sensor_value> get_sensor_data() override;
|
||||
|
||||
private:
|
||||
std::string m_display_str = "";
|
||||
std::unique_ptr<Oled> m_oled;
|
||||
};
|
||||
|
||||
#endif //OLED_ACTUATOR_H
|
||||
Reference in New Issue
Block a user