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

feat: changes for Jaculus support #11

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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: v13.2.0
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"maintainer": true
}
],
"version": "5.1.0",
"version": "5.2.0",
"frameworks": ["espidf", "arduino"],
"platforms": "espressif32",
"dependencies": [
{
"name": "RB3201-RBProtocol",
"version": "https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.0.0.zip"
"version": "https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.2.0.zip"
}
],
"build": {
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ framework = arduino
upload_speed = 921600
monitor_speed = 115200

lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.0.0.zip
lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.2.0.zip
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
2 changes: 1 addition & 1 deletion test-inis/esp32-idf3-arduino.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ build_flags =
-fmax-errors=5
-DLX16A_ARDUINO=1

lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.0.0.zip
lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.2.0.zip
2 changes: 1 addition & 1 deletion test-inis/esp32-idf4-arduino.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ build_flags =
-fmax-errors=5
-DLX16A_ARDUINO=1

lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.0.0.zip
lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.2.0.zip
2 changes: 1 addition & 1 deletion test-inis/esp32-idf5-idf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ build_flags =
-std=gnu++14
-fmax-errors=5

lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.0.0.zip
lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.2.0.zip
2 changes: 1 addition & 1 deletion test-inis/esp32c3-idf4-arduino.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ build_flags =
-fmax-errors=5
-DLX16A_ARDUINO=1

lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.0.0.zip
lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.2.0.zip
2 changes: 1 addition & 1 deletion test-inis/esp32c3-idf5-idf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ build_flags =
-std=gnu++14
-fmax-errors=5

lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.0.0.zip
lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.2.0.zip
2 changes: 1 addition & 1 deletion test-inis/esp32s3-idf4-arduino.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ build_flags =
-fmax-errors=5
-DLX16A_ARDUINO=1

lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.0.0.zip
lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.2.0.zip
2 changes: 1 addition & 1 deletion test-inis/esp32s3-idf5-idf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ build_flags =
-std=gnu++14
-fmax-errors=5

lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.0.0.zip
lib_deps = https://github.com/RoboticsBrno/RB3201-RBProtocol-library/archive/refs/tags/v13.2.0.zip
Loading