RMT integration

This commit is contained in:
2025-07-26 23:55:17 -04:00
parent f09f68c23d
commit 8a463bba10
12 changed files with 108 additions and 26 deletions

View File

@@ -1,4 +1,4 @@
idf_component_register(SRCS "WifiManager.cpp" "mDNSDiscoveryService.cpp" "TCPServer.cpp" "CommunicationRouter.cpp" "MessagingInterface.cpp"
idf_component_register(SRCS "WifiManager.cpp" "mDNSDiscoveryService.cpp" "TCPServer.cpp" "CommunicationRouter.cpp" "MessagingInterface.cpp" "OrientationDetection.cpp"
PRIV_REQUIRES driver esp_event nvs_flash esp_netif esp_wifi espressif__mdns constants config flatbuffers dataLink rmt
REQUIRES ptrQueue
INCLUDE_DIRS "include")

View File

@@ -5,13 +5,11 @@
#include "mDNSDiscoveryService.h"
#include "MPIMessageBuilder.h"
#include "WifiManager.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "Tables.h"
#include "PtrQueue.h"
#include "OrientationDetection.h"
CommunicationRouter::~CommunicationRouter() {
vTaskDelete(m_router_thread);
@@ -139,9 +137,10 @@ std::pair<std::vector<uint8_t>, std::vector<Orientation>> CommunicationRouter::g
}
}
// todo: get orientation (temporary)
for (int i = 0; i < MAX_WIRED_CONNECTIONS; i++) {
connected_module_orientations[i] = Orientation_Deg0;
if (const auto id = connected_module_ids[0]; 0 == id) {
connected_module_orientations[0] = Orientation_Deg0;
} else {
connected_module_orientations[0] = OrientationDetection::get_orientation(0);
}
return { connected_module_ids, connected_module_orientations };

View File

@@ -0,0 +1,46 @@
//
// Created by Johnathon Slightham on 2025-07-26.
//
#include <constants/module.h>
#include "OrientationDetection.h"
#include <ConfigManager.h>
#include <iostream>
#include <bits/ostream.tcc>
void OrientationDetection::init() {
for (int i = 0; i < MODULE_TO_NUM_CHANNELS_MAP[ConfigManager::get_module_type()]; i++) {
setup_gpio(static_cast<gpio_num_t>(CHANNEL_TO_0_DEG_MAP[i]));
setup_gpio(static_cast<gpio_num_t>(CHANNEL_TO_90_DEG_MAP[i]));
setup_gpio(static_cast<gpio_num_t>(CHANNEL_TO_180_DEG_MAP[i]));
setup_gpio(static_cast<gpio_num_t>(CHANNEL_TO_270_DEG_MAP[i]));
}
}
Orientation OrientationDetection::get_orientation(const uint8_t channel) {
if (gpio_get_level(static_cast<gpio_num_t>(CHANNEL_TO_90_DEG_MAP[channel]))) {
std::cout << "90deg" << std::endl;
return Orientation_Deg90;
} else if (gpio_get_level(static_cast<gpio_num_t>(CHANNEL_TO_180_DEG_MAP[channel]))) {
std::cout << "180deg" << std::endl;
return Orientation_Deg180;
} else if (gpio_get_level(static_cast<gpio_num_t>(CHANNEL_TO_270_DEG_MAP[channel]))) {
std::cout << "270deg" << std::endl;
return Orientation_Deg270;
} else {
std::cout << "No orientation detected" << std::endl;
return Orientation_Deg0;
}
}
void OrientationDetection::setup_gpio(const gpio_num_t pin) {
const gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << pin),
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_ENABLE,
.intr_type = GPIO_INTR_DISABLE
};
gpio_config(&io_conf);
}

View File

@@ -9,6 +9,7 @@
#include <functional>
#include <memory>
#include <chrono>
#include <OrientationDetection.h>
#include <WifiManager.h>
#include "freertos/FreeRTOS.h"
@@ -40,6 +41,7 @@ public:
m_pc_connection(std::move(pc_connection)),
m_module_id(ConfigManager::get_module_id()),
m_last_leader_updated(std::chrono::system_clock::now()){
OrientationDetection::init();
update_leader();
xTaskCreate(router_thread, "communication_router", 4096, this, 3, &this->m_router_thread);

View File

@@ -0,0 +1,20 @@
//
// Created by Johnathon Slightham on 2025-07-26.
//
#ifndef ORIENTATIONDETECTION_H
#define ORIENTATIONDETECTION_H
#include <flatbuffers_generated/RobotModule_generated.h>
#include "driver/gpio.h"
class OrientationDetection {
public:
static void init();
static Orientation get_orientation(uint8_t channel);
private:
static void setup_gpio(gpio_num_t pin);
};
#endif //ORIENTATIONDETECTION_H