mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12: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
|
||||
unsigned long strDateToUnix(String date) {
|
||||
int day = selectToMarker(date, ".").toInt();
|
||||
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;
|
||||
int day, month, year;
|
||||
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) {
|
||||
daysInMonth[1] = 29;
|
||||
} else {
|
||||
daysInMonth[1] = 28;
|
||||
}
|
||||
} else {
|
||||
daysInMonth[1] = 28;
|
||||
}
|
||||
int numberOfDaysInPastMonths = 0;
|
||||
for (int i = 0; i <= 11; i++) {
|
||||
if (i <= month - 2) {
|
||||
numberOfDaysInPastMonths = numberOfDaysInPastMonths + daysInMonth[i];
|
||||
}
|
||||
|
||||
day = date.substring(0, date.indexOf(".")).toInt();
|
||||
date = date.substring(date.indexOf(".") + 1);
|
||||
month = date.substring(0, date.indexOf(".")).toInt();
|
||||
date = date.substring(date.indexOf(".") + 1);
|
||||
year = date.toInt();
|
||||
|
||||
unsigned long unixTime = (year - 1970) * 365 * 86400;
|
||||
int numberOfLeepYears = (year - 1968) / 4 - (year - 1900) / 100 + (year - 1600) / 400;
|
||||
unixTime += numberOfLeepYears * 86400;
|
||||
|
||||
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
|
||||
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) {
|
||||
|
||||
@@ -17,6 +17,7 @@ class AnalogAdc : public IoTItem {
|
||||
unsigned int _pin;
|
||||
unsigned int _avgSteps, _avgCount;
|
||||
unsigned long _avgSumm;
|
||||
float adCresult;
|
||||
|
||||
public:
|
||||
//=======================================================================================================
|
||||
@@ -45,6 +46,7 @@ class AnalogAdc : public IoTItem {
|
||||
// и выполнить за несколько тактов
|
||||
void doByInterval() {
|
||||
if (_avgSteps <= 1) value.valD = IoTgpio.analogRead(_pin);
|
||||
value.valD = adCresult;///
|
||||
regEvent(value.valD, "AnalogAdc"); //обязательный вызов хотяб один
|
||||
}
|
||||
|
||||
@@ -56,7 +58,8 @@ class AnalogAdc : public IoTItem {
|
||||
void loop() {
|
||||
if (_avgSteps > 1) {
|
||||
if (_avgCount > _avgSteps) {
|
||||
value.valD = _avgSumm / _avgSteps;
|
||||
// value.valD = _avgSumm / (_avgSteps + 1);
|
||||
adCresult = _avgSumm / (_avgSteps + 1);
|
||||
_avgSumm = 0;
|
||||
_avgCount = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user