Skip to content

Commit e4f946f

Browse files
authored
[BREAKING] Move and update many component implementations to support litgen-based pybind11 generation to overhaul python library (#291)
* Update file system and cli to have guards around ESP-specific code and start fleshing out the espp library * fleshing out library and updating how external libraries are copied; added color and event manager * add simple cli test * WIP trying to use litgen to automatically generate the python bindings 🚀 * WIP move implementation from header to source files so litgen can parse them effectively * WIP update cmakelists * WIP continuing to flesh out automatic binding support * fix: move task auto to header * update color, add missing pragma to fomatters files * fixed unmatched suppression * add missing task scope * working on configuring binding generator * update math components to better support autogenerating bindings * WIP trying to get more of the bindings working... * having to manually modify generated bindings... -.- * generated python docs * add requirements and gitignore * wip trying to get binding to work better * update gaussian so that alpha/beta/gamma class members are public instead of having getter/setter functions for them with the same name * WIP removed autogenerated default constructors for bezier, gaussian, task, timer, socket, tcpsocket, udpsocket and fixed autogenerated bindings. trying to get autogeneration to work for template classes * update python tests; ensure complete scoping for config members to facilitate proper binding generation; remove TcpTransmitConfig from detail namespace and update it to be TcpSocket::TransmitConfig with alternate workaround for gcc bug; updated ftp and rtsp accordingly * WIP trying to flesh out the bindings some more. still have to do a lot of manual editing of the generated bindings file, but it is way better than having to write the whole thing from scratch * revert back to implementation in main header even though it breaks litgen * minor update * move run_on_core out of espp::Task class and into espp::task namespace * update bindings * fix i2c * remove accidentally added i2c files * add missing param doc * add more explicit scoping * minor updates * update cmakelists to install magic enum headers correctly * minor update to support running examples on qtpy s3 * add some notes to the binding generator * update to generate into espp instead of espp_lib * add build library workflow * move sys/stdio.h to stdio.h for linux compat * update github action to support windows * update build to use cmake completely for better x-plat compat * WIP windows library * add simple readme * minor update * starting work on porting socket to windows * fix cmake * WIP windows support * comment out windows build for now * update bindings * feat(math): update gaussian to have getter/setter methods instead of public members * update bindings * update to use pybind11_add_module to simplify cmake lists, add windows build script, and update to build for release * update ci library build * ensure return code * update python bindings * use direct commands to get proper error status * update file system to use std::filesystem when not on esp-idf * clean up file system includes * update ftp to remove use of posix functions and replace with only std::filesystem or espp::FileSystem * explicit scoping * some more explicit scoping * more explicit * try to undefine logger verbosity enums since windows is complaining about them... * WIP trying to make socket a little more x-plat friendly * fix sa * include winsock in "C" linkage * WIP msvc is kinda stupid about include headers so we have to add some shit to the beginning of every file which includes one of the socket files... -.- * WIP getting windows build working * WIP added support for tabulate on msvc * updated to get closer to working compilation on windows * add note * test uplaoding output folder * update to v4 * disable reuseaddr on windows * update how msc_ver is checked * update install and ensure that pc can work * fix(socket): update to properly initialize socket library on windows before configuring socket. updated error logging to work across platforms * add pc tests for udp client/server and update build scripts accordingly * minor update * minor update * update readmes
1 parent 3de5e98 commit e4f946f

File tree

92 files changed

+8761
-2624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+8761
-2624
lines changed

.github/workflows/build_libraries.yml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Build Host C++ / Python Libraries
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
release:
9+
types: [published]
10+
workflow_dispatch:
11+
12+
jobs:
13+
build_windows:
14+
15+
runs-on: windows-latest
16+
continue-on-error: false
17+
18+
steps:
19+
- name: Checkout repo
20+
uses: actions/checkout@v4
21+
with:
22+
submodules: 'recursive'
23+
fetch-depth: 0
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.12'
29+
30+
- name: Build libraries
31+
working-directory: lib/
32+
run: |
33+
mkdir build
34+
cd build
35+
cmake ..
36+
cmake --build . --config Release --target install
37+
38+
- name: Upload output folder
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: libespp_windows
42+
path: lib/pc
43+
44+
build_linux:
45+
46+
runs-on: ubuntu-latest
47+
continue-on-error: false
48+
49+
steps:
50+
- name: Checkout repo
51+
uses: actions/checkout@v4
52+
with:
53+
submodules: 'recursive'
54+
fetch-depth: 0
55+
56+
- name: Set up Python
57+
uses: actions/setup-python@v5
58+
with:
59+
python-version: '3.12'
60+
61+
- name: Build libraries
62+
working-directory: lib/
63+
run: |
64+
./build.sh
65+
66+
- name: Upload output folder
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: libespp_linux
70+
path: lib/pc
71+
72+
build_macos:
73+
74+
runs-on: macos-latest
75+
continue-on-error: false
76+
77+
steps:
78+
- name: Setup XCode
79+
uses: maxim-lobanov/setup-xcode@v1
80+
with:
81+
xcode-version: latest-stable
82+
83+
- name: Set up Python
84+
uses: actions/setup-python@v5
85+
with:
86+
python-version: '3.12'
87+
88+
- name: Checkout repo
89+
uses: actions/checkout@v4
90+
with:
91+
submodules: 'recursive'
92+
fetch-depth: 0
93+
94+
- name: Build libraries
95+
working-directory: lib/
96+
run: |
97+
./build.sh
98+
99+
- name: Upload output folder
100+
uses: actions/upload-artifact@v4
101+
with:
102+
name: libespp_macos
103+
path: lib/pc

components/base_component/include/base_component.hpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ class BaseComponent {
2929
/// \param level The verbosity level to use for the logger
3030
/// \sa Logger::Verbosity
3131
/// \sa Logger::set_verbosity
32-
void set_log_level(Logger::Verbosity level) { logger_.set_verbosity(level); }
32+
void set_log_level(espp::Logger::Verbosity level) { logger_.set_verbosity(level); }
3333

3434
/// Set the log verbosity for the logger
3535
/// \param level The verbosity level to use for the logger
3636
/// \note This is a convenience method that calls set_log_level
3737
/// \sa set_log_level
3838
/// \sa Logger::Verbosity
3939
/// \sa Logger::set_verbosity
40-
void set_log_verbosity(Logger::Verbosity level) { set_log_level(level); }
40+
void set_log_verbosity(espp::Logger::Verbosity level) { set_log_level(level); }
4141

4242
/// Get the log verbosity for the logger
4343
/// \return The verbosity level of the logger
@@ -58,13 +58,14 @@ class BaseComponent {
5858
protected:
5959
BaseComponent() = default;
6060

61-
explicit BaseComponent(std::string_view tag, Logger::Verbosity level = Logger::Verbosity::WARN)
61+
explicit BaseComponent(std::string_view tag,
62+
espp::Logger::Verbosity level = espp::Logger::Verbosity::WARN)
6263
: logger_({.tag = tag, .level = level}) {}
6364

64-
explicit BaseComponent(const Logger::Config &logger_config)
65+
explicit BaseComponent(const espp::Logger::Config &logger_config)
6566
: logger_(logger_config) {}
6667

6768
/// The logger for this component
68-
Logger logger_ = espp::Logger({.tag = "BaseComponent", .level = Logger::Verbosity::INFO});
69+
Logger logger_ = espp::Logger({.tag = "BaseComponent", .level = espp::Logger::Verbosity::INFO});
6970
};
7071
} // namespace espp

components/cli/include/cli.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#if defined(ESP_PLATFORM)
34
#include <sdkconfig.h>
45

56
#if CONFIG_COMPILER_CXX_EXCEPTIONS || defined(_DOXYGEN_)
@@ -13,8 +14,6 @@
1314
#include "esp_vfs_dev.h"
1415
#include "esp_vfs_usb_serial_jtag.h"
1516

16-
#include <cli/cli.h>
17-
1817
#include "line_input.hpp"
1918

2019
#ifdef CONFIG_ESP_CONSOLE_USB_CDC
@@ -26,6 +25,8 @@
2625
#define STRINGIFY2(s) #s
2726
#endif // STRINGIFY
2827

28+
#include <cli/cli.h>
29+
2930
namespace espp {
3031
/**
3132
* @brief Class for implementing a basic Cli using the external cli library.
@@ -388,3 +389,5 @@ class Cli : private cli::CliSession {
388389
} // namespace espp
389390

390391
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS
392+
393+
#endif // ESP_PLATFORM

components/cli/include/line_input.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
#pragma once
2+
3+
#if defined(ESP_PLATFORM)
4+
15
#include <sdkconfig.h>
26

37
#if CONFIG_COMPILER_CXX_EXCEPTIONS || defined(_DOXYGEN_)
48

59
#include <algorithm>
610
#include <atomic>
711
#include <deque>
12+
#include <functional>
813
#include <iostream>
914
#include <stdio.h>
1015
#include <string>
@@ -424,3 +429,5 @@ class LineInput {
424429
} // namespace espp
425430

426431
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS
432+
433+
#endif // ESP_PLATFORM

components/color/include/color.hpp

+9-61
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class Rgb {
8484
*/
8585
Rgb &operator+=(const Rgb &rhs);
8686

87+
bool operator==(const Rgb &rhs) const = default;
88+
89+
bool operator!=(const Rgb &rhs) const = default;
90+
8791
/**
8892
* @brief Get a HSV representation of this RGB color.
8993
* @return An HSV object containing the HSV representation.
@@ -135,6 +139,10 @@ class Hsv {
135139
*/
136140
Hsv &operator=(const Hsv &other) = default;
137141

142+
bool operator==(const Hsv &rhs) const = default;
143+
144+
bool operator!=(const Hsv &rhs) const = default;
145+
138146
/**
139147
* @brief Assign the values of the provided Rgb object to this Hsv object.
140148
* @param rgb The Rgb object to convert and copy.
@@ -156,66 +164,6 @@ class Hsv {
156164
return fg(fmt::rgb(rgb.r * 255, rgb.g * 255, rgb.b * 255));
157165
}
158166

159-
// equality operators
160-
[[maybe_unused]] static bool operator==(const Rgb &lhs, const Rgb &rhs) {
161-
return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b;
162-
}
163-
164-
[[maybe_unused]] static bool operator==(const Hsv &lhs, const Hsv &rhs) {
165-
return lhs.h == rhs.h && lhs.s == rhs.s && lhs.v == rhs.v;
166-
}
167-
168-
// inequality operators
169-
[[maybe_unused]] static bool operator!=(const Rgb &lhs, const Rgb &rhs) { return !(lhs == rhs); }
170-
171-
[[maybe_unused]] static bool operator!=(const Hsv &lhs, const Hsv &rhs) { return !(lhs == rhs); }
172167
} // namespace espp
173168

174-
#include "format.hpp"
175-
176-
// for allowing easy serialization/printing of the
177-
// Rgb
178-
template <> struct fmt::formatter<espp::Rgb> {
179-
// Presentation format: 'f' - floating [0,1] (default), 'd' - integer [0,255], 'x' - hex integer.
180-
char presentation = 'f';
181-
182-
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) {
183-
// Parse the presentation format and store it in the formatter:
184-
auto it = ctx.begin(), end = ctx.end();
185-
if (it != end && (*it == 'f' || *it == 'd' || *it == 'x'))
186-
presentation = *it++;
187-
188-
// TODO: Check if reached the end of the range:
189-
// if (it != end && *it != '}') throw format_error("invalid format");
190-
191-
// Return an iterator past the end of the parsed range:
192-
return it;
193-
}
194-
195-
template <typename FormatContext> auto format(espp::Rgb const &rgb, FormatContext &ctx) const {
196-
switch (presentation) {
197-
case 'f':
198-
return fmt::format_to(ctx.out(), "({}, {}, {})", rgb.r, rgb.g, rgb.b);
199-
case 'd':
200-
return fmt::format_to(ctx.out(), "({}, {}, {})", static_cast<int>(rgb.r * 255),
201-
static_cast<int>(rgb.g * 255), static_cast<int>(rgb.b * 255));
202-
case 'x':
203-
return fmt::format_to(ctx.out(), "{:#08X}", rgb.hex());
204-
default:
205-
// shouldn't get here!
206-
return fmt::format_to(ctx.out(), "({}, {}, {})", rgb.r, rgb.g, rgb.b);
207-
}
208-
}
209-
};
210-
211-
// for allowing easy serialization/printing of the
212-
// Rgb
213-
template <> struct fmt::formatter<espp::Hsv> {
214-
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
215-
return ctx.begin();
216-
}
217-
218-
template <typename FormatContext> auto format(espp::Hsv const &hsv, FormatContext &ctx) const {
219-
return fmt::format_to(ctx.out(), "({}, {}, {})", hsv.h, hsv.s, hsv.v);
220-
}
221-
};
169+
#include "color_formatters.hpp"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
3+
#include "format.hpp"
4+
5+
// for allowing easy serialization/printing of the
6+
// Rgb
7+
template <> struct fmt::formatter<espp::Rgb> {
8+
// Presentation format: 'f' - floating [0,1] (default), 'd' - integer [0,255], 'x' - hex integer.
9+
char presentation = 'f';
10+
11+
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) {
12+
// Parse the presentation format and store it in the formatter:
13+
auto it = ctx.begin(), end = ctx.end();
14+
if (it != end && (*it == 'f' || *it == 'd' || *it == 'x'))
15+
presentation = *it++;
16+
17+
// TODO: Check if reached the end of the range:
18+
// if (it != end && *it != '}') throw format_error("invalid format");
19+
20+
// Return an iterator past the end of the parsed range:
21+
return it;
22+
}
23+
24+
template <typename FormatContext> auto format(espp::Rgb const &rgb, FormatContext &ctx) const {
25+
switch (presentation) {
26+
case 'f':
27+
return fmt::format_to(ctx.out(), "({}, {}, {})", rgb.r, rgb.g, rgb.b);
28+
case 'd':
29+
return fmt::format_to(ctx.out(), "({}, {}, {})", static_cast<int>(rgb.r * 255),
30+
static_cast<int>(rgb.g * 255), static_cast<int>(rgb.b * 255));
31+
case 'x':
32+
return fmt::format_to(ctx.out(), "{:#08X}", rgb.hex());
33+
default:
34+
// shouldn't get here!
35+
return fmt::format_to(ctx.out(), "({}, {}, {})", rgb.r, rgb.g, rgb.b);
36+
}
37+
}
38+
};
39+
40+
// for allowing easy serialization/printing of the
41+
// Hsv
42+
template <> struct fmt::formatter<espp::Hsv> {
43+
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
44+
return ctx.begin();
45+
}
46+
47+
template <typename FormatContext> auto format(espp::Hsv const &hsv, FormatContext &ctx) const {
48+
return fmt::format_to(ctx.out(), "({}, {}, {})", hsv.h, hsv.s, hsv.v);
49+
}
50+
};

components/event_manager/include/event_manager.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace espp {
3434
* \section event_manager_ex1 Event Manager Example
3535
* \snippet event_manager_example.cpp event manager example
3636
*/
37-
class EventManager : public BaseComponent {
37+
class EventManager : public espp::BaseComponent {
3838
public:
3939
/**
4040
* @brief Function definition for function prototypes to be called when
@@ -80,7 +80,8 @@ class EventManager : public BaseComponent {
8080
* registered for that component.
8181
*/
8282
bool add_subscriber(const std::string &topic, const std::string &component,
83-
const event_callback_fn &callback, const size_t stack_size_bytes = 8 * 1024);
83+
const espp::EventManager::event_callback_fn &callback,
84+
const size_t stack_size_bytes = 8192);
8485

8586
/**
8687
* @brief Register a subscriber for \p component on \p topic.
@@ -96,7 +97,8 @@ class EventManager : public BaseComponent {
9697
* registered for that component.
9798
*/
9899
bool add_subscriber(const std::string &topic, const std::string &component,
99-
const event_callback_fn &callback, const Task::BaseConfig &task_config);
100+
const espp::EventManager::event_callback_fn &callback,
101+
const espp::Task::BaseConfig &task_config);
100102

101103
/**
102104
* @brief Publish \p data on \p topic.
@@ -128,7 +130,7 @@ class EventManager : public BaseComponent {
128130

129131
protected:
130132
EventManager()
131-
: BaseComponent("Event Manager") {}
133+
: espp::BaseComponent("Event Manager") {}
132134

133135
struct SubscriberData {
134136
std::mutex m;

0 commit comments

Comments
 (0)