mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
fix даты в графиках, fix среднее AnalogAdc
This commit is contained in:
47
src/NTP.cpp
47
src/NTP.cpp
@@ -156,33 +156,30 @@ const String getTodayDateDotFormated() {
|
|||||||
|
|
||||||
// format 22.02.2022
|
// format 22.02.2022
|
||||||
unsigned long strDateToUnix(String date) {
|
unsigned long strDateToUnix(String date) {
|
||||||
int day = selectToMarker(date, ".").toInt();
|
int day, month, year;
|
||||||
date = deleteBeforeDelimiter(date, ".");
|
|
||||||
int month = selectToMarker(date, ".").toInt();
|
|
||||||
date = deleteBeforeDelimiter(date, ".");
|
|
||||||
int year = selectToMarker(date, ".").toInt();
|
|
||||||
int secsInOneDay = 86400;
|
|
||||||
int daysInOneYear = 365;
|
|
||||||
int daysInLeepYear = 366;
|
|
||||||
int numberOfLeepYears = 12;
|
|
||||||
int totalNormalYears = year - 1970 - numberOfLeepYears;
|
|
||||||
unsigned int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
unsigned int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
if (year % 4 == 0) {
|
|
||||||
if (year % 100 != 0 || year % 400 == 0) {
|
day = date.substring(0, date.indexOf(".")).toInt();
|
||||||
daysInMonth[1] = 29;
|
date = date.substring(date.indexOf(".") + 1);
|
||||||
} else {
|
month = date.substring(0, date.indexOf(".")).toInt();
|
||||||
daysInMonth[1] = 28;
|
date = date.substring(date.indexOf(".") + 1);
|
||||||
}
|
year = date.toInt();
|
||||||
} else {
|
|
||||||
daysInMonth[1] = 28;
|
unsigned long unixTime = (year - 1970) * 365 * 86400;
|
||||||
}
|
int numberOfLeepYears = (year - 1968) / 4 - (year - 1900) / 100 + (year - 1600) / 400;
|
||||||
int numberOfDaysInPastMonths = 0;
|
unixTime += numberOfLeepYears * 86400;
|
||||||
for (int i = 0; i <= 11; i++) {
|
|
||||||
if (i <= month - 2) {
|
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
|
||||||
numberOfDaysInPastMonths = numberOfDaysInPastMonths + daysInMonth[i];
|
daysInMonth[1] = 29;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (day * secsInOneDay) + (numberOfDaysInPastMonths * secsInOneDay) + (totalNormalYears * daysInOneYear * secsInOneDay) + (numberOfLeepYears * daysInLeepYear * secsInOneDay);
|
|
||||||
|
for (int i = 0; i < month - 1; i++) {
|
||||||
|
unixTime += daysInMonth[i] * 86400;
|
||||||
|
}
|
||||||
|
|
||||||
|
unixTime += (day - 1) * 86400;
|
||||||
|
|
||||||
|
return unixTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
const String getDateTimeDotFormatedFromUnix(unsigned long unixTime) {
|
const String getDateTimeDotFormatedFromUnix(unsigned long unixTime) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class AnalogAdc : public IoTItem {
|
|||||||
unsigned int _pin;
|
unsigned int _pin;
|
||||||
unsigned int _avgSteps, _avgCount;
|
unsigned int _avgSteps, _avgCount;
|
||||||
unsigned long _avgSumm;
|
unsigned long _avgSumm;
|
||||||
|
float adCresult;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//=======================================================================================================
|
//=======================================================================================================
|
||||||
@@ -45,6 +46,7 @@ class AnalogAdc : public IoTItem {
|
|||||||
// и выполнить за несколько тактов
|
// и выполнить за несколько тактов
|
||||||
void doByInterval() {
|
void doByInterval() {
|
||||||
if (_avgSteps <= 1) value.valD = IoTgpio.analogRead(_pin);
|
if (_avgSteps <= 1) value.valD = IoTgpio.analogRead(_pin);
|
||||||
|
value.valD = adCresult;///
|
||||||
regEvent(value.valD, "AnalogAdc"); //обязательный вызов хотяб один
|
regEvent(value.valD, "AnalogAdc"); //обязательный вызов хотяб один
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +58,8 @@ class AnalogAdc : public IoTItem {
|
|||||||
void loop() {
|
void loop() {
|
||||||
if (_avgSteps > 1) {
|
if (_avgSteps > 1) {
|
||||||
if (_avgCount > _avgSteps) {
|
if (_avgCount > _avgSteps) {
|
||||||
value.valD = _avgSumm / _avgSteps;
|
// value.valD = _avgSumm / (_avgSteps + 1);
|
||||||
|
adCresult = _avgSumm / (_avgSteps + 1);
|
||||||
_avgSumm = 0;
|
_avgSumm = 0;
|
||||||
_avgCount = 0;
|
_avgCount = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user