Skip to content
Open
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
2 changes: 1 addition & 1 deletion Apps/Calendar/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ set(L10N_DIR ../../../Libraries/AppLocalisation)

tactility_component_register(
SRCS ${SOURCE_FILES} ${L10N_DIR}/Source/AppLocalisation.c
REQUIRES http-module esp_http_client mbedtls localisation-module
REQUIRES http-module localisation-module
INCLUDE_DIRS ${L10N_DIR}/Include $ENV{TACTILITY_SDK_PATH}/Modules/localisation-module/include
)
88 changes: 46 additions & 42 deletions Apps/Calendar/main/Source/CalendarSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
#include <AppLocalisation.h>

#include <app/paths.h>
#include <esp_http_client.h>
#include <http/client.h>
#include <tactility/error.h>
#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
#include <esp_crt_bundle.h>
#endif

#include <algorithm>
#include <cctype>
Expand Down Expand Up @@ -60,16 +57,22 @@ bool isValidWindowTimestamp(const char* value) {
return true;
}

esp_err_t onHttpEvent(esp_http_client_event_t* event) {
auto* parser = static_cast<CalendarResponseParser*>(event->user_data);
if (event->event_id == HTTP_EVENT_ON_DATA && parser != nullptr && event->data_len > 0) {
// The bodies of redirects and authentication challenges are not part of the report.
if (esp_http_client_get_status_code(event->client) >= 300) return ESP_OK;
if (!parser->feed(static_cast<const char*>(event->data), static_cast<size_t>(event->data_len))) {
return ESP_FAIL;
}
}
return ESP_OK;
/** The value of a Basic Authorization header for the user and password, or an empty string when it doesn't fit */
std::string makeBasicAuthorization(const char* username, const char* password) {
static constexpr char ALPHABET[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const std::string credentials = std::string(username) + ":" + password;
std::string result = "Basic ";
for (size_t i = 0; i < credentials.size(); i += 3) {
const size_t left = credentials.size() - i;
const uint32_t chunk = (static_cast<uint8_t>(credentials[i]) << 16) |
((left > 1 ? static_cast<uint8_t>(credentials[i + 1]) : 0) << 8) |
(left > 2 ? static_cast<uint8_t>(credentials[i + 2]) : 0);
result += ALPHABET[(chunk >> 18) & 63];
result += ALPHABET[(chunk >> 12) & 63];
result += left > 1 ? ALPHABET[(chunk >> 6) & 63] : '=';
result += left > 2 ? ALPHABET[chunk & 63] : '=';
}
return result;
}

bool makeFullCalendarReport(char* report, size_t size, char* error, size_t errorSize) {
Expand Down Expand Up @@ -137,36 +140,38 @@ bool makeUpcomingReport(char* report, size_t size,
bool performReport(const CalendarSyncSettings& settings, const char* report,
CalendarResponseParser& parser, const char* invalidMessage,
char* message, size_t messageSize) {
esp_http_client_config_t config {};
config.url = settings.calendarUrl;
config.username = settings.username;
config.password = settings.password;
config.auth_type = HTTP_AUTH_TYPE_BASIC;
config.timeout_ms = HTTP_TIMEOUT_MS;
config.buffer_size = 2048;
config.event_handler = onHttpEvent;
config.user_data = &parser;
#if CONFIG_MBEDTLS_CERTIFICATE_BUNDLE
config.crt_bundle_attach = esp_crt_bundle_attach;
#else
copyText(message, messageSize, tr("This firmware has no HTTPS certificate bundle."));
return false;
#endif

esp_http_client_handle_t client = esp_http_client_init(&config);
HttpClient* client = http_client_alloc();
if (client == nullptr) {
copyText(message, messageSize, tr("Could not create the HTTPS connection."));
return false;
}

esp_err_t result = esp_http_client_set_method(client, HTTP_METHOD_REPORT);
if (result == ESP_OK) result = esp_http_client_set_header(client, "Depth", "1");
if (result == ESP_OK) result = esp_http_client_set_header(client, "Content-Type", "application/xml; charset=utf-8");
if (result == ESP_OK) result = esp_http_client_set_header(client, "Accept", "application/xml");
if (result == ESP_OK) result = esp_http_client_set_post_field(client, report, static_cast<int>(strlen(report)));
if (result == ESP_OK) result = esp_http_client_perform(client);
const int statusCode = esp_http_client_get_status_code(client);
esp_http_client_cleanup(client);
http_client_set_timeout(client, HTTP_TIMEOUT_MS);
// A calendar server may redirect the collection URL, for example to its calendar path
http_client_set_max_redirects(client, 3);
http_client_set_header(client, "Depth", "1");
http_client_set_header(client, "Content-Type", "application/xml; charset=utf-8");
http_client_set_header(client, "Accept", "application/xml");
if (settings.username[0] != '\0') {
// Sent right away, as the client doesn't answer a challenge. It isn't sent to another server after a redirect.
const std::string authorization = makeBasicAuthorization(settings.username, settings.password);
http_client_set_header(client, "Authorization", authorization.c_str());
}

bool received = http_client_send(client, "REPORT", settings.calendarUrl, report, strlen(report)) == ERROR_NONE;
const int statusCode = received ? http_client_get_status_code(client) : 0;
// The bodies of redirects and authentication challenges are not part of the report.
if (received && statusCode >= 200 && statusCode < 300) {
char buffer[2048];
while (true) {
const int read = http_client_read(client, buffer, sizeof(buffer));
if (read == 0) break;
if (read < 0 || !parser.feed(buffer, static_cast<size_t>(read))) {
received = false;
break;
}
}
}
http_client_free(client);

if (parser.error() == CalendarResponseParser::Error::OutOfMemory) {
copyText(message, messageSize, tr("The calendar has too many events for the memory of this device."));
Expand All @@ -176,12 +181,11 @@ bool performReport(const CalendarSyncSettings& settings, const char* report,
copyText(message, messageSize, tr("A calendar entry is too large to load."));
return false;
}
// Checked before the result: the client reports an error for a challenge that it can't answer.
if (statusCode == 401 || statusCode == 403) {
copyText(message, messageSize, tr("CalDAV authentication failed or access was denied."));
return false;
}
if (result != ESP_OK) {
if (!received) {
copyText(message, messageSize, tr("Sync failed. Check Wi-Fi, URL and HTTPS certificate."));
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions Apps/Calendar/manifest.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ manifest.version=0.3
target.sdk=0.8.0-dev
target.platforms=esp32,esp32s3,esp32p4,esp32s31
id=tactility.calendar
version.name=0.7.2
version.code=11
version.name=0.7.3
version.code=12
name=Calendar
description.short=Read-only CalDAV calendar
description.short.de-DE=CalDAV-Kalender (nur lesen)
Expand Down
5 changes: 4 additions & 1 deletion Apps/EpubReader/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ set(L10N_DIR ../../../Libraries/AppLocalisation)

tactility_component_register(
SRCS ${SOURCE_FILES} ${L10N_DIR}/Source/AppLocalisation.c
REQUIRES esp_rom localisation-module
REQUIRES miniz-module localisation-module
INCLUDE_DIRS ${L10N_DIR}/Include $ENV{TACTILITY_SDK_PATH}/Modules/localisation-module/include
)
# miniz comes from miniz-module. Its header must come before the older one of esp_rom, which every ESP-IDF component gets,
# and the SDK doesn't add the include directory for apps.
target_include_directories(${COMPONENT_LIB} BEFORE PRIVATE $ENV{TACTILITY_SDK_PATH}/Modules/miniz-module/include)
4 changes: 2 additions & 2 deletions Apps/EpubReader/manifest.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ manifest.version=0.3
target.sdk=0.8.0-dev
target.platforms=esp32s3,esp32p4,esp32s31
id=tactility.epubreader
version.name=0.28.1
version.code=29
version.name=0.28.2
version.code=30
requires.ram=2M
name=ePub Reader
description.short=ePub and text file reader
Expand Down
15 changes: 14 additions & 1 deletion Apps/Maps/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@ include("$ENV{TACTILITY_SDK_PATH}/TactilitySDK.cmake")
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
tactility_component_register(
SRCS ${SOURCE_FILES}
REQUIRES graphics-module binfont-module location-module http-module esp_rom esp_driver_ppa
REQUIRES graphics-module binfont-module location-module http-module miniz-module esp_driver_ppa
)
# ESP-IDF sets COMPONENT_LIB; host (linux/macOS) builds name the library after the project.
if (NOT DEFINED COMPONENT_LIB)
set(COMPONENT_LIB ${PROJECT_NAME})
endif ()
# The host SDK target doesn't list these modules' include dirs (ESP-IDF resolves them through REQUIRES)
if (NOT ESP_PLATFORM)
target_include_directories(${COMPONENT_LIB} PRIVATE
$ENV{TACTILITY_SDK_PATH}/Modules/graphics-module/include
$ENV{TACTILITY_SDK_PATH}/Modules/location-module/include)
endif ()
# miniz comes from miniz-module on every platform. On ESP32 its header must come before the older one of esp_rom,
# which every ESP-IDF component gets, and the SDK no longer adds the include directory for apps.
target_include_directories(${COMPONENT_LIB} BEFORE PRIVATE $ENV{TACTILITY_SDK_PATH}/Modules/miniz-module/include)
target_compile_options(${COMPONENT_LIB} PRIVATE -O2 -Wno-format-truncation)
# The search index must match the PC's byte for byte (M6): no fused multiply-add in its float maths (MSVC on the PC
# does not fuse; GCC would, and one house at the 50 m limit then went to another street)
Expand Down
17 changes: 8 additions & 9 deletions Apps/Maps/main/Source/app/BrowsedCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "../platform/Platform.h"
#include "../tiles/TileStore.h"

#include <esp_heap_caps.h>
#include <freertos/idf_additions.h>
#include "EspCompat.h"
#include "Threads.h"

#include <dirent.h>

Expand Down Expand Up @@ -127,7 +127,7 @@ bool BrowsedCounter::count(const DownloadPlan& plan, int64_t& out) const {
return true;
}

void BrowsedCounter::taskMain(void* context) {
int32_t BrowsedCounter::taskMain(void* context) {
auto* counter = static_cast<BrowsedCounter*>(context);
CountJob job { counter->rootPath, counter->counting, 0, false };
// A count that gave way to the map is tried again a little later
Expand All @@ -140,14 +140,14 @@ void BrowsedCounter::taskMain(void* context) {
counter->countingResult = job.count;
counter->countingComplete = job.complete;
counter->finished = true;
// Deleted by poll() or stop(): a task cannot free its own PSRAM stack
vTaskSuspend(nullptr);
// Joined by poll() or stop(): a thread cannot free its own PSRAM stack
return 0;
}

bool BrowsedCounter::poll(uint32_t nowMs) {
bool changed = false;
if (task != nullptr && finished) {
vTaskDeleteWithCaps(task);
joinThread(task);
task = nullptr;
if (!countingComplete) {
// Gave way to the map too often: try again after a pause
Expand All @@ -163,8 +163,7 @@ bool BrowsedCounter::poll(uint32_t nowMs) {
wanted.fits && wanted.tiles > 0) {
counting = wanted;
finished = false;
if (xTaskCreatePinnedToCoreWithCaps(taskMain, "maps-count", TASK_STACK, this, TASK_PRIORITY, &task, tskNO_AFFINITY,
MALLOC_CAP_SPIRAM) != pdPASS) {
if ((task = startThread("maps-count", TASK_STACK, taskMain, this, TASK_PRIORITY, tskNO_AFFINITY, true)) == nullptr) {
task = nullptr;
// Not counted: the estimate simply shows no tiles on the card
hasWanted = false;
Expand All @@ -180,7 +179,7 @@ void BrowsedCounter::stop() {
while (!finished) {
vTaskDelay(pdMS_TO_TICKS(10));
}
vTaskDeleteWithCaps(task);
joinThread(task);
task = nullptr;
}

Expand Down
9 changes: 5 additions & 4 deletions Apps/Maps/main/Source/app/BrowsedCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

#include "../tiles/DownloadPlan.h"

#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <tactility/freertos/freertos.h>
#include <tactility/freertos/task.h>
#include <tactility/concurrent/thread.h>

#include <atomic>
#include <cstdint>
Expand Down Expand Up @@ -36,12 +37,12 @@ class BrowsedCounter {
static constexpr uint32_t SETTLE_MS = 400;

private:
static void taskMain(void* context);
static int32_t taskMain(void* context);
static bool samePlan(const DownloadPlan& a, const DownloadPlan& b);

IoTask* io = nullptr;
char rootPath[160] = "";
TaskHandle_t task = nullptr;
Thread* task = nullptr;
std::atomic<bool> finished { false };
/** The plan wanted on screen, since when, and the one being counted. */
DownloadPlan wanted {};
Expand Down
Loading
Loading