Skip to content

Commit 3117b1e

Browse files
authored
Merge pull request #633 from espressif2022/feat/add_user_data
feat(qrcode): Add user_data for qrcode (IEC-446)
2 parents 5ba8d62 + 2a7ca6a commit 3117b1e

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

qrcode/esp_qrcode_main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,15 @@ esp_err_t esp_qrcode_generate(esp_qrcode_config_t *cfg, const char *text)
103103
qrcodegen_VERSION_MIN, cfg->max_qrcode_version,
104104
qrcodegen_Mask_AUTO, true);
105105
if (ok && cfg->display_func) {
106-
cfg->display_func((esp_qrcode_handle_t)qrcode);
106+
// If user_data is provided, use callback version
107+
// Otherwise use simple version (backward compatible)
108+
if (cfg->user_data != NULL) {
109+
// Use callback version with user_data
110+
cfg->display_func_with_cb((esp_qrcode_handle_t)qrcode, cfg->user_data);
111+
} else {
112+
// Use simple version without user_data (backward compatible)
113+
cfg->display_func((esp_qrcode_handle_t)qrcode);
114+
}
107115
err = ESP_OK;
108116
}
109117

qrcode/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
version: "0.1.0~2"
1+
version: "0.2.0"
22
description: QR Code generator
33
url: https://github.com/espressif/idf-extra-components/tree/master/qrcode

qrcode/include/qrcode.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ typedef const uint8_t *esp_qrcode_handle_t;
2121
* @brief QR Code configuration options
2222
*/
2323
typedef struct {
24-
void (*display_func)(esp_qrcode_handle_t qrcode); /**< Function called for displaying the QR Code after encoding is complete */
24+
union {
25+
void (*display_func)(esp_qrcode_handle_t qrcode); /**< Function called for displaying the QR Code (without user_data, for backward compatibility) */
26+
void (*display_func_with_cb)(esp_qrcode_handle_t qrcode, void *user_data); /**< Function called for displaying the QR Code with user_data callback */
27+
}; /**< Display function union for QR Code display */
2528
int max_qrcode_version; /**< Max QR Code Version to be used. Range: 2 - 40 */
2629
int qrcode_ecc_level; /**< Error Correction Level for QR Code */
30+
void *user_data; /**< User data */
2731
} esp_qrcode_config_t;
2832

2933
/**
@@ -90,6 +94,7 @@ bool esp_qrcode_get_module(esp_qrcode_handle_t qrcode, int x, int y);
9094
.display_func = esp_qrcode_print_console, \
9195
.max_qrcode_version = 10, \
9296
.qrcode_ecc_level = ESP_QRCODE_ECC_LOW, \
97+
.user_data = NULL, \
9398
}
9499

95100
#ifdef __cplusplus

0 commit comments

Comments
 (0)