From fcc75352f95434ff995fe6fc67adc0965eaaec86 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Sun, 9 Jun 2024 01:36:55 +0200 Subject: [PATCH] Fix VA --- .clang-format | 8 +++++++- src/MycilaJSY.cpp | 28 ++++++++++++++-------------- src/MycilaJSY.h | 22 +++++++++++----------- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/.clang-format b/.clang-format index a0498d9..63f29c0 100644 --- a/.clang-format +++ b/.clang-format @@ -2,15 +2,21 @@ Language: Cpp BasedOnStyle: LLVM AccessModifierOffset: -2 +AlignConsecutiveMacros: true +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: Inline +BinPackArguments: false ColumnLimit: 0 ContinuationIndentWidth: 2 FixNamespaceComments: false IndentAccessModifiers: true IndentCaseLabels: true +IndentPPDirectives: BeforeHash IndentWidth: 2 NamespaceIndentation: All PointerAlignment: Left ReferenceAlignment: Left TabWidth: 2 -UseTab: Never \ No newline at end of file +UseTab: Never diff --git a/src/MycilaJSY.cpp b/src/MycilaJSY.cpp index b7cd318..b9a7931 100644 --- a/src/MycilaJSY.cpp +++ b/src/MycilaJSY.cpp @@ -5,35 +5,35 @@ #include "MycilaJSY.h" #ifdef MYCILA_LOGGER_SUPPORT -#include + #include extern Mycila::Logger logger; -#define LOGD(tag, format, ...) logger.debug(tag, format, ##__VA_ARGS__) -#define LOGI(tag, format, ...) logger.info(tag, format, ##__VA_ARGS__) -#define LOGW(tag, format, ...) logger.warn(tag, format, ##__VA_ARGS__) -#define LOGE(tag, format, ...) logger.error(tag, format, ##__VA_ARGS__) + #define LOGD(tag, format, ...) logger.debug(tag, format, ##__VA_ARGS__) + #define LOGI(tag, format, ...) logger.info(tag, format, ##__VA_ARGS__) + #define LOGW(tag, format, ...) logger.warn(tag, format, ##__VA_ARGS__) + #define LOGE(tag, format, ...) logger.error(tag, format, ##__VA_ARGS__) #else -#define LOGD(tag, format, ...) ESP_LOGD(tag, format, ##__VA_ARGS__) -#define LOGI(tag, format, ...) ESP_LOGI(tag, format, ##__VA_ARGS__) -#define LOGW(tag, format, ...) ESP_LOGW(tag, format, ##__VA_ARGS__) -#define LOGE(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__) + #define LOGD(tag, format, ...) ESP_LOGD(tag, format, ##__VA_ARGS__) + #define LOGI(tag, format, ...) ESP_LOGI(tag, format, ##__VA_ARGS__) + #define LOGW(tag, format, ...) ESP_LOGW(tag, format, ##__VA_ARGS__) + #define LOGE(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__) #endif #define TAG "JSY" -#define JSY_READ_RESPONSE_SIZE 61 +#define JSY_READ_RESPONSE_SIZE 61 #define JSY_RESET_RESPONSE_SIZE 8 #define JSY_BAUDS_RESPONSE_SIZE 8 static const uint8_t JSY_READ_MSG[] = {0x01, 0x03, 0x00, 0x48, 0x00, 0x0E, 0x44, 0x18}; #ifndef GPIO_IS_VALID_OUTPUT_GPIO -#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((gpio_num >= 0) && \ - (((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0)) + #define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((gpio_num >= 0) && \ + (((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0)) #endif #ifndef GPIO_IS_VALID_GPIO -#define GPIO_IS_VALID_GPIO(gpio_num) ((gpio_num >= 0) && \ - (((1ULL << (gpio_num)) & SOC_GPIO_VALID_GPIO_MASK) != 0)) + #define GPIO_IS_VALID_GPIO(gpio_num) ((gpio_num >= 0) && \ + (((1ULL << (gpio_num)) & SOC_GPIO_VALID_GPIO_MASK) != 0)) #endif void Mycila::JSY::begin(HardwareSerial& serial, const int8_t rxPin, const int8_t txPin, const bool async, uint8_t core, uint32_t stackSize, uint32_t pause) { diff --git a/src/MycilaJSY.h b/src/MycilaJSY.h index a0f2cf2..97ffb55 100644 --- a/src/MycilaJSY.h +++ b/src/MycilaJSY.h @@ -9,33 +9,33 @@ #include #ifdef MYCILA_JSON_SUPPORT -#include + #include #endif -#define MYCILA_JSY_VERSION "9.0.0" -#define MYCILA_JSY_VERSION_MAJOR 9 -#define MYCILA_JSY_VERSION_MINOR 0 +#define MYCILA_JSY_VERSION "9.0.0" +#define MYCILA_JSY_VERSION_MAJOR 9 +#define MYCILA_JSY_VERSION_MINOR 0 #define MYCILA_JSY_VERSION_REVISION 0 #ifndef MYCILA_JSY_ASYNC_CORE -#define MYCILA_JSY_ASYNC_CORE 0 + #define MYCILA_JSY_ASYNC_CORE 0 #endif #ifndef MYCILA_JSY_ASYNC_PRIORITY -#define MYCILA_JSY_ASYNC_PRIORITY 1 + #define MYCILA_JSY_ASYNC_PRIORITY 1 #endif #ifndef MYCILA_JSY_ASYNC_STACK_SIZE -#define MYCILA_JSY_ASYNC_STACK_SIZE 2048 + #define MYCILA_JSY_ASYNC_STACK_SIZE 2048 #endif // time in milliseconds to wait between each read in async mode #ifndef MYCILA_JSY_ASYNC_READ_PAUSE_MS -#define MYCILA_JSY_ASYNC_READ_PAUSE_MS 0 + #define MYCILA_JSY_ASYNC_READ_PAUSE_MS 0 #endif #ifndef MYCILA_JSY_READ_TIMEOUT_MS -#define MYCILA_JSY_READ_TIMEOUT_MS 200 + #define MYCILA_JSY_READ_TIMEOUT_MS 200 #endif namespace Mycila { @@ -115,8 +115,8 @@ namespace Mycila { float getVoltage1() const { return _voltage1; } float getVoltage2() const { return _voltage2; } // apparent power in VA - float getApparentPower1() const { return _power1 / _powerFactor1; } - float getApparentPower2() const { return _power2 / _powerFactor2; } + float getApparentPower1() const { return _powerFactor1 == 0 ? 0 : _power1 / _powerFactor1; } + float getApparentPower2() const { return _powerFactor2 == 0 ? 0 : _power2 / _powerFactor2; } // get the uptime in milliseconds of the last successful read uint32_t getTime() const { return _lastReadSuccess; }