first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
#include "common_functions.h"
float mm_to_inches(float value_mm)
{
return 0.0393701 * value_mm;
}
float hPa_to_inHg(float value_hPa)
{
return 0.02953 * value_hPa;
}
int JulianDate(int d, int m, int y) {
int mm, yy, k1, k2, k3, j;
yy = y - (int)((12 - m) / 10);
mm = m + 9;
if (mm >= 12) mm = mm - 12;
k1 = (int)(365.25 * (yy + 4712));
k2 = (int)(30.6001 * mm + 0.5);
k3 = (int)((int)((yy / 100) + 49) * 0.75) - 38;
// 'j' for dates in Julian calendar:
j = k1 + k2 + d + 59 + 1;
if (j > 2299160) j = j - k3; // 'j' is the Julian date at 12h UT (Universal Time) For Gregorian calendar:
return j;
}
float SumOfPrecip(float DataArray[], int readings) {
float sum = 0;
for (int i = 0; i < readings; i++) {
sum += DataArray[i];
}
return sum;
}
String TitleCase(String text){
if (text.length() > 0) {
String temp_text = text.substring(0,1);
temp_text.toUpperCase();
return temp_text + text.substring(1); // Title-case the string
}
else return text;
}
void copy(float* src, float* dst, int len) {
// memcpy(dst, src, sizeof(src[0])*len);
for (int i = 0; i < len; i++) {
dst[i] = src[i];
}
}
void convertJsonToArray(float v[], String json, String sub_level, String data_name)
{
if (debug) Serial.println("B - convertJsonToArray");
DynamicJsonDocument doc(32000);
DeserializationError error = deserializeJson(doc, json);
if (error) {
if (debug) Serial.print(F("deserializeJson() failed: "));
if (debug) Serial.println(error.c_str());
if (debug) Serial.println("E - convertJsonToArray");
return;
}
JsonObject root = doc.as<JsonObject>();
//JsonArray list = doc.as<JsonArray>();
JsonArray list = root[sub_level];
if (debug) Serial.print("v=");
// Loop through all the elements of the array
int i = 0;
int max = max_readings;
for (byte r = list.size() - max; r < list.size(); r++) {
v[i]= list[r][data_name].as<float>();
if (debug) Serial.print(v[i]);
if (debug) Serial.print(" ");
i ++;
}
if (debug) Serial.println("");
if (debug) Serial.println("E - convertJsonToArray");
}