From 480314e8d4193c235b1ac95423122c52cc32e7b5 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 1 Aug 2018 07:48:32 +0200 Subject: [PATCH] Dalsi polozky - napeti baterie, obecny status --- ETCPLPP.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ ETCPLPP.h | 6 ++++++ 2 files changed, 54 insertions(+) diff --git a/ETCPLPP.cpp b/ETCPLPP.cpp index 158c20d..4a3f43b 100644 --- a/ETCPLPP.cpp +++ b/ETCPLPP.cpp @@ -155,3 +155,51 @@ uint8_t ETCPLPP::addBarometricPressure(uint8_t channel, float hpa) return cursor; } + +uint8_t ETCLPP::addBatteryVoltage(uint8_t channel, float voltage) +{ + + if ((cursor + LPP_BATTERY_VOLTAGE_SIZE) > maxsize) + { + return 0; + } + int16_t val = voltage * 1000; + + buffer[cursor++] = channel; + buffer[cursor++] = LPP_BATTERY_VOLTAGE; + buffer[cursor++] = val >> 8; + buffer[cursor++] = val; + + return cursor; +} + +uint8_t ETCLPP::addBatteryStatus(uint8_t channel, uint8_t percent) +{ + + if ((cursor + LPP_BATTERY_STATUS_SIZE) > maxsize) + { + return 0; + } + + buffer[cursor++] = channel; + buffer[cursor++] = LPP_BATTERY_STATUS; + buffer[cursor++] = percent; + + return cursor; +} + +uint8_t ETCLPP::addStatus(uint8_t channel, uint16_t status) +{ + + if ((cursor + LPP_STATUS_SIZE) > maxsize) + { + return 0; + } + + buffer[cursor++] = channel; + buffer[cursor++] = LPP_STATUS; + buffer[cursor++] = status >> 8; + buffer[cursor++] = status; + + return cursor; +} diff --git a/ETCPLPP.h b/ETCPLPP.h index c6340f6..2bd5d15 100644 --- a/ETCPLPP.h +++ b/ETCPLPP.h @@ -20,6 +20,7 @@ #define LPP_LUMINOSITY 0x09 // input, 2 bytes, 1 lux unsigned #define LPP_BATTERY_VOLTAGE 0x0A // input, 2 bytes, 1mV unsigned #define LPP_BATTERY_STATUS 0x0B // input, 1 byte 1%, 255 == unknown +#define LPP_STATUS 0x0C // input, 2 bytes unsigned // Data ID + Data Type + Data Size #define LPP_DIGITAL_INPUT_SIZE 3 // 1 byte @@ -34,6 +35,7 @@ #define LPP_LUMINOSITY_SIZE 4 // 2 bytes, 1 lux unsigned #define LPP_BATTERY_VOLTAGE_SIZE 4 // 2 bytes, 1mV unsigned #define LPP_BATTERY_STATUS_SIZE 3 // 1 byte 1% +#define LPP_STATUS_SIZE 4 // 2 bytes unsigned class ETCPLPP { @@ -57,6 +59,10 @@ public: uint8_t addRelativeHumidity(uint8_t channel, float rh); uint8_t addBarometricPressure(uint8_t channel, float hpa); + uint8_t addBatteryVoltage(uint8_t channel, float voltage); + uint8_t addBatteryStatus(uint8_t channel, uint8_t percent); + + uint8_t addStatus(uint8_t channel, uint16_t status); private: uint8_t *buffer; uint8_t maxsize;