system config UI work in progress

This commit is contained in:
Sebastien
2020-04-29 19:38:00 -04:00
parent 396f4e58de
commit 293d08deec
29 changed files with 682 additions and 240 deletions

View File

@@ -1,6 +1,6 @@
idf_component_register(SRC_DIRS .
INCLUDE_DIRS .
REQUIRES json tools platform_config
REQUIRES json tools platform_config display
)

View File

@@ -14,8 +14,11 @@
#include "platform_config.h"
#include "accessors.h"
#include "globdefs.h"
#include "display.h"
static const char *TAG = "services";
static char *i2c_name="I2C";
static char *spi_name="SPI";
#define min(a,b) (((a) < (b)) ? (a) : (b))
@@ -34,6 +37,43 @@ esp_err_t config_i2c_set(const i2c_config_t * config, int port){
return ESP_OK;
}
void config_display_free(display_config_t ** disp ){
if(disp && *disp){
free((*disp)->drivername);
free((*disp)->type);
free(*disp);
*disp=NULL;
}
}
const display_config_t * config_display_get(){
static display_config_t dstruct;
char *config = config_alloc_get(NVS_TYPE_STR, "display_config");
if (!config) {
return NULL;
}
char * p=NULL;
if ((p = strcasestr(config, "driver")) != NULL){
dstruct.drivername = display_conf_get_driver_name(strchr(p, '=') + 1);
}
dstruct.drivername=dstruct.drivername?dstruct.drivername:"SSD1306";
if ((p = strcasestr(config, "width")) != NULL) dstruct.width = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(config, "height")) != NULL) dstruct.height = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(config, "reset")) != NULL) dstruct.RST_pin = atoi(strchr(p, '=') + 1);
dstruct.i2c_system_port=i2c_system_port;
if (strstr(config, "I2C") ) dstruct.type=i2c_name;
if ((p = strcasestr(config, "address")) != NULL) dstruct.address = atoi(strchr(p, '=') + 1);
if (strstr(config, "SPI") ) dstruct.type=spi_name;
if ((p = strcasestr(config, "cs")) != NULL) dstruct.CS_pin = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(config, "speed")) != NULL) dstruct.speed = atoi(strchr(p, '=') + 1);
dstruct.hflip= strcasestr(config, "HFlip") ? true : false;
dstruct.vflip= strcasestr(config, "VFlip") ? true : false;
return &dstruct;
}
/****************************************************************************************
*
*/

View File

@@ -11,7 +11,20 @@
#include "esp_system.h"
#include "driver/i2c.h"
#include "driver/spi_master.h"
typedef struct {
int width;
int height;
int RST_pin;
int i2c_system_port;
int address;
int CS_pin;
int speed;
char *drivername;
char *type;
bool hflip;
bool vflip;
} display_config_t;
const display_config_t * config_display_get();
esp_err_t config_i2c_set(const i2c_config_t * config, int port);
const i2c_config_t * config_i2c_get(int * i2c_port);
const spi_bus_config_t * config_spi_get(spi_host_device_t * spi_host);

View File

@@ -245,3 +245,20 @@ void messaging_post_message(messaging_types type,messaging_classes msg_class, co
return;
}
void log_send_messaging(messaging_types msgtype,const char *fmt, ...) {
va_list va;
va_start(va, fmt);
size_t ln = vsnprintf(NULL, 0, fmt, va)+1;
char * message_txt = malloc(ln);
if(message_txt){
vsprintf(message_txt, fmt, va);
va_end(va);
ESP_LOG_LEVEL_LOCAL(messaging_type_to_err_type(msgtype),tag, "%s",message_txt);
messaging_post_message(msgtype, MESSAGING_CLASS_SYSTEM, message_txt );
free(message_txt);
}
else{
ESP_LOGE(tag, "Memory allocation failed while sending message");
}
}

View File

@@ -29,10 +29,11 @@ esp_err_t messaging_post_to_queue(messaging_handle_t subscriber_handle, single_m
void messaging_post_message(messaging_types type,messaging_classes msg_class, const char * fmt, ...);
cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle);
single_message_t * messaging_retrieve_message(RingbufHandle_t buf_handle);
void log_send_messaging(messaging_types msgtype,const char *fmt, ...);
esp_err_t messaging_type_to_err_type(messaging_types type);
void messaging_service_init();
#define REALLOC_CAT(e,n) e=realloc(e,strlen(n)); e=strcat(e,n)
#define LOG_SEND(y, ...) \
{ \
ESP_LOG_LEVEL_LOCAL(messaging_type_to_err_type(y),TAG, ##__VA_ARGS__); \