From 79340cac2a7ba30b052a3d524ac70c787383f7a4 Mon Sep 17 00:00:00 2001 From: Hurumy Date: Wed, 23 Aug 2023 12:26:15 +0900 Subject: [PATCH] fixed the issue --- src/CatGFX.cpp | 28 +++++++++++++++++----------- src/CatGFX.h | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/CatGFX.cpp b/src/CatGFX.cpp index 4a5c660..d6ed458 100644 --- a/src/CatGFX.cpp +++ b/src/CatGFX.cpp @@ -6,11 +6,17 @@ CatPrinter::CatPrinter(uint16_t h): SERVICE_UUID("0000AE30-0000-1000-8000-00805F9B34FB"), CHAR_UUID_DATA("0000AE01-0000-1000-8000-00805F9B34FB") { - strcpy(this->printer_names[0], "GT01"); - strcpy(this->printer_names[1], "GB01"); - strcpy(this->printer_names[2], "GB02"); - strcpy(this->printer_names[3], "MX09"); - strcpy(this->printer_names[4], ""); + if (this->NAME_ARRAY_SIZE >= 5) + { + strcpy(this->printerNames[0], "GT01"); + strcpy(this->printerNames[1], "GB01"); + strcpy(this->printerNames[2], "GB02"); + strcpy(this->printerNames[3], "MX09"); + for (int i = 4; i < this->NAME_ARRAY_SIZE; i ++) + strcpy(this->printerNames[i], ""); + } + else if (this->NAME_ARRAY_SIZE >= 1) + strcpy(this->printerNames[0], ""); } void CatPrinter::begin(byte *buffer, uint16_t size) { @@ -123,8 +129,8 @@ void CatPrinter::printBuffer(void) { void CatPrinter::onResult(BLEAdvertisedDevice advertisedDevice) { uint8_t i = 0; - while (i < this->NAME_ARRAY_SIZE && strcmp(this->printer_names[i], "") != 0){ - if (strcmp(advertisedDevice.getName().c_str(), this->printer_names[i]) == 0) { + while (i < this->NAME_ARRAY_SIZE && strcmp(this->printerNames[i], "") != 0){ + if (strcmp(advertisedDevice.getName().c_str(), this->printerNames[i]) == 0) { blePrinterAddress = new BLEAddress(advertisedDevice.getAddress()); Serial.print("Found Printer: "); Serial.println(blePrinterAddress->toString().c_str()); @@ -206,7 +212,7 @@ void CatPrinter::fillScreen(uint16_t color) { void CatPrinter::resetNameArray(void) { for (uint8_t i = 0; i < this->NAME_ARRAY_SIZE; i ++) - strcpy(this->printer_names[i], ""); + strcpy(this->printerNames[i], ""); } bool CatPrinter::addNameArray(char *newname) @@ -217,21 +223,21 @@ bool CatPrinter::addNameArray(char *newname) return (false); while (i < this->NAME_ARRAY_SIZE) { - if (strcmp(this->printer_names[i], "") != 0) + if (strcmp(this->printerNames[i], "") != 0) i ++; else break ; } if (i >= this->NAME_ARRAY_SIZE - 1) return (false); - strcpy(this->printer_names[i], newname); + strcpy(this->printerNames[i], newname); return (true); } void CatPrinter::printNameArray(void) { for (uint8_t i = 0; i < NAME_ARRAY_SIZE; i ++) - Serial.println(this->printer_names[i]); + Serial.println(this->printerNames[i]); } diff --git a/src/CatGFX.h b/src/CatGFX.h index 4778c6d..d064a92 100644 --- a/src/CatGFX.h +++ b/src/CatGFX.h @@ -54,7 +54,7 @@ class CatPrinter: public Adafruit_GFX, public BLEAdvertisedDeviceCallbacks { //Indicates the end of the array with an empty string instead of NULL. const static uint8_t NAME_ARRAY_SIZE = 6; const static uint8_t NAME_STRING_SIZE = 8; - char printer_names[NAME_ARRAY_SIZE][NAME_STRING_SIZE]; + char printerNames[NAME_ARRAY_SIZE][NAME_STRING_SIZE]; const byte LATTICE_START[11] = {0xAA, 0x55, 0x17, 0x38, 0x44, 0x5F, 0x5F, 0x5F, 0x44, 0x38, 0x2C}; const byte LATTICE_END[11] = {0xAA, 0x55, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17};