@@ -31,7 +31,7 @@ void CustomControlMap::LoadUADfromNVS() {
3131 uadData = (uint8_t *)pvPortMalloc (new_uad_size);
3232 if (uadData == nullptr )
3333 {
34- MLOGE (" CustomControlMap" , " Failed to allocate memory for UAD" );
34+ MLOGE (" CustomControlMap" , " Failed to allocate memory for UAD (%d bytes requested, %d bytes free) " , new_uad_size, xPortGetFreeHeapSize () );
3535 return ;
3636 }
3737
@@ -54,8 +54,8 @@ void CustomControlMap::LoadUADfromNVS() {
5454 uadSize = new_uad_size;
5555}
5656
57- void CustomControlMap::SaveUADtoNVS () {
58- MatrixOS::NVS::SetVariable (UAD_NVS_HASH, uadData, uadSize);
57+ bool CustomControlMap::SaveUADtoNVS () {
58+ return MatrixOS::NVS::SetVariable (UAD_NVS_HASH, uadData, uadSize);
5959}
6060
6161void CustomControlMap::HIDReportHandler () {
@@ -128,6 +128,7 @@ void CustomControlMap::PrepNewUAD(const uint8_t* report) {
128128
129129 if (new_uad_size > MAX_UAD_SIZE)
130130 {
131+ MLOGE (" CustomControlMap" , " UAD size exceeds limit (%d > %d)" , new_uad_size, MAX_UAD_SIZE);
131132 SendError (report[0 ], 3 ); // UAD Size too large
132133 return ;
133134 }
@@ -141,6 +142,7 @@ void CustomControlMap::PrepNewUAD(const uint8_t* report) {
141142 uadData = (uint8_t *)pvPortMalloc (new_uad_size);
142143 if (uadData == nullptr )
143144 {
145+ MLOGE (" CustomControlMap" , " Failed to allocate memory for new UAD (%d bytes requested, %d bytes free)" , new_uad_size, xPortGetFreeHeapSize ());
144146 MatrixOS::SYS::ErrorHandler (" Failed to allocate memory for new UAD" );
145147 SendError (report[0 ], 4 ); // Failed to allocate memory for new UAD
146148 return ;
@@ -194,7 +196,13 @@ void CustomControlMap::SaveUAD() {
194196 return ;
195197 }
196198
197- SaveUADtoNVS ();
199+ if (!SaveUADtoNVS ())
200+ {
201+ MLOGE (" CustomControlMap" , " Failed to save UAD to NVS (%d bytes)" , uadSize);
202+ SendError (UAD_SAVE, 3 ); // Failed to save UAD to NVS
203+ return ;
204+ }
205+
198206 SendAck (UAD_SAVE | HID_RESPONSE);
199207}
200208
0 commit comments