MistyGro API
C++ API for MistyGro's ESP32 controller based on the Arduino framework
utility.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Myron Rodrigues
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _UTILITY_H_
18 #define _UTILITY_H_
19 
20 #include <Arduino.h>
21 
22 namespace constants
23 {
24 static const int sample_size = 10;
25 static const uint8_t adc_bus_num = 0;
26 static const uint8_t adc_bus_addr = 0x48;
27 static const float ldr_thresh_v = 3.5;
28 static const unsigned long mister_toggle_time = 10 * 60; // 10 mins
29 static const unsigned long temperature_check_time = 10 * 60; // 10 mins
30 static const unsigned long light_check_n_set_time = 5 * 60; // 5 mins
31 static const unsigned long check_token_refresh_time = 1 * 60; // 1 min
32 static const int light_start_hour = 6; // GMT
33 static const int light_start_min = 0; // GMT
34 static const unsigned long light_duration = 12 * 60 * 60; // 12 hours
35 static const unsigned long wifi_check_time = 1 * 60; // sec
36 } // namespace constants
37 
38 namespace pin
39 {
40 static const int temp_sensor_bus = 32; // pin
41 static const int adc_scl = 22;
42 static const int adc_sda = 21;
43 static const int misters = 12;
44 static const int light = 14;
45 static const int extra_relay = 27;
46 } // namespace pin
47 
55 inline float median(float * arr, int size)
56 {
57  if (size % 2 == 0) {
58  return (arr[int(size * 0.5)] + arr[int((size - 1) * 0.5)]) * 0.5;
59  }
60  return arr[int(size * 0.5)];
61 }
62 
63 #endif
Definition: utility.h:39
float median(float *arr, int size)
Calculate median of a float array.
Definition: utility.h:55