Smanar / CYD-Domoticz-Remote

WIP project to control your home-automation using Domoticz and a CYD (Cheap touchscreen).
8 stars 2 forks source link

Dont show Swedish letters #10

Open ElMyggo opened 2 months ago

ElMyggo commented 2 months ago

Found this awesome project so i order display and setup software, after upload i found that i cant se the swedish letters... and i have very litte skill to modify the files... Another question, is it possible to use a "scene" at the startpage? like the "Dashboard" to combine from different groups. switches switches_all

Smanar commented 2 months ago

Another question, is it possible to use a "scene" at the startpage? like the "Dashboard" to combine from different groups.

You mean group/scene from domoticz ? So yes, on platformio.ini file just comment this line

-DNO_GROUP_PAGE # Disable the Group/scene panel

IDk on wich branch you are, if you have issue on the "stable, pls try the "beta"

Found this awesome project so i order display and setup software, after upload i found that i cant se the swedish letters... and i have very litte skill to modify the files...

How many letter you miss ? if there is too much better to make a "custom swedish font". I can make the file for you if you have problem, don't worry. But If you want to make it yourself :

First I m using 3 fonts by resolution (it's on the panel.h file)

#if DEVICE_SIZE == 1
LV_FONT_DECLARE(Montserrat_Bold_14)
const lv_font_t font1 = Montserrat_Bold_14;
const lv_font_t font3 = lv_font_montserrat_12;
const lv_font_t font2 = lv_font_montserrat_10;
#else
LV_FONT_DECLARE(Montserrat_Bold_18)
const lv_font_t font1 = Montserrat_Bold_18;
const lv_font_t font3 = lv_font_montserrat_16;
const lv_font_t font2 = lv_font_montserrat_14;
#endif

font1 is a custom one, so this one can miss some char, for information I m using all char from range 32-126 and as special char only €°µ¥£²³ font1 is the bigger one, if you have problem on lower font, it mean the native one on the Lvlg lib miss them, and here forced to make your custom font.

From your capture it seem you have problem on font3 and font2.

I m using montserrat font, you can find them here https://github.com/Smanar/Ressources/blob/main/montserrat.zip

On the archive take the font you want, I m using the bold one, but for font2/font3 I think it's Montserrat-Regular.ttf, can use other one if you prefer.

After go on the online tool converter https://lvgl.io/tools/fontconverter

Here you have my defaut settings

lvlgfont

Click on "parcourir" (on TTF/WOF file) and select the file font. You can increase the range, or just add special char, then select "convert".

You will obtain a new *.c file, put it in the src\font folder, it will be added automatically on code. To use them on the code you can edit it to have for exemple (here the new file is Montserrat_Regular_12.c)

#if DEVICE_SIZE == 1
LV_FONT_DECLARE(Montserrat_Bold_14)
LV_FONT_DECLARE(Montserrat_Regular_12)
const lv_font_t font1 = Montserrat_Bold_14;
const lv_font_t font3 = Montserrat_Regular_12;
const lv_font_t font2 = lv_font_montserrat_10;
#else

I m making this from my memory, I can skip a step ^^, if you have problem just tell me.

ElMyggo commented 2 months ago

Great explaining for a beginner like me... I must give this a try to change the letters, learning by doing ;-) And yes i find the settings for group/scenes but is it possible to get it on same page "homepage" I like to have some switches, a temp and electric power and a scene on same page. I set the idx number in settings but no, still have to swipe right to get to group/scenes page.

Smanar commented 2 months ago

Ha yes, so nope, I m using the same working mode than domoticz. There is an homepage, and a special page for group/scene, It's not the same API requests to use for them, if you have just 1 scene, you can create a custom switch to trigger it ?

ElMyggo commented 2 months ago

Finally i fix it :-) i made new files (lv_font_montserrat_10.c + lv_font_montserrat_12.c) with the same input as the original (find the settings in top of the file) and then added the swedish fonts åäö ÅÄÖ

When i change the file Montserrat_Bold_14 ESP32 crash when doing setup page for Domoticz so i try some more there..

I put this in Domoticz forum also ;-)

settings fixed-font menu

ElMyggo commented 2 months ago

Ha yes, so nope, I m using the same working mode than domoticz. There is an homepage, and a special page for group/scene, It's not the same API requests to use for them, if you have just 1 scene, you can create a custom switch to trigger it ?

Of course! easiest way to get the scene on same homepage, thanks

Smanar commented 2 months ago

i made new files (lv_font_montserrat_10.c + lv_font_montserrat_12.c)

So you made file with the same name than the original font ? I haven't try this. You still need to edit the c++ code in the panel.h file ?

Smanar commented 2 months ago

For the crash I have no idea, you are replacing my file (Montserrat_Bold_14.c )? Can you share your configuration on the online convertor ?

ElMyggo commented 2 months ago

Montserrat_Bold_14.zip This is the settings i use, i notice that filesize is much bigger on my file and when i looked in the file i get "KERNING" but in your file not.. i upload the file i create

convert_bold

ElMyggo commented 2 months ago

lv_font_montserrat.zip

i made new files (lv_font_montserrat_10.c + lv_font_montserrat_12.c)

So you made file with the same name than the original font ? I haven't try this. You still need to edit the c++ code in the panel.h file ?

I only change the contense in the 2 original files at .pio/libdeps/esp32-2432S028R/lvgl/src/font no change in panel.h

Smanar commented 2 months ago

I only change the contense in the 2 original files at .pio/libdeps/esp32-2432S028R/lvgl/src/font

This is not good, it's the library file, need to stay untouched, you are editing the official library. Better to use this way https://github.com/Smanar/CYD-Domoticz-Remote/issues/10#issuecomment-2079774675 But I have updated the branch "test", on this branch just uncomment in platformio.ini file #-DCUSTOM_FONT=1

And after you just need to put your font in the src/font folder with those name

Take care it's case sensitive. And need to edit the firsts line too on *.c file, line 7 - 11

#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "../lvgl.h"
#endif

Like that you will be able to update the code and keeping your files untouched.

About your issue, idk, I m trying on my side with same setting and I don't have the same result, perhaps we are not using the same Montserrat-Bold.ttf file, but there is only 1 file with this name ...

Here my result font.zip

ElMyggo commented 2 months ago

I have no luck... stuck on this.. i only modify main.cpp (wifi and idx) and platformio.ino for custom font and copy the font files attach my files and log error

files.zip

Smanar commented 2 months ago

I have made a try with success 5 mn ago:

And I have swedish character, have corrected a problem on device panel title (displaying square), but it's not blocking like you.

It work if you replace the comment on -DCUSTOM_FONT=1 ?

As you have corrupted the lib, try to "clean" the project, use the "garbage" icon, it will remove all file and re download them. or better, delete the ".pio" folder in the project (it will be re-created).

ElMyggo commented 2 months ago

Finally... almost... i delete everything and download new zipfile from github so i dont get the correction in panel title (i have to login and download direct from github in visual studio but havent test that yet... but try this later) im a total neewbie on this but learning by doing... (alot)

then i modify the bold file manually (copy/paste) and use my 10 and 12 files and now its working again, exept panel title bolderror

Smanar commented 2 months ago

Yes the corrective was not yet online. On my side I m not using the github plugin too, I m doing like you.

It's on line 334 in device panel.cpp

    //Label
    label = lv_label_create(GridTop);
    lv_obj_set_style_text_font(label, &font1, 0);
    lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); 

I m making somes tries (not sure about the font to use), you will have it online today.

Smanar commented 2 months ago

I think I have found a problem. We miss too the "return to line" character, "\n", it mean the application freeze if the result is on 2 lines, like for sensors with temperature+humidity.

I m on it ATM.

Smanar commented 2 months ago

Ok so first have updated the "test" branch to correct square in device title. And I had freeze too when the device need to print data on 2 line, because the ASCII char "line break" is not in our font.

It works on my code because at end of font file I have

    .dsc = &font_dsc,          /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
    .fallback = NULL,
    .user_data = NULL
};

But on your files you have

    .dsc = &font_dsc,          /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
#if LV_VERSION_CHECK(8, 2, 0) || LVGL_VERSION_MAJOR >= 9
    .fallback = &Montserrat_Bold_14,
#endif
    .user_data = NULL,

So it need some work again on the file. Make the change on your 3 files to be sure, even you don't use "line break".

After that all is woring on my side.

But I don't understand why the same editor, whith same values, don't return same code every time ....

ElMyggo commented 2 months ago

My files is updated now and everything seems to work ok :-) Another question, is it possible to use the onboard lightsensor (gpio34) to adjust brightness on display?

Smanar commented 2 months ago

I m trying ATM. I don't found project on github that use this feature, perhaps not reliable.

On my side I m using a fixed setting, no stand by mode.

I can retreive the light sensor value but need to make link with brightness. You have one on a place with a moving luminosity ? We can make a try, but it mean the device will be never in stand by mode.

ElMyggo commented 2 months ago

If its on at night its quite bright so i think if the sensor reduce the brightness, maybe read the value every minute or so.

but i maybe should try the wake timeout instead so the screen go off

Smanar commented 2 months ago

As you want, if you want to make a try, give me 1/2 day to code something.

Smanar commented 2 months ago

Have updated the branch "test" with a stuff to test. Honneslty I don't think it's usefull, on my side I have the device at 25% luminosity all the time, so I can't reduce it according to light. To test it :

The code will change the brighness value from 64 to your max value according the luminosity. Values used are visibles on logs.

#ifdef AUTO_BRIGHTNESS
    int cds = analogRead(CDS);
    //int cds = analogReadMilliVolts(CDS);
    Serial.printf("CDS value: %d\n", cds);

    // On analog value go from 0 light to 1000 dark, we will take 500 as medium
    // Brightness value go from 0 to 255
    // We will use as max value the one set by the user in global_config.brightness
    // 64 is the minimal value

    if (cds> 500) cds = 500;
    int b = 64 + (100 -(cds/5)) * (global_config.brightness - 64) / 100;
    Serial.printf("Brighness value: %d\n", b);

    screen_setBrightness(b);

#else
ElMyggo commented 2 months ago

Ok, i should try to se if i gonna use it, i have mine at 50% right now but i planned to change the position with a lot of sunshine.

Smanar commented 2 months ago

It's possible to edit the code, I have copy/paste it on previous post. But I don't have a real situation to see how it will react on real condition.

ElMyggo commented 2 months ago

i deactivate like this in platformio "-DAUTO_BRIGHTNESS=1" but i get no different in brightness at all, cannot se the cds value in log, only brightness value 64,128,192,255 depending what value set in config. tested in dark and bright condition on sensor

Smanar commented 2 months ago

You need too set the wake up delay to 30s (on device settings), and every 30s, you will see on log CDS value: 75

ElMyggo commented 2 months ago

You need too set the wake up delay to 30s (on device settings), and every 30s, you will see on log CDS value: 75

Aha missed that

ElMyggo commented 2 months ago

I have now test the autobrightness and i have to modify the code so i understand the calculation myself :-) This is probably not correct or the best way but i get it to work as i like with a small hole in the box above sensor. I found that the value from cds is 12-bit so value 0-4096 light-dark

#ifdef AUTO_BRIGHTNESS
    int cds = analogRead(CDS);
    //int cds = analogReadMilliVolts(CDS);
    Serial.printf("CDS value: %d\n", cds);

    //value from sensor is 0(light)-4096(dark) so invert value to 0(dark)-4096(light) and divide with 16,06 to get 0-255
    int b = (4096 -(cds))/16.06; 
    if (b>= global_config.brightness) b = global_config.brightness; //if value b is higher than config settings use config settings
    if (b< 10) b = 10; //if value b is lower than 10 set 10 as lowest brightness
    Serial.printf("Brightness value: %d\n", b);

    screen_setBrightness(b);

#else
Smanar commented 2 months ago

I haven't tried with real solar light, but with my smartphone 's light ^^. On my side using analogRead(CDS); I can't exceed 2000.

But if the code work for you, no problem, you have made more tests then me. Do you want to update the code yourself (on the "test" branch, or want I update it ?

ElMyggo commented 2 months ago

Maybe different version or builder on card so therefore different values. I have test it in a room with complete darkness and lowest value 10 light up a lot ;-) so it maybe need some changes for another user. Better you update the code if you want, im a newbiee ;-)

ElMyggo commented 2 months ago

Here i marked on my printed box with hole for the light sensor

front

Smanar commented 2 months ago

Maybe different version or builder on card so therefore different values.

Yeah probably, there is at least 3 version of this hardware, on this sensor don't work on all accoding issue.

Better you update the code if you want, im a newbiee ;

As you want, but not so hard, you just need to try to edit the file on the branch "test" and github will create a fork itself, and like that your changes will be under your names.

BTW It's a custom design print, or you are using a public one ?

ElMyggo commented 2 months ago

I modify a public one, i attach my 3d-files in stl and step for anyone else to use (this is the usb-c version) CYD v5.zip

Smanar commented 2 months ago

Nice thx a lot