Skip to content

Commit

Permalink
minimal: embedded lhp examples
Browse files Browse the repository at this point in the history
Implements a carousel rendering and displaying remote HTML + JPEG + PNGs
on a variety of display devices, including several EPDs.
  • Loading branch information
lws-team committed Mar 16, 2022
1 parent dfec2c9 commit ad74b77
Show file tree
Hide file tree
Showing 65 changed files with 31,398 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ sdevent, glib and uloop, as well as custom event libs.
News
----

## HTML + CSS + JPEG + PNG display stack in lws

Want to drive your EPD or TFT / OLED display using HTML + CSS? Only got an ESP32?

Want remote JPEGs, PNGs, HTML, RGBA composition, gamma, error diffusion if needed?

Realtime render into a line buffer because you don't have enough heap for a framebuffer?

[Take a look here...](https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.html-parser.md)

## Perl binding for lws available

Thanks to Felipe Gasper, there's now a [perl binding for lws available at metacpan](https://metacpan.org/pod/Net::Libwebsockets),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ render(lws_sorted_usec_list_t *sul)

if (!rs->line) {

lws_display_get_ids_boxes(rs);
lws_display_dl_dump(&rs->displaylist);

/* allocate one line of RGB output pixels to render into */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static const lws_display_ssd1306_t disp = {

static const lws_led_gpio_map_t lgm[] = {
{
.name = "alert",
.name = "red",
.gpio = GPIO_NUM_25,
.pwm_ops = &pwm_ops, /* managed by pwm */
.active_level = 1,
Expand Down Expand Up @@ -205,7 +205,7 @@ init_plat_devices(struct lws_context *ctx)
lws_display_state_init(&lds, ctx, 10000, 20000, lls, &disp.disp);

lws_button_enable(bcs, 0, lws_button_get_bit(bcs, "user"));
lws_led_transition(lls, "alert", &lws_pwmseq_static_off,
lws_led_transition(lls, "red", &lws_pwmseq_static_off,
&lws_pwmseq_static_on);

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ app_main(void)

/* put the logo on the OLED display */

lds.disp->blit(&lds, img, &box);
lds.disp->blit(&lds, img, &box, NULL);
lws_display_state_active(&lds);

/* the lws event loop */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ app_main(void)

/* put the cat picture up there and enable the backlight */

lds.disp->blit(&lds, logo, &box);
lds.disp->blit(&lds, logo, &box, NULL);
lws_display_state_active(&lds);

/* the lws event loop */
Expand Down
81 changes: 81 additions & 0 deletions minimal-examples/embedded/lhp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# lhp (HTML renderer) embedded demos

These are demos for various ESP32 + display combinations. A lot of
the code is common between the demos and is in the toplevel dir
(where this README lives).

Notice that although the demos are for ESP32 currently, there is no
ESP32-specific code in the common part. Only `main/devices.c` in the
combination-specific directories has the platform-specific init.

The demo visits some sites using h2 and renders them on the device +
display combination, with a 10s wait between, in a carousel.

ESP32 WROVER KIT, and ESP32S2 Kaluga boards and displays are
supported, along with Waveshare ESP32 dev board and a variety of
E-ink displays.

## Setting up wifi

Edit ./main/devices.c in your platform-specific subdir, enable this section
and set your wifi SSID and passphrase in the `xxx` strings. This will store
the information on flash on the device.

Boot once with that and then remove your information and disable the code
section again and rebuild.

```
#if 0
/*
* This is a temp hack to bootstrap the settings to contain the test
* AP ssid and passphrase for one time, so the settings can be stored
* while there's no UI atm
*/
{
lws_wifi_creds_t creds;
memset(&creds, 0, sizeof(creds));
lws_strncpy(creds.ssid, "xxx", sizeof(creds.ssid));
lws_strncpy(creds.passphrase, "xxx", sizeof(creds.passphrase));
lws_dll2_add_tail(&creds.list, &netdevs->owner_creds);
if (lws_netdev_credentials_settings_set(netdevs)) {
lwsl_err("%s: failed to write bootstrap creds\n",
__func__);
return 1;
}
}
#endif
```

Eventually there will be a better way to set this up.

## Building

Set up for esp-idf, enter the platform-specific subdir and edit
`build.sh` to point to the correct USB device path.

The first time we need to erase the whole flash and blow the whole
image and partition table

```
$ ./build.sh erase-flash
$ ./build.sh
```

Afterwards you can force-build like this which flashes both OTA
partitions with the new imahe

```
$ ./build.sh f
```

After you have changed `./build.sh` to your own OTA keys and upload path, and adapted the
policy to look at your firmware server, you will typically build via uploading to that,
which resets the board so it can find and install the update and reboot

```
$ ./build.sh u
```

53 changes: 53 additions & 0 deletions minimal-examples/embedded/lhp/esp32-heltec-128-64/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 3.5)

if (ESP_PLATFORM)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(lws-minimal-esp32 C)
enable_testing()

target_link_libraries(lws-minimal-esp32.elf websockets)

option(LWS_WITH_DRIVERS "With generic drivers for gpio, i2c, display etc" ON)
set(LWS_WITH_DRIVERS ON)
option(LWS_WITH_SECURE_STREAMS "With secure streams" ON)
set(LWS_WITH_SECURE_STREAMS ON)
option(LWS_WITH_LWSAC "With lwsac" ON)
set(LWS_WITH_LWSAC ON)
option(LWS_WITH_STRUCT_JSON "With lws_struct JSON" ON)
set(LWS_WITH_STRUCT_JSON ON)
option(LWS_WITH_SYS_NTPCLIENT "With ntpclient" ON)
set(LWS_WITH_SYS_NTPCLIENT ON)
option(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY "Static policy" OFF)
set(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY OFF)
option(LWS_WITH_TLS_JIT_TRUST "With JIT Trust" ON)
set(LWS_WITH_TLS_JIT_TRUST ON)
option(LWS_WITH_COMPRESSED_BACKTRACES "Build with support for compressed backtraces" ON)
set(LWS_WITH_COMPRESSED_BACKTRACES ON)
set(LWS_COMPRESSED_BACKTRACES_SNIP_PRE 2 CACHE STRING "Amount of callstack to snip from top" FORCE)
set(LWS_COMPRESSED_BACKTRACES_SNIP_POST 2 CACHE STRING "Amount of callstack to snip from bottom" FORCE)

option(LWS_WITH_ALLOC_METADATA_LWS "Build lws_*alloc() with compressed backtraces (requires WITH_COMPRESSED_BACKTRACES)" OFF)
set(LWS_WITH_ALLOC_METADATA_LWS OFF)

option(LWS_WITH_OTA "Build with support for Over The Air update download and validation" ON)
set(LWS_WITH_OTA ON)

set(LWS_OTA_VARIANT "esp32-heltec-128-64" CACHE STRING "Build variant for OTA filtering" FORCE)
set(LWS_OTA_PUBLIC_JWK_FILE "$ENV{HOME}/.lws_ota/libwebsockets.org-ota-v1.public.jwk" CACHE STRING "JWK path" FORCE)

set(CMAKE_BUILD_TYPE RELEASE)

add_subdirectory(libwebsockets)

add_test(NAME flashing COMMAND idf.py flash)
set_tests_properties(flashing PROPERTIES
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
TIMEOUT 120)

add_test(NAME boot COMMAND /usr/local/bin/sai-expect)
set_tests_properties(boot PROPERTIES
DEPENDS flashing
TIMEOUT 60)

endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
idf_component_register(SRCS
../../main.c
../../lhp-ss.c
devices.c
INCLUDE_DIRS "../libwebsockets/include;${IDF_PATH}/components/spi_flash/include;${IDF_PATH}/components/nvs_flash/include;${IDF_PATH}/components/mdns/include")

target_link_libraries(${COMPONENT_LIB} websockets)
include_directories(../build/libwebsockets)
Loading

0 comments on commit ad74b77

Please sign in to comment.