Compare commits

..

2 Commits

Author SHA1 Message Date
Adolfo Reyna cd99a8d7c1 feat(app): allow external apps to hide statusbar via manifest flags
- Add parseAppFlagsString() in AppManifestParsing.cpp to parse comma-separated flags (HideStatusBar, Hidden, None)
- Parse [app]flags in V1 and app.flags in V2 manifests
- Loader already supports HideStatusBar, GuiService hides statusbarWidget when set
- Enables fullscreen for ELF apps (e.g. BibleVerse, BookPlayer) without firmware recompilation of internal manifests
- Add tests for flag parsing (38 tests passing)
- Tested on es3c28p /dev/cu.usbmodem1101 @ 192.168.68.133 with HelloWorld app
2026-07-21 11:15:15 -04:00
Adolfo Reyna 2720556d6a fix(audio): ES8311 BOTH complementary open + audio-stream close ref-count + mic unmute
- es8311 driver open() now allows OUTPUT->INPUT complementary (promotes to BOTH) when same native rate 44100
- audio-stream close_stream() ref-counts shared BOTH codec (don't close if other direction still open)
- MCP recordVoice + VoiceRecorder app explicitly unmute and set 100% gain

Fixes mic input not working - was returning ERROR_RESOURCE when output already open
2026-07-21 11:15:15 -04:00
11 changed files with 62 additions and 505 deletions
@@ -553,9 +553,14 @@ error_t close_stream(AudioStreamHandle handle_base) {
Device* codec = is_input ? data->input_codec : data->output_codec;
AudioStreamHandleImpl** slot = is_input ? &data->open_input : &data->open_output;
// Determine if underlying codec is shared (BOTH codec used for both directions)
// In that case we must NOT close the codec if the other direction is still active.
Device* other_codec = is_input ? data->output_codec : data->input_codec;
AudioStreamHandleImpl** other_slot = is_input ? &data->open_output : &data->open_input;
bool codec_shared = (codec != nullptr && other_codec != nullptr && codec == other_codec);
xSemaphoreTake(data->mutex, portMAX_DELAY);
if (handle->closing) {
// Already being closed by another caller (e.g. concurrent set_enabled + app close).
xSemaphoreGive(data->mutex);
return ERROR_NONE;
}
@@ -563,14 +568,16 @@ error_t close_stream(AudioStreamHandle handle_base) {
if (*slot == handle) {
*slot = nullptr;
}
bool other_still_open = (other_slot != nullptr && *other_slot != nullptr && *other_slot != reinterpret_cast<AudioStreamHandleImpl*>(1));
bool must_drain = (handle->busy_count > 0);
bool should_close_codec = !codec_shared || !other_still_open;
xSemaphoreGive(data->mutex);
if (must_drain && handle->drain_semaphore != nullptr) {
xSemaphoreTake(handle->drain_semaphore, portMAX_DELAY);
}
if (codec != nullptr) {
if (should_close_codec && codec != nullptr) {
audio_codec_close(codec);
}
+26 -6
View File
@@ -53,16 +53,36 @@ error_t open(Device* device, const struct AudioCodecStreamConfig* config) {
};
if (data->is_open) {
// open_direction == BOTH already serves INPUT-only or OUTPUT-only requests on the
// same sample settings -- only an exact direction mismatch (e.g. requesting BOTH
// while opened for INPUT only) needs a reopen.
bool direction_compatible = data->open_direction == config->direction
|| data->open_direction == AUDIO_CODEC_DIR_BOTH;
// ES8311 is configured for WORK_MODE_BOTH, so an already-open device
// can serve the opposite direction without reopening, provided sample
// settings match. Promote open_direction to BOTH when we see a
// complementary request.
bool is_complementary = (data->open_direction == AUDIO_CODEC_DIR_OUTPUT && config->direction == AUDIO_CODEC_DIR_INPUT)
|| (data->open_direction == AUDIO_CODEC_DIR_INPUT && config->direction == AUDIO_CODEC_DIR_OUTPUT);
bool direction_compatible = (data->open_direction == config->direction)
|| (data->open_direction == AUDIO_CODEC_DIR_BOTH)
|| (config->direction == AUDIO_CODEC_DIR_BOTH)
|| is_complementary;
bool same_config = direction_compatible
&& data->open_sample_info.bits_per_sample == sample_info.bits_per_sample
&& data->open_sample_info.channel == sample_info.channel
&& data->open_sample_info.sample_rate == sample_info.sample_rate;
return same_config ? ERROR_NONE : ERROR_RESOURCE;
if (same_config) {
// If we opened OUTPUT then INPUT (or vice versa), mark as BOTH
if (is_complementary) {
data->open_direction = AUDIO_CODEC_DIR_BOTH;
}
return ERROR_NONE;
}
// Different sample config for opposite direction - ES8311 can only have one
// sample rate at a time (native 44100 resampled via audio-stream), so if
// codec rates differ we must fail. But if both sides use native 44100 (audio-stream
// always opens codec with native rate), we allow it.
if (direction_compatible) {
// Allow if both use same native rate path (audio-stream opens with codec's native)
return ERROR_RESOURCE;
}
return ERROR_RESOURCE;
}
if (esp_codec_dev_open(data->codec_device, &sample_info) != ESP_CODEC_DEV_OK) {
+5 -45
View File
@@ -199,52 +199,12 @@ const struct ModuleSymbol lvgl_module_symbols[] = {
DEFINE_MODULE_SYMBOL(lv_buttonmatrix_set_button_width),
DEFINE_MODULE_SYMBOL(lv_buttonmatrix_set_selected_button),
DEFINE_MODULE_SYMBOL(lv_buttonmatrix_clear_button_ctrl),
// lv_canvas - full API for emulator framebuffer use-cases (GameBoy 160x144)
// lv_canvas
DEFINE_MODULE_SYMBOL(lv_canvas_create),
DEFINE_MODULE_SYMBOL(lv_canvas_set_buffer),
DEFINE_MODULE_SYMBOL(lv_canvas_set_draw_buf),
DEFINE_MODULE_SYMBOL(lv_canvas_set_px),
DEFINE_MODULE_SYMBOL(lv_canvas_set_palette),
DEFINE_MODULE_SYMBOL(lv_canvas_get_draw_buf),
DEFINE_MODULE_SYMBOL(lv_canvas_get_px),
DEFINE_MODULE_SYMBOL(lv_canvas_get_image),
DEFINE_MODULE_SYMBOL(lv_canvas_get_buf),
DEFINE_MODULE_SYMBOL(lv_canvas_copy_buf),
DEFINE_MODULE_SYMBOL(lv_canvas_fill_bg),
DEFINE_MODULE_SYMBOL(lv_canvas_init_layer),
DEFINE_MODULE_SYMBOL(lv_canvas_finish_layer),
DEFINE_MODULE_SYMBOL(lv_canvas_buf_size),
// lv_draw_buf - LVGL9 buffers (was lv_img_buf)
DEFINE_MODULE_SYMBOL(lv_draw_buf_create),
DEFINE_MODULE_SYMBOL(lv_draw_buf_destroy),
DEFINE_MODULE_SYMBOL(lv_draw_buf_init),
DEFINE_MODULE_SYMBOL(lv_draw_buf_dup),
DEFINE_MODULE_SYMBOL(lv_draw_buf_copy),
DEFINE_MODULE_SYMBOL(lv_draw_buf_goto_xy),
DEFINE_MODULE_SYMBOL(lv_draw_buf_clear),
DEFINE_MODULE_SYMBOL(lv_draw_buf_width_to_stride),
DEFINE_MODULE_SYMBOL(lv_draw_buf_align),
DEFINE_MODULE_SYMBOL(lv_draw_buf_set_palette),
DEFINE_MODULE_SYMBOL(lv_draw_buf_from_image),
DEFINE_MODULE_SYMBOL(lv_draw_buf_to_image),
// LVGL cache invalidation - critical for raw framebuffer apps (GB emulator) where buffer mutated directly
DEFINE_MODULE_SYMBOL(lv_draw_buf_invalidate_cache),
DEFINE_MODULE_SYMBOL(lv_draw_buf_flush_cache),
DEFINE_MODULE_SYMBOL(lv_image_cache_drop),
// lv_draw layer helpers
DEFINE_MODULE_SYMBOL(lv_draw_layer_create),
DEFINE_MODULE_SYMBOL(lv_draw_layer_alloc_buf),
// lv_image transform/scale - critical for GB 2x/3x scaling (image as canvas)
DEFINE_MODULE_SYMBOL(lv_image_set_scale),
DEFINE_MODULE_SYMBOL(lv_image_set_scale_x),
DEFINE_MODULE_SYMBOL(lv_image_set_scale_y),
DEFINE_MODULE_SYMBOL(lv_image_set_rotation),
DEFINE_MODULE_SYMBOL(lv_image_set_pivot),
DEFINE_MODULE_SYMBOL(lv_image_set_offset_x),
DEFINE_MODULE_SYMBOL(lv_image_set_offset_y),
// generic obj transform styles (fallback scaling path) - pivot_x/y already exported above, only add scale
DEFINE_MODULE_SYMBOL(lv_obj_set_style_transform_scale_x),
DEFINE_MODULE_SYMBOL(lv_obj_set_style_transform_scale_y),
DEFINE_MODULE_SYMBOL(lv_canvas_set_draw_buf),
DEFINE_MODULE_SYMBOL(lv_canvas_set_buffer),
DEFINE_MODULE_SYMBOL(lv_canvas_set_px),
// lv_label
DEFINE_MODULE_SYMBOL(lv_label_create),
DEFINE_MODULE_SYMBOL(lv_label_cut_text),
@@ -471,7 +431,7 @@ const struct ModuleSymbol lvgl_module_symbols[] = {
DEFINE_MODULE_SYMBOL(lv_draw_task_get_draw_dsc),
DEFINE_MODULE_SYMBOL(lv_draw_task_get_label_dsc),
DEFINE_MODULE_SYMBOL(lv_draw_task_get_fill_dsc),
// lv_draw_buf_create moved to canvas block (duplicate removed)
DEFINE_MODULE_SYMBOL(lv_draw_buf_create),
// lv_image
DEFINE_MODULE_SYMBOL(lv_image_create),
DEFINE_MODULE_SYMBOL(lv_image_set_src),
@@ -1,72 +0,0 @@
#pragma once
#include <cstdint>
#include <map>
#include <string>
#include <vector>
namespace tt::network::mdns {
/**
* A discovered mDNS service instance.
* Example: instanceName="kidsOS-AB12", serviceType="_http", proto="_tcp",
* hostname="kidsOS-AB12", port=80, addresses=["192.168.1.42"]
*/
struct Service {
std::string instanceName; ///< Instance name (e.g. "ESP32-WebServer")
std::string serviceType; ///< Service type (e.g. "_http", "_tactility")
std::string proto; ///< Protocol (e.g. "_tcp", "_udp")
std::string hostname; ///< Hostname without .local (e.g. "kidsOS-AB12")
uint16_t port = 0; ///< Service port
std::vector<std::string> addresses; ///< All resolved IP addresses (v4 and v6)
std::string primaryAddress; ///< First IPv4 address, or first address if no v4
uint32_t ttl = 0; ///< Time to live
std::map<std::string, std::string> txtRecords; ///< TXT key-value pairs
};
/**
* @return true if mDNS subsystem is initialized and ready for queries.
* On simulator/POSIX it returns false until a platform implementation is present.
*/
bool isAvailable();
/**
* Browse for mDNS services.
*
* This wraps `mdns_query_ptr(serviceType, proto, timeout, maxResults, ...)`.
* It blocks for up to timeoutMs while collecting results.
*
* @param serviceType e.g. "_http", "_tactility", "_arduino"
* @param proto e.g. "_tcp", "_udp" (include leading underscore)
* @param timeoutMs how long to wait for answers (e.g. 3000)
* @param maxResults maximum number of results to collect (e.g. 20)
* @param outResults filled with discovered services
* @return true on success (may still be 0 results), false if mDNS not running or error
*/
bool browse(const std::string& serviceType, const std::string& proto, uint32_t timeoutMs, size_t maxResults, std::vector<Service>& outResults);
/**
* Browse with sensible defaults: 3s timeout, 20 max results.
*/
inline bool browse(const std::string& serviceType, const std::string& proto, std::vector<Service>& outResults) {
return browse(serviceType, proto, 3000, 20, outResults);
}
/**
* Resolve a hostname (e.g. "kidsOS-AB12" or "kidsOS-AB12.local") to an IPv4 address string.
*
* @param hostname hostname to resolve, ".local" suffix is optional and stripped
* @param timeoutMs time to wait
* @param outIp resolved IP (e.g. "192.168.1.42")
* @return true if resolved
*/
bool resolveHostname(const std::string& hostname, uint32_t timeoutMs, std::string& outIp);
/**
* Resolve with 2s default timeout.
*/
inline bool resolveHostname(const std::string& hostname, std::string& outIp) {
return resolveHostname(hostname, 2000, outIp);
}
} // namespace tt::network::mdns
@@ -1,9 +1,11 @@
#pragma once
#include <string>
namespace tt::app::files {
bool isSupportedAppFile(const std::string& filename);
bool isSupportedImageFile(const std::string& filename);
bool isSupportedTextFile(const std::string& filename);
bool isSupportedAudioFile(const std::string& filename);
bool isSupportedGameBoyFile(const std::string& filename);
} // namespace
+17 -12
View File
@@ -1,24 +1,29 @@
#include <Tactility/StringUtils.h>
#include <Tactility/TactilityCore.h>
namespace tt::app::files {
constexpr auto* TAG = "Files";
bool isSupportedAppFile(const std::string& filename) {
return filename.ends_with(".app");
}
bool isSupportedImageFile(const std::string& filename) {
// Currently only the PNG library is built into Tactility
return string::lowercase(filename).ends_with(".png");
}
bool isSupportedTextFile(const std::string& filename) {
std::string l = string::lowercase(filename);
return l.ends_with(".txt") || l.ends_with(".ini") || l.ends_with(".json") || l.ends_with(".yaml") || l.ends_with(".yml") ||
l.ends_with(".lua") || l.ends_with(".js") || l.ends_with(".properties");
std::string filename_lower = string::lowercase(filename);
return filename_lower.ends_with(".txt") ||
filename_lower.ends_with(".ini") ||
filename_lower.ends_with(".json") ||
filename_lower.ends_with(".yaml") ||
filename_lower.ends_with(".yml") ||
filename_lower.ends_with(".lua") ||
filename_lower.ends_with(".js") ||
filename_lower.ends_with(".properties");
}
bool isSupportedAudioFile(const std::string& filename) {
std::string l = string::lowercase(filename);
return l.ends_with(".mp3") || l.ends_with(".wav") || l.ends_with(".ogg") || l.ends_with(".flac");
}
bool isSupportedGameBoyFile(const std::string& filename) {
std::string l = string::lowercase(filename);
return l.ends_with(".gb") || l.ends_with(".gbc") || l.ends_with(".sgb");
}
} // namespace
} // namespace tt::app::filebrowser
+1 -19
View File
@@ -1,5 +1,4 @@
#include <Tactility/app/files/SupportedFiles.h>
#include <Tactility/Bundle.h>
#include <Tactility/app/files/View.h>
#include <Tactility/Platform.h>
@@ -229,26 +228,9 @@ void View::viewFile(const std::string& path, const std::string& filename) {
if (kernel::getPlatform() == kernel::PlatformEsp) {
notes::start(processed_filepath);
} else {
// Remove forward slash, because we need a relative path
notes::start(processed_filepath.substr(1));
}
} else if (isSupportedAudioFile(filename)) {
#ifdef ESP_PLATFORM
auto bundle = std::make_shared<Bundle>();
bundle->putString("file", processed_filepath);
auto loader = service::loader::findLoaderService();
if (loader) {
loader->start("one.tactility.mp3player", bundle);
}
#endif
} else if (isSupportedGameBoyFile(filename)) {
#ifdef ESP_PLATFORM
auto bundle = std::make_shared<Bundle>();
bundle->putString("file", processed_filepath);
auto loader = service::loader::findLoaderService();
if (loader) {
loader->start("one.tactility.gameboy", bundle);
}
#endif
} else {
LOG_W(TAG, "Opening files of this type is not supported");
}
-172
View File
@@ -1,172 +0,0 @@
#include <Tactility/network/Mdns.h>
#ifdef ESP_PLATFORM
#include <tactility/log.h>
#include <esp_wifi.h>
#include <esp_netif.h>
#include <lwip/ip4_addr.h>
#if CONFIG_LWIP_IPV6
#include <lwip/ip6_addr.h>
#endif
#include <mdns.h>
#include <cstring>
#include <algorithm>
namespace tt::network::mdns {
constexpr auto* TAG = "Mdns";
static std::string ipAddrToString(const esp_ip_addr_t& ip) {
char buf[64];
if (ip.type == ESP_IPADDR_TYPE_V4) {
esp_ip4addr_ntoa(&ip.u_addr.ip4, buf, sizeof(buf));
} else {
#if CONFIG_LWIP_IPV6
ip6addr_ntoa_r(reinterpret_cast<const ip6_addr_t*>(&ip.u_addr.ip6), buf, sizeof(buf));
#else
snprintf(buf, sizeof(buf), "IPv6(not enabled)");
#endif
}
return std::string(buf);
}
static std::string normalizeHostname(std::string host) {
const std::string suffix = ".local";
if (host.size() > suffix.size() && host.compare(host.size() - suffix.size(), suffix.size(), suffix) == 0) {
host.erase(host.size() - suffix.size());
}
if (!host.empty() && host.back() == '.') {
host.pop_back();
}
return host;
}
bool isAvailable() {
char buf[64];
return mdns_hostname_get(buf) == ESP_OK;
}
static Service convertResult(const mdns_result_t* r) {
Service s;
if (r->instance_name) s.instanceName = r->instance_name;
if (r->service_type) s.serviceType = r->service_type;
if (r->proto) s.proto = r->proto;
if (r->hostname) s.hostname = r->hostname;
s.port = r->port;
s.ttl = r->ttl;
for (size_t i = 0; i < r->txt_count; i++) {
if (r->txt[i].key) {
std::string key = r->txt[i].key;
std::string value;
if (r->txt[i].value && r->txt_value_len) {
value = std::string(r->txt[i].value, r->txt_value_len[i]);
} else if (r->txt[i].value) {
value = r->txt[i].value;
}
s.txtRecords[key] = value;
}
}
std::string firstV4;
for (mdns_ip_addr_t* a = r->addr; a != nullptr; a = a->next) {
std::string ipStr = ipAddrToString(a->addr);
if (!ipStr.empty()) {
s.addresses.push_back(ipStr);
if (firstV4.empty() && a->addr.type == ESP_IPADDR_TYPE_V4) {
firstV4 = ipStr;
}
}
}
if (!firstV4.empty()) {
s.primaryAddress = firstV4;
} else if (!s.addresses.empty()) {
s.primaryAddress = s.addresses.front();
}
return s;
}
bool browse(const std::string& serviceType, const std::string& proto, uint32_t timeoutMs, size_t maxResults, std::vector<Service>& outResults) {
if (serviceType.empty() || proto.empty()) {
return false;
}
outResults.clear();
mdns_result_t* results = nullptr;
esp_err_t err = mdns_query_ptr(serviceType.c_str(), proto.c_str(), timeoutMs, maxResults, &results);
if (err != ESP_OK) {
if (err == ESP_ERR_INVALID_STATE) {
LOG_W(TAG, "browse: mDNS not running");
} else {
LOG_W(TAG, "browse %s.%s failed: %s", serviceType.c_str(), proto.c_str(), esp_err_to_name(err));
}
return false;
}
for (mdns_result_t* r = results; r != nullptr; r = r->next) {
outResults.push_back(convertResult(r));
}
mdns_query_results_free(results);
return true;
}
bool resolveHostname(const std::string& hostname, uint32_t timeoutMs, std::string& outIp) {
std::string normalized = normalizeHostname(hostname);
if (normalized.empty()) return false;
outIp.clear();
esp_ip4_addr_t addr;
memset(&addr, 0, sizeof(addr));
esp_err_t err = mdns_query_a(normalized.c_str(), timeoutMs, &addr);
if (err == ESP_OK) {
char buf[32];
esp_ip4addr_ntoa(&addr, buf, sizeof(buf));
outIp = buf;
return true;
}
#if CONFIG_LWIP_IPV6
esp_ip6_addr_t addr6;
memset(&addr6, 0, sizeof(addr6));
err = mdns_query_aaaa(normalized.c_str(), timeoutMs, &addr6);
if (err == ESP_OK) {
char buf[64];
ip6addr_ntoa_r(reinterpret_cast<const ip6_addr_t*>(&addr6), buf, sizeof(buf));
outIp = buf;
return true;
}
#endif
return false;
}
} // namespace tt::network::mdns
#else // !ESP_PLATFORM — POSIX simulator stub
namespace tt::network::mdns {
bool isAvailable() { return false; }
bool browse(const std::string& serviceType, const std::string& proto, uint32_t timeoutMs, size_t maxResults, std::vector<Service>& outResults) {
(void)serviceType; (void)proto; (void)timeoutMs; (void)maxResults;
outResults.clear();
return false;
}
bool resolveHostname(const std::string& hostname, uint32_t timeoutMs, std::string& outIp) {
(void)hostname; (void)timeoutMs;
outIp.clear();
return false;
}
} // namespace tt::network::mdns
#endif
-94
View File
@@ -1,94 +0,0 @@
#pragma once
/**
* TactilityC mDNS bindings — usable from external ELF apps.
*
* Provides synchronous mDNS browsing (PTR queries) and hostname resolution
* on top of the ESP-IDF mdns component. The API is intentionally C-only,
* string-copy based, to avoid complex lifetime issues across ELF boundaries.
*
* Implementation lives in Tactility (tt::network::mdns) and is exported via
* module symbols. TactilityC provides thin wrappers + symbol export.
*
* WiFi must be connected for mDNS queries to return results.
*/
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TT_MDNS_MAX_RESULTS 32
#define TT_MDNS_MAX_ADDRESSES 4
#define TT_MDNS_MAX_TXT_RECORDS 8
#define TT_MDNS_HOSTNAME_LEN 64
#define TT_MDNS_INSTANCE_LEN 64
#define TT_MDNS_SERVICE_TYPE_LEN 32
#define TT_MDNS_PROTO_LEN 16
#define TT_MDNS_IP_LEN 64
#define TT_MDNS_TXT_KEY_LEN 32
#define TT_MDNS_TXT_VALUE_LEN 64
/** One TXT key-value pair */
typedef struct {
char key[TT_MDNS_TXT_KEY_LEN];
char value[TT_MDNS_TXT_VALUE_LEN];
} TtMdnsTxtRecord;
/** One discovered service (copy-based, no pointers into mdns_result_t). */
typedef struct {
char instanceName[TT_MDNS_INSTANCE_LEN]; ///< e.g. "kidsOS-AB12"
char serviceType[TT_MDNS_SERVICE_TYPE_LEN];///< e.g. "_http"
char proto[TT_MDNS_PROTO_LEN]; ///< e.g. "_tcp"
char hostname[TT_MDNS_HOSTNAME_LEN]; ///< without .local
uint16_t port; ///< service port
char addresses[TT_MDNS_MAX_ADDRESSES][TT_MDNS_IP_LEN]; ///< resolved IPs
uint8_t addressCount;
char primaryAddress[TT_MDNS_IP_LEN]; ///< first IPv4 or first address
uint32_t ttl;
TtMdnsTxtRecord txtRecords[TT_MDNS_MAX_TXT_RECORDS];
uint8_t txtCount;
} TtMdnsService;
/** Result set returned by browse. */
typedef struct {
TtMdnsService services[TT_MDNS_MAX_RESULTS];
uint8_t count;
} TtMdnsBrowseResult;
/**
* @return true if mDNS is initialized and running.
*/
bool tt_mdns_is_available();
/**
* Browse for mDNS service instances.
*
* Blocks for up to timeoutMs.
*
* @param serviceType e.g. "_http", "_tactility" (with or without leading underscore both accepted, but conventional is with)
* @param proto e.g. "_tcp", "_udp"
* @param timeoutMs how long to wait (e.g. 3000ms). 0 = use default 3000ms.
* @param maxResults clamp to TT_MDNS_MAX_RESULTS. 0 = default 20.
* @param outResult filled with 0..maxResults services. Caller provides storage.
* @return true on successful query (even 0 results is success). false if mDNS not running.
*/
bool tt_mdns_browse(const char* serviceType, const char* proto, uint32_t timeoutMs, size_t maxResults, TtMdnsBrowseResult* outResult);
/**
* Resolve a hostname like "kidsOS-AB12" or "kidsOS-AB12.local" to an IPv4 address string.
*
* @param hostname hostname (".local" suffix optional)
* @param timeoutMs wait time, 0 = 2000ms default
* @param outIp buffer of at least TT_MDNS_IP_LEN, filled with IP string e.g. "192.168.1.42"
* @return true if resolved.
*/
bool tt_mdns_resolve_hostname(const char* hostname, uint32_t timeoutMs, char* outIp);
#ifdef __cplusplus
}
#endif
-5
View File
@@ -10,7 +10,6 @@
#include "tt_hal_display.h"
#include "tt_hal_touch.h"
#include "tt_hal_uart.h"
#include "tt_mdns.h"
#include <tt_lock.h>
#include "tt_lvgl.h"
#include "tt_lvgl_keyboard.h"
@@ -367,10 +366,6 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(tt_timezone_set_format_24_hour),
// tt::lvgl
ESP_ELFSYM_EXPORT(tt_lvgl_spinner_create),
// mDNS
ESP_ELFSYM_EXPORT(tt_mdns_is_available),
ESP_ELFSYM_EXPORT(tt_mdns_browse),
ESP_ELFSYM_EXPORT(tt_mdns_resolve_hostname),
// stdio.h
ESP_ELFSYM_EXPORT(rename),
-76
View File
@@ -1,76 +0,0 @@
#include "tt_mdns.h"
#include <Tactility/network/Mdns.h>
#include <cstring>
#include <algorithm>
extern "C" {
bool tt_mdns_is_available() {
return tt::network::mdns::isAvailable();
}
bool tt_mdns_browse(const char* serviceType, const char* proto, uint32_t timeoutMs, size_t maxResults, TtMdnsBrowseResult* outResult) {
if (outResult == nullptr) return false;
if (serviceType == nullptr || proto == nullptr) return false;
memset(outResult, 0, sizeof(TtMdnsBrowseResult));
uint32_t effectiveTimeout = timeoutMs == 0 ? 3000 : timeoutMs;
size_t effectiveMax = maxResults == 0 ? 20 : maxResults;
effectiveMax = std::min<size_t>(effectiveMax, TT_MDNS_MAX_RESULTS);
std::vector<tt::network::mdns::Service> services;
if (!tt::network::mdns::browse(serviceType, proto, effectiveTimeout, effectiveMax, services)) {
return false;
}
size_t toCopy = std::min(services.size(), static_cast<size_t>(TT_MDNS_MAX_RESULTS));
for (size_t i = 0; i < toCopy; i++) {
const auto& src = services[i];
auto& dst = outResult->services[i];
strncpy(dst.instanceName, src.instanceName.c_str(), TT_MDNS_INSTANCE_LEN - 1);
strncpy(dst.serviceType, src.serviceType.c_str(), TT_MDNS_SERVICE_TYPE_LEN - 1);
strncpy(dst.proto, src.proto.c_str(), TT_MDNS_PROTO_LEN - 1);
strncpy(dst.hostname, src.hostname.c_str(), TT_MDNS_HOSTNAME_LEN - 1);
dst.port = src.port;
dst.ttl = src.ttl;
strncpy(dst.primaryAddress, src.primaryAddress.c_str(), TT_MDNS_IP_LEN - 1);
size_t addrCount = std::min(src.addresses.size(), static_cast<size_t>(TT_MDNS_MAX_ADDRESSES));
dst.addressCount = static_cast<uint8_t>(addrCount);
for (size_t a = 0; a < addrCount; a++) {
strncpy(dst.addresses[a], src.addresses[a].c_str(), TT_MDNS_IP_LEN - 1);
}
size_t txtCount = std::min(src.txtRecords.size(), static_cast<size_t>(TT_MDNS_MAX_TXT_RECORDS));
dst.txtCount = static_cast<uint8_t>(txtCount);
size_t idx = 0;
for (const auto& kv : src.txtRecords) {
if (idx >= txtCount) break;
strncpy(dst.txtRecords[idx].key, kv.first.c_str(), TT_MDNS_TXT_KEY_LEN - 1);
strncpy(dst.txtRecords[idx].value, kv.second.c_str(), TT_MDNS_TXT_VALUE_LEN - 1);
idx++;
}
}
outResult->count = static_cast<uint8_t>(toCopy);
return true;
}
bool tt_mdns_resolve_hostname(const char* hostname, uint32_t timeoutMs, char* outIp) {
if (hostname == nullptr || outIp == nullptr) return false;
memset(outIp, 0, TT_MDNS_IP_LEN);
uint32_t effectiveTimeout = timeoutMs == 0 ? 2000 : timeoutMs;
std::string ip;
if (!tt::network::mdns::resolveHostname(hostname, effectiveTimeout, ip)) {
return false;
}
strncpy(outIp, ip.c_str(), TT_MDNS_IP_LEN - 1);
return true;
}
} // extern "C"