Ran clang-format

This commit is contained in:
2023-10-28 17:28:13 +01:00
parent ebd2909d15
commit 5c6a89df87
6 changed files with 116 additions and 131 deletions

View File

@@ -5,8 +5,6 @@
*/
#include "dht22.h"
#include "sdkconfig.h"
#include "wifi.h"
#include "esp_log.h"
#include "esp_sntp.h"
#include "freertos/FreeRTOS.h"
@@ -14,11 +12,13 @@
#include "freertos/task.h"
#include "nvs_flash.h"
#include "portmacro.h"
#include "sdkconfig.h"
#include "wifi.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
static const char* TAG = "YASPAM";
static const char *TAG = "YASPAM";
static volatile bool run_dht = true;
static volatile bool run_pms5003 = true;
@@ -27,20 +27,18 @@ static TaskHandle_t dht22_handle = NULL;
static TaskHandle_t pms5003_handle = NULL;
typedef struct {
uint8_t myt_sec; // 0 -> 61
uint8_t myt_min; // 0 -> 69
uint8_t myt_hour; // 0 -> 23
uint8_t myt_day; // 1 -> 31
uint8_t myt_month; // 0 -> 11 !!
uint8_t myt_year; // years since 1900
uint8_t myt_sec; // 0 -> 61
uint8_t myt_min; // 0 -> 69
uint8_t myt_hour; // 0 -> 23
uint8_t myt_day; // 1 -> 31
uint8_t myt_month; // 0 -> 11 !!
uint8_t myt_year; // years since 1900
} my_time;
#ifdef CONFIG_PMS5003_ENABLED
#include "pms5003.h"
void
read_from_pms5003()
{
void read_from_pms5003() {
while (run_pms5003) {
// TODO: actually collect some data
ESP_LOGI(TAG, "Got PMS5003 data!");
@@ -79,18 +77,20 @@ void read_from_dht22() {
latest_datapoint.rh = dht22_relative_humidity();
if (has_ntp_time_obtained_once()) {
// I _think_ I only want to be doing that rolling average and saving if/when
// we've got an actual time to do that with. I think that'd avoid some weird
// bugs (time changing from 1970 -> current time within a 10 min period)
// I _think_ I only want to be doing that rolling average and saving
// if/when we've got an actual time to do that with. I think that'd
// avoid some weird bugs (time changing from 1970 -> current time within
// a 10 min period)
time_t epoch;
time(&epoch);
struct tm *timeinfo = localtime(&epoch);
// There must be a better way - I couldn't figure out how to do it nicely all at once
latest_datapoint.time.myt_sec = timeinfo->tm_sec;
latest_datapoint.time.myt_min = timeinfo->tm_min;
latest_datapoint.time.myt_hour = timeinfo->tm_hour;
latest_datapoint.time.myt_day = timeinfo->tm_mday;
// There must be a better way - I couldn't figure out how to do it
// nicely all at once
latest_datapoint.time.myt_sec = timeinfo->tm_sec;
latest_datapoint.time.myt_min = timeinfo->tm_min;
latest_datapoint.time.myt_hour = timeinfo->tm_hour;
latest_datapoint.time.myt_day = timeinfo->tm_mday;
latest_datapoint.time.myt_month = timeinfo->tm_mon;
latest_datapoint.time.myt_year = timeinfo->tm_year;
@@ -102,20 +102,23 @@ void read_from_dht22() {
(latest_datapoint.rh - ten_minute_rolling_average.rh) /
num_samples_last_ten_mins;
ten_minute_rolling_average.temp +=
(latest_datapoint.temp - ten_minute_rolling_average.temp) / num_samples_last_ten_mins;
(latest_datapoint.temp - ten_minute_rolling_average.temp) /
num_samples_last_ten_mins;
}
num_samples_last_ten_mins += 1;
// This should be: if (number of samples in 10 mins taken)
// This _will_ break if sampled too quickly, because we'll have more samples per 10 minutes
// than can be stored in a uint32 - I'll calculate what that is and perhaps raise a compile
// error if too high.
// This _will_ break if sampled too quickly, because we'll have more
// samples per 10 minutes than can be stored in a uint32 - I'll
// calculate what that is and perhaps raise a compile error if too high.
if (num_samples_last_ten_mins >=
(CONFIG_DHT22_PERIOD_POLL * 1000 * 60 * 10)) {
num_samples_last_ten_mins = 0;
// TODO: Write the data out somewhere - into RAM maybe
// TODO: maybe push the data somewhere - or put a flag up that data can be pushed
// ^ could do a cute Semaphore thingy here - I don't think I've actually used one before
// TODO: maybe push the data somewhere - or put a flag up that data
// can be pushed
// ^ could do a cute Semaphore thingy here - I don't think I've
// actually used one before
}
}
}
@@ -124,9 +127,7 @@ void read_from_dht22() {
}
#endif /* CONFIG DHT22_ENABLED */
void
app_main(void)
{
void app_main(void) {
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@@ -136,24 +137,22 @@ app_main(void)
ESP_ERROR_CHECK(ret);
#ifdef CONFIG_DHT22_ENABLED
xTaskCreate(read_from_dht22,
"DHT22",
xTaskCreate(read_from_dht22, "DHT22",
4 * 1024, // honestly I have _no_ idea
NULL,
5, // no idea either
5, // no idea either
&dht22_handle);
#endif /* CONFIG_DHT22_ENABLED */
#ifdef CONFIG_PMS5003_ENABLED
xTaskCreate(read_from_pms5003,
"PMS5003",
xTaskCreate(read_from_pms5003, "PMS5003",
4 * 1024, // honestly I have _no_ idea
NULL,
5, // no idea either
5, // no idea either
&pms5003_handle);
#endif /* CONFIG_PMS5003_ENABLED */
start_wifi();