From a4eed77f33338a79a0f65cd06ffbe7bab5d5cd53 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Sun, 10 Oct 2021 04:21:04 +0200 Subject: [PATCH 01/16] Added battery icon --- icons/battery.png | Bin 0 -> 7711 bytes main/icons/battery.h | 46 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 icons/battery.png create mode 100644 main/icons/battery.h diff --git a/icons/battery.png b/icons/battery.png new file mode 100644 index 0000000000000000000000000000000000000000..385f44f8b4157fc4f31fe5280bec07fcea6c6753 GIT binary patch literal 7711 zcmeAS@N?(olHy`uVBq!ia0y~yV2}V|4mJh`h6m-gKNuMJ+^a$&N`ey06$*;-(=u~X z6-p`#QWa7wGSe6sDsH`<6`>x-;y3@Hq zBAhW-3Rde~$@=&FzW3km`4gPO?3T!Q_so)yuh}?t@|ynn+x|p+KOI2U&z<9 zGrn*8x#8mE`Q_7=&P?&$`SV=%_Q%tA?3_DO{rY)>9hJJrKQn*7xz_4lAOHH<1-vD- z5Ar_W_&u|D|Jgq;t0pMEtGlvy_jRetx2~JJUMX+uc)n=e(l^HMvXhSf4S6!PB!p+K z<;3uZQ%kSToguYra%S)6B%OP)$7Uz4icEW#Y%bez&u_Lx)NRp+3gX6oTHD?SeE4K^ zT8$}bhtH9cq!Wc#?`@c2n|t$e>8DZ+Tb}JvhZEY||NUBeZ*QUQN!8?%eK)yc!Zrzu z+4`1&L3`S{y%pPgY^o%c#&5$k8cm^|xSg~<;pQuca2mSGS! zEM@2^tZ;CD+|;SybxkeVAmx~&=!pY|R!N|d{xOl(dD%rLmrqFY(p()9bXKqW zhxM~5#dksppdwdXdm#Ul+xO`^Ir7y;3EH0nfd}bHN)~D0r6OT^4a%%OOs?WDxUdvx^|6!Kp z-n8w@pByXsEEOKStIfbk-Lazf45iwZ6h(WtZE1`;EGa)_OPJijHOF{Yi&yyBMf$SGKUw2cQtBCz zWv<-+bjFlewYQ90^6#CL^uPIc!OE*^GiU5=R}J5@vH6w7(>?DGR_R9v;w*J`8yed8W-(|+D+RFQ^ z7gSx>Ue6X%|LR#f^Q!&5v)41Py3h8=bit+n?I+B%pH5s>xOwZ!y<57RUj=3#c8&Ua zp(sPMMXXCw)tW2rP3o7PHisWOH@4;8^tReA`gww6m#=PK$iM3$C_SZT@zw_WexZ z@6sEtw%@H!FDq^T7oHYg-}0Y*^J@Ox|IfX7b@<(WV0*IZrVRg&vsZw=wNS6!(&wZ}Hy-gu|{_Vg72 z)^TU8KCPKkY33|sq1gMkX6>q}EnZP8zc|j85_b5}VzWajYQ6HJYWqi$rDacUOQr8y z>Um_<)U-Q4!!)8;_X|sYm9kwv%`4LGoni_rd#lU`{|_z}AFh`FnUr76YW}CKV$I}v zyEwY6AN*pAo%D^*a)mgZ@h2tduTS)TLiB+@iFr=)zm}X{oafwaS;P z-|FrBX5t=EdB1F)d8}2pgN;y_o03*>XU8VKtpYL9EZd#K*hHIM^Dh;f>vvA9GB`Y| zR&Vzl|32%#y+1_rI84mFFP_=1af7|IinBs#gELcS#wuMuTlH<4j_H@|l_SC?Tv^wh z*5Ghv+P(TKYo2|Py(8zix$AzCW4ZW~eGzjeT6#^e4A{HPfAvPMDchDUy?ZU;&YH!S zyW-LcG&}mM4;dVl@ZNFG?~PvI=GK`w^D}luv0q*4_p>0~<;He84?O?A5vg_NS53ey2Vc2glu*a$Lex^&zv6`_z!7LR(c+vy~;6J^7RS zESxRiedL3!##g+x4=jx>>)%-~=->V1jg!t%XPrsrEt9SX6Xz{HKDq|#q3Se zn|puAWe1lgimQGxDq|9!k?E+HG2;<)RdZ6=)R^=I$K-di?w!V!{C~!}D-L^9-A<|Q za$dN@pKGZ{*Mj_((zUK`p&d-+vud0^8rCK64B0p<$3ooM+nuAdnXT#1=M&Z$DpeE0 zci(f>DY31bN>I^e&LB(K)JeBJcF6kRL7%zq8JLYh68C*O`Yg~y+eMsXAc>3_D`Bp=J{(@OVs>K51~~%@BXyq zKl+JiBvJ>gJs=s0pfF z#vG#k#rR9oi~s#hey5v7>OK1z0_q>loG-KZR(#Nt@Z%aEd!*C7T|}~19u4;vd71F@ zYPz?GvZ2hWi$a;|uQ~+mc6n@-w%Rz!q~y}$ix*_0HBCysJl}G|`b_Mib7luFsHM@Gr_+upuDZH%)%^>9wuFB97&2?g zekb-Fzak^|2mCF+aJBqReR@^t_Q#(%esib&IIu>p$?r+8VrvsU75!DE zlUb*+na=5DKU?W6s*rc>V&#?Iqch9)Yc>Q0l<#JWQn-|Fz9idObn0ID4WHk;#%3;Z zO>pnOk`%kPswBI`$%1v4nzZ1Vg?zg@oI^x!aX;^J3|3subTzc9or!~$EA51-@}lQc z9(ZJ`7|C;h*g*ZOPW$6BrL@^6Dz%s1D%cYk?+eSXNE{F1Mq-H!ft3!i?qKD*>=+pUVz zFJA4vyYRYO`1`kfd(C!L<(I#>{Y>Bs|KxSa9osCo|{fxlxmtbt@wSGQ$W%6dslr_a#vgt+2fRd?XbXM zr9E>buH`Qk$u9Ku*mU{ap+9S`R`$2lKl-+8hvi*W+m4xIyFaEYipRyaW!Gid zZoYSUXSrA$_l^hZTQAmczuUigz5cT5NB?I3)%$Ea1trJ;(9a<>rz5>zVAKG;=Pl%2cFA|=B*Qb4ruik8Sirxl`6 zr3O2{aL+PP(bel~%076o|LCgb?#=7?)-@^oV0`rK*^(DZs{iygw{(1butWa+JKJ~n z7@ZcMF}4 zT+99a`^L7}>J9%TcU-#t&x?7+PnEs*t{rkeaKNmf@b0xKwhxNfCF+b)g3DCweHG`k z-#h0U zT&uidE0D0hk^)#sNw%$0gl~X?bAC~(f{C7qo`J4wMP`|ik{y?VO;JjkRgjAt)QF;# zG+U*Nl9B=|ef{$Ca=mh6z5JqdeM3u2OML?)eIp~?qLeh<;>x^|#0uTKVr7sK5Hnm- zi<65o3raHc^Atd4CMM;Vme?vOaVaP$Kn<_RE%5b)8=qGU4Ta?VT>Xl~0)0b01O41w zePkWQC9Y*9_;nPAR2HP_2c;J0mlh?bx|XHpl_(<{k&+D8Ur<_<1NKfzvVLk#YHn&? zNwL16o*{~r?w-B@a2=o^NYBhI0PCvAEkIFOl9`4GEEL~>WWe4*c1T5T0o+^^)iA$< z6@$ab$|XO!6y!Wl7h5He{Z=XY$(bouU}maOTB<=}vXO2|T8gQziK$_-Zla}SlCDu& zQi^4=silcQni-N&o_WP3iFwJXAfqaB3-mHGQ>@I=ObsnlOe}TNlFiI?O$<_ubQ8_Z z4Rlk|%!~|-lTD0`EsT(i@Gr_t&&*5AL3S0$sFchUE5jrMa|;ubG~MJxBU4?IBojm3 z#6*)c-BinzMAOt%qoh`2X13e=PunZ_#to(~IQ}ap^LFv?1$q+1Fky~KpT$Gwvl3x^(pPyr^1ag3ak)ELe zIC(4BKqAE>v$!O`sL~FcqQUtlIJFSMgJgl6Ot6%K0yx=PB_=~GDNZa)O#xe^0Fz42 zNX$!5O|eyiCMcMACYH!DOiM8`v@lE3wKPvO*ELB@HrKTNCkzHfsvuEp@FWUL5P8&m9eFj zv8A?wk(Gggl0L+XHu|7k4fC;$K1P^86d)A?c3cV&u^<;WJ1!f2a9IQ@mmmg$$^}|t zXk5_J3I&BxOGpae(cl^lE|NlkB*mktYc#k>3IUQ7kESlF1s4~h!;_kqVyjfHWN)W^ z#^)IW0|Q%&pI=i&I=( z{kHQ_M+OE4$r9Iy66gF}P`jA{+?-2IQ7F$W$xr|_=fWHL#2FYE>O5T>Lp+YZ4RPc; zpum&8#0jH(B$vTO2oAd#KH_bLtY!UKj5D?3WZ^$(P6P) zNO9A)>7Ps%-F5sFSUu(X{Z58w>zdWKW*^CL%b)mi?#5LI3fOh^o>^V!mpQPrbfVov pBj(_JUCx)QWfh;_Qrh_;G3Wkc8L_Jq{2V}?K2KLamvv4FO#nV_^(p`W literal 0 HcmV?d00001 diff --git a/main/icons/battery.h b/main/icons/battery.h new file mode 100644 index 0000000..7de71cf --- /dev/null +++ b/main/icons/battery.h @@ -0,0 +1,46 @@ +#pragma once + +#include "icon.h" + +namespace { +namespace icons { +const Icon<24, 24> battery{{ + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0010 (16) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0020 (32) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0030 (48) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0040 (64) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0050 (80) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0060 (96) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0070 (112) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0080 (128) pixels + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0090 (144) pixels + 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x00A0 (160) pixels + 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0xFFDF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x00B0 (176) pixels + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, // 0x00C0 (192) pixels + 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x00D0 (208) pixels + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x0000, 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x00E0 (224) pixels + 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, // 0x00F0 (240) pixels + 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0100 (256) pixels + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0110 (272) pixels + 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0120 (288) pixels + 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0130 (304) pixels + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0140 (320) pixels + 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0150 (336) pixels + 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0160 (352) pixels + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0170 (368) pixels + 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x0000, // 0x0180 (384) pixels + 0x001F, 0x001F, 0x001F, 0xFFDF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0190 (400) pixels + 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x01A0 (416) pixels + 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, // 0x01B0 (432) pixels + 0x0000, 0x0000, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, // 0x01C0 (448) pixels + 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01D0 (464) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01E0 (480) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01F0 (496) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0200 (512) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0210 (528) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0220 (544) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels + }}; +} +} From 26d91437aea92d5f5382a63955d5f10f9a9bbf68 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Sun, 10 Oct 2021 04:21:31 +0200 Subject: [PATCH 02/16] Added new files --- main/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index b458dde..9805a23 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -23,6 +23,7 @@ set(headers actions/wifiscanaction.h actions/switchprofileaction.h actions/updateswapfrontbackaction.h + battery.h bluetoothmode.h ble_bobby.h bletexthelpers.h @@ -40,6 +41,7 @@ set(headers displays/graphdisplay.h displays/menus/aboutmenu.h displays/menus/accesspointwifisettingsmenu.h + displays/menus/batterymenu.h displays/menus/blesettingsmenu.h displays/menus/bluetoothsettingsmenu.h displays/menus/bmsmenu.h @@ -63,6 +65,7 @@ set(headers displays/menus/presetsmenu.h displays/menus/profilesmenu.h displays/menus/selectmodemenu.h + displays/menus/selectbatterytypemenu.h displays/menus/settingsmenu.h displays/menus/stationwifisettingsmenu.h displays/menus/tempomatmodesettingsmenu.h @@ -95,6 +98,7 @@ set(headers displays/statusdisplay.h displays/updatedisplay.h icons/alert.h + icons/battery.h icons/bluetooth.h icons/bms.h icons/buzzer.h @@ -189,6 +193,7 @@ target_compile_options(${COMPONENT_TARGET} PRIVATE -fstack-reuse=all -fstack-protector-all + -fdiagnostics-color=always -Wno-unused-function -Wno-deprecated-declarations -Wno-missing-field-initializers From f49a8c0a09da1c62921de980b9ffddffe126e2b4 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Sun, 10 Oct 2021 04:22:03 +0200 Subject: [PATCH 03/16] Preparation of battery menu --- main/accessors/settingsaccessors.h | 4 ++ main/battery.h | 40 ++++++++++++ main/displays/menus/batterymenu.h | 57 ++++++++++++++++ .../menus/ledstripselectanimationmenu.h | 18 +++++ main/displays/menus/ledstripselectblinkmenu.h | 25 +++++++ main/displays/menus/mainmenu.h | 4 ++ main/displays/menus/selectbatterytypemenu.h | 65 +++++++++++++++++++ main/ledstrip.h | 1 - main/presets.h | 7 ++ main/settings.h | 13 +++- main/texts.h | 12 ++++ 11 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 main/battery.h create mode 100644 main/displays/menus/batterymenu.h create mode 100644 main/displays/menus/selectbatterytypemenu.h diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index 4bb5e4e..f5c1a83 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -168,6 +168,10 @@ struct AnimationMultiplierAccessor : public RefAccessorSaveSettings { i struct LedstripBrightnessAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.ledstrip.brightness; } }; #endif +// Battery +struct BatterySeriesCellsAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.battery.cellsSeries; } }; +struct BatteryParallelCellsAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.battery.cellsParallel; } }; + struct LockscreenAllowPresetSwitchAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.lockscreen.allowPresetSwitch; } }; template struct LockscreenPinDigitAccessor : public RefAccessorSaveSettings { int8_t &getRef() const override { return settings.lockscreen.pin[index]; } }; diff --git a/main/battery.h b/main/battery.h new file mode 100644 index 0000000..842d3fc --- /dev/null +++ b/main/battery.h @@ -0,0 +1,40 @@ +#pragma once + +// local includes +#include "globals.h" +#include "cpputils.h" + +#define BATTERY_CELLTYPE_22P 0 +#define BATTERY_CELLTYPE_HG2 1 +#define BATTERY_CELLTYPE_MH1 2 +#define BATTERY_CELLTYPE_VTC5 3 + +float battery_percentage = 42.0; + +std::string getBatteryPercentageString() { + std::string output = fmt::format("Battery: {:.1f}%", battery_percentage); + return output; +} + +std::string getBatteryCellTypeString() { + std::string output = ""; + switch (settings.battery.cellType) { + case BATTERY_CELLTYPE_22P: + output = "Cells: 22P"; + break; + case BATTERY_CELLTYPE_HG2: + output = "Cells: HG2"; + break; + case BATTERY_CELLTYPE_MH1: + output = "Cells: MH1"; + break; + case BATTERY_CELLTYPE_VTC5: + output = "Cells: VTC5"; + break; + default: + output = "Unkown cell type"; + break; + } + + return output; +} diff --git a/main/displays/menus/batterymenu.h b/main/displays/menus/batterymenu.h new file mode 100644 index 0000000..92f8c77 --- /dev/null +++ b/main/displays/menus/batterymenu.h @@ -0,0 +1,57 @@ +#pragma once + +// Local includes +#include "menudisplay.h" +#include "utils.h" +#include "menuitem.h" +#include "icons/back.h" +#include "icons/settings.h" +#include "texts.h" +#include "actions/dummyaction.h" +#include "actions/switchscreenaction.h" +#include "mainmenu.h" +#include "battery.h" +#include "selectbatterytypemenu.h" + +// Helper +class currentBatteryStatus : public virtual TextInterface { public: std::string text() const override { return getBatteryPercentageString(); } }; + +using namespace espgui; + +namespace { + class BatteryMenu; + + using BatteryCellSeriesChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + BatterySeriesCellsAccessor, + BackActionInterface>, + SwitchScreenAction + >; + + using BatteryCellParallelChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + BatteryParallelCellsAccessor, + BackActionInterface>, + SwitchScreenAction + >; +} + +namespace { + class BatteryMenu : + public MenuDisplay, + public StaticText, + public BackActionInterface> + { + public: + BatteryMenu() + { + constructMenuItem>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); + } + }; +} // Namespace diff --git a/main/displays/menus/ledstripselectanimationmenu.h b/main/displays/menus/ledstripselectanimationmenu.h index da001ad..6d07fb7 100644 --- a/main/displays/menus/ledstripselectanimationmenu.h +++ b/main/displays/menus/ledstripselectanimationmenu.h @@ -11,6 +11,22 @@ #include "actions/dummyaction.h" #include "actions/ledstripanimationactions.h" #include "actions/switchscreenaction.h" +#include "ledstrip.h" +#include "ledstripdefines.h" + +class currentSelectedAnimationText : public virtual TextInterface { public: std::string text() const override { + switch (animation_type) { + case LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW: + return TEXT_ANIMATION_DEFAULTRAINBOW; + case LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW: + return TEXT_ANIMATION_BETTERRAINBOW; + case LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION: + return TEXT_ANIMATION_SPEEDSYNCANIMATION; + default: + return "Animation Unkown"; + } + }; +}; using namespace espgui; @@ -27,6 +43,8 @@ namespace { public: LedstripSelectAnimationMenu() { + constructMenuItem>(); + constructMenuItem>(); constructMenuItem, LedstripAnimationDefaultRainbowAction>>(); constructMenuItem, LedstripAnimationBetterRainbowAction>>(); constructMenuItem, LedstripAnimationSyncToSpeedAction>>(); diff --git a/main/displays/menus/ledstripselectblinkmenu.h b/main/displays/menus/ledstripselectblinkmenu.h index 336d291..06122e4 100644 --- a/main/displays/menus/ledstripselectblinkmenu.h +++ b/main/displays/menus/ledstripselectblinkmenu.h @@ -11,6 +11,29 @@ #include "actions/dummyaction.h" #include "actions/ledstripblinkactions.h" #include "actions/switchscreenaction.h" +#include "ledstripdefines.h" + +class currentSelectedBlinkAnimationText : public virtual TextInterface { public: std::string text() const override { + switch (blinkAnimation) { + case LEDSTRIP_OVERWRITE_BLINKLEFT: +#ifndef LEDSTRIP_WRONG_DIRECTION + return TEXT_ANIMATION_BLINKLEFT; +#else + return TEXT_ANIMATION_BLINKRIGHT; +#endif + case LEDSTRIP_OVERWRITE_BLINKRIGHT: +#ifndef LEDSTRIP_WRONG_DIRECTION + return TEXT_ANIMATION_BLINKRIGHT; +#else + return TEXT_ANIMATION_BLINKLEFT; +#endif + case LEDSTRIP_OVERWRITE_BLINKBOTH: + return TEXT_ANIMATION_BLINKBOTH; + default: + return TEXT_ANIMATION_BLINKNONE; + } + }; +}; using namespace espgui; @@ -27,6 +50,8 @@ namespace { public: LedstripSelectBlinkMenu() { + constructMenuItem>(); + constructMenuItem>(); constructMenuItem, LedstripAnimationBlinkNoneAction>>(); constructMenuItem, LedstripAnimationBlinkLeftAction>>(); constructMenuItem, LedstripAnimationBlinkRightAction>>(); diff --git a/main/displays/menus/mainmenu.h b/main/displays/menus/mainmenu.h index e5c3020..37d4518 100644 --- a/main/displays/menus/mainmenu.h +++ b/main/displays/menus/mainmenu.h @@ -3,11 +3,13 @@ // local includes #include "menudisplay.h" #include "menuitem.h" +#include "batterymenu.h" #include "actions/switchscreenaction.h" #include "actions/modesettingsaction.h" #include "actions/rebootaction.h" #include "texts.h" #include "icons/back.h" +#include "icons/battery.h" #include "icons/modes.h" #include "icons/presets.h" #include "icons/graph.h" @@ -44,6 +46,7 @@ class GarageDisplay; class UpdateDisplay; class PoweroffDisplay; class DebugMenu; +class BatteryMenu; } // namespace using namespace espgui; @@ -66,6 +69,7 @@ public: if (!simplified) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::presets>>>(); } if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } if (!simplified) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::graph>>>(); } + if (!simplified) { constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::battery>>>(); } #if defined(FEATURE_CAN) && defined(FEATURE_POWERSUPPLY) if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } #endif diff --git a/main/displays/menus/selectbatterytypemenu.h b/main/displays/menus/selectbatterytypemenu.h new file mode 100644 index 0000000..72de417 --- /dev/null +++ b/main/displays/menus/selectbatterytypemenu.h @@ -0,0 +1,65 @@ +#pragma once + +// Local includes +#include "menudisplay.h" +#include "utils.h" +#include "menuitem.h" +#include "icons/back.h" +#include "texts.h" +#include "actions/switchscreenaction.h" +#include "batterymenu.h" +#include "battery.h" +#include "actioninterface.h" + +// Helper +class currentBatteryType : public virtual TextInterface { public: std::string text() const override { return getBatteryCellTypeString(); } }; + +using namespace espgui; + +namespace { + class BatteryTypeMenu; + class BatteryMenu; + + class BatterySelectType22PAction : public virtual ActionInterface + { + public: + void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_22P; saveSettings(); } + }; + + class BatterySelectTypeHG2Action : public virtual ActionInterface + { + public: + void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_HG2; saveSettings(); } + }; + + class BatterySelectTypeMH1Action : public virtual ActionInterface + { + public: + void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_MH1; saveSettings(); } + }; + + class BatterySelectTypeVTC5Action : public virtual ActionInterface + { + public: + void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_VTC5; saveSettings(); } + }; +} + +namespace { + class BatteryTypeMenu : + public MenuDisplay, + public StaticText, + public BackActionInterface> + { + public: + BatteryTypeMenu() + { + constructMenuItem>(); + constructMenuItem, BatterySelectType22PAction>>(); + constructMenuItem, BatterySelectTypeHG2Action>>(); + constructMenuItem, BatterySelectTypeMH1Action>>(); + constructMenuItem, BatterySelectTypeVTC5Action>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); + } + }; +} // Namespace diff --git a/main/ledstrip.h b/main/ledstrip.h index 6f2b430..cdaa50c 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -1,5 +1,4 @@ #pragma once -#define FEATURE_LEDSTRIP #ifdef FEATURE_LEDSTRIP // 3rdparty lib includes #include diff --git a/main/presets.h b/main/presets.h index d75cc85..20a5a37 100644 --- a/main/presets.h +++ b/main/presets.h @@ -253,6 +253,12 @@ constexpr Settings::LockscreenSettings defaultLockscreen { .pin = { 1, 2, 3, 4 } }; +constexpr Settings::Battery defaultBattery { + .cellsSeries = 12, + .cellsParallel = 4, + .cellType = 0 +}; + constexpr Settings defaultSettings { #ifdef FEATURE_BMS .autoConnectBms = false, @@ -278,6 +284,7 @@ constexpr Settings defaultSettings { #ifdef FEATURE_LEDSTRIP .ledstrip = defaultLedstrip, #endif + .battery = defaultBattery, .lockscreen = defaultLockscreen }; diff --git a/main/settings.h b/main/settings.h index 6d92256..7eb693c 100644 --- a/main/settings.h +++ b/main/settings.h @@ -170,6 +170,13 @@ struct Settings int16_t animationMultiplier; uint8_t brightness; } ledstrip; + + struct Battery { + uint8_t cellsSeries; + uint8_t cellsParallel; + uint8_t cellType; + } battery; + #endif struct LockscreenSettings { @@ -275,10 +282,14 @@ void Settings::executeForEveryCommonSetting(T &&callable) callable("ledstvofoff", ledstrip.stvoFrontOffset); callable("ledstvoflen", ledstrip.stvoFrontLength); callable("ledstvoen", ledstrip.stvoFrontEnable); - callable("ledAnimMultiplier", ledstrip.animationMultiplier); + callable("ledAnimMul", ledstrip.animationMultiplier); callable("ledbrightness", ledstrip.brightness); #endif + callable("batteryCS", battery.cellsSeries); + callable("batteryCP", battery.cellsParallel); + callable("batteryType", battery.cellType); + callable("lockAlwPresetSw", lockscreen.allowPresetSwitch); callable("lockscreenPin", lockscreen.pin); } diff --git a/main/texts.h b/main/texts.h index 383719c..eb166c5 100644 --- a/main/texts.h +++ b/main/texts.h @@ -86,6 +86,18 @@ constexpr char TEXT_UPDATE[] = "Update"; constexpr char TEXT_POWEROFF[] = "Poweroff"; constexpr char TEXT_REBOOT[] = "Reboot"; constexpr char TEXT_DEBUG[] = "Debug"; +constexpr char TEXT_BATTERY[] = "Battery"; + +//BatteryMenu +constexpr char TEXT_CELL_SERIES[] = "Cells (Series)"; +constexpr char TEXT_CELL_PARALLEL[] = "Cells (Parallel)"; +constexpr char TEXT_SELECT_CELL_TYPE[] = "Select Cell Type"; +constexpr char TEXT_CELL_TYPE[] = "Cell Type"; +constexpr char TEXT_BATTERY_CALIBRATE[] = "Calibrate Voltages"; +constexpr char TEXT_BATTERY_TYPE_22P[] = "22P cells"; +constexpr char TEXT_BATTERY_TYPE_HG2[] = "HG2 cells"; +constexpr char TEXT_BATTERY_TYPE_MH1[] = "MH1 cells"; +constexpr char TEXT_BATTERY_TYPE_VTC5[] = "VTC5 cells"; //SettingsMenu //constexpr char TEXT_SETTINGS[] = "Settings"; From b3eff312612cbad53eb25ce921139a31895fcf96 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Sun, 10 Oct 2021 21:31:09 +0200 Subject: [PATCH 04/16] Added Wh/km, voltage calibration display and stvo front light switch --- main/CMakeLists.txt | 1 + main/accessors/settingsaccessors.h | 1 + main/displays/calibratevoltagedisplay.h | 34 +++++++++++++++++++++++++ main/displays/menus/batterymenu.h | 14 ++++++++++ main/displays/menus/ledstripmenu.h | 7 ++--- main/displays/statusdisplay.h | 7 +++++ main/presets.h | 3 ++- main/settings.h | 2 ++ main/texts.h | 1 + 9 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 main/displays/calibratevoltagedisplay.h diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 9805a23..6c73bfb 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -37,6 +37,7 @@ set(headers changevaluedisplay_wifi_power_t.h cloud.h debugcolorhelpers.h + displays/calibratevoltagedisplay.h displays/gameoflifedisplay.h displays/graphdisplay.h displays/menus/aboutmenu.h diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index f5c1a83..7ee9167 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -171,6 +171,7 @@ struct LedstripBrightnessAccessor : public RefAccessorSaveSettings { ui // Battery struct BatterySeriesCellsAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.battery.cellsSeries; } }; struct BatteryParallelCellsAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.battery.cellsParallel; } }; +struct BatteryWHperKMAccessor : public RefAccessorSaveSettings { uint16_t &getRef() const override { return settings.battery.watthoursPerKilometer; } }; struct LockscreenAllowPresetSwitchAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.lockscreen.allowPresetSwitch; } }; template diff --git a/main/displays/calibratevoltagedisplay.h b/main/displays/calibratevoltagedisplay.h new file mode 100644 index 0000000..f4bb6c0 --- /dev/null +++ b/main/displays/calibratevoltagedisplay.h @@ -0,0 +1,34 @@ +#pragma once + +// Local includes +#include "menudisplay.h" +#include "utils.h" +#include "menuitem.h" +#include "icons/back.h" +#include "icons/settings.h" +#include "texts.h" +#include "actions/dummyaction.h" +#include "actions/switchscreenaction.h" +#include "battery.h" +#include "menus/batterymenu.h" + +using namespace espgui; + +namespace { + class CalibrateVoltageDisplay; + class BatteryMenu; +} + +namespace { + class CalibrateVoltageDisplay : + public MenuDisplay, + public StaticText, + public BackActionInterface> + { + public: + CalibrateVoltageDisplay() + { + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); + } + }; +} // Namespace diff --git a/main/displays/menus/batterymenu.h b/main/displays/menus/batterymenu.h index 92f8c77..e98a449 100644 --- a/main/displays/menus/batterymenu.h +++ b/main/displays/menus/batterymenu.h @@ -12,6 +12,7 @@ #include "mainmenu.h" #include "battery.h" #include "selectbatterytypemenu.h" +#include "displays/calibratevoltagedisplay.h" // Helper class currentBatteryStatus : public virtual TextInterface { public: std::string text() const override { return getBatteryPercentageString(); } }; @@ -20,6 +21,7 @@ using namespace espgui; namespace { class BatteryMenu; + class CalibrateVoltageDisplay; using BatteryCellSeriesChangeScreen = makeComponent< ChangeValueDisplay, @@ -36,6 +38,14 @@ namespace { BackActionInterface>, SwitchScreenAction >; + + using BatteryWHperKMChangeScreen = makeComponent< + ChangeValueDisplay, + StaticText, + BatteryWHperKMAccessor, + BackActionInterface>, + SwitchScreenAction + >; } namespace { @@ -48,9 +58,13 @@ namespace { BatteryMenu() { constructMenuItem>(); + constructMenuItem>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); + constructMenuItem>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&icons::settings>>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } }; diff --git a/main/displays/menus/ledstripmenu.h b/main/displays/menus/ledstripmenu.h index a85a0fb..bb680ae 100644 --- a/main/displays/menus/ledstripmenu.h +++ b/main/displays/menus/ledstripmenu.h @@ -113,9 +113,10 @@ public: constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableBeepWhenBlinkAccessor>>(); constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableFullBlinkAccessor>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedstripStVOAccessor>>(); - constructMenuItem, SwitchScreenAction>>(); - constructMenuItem, SwitchScreenAction>>(); + if (!simplified) { constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedstripStVOAccessor>>(); } + constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedstripStVOFrontlight>>(); + if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } + if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); diff --git a/main/displays/statusdisplay.h b/main/displays/statusdisplay.h index d7ae2be..71a5e0e 100644 --- a/main/displays/statusdisplay.h +++ b/main/displays/statusdisplay.h @@ -16,6 +16,7 @@ #include "widgets/label.h" #include "widgets/progressbar.h" #include "icons/alert.h" +#include "battery.h" // forward declares namespace { @@ -94,6 +95,8 @@ private: Label m_labelBrems{90, 15}; // 60, 15 ProgressBar m_progressBarBrems{150, 15, 90, 15, 0, 1000}; + Label m_batterypercent{0, 30}; + BoardStatus m_frontStatus{42}; BoardStatus m_backStatus{142}; @@ -126,6 +129,8 @@ void StatusDisplay::initScreen() m_labelBrems.start(); m_progressBarBrems.start(); + m_batterypercent.start(); + m_frontStatus.start(); m_backStatus.start(); @@ -161,6 +166,8 @@ void StatusDisplay::redraw() m_labelBrems.redraw(brems ? fmt::format("{:.2f}", *brems) : "?"); m_progressBarBrems.redraw(brems ? *brems : 0); + m_batterypercent.redraw(getBatteryPercentageString()); + m_frontStatus.redraw(controllers.front); m_backStatus.redraw(controllers.back); diff --git a/main/presets.h b/main/presets.h index 20a5a37..6d7cebd 100644 --- a/main/presets.h +++ b/main/presets.h @@ -256,7 +256,8 @@ constexpr Settings::LockscreenSettings defaultLockscreen { constexpr Settings::Battery defaultBattery { .cellsSeries = 12, .cellsParallel = 4, - .cellType = 0 + .cellType = 0, + .watthoursPerKilometer = 10 }; constexpr Settings defaultSettings { diff --git a/main/settings.h b/main/settings.h index 7eb693c..00ba2d2 100644 --- a/main/settings.h +++ b/main/settings.h @@ -175,6 +175,7 @@ struct Settings uint8_t cellsSeries; uint8_t cellsParallel; uint8_t cellType; + uint16_t watthoursPerKilometer; } battery; #endif @@ -289,6 +290,7 @@ void Settings::executeForEveryCommonSetting(T &&callable) callable("batteryCS", battery.cellsSeries); callable("batteryCP", battery.cellsParallel); callable("batteryType", battery.cellType); + callable("whkm", battery.watthoursPerKilometer); callable("lockAlwPresetSw", lockscreen.allowPresetSwitch); callable("lockscreenPin", lockscreen.pin); diff --git a/main/texts.h b/main/texts.h index eb166c5..5aafe0f 100644 --- a/main/texts.h +++ b/main/texts.h @@ -98,6 +98,7 @@ constexpr char TEXT_BATTERY_TYPE_22P[] = "22P cells"; constexpr char TEXT_BATTERY_TYPE_HG2[] = "HG2 cells"; constexpr char TEXT_BATTERY_TYPE_MH1[] = "MH1 cells"; constexpr char TEXT_BATTERY_TYPE_VTC5[] = "VTC5 cells"; +constexpr char TEXT_BATTERY_WHKM[] = "Wh per km"; //SettingsMenu //constexpr char TEXT_SETTINGS[] = "Settings"; From 9cc69afd5d0717adee0f99d5bff29bcb19cb517d Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Mon, 11 Oct 2021 00:27:44 +0200 Subject: [PATCH 05/16] Voltage Calibration Screen, new battery icon --- icons/battery.png | Bin 7711 -> 251 bytes main/accessors/settingsaccessors.h | 1 + main/displays/calibratevoltagedisplay.h | 39 ++++++++++++- main/icons/battery.h | 74 ++++++++++++------------ main/presets.h | 6 +- main/settings.h | 8 +++ main/texts.h | 8 +++ 7 files changed, 97 insertions(+), 39 deletions(-) diff --git a/icons/battery.png b/icons/battery.png index 385f44f8b4157fc4f31fe5280bec07fcea6c6753..972da02d07cd7200527013da8e3e916ffcbe9202 100644 GIT binary patch delta 163 zcmbPl^P6#k@?<+%ISwvCJ+lFz@i_iAG@9#x0*`n1_x(lRt{N76 z-MH1c?WfR^V@H;8d8Rl`?D4(e%E%ztvd@Hb<5mXC+!U3iNA0?;)%{q@Hl$zI__%dm zOU8RPE+4Z%_Z1tmP)_kJ}Tg#?CS+QWJXWu+;sa$W`>x-;y3@Hq zBAhW-3Rde~$@=&FzW3km`4gPO?3T!Q_so)yuh}?t@|ynn+x|p+KOI2U&z<9 zGrn*8x#8mE`Q_7=&P?&$`SV=%_Q%tA?3_DO{rY)>9hJJrKQn*7xz_4lAOHH<1-vD- z5Ar_W_&u|D|Jgq;t0pMEtGlvy_jRetx2~JJUMX+uc)n=e(l^HMvXhSf4S6!PB!p+K z<;3uZQ%kSToguYra%S)6B%OP)$7Uz4icEW#Y%bez&u_Lx)NRp+3gX6oTHD?SeE4K^ zT8$}bhtH9cq!Wc#?`@c2n|t$e>8DZ+Tb}JvhZEY||NUBeZ*QUQN!8?%eK)yc!Zrzu z+4`1&L3`S{y%pPgY^o%c#&5$k8cm^|xSg~<;pQuca2mSGS! zEM@2^tZ;CD+|;SybxkeVAmx~&=!pY|R!N|d{xOl(dD%rLmrqFY(p()9bXKqW zhxM~5#dksppdwdXdm#Ul+xO`^Ir7y;3EH0nfd}bHN)~D0r6OT^4a%%OOs?WDxUdvx^|6!Kp z-n8w@pByXsEEOKStIfbk-Lazf45iwZ6h(WtZE1`;EGa)_OPJijHOF{Yi&yyBMf$SGKUw2cQtBCz zWv<-+bjFlewYQ90^6#CL^uPIc!OE*^GiU5=R}J5@vH6w7(>?DGR_R9v;w*J`8yed8W-(|+D+RFQ^ z7gSx>Ue6X%|LR#f^Q!&5v)41Py3h8=bit+n?I+B%pH5s>xOwZ!y<57RUj=3#c8&Ua zp(sPMMXXCw)tW2rP3o7PHisWOH@4;8^tReA`gww6m#=PK$iM3$C_SZT@zw_WexZ z@6sEtw%@H!FDq^T7oHYg-}0Y*^J@Ox|IfX7b@<(WV0*IZrVRg&vsZw=wNS6!(&wZ}Hy-gu|{_Vg72 z)^TU8KCPKkY33|sq1gMkX6>q}EnZP8zc|j85_b5}VzWajYQ6HJYWqi$rDacUOQr8y z>Um_<)U-Q4!!)8;_X|sYm9kwv%`4LGoni_rd#lU`{|_z}AFh`FnUr76YW}CKV$I}v zyEwY6AN*pAo%D^*a)mgZ@h2tduTS)TLiB+@iFr=)zm}X{oafwaS;P z-|FrBX5t=EdB1F)d8}2pgN;y_o03*>XU8VKtpYL9EZd#K*hHIM^Dh;f>vvA9GB`Y| zR&Vzl|32%#y+1_rI84mFFP_=1af7|IinBs#gELcS#wuMuTlH<4j_H@|l_SC?Tv^wh z*5Ghv+P(TKYo2|Py(8zix$AzCW4ZW~eGzjeT6#^e4A{HPfAvPMDchDUy?ZU;&YH!S zyW-LcG&}mM4;dVl@ZNFG?~PvI=GK`w^D}luv0q*4_p>0~<;He84?O?A5vg_NS53ey2Vc2glu*a$Lex^&zv6`_z!7LR(c+vy~;6J^7RS zESxRiedL3!##g+x4=jx>>)%-~=->V1jg!t%XPrsrEt9SX6Xz{HKDq|#q3Se zn|puAWe1lgimQGxDq|9!k?E+HG2;<)RdZ6=)R^=I$K-di?w!V!{C~!}D-L^9-A<|Q za$dN@pKGZ{*Mj_((zUK`p&d-+vud0^8rCK64B0p<$3ooM+nuAdnXT#1=M&Z$DpeE0 zci(f>DY31bN>I^e&LB(K)JeBJcF6kRL7%zq8JLYh68C*O`Yg~y+eMsXAc>3_D`Bp=J{(@OVs>K51~~%@BXyq zKl+JiBvJ>gJs=s0pfF z#vG#k#rR9oi~s#hey5v7>OK1z0_q>loG-KZR(#Nt@Z%aEd!*C7T|}~19u4;vd71F@ zYPz?GvZ2hWi$a;|uQ~+mc6n@-w%Rz!q~y}$ix*_0HBCysJl}G|`b_Mib7luFsHM@Gr_+upuDZH%)%^>9wuFB97&2?g zekb-Fzak^|2mCF+aJBqReR@^t_Q#(%esib&IIu>p$?r+8VrvsU75!DE zlUb*+na=5DKU?W6s*rc>V&#?Iqch9)Yc>Q0l<#JWQn-|Fz9idObn0ID4WHk;#%3;Z zO>pnOk`%kPswBI`$%1v4nzZ1Vg?zg@oI^x!aX;^J3|3subTzc9or!~$EA51-@}lQc z9(ZJ`7|C;h*g*ZOPW$6BrL@^6Dz%s1D%cYk?+eSXNE{F1Mq-H!ft3!i?qKD*>=+pUVz zFJA4vyYRYO`1`kfd(C!L<(I#>{Y>Bs|KxSa9osCo|{fxlxmtbt@wSGQ$W%6dslr_a#vgt+2fRd?XbXM zr9E>buH`Qk$u9Ku*mU{ap+9S`R`$2lKl-+8hvi*W+m4xIyFaEYipRyaW!Gid zZoYSUXSrA$_l^hZTQAmczuUigz5cT5NB?I3)%$Ea1trJ;(9a<>rz5>zVAKG;=Pl%2cFA|=B*Qb4ruik8Sirxl`6 zr3O2{aL+PP(bel~%076o|LCgb?#=7?)-@^oV0`rK*^(DZs{iygw{(1butWa+JKJ~n z7@ZcMF}4 zT+99a`^L7}>J9%TcU-#t&x?7+PnEs*t{rkeaKNmf@b0xKwhxNfCF+b)g3DCweHG`k z-#h0U zT&uidE0D0hk^)#sNw%$0gl~X?bAC~(f{C7qo`J4wMP`|ik{y?VO;JjkRgjAt)QF;# zG+U*Nl9B=|ef{$Ca=mh6z5JqdeM3u2OML?)eIp~?qLeh<;>x^|#0uTKVr7sK5Hnm- zi<65o3raHc^Atd4CMM;Vme?vOaVaP$Kn<_RE%5b)8=qGU4Ta?VT>Xl~0)0b01O41w zePkWQC9Y*9_;nPAR2HP_2c;J0mlh?bx|XHpl_(<{k&+D8Ur<_<1NKfzvVLk#YHn&? zNwL16o*{~r?w-B@a2=o^NYBhI0PCvAEkIFOl9`4GEEL~>WWe4*c1T5T0o+^^)iA$< z6@$ab$|XO!6y!Wl7h5He{Z=XY$(bouU}maOTB<=}vXO2|T8gQziK$_-Zla}SlCDu& zQi^4=silcQni-N&o_WP3iFwJXAfqaB3-mHGQ>@I=ObsnlOe}TNlFiI?O$<_ubQ8_Z z4Rlk|%!~|-lTD0`EsT(i@Gr_t&&*5AL3S0$sFchUE5jrMa|;ubG~MJxBU4?IBojm3 z#6*)c-BinzMAOt%qoh`2X13e=PunZ_#to(~IQ}ap^LFv?1$q+1Fky~KpT$Gwvl3x^(pPyr^1ag3ak)ELe zIC(4BKqAE>v$!O`sL~FcqQUtlIJFSMgJgl6Ot6%K0yx=PB_=~GDNZa)O#xe^0Fz42 zNX$!5O|eyiCMcMACYH!DOiM8`v@lE3wKPvO*ELB@HrKTNCkzHfsvuEp@FWUL5P8&m9eFj zv8A?wk(Gggl0L+XHu|7k4fC;$K1P^86d)A?c3cV&u^<;WJ1!f2a9IQ@mmmg$$^}|t zXk5_J3I&BxOGpae(cl^lE|NlkB*mktYc#k>3IUQ7kESlF1s4~h!;_kqVyjfHWN)W^ z#^)IW0|Q%&pI=i&I=( z{kHQ_M+OE4$r9Iy66gF}P`jA{+?-2IQ7F$W$xr|_=fWHL#2FYE>O5T>Lp+YZ4RPc; zpum&8#0jH(B$vTO2oAd#KH_bLtY!UKj5D?3WZ^$(P6P) zNO9A)>7Ps%-F5sFSUu(X{Z58w>zdWKW*^CL%b)mi?#5LI3fOh^o>^V!mpQPrbfVov pBj(_JUCx)QWfh;_Qrh_;G3Wkc8L_Jq{2V}?K2KLamvv4FO#nV_^(p`W diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index 7ee9167..ae7f854 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -173,6 +173,7 @@ struct BatterySeriesCellsAccessor : public RefAccessorSaveSettings { ui struct BatteryParallelCellsAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.battery.cellsParallel; } }; struct BatteryWHperKMAccessor : public RefAccessorSaveSettings { uint16_t &getRef() const override { return settings.battery.watthoursPerKilometer; } }; + struct LockscreenAllowPresetSwitchAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.lockscreen.allowPresetSwitch; } }; template struct LockscreenPinDigitAccessor : public RefAccessorSaveSettings { int8_t &getRef() const override { return settings.lockscreen.pin[index]; } }; diff --git a/main/displays/calibratevoltagedisplay.h b/main/displays/calibratevoltagedisplay.h index f4bb6c0..891b0f8 100644 --- a/main/displays/calibratevoltagedisplay.h +++ b/main/displays/calibratevoltagedisplay.h @@ -11,12 +11,39 @@ #include "actions/switchscreenaction.h" #include "battery.h" #include "menus/batterymenu.h" +#include "widgets/label.h" +#include "globals.h" using namespace espgui; namespace { class CalibrateVoltageDisplay; class BatteryMenu; + + class Save30VCalibrationAction : public virtual ActionInterface + { + public: + void triggered() override { + settings.battery.front30VoltCalibration = controllers.front.feedback.batVoltage; + settings.battery.back30VoltCalibration = controllers.back.feedback.batVoltage; + saveSettings(); + } + }; + + class Save50VCalibrationAction : public virtual ActionInterface + { + public: + void triggered() override { + settings.battery.front50VoltCalibration = controllers.front.feedback.batVoltage; + settings.battery.back50VoltCalibration = controllers.back.feedback.batVoltage; + saveSettings(); + } + }; + + class BatteryVoltageCalibrationFront30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Front: {:.2f}V", fixBatVoltage(settings.battery.front30VoltCalibration)); } }; + class BatteryVoltageCalibrationBack30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Back: {:.2f}V", fixBatVoltage(settings.battery.back30VoltCalibration)); } }; + class BatteryVoltageCalibrationFront50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Front: {:.2f}V", fixBatVoltage(settings.battery.front50VoltCalibration)); } }; + class BatteryVoltageCalibrationBack50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Back: {:.2f}V", fixBatVoltage(settings.battery.back50VoltCalibration)); } }; } namespace { @@ -28,7 +55,17 @@ namespace { public: CalibrateVoltageDisplay() { - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); + constructMenuItem, Save30VCalibrationAction>>(); + constructMenuItem, Save50VCalibrationAction>>(); + + constructMenuItem>(); + + constructMenuItem>(); + constructMenuItem>(); + constructMenuItem>(); + constructMenuItem>(); + + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } }; } // Namespace diff --git a/main/icons/battery.h b/main/icons/battery.h index 7de71cf..315c4ac 100644 --- a/main/icons/battery.h +++ b/main/icons/battery.h @@ -5,42 +5,42 @@ namespace { namespace icons { const Icon<24, 24> battery{{ - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0010 (16) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0020 (32) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0030 (48) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0040 (64) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0050 (80) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0060 (96) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0070 (112) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0080 (128) pixels - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0090 (144) pixels - 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x00A0 (160) pixels - 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0xFFDF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x00B0 (176) pixels - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, // 0x00C0 (192) pixels - 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x00D0 (208) pixels - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x0000, 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x00E0 (224) pixels - 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, // 0x00F0 (240) pixels - 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0100 (256) pixels - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0110 (272) pixels - 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0120 (288) pixels - 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0130 (304) pixels - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0140 (320) pixels - 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0150 (336) pixels - 0x001F, 0x001F, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0160 (352) pixels - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0170 (368) pixels - 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x0000, // 0x0180 (384) pixels - 0x001F, 0x001F, 0x001F, 0xFFDF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0190 (400) pixels - 0xFFFF, 0xFFFF, 0xFFFF, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x01A0 (416) pixels - 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, // 0x01B0 (432) pixels - 0x0000, 0x0000, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, // 0x01C0 (448) pixels - 0xF7BF, 0xF7BF, 0xF7BF, 0xF7BF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01D0 (464) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01E0 (480) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01F0 (496) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0200 (512) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0210 (528) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0220 (544) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels - }}; +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0010 (16) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0020 (32) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0030 (48) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0040 (64) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0050 (80) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0060 (96) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0070 (112) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0080 (128) pixels +0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, // 0x0090 (144) pixels +0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x00A0 (160) pixels +0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00B0 (176) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, // 0x00C0 (192) pixels +0x001F, 0x001F, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00D0 (208) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x0000, 0x001F, 0x001F, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x00E0 (224) pixels +0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, // 0x00F0 (240) pixels +0x001F, 0x001F, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0100 (256) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0110 (272) pixels +0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0120 (288) pixels +0x001F, 0x001F, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0130 (304) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0140 (320) pixels +0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0150 (336) pixels +0x001F, 0x001F, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, // 0x0160 (352) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, // 0x0170 (368) pixels +0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x0000, // 0x0180 (384) pixels +0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0190 (400) pixels +0x0000, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x01A0 (416) pixels +0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, // 0x01B0 (432) pixels +0x0000, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, // 0x01C0 (448) pixels +0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01D0 (464) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01E0 (480) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x01F0 (496) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0200 (512) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0210 (528) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0220 (544) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels +0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels +}}; } } diff --git a/main/presets.h b/main/presets.h index 6d7cebd..17e2256 100644 --- a/main/presets.h +++ b/main/presets.h @@ -257,7 +257,11 @@ constexpr Settings::Battery defaultBattery { .cellsSeries = 12, .cellsParallel = 4, .cellType = 0, - .watthoursPerKilometer = 10 + .watthoursPerKilometer = 20, + .front30VoltCalibration = 30, + .back30VoltCalibration = 30, + .front50VoltCalibration = 50, + .back50VoltCalibration = 50 }; constexpr Settings defaultSettings { diff --git a/main/settings.h b/main/settings.h index 00ba2d2..ca2a0b0 100644 --- a/main/settings.h +++ b/main/settings.h @@ -176,6 +176,10 @@ struct Settings uint8_t cellsParallel; uint8_t cellType; uint16_t watthoursPerKilometer; + int16_t front30VoltCalibration; + int16_t back30VoltCalibration; + int16_t front50VoltCalibration; + int16_t back50VoltCalibration; } battery; #endif @@ -291,6 +295,10 @@ void Settings::executeForEveryCommonSetting(T &&callable) callable("batteryCP", battery.cellsParallel); callable("batteryType", battery.cellType); callable("whkm", battery.watthoursPerKilometer); + callable("batF30VCal", battery.front30VoltCalibration); + callable("batB30VCal", battery.back30VoltCalibration); + callable("batF50VCal", battery.front50VoltCalibration); + callable("batB50VCal", battery.back50VoltCalibration); callable("lockAlwPresetSw", lockscreen.allowPresetSwitch); callable("lockscreenPin", lockscreen.pin); diff --git a/main/texts.h b/main/texts.h index 5aafe0f..1258fc3 100644 --- a/main/texts.h +++ b/main/texts.h @@ -100,6 +100,14 @@ constexpr char TEXT_BATTERY_TYPE_MH1[] = "MH1 cells"; constexpr char TEXT_BATTERY_TYPE_VTC5[] = "VTC5 cells"; constexpr char TEXT_BATTERY_WHKM[] = "Wh per km"; +//CalibrateVoltageDisplay +constexpr char TEXT_VOLTAGECALIBRATION_30V[] = "Calibrate 30.0V"; +constexpr char TEXT_VOLTAGECALIBRATION_50V[] = "Calibrate 50.0V"; +constexpr char TEXT_VOLTAGECALIBRATION_VALUE_30_FRONT[] = "30V Front"; +constexpr char TEXT_VOLTAGECALIBRATION_VALUE_30_BACK[] = "30V Back"; +constexpr char TEXT_VOLTAGECALIBRATION_VALUE_50_FRONT[] = "50V Front"; +constexpr char TEXT_VOLTAGECALIBRATION_VALUE_50_BACK[] = "50V Back"; + //SettingsMenu //constexpr char TEXT_SETTINGS[] = "Settings"; constexpr char TEXT_BACKLIGHT[] = "Backlight"; From 49138c64f1b661f23fe68921f065463481efb3ab Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Mon, 11 Oct 2021 21:41:57 +0200 Subject: [PATCH 06/16] Added option to apply calibration, preparations for calibration implementation --- main/accessors/settingsaccessors.h | 1 + main/displays/calibratevoltagedisplay.h | 3 ++- main/presets.h | 3 ++- main/settings.h | 2 ++ main/texts.h | 1 + main/utils.h | 10 ++++++++++ 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index ae7f854..46ad53a 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -172,6 +172,7 @@ struct LedstripBrightnessAccessor : public RefAccessorSaveSettings { ui struct BatterySeriesCellsAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.battery.cellsSeries; } }; struct BatteryParallelCellsAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.battery.cellsParallel; } }; struct BatteryWHperKMAccessor : public RefAccessorSaveSettings { uint16_t &getRef() const override { return settings.battery.watthoursPerKilometer; } }; +struct BatteryApplyCalibrationAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.battery.applyCalibration; } }; struct LockscreenAllowPresetSwitchAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.lockscreen.allowPresetSwitch; } }; diff --git a/main/displays/calibratevoltagedisplay.h b/main/displays/calibratevoltagedisplay.h index 891b0f8..025e88d 100644 --- a/main/displays/calibratevoltagedisplay.h +++ b/main/displays/calibratevoltagedisplay.h @@ -57,6 +57,8 @@ namespace { { constructMenuItem, Save30VCalibrationAction>>(); constructMenuItem, Save50VCalibrationAction>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, BatteryApplyCalibrationAccessor>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); constructMenuItem>(); @@ -65,7 +67,6 @@ namespace { constructMenuItem>(); constructMenuItem>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } }; } // Namespace diff --git a/main/presets.h b/main/presets.h index 17e2256..5320ad6 100644 --- a/main/presets.h +++ b/main/presets.h @@ -261,7 +261,8 @@ constexpr Settings::Battery defaultBattery { .front30VoltCalibration = 30, .back30VoltCalibration = 30, .front50VoltCalibration = 50, - .back50VoltCalibration = 50 + .back50VoltCalibration = 50, + .applyCalibration = false }; constexpr Settings defaultSettings { diff --git a/main/settings.h b/main/settings.h index ca2a0b0..1b88a38 100644 --- a/main/settings.h +++ b/main/settings.h @@ -180,6 +180,7 @@ struct Settings int16_t back30VoltCalibration; int16_t front50VoltCalibration; int16_t back50VoltCalibration; + bool applyCalibration; } battery; #endif @@ -299,6 +300,7 @@ void Settings::executeForEveryCommonSetting(T &&callable) callable("batB30VCal", battery.back30VoltCalibration); callable("batF50VCal", battery.front50VoltCalibration); callable("batB50VCal", battery.back50VoltCalibration); + callable("applyBatCal", battery.applyCalibration); callable("lockAlwPresetSw", lockscreen.allowPresetSwitch); callable("lockscreenPin", lockscreen.pin); diff --git a/main/texts.h b/main/texts.h index 1258fc3..e1eae2d 100644 --- a/main/texts.h +++ b/main/texts.h @@ -99,6 +99,7 @@ constexpr char TEXT_BATTERY_TYPE_HG2[] = "HG2 cells"; constexpr char TEXT_BATTERY_TYPE_MH1[] = "MH1 cells"; constexpr char TEXT_BATTERY_TYPE_VTC5[] = "VTC5 cells"; constexpr char TEXT_BATTERY_WHKM[] = "Wh per km"; +constexpr char TEXT_BATTERY_APPLYCALIB[] = "Apply calibration"; //CalibrateVoltageDisplay constexpr char TEXT_VOLTAGECALIBRATION_30V[] = "Calibrate 30.0V"; diff --git a/main/utils.h b/main/utils.h index e032f4e..98a6c0f 100644 --- a/main/utils.h +++ b/main/utils.h @@ -64,6 +64,16 @@ float fixBatVoltage(int16_t value) return value/100.; } +float fixFrontBatVoltage(int16_t value) +{ + float frontVoltage = fixBatVoltage(value); + // settings.battery.front30VoltCalibration // Front 30.0V + // settings.battery.back30VoltCalibration // Back 30.0V + // settings.battery.front50VoltCalibration // Front 50.0V + // settings.battery.back50VoltCalibration // Back 50.0V + return frontVoltage; +} + float fixBoardTemp(int16_t value) { return value/10.; From abf92f439efb76407baa776c12497981b8b790a5 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Mon, 11 Oct 2021 22:52:53 +0200 Subject: [PATCH 07/16] Fixed batVoltage value --- main/displays/calibratevoltagedisplay.h | 30 ++++++++++++++++++------- main/texts.h | 1 + main/utils.h | 12 ++++++---- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/main/displays/calibratevoltagedisplay.h b/main/displays/calibratevoltagedisplay.h index 025e88d..9c10ab1 100644 --- a/main/displays/calibratevoltagedisplay.h +++ b/main/displays/calibratevoltagedisplay.h @@ -40,10 +40,23 @@ namespace { } }; + class ResetCalibrationAction : public virtual ActionInterface + { + public: + void triggered() override { + settings.battery.front30VoltCalibration = 3000; + settings.battery.back30VoltCalibration = 3000; + settings.battery.front50VoltCalibration = 5000; + settings.battery.back50VoltCalibration = 5000; + saveSettings(); + } + }; + class BatteryVoltageCalibrationFront30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Front: {:.2f}V", fixBatVoltage(settings.battery.front30VoltCalibration)); } }; class BatteryVoltageCalibrationBack30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Back: {:.2f}V", fixBatVoltage(settings.battery.back30VoltCalibration)); } }; class BatteryVoltageCalibrationFront50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Front: {:.2f}V", fixBatVoltage(settings.battery.front50VoltCalibration)); } }; class BatteryVoltageCalibrationBack50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Back: {:.2f}V", fixBatVoltage(settings.battery.back50VoltCalibration)); } }; + class BatteryVoltageCalibratedText : public virtual TextInterface { public: std::string text() const override { if (settings.battery.applyCalibration) return fmt::format("F{:.2f}V B{:.2f}", fixFrontBatVoltage(controllers.front.feedback.batVoltage), fixFrontBatVoltage(controllers.back.feedback.batVoltage)); else return "Not activated"; } }; } namespace { @@ -55,18 +68,19 @@ namespace { public: CalibrateVoltageDisplay() { - constructMenuItem, Save30VCalibrationAction>>(); - constructMenuItem, Save50VCalibrationAction>>(); - constructMenuItem, ToggleBoolAction, CheckboxIcon, BatteryApplyCalibrationAccessor>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); + constructMenuItem, Save30VCalibrationAction>>(); + constructMenuItem, Save50VCalibrationAction>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, BatteryApplyCalibrationAccessor>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - constructMenuItem>(); + constructMenuItem>(); - constructMenuItem>(); + constructMenuItem>(); constructMenuItem>(); - constructMenuItem>(); + constructMenuItem>(); constructMenuItem>(); - + constructMenuItem>(); + constructMenuItem, ResetCalibrationAction>>(); } }; } // Namespace diff --git a/main/texts.h b/main/texts.h index e1eae2d..a452db2 100644 --- a/main/texts.h +++ b/main/texts.h @@ -100,6 +100,7 @@ constexpr char TEXT_BATTERY_TYPE_MH1[] = "MH1 cells"; constexpr char TEXT_BATTERY_TYPE_VTC5[] = "VTC5 cells"; constexpr char TEXT_BATTERY_WHKM[] = "Wh per km"; constexpr char TEXT_BATTERY_APPLYCALIB[] = "Apply calibration"; +constexpr char TEXT_VOLTAGECALIBRATION_RESET[] = "Reset calibration"; //CalibrateVoltageDisplay constexpr char TEXT_VOLTAGECALIBRATION_30V[] = "Calibrate 30.0V"; diff --git a/main/utils.h b/main/utils.h index 98a6c0f..742012c 100644 --- a/main/utils.h +++ b/main/utils.h @@ -67,13 +67,17 @@ float fixBatVoltage(int16_t value) float fixFrontBatVoltage(int16_t value) { float frontVoltage = fixBatVoltage(value); - // settings.battery.front30VoltCalibration // Front 30.0V - // settings.battery.back30VoltCalibration // Back 30.0V - // settings.battery.front50VoltCalibration // Front 50.0V - // settings.battery.back50VoltCalibration // Back 50.0V + frontVoltage = ((frontVoltage - fixBatVoltage(settings.battery.front30VoltCalibration)) * (20.f / (fixBatVoltage(settings.battery.front50VoltCalibration) - fixBatVoltage(settings.battery.front30VoltCalibration))) + 30.f); return frontVoltage; } +float fixBackBatVoltage(int16_t value) +{ + float backVoltage = fixBatVoltage(value); + backVoltage = ((backVoltage - fixBatVoltage(settings.battery.back30VoltCalibration)) * (20.f / (fixBatVoltage(settings.battery.back50VoltCalibration) - fixBatVoltage(settings.battery.back30VoltCalibration))) + 30.f); + return backVoltage; +} + float fixBoardTemp(int16_t value) { return value/10.; From 63c6322792d620f70f1e1bf3ad3edb4fac7509b5 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Tue, 12 Oct 2021 16:55:42 +0200 Subject: [PATCH 08/16] Moved calibration in controller object (#111) --- main/can.h | 7 +++++++ main/controller.h | 4 ++++ main/displays/statusdisplay.h | 9 ++++++++- main/utils.h | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/main/can.h b/main/can.h index 8a6bc9b..6bfa824 100644 --- a/main/can.h +++ b/main/can.h @@ -22,6 +22,11 @@ #include CAN_PLUGIN #endif +namespace { + float fixFrontBatVoltage(int16_t value); + float fixBackBatVoltage(int16_t value); +} + namespace can { namespace { @@ -252,6 +257,7 @@ bool tryParseCanInput() front.lastCanFeedback = espchrono::millis_clock::now(); front.feedbackValid = true; + front.calibrated.batVoltage = fixFrontBatVoltage(front.feedback.batVoltage); return true; } else @@ -264,6 +270,7 @@ bool tryParseCanInput() { back.lastCanFeedback = espchrono::millis_clock::now(); back.feedbackValid = true; + back.calibrated.batVoltage = fixBackBatVoltage(back.feedback.batVoltage); return true; } else diff --git a/main/controller.h b/main/controller.h index ca2772a..148d74f 100644 --- a/main/controller.h +++ b/main/controller.h @@ -52,8 +52,12 @@ struct Controller { bool feedbackValid{}; bobbycar::protocol::serial::Feedback feedback{}; + #ifdef FEATURE_SERIAL FeedbackParser parser{serial, feedbackValid, feedback}; #endif + struct Calibrated { + float batVoltage; + } calibrated; }; } diff --git a/main/displays/statusdisplay.h b/main/displays/statusdisplay.h index 71a5e0e..fffc344 100644 --- a/main/displays/statusdisplay.h +++ b/main/displays/statusdisplay.h @@ -297,7 +297,14 @@ void StatusDisplay::BoardStatus::redraw(const Controller &controller) if (controller.feedbackValid) { - m_labelVoltage.redraw(fmt::format("{:.2f}V", fixBatVoltage(controller.feedback.batVoltage))); + if (settings.battery.applyCalibration) + { + m_labelVoltage.redraw(fmt::format("{:.2f}V", controller.calibrated.batVoltage)); + } + else + { + m_labelVoltage.redraw(fmt::format("{:.2f}V", fixBatVoltage(controller.feedback.batVoltage))); + } m_labelTemperature.redraw(fmt::format("{:.2f}C", fixBoardTemp(controller.feedback.boardTemp))); m_leftMotor.redraw(controller.feedback.left); m_rightMotor.redraw(controller.feedback.right); diff --git a/main/utils.h b/main/utils.h index 742012c..c970cb8 100644 --- a/main/utils.h +++ b/main/utils.h @@ -67,6 +67,7 @@ float fixBatVoltage(int16_t value) float fixFrontBatVoltage(int16_t value) { float frontVoltage = fixBatVoltage(value); + if (!settings.battery.applyCalibration) return frontVoltage; frontVoltage = ((frontVoltage - fixBatVoltage(settings.battery.front30VoltCalibration)) * (20.f / (fixBatVoltage(settings.battery.front50VoltCalibration) - fixBatVoltage(settings.battery.front30VoltCalibration))) + 30.f); return frontVoltage; } @@ -74,6 +75,7 @@ float fixFrontBatVoltage(int16_t value) float fixBackBatVoltage(int16_t value) { float backVoltage = fixBatVoltage(value); + if (!settings.battery.applyCalibration) return backVoltage; backVoltage = ((backVoltage - fixBatVoltage(settings.battery.back30VoltCalibration)) * (20.f / (fixBatVoltage(settings.battery.back50VoltCalibration) - fixBatVoltage(settings.battery.back30VoltCalibration))) + 30.f); return backVoltage; } From acb56100d622068c76736811118de8c84f1c2d3e Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Wed, 13 Oct 2021 10:13:40 +0200 Subject: [PATCH 09/16] Cleanups --- main/battery.h | 45 ++++++++++--------------- main/ble_bobby.h | 4 +-- main/can.h | 7 ---- main/cloud.h | 2 +- main/controller.h | 24 +++++++++++-- main/debugtexthelpers.h | 2 +- main/displays/calibratevoltagedisplay.h | 10 +++--- main/displays/metersdisplay.h | 4 +-- main/displays/statusdisplay.h | 9 +---- main/presets.h | 2 +- main/statistics.h | 4 +-- main/utils.h | 21 ------------ 12 files changed, 54 insertions(+), 80 deletions(-) diff --git a/main/battery.h b/main/battery.h index 842d3fc..e277a1e 100644 --- a/main/battery.h +++ b/main/battery.h @@ -1,40 +1,31 @@ #pragma once +// 3rdparty lib includes +#include +#include + // local includes #include "globals.h" #include "cpputils.h" -#define BATTERY_CELLTYPE_22P 0 -#define BATTERY_CELLTYPE_HG2 1 -#define BATTERY_CELLTYPE_MH1 2 -#define BATTERY_CELLTYPE_VTC5 3 +#define BatteryCellTypeValues(x) \ + x(_22P) \ + x(HG2) \ + x(MH1) \ + x(VTC5) +DECLARE_TYPESAFE_ENUM(BatteryCellType, : uint8_t, BatteryCellTypeValues) -float battery_percentage = 42.0; +namespace { +float battery_percentage = 42.f; -std::string getBatteryPercentageString() { +std::string getBatteryPercentageString() +{ std::string output = fmt::format("Battery: {:.1f}%", battery_percentage); return output; } -std::string getBatteryCellTypeString() { - std::string output = ""; - switch (settings.battery.cellType) { - case BATTERY_CELLTYPE_22P: - output = "Cells: 22P"; - break; - case BATTERY_CELLTYPE_HG2: - output = "Cells: HG2"; - break; - case BATTERY_CELLTYPE_MH1: - output = "Cells: MH1"; - break; - case BATTERY_CELLTYPE_VTC5: - output = "Cells: VTC5"; - break; - default: - output = "Unkown cell type"; - break; - } - - return output; +std::string getBatteryCellTypeString() +{ + return fmt::format("Cells: {}", toString(BatteryCellType(settings.battery.cellType))); } +} // namespace diff --git a/main/ble_bobby.h b/main/ble_bobby.h index 218868d..4bcd3ad 100644 --- a/main/ble_bobby.h +++ b/main/ble_bobby.h @@ -81,11 +81,11 @@ void handleBle() { auto arr = doc.createNestedArray("v"); if (controllers.front.feedbackValid) - arr.add(fixBatVoltage(controllers.front.feedback.batVoltage)); + arr.add(controllers.front.getCalibratedVoltage()); else arr.add(nullptr); if (controllers.back.feedbackValid) - arr.add(fixBatVoltage(controllers.back.feedback.batVoltage)); + arr.add(controllers.back.getCalibratedVoltage()); else arr.add(nullptr); } diff --git a/main/can.h b/main/can.h index 6bfa824..8a6bc9b 100644 --- a/main/can.h +++ b/main/can.h @@ -22,11 +22,6 @@ #include CAN_PLUGIN #endif -namespace { - float fixFrontBatVoltage(int16_t value); - float fixBackBatVoltage(int16_t value); -} - namespace can { namespace { @@ -257,7 +252,6 @@ bool tryParseCanInput() front.lastCanFeedback = espchrono::millis_clock::now(); front.feedbackValid = true; - front.calibrated.batVoltage = fixFrontBatVoltage(front.feedback.batVoltage); return true; } else @@ -270,7 +264,6 @@ bool tryParseCanInput() { back.lastCanFeedback = espchrono::millis_clock::now(); back.feedbackValid = true; - back.calibrated.batVoltage = fixBackBatVoltage(back.feedback.batVoltage); return true; } else diff --git a/main/cloud.h b/main/cloud.h index 0a423da..eac0e09 100644 --- a/main/cloud.h +++ b/main/cloud.h @@ -109,7 +109,7 @@ void cloudCollect() } cloudBuffer += fmt::format(",[{:.02f},{:.02f}", - fixBatVoltage(controller.feedback.batVoltage), + controller.getCalibratedVoltage(), fixBoardTemp(controller.feedback.boardTemp)); constexpr const auto addMotor = [](const bobbycar::protocol::serial::MotorState &command, diff --git a/main/controller.h b/main/controller.h index 148d74f..dbd2c59 100644 --- a/main/controller.h +++ b/main/controller.h @@ -56,8 +56,26 @@ struct Controller { #ifdef FEATURE_SERIAL FeedbackParser parser{serial, feedbackValid, feedback}; #endif - struct Calibrated { - float batVoltage; - } calibrated; + + float getCalibratedVoltage() const + { + return 0.f; + } + +// float fixFrontBatVoltage(int16_t value) +// { +// float frontVoltage = value; +// if (settings.battery.applyCalibration) +// frontVoltage = ((frontVoltage - float(settings.battery.front30VoltCalibration)) * (20.f / (float(settings.battery.front50VoltCalibration) - float(settings.battery.front30VoltCalibration))) + 30.f); +// return frontVoltage; +// } + +// float fixBackBatVoltage(int16_t value) +// { +// float backVoltage = value; +// if (settings.battery.applyCalibration) +// backVoltage = ((backVoltage - float(settings.battery.back30VoltCalibration)) * (20.f / (float(settings.battery.back50VoltCalibration) - float(settings.battery.back30VoltCalibration))) + 30.f); +// return backVoltage; +// } }; } diff --git a/main/debugtexthelpers.h b/main/debugtexthelpers.h index b553089..bdaa1a2 100644 --- a/main/debugtexthelpers.h +++ b/main/debugtexthelpers.h @@ -48,7 +48,7 @@ public: using RightCommand = CommandTexts; //struct BatVoltageText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.batVoltage); return line; } }; - struct BatVoltageFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}V", fixBatVoltage(controller::get().feedback.batVoltage)); return line; } }; + struct BatVoltageFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}V", controller::get().getCalibratedVoltage()); return line; } }; //struct BoardTempText : public virtual TextInterface { public: std::string text() const override { std::string line{"boardTemp: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.boardTemp); return line; } }; struct BoardTempFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"boardTemp: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}C", fixBoardTemp(controller::get().feedback.boardTemp)); return line; } }; struct TimeoutCntSerialText : public virtual TextInterface { public: std::string text() const override { std::string line{"timeoutCntSerial: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.timeoutCntSerial); return line; } }; diff --git a/main/displays/calibratevoltagedisplay.h b/main/displays/calibratevoltagedisplay.h index 9c10ab1..4cb5e26 100644 --- a/main/displays/calibratevoltagedisplay.h +++ b/main/displays/calibratevoltagedisplay.h @@ -52,11 +52,11 @@ namespace { } }; - class BatteryVoltageCalibrationFront30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Front: {:.2f}V", fixBatVoltage(settings.battery.front30VoltCalibration)); } }; - class BatteryVoltageCalibrationBack30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Back: {:.2f}V", fixBatVoltage(settings.battery.back30VoltCalibration)); } }; - class BatteryVoltageCalibrationFront50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Front: {:.2f}V", fixBatVoltage(settings.battery.front50VoltCalibration)); } }; - class BatteryVoltageCalibrationBack50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Back: {:.2f}V", fixBatVoltage(settings.battery.back50VoltCalibration)); } }; - class BatteryVoltageCalibratedText : public virtual TextInterface { public: std::string text() const override { if (settings.battery.applyCalibration) return fmt::format("F{:.2f}V B{:.2f}", fixFrontBatVoltage(controllers.front.feedback.batVoltage), fixFrontBatVoltage(controllers.back.feedback.batVoltage)); else return "Not activated"; } }; + class BatteryVoltageCalibrationFront30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Front: {}", settings.battery.front30VoltCalibration); } }; + class BatteryVoltageCalibrationBack30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Back: {}", settings.battery.back30VoltCalibration); } }; + class BatteryVoltageCalibrationFront50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Front: {}", settings.battery.front50VoltCalibration); } }; + class BatteryVoltageCalibrationBack50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Back: {}", settings.battery.back50VoltCalibration); } }; + class BatteryVoltageCalibratedText : public virtual TextInterface { public: std::string text() const override { if (settings.battery.applyCalibration) return fmt::format("F{:.2f}V B{:.2f}", controllers.front.getCalibratedVoltage(), controllers.back.getCalibratedVoltage()); else return "Not activated"; } }; } namespace { diff --git a/main/displays/metersdisplay.h b/main/displays/metersdisplay.h index fa8875a..7443ffc 100644 --- a/main/displays/metersdisplay.h +++ b/main/displays/metersdisplay.h @@ -74,8 +74,8 @@ void MetersDisplay::redraw() tft.setTextFont(2); m_sumCurrentLabel.redraw(std::to_string(sumCurrent) + 'A'); - meters[0].redraw(fixBatVoltage(controllers.front.feedback.batVoltage), 35, 50); - meters[1].redraw(fixBatVoltage(controllers.back.feedback.batVoltage), 35, 50); + meters[0].redraw(controllers.front.getCalibratedVoltage(), 35, 50); + meters[1].redraw(controllers.back.getCalibratedVoltage(), 35, 50); meters[2].redraw(fixCurrent(controllers.front.feedback.left.dcLink), -10, 10); meters[3].redraw(fixCurrent(controllers.front.feedback.right.dcLink), -10, 10); meters[4].redraw(fixCurrent(controllers.back.feedback.left.dcLink), -10, 10); diff --git a/main/displays/statusdisplay.h b/main/displays/statusdisplay.h index fffc344..3202ebf 100644 --- a/main/displays/statusdisplay.h +++ b/main/displays/statusdisplay.h @@ -297,14 +297,7 @@ void StatusDisplay::BoardStatus::redraw(const Controller &controller) if (controller.feedbackValid) { - if (settings.battery.applyCalibration) - { - m_labelVoltage.redraw(fmt::format("{:.2f}V", controller.calibrated.batVoltage)); - } - else - { - m_labelVoltage.redraw(fmt::format("{:.2f}V", fixBatVoltage(controller.feedback.batVoltage))); - } + m_labelVoltage.redraw(fmt::format("{:.2f}V", controller.getCalibratedVoltage())); m_labelTemperature.redraw(fmt::format("{:.2f}C", fixBoardTemp(controller.feedback.boardTemp))); m_leftMotor.redraw(controller.feedback.left); m_rightMotor.redraw(controller.feedback.right); diff --git a/main/presets.h b/main/presets.h index 5320ad6..eea3b68 100644 --- a/main/presets.h +++ b/main/presets.h @@ -262,7 +262,7 @@ constexpr Settings::Battery defaultBattery { .back30VoltCalibration = 30, .front50VoltCalibration = 50, .back50VoltCalibration = 50, - .applyCalibration = false + .applyCalibration = true }; constexpr Settings defaultSettings { diff --git a/main/statistics.h b/main/statistics.h index 662dfed..6090e21 100644 --- a/main/statistics.h +++ b/main/statistics.h @@ -30,13 +30,13 @@ void pushStats() statistics::sumCurrent.push_back(sumCurrent); if (controllers.front.feedbackValid) { - statistics::frontVoltage.push_back(fixBatVoltage(controllers.front.feedback.batVoltage)); + statistics::frontVoltage.push_back(controllers.front.getCalibratedVoltage()); statistics::frontLeftCurrent.push_back(fixCurrent(controllers.front.feedback.left.dcLink)); statistics::frontRightCurrent.push_back(fixCurrent(controllers.front.feedback.right.dcLink)); } if (controllers.back.feedbackValid) { - statistics::backVoltage.push_back(fixBatVoltage(controllers.back.feedback.batVoltage)); + statistics::backVoltage.push_back(controllers.back.getCalibratedVoltage()); statistics::backLeftCurrent.push_back(fixCurrent(controllers.back.feedback.left.dcLink)); statistics::backRightCurrent.push_back(fixCurrent(controllers.back.feedback.right.dcLink)); } diff --git a/main/utils.h b/main/utils.h index c970cb8..d65f413 100644 --- a/main/utils.h +++ b/main/utils.h @@ -59,27 +59,6 @@ float fixCurrent(int16_t value) return -value/50.; } -float fixBatVoltage(int16_t value) -{ - return value/100.; -} - -float fixFrontBatVoltage(int16_t value) -{ - float frontVoltage = fixBatVoltage(value); - if (!settings.battery.applyCalibration) return frontVoltage; - frontVoltage = ((frontVoltage - fixBatVoltage(settings.battery.front30VoltCalibration)) * (20.f / (fixBatVoltage(settings.battery.front50VoltCalibration) - fixBatVoltage(settings.battery.front30VoltCalibration))) + 30.f); - return frontVoltage; -} - -float fixBackBatVoltage(int16_t value) -{ - float backVoltage = fixBatVoltage(value); - if (!settings.battery.applyCalibration) return backVoltage; - backVoltage = ((backVoltage - fixBatVoltage(settings.battery.back30VoltCalibration)) * (20.f / (fixBatVoltage(settings.battery.back50VoltCalibration) - fixBatVoltage(settings.battery.back30VoltCalibration))) + 30.f); - return backVoltage; -} - float fixBoardTemp(int16_t value) { return value/10.; From 2cc1ca6ab789f47acb7834398a3a470d35641565 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Wed, 13 Oct 2021 12:04:07 +0200 Subject: [PATCH 10/16] fix compiling --- main/displays/menus/selectbatterytypemenu.h | 33 +++++---------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/main/displays/menus/selectbatterytypemenu.h b/main/displays/menus/selectbatterytypemenu.h index 72de417..a0033c8 100644 --- a/main/displays/menus/selectbatterytypemenu.h +++ b/main/displays/menus/selectbatterytypemenu.h @@ -20,30 +20,13 @@ namespace { class BatteryTypeMenu; class BatteryMenu; - class BatterySelectType22PAction : public virtual ActionInterface + template + class BatterySelectTypeAction : public virtual ActionInterface { public: - void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_22P; saveSettings(); } + void triggered() override { settings.battery.cellType = uint8_t(T); saveSettings(); } }; - - class BatterySelectTypeHG2Action : public virtual ActionInterface - { - public: - void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_HG2; saveSettings(); } - }; - - class BatterySelectTypeMH1Action : public virtual ActionInterface - { - public: - void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_MH1; saveSettings(); } - }; - - class BatterySelectTypeVTC5Action : public virtual ActionInterface - { - public: - void triggered() override { settings.battery.cellType = BATTERY_CELLTYPE_VTC5; saveSettings(); } - }; -} +} // namespace namespace { class BatteryTypeMenu : @@ -55,10 +38,10 @@ namespace { BatteryTypeMenu() { constructMenuItem>(); - constructMenuItem, BatterySelectType22PAction>>(); - constructMenuItem, BatterySelectTypeHG2Action>>(); - constructMenuItem, BatterySelectTypeMH1Action>>(); - constructMenuItem, BatterySelectTypeVTC5Action>>(); + constructMenuItem, BatterySelectTypeAction>>(); + constructMenuItem, BatterySelectTypeAction>>(); + constructMenuItem, BatterySelectTypeAction>>(); + constructMenuItem, BatterySelectTypeAction>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } }; From 8414769397075e509a067c39dbd5b6be29245b48 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Wed, 13 Oct 2021 13:46:19 +0200 Subject: [PATCH 11/16] dont return 0 in calibrated voltage --- main/controller.h | 28 +++++++++------------------- main/globals.h | 6 ++++-- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/main/controller.h b/main/controller.h index dbd2c59..5c6979a 100644 --- a/main/controller.h +++ b/main/controller.h @@ -29,11 +29,13 @@ struct Controller { #ifdef FEATURE_SERIAL HardwareSerial &serial, #endif - bool &enableLeft, bool &enableRight, bool &invertLeft, bool &invertRight) : + bool &enableLeft, bool &enableRight, bool &invertLeft, bool &invertRight, + int16_t &voltageCalib30V, int16_t &voltageCalib50V) : #ifdef FEATURE_SERIAL serial{serial}, #endif - enableLeft{enableLeft}, enableRight{enableRight}, invertLeft{invertLeft}, invertRight{invertRight} + enableLeft{enableLeft}, enableRight{enableRight}, invertLeft{invertLeft}, invertRight{invertRight}, + voltageCalib30V{voltageCalib30V}, voltageCalib50V{voltageCalib50V} { } // Controller(const Controller &) = delete; @@ -43,6 +45,7 @@ struct Controller { std::reference_wrapper serial; #endif bool &enableLeft, &enableRight, &invertLeft, &invertRight; + int16_t &voltageCalib30V, &voltageCalib50V; bobbycar::protocol::serial::Command command{}; @@ -59,23 +62,10 @@ struct Controller { float getCalibratedVoltage() const { - return 0.f; + float voltage = feedback.batVoltage; + //if (settings.battery.applyCalibration) + voltage = ((voltage - float(voltageCalib30V)) * (20.f / (float(voltageCalib50V) - float(voltageCalib30V))) + 30.f); + return voltage; } - -// float fixFrontBatVoltage(int16_t value) -// { -// float frontVoltage = value; -// if (settings.battery.applyCalibration) -// frontVoltage = ((frontVoltage - float(settings.battery.front30VoltCalibration)) * (20.f / (float(settings.battery.front50VoltCalibration) - float(settings.battery.front30VoltCalibration))) + 30.f); -// return frontVoltage; -// } - -// float fixBackBatVoltage(int16_t value) -// { -// float backVoltage = value; -// if (settings.battery.applyCalibration) -// backVoltage = ((backVoltage - float(settings.battery.back30VoltCalibration)) * (20.f / (float(settings.battery.back50VoltCalibration) - float(settings.battery.back30VoltCalibration))) + 30.f); -// return backVoltage; -// } }; } diff --git a/main/globals.h b/main/globals.h index 8429f1c..457d6fb 100644 --- a/main/globals.h +++ b/main/globals.h @@ -60,13 +60,15 @@ public: #ifdef FEATURE_SERIAL Serial1, #endif - settings.controllerHardware.enableFrontLeft, settings.controllerHardware.enableFrontRight, settings.controllerHardware.invertFrontLeft, settings.controllerHardware.invertFrontRight + settings.controllerHardware.enableFrontLeft, settings.controllerHardware.enableFrontRight, settings.controllerHardware.invertFrontLeft, settings.controllerHardware.invertFrontRight, + settings.battery.front30VoltCalibration, settings.battery.front50VoltCalibration }, Controller { #ifdef FEATURE_SERIAL Serial2, #endif - settings.controllerHardware.enableBackLeft, settings.controllerHardware.enableBackRight, settings.controllerHardware.invertBackLeft, settings.controllerHardware.invertBackRight + settings.controllerHardware.enableBackLeft, settings.controllerHardware.enableBackRight, settings.controllerHardware.invertBackLeft, settings.controllerHardware.invertBackRight, + settings.battery.back30VoltCalibration, settings.battery.back50VoltCalibration } }} {} From 5dc794b903d4f453c4da992ed3f7757c329544ff Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 14 Oct 2021 18:27:08 +0200 Subject: [PATCH 12/16] Converted int16_t to float --- main/displays/calibratevoltagedisplay.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main/displays/calibratevoltagedisplay.h b/main/displays/calibratevoltagedisplay.h index 4cb5e26..5f2f795 100644 --- a/main/displays/calibratevoltagedisplay.h +++ b/main/displays/calibratevoltagedisplay.h @@ -52,10 +52,15 @@ namespace { } }; - class BatteryVoltageCalibrationFront30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Front: {}", settings.battery.front30VoltCalibration); } }; - class BatteryVoltageCalibrationBack30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Back: {}", settings.battery.back30VoltCalibration); } }; - class BatteryVoltageCalibrationFront50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Front: {}", settings.battery.front50VoltCalibration); } }; - class BatteryVoltageCalibrationBack50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Back: {}", settings.battery.back50VoltCalibration); } }; + float convertToFloat(int16_t value) + { + return value/100.; + } + + class BatteryVoltageCalibrationFront30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Front: {}", convertToFloat(settings.battery.front30VoltCalibration)); } }; + class BatteryVoltageCalibrationBack30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Back: {}", convertToFloat(settings.battery.back30VoltCalibration)); } }; + class BatteryVoltageCalibrationFront50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Front: {}", convertToFloat(settings.battery.front50VoltCalibration)); } }; + class BatteryVoltageCalibrationBack50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Back: {}", convertToFloat(settings.battery.back50VoltCalibration)); } }; class BatteryVoltageCalibratedText : public virtual TextInterface { public: std::string text() const override { if (settings.battery.applyCalibration) return fmt::format("F{:.2f}V B{:.2f}", controllers.front.getCalibratedVoltage(), controllers.back.getCalibratedVoltage()); else return "Not activated"; } }; } From 7e7727e180d182ef299e1067d38dc2d4297d59f5 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 14 Oct 2021 20:32:52 +0200 Subject: [PATCH 13/16] First steps for discharge curves, calibration can be deactivated now --- main/battery.h | 26 +++++++++++++++++++++++-- main/ble_bobby.h | 4 ++-- main/cloud.h | 2 +- main/controller.h | 11 +++++++++-- main/debugtexthelpers.h | 2 +- main/displays/calibratevoltagedisplay.h | 2 +- main/displays/metersdisplay.h | 4 ++-- main/displays/statusdisplay.h | 6 +++--- main/statistics.h | 4 ++-- 9 files changed, 45 insertions(+), 16 deletions(-) diff --git a/main/battery.h b/main/battery.h index e277a1e..aa2694c 100644 --- a/main/battery.h +++ b/main/battery.h @@ -16,11 +16,33 @@ DECLARE_TYPESAFE_ENUM(BatteryCellType, : uint8_t, BatteryCellTypeValues) namespace { -float battery_percentage = 42.f; + +float getBatteryPercentage(float batVoltage, BatteryCellType cellType) +{ + float percentage = 0; + switch (cellType) { + case BatteryCellType::_22P: + break; + case BatteryCellType::MH1: + break; + case BatteryCellType::HG2: + break; + case BatteryCellType::VTC5: + break; + } + return percentage; +} std::string getBatteryPercentageString() { - std::string output = fmt::format("Battery: {:.1f}%", battery_percentage); + float avgVoltage = 0; + for (auto &controller : controllers) + { + avgVoltage += controller.getCalibratedVoltage(settings.battery.applyCalibration); + } + avgVoltage = avgVoltage / controllers.size(); + + std::string output = fmt::format("Battery: {:.1f}%", getBatteryPercentage(avgVoltage, BatteryCellType(settings.battery.cellType))); return output; } diff --git a/main/ble_bobby.h b/main/ble_bobby.h index 4bcd3ad..e72c746 100644 --- a/main/ble_bobby.h +++ b/main/ble_bobby.h @@ -81,11 +81,11 @@ void handleBle() { auto arr = doc.createNestedArray("v"); if (controllers.front.feedbackValid) - arr.add(controllers.front.getCalibratedVoltage()); + arr.add(controllers.front.getCalibratedVoltage(settings.battery.applyCalibration)); else arr.add(nullptr); if (controllers.back.feedbackValid) - arr.add(controllers.back.getCalibratedVoltage()); + arr.add(controllers.back.getCalibratedVoltage(settings.battery.applyCalibration)); else arr.add(nullptr); } diff --git a/main/cloud.h b/main/cloud.h index eac0e09..a4ba268 100644 --- a/main/cloud.h +++ b/main/cloud.h @@ -109,7 +109,7 @@ void cloudCollect() } cloudBuffer += fmt::format(",[{:.02f},{:.02f}", - controller.getCalibratedVoltage(), + controller.getCalibratedVoltage(settings.battery.applyCalibration), fixBoardTemp(controller.feedback.boardTemp)); constexpr const auto addMotor = [](const bobbycar::protocol::serial::MotorState &command, diff --git a/main/controller.h b/main/controller.h index 5c6979a..cc415b6 100644 --- a/main/controller.h +++ b/main/controller.h @@ -24,6 +24,7 @@ class HardwareSerial; #endif namespace { + struct Controller { Controller( #ifdef FEATURE_SERIAL @@ -60,11 +61,17 @@ struct Controller { FeedbackParser parser{serial, feedbackValid, feedback}; #endif - float getCalibratedVoltage() const + float getCalibratedVoltage(bool applyCalibration) const { float voltage = feedback.batVoltage; - //if (settings.battery.applyCalibration) + if (applyCalibration) + { voltage = ((voltage - float(voltageCalib30V)) * (20.f / (float(voltageCalib50V) - float(voltageCalib30V))) + 30.f); + } + else + { + voltage = voltage / 100.; + } return voltage; } }; diff --git a/main/debugtexthelpers.h b/main/debugtexthelpers.h index bdaa1a2..ecb135f 100644 --- a/main/debugtexthelpers.h +++ b/main/debugtexthelpers.h @@ -48,7 +48,7 @@ public: using RightCommand = CommandTexts; //struct BatVoltageText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.batVoltage); return line; } }; - struct BatVoltageFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}V", controller::get().getCalibratedVoltage()); return line; } }; + struct BatVoltageFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"batVoltage: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}V", controller::get().getCalibratedVoltage(settings.battery.applyCalibration)); return line; } }; //struct BoardTempText : public virtual TextInterface { public: std::string text() const override { std::string line{"boardTemp: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.boardTemp); return line; } }; struct BoardTempFixedText : public virtual TextInterface { public: std::string text() const override { std::string line{"boardTemp: "}; if (controller::get().feedbackValid) line += fmt::format("{:.2f}C", fixBoardTemp(controller::get().feedback.boardTemp)); return line; } }; struct TimeoutCntSerialText : public virtual TextInterface { public: std::string text() const override { std::string line{"timeoutCntSerial: "}; if (controller::get().feedbackValid) line += std::to_string(controller::get().feedback.timeoutCntSerial); return line; } }; diff --git a/main/displays/calibratevoltagedisplay.h b/main/displays/calibratevoltagedisplay.h index 5f2f795..67c9646 100644 --- a/main/displays/calibratevoltagedisplay.h +++ b/main/displays/calibratevoltagedisplay.h @@ -61,7 +61,7 @@ namespace { class BatteryVoltageCalibrationBack30VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("30V Back: {}", convertToFloat(settings.battery.back30VoltCalibration)); } }; class BatteryVoltageCalibrationFront50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Front: {}", convertToFloat(settings.battery.front50VoltCalibration)); } }; class BatteryVoltageCalibrationBack50VText : public virtual TextInterface { public: std::string text() const override { return fmt::format("50V Back: {}", convertToFloat(settings.battery.back50VoltCalibration)); } }; - class BatteryVoltageCalibratedText : public virtual TextInterface { public: std::string text() const override { if (settings.battery.applyCalibration) return fmt::format("F{:.2f}V B{:.2f}", controllers.front.getCalibratedVoltage(), controllers.back.getCalibratedVoltage()); else return "Not activated"; } }; + class BatteryVoltageCalibratedText : public virtual TextInterface { public: std::string text() const override { if (settings.battery.applyCalibration) return fmt::format("F{:.2f}V B{:.2f}", controllers.front.getCalibratedVoltage(settings.battery.applyCalibration), controllers.back.getCalibratedVoltage(settings.battery.applyCalibration)); else return "Not activated"; } }; } namespace { diff --git a/main/displays/metersdisplay.h b/main/displays/metersdisplay.h index 7443ffc..92e621a 100644 --- a/main/displays/metersdisplay.h +++ b/main/displays/metersdisplay.h @@ -74,8 +74,8 @@ void MetersDisplay::redraw() tft.setTextFont(2); m_sumCurrentLabel.redraw(std::to_string(sumCurrent) + 'A'); - meters[0].redraw(controllers.front.getCalibratedVoltage(), 35, 50); - meters[1].redraw(controllers.back.getCalibratedVoltage(), 35, 50); + meters[0].redraw(controllers.front.getCalibratedVoltage(settings.battery.applyCalibration), 35, 50); + meters[1].redraw(controllers.back.getCalibratedVoltage(settings.battery.applyCalibration), 35, 50); meters[2].redraw(fixCurrent(controllers.front.feedback.left.dcLink), -10, 10); meters[3].redraw(fixCurrent(controllers.front.feedback.right.dcLink), -10, 10); meters[4].redraw(fixCurrent(controllers.back.feedback.left.dcLink), -10, 10); diff --git a/main/displays/statusdisplay.h b/main/displays/statusdisplay.h index 3202ebf..533e5f0 100644 --- a/main/displays/statusdisplay.h +++ b/main/displays/statusdisplay.h @@ -97,8 +97,8 @@ private: Label m_batterypercent{0, 30}; - BoardStatus m_frontStatus{42}; - BoardStatus m_backStatus{142}; + BoardStatus m_frontStatus{45}; + BoardStatus m_backStatus{145}; Label m_labelWifiStatus{35, bottomLines[0]}; // 120, 15 Label m_labelLimit0{205, bottomLines[0]}; // 35, 15 @@ -297,7 +297,7 @@ void StatusDisplay::BoardStatus::redraw(const Controller &controller) if (controller.feedbackValid) { - m_labelVoltage.redraw(fmt::format("{:.2f}V", controller.getCalibratedVoltage())); + m_labelVoltage.redraw(fmt::format("{:.2f}V", controller.getCalibratedVoltage(settings.battery.applyCalibration))); m_labelTemperature.redraw(fmt::format("{:.2f}C", fixBoardTemp(controller.feedback.boardTemp))); m_leftMotor.redraw(controller.feedback.left); m_rightMotor.redraw(controller.feedback.right); diff --git a/main/statistics.h b/main/statistics.h index 6090e21..d03d891 100644 --- a/main/statistics.h +++ b/main/statistics.h @@ -30,13 +30,13 @@ void pushStats() statistics::sumCurrent.push_back(sumCurrent); if (controllers.front.feedbackValid) { - statistics::frontVoltage.push_back(controllers.front.getCalibratedVoltage()); + statistics::frontVoltage.push_back(controllers.front.getCalibratedVoltage(settings.battery.applyCalibration)); statistics::frontLeftCurrent.push_back(fixCurrent(controllers.front.feedback.left.dcLink)); statistics::frontRightCurrent.push_back(fixCurrent(controllers.front.feedback.right.dcLink)); } if (controllers.back.feedbackValid) { - statistics::backVoltage.push_back(controllers.back.getCalibratedVoltage()); + statistics::backVoltage.push_back(controllers.back.getCalibratedVoltage(settings.battery.applyCalibration)); statistics::backLeftCurrent.push_back(fixCurrent(controllers.back.feedback.left.dcLink)); statistics::backRightCurrent.push_back(fixCurrent(controllers.back.feedback.right.dcLink)); } From 3b270bda3de8a52e29142b85ae31bf64c27f5acf Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 14 Oct 2021 21:00:01 +0200 Subject: [PATCH 14/16] Added labels --- main/battery.h | 18 +++++++++++++++++- main/displays/statusdisplay.h | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/main/battery.h b/main/battery.h index aa2694c..07ca95e 100644 --- a/main/battery.h +++ b/main/battery.h @@ -19,7 +19,7 @@ namespace { float getBatteryPercentage(float batVoltage, BatteryCellType cellType) { - float percentage = 0; + float percentage = 12.34; switch (cellType) { case BatteryCellType::_22P: break; @@ -33,6 +33,11 @@ float getBatteryPercentage(float batVoltage, BatteryCellType cellType) return percentage; } +float getRemainingWattHours() +{ + return 42.69; +} + std::string getBatteryPercentageString() { float avgVoltage = 0; @@ -46,8 +51,19 @@ std::string getBatteryPercentageString() return output; } +std::string getBatteryRemainingWattHoursString() +{ + return fmt::format("{:.1f} Wh", getRemainingWattHours()); +} + std::string getBatteryCellTypeString() { return fmt::format("Cells: {}", toString(BatteryCellType(settings.battery.cellType))); } + +std::string getRemainingRangeString() +{ + return fmt::format("{:.1f} km", getRemainingWattHours() / settings.battery.watthoursPerKilometer); +} + } // namespace diff --git a/main/displays/statusdisplay.h b/main/displays/statusdisplay.h index 533e5f0..e788984 100644 --- a/main/displays/statusdisplay.h +++ b/main/displays/statusdisplay.h @@ -96,6 +96,8 @@ private: ProgressBar m_progressBarBrems{150, 15, 90, 15, 0, 1000}; Label m_batterypercent{0, 30}; + Label m_watthoursleft{110, 30}; + Label m_kilometersleft{175, 30}; BoardStatus m_frontStatus{45}; BoardStatus m_backStatus{145}; @@ -130,6 +132,8 @@ void StatusDisplay::initScreen() m_progressBarBrems.start(); m_batterypercent.start(); + m_watthoursleft.start(); + m_kilometersleft.start(); m_frontStatus.start(); m_backStatus.start(); @@ -167,6 +171,8 @@ void StatusDisplay::redraw() m_progressBarBrems.redraw(brems ? *brems : 0); m_batterypercent.redraw(getBatteryPercentageString()); + m_watthoursleft.redraw(getBatteryRemainingWattHoursString()); + m_kilometersleft.redraw(getRemainingRangeString()); m_frontStatus.redraw(controllers.front); m_backStatus.redraw(controllers.back); From fa01d2bcbd6ffa0a320c1868d53de4cc02e2db4e Mon Sep 17 00:00:00 2001 From: Peter Poetzi Date: Thu, 14 Oct 2021 21:44:28 +0200 Subject: [PATCH 15/16] implement curves --- main/battery.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 7 deletions(-) diff --git a/main/battery.h b/main/battery.h index 07ca95e..ffb340f 100644 --- a/main/battery.h +++ b/main/battery.h @@ -17,25 +17,98 @@ DECLARE_TYPESAFE_ENUM(BatteryCellType, : uint8_t, BatteryCellTypeValues) namespace { +float mapFloat(float x, float in_min, float in_max, float out_min, float out_max) { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} +#define CURVE(higherVoltage,lowerVoltage,fromAh,toAh) if(cellVoltage >= lowerVoltage && cellVoltage <= higherVoltage) return 100 * mapFloat(cellVoltage, higherVoltage, lowerVoltage, fromAh, toAh) / expected_ah; + float getBatteryPercentage(float batVoltage, BatteryCellType cellType) { - float percentage = 12.34; + const float cellVoltage = batVoltage / settings.battery.cellsSeries; + switch (cellType) { - case BatteryCellType::_22P: + case BatteryCellType::_22P: { + const float expected_ah = 2.2; + CURVE(4.15, 4.04, 0, 0.25) + CURVE(4.04, 3.95, 0.25, 0.5) + CURVE(3.95, 3.86, 0.5, 0.75) + CURVE(3.86, 3.74, 0.75, 1.0) + CURVE(3.74, 3.64, 1.0, 1.25) + CURVE(3.64, 3.59, 1.25, 1.5) + CURVE(3.59, 3.54, 1.5, 1.75) + CURVE(3.54, 3.43, 1.75, 2.0) + CURVE(3.43, 3.35, 2.0, 2.1) + CURVE(3.35, 2.50, 2.1, 2.2) break; - case BatteryCellType::MH1: + } + case BatteryCellType::MH1: { + const float expected_ah = 3.2; + CURVE(4.15, 4.09, 0, 0.25) + CURVE(4.09, 4.04, 0.25, 0.5) + CURVE(4.04, 3.95, 0.5, 0.75) + CURVE(3.95, 3.88, 0.75, 1.0) + CURVE(3.88, 3.79, 1.0, 1.25) + CURVE(3.79, 3.70, 1.25, 1.5) + CURVE(3.70, 3.65, 1.5, 1.75) + CURVE(3.65, 3.60, 1.75, 2.0) + CURVE(3.60, 3.56, 2.0, 2.25) + CURVE(3.56, 3.50, 2.25, 2.5) + CURVE(3.50, 3.40, 2.5, 2.75) + CURVE(3.40, 3.30, 2.75, 3.0) + CURVE(3.30, 2.5, 3.0, 3.2) break; - case BatteryCellType::HG2: + } + case BatteryCellType::HG2: { + const float expected_ah = 3.0; + CURVE(4.15, 4.08, 0, 0.25) + CURVE(4.08, 4.01, 0.25, 0.5) + CURVE(4.01, 3.92, 0.5, 0.75) + CURVE(3.92, 3.84, 0.75, 1.0) + CURVE(3.84, 3.75, 1.0, 1.25) + CURVE(3.75, 3.67, 1.25, 1.5) + CURVE(3.67, 3.62, 1.5, 1.75) + CURVE(3.62, 3.55, 1.75, 2.0) + CURVE(3.55, 3.44, 2.0, 2.25) + CURVE(3.44, 3.30, 2.25, 2.5) + CURVE(3.30, 3.05, 2.5, 2.75) + CURVE(3.05, 2.50, 2.75, 3.0) break; - case BatteryCellType::VTC5: + } + case BatteryCellType::VTC5: { + const float expected_ah = 2.6; + CURVE(4.15, 4.08, 0, 0.25) + CURVE(4.08, 3.98, 0.25, 0.5) + CURVE(3.98, 3.89, 0.5, 0.75) + CURVE(3.89, 3.79, 0.75, 1.0) + CURVE(3.79, 3.71, 1.0, 1.25) + CURVE(3.71, 3.64, 1.25, 1.5) + CURVE(3.64, 3.53, 1.5, 1.75) + CURVE(3.53, 3.44, 1.75, 2.0) + CURVE(3.44, 3.20, 2.0, 2.25) + CURVE(3.20, 2.80, 2.25, 2.5) + CURVE(2.80, 2.50, 2.5, 2.60) break; + } } - return percentage; + return 0.f; } float getRemainingWattHours() { - return 42.69; + float target_mah = 2000; //default + if(BatteryCellType(settings.battery.cellType) == BatteryCellType::_22P) target_mah = 2200; + if(BatteryCellType(settings.battery.cellType) == BatteryCellType::HG2) target_mah = 3000; + if(BatteryCellType(settings.battery.cellType) == BatteryCellType::MH1) target_mah = 3200; + if(BatteryCellType(settings.battery.cellType) == BatteryCellType::VTC5) target_mah = 2600; + + float avgVoltage = 0; + for (auto &controller : controllers) + { + avgVoltage += controller.getCalibratedVoltage(settings.battery.applyCalibration); + } + avgVoltage = avgVoltage / controllers.size(); + + return (target_mah / 1000.f) * 3.7 * settings.battery.cellsParallel * settings.battery.cellsSeries * (getBatteryPercentage(avgVoltage, BatteryCellType(settings.battery.cellType)) / 100); } std::string getBatteryPercentageString() From e7055a8508e9633fc4bd18cf3efd4bc536fb3e59 Mon Sep 17 00:00:00 2001 From: Peter Poetzi Date: Thu, 14 Oct 2021 21:55:30 +0200 Subject: [PATCH 16/16] fix percent --- main/battery.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main/battery.h b/main/battery.h index ffb340f..f4b4c0c 100644 --- a/main/battery.h +++ b/main/battery.h @@ -20,7 +20,7 @@ namespace { float mapFloat(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } -#define CURVE(higherVoltage,lowerVoltage,fromAh,toAh) if(cellVoltage >= lowerVoltage && cellVoltage <= higherVoltage) return 100 * mapFloat(cellVoltage, higherVoltage, lowerVoltage, fromAh, toAh) / expected_ah; +#define CURVE(higherVoltage,lowerVoltage,fromAh,toAh) if(cellVoltage >= lowerVoltage && cellVoltage <= higherVoltage) return 100 * (expected_ah - mapFloat(cellVoltage, higherVoltage, lowerVoltage, fromAh, toAh)) / expected_ah; float getBatteryPercentage(float batVoltage, BatteryCellType cellType) { @@ -29,6 +29,9 @@ float getBatteryPercentage(float batVoltage, BatteryCellType cellType) switch (cellType) { case BatteryCellType::_22P: { const float expected_ah = 2.2; + if(cellVoltage > 4.15){ + return 100; + } CURVE(4.15, 4.04, 0, 0.25) CURVE(4.04, 3.95, 0.25, 0.5) CURVE(3.95, 3.86, 0.5, 0.75) @@ -43,6 +46,9 @@ float getBatteryPercentage(float batVoltage, BatteryCellType cellType) } case BatteryCellType::MH1: { const float expected_ah = 3.2; + if(cellVoltage > 4.15){ + return 100; + } CURVE(4.15, 4.09, 0, 0.25) CURVE(4.09, 4.04, 0.25, 0.5) CURVE(4.04, 3.95, 0.5, 0.75) @@ -60,6 +66,9 @@ float getBatteryPercentage(float batVoltage, BatteryCellType cellType) } case BatteryCellType::HG2: { const float expected_ah = 3.0; + if(cellVoltage > 4.15){ + return 100; + } CURVE(4.15, 4.08, 0, 0.25) CURVE(4.08, 4.01, 0.25, 0.5) CURVE(4.01, 3.92, 0.5, 0.75) @@ -76,6 +85,9 @@ float getBatteryPercentage(float batVoltage, BatteryCellType cellType) } case BatteryCellType::VTC5: { const float expected_ah = 2.6; + if(cellVoltage > 4.15){ + return 100; + } CURVE(4.15, 4.08, 0, 0.25) CURVE(4.08, 3.98, 0.25, 0.5) CURVE(3.98, 3.89, 0.5, 0.75)