Skip to content

Commit

Permalink
UiFlow2 fix and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorcelli committed Oct 24, 2024
1 parent 34b1261 commit 543804b
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 89 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Sourcecode will be released in the future..
* UiFlow 1 doesn´t work with Launcher.. it uses an old MicroPython distro, that uses an old ESP-IDF distro with lots os secrets that I couldn´t figure out.

## Changelog
* 2.3.1:
* [x] Fox for https://github.com/bmorcelli/M5Stick-Launcher/issues/77
* [x] Fixed screen direction for T-Deck devices
* [x] Fixed Json handling and config.conf random fails
* 2.3.0:
* [x] Ported to Lilygo T-Embed CC1101
* [x] Ported to Lilygo T-Embed
Expand Down
8 changes: 4 additions & 4 deletions custom_8Mb.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Defaul, , , , ,
# Default, , , , ,
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x6000,
app0, app, test, 0x10000, 0x180000,
Expand All @@ -18,6 +18,6 @@ coredump, data, coredump,0x7F0000, 0x10000,
# Name, Type, SubType, Offset, Size, Flags
#nvs, data, nvs, 0x9000, 0x6000,
#app0, app, test, 0x10000, 0x180000,
#app1, app, ota_0, 0x190000, 0x450000,
#sys, data, fat, 0x5E0000, 0x100000,
#vfs, data, fat, 0x6E0000, 0x120000,
#app1, app, ota_0, 0x190000, 0x470000,
#sys, data, fat, 0x600000, 0x100000,
#vfs, data, fat, 0x700000, 0x100000,
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ extra_scripts = pre:support_files/nvs_script.py
board_build.partitions = custom_8Mb.csv
build_flags =
${common.build_flags}
;-DCORE_DEBUG_LEVEL=5
-DCORE_DEBUG_LEVEL=5
-DCARDPUTER=1
-DREDRAW_DELAY=200

Expand Down Expand Up @@ -866,7 +866,7 @@ build_flags =
;-DPART_04MB =0
;-DPART_08MB =0
-DPART_16MB=1
-DROTATION=1
-DROTATION=3
-DHAS_BTN=1
-DSEL_BTN=0
-DUP_BTN=3 ;2
Expand Down
8 changes: 2 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ void setup() {
#elif defined(T_DECK)
pinMode(PIN_POWER_ON, OUTPUT);
digitalWrite(PIN_POWER_ON, HIGH);
pinMode(9, OUTPUT); // Radio CS Pin to HIGH (Inhibit the SPI Communication for this module)
digitalWrite(9, HIGH);
pinMode(SEL_BTN, INPUT);

// Setup for Trackball
Expand All @@ -274,13 +276,7 @@ void setup() {
attachInterrupt(L_BTN, ISR_left, FALLING);
pinMode(R_BTN, INPUT_PULLUP);
attachInterrupt(R_BTN, ISR_right, FALLING);
//pinMode(BACKLIGHT, OUTPUT);
//digitalWrite(BACKLIGHT,HIGH);

// PWM backlight setup
// ledcSetup(TFT_BRIGHT_CHANNEL,TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits); //Channel 0, 10khz, 8bits
// ledcAttachPin(TFT_BL, TFT_BRIGHT_CHANNEL);
// ledcWrite(TFT_BRIGHT_CHANNEL,125);

#elif defined(HEADLESS)
#if SEL_BTN >= 0 // handle enter in launcher
Expand Down
8 changes: 4 additions & 4 deletions src/partitioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ const uint8_t uiflow2[192] PROGMEM = { // uiflow partition scheme, APP, sys(FAT)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xAA, 0x50, 0x00, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x61, 0x70, 0x70, 0x30,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xAA, 0x50, 0x00, 0x10, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x45, 0x00, 0x61, 0x70, 0x70, 0x31,
0xAA, 0x50, 0x00, 0x10, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x47, 0x00, 0x61, 0x70, 0x70, 0x31,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xAA, 0x50, 0x01, 0x81, 0x00, 0x00, 0x5E, 0x00, 0x00, 0x00, 0x10, 0x00, 0x73, 0x79, 0x73, 0x00,
0xAA, 0x50, 0x01, 0x81, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x10, 0x00, 0x73, 0x79, 0x73, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xAA, 0x50, 0x01, 0x81, 0x00, 0x00, 0x6E, 0x00, 0x00, 0x00, 0x12, 0x00, 0x76, 0x66, 0x73, 0x00,
0xAA, 0x50, 0x01, 0x81, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x10, 0x00, 0x76, 0x66, 0x73, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xEB, 0xEB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x48, 0xF8, 0x55, 0x10, 0x56, 0x7F, 0x21, 0xB9, 0x2C, 0x39, 0x4A, 0xA9, 0xF7, 0xC9, 0x22, 0x3B,
0xA9, 0x7C, 0xFA, 0x04, 0x64, 0x3F, 0x74, 0xF6, 0xBA, 0x15, 0x15, 0x9C, 0x32, 0xBD, 0x2F, 0x23,
};

#elif defined(PART_04MB)
Expand Down
174 changes: 101 additions & 73 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,87 +313,99 @@ void chargeMode() {
delay(200);
}


bool config_exists() {
if (!SDM.exists(CONFIG_FILE)) {
File conf = SDM.open(CONFIG_FILE, FILE_WRITE);
if (conf) {
#if ROTATION > 1
conf.print("[{\"rot\":3,\"dimmerSet\":10,\"onlyBins\":1,\"bright\":100,\"askSpiffs\":1,\"wui_usr\":\"admin\",\"wui_pwd\":\"launcher\",\"dwn_path\":\"/downloads/\",\"FGCOLOR\":2016,\"BGCOLOR\":0,\"ALCOLOR\":63488,\"even\":13029,\"odd\":12485,\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}]}]");
#else
conf.print("[{\"rot\":1,\"dimmerSet\":10,\"onlyBins\":1,\"bright\":100,\"askSpiffs\":1,\"wui_usr\":\"admin\",\"wui_pwd\":\"launcher\",\"dwn_path\":\"/downloads/\",\"FGCOLOR\":2016,\"BGCOLOR\":0,\"ALCOLOR\":63488,\"even\":13029,\"odd\":12485,\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}]}]");
#endif
}
conf.close();
delay(50);
log_i("config_exists: config.conf created with default");
return false;
} else {
log_i("config_exists: config.conf exists");
return true;
}
}


/*********************************************************************
** Function: getConfigs
** getConfigurations from EEPROM or JSON
**********************************************************************/
void getConfigs() {
if(setupSdCard()) {
if(!SDM.exists(CONFIG_FILE)) {
File conf = SDM.open(CONFIG_FILE, FILE_WRITE);
if(conf) {
#if ROTATION >1
conf.print("[{\"rot\":3,\"dimmerSet\":10,\"onlyBins\":1,\"bright\":100,\"askSpiffs\":1,\"wui_usr\":\"admin\",\"wui_pwd\":\"launcher\",\"dwn_path\":\"/downloads/\",\"FGCOLOR\":2016,\"BGCOLOR\":0,\"ALCOLOR\":63488,\"even\":13029,\"odd\":12485,\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}]}]");
#else
conf.print("[{\"rot\":1,\"dimmerSet\":10,\"onlyBins\":1,\"bright\":100,\"askSpiffs\":1,\"wui_usr\":\"admin\",\"wui_pwd\":\"launcher\",\"dwn_path\":\"/downloads/\",\"FGCOLOR\":2016,\"BGCOLOR\":0,\"ALCOLOR\":63488,\"even\":13029,\"odd\":12485,\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}]}]");
#endif
}
conf.close();
delay(50);
} else log_i("getConfigs: config.conf exists");
File file = SDM.open(CONFIG_FILE, FILE_READ);
if(file) {
// Deserialize the JSON document
DeserializationError error = deserializeJson(settings, file);
if (error) {
log_i("Failed to read file, using default configuration");
goto Default;
} else log_i("getConfigs: deserialized correctly");

int count=0;
JsonObject setting = settings[0];
if(setting.containsKey("onlyBins")) { onlyBins = gsetOnlyBins(setting["onlyBins"].as<bool>()); } else { count++; log_i("Fail"); }
if(setting.containsKey("askSpiffs")) { askSpiffs = gsetAskSpiffs(setting["askSpiffs"].as<bool>()); } else { count++; log_i("Fail"); }
if(setting.containsKey("bright")) { bright = setting["bright"].as<int>(); } else { count++; log_i("Fail"); }
if(setting.containsKey("dimmerSet")) { dimmerSet = setting["dimmerSet"].as<int>(); } else { count++; log_i("Fail"); }
if(setting.containsKey("rot")) { rotation = setting["rot"].as<int>(); } else { count++; log_i("Fail"); }
if(setting.containsKey("FGCOLOR")) { FGCOLOR = setting["FGCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
if(setting.containsKey("BGCOLOR")) { BGCOLOR = setting["BGCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
if(setting.containsKey("ALCOLOR")) { ALCOLOR = setting["ALCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
if(setting.containsKey("odd")) { odd_color = setting["odd"].as<uint16_t>(); } else { count++; log_i("Fail"); }
if(setting.containsKey("even")) { even_color= setting["even"].as<uint16_t>(); } else { count++; log_i("Fail"); }
if(setting.containsKey("wui_usr")) { wui_usr = setting["wui_usr"].as<String>(); } else { count++; log_i("Fail"); }
if(setting.containsKey("wui_pwd")) { wui_pwd = setting["wui_pwd"].as<String>(); } else { count++; log_i("Fail"); }
if(setting.containsKey("dwn_path")) { dwn_path = setting["dwn_path"].as<String>(); } else { count++; log_i("Fail"); }
if(!setting.containsKey("wifi")) { count++; log_i("Fail"); }
if(count>0) saveConfigs();

log_i("Brightness: %d", bright);
setBrightness(bright);
if(dimmerSet<10) dimmerSet=10;
file.close();
if (setupSdCard()) {
// check if config file exists, otherwise create it with default values
config_exists();
File file = SDM.open(CONFIG_FILE, FILE_READ);
if (file) {
DeserializationError error = deserializeJson(settings, file);
if (error) {
log_i("Failed to read file, using default configuration");
goto Default;
} else {
log_i("getConfigs: deserialized correctly");
}

int count = 0;
JsonObject setting = settings[0];
if(setting["onlyBins"].is<bool>()) { onlyBins = gsetOnlyBins(setting["onlyBins"].as<bool>()); } else { count++; log_i("Fail"); }
if(setting["askSpiffs"].is<bool>()) { askSpiffs = gsetAskSpiffs(setting["askSpiffs"].as<bool>()); } else { count++; log_i("Fail"); }
if(setting["bright"].is<int>()) { bright = setting["bright"].as<int>(); } else { count++; log_i("Fail"); }
if(setting["dimmerSet"].is<int>()) { dimmerSet = setting["dimmerSet"].as<int>(); } else { count++; log_i("Fail"); }
if(setting["rot"].is<int>()) { rotation = setting["rot"].as<int>(); } else { count++; log_i("Fail"); }
if(setting["FGCOLOR"].is<uint16_t>()) { FGCOLOR = setting["FGCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
if(setting["BGCOLOR"].is<uint16_t>()) { BGCOLOR = setting["BGCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
if(setting["ALCOLOR"].is<uint16_t>()) { ALCOLOR = setting["ALCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
if(setting["odd"].is<uint16_t>()) { odd_color = setting["odd"].as<uint16_t>(); } else { count++; log_i("Fail"); }
if(setting["even"].is<uint16_t>()) { even_color= setting["even"].as<uint16_t>(); } else { count++; log_i("Fail"); }
if(setting["wui_usr"].is<String>()) { wui_usr = setting["wui_usr"].as<String>(); } else { count++; log_i("Fail"); }
if(setting["wui_pwd"].is<String>()) { wui_pwd = setting["wui_pwd"].as<String>(); } else { count++; log_i("Fail"); }
if(setting["dwn_path"].is<String>()) { dwn_path = setting["dwn_path"].as<String>(); } else { count++; log_i("Fail"); }
if (!setting["wifi"].is<JsonArray>()) { ++count; log_i("Fail"); }
if(count>0) saveConfigs();

log_i("Brightness: %d", bright);
setBrightness(bright);
if (dimmerSet < 10) dimmerSet = 10;

file.close();

EEPROM.begin(EEPROMSIZE);
EEPROM.write(EEPROMSIZE - 13, rotation);
EEPROM.write(EEPROMSIZE - 14, dimmerSet);
EEPROM.write(EEPROMSIZE - 15, bright);
EEPROM.write(EEPROMSIZE - 1, int(onlyBins));
EEPROM.write(EEPROMSIZE - 2, int(askSpiffs));



EEPROM.begin(EEPROMSIZE); // open eeprom
EEPROM.write(EEPROMSIZE-13, rotation);
EEPROM.write(EEPROMSIZE-14, dimmerSet);
EEPROM.write(EEPROMSIZE-15, bright);
EEPROM.write(EEPROMSIZE-1, int(onlyBins));
EEPROM.write(EEPROMSIZE-2, int(askSpiffs));
EEPROM.write(EEPROMSIZE - 3, int((FGCOLOR >> 8) & 0x00FF));
EEPROM.write(EEPROMSIZE - 4, int(FGCOLOR & 0x00FF));

EEPROM.write(EEPROMSIZE-3, int((FGCOLOR >> 8) & 0x00FF));
EEPROM.write(EEPROMSIZE-4, int(FGCOLOR & 0x00FF));
EEPROM.write(EEPROMSIZE - 5, int((BGCOLOR >> 8) & 0x00FF));
EEPROM.write(EEPROMSIZE - 6, int(BGCOLOR & 0x00FF));

EEPROM.write(EEPROMSIZE-5, int((BGCOLOR >> 8) & 0x00FF));
EEPROM.write(EEPROMSIZE-6, int(BGCOLOR & 0x00FF));
EEPROM.write(EEPROMSIZE - 7, int((ALCOLOR >> 8) & 0x00FF));
EEPROM.write(EEPROMSIZE - 8, int(ALCOLOR & 0x00FF));

EEPROM.write(EEPROMSIZE-7, int((ALCOLOR >> 8) & 0x00FF));
EEPROM.write(EEPROMSIZE-8, int(ALCOLOR & 0x00FF));
EEPROM.write(EEPROMSIZE - 9, int((odd_color >> 8) & 0x00FF));
EEPROM.write(EEPROMSIZE - 10, int(odd_color & 0x00FF));

EEPROM.write(EEPROMSIZE-9, int((odd_color >> 8) & 0x00FF));
EEPROM.write(EEPROMSIZE-10, int(odd_color & 0x00FF));
EEPROM.write(EEPROMSIZE - 11, int((even_color >> 8) & 0x00FF));
EEPROM.write(EEPROMSIZE - 12, int(even_color & 0x00FF));

EEPROM.write(EEPROMSIZE-11, int((even_color >> 8) & 0x00FF));
EEPROM.write(EEPROMSIZE-12, int(even_color & 0x00FF));
if(!EEPROM.commit()) log_i("fail to write EEPROM"); // Store data to EEPROM
EEPROM.end();
log_i("Using config.conf setup file");
if (!EEPROM.commit()) log_i("fail to write EEPROM");
EEPROM.end();
log_i("Using config.conf setup file");
} else {
Default:
Default:
file.close();
saveConfigs();

log_i("Using settings stored on EEPROM");
}
}
Expand All @@ -404,16 +416,19 @@ void getConfigs() {
**********************************************************************/
void saveConfigs() {
// Delete existing file, otherwise the configuration is appended to the file
bool retry=true;
Retry:
if(setupSdCard()) {
if(SDM.remove(CONFIG_FILE)) log_i("config.conf deleted");
else log_i("fail deleting config.conf");

JsonObject setting = settings[0];
//if(!settings[0].containsKey("onlyBins"))

// Atribuindo as configurações ao objeto JSON
setting["onlyBins"] = onlyBins;
setting["askSpiffs"] = askSpiffs;
setting["bright"] = bright;
setting["dimmerSet"] = dimmerSet;
setting["dimmerSet"] = dimmerSet;
setting["rot"] = rotation;
setting["FGCOLOR"] = FGCOLOR;
setting["BGCOLOR"] = BGCOLOR;
Expand All @@ -423,7 +438,7 @@ void saveConfigs() {
setting["wui_usr"] = wui_usr;
setting["wui_pwd"] = wui_pwd;
setting["dwn_path"] = dwn_path;
if(!setting.containsKey("wifi")) {
if(!setting["wifi"].is<JsonArray>()) {
JsonArray WifiList = setting["wifi"].to<JsonArray>();
if(WifiList.size()<1) {
JsonObject WifiObj = WifiList.add<JsonObject>();
Expand All @@ -439,9 +454,22 @@ void saveConfigs() {
return;
} else log_i("config.conf created");
// Serialize JSON to file
if (serializeJsonPretty(settings, file) < 5) {
if (serializeJsonPretty(settings, file) < 5 && retry) {
log_i("Failed to write to file");
} else log_i("config.conf written successfully");
file.close();
log_i("Deleting file");
SDM.remove(CONFIG_FILE);
log_i("Creating default file");
// check if config file exists, otherwise create it with default values
config_exists();
//Try to rewrite the configs
file = SDM.open(CONFIG_FILE, FILE_READ);
deserializeJson(settings, file);
retry=false;
goto Retry;

} else if (!retry) log_i("Create new file and Rewriting didn't work");
else log_i("config.conf written successfully");

// Close the file
file.close();
Expand All @@ -451,4 +479,4 @@ void saveConfigs() {
EEPROM.writeString(EEPROMSIZE,ssid);
EEPROM.commit();
EEPROM.end();
}
}

0 comments on commit 543804b

Please sign in to comment.