mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Test QR with lv_img instead of lv_canvas
This commit is contained in:
parent
a8c96598d1
commit
889e8aa779
@ -59,6 +59,28 @@ lv_obj_t * lv_qrcode_create(lv_obj_t * parent, lv_coord_t size, lv_color_t dark_
|
|||||||
lv_canvas_set_palette(canvas, 1, light_color);
|
lv_canvas_set_palette(canvas, 1, light_color);
|
||||||
|
|
||||||
return canvas;
|
return canvas;
|
||||||
|
|
||||||
|
// lv_img_dsc_t * img_buf = lv_img_buf_alloc(20, 20, LV_IMG_CF_TRUE_COLOR);
|
||||||
|
// if(img_buf == NULL) {
|
||||||
|
// LV_LOG_ERROR("img_buf failed");
|
||||||
|
// return NULL;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// lv_obj_t * image = lv_img_create(parent, NULL); // empty image
|
||||||
|
// if(image == NULL) {
|
||||||
|
// lv_img_buf_free(img_buf);
|
||||||
|
// LV_LOG_ERROR("image failed");
|
||||||
|
// return NULL;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// lv_img_set_auto_size(image, true); // auto size according to img_buf
|
||||||
|
// lv_img_set_src(image, img_buf); // assign the image buffer
|
||||||
|
|
||||||
|
// lv_img_set_zoom(image, 5 * LV_IMG_ZOOM_NONE); // default zoom
|
||||||
|
// lv_img_set_antialias(image, false); // don't anti-alias
|
||||||
|
// lv_obj_set_style_local_image_recolor(image, LV_IMG_PART_MAIN, LV_STATE_DEFAULT, dark_color);
|
||||||
|
|
||||||
|
// return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,6 +124,54 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le
|
|||||||
return LV_RES_OK;
|
return LV_RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lv_res_t lv_qrcode_update2(lv_obj_t * qrcode, const void * data, uint32_t data_len)
|
||||||
|
{
|
||||||
|
lv_color_t c;
|
||||||
|
// c.full = 1;
|
||||||
|
|
||||||
|
if(data_len > qrcodegen_BUFFER_LEN_MAX) return LV_RES_INV;
|
||||||
|
|
||||||
|
/* create a working cache and results buffer */
|
||||||
|
uint8_t data_tmp[qrcodegen_BUFFER_LEN_MAX];
|
||||||
|
uint8_t qr_pixels[qrcodegen_BUFFER_LEN_MAX];
|
||||||
|
memcpy(data_tmp, data, data_len);
|
||||||
|
|
||||||
|
/* convert data into pixels */
|
||||||
|
bool ok = qrcodegen_encodeBinary(data_tmp, data_len, qr_pixels, qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN,
|
||||||
|
qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
|
||||||
|
|
||||||
|
if(!ok) return LV_RES_INV;
|
||||||
|
|
||||||
|
// lv_coord_t obj_w = lv_obj_get_width(qrcode);
|
||||||
|
int qr_size = qrcodegen_getSize(qr_pixels);
|
||||||
|
int scale = 1;
|
||||||
|
int scaled = 0;
|
||||||
|
int margin = 0;
|
||||||
|
LV_LOG_ERROR("5 OK");
|
||||||
|
|
||||||
|
lv_img_ext_t * ext = (lv_img_ext_t *)lv_obj_get_ext_attr(qrcode);
|
||||||
|
if(!ext || !ext->src) return LV_RES_INV;
|
||||||
|
LV_LOG_ERROR("6 OK");
|
||||||
|
|
||||||
|
lv_img_header_t header;
|
||||||
|
lv_img_decoder_get_info(ext->src, &header);
|
||||||
|
LV_LOG_ERROR("7 OK");
|
||||||
|
|
||||||
|
lv_img_decoder_dsc_t dec_dsc;
|
||||||
|
lv_res_t res = lv_img_decoder_open(&dec_dsc, ext->src, LV_COLOR_CYAN);
|
||||||
|
LV_LOG_ERROR("8 OK");
|
||||||
|
|
||||||
|
for(int y = 0; y < dec_dsc.header.h; y++) {
|
||||||
|
for(int x = 0; x < dec_dsc.header.w; x++) {
|
||||||
|
c = qrcodegen_getModule(qr_pixels, x, y) ? LV_COLOR_WHITE : LV_COLOR_BLACK;
|
||||||
|
lv_img_buf_set_px_color(dec_dsc.src, x + margin, y + margin, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LV_LOG_ERROR("9 OK");
|
||||||
|
|
||||||
|
return LV_RES_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a QR code object
|
* Delete a QR code object
|
||||||
* @param qrcode pointer to a QR code obejct
|
* @param qrcode pointer to a QR code obejct
|
||||||
@ -109,8 +179,8 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le
|
|||||||
void lv_qrcode_delete(lv_obj_t * qrcode)
|
void lv_qrcode_delete(lv_obj_t * qrcode)
|
||||||
{
|
{
|
||||||
lv_img_dsc_t * img = lv_canvas_get_img(qrcode);
|
lv_img_dsc_t * img = lv_canvas_get_img(qrcode);
|
||||||
|
|
||||||
lv_mem_free(img->data);
|
lv_mem_free(img->data);
|
||||||
|
lv_mem_free(img);
|
||||||
lv_obj_del(qrcode);
|
lv_obj_del(qrcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user