Skip to content

Commit 543804b

Browse files
committed
UiFlow2 fix and fixes
1 parent 34b1261 commit 543804b

6 files changed

Lines changed: 117 additions & 89 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Sourcecode will be released in the future..
6262
* 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.
6363

6464
## Changelog
65+
* 2.3.1:
66+
* [x] Fox for https://github.com/bmorcelli/M5Stick-Launcher/issues/77
67+
* [x] Fixed screen direction for T-Deck devices
68+
* [x] Fixed Json handling and config.conf random fails
6569
* 2.3.0:
6670
* [x] Ported to Lilygo T-Embed CC1101
6771
* [x] Ported to Lilygo T-Embed

custom_8Mb.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Defaul, , , , ,
1+
# Default, , , , ,
22
# Name, Type, SubType, Offset, Size, Flags
33
nvs, data, nvs, 0x9000, 0x6000,
44
app0, app, test, 0x10000, 0x180000,
@@ -18,6 +18,6 @@ coredump, data, coredump,0x7F0000, 0x10000,
1818
# Name, Type, SubType, Offset, Size, Flags
1919
#nvs, data, nvs, 0x9000, 0x6000,
2020
#app0, app, test, 0x10000, 0x180000,
21-
#app1, app, ota_0, 0x190000, 0x450000,
22-
#sys, data, fat, 0x5E0000, 0x100000,
23-
#vfs, data, fat, 0x6E0000, 0x120000,
21+
#app1, app, ota_0, 0x190000, 0x470000,
22+
#sys, data, fat, 0x600000, 0x100000,
23+
#vfs, data, fat, 0x700000, 0x100000,

platformio.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ extra_scripts = pre:support_files/nvs_script.py
187187
board_build.partitions = custom_8Mb.csv
188188
build_flags =
189189
${common.build_flags}
190-
;-DCORE_DEBUG_LEVEL=5
190+
-DCORE_DEBUG_LEVEL=5
191191
-DCARDPUTER=1
192192
-DREDRAW_DELAY=200
193193

@@ -866,7 +866,7 @@ build_flags =
866866
;-DPART_04MB =0
867867
;-DPART_08MB =0
868868
-DPART_16MB=1
869-
-DROTATION=1
869+
-DROTATION=3
870870
-DHAS_BTN=1
871871
-DSEL_BTN=0
872872
-DUP_BTN=3 ;2

src/main.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ void setup() {
263263
#elif defined(T_DECK)
264264
pinMode(PIN_POWER_ON, OUTPUT);
265265
digitalWrite(PIN_POWER_ON, HIGH);
266+
pinMode(9, OUTPUT); // Radio CS Pin to HIGH (Inhibit the SPI Communication for this module)
267+
digitalWrite(9, HIGH);
266268
pinMode(SEL_BTN, INPUT);
267269

268270
// Setup for Trackball
@@ -274,13 +276,7 @@ void setup() {
274276
attachInterrupt(L_BTN, ISR_left, FALLING);
275277
pinMode(R_BTN, INPUT_PULLUP);
276278
attachInterrupt(R_BTN, ISR_right, FALLING);
277-
//pinMode(BACKLIGHT, OUTPUT);
278-
//digitalWrite(BACKLIGHT,HIGH);
279279

280-
// PWM backlight setup
281-
// ledcSetup(TFT_BRIGHT_CHANNEL,TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits); //Channel 0, 10khz, 8bits
282-
// ledcAttachPin(TFT_BL, TFT_BRIGHT_CHANNEL);
283-
// ledcWrite(TFT_BRIGHT_CHANNEL,125);
284280

285281
#elif defined(HEADLESS)
286282
#if SEL_BTN >= 0 // handle enter in launcher

src/partitioner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ const uint8_t uiflow2[192] PROGMEM = { // uiflow partition scheme, APP, sys(FAT)
4545
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4646
0xAA, 0x50, 0x00, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x61, 0x70, 0x70, 0x30,
4747
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48-
0xAA, 0x50, 0x00, 0x10, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x45, 0x00, 0x61, 0x70, 0x70, 0x31,
48+
0xAA, 0x50, 0x00, 0x10, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x47, 0x00, 0x61, 0x70, 0x70, 0x31,
4949
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50-
0xAA, 0x50, 0x01, 0x81, 0x00, 0x00, 0x5E, 0x00, 0x00, 0x00, 0x10, 0x00, 0x73, 0x79, 0x73, 0x00,
50+
0xAA, 0x50, 0x01, 0x81, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x10, 0x00, 0x73, 0x79, 0x73, 0x00,
5151
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52-
0xAA, 0x50, 0x01, 0x81, 0x00, 0x00, 0x6E, 0x00, 0x00, 0x00, 0x12, 0x00, 0x76, 0x66, 0x73, 0x00,
52+
0xAA, 0x50, 0x01, 0x81, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x10, 0x00, 0x76, 0x66, 0x73, 0x00,
5353
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5454
0xEB, 0xEB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
55-
0x48, 0xF8, 0x55, 0x10, 0x56, 0x7F, 0x21, 0xB9, 0x2C, 0x39, 0x4A, 0xA9, 0xF7, 0xC9, 0x22, 0x3B,
55+
0xA9, 0x7C, 0xFA, 0x04, 0x64, 0x3F, 0x74, 0xF6, 0xBA, 0x15, 0x15, 0x9C, 0x32, 0xBD, 0x2F, 0x23,
5656
};
5757

5858
#elif defined(PART_04MB)

src/settings.cpp

Lines changed: 101 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -313,87 +313,99 @@ void chargeMode() {
313313
delay(200);
314314
}
315315

316+
317+
bool config_exists() {
318+
if (!SDM.exists(CONFIG_FILE)) {
319+
File conf = SDM.open(CONFIG_FILE, FILE_WRITE);
320+
if (conf) {
321+
#if ROTATION > 1
322+
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\"}]}]");
323+
#else
324+
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\"}]}]");
325+
#endif
326+
}
327+
conf.close();
328+
delay(50);
329+
log_i("config_exists: config.conf created with default");
330+
return false;
331+
} else {
332+
log_i("config_exists: config.conf exists");
333+
return true;
334+
}
335+
}
336+
337+
316338
/*********************************************************************
317339
** Function: getConfigs
318340
** getConfigurations from EEPROM or JSON
319341
**********************************************************************/
320342
void getConfigs() {
321-
if(setupSdCard()) {
322-
if(!SDM.exists(CONFIG_FILE)) {
323-
File conf = SDM.open(CONFIG_FILE, FILE_WRITE);
324-
if(conf) {
325-
#if ROTATION >1
326-
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\"}]}]");
327-
#else
328-
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\"}]}]");
329-
#endif
330-
}
331-
conf.close();
332-
delay(50);
333-
} else log_i("getConfigs: config.conf exists");
334-
File file = SDM.open(CONFIG_FILE, FILE_READ);
335-
if(file) {
336-
// Deserialize the JSON document
337-
DeserializationError error = deserializeJson(settings, file);
338-
if (error) {
339-
log_i("Failed to read file, using default configuration");
340-
goto Default;
341-
} else log_i("getConfigs: deserialized correctly");
342-
343-
int count=0;
344-
JsonObject setting = settings[0];
345-
if(setting.containsKey("onlyBins")) { onlyBins = gsetOnlyBins(setting["onlyBins"].as<bool>()); } else { count++; log_i("Fail"); }
346-
if(setting.containsKey("askSpiffs")) { askSpiffs = gsetAskSpiffs(setting["askSpiffs"].as<bool>()); } else { count++; log_i("Fail"); }
347-
if(setting.containsKey("bright")) { bright = setting["bright"].as<int>(); } else { count++; log_i("Fail"); }
348-
if(setting.containsKey("dimmerSet")) { dimmerSet = setting["dimmerSet"].as<int>(); } else { count++; log_i("Fail"); }
349-
if(setting.containsKey("rot")) { rotation = setting["rot"].as<int>(); } else { count++; log_i("Fail"); }
350-
if(setting.containsKey("FGCOLOR")) { FGCOLOR = setting["FGCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
351-
if(setting.containsKey("BGCOLOR")) { BGCOLOR = setting["BGCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
352-
if(setting.containsKey("ALCOLOR")) { ALCOLOR = setting["ALCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
353-
if(setting.containsKey("odd")) { odd_color = setting["odd"].as<uint16_t>(); } else { count++; log_i("Fail"); }
354-
if(setting.containsKey("even")) { even_color= setting["even"].as<uint16_t>(); } else { count++; log_i("Fail"); }
355-
if(setting.containsKey("wui_usr")) { wui_usr = setting["wui_usr"].as<String>(); } else { count++; log_i("Fail"); }
356-
if(setting.containsKey("wui_pwd")) { wui_pwd = setting["wui_pwd"].as<String>(); } else { count++; log_i("Fail"); }
357-
if(setting.containsKey("dwn_path")) { dwn_path = setting["dwn_path"].as<String>(); } else { count++; log_i("Fail"); }
358-
if(!setting.containsKey("wifi")) { count++; log_i("Fail"); }
359-
if(count>0) saveConfigs();
360-
361-
log_i("Brightness: %d", bright);
362-
setBrightness(bright);
363-
if(dimmerSet<10) dimmerSet=10;
364-
file.close();
343+
if (setupSdCard()) {
344+
// check if config file exists, otherwise create it with default values
345+
config_exists();
346+
File file = SDM.open(CONFIG_FILE, FILE_READ);
347+
if (file) {
348+
DeserializationError error = deserializeJson(settings, file);
349+
if (error) {
350+
log_i("Failed to read file, using default configuration");
351+
goto Default;
352+
} else {
353+
log_i("getConfigs: deserialized correctly");
354+
}
355+
356+
int count = 0;
357+
JsonObject setting = settings[0];
358+
if(setting["onlyBins"].is<bool>()) { onlyBins = gsetOnlyBins(setting["onlyBins"].as<bool>()); } else { count++; log_i("Fail"); }
359+
if(setting["askSpiffs"].is<bool>()) { askSpiffs = gsetAskSpiffs(setting["askSpiffs"].as<bool>()); } else { count++; log_i("Fail"); }
360+
if(setting["bright"].is<int>()) { bright = setting["bright"].as<int>(); } else { count++; log_i("Fail"); }
361+
if(setting["dimmerSet"].is<int>()) { dimmerSet = setting["dimmerSet"].as<int>(); } else { count++; log_i("Fail"); }
362+
if(setting["rot"].is<int>()) { rotation = setting["rot"].as<int>(); } else { count++; log_i("Fail"); }
363+
if(setting["FGCOLOR"].is<uint16_t>()) { FGCOLOR = setting["FGCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
364+
if(setting["BGCOLOR"].is<uint16_t>()) { BGCOLOR = setting["BGCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
365+
if(setting["ALCOLOR"].is<uint16_t>()) { ALCOLOR = setting["ALCOLOR"].as<uint16_t>(); } else { count++; log_i("Fail"); }
366+
if(setting["odd"].is<uint16_t>()) { odd_color = setting["odd"].as<uint16_t>(); } else { count++; log_i("Fail"); }
367+
if(setting["even"].is<uint16_t>()) { even_color= setting["even"].as<uint16_t>(); } else { count++; log_i("Fail"); }
368+
if(setting["wui_usr"].is<String>()) { wui_usr = setting["wui_usr"].as<String>(); } else { count++; log_i("Fail"); }
369+
if(setting["wui_pwd"].is<String>()) { wui_pwd = setting["wui_pwd"].as<String>(); } else { count++; log_i("Fail"); }
370+
if(setting["dwn_path"].is<String>()) { dwn_path = setting["dwn_path"].as<String>(); } else { count++; log_i("Fail"); }
371+
if (!setting["wifi"].is<JsonArray>()) { ++count; log_i("Fail"); }
372+
if(count>0) saveConfigs();
373+
374+
log_i("Brightness: %d", bright);
375+
setBrightness(bright);
376+
if (dimmerSet < 10) dimmerSet = 10;
377+
378+
file.close();
379+
380+
EEPROM.begin(EEPROMSIZE);
381+
EEPROM.write(EEPROMSIZE - 13, rotation);
382+
EEPROM.write(EEPROMSIZE - 14, dimmerSet);
383+
EEPROM.write(EEPROMSIZE - 15, bright);
384+
EEPROM.write(EEPROMSIZE - 1, int(onlyBins));
385+
EEPROM.write(EEPROMSIZE - 2, int(askSpiffs));
365386

366-
367-
368-
EEPROM.begin(EEPROMSIZE); // open eeprom
369-
EEPROM.write(EEPROMSIZE-13, rotation);
370-
EEPROM.write(EEPROMSIZE-14, dimmerSet);
371-
EEPROM.write(EEPROMSIZE-15, bright);
372-
EEPROM.write(EEPROMSIZE-1, int(onlyBins));
373-
EEPROM.write(EEPROMSIZE-2, int(askSpiffs));
387+
EEPROM.write(EEPROMSIZE - 3, int((FGCOLOR >> 8) & 0x00FF));
388+
EEPROM.write(EEPROMSIZE - 4, int(FGCOLOR & 0x00FF));
374389

375-
EEPROM.write(EEPROMSIZE-3, int((FGCOLOR >> 8) & 0x00FF));
376-
EEPROM.write(EEPROMSIZE-4, int(FGCOLOR & 0x00FF));
390+
EEPROM.write(EEPROMSIZE - 5, int((BGCOLOR >> 8) & 0x00FF));
391+
EEPROM.write(EEPROMSIZE - 6, int(BGCOLOR & 0x00FF));
377392

378-
EEPROM.write(EEPROMSIZE-5, int((BGCOLOR >> 8) & 0x00FF));
379-
EEPROM.write(EEPROMSIZE-6, int(BGCOLOR & 0x00FF));
393+
EEPROM.write(EEPROMSIZE - 7, int((ALCOLOR >> 8) & 0x00FF));
394+
EEPROM.write(EEPROMSIZE - 8, int(ALCOLOR & 0x00FF));
380395

381-
EEPROM.write(EEPROMSIZE-7, int((ALCOLOR >> 8) & 0x00FF));
382-
EEPROM.write(EEPROMSIZE-8, int(ALCOLOR & 0x00FF));
396+
EEPROM.write(EEPROMSIZE - 9, int((odd_color >> 8) & 0x00FF));
397+
EEPROM.write(EEPROMSIZE - 10, int(odd_color & 0x00FF));
383398

384-
EEPROM.write(EEPROMSIZE-9, int((odd_color >> 8) & 0x00FF));
385-
EEPROM.write(EEPROMSIZE-10, int(odd_color & 0x00FF));
399+
EEPROM.write(EEPROMSIZE - 11, int((even_color >> 8) & 0x00FF));
400+
EEPROM.write(EEPROMSIZE - 12, int(even_color & 0x00FF));
386401

387-
EEPROM.write(EEPROMSIZE-11, int((even_color >> 8) & 0x00FF));
388-
EEPROM.write(EEPROMSIZE-12, int(even_color & 0x00FF));
389-
if(!EEPROM.commit()) log_i("fail to write EEPROM"); // Store data to EEPROM
390-
EEPROM.end();
391-
log_i("Using config.conf setup file");
402+
if (!EEPROM.commit()) log_i("fail to write EEPROM");
403+
EEPROM.end();
404+
log_i("Using config.conf setup file");
392405
} else {
393-
Default:
406+
Default:
394407
file.close();
395408
saveConfigs();
396-
397409
log_i("Using settings stored on EEPROM");
398410
}
399411
}
@@ -404,16 +416,19 @@ void getConfigs() {
404416
**********************************************************************/
405417
void saveConfigs() {
406418
// Delete existing file, otherwise the configuration is appended to the file
419+
bool retry=true;
420+
Retry:
407421
if(setupSdCard()) {
408422
if(SDM.remove(CONFIG_FILE)) log_i("config.conf deleted");
409423
else log_i("fail deleting config.conf");
410424

411425
JsonObject setting = settings[0];
412-
//if(!settings[0].containsKey("onlyBins"))
426+
427+
// Atribuindo as configurações ao objeto JSON
413428
setting["onlyBins"] = onlyBins;
414429
setting["askSpiffs"] = askSpiffs;
415430
setting["bright"] = bright;
416-
setting["dimmerSet"] = dimmerSet;
431+
setting["dimmerSet"] = dimmerSet;
417432
setting["rot"] = rotation;
418433
setting["FGCOLOR"] = FGCOLOR;
419434
setting["BGCOLOR"] = BGCOLOR;
@@ -423,7 +438,7 @@ void saveConfigs() {
423438
setting["wui_usr"] = wui_usr;
424439
setting["wui_pwd"] = wui_pwd;
425440
setting["dwn_path"] = dwn_path;
426-
if(!setting.containsKey("wifi")) {
441+
if(!setting["wifi"].is<JsonArray>()) {
427442
JsonArray WifiList = setting["wifi"].to<JsonArray>();
428443
if(WifiList.size()<1) {
429444
JsonObject WifiObj = WifiList.add<JsonObject>();
@@ -439,9 +454,22 @@ void saveConfigs() {
439454
return;
440455
} else log_i("config.conf created");
441456
// Serialize JSON to file
442-
if (serializeJsonPretty(settings, file) < 5) {
457+
if (serializeJsonPretty(settings, file) < 5 && retry) {
443458
log_i("Failed to write to file");
444-
} else log_i("config.conf written successfully");
459+
file.close();
460+
log_i("Deleting file");
461+
SDM.remove(CONFIG_FILE);
462+
log_i("Creating default file");
463+
// check if config file exists, otherwise create it with default values
464+
config_exists();
465+
//Try to rewrite the configs
466+
file = SDM.open(CONFIG_FILE, FILE_READ);
467+
deserializeJson(settings, file);
468+
retry=false;
469+
goto Retry;
470+
471+
} else if (!retry) log_i("Create new file and Rewriting didn't work");
472+
else log_i("config.conf written successfully");
445473

446474
// Close the file
447475
file.close();
@@ -451,4 +479,4 @@ void saveConfigs() {
451479
EEPROM.writeString(EEPROMSIZE,ssid);
452480
EEPROM.commit();
453481
EEPROM.end();
454-
}
482+
}

0 commit comments

Comments
 (0)