refactor: migrate MICRO_PIP to fine-grained feature flags
Replace monolithic MICRO_PIP/PIP_MICRO with granular flags: Feature flags (CMake options + platform auto-detection): - PIP_NO_FILESYSTEM, PIP_NO_THREADS, PIP_NO_SOCKET - PIP_NO_PROCESS, PIP_NO_DYNLIB, PIP_NO_FFT, PIP_NO_SERIAL Embedded optimization flag: - PIP_EMBEDDED (auto-set for Pico SDK and FreeRTOS) Controls buffer sizes, time stubs, terminal fallback, init stubs Platform blocks in CMakeLists.txt: - Pico SDK: auto-disables FS, PROCESS, DYNLIB, FFT, SERIAL; conditionally disables THREADS (no FreeRTOS) and SOCKET (no LWIP) - FreeRTOS: auto-disables FS, PROCESS, DYNLIB, FFT, SERIAL; conditionally disables SOCKET (no LWIP) - Android: auto-disables PROCESS, DYNLIB, FFT Updated 96 files across libs/, utils/, tests/, and CMakeLists.txt. Builds verified for Linux (547 tests pass) and Pico SDK (100%). Removed all MICRO_PIP and PIP_MICRO references (0 remaining).
This commit is contained in:
@@ -2,27 +2,29 @@
|
||||
|
||||
#include "piliterals_string.h"
|
||||
#include "piliterals_time.h"
|
||||
#ifndef WINDOWS
|
||||
# include "pidir.h"
|
||||
# include "pifile.h"
|
||||
# include "piiostream.h"
|
||||
|
||||
# ifdef LINUX
|
||||
# include <fcntl.h>
|
||||
# include <linux/input-event-codes.h>
|
||||
# include <linux/input.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/time.h>
|
||||
# include <unistd.h>
|
||||
# else
|
||||
#ifndef PIP_NO_THREADS
|
||||
# ifndef WINDOWS
|
||||
# include "pidir.h"
|
||||
# include "pifile.h"
|
||||
# include "piiostream.h"
|
||||
|
||||
# ifdef LINUX
|
||||
# include <fcntl.h>
|
||||
# include <linux/input-event-codes.h>
|
||||
# include <linux/input.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/time.h>
|
||||
# include <unistd.h>
|
||||
# else
|
||||
// Stubs for embedded/non-Linux builds
|
||||
# define EV_SYN 0
|
||||
# define EV_KEY 1
|
||||
# define EV_REL 2
|
||||
# define EV_ABS 3
|
||||
# define EVIOCGABS(_v) 0
|
||||
# endif
|
||||
#else
|
||||
# define EV_SYN 0
|
||||
# define EV_KEY 1
|
||||
# define EV_REL 2
|
||||
# define EV_ABS 3
|
||||
# define EVIOCGABS(_v) 0
|
||||
# endif
|
||||
# else
|
||||
// clang-format off
|
||||
# undef _WIN32_WINNT
|
||||
# define _WIN32_WINNT 0x0600
|
||||
@@ -32,7 +34,7 @@ extern "C" {
|
||||
# include <hidsdi.h>
|
||||
}
|
||||
// clang-format on
|
||||
#endif
|
||||
# endif
|
||||
|
||||
|
||||
bool PIHIDeviceInfo::match(const PIString & str) const {
|
||||
@@ -79,14 +81,14 @@ PICout operator<<(PICout s, const PIHIDeviceInfo & v) {
|
||||
|
||||
|
||||
PRIVATE_DEFINITION_START(PIHIDevice)
|
||||
#ifndef WINDOWS
|
||||
# ifndef WINDOWS
|
||||
PIFile file;
|
||||
bool is_js = false;
|
||||
#else
|
||||
# else
|
||||
PIByteArray buffer;
|
||||
HANDLE deviceHandle = nullptr;
|
||||
PHIDP_PREPARSED_DATA preparsed = nullptr;
|
||||
#endif
|
||||
# endif
|
||||
PRIVATE_DEFINITION_END(PIHIDevice)
|
||||
|
||||
|
||||
@@ -95,11 +97,11 @@ PIHIDevice::~PIHIDevice() {
|
||||
}
|
||||
|
||||
bool PIHIDevice::isOpened() const {
|
||||
#ifndef WINDOWS
|
||||
# ifndef WINDOWS
|
||||
return PRIVATE->file.isOpened();
|
||||
#else
|
||||
# else
|
||||
return PRIVATE->deviceHandle;
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
@@ -110,21 +112,21 @@ bool PIHIDevice::open(const PIHIDeviceInfo & device) {
|
||||
di = device;
|
||||
di.prepare();
|
||||
if (device.isNull()) return false;
|
||||
#ifndef WINDOWS
|
||||
# ifndef WINDOWS
|
||||
if (!PRIVATE->file.open(di.path, PIIODevice::ReadOnly)) {
|
||||
piCout << "PIHIDevice::open" << di.path << "error:" << errorString();
|
||||
return false;
|
||||
}
|
||||
PRIVATE->is_js = PIFile::FileInfo(di.path).name().startsWith("js"_a);
|
||||
return true;
|
||||
#else
|
||||
# else
|
||||
PRIVATE->deviceHandle = CreateFileA(di.path.dataAscii(),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
nullptr,
|
||||
OPEN_EXISTING,
|
||||
0,
|
||||
nullptr);
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
nullptr,
|
||||
OPEN_EXISTING,
|
||||
0,
|
||||
nullptr);
|
||||
if (PRIVATE->deviceHandle == INVALID_HANDLE_VALUE) {
|
||||
piCoutObj << "PIHIDevice::open" << di.path << "error:" << errorString();
|
||||
PRIVATE->deviceHandle = nullptr;
|
||||
@@ -136,7 +138,7 @@ bool PIHIDevice::open(const PIHIDeviceInfo & device) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
@@ -147,9 +149,9 @@ bool PIHIDevice::open() {
|
||||
|
||||
void PIHIDevice::close() {
|
||||
stop();
|
||||
#ifndef WINDOWS
|
||||
# ifndef WINDOWS
|
||||
PRIVATE->file.close();
|
||||
#else
|
||||
# else
|
||||
if (PRIVATE->deviceHandle) {
|
||||
CloseHandle(PRIVATE->deviceHandle);
|
||||
PRIVATE->deviceHandle = nullptr;
|
||||
@@ -158,34 +160,34 @@ void PIHIDevice::close() {
|
||||
HidD_FreePreparsedData(PRIVATE->preparsed);
|
||||
PRIVATE->preparsed = nullptr;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void PIHIDevice::start() {
|
||||
if (!isOpened()) return;
|
||||
PIThread::start(200_Hz);
|
||||
#ifndef WINDOWS
|
||||
#else
|
||||
#endif
|
||||
# ifndef WINDOWS
|
||||
# else
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void PIHIDevice::stop() {
|
||||
PIThread::stop();
|
||||
#ifdef WINDOWS
|
||||
# ifdef WINDOWS
|
||||
if (PRIVATE->deviceHandle) {
|
||||
CancelIoEx(PRIVATE->deviceHandle, nullptr);
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
if (!waitForFinish(1000_ms)) terminate();
|
||||
}
|
||||
|
||||
|
||||
void PIHIDevice::run() {
|
||||
Event e;
|
||||
#ifndef WINDOWS
|
||||
# pragma pack(push, 1)
|
||||
# ifndef WINDOWS
|
||||
# pragma pack(push, 1)
|
||||
struct input_event {
|
||||
struct timeval time;
|
||||
ushort type;
|
||||
@@ -198,7 +200,7 @@ void PIHIDevice::run() {
|
||||
uchar type; /* event type */
|
||||
uchar number; /* axis/button number */
|
||||
};
|
||||
# pragma pack(pop)
|
||||
# pragma pack(pop)
|
||||
if (PRIVATE->is_js) {
|
||||
js_event ie;
|
||||
while (PRIVATE->file.read(&ie, sizeof(ie)) == sizeof(ie)) {
|
||||
@@ -253,7 +255,7 @@ void PIHIDevice::run() {
|
||||
if (!ok) continue;
|
||||
}
|
||||
}
|
||||
#else
|
||||
# else
|
||||
PRIVATE->buffer.resize(di.input_report_size).fill(0);
|
||||
DWORD readed = 0;
|
||||
// piCout << "read" << PRIVATE->deviceHandle << PRIVATE->buffer.size();
|
||||
@@ -293,7 +295,7 @@ void PIHIDevice::run() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
|
||||
auto ait = cur_axes.makeIterator();
|
||||
e.type = Event::tAxisMove;
|
||||
@@ -333,7 +335,7 @@ double PIHIDevice::procDeadZone(double in) {
|
||||
PIVector<PIHIDeviceInfo> PIHIDevice::allDevices(bool try_open) {
|
||||
PIVector<PIHIDeviceInfo> ret;
|
||||
|
||||
#ifndef WINDOWS
|
||||
# ifndef WINDOWS
|
||||
|
||||
auto readFile = [](const PIString & path) {
|
||||
auto ba = PIFile::readAll(path);
|
||||
@@ -379,11 +381,11 @@ PIVector<PIHIDeviceInfo> PIHIDevice::allDevices(bool try_open) {
|
||||
}
|
||||
/*bool dev_found = false;
|
||||
for (const auto & d: devs) {
|
||||
if (d.startsWith("js"_a)) {
|
||||
dev.path = "/dev/input/"_a + d;
|
||||
dev_found = true;
|
||||
break;
|
||||
}
|
||||
if (d.startsWith("js"_a)) {
|
||||
dev.path = "/dev/input/"_a + d;
|
||||
dev_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!dev_found) {*/
|
||||
// search for event<N> dir
|
||||
@@ -408,7 +410,7 @@ PIVector<PIHIDeviceInfo> PIHIDevice::allDevices(bool try_open) {
|
||||
ullong bits = readFile(hd_i.path + file).toULLong(16);
|
||||
// piCout<< PICoutManipulators::Bin << abs;
|
||||
if (bits > 0) {
|
||||
#ifdef LINUX
|
||||
# ifdef LINUX
|
||||
int fd = ::open(dev.path.dataAscii(), O_RDONLY);
|
||||
if (fd < 0) {
|
||||
// piCout << "Warning: can`t open" << dev.path << errorString();
|
||||
@@ -433,7 +435,7 @@ PIVector<PIHIDeviceInfo> PIHIDevice::allDevices(bool try_open) {
|
||||
}
|
||||
}
|
||||
if (fd >= 0) ::close(fd);
|
||||
#else
|
||||
# else
|
||||
// Stub implementation for non-Linux builds
|
||||
PIHIDeviceInfo::AxisInfo ai;
|
||||
ai.is_relative = is_relative;
|
||||
@@ -445,7 +447,7 @@ PIVector<PIHIDeviceInfo> PIHIDevice::allDevices(bool try_open) {
|
||||
ret << ai;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
@@ -496,7 +498,7 @@ PIVector<PIHIDeviceInfo> PIHIDevice::allDevices(bool try_open) {
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
# else
|
||||
|
||||
GUID guid;
|
||||
HidD_GetHidGuid(&guid);
|
||||
@@ -518,23 +520,23 @@ PIVector<PIHIDeviceInfo> PIHIDevice::allDevices(bool try_open) {
|
||||
PIScopeExitCall exit_call([&deviceInterfaceDetailData]() { delete[] reinterpret_cast<BYTE *>(deviceInterfaceDetailData); });
|
||||
deviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
||||
if (!SetupDiGetDeviceInterfaceDetail(deviceInfoSet,
|
||||
&deviceInterfaceData,
|
||||
deviceInterfaceDetailData,
|
||||
requiredSize,
|
||||
nullptr,
|
||||
nullptr)) {
|
||||
&deviceInterfaceData,
|
||||
deviceInterfaceDetailData,
|
||||
requiredSize,
|
||||
nullptr,
|
||||
nullptr)) {
|
||||
piCout << "SetupDiGetDeviceInterfaceDetail error:" << errorString();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (try_open) {
|
||||
auto test_f = CreateFileA(deviceInterfaceDetailData->DevicePath,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
nullptr,
|
||||
OPEN_EXISTING,
|
||||
0,
|
||||
nullptr);
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
nullptr,
|
||||
OPEN_EXISTING,
|
||||
0,
|
||||
nullptr);
|
||||
if (test_f == INVALID_HANDLE_VALUE) continue;
|
||||
CloseHandle(test_f);
|
||||
}
|
||||
@@ -657,7 +659,7 @@ PIVector<PIHIDeviceInfo> PIHIDevice::allDevices(bool try_open) {
|
||||
|
||||
SetupDiDestroyDeviceInfoList(deviceInfoSet);
|
||||
|
||||
#endif
|
||||
# endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -671,3 +673,5 @@ PIHIDeviceInfo PIHIDevice::findDevice(const PIString & name) {
|
||||
}
|
||||
return PIHIDeviceInfo();
|
||||
}
|
||||
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
Reference in New Issue
Block a user