Skip to content

Commit

Permalink
feat: changes for Jaculus support
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasssadar committed Jun 25, 2024
1 parent b7bbe40 commit ebe8256
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 5 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set(SRCS
"src/builder/widget.cpp"
"src/widgets/widget.cpp"
"src/gridui.cpp"
)

idf_component_register(
SRCS ${SRCS}
INCLUDE_DIRS "./src"
REQUIRES esp_timer RB3201-RBProtocol-library
EMBED_FILES ${CMAKE_CURRENT_BINARY_DIR}/combined.js.gz ${CMAKE_CURRENT_BINARY_DIR}/index.html.gz
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/combined.js.gz ${CMAKE_CURRENT_BINARY_DIR}/index.html.gz
COMMAND ${COMPONENT_DIR}/rbgridui_post_extra_script.py generate -o ${CMAKE_CURRENT_BINARY_DIR}
)

target_compile_options(${COMPONENT_LIB} PRIVATE -DRBGRIDUI_USING_ESP_IDF=1)

5 changes: 5 additions & 0 deletions idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dependencies:
idf: ">=5.1"
RB3201-RBProtocol-library:
git: https://github.com/RoboticsBrno/RB3201-RBProtocol-library.git
version: 9272a43675db630d3ae69a3dafb8cbe978f42fdd
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"maintainer": true
}
],
"version": "5.1.0",
"version": "5.2.0",
"frameworks": ["espidf", "arduino"],
"platforms": "espressif32",
"dependencies": [
Expand Down
3 changes: 2 additions & 1 deletion rbgridui_post_extra_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ def after_upload(source, target, env, base="."):

sub = subparsers.add_parser("generate", help="Generate amalgamations from web/ to data/")
sub.add_argument("--base", help="Base dir of the library", default=os.path.dirname(__file__))
sub.add_argument("--output", "-o", help="Output directory", default="data")

args = parser.parse_args()

env = {
"PROJECTDATA_DIR": "data",
"PROJECTDATA_DIR": args.output,
}

if args.cmd == "generate":
Expand Down
5 changes: 5 additions & 0 deletions src/builder/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class Button : public Widget, public BuilderMixin<Button, gridui::Button> {
return *this;
}

Button& text(const std::string& text) {
extra().set("text", text);
return *this;
}

Button& fontSize(float fontSize) {
extra().set("fontSize", fontSize);
return *this;
Expand Down
2 changes: 2 additions & 0 deletions src/builder/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class Widget {
Widget(Widget&& o) noexcept;
virtual ~Widget();

const char *widgetTypeName() const { return m_type; }

protected:
Widget(const char* type, WidgetState& state);

Expand Down
32 changes: 32 additions & 0 deletions src/gridui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@ static void defaultOnPacketReceived(const std::string& cmd, rbjson::Object* pkt)
// ignore the rest
}

#ifdef RBGRIDUI_USING_ESP_IDF

extern const uint8_t index_html_start[] asm("_binary_index_html_gz_start");
extern const uint8_t index_html_end[] asm("_binary_index_html_gz_end");

extern const uint8_t combined_js_start[] asm("_binary_combined_js_gz_start");
extern const uint8_t combined_js_end[] asm("_binary_combined_js_gz_end");

not_found_response_t webserverNotFoundCallback(const char *request_path) {
not_found_response_t resp = {};
if(strcmp(request_path, "/") == 0 || strcmp(request_path, "/index.html") == 0) {
resp.data = (uint8_t*)index_html_start;
resp.size = index_html_end - index_html_start;
resp.is_gzipped = 1;
} else if(strcmp(request_path, "/combined.js") == 0) {
resp.data = (uint8_t*)combined_js_start;
resp.size = combined_js_end - combined_js_start;
resp.is_gzipped = 1;
}
return resp;
}
#else
not_found_response_t webserverNotFoundCallback(const char *request_path) {
not_found_response_t resp = {};
return resp;
}
#endif

_GridUi::_GridUi()
: m_protocol(nullptr)
, m_protocol_ours(false)
Expand Down Expand Up @@ -55,6 +83,10 @@ rb::Protocol* _GridUi::begin(const char* owner, const char* deviceName) {
return nullptr;
}

#ifdef RBGRIDUI_USING_ESP_IDF
rb_web_set_not_found_callback(webserverNotFoundCallback);
#endif

auto protocol = new rb::Protocol(owner, deviceName, "Compiled at " __DATE__ " " __TIME__, defaultOnPacketReceived);
protocol->start();

Expand Down
6 changes: 5 additions & 1 deletion src/gridui.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "esp_timer.h"

#include "rbwebserver.h"

#include "builder/arm.h"
#include "builder/bar.h"
#include "builder/button.h"
Expand All @@ -35,6 +37,8 @@ namespace gridui {

class WidgetState;

not_found_response_t webserverNotFoundCallback(const char *request_path);

class _GridUi {
friend class WidgetState;

Expand Down Expand Up @@ -143,7 +147,6 @@ class _GridUi {
return *newWidget<builder::Select>(x, y, w, h, uuid, tab);
}

private:
template <typename T>
T* newWidget(float x, float y, float w, float h, uint16_t uuid, uint16_t tab) {
static_assert(std::is_base_of<builder::Widget, T>::value, "T must inherit from builder::Widget.");
Expand All @@ -161,6 +164,7 @@ class _GridUi {
return widget;
}

private:
inline WidgetState* stateByUuidLocked(uint16_t uuid) const {
for (auto& itr : m_states) {
if (itr->uuid() == uuid) {
Expand Down
2 changes: 1 addition & 1 deletion src/gridui_version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once

#define RB_GRIDUI_VERSION 0x050100
#define RB_GRIDUI_VERSION 0x050200
5 changes: 4 additions & 1 deletion src/widgets/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ class Widget {
: m_state(o.m_state) {
}

Widget(const Widget& o)
: m_state(o.m_state) {
}

Widget& operator=(const Widget&& o) {
m_state = o.m_state;
return *this;
Expand Down Expand Up @@ -206,7 +210,6 @@ class Widget {
: m_state(state) {
}

Widget(const Widget&) = delete;
Widget& operator=(const Widget&) = delete;

const rbjson::Object& data() const { return static_cast<const WidgetState*>(m_state)->data(); }
Expand Down

0 comments on commit ebe8256

Please sign in to comment.