From dd2f2f8b020a0e6a0caab761861ff598e2c97261 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 10 Feb 2023 03:09:50 +0100 Subject: [PATCH] Apply all clang-tidy fixes --- AfRApay.MateCard/.clang-tidy | 5 +---- AfRApay.MateCard/include/oled.h | 6 +++--- AfRApay.MateCard/include/pitches.h | 4 ++++ AfRApay.MateCard/include/utils.h | 9 ++++----- AfRApay.MateCard/include/wifiFix.h | 4 ++++ AfRApay.MateCard/src/main.cpp | 2 +- AfRApay.MateCard/src/oled.cpp | 8 ++++---- AfRApay.MateCard/src/utils.cpp | 16 ++++++---------- AfRApay.MateCard/src/wifiFix.cpp | 2 +- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/AfRApay.MateCard/.clang-tidy b/AfRApay.MateCard/.clang-tidy index ae0153a..88a0983 100644 --- a/AfRApay.MateCard/.clang-tidy +++ b/AfRApay.MateCard/.clang-tidy @@ -59,7 +59,6 @@ cert-err60-cpp, cert-flp30-c, cert-msc50-cpp, cert-msc51-cpp, -cert-str34-c, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-narrowing-conversions, cppcoreguidelines-pro-type-member-init, @@ -122,7 +121,6 @@ performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, performance-unnecessary-value-param, portability-simd-intrinsics, -readability-avoid-const-params-in-decls, readability-const-return-type, readability-container-size-empty, readability-convert-member-functions-to-static, @@ -131,7 +129,6 @@ readability-deleted-default, readability-inconsistent-declaration-parameter-name, readability-make-member-function-const, readability-misleading-indentation, -readability-misplaced-array-index, readability-non-const-parameter, readability-redundant-control-flow, readability-redundant-declaration, @@ -144,4 +141,4 @@ readability-static-accessed-through-instance, readability-static-definition-in-anonymous-namespace, readability-string-compare, readability-uniqueptr-delete-release, -readability-use-anyofallof' \ No newline at end of file +readability-use-anyofallof' diff --git a/AfRApay.MateCard/include/oled.h b/AfRApay.MateCard/include/oled.h index 9733028..6176b16 100644 --- a/AfRApay.MateCard/include/oled.h +++ b/AfRApay.MateCard/include/oled.h @@ -5,7 +5,7 @@ #include "utils.h" void drawLogo(U8G2 u8g2, e_logo logo); -void drawStatusText(U8G2 u8g2, String status, String statusRightAligned = ""); +void drawStatusText(U8G2 u8g2, const String& status, const String& statusRightAligned = ""); -void updateOLED(U8G2 u8g2, e_state state, String statusText, String statusTextRightAligned = ""); -void updateOLED(U8G2 u8g2, e_state state); +void updateOLED(U8G2 u8g2, e_state state, const String& statusText, const String& statusTextRightAligned = ""); +void updateOLED(const U8G2& u8g2, e_state state); diff --git a/AfRApay.MateCard/include/pitches.h b/AfRApay.MateCard/include/pitches.h index 92ec66d..96fe31d 100644 --- a/AfRApay.MateCard/include/pitches.h +++ b/AfRApay.MateCard/include/pitches.h @@ -1,4 +1,6 @@ #pragma once +#pragma clang diagnostic push +#pragma ide diagnostic ignored "OCUnusedMacroInspection" #define NOTE_NONE 0 #define NOTE_B0 31 @@ -90,3 +92,5 @@ #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978 + +#pragma clang diagnostic pop diff --git a/AfRApay.MateCard/include/utils.h b/AfRApay.MateCard/include/utils.h index 0bae424..e6c121d 100644 --- a/AfRApay.MateCard/include/utils.h +++ b/AfRApay.MateCard/include/utils.h @@ -4,11 +4,10 @@ unsigned long cooldownSecondsRemaining(unsigned long timeout, unsigned long timer); String byteArrayAsHexString(byte *buffer, byte bufferSize); -String uint32AsHexString(uint32_t input); -String cardLink(WiFiClient* wifi, HTTPClient* http, String apiUrl, String cardId); -String cardBalance(WiFiClient* wifi, HTTPClient* http, String apiUrl, String cardId); -String cardTransaction(WiFiClient* wifi, HTTPClient* http, String apiUrl, String cardId, String amount); -String splitString(String data, char separator, int index); +String cardLink(WiFiClient* wifi, HTTPClient* http, const String& apiUrl, const String& cardId); +String cardBalance(WiFiClient* wifi, HTTPClient* http, const String& apiUrl, const String& cardId); +String cardTransaction(WiFiClient* wifi, HTTPClient* http, const String& apiUrl, const String& cardId, const String& amount); +String splitString(const String& data, char separator, int index); enum e_state { STATE_IDLE, diff --git a/AfRApay.MateCard/include/wifiFix.h b/AfRApay.MateCard/include/wifiFix.h index 1a9207f..fa2f503 100644 --- a/AfRApay.MateCard/include/wifiFix.h +++ b/AfRApay.MateCard/include/wifiFix.h @@ -1,6 +1,10 @@ #pragma once +#pragma clang diagnostic push +#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" class WiFiClientFixed : public WiFiClient { public: void flush() override; }; + +#pragma clang diagnostic pop diff --git a/AfRApay.MateCard/src/main.cpp b/AfRApay.MateCard/src/main.cpp index 6c4bd5c..b3cfbfb 100644 --- a/AfRApay.MateCard/src/main.cpp +++ b/AfRApay.MateCard/src/main.cpp @@ -109,7 +109,7 @@ void setup() { } void loop() { - if (WiFi.status() != WL_CONNECTED) { + if (WiFiClass::status() != WL_CONNECTED) { updateOLED(u8g2, state, "WiFi disconnected :("); state = STATE_IDLE; WiFi.reconnect(); diff --git a/AfRApay.MateCard/src/oled.cpp b/AfRApay.MateCard/src/oled.cpp index 72f4d36..969167a 100644 --- a/AfRApay.MateCard/src/oled.cpp +++ b/AfRApay.MateCard/src/oled.cpp @@ -74,7 +74,7 @@ void drawLogo(U8G2 u8g2, e_logo logo) { } } -void drawStatusText(U8G2 u8g2, String status, String statusRightAligned = "") { +void drawStatusText(U8G2 u8g2, const String& status, const String& statusRightAligned = "") { u8g2.setFont(u8g2_font_bpixel_te); u8g2.drawUTF8(0, 61, status.c_str()); @@ -84,14 +84,14 @@ void drawStatusText(U8G2 u8g2, String status, String statusRightAligned = "") { } } -void drawFullScreenText(U8G2 u8g2, String textTop, String textBottom) { +void drawFullScreenText(U8G2 u8g2, const String& textTop, const String& textBottom) { u8g2.setFont(u8g2_font_chargen_92_tr); u8g2.drawUTF8((127-u8g2.getUTF8Width(textTop.c_str()))/2, 13, textTop.c_str()); u8g2.setFont(u8g2_font_maniac_te); u8g2.drawUTF8((127-u8g2.getUTF8Width(textBottom.c_str()))/2, 45, textBottom.c_str()); } -void updateOLED(U8G2 u8g2, e_state state, String statusText, String statusTextRightAligned = "") { +void updateOLED(U8G2 u8g2, e_state state, const String& statusText, const String& statusTextRightAligned = "") { u8g2.clearBuffer(); switch (state) { @@ -125,7 +125,7 @@ void updateOLED(U8G2 u8g2, e_state state, String statusText, String statusTextRi u8g2.sendBuffer(); } -void updateOLED(U8G2 u8g2, e_state state) { +void updateOLED(const U8G2& u8g2, e_state state) { String time = DateTime.format(DateFormatter::TIME_ONLY); if (!digitalRead(PIN_INTERRUPT_CANCEL) || millis()%20000 < 10000) updateOLED(u8g2, state, time, AFRAPAY_REVISION); diff --git a/AfRApay.MateCard/src/utils.cpp b/AfRApay.MateCard/src/utils.cpp index 9a4ecc8..8ba29eb 100644 --- a/AfRApay.MateCard/src/utils.cpp +++ b/AfRApay.MateCard/src/utils.cpp @@ -12,10 +12,6 @@ String byteArrayAsHexString(byte *buffer, byte bufferSize) { return s; } -String uint32AsHexString(uint32_t input) { - return byteArrayAsHexString(reinterpret_cast(&input), sizeof input); -} - String CentsToEuros(long cents){ char euros[16]; sprintf(euros, "%s%ld,%02ld", cents < 0 ? "-" : "", abs(cents / 100), abs(cents % 100)); @@ -33,10 +29,10 @@ String getIdempotencyKey(){ return byteArrayAsHexString(buf, len); } -String splitString(String data, char separator, int index) { - int found = 0; +String splitString(const String& data, char separator, int index) { + unsigned int maxIndex = data.length() - 1; int strIndex[] = {0, -1}; - int maxIndex = data.length() - 1; + int found = 0; for (int i = 0; i <= maxIndex && found <= index; i++) { if (data.charAt(i) == separator || i == maxIndex) { @@ -49,7 +45,7 @@ String splitString(String data, char separator, int index) { } -String cardLink(WiFiClient *wifi, HTTPClient *http, String apiUrl, String cardId) { +String cardLink(WiFiClient *wifi, HTTPClient *http, const String& apiUrl, const String& cardId) { String finalRequestUrl = apiUrl + "/api/card/" + cardId + "/link"; http->begin(*wifi, finalRequestUrl.c_str()); http->addHeader("Content-Type", "application/json"); @@ -88,7 +84,7 @@ String cardLink(WiFiClient *wifi, HTTPClient *http, String apiUrl, String cardId return String("E:Internal Error ") + httpResponseCode; } -String cardBalance(WiFiClient *wifi, HTTPClient *http, String apiUrl, String cardId) { +String cardBalance(WiFiClient *wifi, HTTPClient *http, const String& apiUrl, const String& cardId) { String finalRequestUrl = apiUrl + "/api/card/" + cardId + "/balance"; http->begin(*wifi, finalRequestUrl.c_str()); http->addHeader("Content-Type", "application/json"); @@ -125,7 +121,7 @@ String cardBalance(WiFiClient *wifi, HTTPClient *http, String apiUrl, String car return String("E:Internal Error ") + httpResponseCode; } -String cardTransaction(WiFiClient *wifi, HTTPClient *http, String apiUrl, String cardId, String amount) { +String cardTransaction(WiFiClient *wifi, HTTPClient *http, const String& apiUrl, const String& cardId, const String& amount) { String idempotencyKey = getIdempotencyKey(); String finalRequestUrl = apiUrl + "/api/card/" + cardId + "/transaction/" + idempotencyKey + "?amount=" + amount; http->begin(*wifi, finalRequestUrl.c_str()); diff --git a/AfRApay.MateCard/src/wifiFix.cpp b/AfRApay.MateCard/src/wifiFix.cpp index f82d5a3..e4403f1 100644 --- a/AfRApay.MateCard/src/wifiFix.cpp +++ b/AfRApay.MateCard/src/wifiFix.cpp @@ -6,7 +6,7 @@ void WiFiClientFixed::flush() { int res; - size_t a = available(), toRead = 0; + size_t a = available(); if (!a) { return;//nothing to flush }