From 2c3b383d4f15ca1ca64b2192dd1774f60701f7fd Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sun, 25 Apr 2021 05:43:14 +0200 Subject: [PATCH] Fix compiler warnings --- lib/lv_lib_qrcode/lv_qrcode.c | 32 ++++++++++++++------------------ lib/lv_lib_qrcode/qrcodegen.cpp | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/lib/lv_lib_qrcode/lv_qrcode.c b/lib/lv_lib_qrcode/lv_qrcode.c index 9ee582f9..f0a7b400 100644 --- a/lib/lv_lib_qrcode/lv_qrcode.c +++ b/lib/lv_lib_qrcode/lv_qrcode.c @@ -45,14 +45,14 @@ * @param light_color light color of the QR code * @return pointer to the created QR code object */ -lv_obj_t * lv_qrcode_create(lv_obj_t * parent, lv_coord_t size, lv_color_t dark_color, lv_color_t light_color) +lv_obj_t* lv_qrcode_create(lv_obj_t* parent, lv_coord_t size, lv_color_t dark_color, lv_color_t light_color) { uint32_t buf_size = LV_CANVAS_BUF_SIZE_INDEXED_1BIT(size, size); - uint8_t * buf = lv_mem_alloc(buf_size); + uint8_t* buf = lv_mem_alloc(buf_size); LV_ASSERT_MEM(buf); if(buf == NULL) return NULL; - lv_obj_t * canvas = lv_canvas_create(parent, NULL); + lv_obj_t* canvas = lv_canvas_create(parent, NULL); lv_canvas_set_buffer(canvas, buf, size, size, LV_IMG_CF_INDEXED_1BIT); lv_canvas_set_palette(canvas, 0, dark_color); @@ -90,7 +90,7 @@ lv_obj_t * lv_qrcode_create(lv_obj_t * parent, lv_coord_t size, lv_color_t dark_ * @param data_len length of data in bytes * @return LV_RES_OK: if no error; LV_RES_INV: on error */ -lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_len) +lv_res_t lv_qrcode_update(lv_obj_t* qrcode, const void* data, uint32_t data_len) { lv_color_t c; c.full = 1; @@ -124,7 +124,7 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le return LV_RES_OK; } -lv_res_t lv_qrcode_update2(lv_obj_t * qrcode, const void * data, uint32_t data_len) +lv_res_t lv_qrcode_update2(lv_obj_t* qrcode, const void* data, uint32_t data_len) { lv_color_t c; // c.full = 1; @@ -143,31 +143,27 @@ lv_res_t lv_qrcode_update2(lv_obj_t * qrcode, const void * data, uint32_t data_l 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"); + // int scale = 1; + // int scaled = 0; + // int qr_size = qrcodegen_getSize(qr_pixels); + int margin = 0; - lv_img_ext_t * ext = (lv_img_ext_t *)lv_obj_get_ext_attr(qrcode); + 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"); + (void)res; 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_img_buf_set_px_color((lv_img_dsc_t*)dec_dsc.src, x + margin, y + margin, c); } } - LV_LOG_ERROR("9 OK"); return LV_RES_OK; } @@ -176,9 +172,9 @@ lv_res_t lv_qrcode_update2(lv_obj_t * qrcode, const void * data, uint32_t data_l * Delete a QR code object * @param qrcode pointer to a QR code obejct */ -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); lv_obj_del(qrcode); diff --git a/lib/lv_lib_qrcode/qrcodegen.cpp b/lib/lv_lib_qrcode/qrcodegen.cpp index ef325db9..45a62e1a 100644 --- a/lib/lv_lib_qrcode/qrcodegen.cpp +++ b/lib/lv_lib_qrcode/qrcodegen.cpp @@ -55,7 +55,7 @@ // - They are completely thread-safe if the caller does not give the // same writable buffer to concurrent calls to these functions. -testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int * bitLen); +testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int* bitLen); testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]); testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl); @@ -135,7 +135,7 @@ static const int PENALTY_N4 = 10; /*---- High-level QR Code encoding functions ----*/ // Public function - see documentation comment in header file. -bool qrcodegen_encodeText(const char * text, uint8_t tempBuffer[], uint8_t qrcode[], enum qrcodegen_Ecc ecl, +bool qrcodegen_encodeText(const char* text, uint8_t tempBuffer[], uint8_t qrcode[], enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl) { @@ -187,7 +187,7 @@ bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcod // Appends the given number of low-order bits of the given value to the given byte-based // bit buffer, increasing the bit length. Requires 0 <= numBits <= 16 and val < 2^numBits. -testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int * bitLen) +testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int* bitLen) { assert(0 <= numBits && numBits <= 16 && (unsigned long)val >> numBits == 0); for(int i = numBits - 1; i >= 0; i--, (*bitLen)++) buffer[*bitLen >> 3] |= ((val >> i) & 1) << (7 - (*bitLen & 7)); @@ -235,7 +235,7 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz memset(qrcode, 0, qrcodegen_BUFFER_LEN_FOR_VERSION(version) * sizeof(qrcode[0])); int bitLen = 0; for(size_t i = 0; i < len; i++) { - const struct qrcodegen_Segment * seg = &segs[i]; + const struct qrcodegen_Segment* seg = &segs[i]; appendBitsToBuffer((int)seg->mode, 4, qrcode, &bitLen); appendBitsToBuffer(seg->numChars, numCharCountBits(seg->mode, version), qrcode, &bitLen); for(int j = 0; j < seg->bitLength; j++) @@ -305,10 +305,10 @@ testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ec // (not concatenate) the bytes into a single sequence uint8_t generator[qrcodegen_REED_SOLOMON_DEGREE_MAX]; calcReedSolomonGenerator(blockEccLen, generator); - const uint8_t * dat = data; + const uint8_t* dat = data; for(int i = 0; i < numBlocks; i++) { - int datLen = shortBlockDataLen + (i < numShortBlocks ? 0 : 1); - uint8_t * ecc = &data[dataLen]; // Temporary storage + int datLen = shortBlockDataLen + (i < numShortBlocks ? 0 : 1); + uint8_t* ecc = &data[dataLen]; // Temporary storage calcReedSolomonRemainder(dat, datLen, generator, blockEccLen, ecc); for(int j = 0, k = i; j < datLen; j++, k += numBlocks) { // Copy data if(j == shortBlockDataLen) k -= numShortBlocks; @@ -782,7 +782,7 @@ static bool getBit(int x, int i) /*---- Segment handling ----*/ // Public function - see documentation comment in header file. -bool qrcodegen_isAlphanumeric(const char * text) +bool qrcodegen_isAlphanumeric(const char* text) { char buffer[64]; snprintf_P(buffer, sizeof(buffer), ALPHANUMERIC_CHARSET); @@ -795,7 +795,7 @@ bool qrcodegen_isAlphanumeric(const char * text) } // Public function - see documentation comment in header file. -bool qrcodegen_isNumeric(const char * text) +bool qrcodegen_isNumeric(const char* text) { assert(text != NULL); for(; *text != '\0'; text++) { @@ -860,7 +860,7 @@ struct qrcodegen_Segment qrcodegen_makeBytes(const uint8_t data[], size_t len, u } // Public function - see documentation comment in header file. -struct qrcodegen_Segment qrcodegen_makeNumeric(const char * digits, uint8_t buf[]) +struct qrcodegen_Segment qrcodegen_makeNumeric(const char* digits, uint8_t buf[]) { assert(digits != NULL); struct qrcodegen_Segment result; @@ -893,7 +893,7 @@ struct qrcodegen_Segment qrcodegen_makeNumeric(const char * digits, uint8_t buf[ } // Public function - see documentation comment in header file. -struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char * text, uint8_t buf[]) +struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char* text, uint8_t buf[]) { char buffer[64]; snprintf_P(buffer, sizeof(buffer), ALPHANUMERIC_CHARSET); @@ -911,7 +911,7 @@ struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char * text, uint8_t b unsigned int accumData = 0; int accumCount = 0; for(; *text != '\0'; text++) { - const char * temp = strchr(buffer, *text); // ALPHANUMERIC_CHARSET + const char* temp = strchr(buffer, *text); // ALPHANUMERIC_CHARSET assert(temp != NULL); accumData = accumData * 45 + (unsigned int)(temp - buffer); // ALPHANUMERIC_CHARSET accumCount++; @@ -963,8 +963,8 @@ testable int getTotalBits(const struct qrcodegen_Segment segs[], size_t len, int assert(segs != NULL || len == 0); long result = 0; for(size_t i = 0; i < len; i++) { - int numChars = segs[i].numChars; - int bitLength = segs[i].bitLength; + int16_t numChars = segs[i].numChars; + int16_t bitLength = segs[i].bitLength; assert(0 <= numChars && numChars <= INT16_MAX); assert(0 <= bitLength && bitLength <= INT16_MAX); int ccbits = numCharCountBits(segs[i].mode, version);