add Muse support

This commit is contained in:
Philippe G
2022-01-19 13:40:03 -08:00
parent 750e455b0d
commit d1dd27b7cb
7 changed files with 51 additions and 47 deletions

View File

@@ -14,6 +14,11 @@ extern "C" {
if ((__p = strcasestr(S, P)) && (__p = strchr(__p, C))) V = atoi(__p+1); \
} while (0)
#define PARSE_PARAM_FLOAT(S,P,C,V) do { \
char *__p; \
if ((__p = strcasestr(S, P)) && (__p = strchr(__p, C))) V = atof(__p+1); \
} while (0)
#define PARSE_PARAM_STR(S,P,C,V,I) do { \
char *__p; \
if ((__p = strstr(S, P)) && (__p = strchr(__p, C))) { \

View File

@@ -1109,7 +1109,6 @@ cJSON * get_gpio_list(bool refresh) {
}
gpio_list= cJSON_CreateArray();
#ifndef CONFIG_BAT_LOCKED
char *bat_config = config_alloc_get_default(NVS_TYPE_STR, "bat_config", NULL, 0);
if (bat_config) {
int channel = -1;
@@ -1121,11 +1120,6 @@ cJSON * get_gpio_list(bool refresh) {
}
free(bat_config);
}
#else
if(adc1_pad_get_io_num(CONFIG_BAT_CHANNEL,&gpio_num )==ESP_OK){
cJSON_AddItemToArray(gpio_list,get_gpio_entry("bat","other",gpio_num,true));
}
#endif
gpio_list=get_GPIO_nvs_list(gpio_list);
gpio_list=get_SPDIF_GPIO(gpio_list,is_spdif_config_locked());
gpio_list=get_Rotary_GPIO(gpio_list);

View File

@@ -35,10 +35,9 @@ static struct {
int count;
int cells, attenuation;
TimerHandle_t timer;
} battery = {
.channel = CONFIG_BAT_CHANNEL,
} battery = {
.channel = -1,
.cells = 2,
.attenuation = ADC_ATTEN_DB_0,
};
void (*battery_handler_svc)(float value);
@@ -76,17 +75,18 @@ static void battery_callback(TimerHandle_t xTimer) {
*
*/
void battery_svc_init(void) {
#ifdef CONFIG_BAT_SCALE
battery.scale = atof(CONFIG_BAT_SCALE);
#endif
char *nvs_item = config_alloc_get_default(NVS_TYPE_STR, "bat_config", "n", 0);
if (nvs_item) {
#ifndef CONFIG_BAT_LOCKED
PARSE_PARAM(nvs_item, "channel", '=', battery.channel);
PARSE_PARAM(nvs_item, "scale", '=', battery.scale);
PARSE_PARAM(nvs_item, "atten", '=', battery.attenuation);
char *nvs_item = config_alloc_get_default(NVS_TYPE_STR, "bat_config", "", 0);
#ifdef CONFIG_BAT_LOCKED
char *p = nvs_item;
asprintf(&nvs_item, CONFIG_BAT_CONFIG ",%s", p);
free(p);
#endif
if (nvs_item) {
PARSE_PARAM(nvs_item, "channel", '=', battery.channel);
PARSE_PARAM_FLOAT(nvs_item, "scale", '=', battery.scale);
PARSE_PARAM(nvs_item, "atten", '=', battery.attenuation);
PARSE_PARAM(nvs_item, "cells", '=', battery.cells);
free(nvs_item);
}
@@ -99,7 +99,7 @@ void battery_svc_init(void) {
battery.timer = xTimerCreate("battery", BATTERY_TIMER / portTICK_RATE_MS, pdTRUE, NULL, battery_callback);
xTimerStart(battery.timer, portMAX_DELAY);
ESP_LOGI(TAG, "Battery measure channel: %u, scale %f, cells %u, avg %.2fV", battery.channel, battery.scale, battery.cells, battery.avg);
ESP_LOGI(TAG, "Battery measure channel: %u, scale %f, atten %d, cells %u, avg %.2fV", battery.channel, battery.scale, battery.attenuation, battery.cells, battery.avg);
} else {
ESP_LOGI(TAG, "No battery");
}

View File

@@ -7,7 +7,7 @@
#include <esp_system.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <driver/adc.h>
//#include <driver/adc.h>
#include "driver/rmt.h"
#include "monitor.h"
@@ -43,8 +43,6 @@ void ws2812_write_leds(struct led_state new_state);
static const char TAG[] = "muse";
static void (*battery_handler_chain)(float value);
static void battery(void *data);
static void battery_svc(float value);
void target_init(void) {
@@ -55,10 +53,12 @@ void target_init(void) {
static void battery_svc(float value) {
ESP_LOGI(TAG, "Called for battery service with %f", value);
// put here your code for LED according to value
if (battery_handler_chain) battery_handler_chain(value);
}
// Battery monitoring
/*
static void battery(void *data)
{
#define VGREEN 2300
@@ -91,6 +91,7 @@ static void battery(void *data)
}
}
*/
// This is the buffer which the hw peripheral will access while pulsing the output pin
rmt_item32_t led_data_buffer[LED_BUFFER_ITEMS];