migrate from binary config to json config
This commit is contained in:
@@ -37,6 +37,7 @@
|
|||||||
#include "gui/keyboard.h"
|
#include "gui/keyboard.h"
|
||||||
#include "hardware/motor.h"
|
#include "hardware/motor.h"
|
||||||
#include "hardware/powermgm.h"
|
#include "hardware/powermgm.h"
|
||||||
|
#include "hardware/json_config_psram_allocator.h"
|
||||||
|
|
||||||
EventGroupHandle_t weather_widget_event_handle = NULL;
|
EventGroupHandle_t weather_widget_event_handle = NULL;
|
||||||
TaskHandle_t _weather_widget_sync_Task;
|
TaskHandle_t _weather_widget_sync_Task;
|
||||||
@@ -211,27 +212,67 @@ void weather_widget_sync_Task( void * pvParameters ) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void weather_save_config( void ) {
|
void weather_save_config( void ) {
|
||||||
|
if ( SPIFFS.exists( WEATHER_CONFIG_FILE ) ) {
|
||||||
|
SPIFFS.remove( WEATHER_CONFIG_FILE );
|
||||||
|
log_i("remove old binary weather config");
|
||||||
|
}
|
||||||
|
|
||||||
fs::File file = SPIFFS.open( WEATHER_CONFIG_FILE, FILE_WRITE );
|
fs::File file = SPIFFS.open( WEATHER_JSON_CONFIG_FILE, FILE_WRITE );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
log_e( "Can't save file: %s\r\n", WEATHER_CONFIG_FILE );
|
log_e("Can't open file: %s!", WEATHER_JSON_CONFIG_FILE );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.write( (uint8_t *)&weather_config, sizeof( weather_config ) );
|
SpiRamJsonDocument doc( 1000 );
|
||||||
file.close();
|
|
||||||
|
doc["apikey"] = weather_config.apikey;
|
||||||
|
doc["lat"] = weather_config.lat;
|
||||||
|
doc["lon"] = weather_config.lon;
|
||||||
|
doc["autosync"] = weather_config.autosync;
|
||||||
|
doc["showWind"] = weather_config.showWind;
|
||||||
|
|
||||||
|
if ( serializeJsonPretty( doc, file ) == 0) {
|
||||||
|
log_e("Failed to write config file");
|
||||||
}
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void weather_load_config( void ) {
|
void weather_load_config( void ) {
|
||||||
|
if ( SPIFFS.exists( WEATHER_JSON_CONFIG_FILE ) ) {
|
||||||
|
fs::File file = SPIFFS.open( WEATHER_JSON_CONFIG_FILE, FILE_READ );
|
||||||
|
if (!file) {
|
||||||
|
log_e("Can't open file: %s!", WEATHER_JSON_CONFIG_FILE );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int filesize = file.size();
|
||||||
|
SpiRamJsonDocument doc( filesize * 2 );
|
||||||
|
|
||||||
|
DeserializationError error = deserializeJson( doc, file );
|
||||||
|
if ( error ) {
|
||||||
|
log_e("update check deserializeJson() failed: %s", error.c_str() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strlcpy( weather_config.apikey, doc["apikey"], sizeof( weather_config.apikey ) );
|
||||||
|
strlcpy( weather_config.lat, doc["lat"], sizeof( weather_config.lat ) );
|
||||||
|
strlcpy( weather_config.lon, doc["lon"], sizeof( weather_config.lon ) );
|
||||||
|
weather_config.autosync = doc["autosync"].as<bool>();
|
||||||
|
weather_config.showWind = doc["showWind"].as<bool>();
|
||||||
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_i("no json config exists, read from binary");
|
||||||
fs::File file = SPIFFS.open( WEATHER_CONFIG_FILE, FILE_READ );
|
fs::File file = SPIFFS.open( WEATHER_CONFIG_FILE, FILE_READ );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
log_e( "Can't open file: %s\r\n", WEATHER_CONFIG_FILE );
|
log_e("Can't open file: %s!", WEATHER_CONFIG_FILE );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int filesize = file.size();
|
int filesize = file.size();
|
||||||
@@ -240,8 +281,12 @@ void weather_load_config( void ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.read( (uint8_t *)&weather_config, filesize );
|
file.read( (uint8_t *)&weather_config, filesize );
|
||||||
|
file.close();
|
||||||
|
weather_save_config();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <TTGO.h>
|
#include <TTGO.h>
|
||||||
|
|
||||||
#define WEATHER_CONFIG_FILE "/weather.cfg"
|
#define WEATHER_CONFIG_FILE "/weather.cfg"
|
||||||
|
#define WEATHER_JSON_CONFIG_FILE "/weather.json"
|
||||||
|
|
||||||
#define WEATHER_WIDGET_SYNC_REQUEST _BV(0)
|
#define WEATHER_WIDGET_SYNC_REQUEST _BV(0)
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ArduinoJson.h"
|
|
||||||
#include "HTTPClient.h"
|
#include "HTTPClient.h"
|
||||||
|
|
||||||
#include "weather.h"
|
#include "weather.h"
|
||||||
@@ -28,27 +27,7 @@
|
|||||||
#include "weather_forecast.h"
|
#include "weather_forecast.h"
|
||||||
|
|
||||||
#include "hardware/powermgm.h"
|
#include "hardware/powermgm.h"
|
||||||
|
#include "hardware/json_config_psram_allocator.h"
|
||||||
// arduinoJson allocator for external PSRAM
|
|
||||||
// see: https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/
|
|
||||||
struct WeatherSpiRamAllocator {
|
|
||||||
void* allocate( size_t size ) {
|
|
||||||
void *psram = ps_calloc( size, 1 );
|
|
||||||
if ( psram ) {
|
|
||||||
log_i("allocate %dbytes(%p) json psram", size, psram );
|
|
||||||
return( psram );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
log_e("allocate %dbytes(%p) json psram failed", size, psram );
|
|
||||||
while(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void deallocate( void* pointer ) {
|
|
||||||
log_i("deallocate (%p) json psram", pointer );
|
|
||||||
free( pointer );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
using WeatherSpiRamJsonDocument = BasicJsonDocument<WeatherSpiRamAllocator>;
|
|
||||||
|
|
||||||
/* Utility function to convert numbers to directions */
|
/* Utility function to convert numbers to directions */
|
||||||
static void weather_wind_to_string( weather_forcast_t* container, int speed, int directionDegree);
|
static void weather_wind_to_string( weather_forcast_t* container, int speed, int directionDegree);
|
||||||
@@ -71,7 +50,7 @@ int weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *we
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
WeatherSpiRamJsonDocument doc( today_client.getSize() * 2 );
|
SpiRamJsonDocument doc( today_client.getSize() * 2 );
|
||||||
|
|
||||||
DeserializationError error = deserializeJson( doc, today_client.getStream() );
|
DeserializationError error = deserializeJson( doc, today_client.getStream() );
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -116,7 +95,7 @@ int weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
WeatherSpiRamJsonDocument doc( forecast_client.getSize() * 2 );
|
SpiRamJsonDocument doc( forecast_client.getSize() * 2 );
|
||||||
|
|
||||||
DeserializationError error = deserializeJson( doc, forecast_client.getStream() );
|
DeserializationError error = deserializeJson( doc, forecast_client.getStream() );
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|||||||
@@ -32,6 +32,6 @@
|
|||||||
/*
|
/*
|
||||||
* firmeware version string
|
* firmeware version string
|
||||||
*/
|
*/
|
||||||
#define __FIRMWARE__ "2020081102"
|
#define __FIRMWARE__ "2020081103"
|
||||||
|
|
||||||
#endif // _CONFIG_H
|
#endif // _CONFIG_H
|
||||||
|
|||||||
@@ -20,31 +20,11 @@
|
|||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ArduinoJson.h"
|
|
||||||
#include "HTTPClient.h"
|
#include "HTTPClient.h"
|
||||||
|
|
||||||
#include "update_check_version.h"
|
#include "update_check_version.h"
|
||||||
|
|
||||||
// arduinoJson allocator for external PSRAM
|
#include "hardware/json_config_psram_allocator.h"
|
||||||
// see: https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/
|
|
||||||
struct UpdateSpiRamAllocator {
|
|
||||||
void* allocate( size_t size ) {
|
|
||||||
void *psram = ps_calloc( size, 1 );
|
|
||||||
if ( psram ) {
|
|
||||||
log_i("allocate %dbytes(%p) json psram", size, psram );
|
|
||||||
return( psram );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
log_e("allocate %dbytes(%p) json psram failed", size, psram );
|
|
||||||
while(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void deallocate( void* pointer ) {
|
|
||||||
log_i("deallocate (%p) json psram", pointer );
|
|
||||||
free( pointer );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
using SpiRamJsonDocument = BasicJsonDocument<UpdateSpiRamAllocator>;
|
|
||||||
|
|
||||||
uint64_t update_check_new_version( void ) {
|
uint64_t update_check_new_version( void ) {
|
||||||
char url[512]="";
|
char url[512]="";
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
#include "gui/statusbar.h"
|
#include "gui/statusbar.h"
|
||||||
#include "gui/keyboard.h"
|
#include "gui/keyboard.h"
|
||||||
|
|
||||||
|
#include "hardware/json_config_psram_allocator.h"
|
||||||
|
|
||||||
update_config_t update_config;
|
update_config_t update_config;
|
||||||
|
|
||||||
lv_obj_t *update_setup_tile = NULL;
|
lv_obj_t *update_setup_tile = NULL;
|
||||||
@@ -112,18 +114,52 @@ static void exit_update_check_setup_event_cb( lv_obj_t * obj, lv_event_t event )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update_save_config( void ) {
|
void update_save_config( void ) {
|
||||||
fs::File file = SPIFFS.open( UPDATE_CONFIG_FILE, FILE_WRITE );
|
if ( SPIFFS.exists( UPDATE_CONFIG_FILE ) ) {
|
||||||
|
SPIFFS.remove( UPDATE_CONFIG_FILE );
|
||||||
|
log_i("remove old binary update config");
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::File file = SPIFFS.open( UPDATE_JSON_CONFIG_FILE, FILE_WRITE );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
log_e("Can't save file: %s", UPDATE_CONFIG_FILE );
|
log_e("Can't open file: %s!", UPDATE_JSON_CONFIG_FILE );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.write( (uint8_t *)&update_config, sizeof( update_config ) );
|
SpiRamJsonDocument doc( 1000 );
|
||||||
file.close();
|
|
||||||
|
doc["autosync"] = update_config.autosync;
|
||||||
|
|
||||||
|
if ( serializeJsonPretty( doc, file ) == 0) {
|
||||||
|
log_e("Failed to write config file");
|
||||||
}
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_read_config( void ) {
|
void update_read_config( void ) {
|
||||||
|
if ( SPIFFS.exists( UPDATE_JSON_CONFIG_FILE ) ) {
|
||||||
|
fs::File file = SPIFFS.open( UPDATE_JSON_CONFIG_FILE, FILE_READ );
|
||||||
|
if (!file) {
|
||||||
|
log_e("Can't open file: %s!", UPDATE_JSON_CONFIG_FILE );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int filesize = file.size();
|
||||||
|
SpiRamJsonDocument doc( filesize * 2 );
|
||||||
|
|
||||||
|
DeserializationError error = deserializeJson( doc, file );
|
||||||
|
if ( error ) {
|
||||||
|
log_e("update check deserializeJson() failed: %s", error.c_str() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
update_config.autosync = doc["autosync"].as<bool>();
|
||||||
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_i("no json config exists, read from binary");
|
||||||
fs::File file = SPIFFS.open( UPDATE_CONFIG_FILE, FILE_READ );
|
fs::File file = SPIFFS.open( UPDATE_CONFIG_FILE, FILE_READ );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -136,10 +172,14 @@ void update_read_config( void ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.read( (uint8_t *)&update_config, filesize );
|
file.read( (uint8_t *)&update_config, filesize );
|
||||||
|
file.close();
|
||||||
|
update_save_config();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool update_setup_get_autosync( void ) {
|
bool update_setup_get_autosync( void ) {
|
||||||
return( update_config.autosync );
|
return( update_config.autosync );
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <TTGO.h>
|
#include <TTGO.h>
|
||||||
|
|
||||||
#define UPDATE_CONFIG_FILE "/update.cfg"
|
#define UPDATE_CONFIG_FILE "/update.cfg"
|
||||||
|
#define UPDATE_JSON_CONFIG_FILE "/update.json"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool autosync = true;
|
bool autosync = true;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ void screenshot_setup( void ) {
|
|||||||
log_e("error memory alloc");
|
log_e("error memory alloc");
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
SPIFFS.remove( SCREENSHOT_FILE_NAME );
|
||||||
}
|
}
|
||||||
|
|
||||||
void screenshot_take( void ) {
|
void screenshot_take( void ) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "bma.h"
|
#include "bma.h"
|
||||||
#include "powermgm.h"
|
#include "powermgm.h"
|
||||||
|
#include "json_config_psram_allocator.h"
|
||||||
|
|
||||||
#include "gui/statusbar.h"
|
#include "gui/statusbar.h"
|
||||||
|
|
||||||
@@ -145,21 +146,57 @@ void bma_loop( TTGOClass *ttgo ) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void bma_save_config( void ) {
|
void bma_save_config( void ) {
|
||||||
fs::File file = SPIFFS.open( BMA_COFIG_FILE, FILE_WRITE );
|
if ( SPIFFS.exists( BMA_COFIG_FILE ) ) {
|
||||||
|
SPIFFS.remove( BMA_COFIG_FILE );
|
||||||
|
log_i("remove old binary bma config");
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::File file = SPIFFS.open( BMA_JSON_COFIG_FILE, FILE_WRITE );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
log_e("Can't save file: %s", BMA_COFIG_FILE );
|
log_e("Can't open file: %s!", BMA_JSON_COFIG_FILE );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.write( (uint8_t *)bma_config, sizeof( bma_config ) );
|
SpiRamJsonDocument doc( 1000 );
|
||||||
file.close();
|
|
||||||
|
doc["stepcounter"] = bma_config[ BMA_STEPCOUNTER ].enable;
|
||||||
|
doc["doubleclick"] = bma_config[ BMA_DOUBLECLICK ].enable;
|
||||||
|
|
||||||
|
if ( serializeJsonPretty( doc, file ) == 0) {
|
||||||
|
log_e("Failed to write config file");
|
||||||
}
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void bma_read_config( void ) {
|
void bma_read_config( void ) {
|
||||||
|
if ( SPIFFS.exists( BMA_JSON_COFIG_FILE ) ) {
|
||||||
|
fs::File file = SPIFFS.open( BMA_JSON_COFIG_FILE, FILE_READ );
|
||||||
|
if (!file) {
|
||||||
|
log_e("Can't open file: %s!", BMA_JSON_COFIG_FILE );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int filesize = file.size();
|
||||||
|
SpiRamJsonDocument doc( filesize * 2 );
|
||||||
|
|
||||||
|
DeserializationError error = deserializeJson( doc, file );
|
||||||
|
if ( error ) {
|
||||||
|
log_e("update check deserializeJson() failed: %s", error.c_str() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bma_config[ BMA_STEPCOUNTER ].enable = doc["stepcounter"].as<bool>();
|
||||||
|
bma_config[ BMA_DOUBLECLICK ].enable = doc["doubleclick"].as<bool>();
|
||||||
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_i("no json config exists, read from binary");
|
||||||
fs::File file = SPIFFS.open( BMA_COFIG_FILE, FILE_READ );
|
fs::File file = SPIFFS.open( BMA_COFIG_FILE, FILE_READ );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -172,10 +209,14 @@ void bma_read_config( void ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.read( (uint8_t *)bma_config, filesize );
|
file.read( (uint8_t *)bma_config, filesize );
|
||||||
|
file.close();
|
||||||
|
bma_save_config();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
|
|
||||||
#define BMA_EVENT_INT _BV(0)
|
#define BMA_EVENT_INT _BV(0)
|
||||||
|
|
||||||
|
#define BMA_COFIG_FILE "/bma.cfg"
|
||||||
|
#define BMA_JSON_COFIG_FILE "/bma.json"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool enable=true;
|
bool enable=true;
|
||||||
} bma_config_t;
|
} bma_config_t;
|
||||||
@@ -34,8 +37,6 @@
|
|||||||
BMA_CONFIG_NUM
|
BMA_CONFIG_NUM
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BMA_COFIG_FILE "/bma.cfg"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief setup bma activity measurement
|
* @brief setup bma activity measurement
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
#include "powermgm.h"
|
#include "powermgm.h"
|
||||||
#include "motor.h"
|
#include "motor.h"
|
||||||
|
|
||||||
|
#include "json_config_psram_allocator.h"
|
||||||
|
|
||||||
display_config_t display_config;
|
display_config_t display_config;
|
||||||
|
|
||||||
static uint8_t dest_brightness = 0;
|
static uint8_t dest_brightness = 0;
|
||||||
@@ -106,21 +108,59 @@ void display_wakeup( void ) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void display_save_config( void ) {
|
void display_save_config( void ) {
|
||||||
fs::File file = SPIFFS.open( DISPLAY_CONFIG_FILE, FILE_WRITE );
|
if ( SPIFFS.exists( DISPLAY_CONFIG_FILE ) ) {
|
||||||
|
SPIFFS.remove( DISPLAY_CONFIG_FILE );
|
||||||
|
log_i("remove old binary display config");
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::File file = SPIFFS.open( DISPLAY_JSON_CONFIG_FILE, FILE_WRITE );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
log_e("Can't save file: %s", DISPLAY_CONFIG_FILE );
|
log_e("Can't open file: %s!", DISPLAY_JSON_CONFIG_FILE );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.write( (uint8_t *)&display_config, sizeof( display_config ) );
|
SpiRamJsonDocument doc( 1000 );
|
||||||
file.close();
|
|
||||||
|
doc["brightness"] = display_config.brightness;
|
||||||
|
doc["rotation"] = display_config.rotation;
|
||||||
|
doc["timeout"] = display_config.timeout;
|
||||||
|
|
||||||
|
if ( serializeJsonPretty( doc, file ) == 0) {
|
||||||
|
log_e("Failed to write config file");
|
||||||
}
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void display_read_config( void ) {
|
void display_read_config( void ) {
|
||||||
|
if ( SPIFFS.exists( DISPLAY_JSON_CONFIG_FILE ) ) {
|
||||||
|
fs::File file = SPIFFS.open( DISPLAY_JSON_CONFIG_FILE, FILE_READ );
|
||||||
|
if (!file) {
|
||||||
|
log_e("Can't open file: %s!", DISPLAY_JSON_CONFIG_FILE );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int filesize = file.size();
|
||||||
|
SpiRamJsonDocument doc( filesize * 2 );
|
||||||
|
|
||||||
|
DeserializationError error = deserializeJson( doc, file );
|
||||||
|
if ( error ) {
|
||||||
|
log_e("update check deserializeJson() failed: %s", error.c_str() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
display_config.brightness = doc["brightness"].as<uint32_t>();
|
||||||
|
display_config.rotation = doc["rotation"].as<uint32_t>();
|
||||||
|
display_config.timeout = doc["timeout"].as<uint32_t>();
|
||||||
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_i("no json config exists, read from binary");
|
||||||
fs::File file = SPIFFS.open( DISPLAY_CONFIG_FILE, FILE_READ );
|
fs::File file = SPIFFS.open( DISPLAY_CONFIG_FILE, FILE_READ );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -133,10 +173,14 @@ void display_read_config( void ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.read( (uint8_t *)&display_config, filesize );
|
file.read( (uint8_t *)&display_config, filesize );
|
||||||
|
file.close();
|
||||||
|
display_save_config();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t display_get_timeout( void ) {
|
uint32_t display_get_timeout( void ) {
|
||||||
return( display_config.timeout );
|
return( display_config.timeout );
|
||||||
|
|||||||
@@ -32,12 +32,13 @@
|
|||||||
#define DISPLAY_MAX_ROTATE 270
|
#define DISPLAY_MAX_ROTATE 270
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t brightness = DISPLAY_MIN_BRIGHTNESS;
|
uint32_t brightness = DISPLAY_MAX_BRIGHTNESS;
|
||||||
uint32_t timeout = DISPLAY_MIN_TIMEOUT;
|
uint32_t timeout = DISPLAY_MIN_TIMEOUT;
|
||||||
uint32_t rotation = 0;
|
uint32_t rotation = 0;
|
||||||
} display_config_t;
|
} display_config_t;
|
||||||
|
|
||||||
#define DISPLAY_CONFIG_FILE "/display.cfg"
|
#define DISPLAY_CONFIG_FILE "/display.cfg"
|
||||||
|
#define DISPLAY_JSON_CONFIG_FILE "/display.json"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief setup display
|
* @brief setup display
|
||||||
|
|||||||
23
src/hardware/json_config_psram_allocator.h
Normal file
23
src/hardware/json_config_psram_allocator.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include "config.h"
|
||||||
|
#include "ArduinoJson.h"
|
||||||
|
|
||||||
|
// arduinoJson allocator for external PSRAM
|
||||||
|
// see: https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/
|
||||||
|
struct SpiRamAllocator {
|
||||||
|
void* allocate( size_t size ) {
|
||||||
|
void *psram = ps_calloc( size, 1 );
|
||||||
|
if ( psram ) {
|
||||||
|
log_i("allocate %dbytes(%p) json psram", size, psram );
|
||||||
|
return( psram );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_e("allocate %dbytes(%p) json psram failed", size, psram );
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void deallocate( void* pointer ) {
|
||||||
|
log_i("deallocate (%p) json psram", pointer );
|
||||||
|
free( pointer );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
using SpiRamJsonDocument = BasicJsonDocument<SpiRamAllocator>;
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <TTGO.h>
|
#include <TTGO.h>
|
||||||
|
#include "json_config_psram_allocator.h"
|
||||||
|
|
||||||
#include "motor.h"
|
#include "motor.h"
|
||||||
#include "powermgm.h"
|
#include "powermgm.h"
|
||||||
@@ -55,6 +56,8 @@ void motor_setup( void ) {
|
|||||||
if ( motor_init == true )
|
if ( motor_init == true )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
motor_read_config();
|
||||||
|
|
||||||
pinMode(GPIO_NUM_4, OUTPUT);
|
pinMode(GPIO_NUM_4, OUTPUT);
|
||||||
timer = timerBegin(0, 80, true);
|
timer = timerBegin(0, 80, true);
|
||||||
timerAttachInterrupt(timer, &onTimer, true);
|
timerAttachInterrupt(timer, &onTimer, true);
|
||||||
@@ -92,21 +95,55 @@ void motor_set_vibe_config( bool enable ) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void motor_save_config( void ) {
|
void motor_save_config( void ) {
|
||||||
fs::File file = SPIFFS.open( MOTOR_CONFIG_FILE, FILE_WRITE );
|
if ( SPIFFS.exists( MOTOR_CONFIG_FILE ) ) {
|
||||||
|
SPIFFS.remove( MOTOR_CONFIG_FILE );
|
||||||
|
log_i("remove old binary motor config");
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::File file = SPIFFS.open( MOTOR_JSON_CONFIG_FILE, FILE_WRITE );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
log_e("Can't save file: %s", MOTOR_CONFIG_FILE );
|
log_e("Can't open file: %s!", MOTOR_JSON_CONFIG_FILE );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.write( (uint8_t *)&motor_config, sizeof( motor_config ) );
|
SpiRamJsonDocument doc( 1000 );
|
||||||
file.close();
|
|
||||||
|
doc["motor"] = motor_config.vibe;
|
||||||
|
|
||||||
|
if ( serializeJsonPretty( doc, file ) == 0) {
|
||||||
|
log_e("Failed to write config file");
|
||||||
}
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void motor_read_config( void ) {
|
void motor_read_config( void ) {
|
||||||
|
if ( SPIFFS.exists( MOTOR_JSON_CONFIG_FILE ) ) {
|
||||||
|
fs::File file = SPIFFS.open( MOTOR_JSON_CONFIG_FILE, FILE_READ );
|
||||||
|
if (!file) {
|
||||||
|
log_e("Can't open file: %s!", MOTOR_JSON_CONFIG_FILE );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int filesize = file.size();
|
||||||
|
SpiRamJsonDocument doc( filesize * 2 );
|
||||||
|
|
||||||
|
DeserializationError error = deserializeJson( doc, file );
|
||||||
|
if ( error ) {
|
||||||
|
log_e("update check deserializeJson() failed: %s", error.c_str() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
motor_config.vibe = doc["motor"].as<bool>();
|
||||||
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_i("no json config exists, read from binary");
|
||||||
fs::File file = SPIFFS.open( MOTOR_CONFIG_FILE, FILE_READ );
|
fs::File file = SPIFFS.open( MOTOR_CONFIG_FILE, FILE_READ );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -119,7 +156,11 @@ void motor_read_config( void ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.read( (uint8_t *)&motor_config, filesize );
|
file.read( (uint8_t *)&motor_config, filesize );
|
||||||
|
file.close();
|
||||||
|
motor_save_config();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "TTGO.h"
|
#include "TTGO.h"
|
||||||
|
|
||||||
#define MOTOR_CONFIG_FILE "/motor.cfg"
|
#define MOTOR_CONFIG_FILE "/motor.cfg"
|
||||||
|
#define MOTOR_JSON_CONFIG_FILE "/motor.json"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool vibe = true;
|
bool vibe = true;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <TTGO.h>
|
#include <TTGO.h>
|
||||||
#include <soc/rtc.h>
|
#include <soc/rtc.h>
|
||||||
|
#include "json_config_psram_allocator.h"
|
||||||
|
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "pmu.h"
|
#include "pmu.h"
|
||||||
@@ -112,21 +113,59 @@ void pmu_wakeup( void ) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void pmu_save_config( void ) {
|
void pmu_save_config( void ) {
|
||||||
fs::File file = SPIFFS.open( PMU_CONFIG_FILE, FILE_WRITE );
|
if ( SPIFFS.exists( PMU_CONFIG_FILE ) ) {
|
||||||
|
SPIFFS.remove( PMU_CONFIG_FILE );
|
||||||
|
log_i("remove old binary pmu config");
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::File file = SPIFFS.open( PMU_JSON_CONFIG_FILE, FILE_WRITE );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
log_e("Can't save file: %s", PMU_CONFIG_FILE );
|
log_e("Can't open file: %s!", PMU_JSON_CONFIG_FILE );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.write( (uint8_t *)&pmu_config, sizeof( pmu_config ) );
|
SpiRamJsonDocument doc( 1000 );
|
||||||
file.close();
|
|
||||||
|
doc["silence_wakeup"] = pmu_config.silence_wakeup;
|
||||||
|
doc["experimental_power_save"] = pmu_config.experimental_power_save;
|
||||||
|
doc["compute_percent"] = pmu_config.compute_percent;
|
||||||
|
|
||||||
|
if ( serializeJsonPretty( doc, file ) == 0) {
|
||||||
|
log_e("Failed to write config file");
|
||||||
}
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void pmu_read_config( void ) {
|
void pmu_read_config( void ) {
|
||||||
|
if ( SPIFFS.exists( PMU_JSON_CONFIG_FILE ) ) {
|
||||||
|
fs::File file = SPIFFS.open( PMU_JSON_CONFIG_FILE, FILE_READ );
|
||||||
|
if (!file) {
|
||||||
|
log_e("Can't open file: %s!", PMU_JSON_CONFIG_FILE );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int filesize = file.size();
|
||||||
|
SpiRamJsonDocument doc( filesize * 2 );
|
||||||
|
|
||||||
|
DeserializationError error = deserializeJson( doc, file );
|
||||||
|
if ( error ) {
|
||||||
|
log_e("update check deserializeJson() failed: %s", error.c_str() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pmu_config.silence_wakeup = doc["silence_wakeup"].as<bool>();
|
||||||
|
pmu_config.experimental_power_save = doc["experimental_power_save"].as<bool>();
|
||||||
|
pmu_config.compute_percent = doc["compute_percent"].as<bool>();
|
||||||
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_i("no json config exists, read from binary");
|
||||||
fs::File file = SPIFFS.open( PMU_CONFIG_FILE, FILE_READ );
|
fs::File file = SPIFFS.open( PMU_CONFIG_FILE, FILE_READ );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -139,10 +178,14 @@ void pmu_read_config( void ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.read( (uint8_t *)&pmu_config, filesize );
|
file.read( (uint8_t *)&pmu_config, filesize );
|
||||||
|
file.close();
|
||||||
|
pmu_save_config();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool pmu_get_silence_wakeup( void ) {
|
bool pmu_get_silence_wakeup( void ) {
|
||||||
return( pmu_config.silence_wakeup );
|
return( pmu_config.silence_wakeup );
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#define PMU_BATTERY_CAP 300
|
#define PMU_BATTERY_CAP 300
|
||||||
|
|
||||||
#define PMU_CONFIG_FILE "/pmu.cfg"
|
#define PMU_CONFIG_FILE "/pmu.cfg"
|
||||||
|
#define PMU_JSON_CONFIG_FILE "/pmu.json"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool compute_percent = false;
|
bool compute_percent = false;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "timesync.h"
|
#include "timesync.h"
|
||||||
#include "powermgm.h"
|
#include "powermgm.h"
|
||||||
|
#include "json_config_psram_allocator.h"
|
||||||
|
|
||||||
EventGroupHandle_t time_event_handle = NULL;
|
EventGroupHandle_t time_event_handle = NULL;
|
||||||
TaskHandle_t _timesync_Task;
|
TaskHandle_t _timesync_Task;
|
||||||
@@ -57,18 +58,56 @@ void timesync_setup( TTGOClass *ttgo ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void timesync_save_config( void ) {
|
void timesync_save_config( void ) {
|
||||||
fs::File file = SPIFFS.open( TIMESYNC_CONFIG_FILE, FILE_WRITE );
|
if ( SPIFFS.exists( TIMESYNC_CONFIG_FILE ) ) {
|
||||||
|
SPIFFS.remove( TIMESYNC_CONFIG_FILE );
|
||||||
|
log_i("remove old binary timesync config");
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::File file = SPIFFS.open( TIMESYNC_JSON_CONFIG_FILE, FILE_WRITE );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
log_e("Can't save file: %s", TIMESYNC_CONFIG_FILE );
|
log_e("Can't open file: %s!", TIMESYNC_JSON_CONFIG_FILE );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.write( (uint8_t *)×ync_config, sizeof( timesync_config ) );
|
SpiRamJsonDocument doc( 1000 );
|
||||||
file.close();
|
|
||||||
|
doc["daylightsave"] = timesync_config.daylightsave;
|
||||||
|
doc["timesync"] = timesync_config.timesync;
|
||||||
|
doc["timezone"] = timesync_config.timezone;
|
||||||
|
|
||||||
|
if ( serializeJsonPretty( doc, file ) == 0) {
|
||||||
|
log_e("Failed to write config file");
|
||||||
}
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void timesync_read_config( void ) {
|
void timesync_read_config( void ) {
|
||||||
|
if ( SPIFFS.exists( TIMESYNC_JSON_CONFIG_FILE ) ) {
|
||||||
|
fs::File file = SPIFFS.open( TIMESYNC_JSON_CONFIG_FILE, FILE_READ );
|
||||||
|
if (!file) {
|
||||||
|
log_e("Can't open file: %s!", TIMESYNC_JSON_CONFIG_FILE );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int filesize = file.size();
|
||||||
|
SpiRamJsonDocument doc( filesize * 2 );
|
||||||
|
|
||||||
|
DeserializationError error = deserializeJson( doc, file );
|
||||||
|
if ( error ) {
|
||||||
|
log_e("update check deserializeJson() failed: %s", error.c_str() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timesync_config.daylightsave = doc["daylightsave"].as<bool>();
|
||||||
|
timesync_config.timesync = doc["timesync"].as<bool>();
|
||||||
|
timesync_config.timezone = doc["timezone"].as<uint32_t>();
|
||||||
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_i("no json config exists, read from binary");
|
||||||
fs::File file = SPIFFS.open( TIMESYNC_CONFIG_FILE, FILE_READ );
|
fs::File file = SPIFFS.open( TIMESYNC_CONFIG_FILE, FILE_READ );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -81,10 +120,14 @@ void timesync_read_config( void ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.read( (uint8_t *)×ync_config, filesize );
|
file.read( (uint8_t *)×ync_config, filesize );
|
||||||
|
file.close();
|
||||||
|
timesync_save_config();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool timesync_get_timesync( void ) {
|
bool timesync_get_timesync( void ) {
|
||||||
return( timesync_config.timesync );
|
return( timesync_config.timesync );
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#define TIME_SYNC_REQUEST _BV(0)
|
#define TIME_SYNC_REQUEST _BV(0)
|
||||||
|
|
||||||
#define TIMESYNC_CONFIG_FILE "/timesync.cfg"
|
#define TIMESYNC_CONFIG_FILE "/timesync.cfg"
|
||||||
|
#define TIMESYNC_JSON_CONFIG_FILE "/timesync.json"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool timesync = true;
|
bool timesync = true;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "powermgm.h"
|
#include "powermgm.h"
|
||||||
#include "wifictl.h"
|
#include "wifictl.h"
|
||||||
|
#include "json_config_psram_allocator.h"
|
||||||
|
|
||||||
#include "gui/statusbar.h"
|
#include "gui/statusbar.h"
|
||||||
#include "webserver/webserver.h"
|
#include "webserver/webserver.h"
|
||||||
@@ -67,8 +68,7 @@ void wifictl_setup( void ) {
|
|||||||
wifictl_networklist[ entry ].password[ 0 ] = '\0';
|
wifictl_networklist[ entry ].password[ 0 ] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
// load network list from spiff
|
// load config from spiff
|
||||||
wifictl_load_network();
|
|
||||||
wifictl_load_config();
|
wifictl_load_config();
|
||||||
|
|
||||||
// register WiFi events
|
// register WiFi events
|
||||||
@@ -185,25 +185,76 @@ void wifictl_setup( void ) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void wifictl_save_config( void ) {
|
void wifictl_save_config( void ) {
|
||||||
fs::File file = SPIFFS.open( WIFICTL_CONFIG_FILE, FILE_WRITE );
|
if ( SPIFFS.exists( WIFICTL_CONFIG_FILE ) ) {
|
||||||
|
SPIFFS.remove( WIFICTL_CONFIG_FILE );
|
||||||
|
log_i("remove old binary wificfg config");
|
||||||
|
}
|
||||||
|
if ( SPIFFS.exists( WIFICTL_LIST_FILE ) ) {
|
||||||
|
SPIFFS.remove( WIFICTL_LIST_FILE );
|
||||||
|
log_i("remove old binary wifilist config");
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::File file = SPIFFS.open( WIFICTL_JSON_CONFIG_FILE, FILE_WRITE );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
log_e("Can't save file: %s", WIFICTL_CONFIG_FILE );
|
log_e("Can't open file: %s!", WIFICTL_JSON_CONFIG_FILE );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.write( (uint8_t *)&wifictl_config, sizeof( wifictl_config ) );
|
SpiRamJsonDocument doc( 10000 );
|
||||||
file.close();
|
|
||||||
|
doc["autoon"] = wifictl_config.autoon;
|
||||||
|
doc["webserver"] = wifictl_config.webserver;
|
||||||
|
for ( int i = 0 ; i < NETWORKLIST_ENTRYS ; i++ ) {
|
||||||
|
doc["networklist"][ i ]["ssid"] = wifictl_networklist[ i ].ssid;
|
||||||
|
doc["networklist"][ i ]["psk"] = wifictl_networklist[ i ].password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( serializeJsonPretty( doc, file ) == 0) {
|
||||||
|
log_e("Failed to write config file");
|
||||||
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void wifictl_load_config( void ) {
|
void wifictl_load_config( void ) {
|
||||||
|
if ( SPIFFS.exists( WIFICTL_JSON_CONFIG_FILE ) ) {
|
||||||
|
fs::File file = SPIFFS.open( WIFICTL_JSON_CONFIG_FILE, FILE_READ );
|
||||||
|
if (!file) {
|
||||||
|
log_e("Can't open file: %s!", WIFICTL_JSON_CONFIG_FILE );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int filesize = file.size();
|
||||||
|
SpiRamJsonDocument doc( filesize * 2 );
|
||||||
|
|
||||||
|
DeserializationError error = deserializeJson( doc, file );
|
||||||
|
if ( error ) {
|
||||||
|
log_e("update check deserializeJson() failed: %s", error.c_str() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wifictl_config.autoon = doc["autoon"].as<bool>();
|
||||||
|
wifictl_config.webserver = doc["webserver"].as<bool>();
|
||||||
|
for ( int i = 0 ; i < NETWORKLIST_ENTRYS ; i++ ) {
|
||||||
|
strlcpy( wifictl_networklist[ i ].ssid , doc["networklist"][ i ]["ssid"], sizeof( wifictl_networklist[ i ].ssid ) );
|
||||||
|
strlcpy( wifictl_networklist[ i ].password, doc["networklist"][ i ]["psk"], sizeof( wifictl_networklist[ i ].password ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
doc.clear();
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_i("no json config exists, read from binary");
|
||||||
|
|
||||||
|
wifictl_load_network();
|
||||||
|
|
||||||
fs::File file = SPIFFS.open( WIFICTL_CONFIG_FILE, FILE_READ );
|
fs::File file = SPIFFS.open( WIFICTL_CONFIG_FILE, FILE_READ );
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
log_e("Can't open file: %s", WIFICTL_CONFIG_FILE );
|
log_e("Can't open file: %s!", WIFICTL_CONFIG_FILE );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int filesize = file.size();
|
int filesize = file.size();
|
||||||
@@ -212,10 +263,14 @@ void wifictl_load_config( void ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.read( (uint8_t *)&wifictl_config, filesize );
|
file.read( (uint8_t *)&wifictl_config, filesize );
|
||||||
|
file.close();
|
||||||
|
wifictl_save_config();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool wifictl_get_autoon( void ) {
|
bool wifictl_get_autoon( void ) {
|
||||||
return( wifictl_config.autoon );
|
return( wifictl_config.autoon );
|
||||||
@@ -234,20 +289,6 @@ void wifictl_set_webserver( bool webserver ) {
|
|||||||
wifictl_config.webserver = webserver;
|
wifictl_config.webserver = webserver;
|
||||||
wifictl_save_config();
|
wifictl_save_config();
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void wifictl_save_network( void ) {
|
|
||||||
fs::File file = SPIFFS.open( WIFICTL_LIST_FILE, FILE_WRITE );
|
|
||||||
|
|
||||||
if ( !file ) {
|
|
||||||
log_e("Can't save file: %s", WIFICTL_LIST_FILE );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
file.write( (uint8_t *)wifictl_networklist, sizeof( wifictl_networklist ) );
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
@@ -296,7 +337,7 @@ bool wifictl_delete_network( const char *ssid ) {
|
|||||||
if( !strcmp( ssid, wifictl_networklist[ entry ].ssid ) ) {
|
if( !strcmp( ssid, wifictl_networklist[ entry ].ssid ) ) {
|
||||||
wifictl_networklist[ entry ].ssid[ 0 ] = '\0';
|
wifictl_networklist[ entry ].ssid[ 0 ] = '\0';
|
||||||
wifictl_networklist[ entry ].password[ 0 ] = '\0';
|
wifictl_networklist[ entry ].password[ 0 ] = '\0';
|
||||||
wifictl_save_network();
|
wifictl_save_config();
|
||||||
return( true );
|
return( true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,7 +355,7 @@ bool wifictl_insert_network( const char *ssid, const char *password ) {
|
|||||||
for( int entry = 0 ; entry < NETWORKLIST_ENTRYS; entry++ ) {
|
for( int entry = 0 ; entry < NETWORKLIST_ENTRYS; entry++ ) {
|
||||||
if( !strcmp( ssid, wifictl_networklist[ entry ].ssid ) ) {
|
if( !strcmp( ssid, wifictl_networklist[ entry ].ssid ) ) {
|
||||||
strncpy( wifictl_networklist[ entry ].password, password, sizeof( wifictl_networklist[ entry ].password ) );
|
strncpy( wifictl_networklist[ entry ].password, password, sizeof( wifictl_networklist[ entry ].password ) );
|
||||||
wifictl_save_network();
|
wifictl_save_config();
|
||||||
WiFi.scanNetworks();
|
WiFi.scanNetworks();
|
||||||
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
||||||
return( true );
|
return( true );
|
||||||
@@ -325,7 +366,7 @@ bool wifictl_insert_network( const char *ssid, const char *password ) {
|
|||||||
if( strlen( wifictl_networklist[ entry ].ssid ) == 0 ) {
|
if( strlen( wifictl_networklist[ entry ].ssid ) == 0 ) {
|
||||||
strncpy( wifictl_networklist[ entry ].ssid, ssid, sizeof( wifictl_networklist[ entry ].ssid ) );
|
strncpy( wifictl_networklist[ entry ].ssid, ssid, sizeof( wifictl_networklist[ entry ].ssid ) );
|
||||||
strncpy( wifictl_networklist[ entry ].password, password, sizeof( wifictl_networklist[ entry ].password ) );
|
strncpy( wifictl_networklist[ entry ].password, password, sizeof( wifictl_networklist[ entry ].password ) );
|
||||||
wifictl_save_network();
|
wifictl_save_config();
|
||||||
WiFi.scanNetworks();
|
WiFi.scanNetworks();
|
||||||
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
||||||
return( true );
|
return( true );
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#define NETWORKLIST_ENTRYS 20
|
#define NETWORKLIST_ENTRYS 20
|
||||||
#define WIFICTL_LIST_FILE "/wifilist.cfg"
|
#define WIFICTL_LIST_FILE "/wifilist.cfg"
|
||||||
#define WIFICTL_CONFIG_FILE "/wificfg.cfg"
|
#define WIFICTL_CONFIG_FILE "/wificfg.cfg"
|
||||||
|
#define WIFICTL_JSON_CONFIG_FILE "/wificfg.json"
|
||||||
|
|
||||||
#define ESP_WPS_MODE WPS_TYPE_PBC
|
#define ESP_WPS_MODE WPS_TYPE_PBC
|
||||||
#define ESP_MANUFACTURER "ESPRESSIF"
|
#define ESP_MANUFACTURER "ESPRESSIF"
|
||||||
|
|||||||
@@ -40,13 +40,15 @@ TTGOClass *ttgo = TTGOClass::getWatch();
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
motor_setup();
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.printf("starting t-watch V1, version: " __FIRMWARE__ "\r\n");
|
Serial.printf("starting t-watch V1, version: " __FIRMWARE__ "\r\n");
|
||||||
ttgo->begin();
|
ttgo->begin();
|
||||||
ttgo->lvgl_begin();
|
ttgo->lvgl_begin();
|
||||||
|
|
||||||
SPIFFS.begin();
|
SPIFFS.begin();
|
||||||
|
|
||||||
|
motor_setup();
|
||||||
|
|
||||||
display_setup( ttgo );
|
display_setup( ttgo );
|
||||||
|
|
||||||
screenshot_setup();
|
screenshot_setup();
|
||||||
|
|||||||
Binary file not shown.
@@ -1 +1 @@
|
|||||||
{"version":"2020081102","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}
|
{"version":"2020081103","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}
|
||||||
|
|||||||
Reference in New Issue
Block a user