From e3b76c8c5d76d1fb2cc9e773d8b73ac14c6355b9 Mon Sep 17 00:00:00 2001 From: atc1441 Date: Sun, 5 May 2024 22:41:40 +0200 Subject: [PATCH] More BLE Fixes --- ESP32_AP-Flasher/src/ble_filter.cpp | 132 +++++++++++++++++++--------- resources/tagtypes/B0.json | 8 +- resources/tagtypes/B1.json | 8 +- resources/tagtypes/BA.json | 2 +- 4 files changed, 101 insertions(+), 49 deletions(-) diff --git a/ESP32_AP-Flasher/src/ble_filter.cpp b/ESP32_AP-Flasher/src/ble_filter.cpp index c950eb89..e21519af 100644 --- a/ESP32_AP-Flasher/src/ble_filter.cpp +++ b/ESP32_AP-Flasher/src/ble_filter.cpp @@ -14,6 +14,8 @@ #include "util.h" #include "web.h" +uint8_t* Mirrorbuffer; + uint8_t gicToOEPLtype(uint8_t gicType) { switch (gicType) { case 0xA0: @@ -143,7 +145,7 @@ bool BLE_filter_add_device(BLEAdvertisedDevice advertisedDevice) { bool BLE_is_image_pending(uint8_t address[8]) { for (int16_t c = 0; c < tagDB.size(); c++) { tagRecord* taginfo = tagDB.at(c); - if (taginfo->pendingCount > 0 && taginfo->version == 0 && (taginfo->hwType & 0xB0)) { + if (taginfo->pendingCount > 0 && taginfo->version == 0 && ((taginfo->hwType & 0xB0) == 0xB0)) { memcpy(address, taginfo->mac, 8); return true; } @@ -151,6 +153,14 @@ bool BLE_is_image_pending(uint8_t address[8]) { return false; } +uint8_t swapBits(uint8_t num) { + uint8_t result = 0; + for (int i = 0; i < 8; ++i) { + result |= ((num >> i) & 0x01) << (7 - i); + } + return result; +} + uint32_t compress_image(uint8_t address[8], uint8_t* buffer, uint32_t max_len) { uint32_t t = millis(); PendingItem* queueItem = getQueueItem(address, 0); @@ -179,76 +189,77 @@ uint32_t compress_image(uint8_t address[8], uint8_t* buffer, uint32_t max_len) { uint8_t special_color = ((giciType >> 10) & 12); uint8_t singleDoubleMirror = giciType & 1; uint8_t canDoCompression = (giciType & 0x4000) ? 0 : 1; - Serial.printf("BLE Filter options:\r\n"); - Serial.printf("screenResolution %d\r\n", screenResolution); - Serial.printf("dispPtype %d\r\n", dispPtype); - Serial.printf("availColors %d\r\n", availColors); - Serial.printf("special_color %d\r\n", special_color); - Serial.printf("singleDoubleMirror %d\r\n", singleDoubleMirror); - Serial.printf("canDoCompression %d\r\n", canDoCompression); bool extra_color = false; + bool mirror_width = false; uint16_t width_display = 104; uint16_t height_display = 212; switch (screenResolution) { case 0: - width_display = 104; - height_display = 212; + width_display = 216; + height_display = 104; break; case 1: - width_display = 128; - height_display = 296; + width_display = 296; + height_display = 128; break; case 2: width_display = 300; height_display = 400; break; case 3: - width_display = 384; - height_display = 640; + width_display = 640; + height_display = 384; break; case 4: - width_display = 640; - height_display = 960; - break; - case 5: - width_display = 132; - height_display = 256; - break; - case 6: - width_display = 96; - height_display = 196; - break; - case 7: - width_display = 480; + width_display = 960; height_display = 640; break; + case 5: + width_display = 250; + height_display = 136; + break; + case 6: + width_display = 196; + height_display = 96; + break; + case 7: + width_display = 640; + height_display = 480; + break; case 8: - width_display = 128; - height_display = 256; + width_display = 250; + height_display = 128; break; case 9: - width_display = 480; - height_display = 800; + width_display = 800; + height_display = 480; break; case 10: - width_display = 480; - height_display = 280; + width_display = 280; + height_display = 480; break; } switch (dispPtype) { case 0: // TFT + mirror_width = true; break; case 1: // EPA + mirror_width = false; break; case 2: // EPA1 + mirror_width = false; break; case 3: // EPA2 + mirror_width = false; break; } + if (giciType & 0x100) // Some special case, needs to be tested if always correct + mirror_width = true; + switch (availColors) { case 0: // BW extra_color = false; @@ -278,6 +289,24 @@ uint32_t compress_image(uint8_t address[8], uint8_t* buffer, uint32_t max_len) { len_compressed = 4; uint32_t curr_input_posi = 0; uint32_t byte_per_line = (height_display / 8); + if (height_display % 8 != 0) + byte_per_line++; + Mirrorbuffer = (uint8_t*)malloc(byte_per_line + 1); + if (Mirrorbuffer == nullptr) { + Serial.println("BLE Could not create Mirrorbuffer!"); + return 0; + } + Serial.printf("BLE Filter options:\r\n"); + Serial.printf("screenResolution %d\r\n", screenResolution); + Serial.printf("dispPtype %d\r\n", dispPtype); + Serial.printf("availColors %d\r\n", availColors); + Serial.printf("special_color %d\r\n", special_color); + Serial.printf("singleDoubleMirror %d\r\n", singleDoubleMirror); + Serial.printf("canDoCompression %d\r\n", canDoCompression); + Serial.printf("byte_per_line %d\r\n", byte_per_line); + Serial.printf("width_display %d\r\n", width_display); + Serial.printf("height_display %d\r\n", height_display); + Serial.printf("mirror_width %d\r\n", mirror_width); for (int i = 0; i < width_display; i++) { if (canDoCompression) { buffer[len_compressed++] = 0x75; @@ -288,8 +317,17 @@ uint32_t compress_image(uint8_t address[8], uint8_t* buffer, uint32_t max_len) { buffer[len_compressed++] = 0x00; buffer[len_compressed++] = 0x00; } - for (int b = 0; b < byte_per_line; b++) { - buffer[len_compressed++] = ~queueItem->data[curr_input_posi++]; + if (mirror_width) { + for (int b = 0; b < byte_per_line; b++) { + Mirrorbuffer[b] = ~queueItem->data[curr_input_posi++]; + } + for (int b = byte_per_line - 1; b >= 0; b--) { + buffer[len_compressed++] = swapBits(Mirrorbuffer[b]); + } + } else { + for (int b = 0; b < byte_per_line; b++) { + buffer[len_compressed++] = ~queueItem->data[curr_input_posi++]; + } } } if (extra_color) { @@ -303,11 +341,24 @@ uint32_t compress_image(uint8_t address[8], uint8_t* buffer, uint32_t max_len) { buffer[len_compressed++] = 0x00; buffer[len_compressed++] = 0x00; } - for (int b = 0; b < byte_per_line; b++) { - if (queueItem->len <= curr_input_posi) - buffer[len_compressed++] = 0x00; - else - buffer[len_compressed++] = queueItem->data[curr_input_posi++]; + if (mirror_width) { + for (int b = 0; b < byte_per_line; b++) { + if (queueItem->len <= curr_input_posi) + Mirrorbuffer[b] = 0x00; // Do not anything outside of the buffer! + else + Mirrorbuffer[b] = queueItem->data[curr_input_posi++]; + } + for (int b = byte_per_line - 1; b >= 0; b--) { + buffer[len_compressed++] = swapBits(Mirrorbuffer[b]); + } + } else { + for (int b = 0; b < byte_per_line; b++) { + if (queueItem->len <= curr_input_posi) { + buffer[len_compressed++] = 0x00; // Do not anything outside of the buffer! + } else { + buffer[len_compressed++] = queueItem->data[curr_input_posi++]; + } + } } } } @@ -317,6 +368,7 @@ uint32_t compress_image(uint8_t address[8], uint8_t* buffer, uint32_t max_len) { buffer[2] = (len_compressed >> 16) & 0xff; buffer[3] = (len_compressed >> 24) & 0xff; } + free(Mirrorbuffer); return len_compressed; } diff --git a/resources/tagtypes/B0.json b/resources/tagtypes/B0.json index 48507dda..0ec59d23 100644 --- a/resources/tagtypes/B0.json +++ b/resources/tagtypes/B0.json @@ -1,9 +1,9 @@ { - "version": 3, - "name": "Gicisky BLE EPD BW 2.1\"", - "width": 256, + "version": 4, + "name": "Gicisky BLE EPD BW 2.13\"", + "width": 250, "height": 128, - "rotatebuffer": 1, + "rotatebuffer": 3, "bpp": 1, "colortable": { "white": [ 255, 255, 255 ], diff --git a/resources/tagtypes/B1.json b/resources/tagtypes/B1.json index c3490bda..d0a676fb 100644 --- a/resources/tagtypes/B1.json +++ b/resources/tagtypes/B1.json @@ -1,9 +1,9 @@ { - "version": 3, - "name": "Gicisky BLE EPD BWR 2.1\"", - "width": 256, + "version": 4, + "name": "Gicisky BLE EPD BWR 2.13\"", + "width": 250, "height": 128, - "rotatebuffer": 1, + "rotatebuffer": 3, "bpp": 2, "colortable": { "white": [ 255, 255, 255 ], diff --git a/resources/tagtypes/BA.json b/resources/tagtypes/BA.json index debc5cee..b00633b1 100644 --- a/resources/tagtypes/BA.json +++ b/resources/tagtypes/BA.json @@ -1,5 +1,5 @@ { - "version": 1, + "version": 3, "name": "Gicisky BLE TFT 2.13\"", "width": 250, "height": 132,