Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] Move and update many component implementations to support litgen-based pybind11 generation to overhaul python library #291

Merged
merged 86 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
6d430c8
Update file system and cli to have guards around ESP-specific code an…
finger563 Jul 11, 2024
3d25c8a
fleshing out library and updating how external libraries are copied; …
finger563 Jul 11, 2024
194de67
add simple cli test
finger563 Jul 11, 2024
c44c9a9
WIP trying to use litgen to automatically generate the python binding…
finger563 Jul 12, 2024
76c5850
WIP move implementation from header to source files so litgen can par…
finger563 Jul 12, 2024
ecf029c
WIP update cmakelists
finger563 Jul 12, 2024
a6c83b2
WIP continuing to flesh out automatic binding support
finger563 Jul 12, 2024
927a060
fix: move task auto to header
finger563 Jul 12, 2024
60eff08
update color, add missing pragma to fomatters files
finger563 Jul 12, 2024
0c751bf
fixed unmatched suppression
finger563 Jul 12, 2024
7053f5c
add missing task scope
finger563 Jul 12, 2024
d2c4a34
working on configuring binding generator
finger563 Jul 12, 2024
0860ba8
Merge branch 'main' into feature/file-system-cross-platform-update
finger563 Jul 27, 2024
9e45fee
update math components to better support autogenerating bindings
finger563 Jul 28, 2024
cb203ce
WIP trying to get more of the bindings working...
finger563 Jul 28, 2024
d514b21
having to manually modify generated bindings... -.-
finger563 Jul 28, 2024
784f9f5
generated python docs
finger563 Jul 28, 2024
968bbeb
add requirements and gitignore
finger563 Jul 28, 2024
47432dc
wip trying to get binding to work better
finger563 Jul 28, 2024
ca7a50e
update gaussian so that alpha/beta/gamma class members are public ins…
finger563 Jul 29, 2024
2cdc80d
WIP removed autogenerated default constructors for bezier, gaussian, …
finger563 Jul 29, 2024
10f9bac
update python tests; ensure complete scoping for config members to fa…
finger563 Jul 29, 2024
1cae17f
WIP trying to flesh out the bindings some more. still have to do a lo…
finger563 Jul 29, 2024
014a17b
revert back to implementation in main header even though it breaks li…
finger563 Jul 29, 2024
184b353
minor update
finger563 Jul 29, 2024
6fd5285
Merge branch 'main' into feature/file-system-cross-platform-update
finger563 Jul 29, 2024
cf199ad
move run_on_core out of espp::Task class and into espp::task namespace
finger563 Jul 29, 2024
64c8d58
update bindings
finger563 Jul 29, 2024
a1520d1
fix i2c
finger563 Jul 29, 2024
ad9868b
remove accidentally added i2c files
finger563 Jul 29, 2024
5717dd3
Merge branch 'main' into feature/file-system-cross-platform-update
finger563 Jul 29, 2024
d28e8d2
add missing param doc
finger563 Jul 30, 2024
fbe1708
add more explicit scoping
finger563 Jul 30, 2024
5b2338a
minor updates
finger563 Jul 30, 2024
2ab1ecf
update cmakelists to install magic enum headers correctly
finger563 Jul 30, 2024
d4bdf47
minor update to support running examples on qtpy s3
finger563 Jul 30, 2024
b37137f
add some notes to the binding generator
finger563 Jul 30, 2024
c82b243
update to generate into espp instead of espp_lib
finger563 Jul 30, 2024
3925615
add build library workflow
finger563 Jul 30, 2024
aa95a56
move sys/stdio.h to stdio.h for linux compat
finger563 Jul 30, 2024
a887781
update github action to support windows
finger563 Jul 30, 2024
e82d9cf
update build to use cmake completely for better x-plat compat
finger563 Jul 30, 2024
323291b
WIP windows library
finger563 Jul 30, 2024
6f20728
add simple readme
finger563 Jul 30, 2024
b04ca77
minor update
finger563 Jul 30, 2024
fb121db
starting work on porting socket to windows
finger563 Jul 30, 2024
b5df1fc
fix cmake
finger563 Jul 30, 2024
d9cd3da
WIP windows support
finger563 Jul 30, 2024
d61bd66
comment out windows build for now
finger563 Jul 30, 2024
2b1dccc
Merge branch 'main' into feature/file-system-cross-platform-update
finger563 Jul 30, 2024
6245807
update bindings
finger563 Jul 31, 2024
337c0ac
feat(math): update gaussian to have getter/setter methods instead of …
finger563 Jul 31, 2024
0d7163d
update bindings
finger563 Jul 31, 2024
c3b25e5
Merge branch 'main' into feature/file-system-cross-platform-update
finger563 Aug 2, 2024
212a47f
merge main
finger563 Aug 3, 2024
0c069e1
update to use pybind11_add_module to simplify cmake lists, add window…
finger563 Aug 3, 2024
4e5d99b
update ci library build
finger563 Aug 3, 2024
b5c683c
ensure return code
finger563 Aug 3, 2024
3c152cf
update python bindings
finger563 Aug 3, 2024
e38e35e
use direct commands to get proper error status
finger563 Aug 3, 2024
f02f7ed
update file system to use std::filesystem when not on esp-idf
finger563 Aug 3, 2024
1bbc828
clean up file system includes
finger563 Aug 3, 2024
c2a7a47
update ftp to remove use of posix functions and replace with only std…
finger563 Aug 3, 2024
3a3b081
explicit scoping
finger563 Aug 3, 2024
c4b3d77
some more explicit scoping
finger563 Aug 3, 2024
127f74a
more explicit
finger563 Aug 3, 2024
e2daba0
try to undefine logger verbosity enums since windows is complaining a…
finger563 Aug 3, 2024
07999ff
WIP trying to make socket a little more x-plat friendly
finger563 Aug 3, 2024
4dacfc6
fix sa
finger563 Aug 3, 2024
d756b58
include winsock in "C" linkage
finger563 Aug 3, 2024
24888cd
WIP msvc is kinda stupid about include headers so we have to add some…
finger563 Aug 3, 2024
31b0b22
WIP getting windows build working
finger563 Aug 3, 2024
a4ea414
WIP added support for tabulate on msvc
finger563 Aug 3, 2024
632c049
updated to get closer to working compilation on windows
finger563 Aug 3, 2024
77cbb4a
add note
finger563 Aug 3, 2024
65c0ecd
test uplaoding output folder
finger563 Aug 4, 2024
a209d6a
update to v4
finger563 Aug 4, 2024
d8e82b3
disable reuseaddr on windows
finger563 Aug 4, 2024
7bad1e2
update how msc_ver is checked
finger563 Aug 4, 2024
be5e51c
update install and ensure that pc can work
finger563 Aug 4, 2024
07bb223
fix(socket): update to properly initialize socket library on windows …
finger563 Aug 11, 2024
9f4e0f3
add pc tests for udp client/server and update build scripts accordingly
finger563 Aug 11, 2024
8754d02
minor update
finger563 Aug 11, 2024
bf0eee3
minor update
finger563 Aug 11, 2024
0fc2521
merge main
finger563 Aug 11, 2024
0975735
update readmes
finger563 Aug 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/workflows/build_libraries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Build Host C++ / Python Libraries

on:
pull_request:
branches: [main]
push:
branches: [main]
release:
types: [published]
workflow_dispatch:

jobs:
build_windows:

runs-on: windows-latest
continue-on-error: false

steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Build libraries
working-directory: lib/
run: |
mkdir build
cd build
cmake ..
cmake --build . --config Release --target install

- name: Upload output folder
uses: actions/upload-artifact@v4
with:
name: libespp_windows
path: lib/pc

build_linux:

runs-on: ubuntu-latest
continue-on-error: false

steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Build libraries
working-directory: lib/
run: |
./build.sh

- name: Upload output folder
uses: actions/upload-artifact@v4
with:
name: libespp_linux
path: lib/pc

build_macos:

runs-on: macos-latest
continue-on-error: false

steps:
- name: Setup XCode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0

- name: Build libraries
working-directory: lib/
run: |
./build.sh

- name: Upload output folder
uses: actions/upload-artifact@v4
with:
name: libespp_macos
path: lib/pc
11 changes: 6 additions & 5 deletions components/base_component/include/base_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class BaseComponent {
/// \param level The verbosity level to use for the logger
/// \sa Logger::Verbosity
/// \sa Logger::set_verbosity
void set_log_level(Logger::Verbosity level) { logger_.set_verbosity(level); }
void set_log_level(espp::Logger::Verbosity level) { logger_.set_verbosity(level); }

/// Set the log verbosity for the logger
/// \param level The verbosity level to use for the logger
/// \note This is a convenience method that calls set_log_level
/// \sa set_log_level
/// \sa Logger::Verbosity
/// \sa Logger::set_verbosity
void set_log_verbosity(Logger::Verbosity level) { set_log_level(level); }
void set_log_verbosity(espp::Logger::Verbosity level) { set_log_level(level); }

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

explicit BaseComponent(std::string_view tag, Logger::Verbosity level = Logger::Verbosity::WARN)
explicit BaseComponent(std::string_view tag,
espp::Logger::Verbosity level = espp::Logger::Verbosity::WARN)
: logger_({.tag = tag, .level = level}) {}

explicit BaseComponent(const Logger::Config &logger_config)
explicit BaseComponent(const espp::Logger::Config &logger_config)
: logger_(logger_config) {}

/// The logger for this component
Logger logger_ = espp::Logger({.tag = "BaseComponent", .level = Logger::Verbosity::INFO});
Logger logger_ = espp::Logger({.tag = "BaseComponent", .level = espp::Logger::Verbosity::INFO});
};
} // namespace espp
7 changes: 5 additions & 2 deletions components/cli/include/cli.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#if defined(ESP_PLATFORM)
#include <sdkconfig.h>

#if CONFIG_COMPILER_CXX_EXCEPTIONS || defined(_DOXYGEN_)
Expand All @@ -13,8 +14,6 @@
#include "esp_vfs_dev.h"
#include "esp_vfs_usb_serial_jtag.h"

#include <cli/cli.h>

#include "line_input.hpp"

#ifdef CONFIG_ESP_CONSOLE_USB_CDC
Expand All @@ -26,6 +25,8 @@
#define STRINGIFY2(s) #s
#endif // STRINGIFY

#include <cli/cli.h>

namespace espp {
/**
* @brief Class for implementing a basic Cli using the external cli library.
Expand Down Expand Up @@ -388,3 +389,5 @@ class Cli : private cli::CliSession {
} // namespace espp

#endif // CONFIG_COMPILER_CXX_EXCEPTIONS

#endif // ESP_PLATFORM
7 changes: 7 additions & 0 deletions components/cli/include/line_input.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#pragma once

#if defined(ESP_PLATFORM)

#include <sdkconfig.h>

#if CONFIG_COMPILER_CXX_EXCEPTIONS || defined(_DOXYGEN_)

#include <algorithm>
#include <atomic>
#include <deque>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string>
Expand Down Expand Up @@ -424,3 +429,5 @@ class LineInput {
} // namespace espp

#endif // CONFIG_COMPILER_CXX_EXCEPTIONS

#endif // ESP_PLATFORM
70 changes: 9 additions & 61 deletions components/color/include/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class Rgb {
*/
Rgb &operator+=(const Rgb &rhs);

bool operator==(const Rgb &rhs) const = default;

bool operator!=(const Rgb &rhs) const = default;

/**
* @brief Get a HSV representation of this RGB color.
* @return An HSV object containing the HSV representation.
Expand Down Expand Up @@ -135,6 +139,10 @@ class Hsv {
*/
Hsv &operator=(const Hsv &other) = default;

bool operator==(const Hsv &rhs) const = default;

bool operator!=(const Hsv &rhs) const = default;

/**
* @brief Assign the values of the provided Rgb object to this Hsv object.
* @param rgb The Rgb object to convert and copy.
Expand All @@ -156,66 +164,6 @@ class Hsv {
return fg(fmt::rgb(rgb.r * 255, rgb.g * 255, rgb.b * 255));
}

// equality operators
[[maybe_unused]] static bool operator==(const Rgb &lhs, const Rgb &rhs) {
return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b;
}

[[maybe_unused]] static bool operator==(const Hsv &lhs, const Hsv &rhs) {
return lhs.h == rhs.h && lhs.s == rhs.s && lhs.v == rhs.v;
}

// inequality operators
[[maybe_unused]] static bool operator!=(const Rgb &lhs, const Rgb &rhs) { return !(lhs == rhs); }

[[maybe_unused]] static bool operator!=(const Hsv &lhs, const Hsv &rhs) { return !(lhs == rhs); }
} // namespace espp

#include "format.hpp"

// for allowing easy serialization/printing of the
// Rgb
template <> struct fmt::formatter<espp::Rgb> {
// Presentation format: 'f' - floating [0,1] (default), 'd' - integer [0,255], 'x' - hex integer.
char presentation = 'f';

template <typename ParseContext> constexpr auto parse(ParseContext &ctx) {
// Parse the presentation format and store it in the formatter:
auto it = ctx.begin(), end = ctx.end();
if (it != end && (*it == 'f' || *it == 'd' || *it == 'x'))
presentation = *it++;

// TODO: Check if reached the end of the range:
// if (it != end && *it != '}') throw format_error("invalid format");

// Return an iterator past the end of the parsed range:
return it;
}

template <typename FormatContext> auto format(espp::Rgb const &rgb, FormatContext &ctx) const {
switch (presentation) {
case 'f':
return fmt::format_to(ctx.out(), "({}, {}, {})", rgb.r, rgb.g, rgb.b);
case 'd':
return fmt::format_to(ctx.out(), "({}, {}, {})", static_cast<int>(rgb.r * 255),
static_cast<int>(rgb.g * 255), static_cast<int>(rgb.b * 255));
case 'x':
return fmt::format_to(ctx.out(), "{:#08X}", rgb.hex());
default:
// shouldn't get here!
return fmt::format_to(ctx.out(), "({}, {}, {})", rgb.r, rgb.g, rgb.b);
}
}
};

// for allowing easy serialization/printing of the
// Rgb
template <> struct fmt::formatter<espp::Hsv> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext> auto format(espp::Hsv const &hsv, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "({}, {}, {})", hsv.h, hsv.s, hsv.v);
}
};
#include "color_formatters.hpp"
50 changes: 50 additions & 0 deletions components/color/include/color_formatters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include "format.hpp"

// for allowing easy serialization/printing of the
// Rgb
template <> struct fmt::formatter<espp::Rgb> {
// Presentation format: 'f' - floating [0,1] (default), 'd' - integer [0,255], 'x' - hex integer.
char presentation = 'f';

template <typename ParseContext> constexpr auto parse(ParseContext &ctx) {
// Parse the presentation format and store it in the formatter:
auto it = ctx.begin(), end = ctx.end();
if (it != end && (*it == 'f' || *it == 'd' || *it == 'x'))
presentation = *it++;

// TODO: Check if reached the end of the range:
// if (it != end && *it != '}') throw format_error("invalid format");

// Return an iterator past the end of the parsed range:
return it;
}

template <typename FormatContext> auto format(espp::Rgb const &rgb, FormatContext &ctx) const {
switch (presentation) {
case 'f':
return fmt::format_to(ctx.out(), "({}, {}, {})", rgb.r, rgb.g, rgb.b);
case 'd':
return fmt::format_to(ctx.out(), "({}, {}, {})", static_cast<int>(rgb.r * 255),
static_cast<int>(rgb.g * 255), static_cast<int>(rgb.b * 255));
case 'x':
return fmt::format_to(ctx.out(), "{:#08X}", rgb.hex());
default:
// shouldn't get here!
return fmt::format_to(ctx.out(), "({}, {}, {})", rgb.r, rgb.g, rgb.b);
}
}
};

// for allowing easy serialization/printing of the
// Hsv
template <> struct fmt::formatter<espp::Hsv> {
template <typename ParseContext> constexpr auto parse(ParseContext &ctx) const {
return ctx.begin();
}

template <typename FormatContext> auto format(espp::Hsv const &hsv, FormatContext &ctx) const {
return fmt::format_to(ctx.out(), "({}, {}, {})", hsv.h, hsv.s, hsv.v);
}
};
10 changes: 6 additions & 4 deletions components/event_manager/include/event_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace espp {
* \section event_manager_ex1 Event Manager Example
* \snippet event_manager_example.cpp event manager example
*/
class EventManager : public BaseComponent {
class EventManager : public espp::BaseComponent {
public:
/**
* @brief Function definition for function prototypes to be called when
Expand Down Expand Up @@ -80,7 +80,8 @@ class EventManager : public BaseComponent {
* registered for that component.
*/
bool add_subscriber(const std::string &topic, const std::string &component,
const event_callback_fn &callback, const size_t stack_size_bytes = 8 * 1024);
const espp::EventManager::event_callback_fn &callback,
const size_t stack_size_bytes = 8192);

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

/**
* @brief Publish \p data on \p topic.
Expand Down Expand Up @@ -128,7 +130,7 @@ class EventManager : public BaseComponent {

protected:
EventManager()
: BaseComponent("Event Manager") {}
: espp::BaseComponent("Event Manager") {}

struct SubscriberData {
std::mutex m;
Expand Down
Loading