попытки сделать crsf, не взлетела часть с пультом

This commit is contained in:
2025-11-24 16:24:59 +03:00
parent 0f14fd0155
commit 3eaea1b966
20 changed files with 769 additions and 535 deletions

51
lib/port/unix/poller.cpp Normal file
View File

@@ -0,0 +1,51 @@
#include "port/poller.h"
#include <sys/poll.h>
#include <algorithm>
bool poller::PollObject::isPollIn() const { return revents & POLLIN; }
bool poller::PollObject::isPollOut() const { return revents & POLLOUT; }
bool poller::PollObject::isPollHup() const { return revents & POLLHUP; }
poller::PollObject::~PollObject() = default;
poller::PollWrapper::PollWrapper() = default;
void poller::PollWrapper::loop(int timeoutMs) {
if (this->objects.empty()) {
return;
}
// проверяем, что нет объектов с fd < 0, удаляем такие объекты если они есть
for (size_t index = 0; index < this->objects.size();) {
if (this->objects[index]->fd < 0) {
this->objects.erase(this->objects.begin() + static_cast<ssize_t>(index));
} else {
index++;
}
}
const auto qsize = this->objects.size();
// массив для вызова poll
pollfd pollFds[qsize];
// заполняем данные для poll
for (size_t i = 0; i < qsize; i++) {
pollFds[i].revents = 0;
pollFds[i].fd = this->objects[i]->fd;
pollFds[i].events = this->objects[i]->events;
}
// выполняем poll
poll(pollFds, qsize, timeoutMs);
// проверяем события
for (size_t i = 0; i < qsize; i++) {
objects[i]->revents = pollFds[i].revents;
// if (pollFds[i].revents != 0) {
// objects[i]->callback();
// }
}
}
poller::PollWrapper::~PollWrapper() = default;