refactor services, increase max sockets - release

This commit is contained in:
philippe44
2020-01-06 16:08:15 -08:00
parent d301a2d9df
commit 26ecdf60d9
35 changed files with 204 additions and 57 deletions

View File

@@ -0,0 +1,57 @@
/*
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
#include "esp_system.h"
#include "esp_log.h"
#include "driver/adc.h"
#include "battery.h"
#define BATTERY_TIMER (10*1000)
static const char TAG[] = "battery";
#ifdef CONFIG_SQUEEZEAMP
static struct {
float sum, avg;
int count;
TimerHandle_t timer;
} battery;
#endif
/****************************************************************************************
*
*/
static void battery_callback(TimerHandle_t xTimer) {
battery.sum += adc1_get_raw(ADC1_CHANNEL_7) / 4095. * (10+174)/10. * 1.1;
if (++battery.count == 30) {
battery.avg = battery.sum / battery.count;
battery.sum = battery.count = 0;
ESP_LOGI(TAG, "Voltage %.2fV", battery.avg);
}
}
/****************************************************************************************
*
*/
void battery_svc_init(void) {
#ifdef CONFIG_SQUEEZEAMP
ESP_LOGI(TAG, "Initializing battery");
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ADC1_CHANNEL_7, ADC_ATTEN_DB_0);
battery.timer = xTimerCreate("battery", BATTERY_TIMER / portTICK_RATE_MS, pdTRUE, NULL, battery_callback);
xTimerStart(battery.timer, portMAX_DELAY);
#endif
}