From cddef776f710b67f7665e92325fedf7a11e509d6 Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Mon, 8 Feb 2021 20:54:49 +0100 Subject: [PATCH] move MAX,MIN,ABS to bits.h --- examples/knx-linux/main.cpp | 36 ++++++++++++++-------------- src/knx/bits.h | 14 ++++++++++- src/knx/rf_physical_layer_cc1101.cpp | 4 ---- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/examples/knx-linux/main.cpp b/examples/knx-linux/main.cpp index b48c160..e3d7ed5 100644 --- a/examples/knx-linux/main.cpp +++ b/examples/knx-linux/main.cpp @@ -46,10 +46,10 @@ KnxFacade knx; long lastsend = 0; -#define CURR knx.getGroupObject(1) -#define MAX knx.getGroupObject(2) -#define MIN knx.getGroupObject(3) -#define RESET knx.getGroupObject(4) +#define GO_CURR knx.getGroupObject(1) +#define GO_MAX knx.getGroupObject(2) +#define GO_MIN knx.getGroupObject(3) +#define GO_RESET knx.getGroupObject(4) void measureTemp() { @@ -65,22 +65,22 @@ void measureTemp() // currentValue *= (670433.28 + 273); // currentValue -= 273; println(currentValue); - CURR.value(currentValue); + GO_CURR.value(currentValue); - double max = MAX.value(); + double max = GO_MAX.value(); if (currentValue > max) - MAX.value(currentValue); + GO_MAX.value(currentValue); - if (currentValue < (double)MIN.value()) - MIN.value(currentValue); + if (currentValue < (double)GO_MIN.value()) + GO_MIN.value(currentValue); } void resetCallback(GroupObject& go) { if (go.value()) { - MAX.valueNoSend(-273.0); - MIN.valueNoSend(670433.28); + GO_MAX.valueNoSend(-273.0); + GO_MIN.valueNoSend(670433.28); } } @@ -102,13 +102,13 @@ void setup() if (knx.configured()) { - CURR.dataPointType(Dpt(9, 1)); - MIN.dataPointType(Dpt(9, 1)); - MIN.value(670433.28); - MAX.dataPointType(Dpt(9, 1)); - MAX.valueNoSend(-273.0); - RESET.dataPointType(Dpt(1, 15)); - RESET.callback(resetCallback); + GO_CURR.dataPointType(Dpt(9, 1)); + GO_MIN.dataPointType(Dpt(9, 1)); + GO_MIN.value(670433.28); + GO_MAX.dataPointType(Dpt(9, 1)); + GO_MAX.valueNoSend(-273.0); + GO_RESET.dataPointType(Dpt(1, 15)); + GO_RESET.callback(resetCallback); printf("Timeout: %d\n", knx.paramWord(0)); printf("Zykl. senden: %d\n", knx.paramByte(2)); printf("Min/Max senden: %d\n", knx.paramByte(3)); diff --git a/src/knx/bits.h b/src/knx/bits.h index 1d29279..2a30385 100644 --- a/src/knx/bits.h +++ b/src/knx/bits.h @@ -13,6 +13,18 @@ #define ntohl(x) htonl(x) #endif +#ifndef MIN +#define MIN(a, b) ((a < b) ? (a) : (b)) +#endif + +#ifndef MAX +#define MAX(a, b) ((a > b) ? (a) : (b)) +#endif + +#ifndef ABS +#define ABS(x) ((x > 0) ? (x) : (-x)) +#endif + #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) #include #elif defined(ARDUINO_ARCH_ESP8266) @@ -106,4 +118,4 @@ enum ParameterFloatEncodings #undef max #undef min // end of temporary undef -#endif \ No newline at end of file +#endif diff --git a/src/knx/rf_physical_layer_cc1101.cpp b/src/knx/rf_physical_layer_cc1101.cpp index a2ee581..c3de950 100644 --- a/src/knx/rf_physical_layer_cc1101.cpp +++ b/src/knx/rf_physical_layer_cc1101.cpp @@ -12,10 +12,6 @@ #include #include -#define MIN(a, b) ((a < b) ? (a) : (b)) -#define MAX(a, b) ((a > b) ? (a) : (b)) -#define ABS(x) ((x > 0) ? (x) : (-x)) - // Table for encoding 4-bit data into a 8-bit Manchester encoding. const uint8_t RfPhysicalLayerCC1101::manchEncodeTab[16] = {0xAA, // 0x0 Manchester encoded 0xA9, // 0x1 Manchester encoded