@@ -173,7 +173,7 @@ static bool is_digit(char *ptr, bool hex)
173
173
if (hex ) {
174
174
c &= ~0x20 ;
175
175
if (c >= 'A' && c <= 'F' ) return true;
176
- }
176
+ } else if ( c == '-' ) return true;
177
177
return false;
178
178
}
179
179
@@ -218,6 +218,29 @@ static void add_to_str_hex_bytes(char *out, uint8_t *arr, int bytes)
218
218
} while (-- bytes );
219
219
}
220
220
221
+ void Edit_insert_digit (char new )
222
+ {
223
+ if (* Edit_pos == '-' ) return ;
224
+ if (what_doing <= 1 ) {
225
+ if (strlen (Edit_start ) < (what_doing == 0 && setup_cursor == 2 ? 3 : 5 * 2 )) {
226
+ memmove (Edit_pos + 1 , Edit_pos , strlen (Edit_pos ) + 1 );
227
+ * Edit_pos = new ;
228
+ }
229
+ } else {
230
+ FuriString * fs = Log [view_Batch ];
231
+ FuriString * ns = furi_string_alloc ();
232
+ if (ns ) {
233
+ uint16_t len = Edit_pos - (char * )furi_string_get_cstr (fs );
234
+ furi_string_set_n (ns , fs , 0 , len );
235
+ furi_string_cat_printf (ns , "%c" , new );
236
+ furi_string_cat_str (ns , Edit_pos );
237
+ furi_string_free (fs );
238
+ Log [view_Batch ] = ns ;
239
+ Edit_pos = (char * )furi_string_get_cstr (ns ) + len ;
240
+ }
241
+ }
242
+ }
243
+
221
244
int32_t get_payload_receive_field (uint8_t * var , uint8_t size )
222
245
{
223
246
if (size <= 1 ) return * var ;
@@ -361,7 +384,7 @@ static void prepare_nrf24(void)
361
384
NRF_INITED = 0 ;
362
385
return ;
363
386
}
364
- // EN_DYN_ACK(0x01) option for W_TX_PAYLOAD_NOACK cmd broke AA on some fake nRF24l01+ modules
387
+ // EN_DYN_ACK(0x01) option for W_TX_PAYLOAD_NOACK cmd broke AA on some fake nRF24l01+, i.e. set it to 0
365
388
nrf24_write_reg (nrf24_HANDLE , REG_FEATURE , (NRF_DPL ? 4 : 0 )); // Dynamic Payload, Payload with ACK, W_TX_PAYLOAD_NOACK command
366
389
nrf24_write_reg (nrf24_HANDLE , REG_RF_CH , NRF_channel );
367
390
nrf24_write_reg (nrf24_HANDLE , REG_RF_SETUP , (NRF_rate == 0 ? 0b00100000 : NRF_rate == 1 ? 0 : 0b00001000 ) | 0b111 ); // +TX high power
@@ -1292,13 +1315,15 @@ int32_t nrf24batch_app(void* p) {
1292
1315
if (event .input .type == InputTypeShort || event .input .type == InputTypeRepeat ) {
1293
1316
if (!ask_question ) {
1294
1317
if (Edit ) {
1295
- if (* Edit_pos < '9' ) (* Edit_pos )++ ;
1296
- else if (Edit_hex ) {
1297
- if (* Edit_pos == '9' ) * Edit_pos = 'A' ;
1298
- else if ((* Edit_pos & ~0x20 ) < 'F' ) (* Edit_pos )++ ;
1299
- } else if (Edit_pos > Edit_start && * (Edit_pos - 1 ) < '9' ) {
1300
- * Edit_pos = '0' ;
1301
- (* (Edit_pos - 1 ))++ ;
1318
+ if (* Edit_pos != '-' ) {
1319
+ if (* Edit_pos < '9' ) (* Edit_pos )++ ;
1320
+ else if (Edit_hex ) {
1321
+ if (* Edit_pos == '9' ) * Edit_pos = 'A' ;
1322
+ else if ((* Edit_pos & ~0x20 ) < 'F' ) (* Edit_pos )++ ;
1323
+ } else if (Edit_pos > Edit_start && * (Edit_pos - 1 ) < '9' && * (Edit_pos - 1 ) >= '0' ) {
1324
+ * Edit_pos = '0' ;
1325
+ (* (Edit_pos - 1 ))++ ;
1326
+ }
1302
1327
}
1303
1328
} else if (what_doing == 0 ) {
1304
1329
if (addr_len ) {
@@ -1316,11 +1341,19 @@ int32_t nrf24batch_app(void* p) {
1316
1341
if (event .input .type == InputTypeShort || event .input .type == InputTypeRepeat ) {
1317
1342
if (!ask_question ) {
1318
1343
if (Edit ) {
1319
- if (Edit_hex && (* Edit_pos & ~0x20 ) == 'A' ) (* Edit_pos ) = '9' ;
1320
- else if (* Edit_pos > '0' ) (* Edit_pos )-- ;
1321
- else if (!Edit_hex && Edit_pos > Edit_start && * (Edit_pos - 1 ) > '0' ) {
1322
- * Edit_pos = '9' ;
1323
- (* (Edit_pos - 1 ))-- ;
1344
+ if (* Edit_pos != '-' ) {
1345
+ if (Edit_hex && (* Edit_pos & ~0x20 ) == 'A' ) (* Edit_pos ) = '9' ;
1346
+ else if (* Edit_pos > '0' ) (* Edit_pos )-- ;
1347
+ else if (!Edit_hex ) {
1348
+ if (Edit_pos > Edit_start ) {
1349
+ if (* (Edit_pos - 1 ) > '0' ) {
1350
+ * Edit_pos = '9' ;
1351
+ (* (Edit_pos - 1 ))-- ;
1352
+ }
1353
+ } else if (strlen (Edit_start ) == 1 ) { // negative
1354
+ Edit_insert_digit ('-' );
1355
+ }
1356
+ }
1324
1357
}
1325
1358
} else if (what_doing == 0 ) {
1326
1359
if (addr_len ) {
@@ -1415,24 +1448,7 @@ int32_t nrf24batch_app(void* p) {
1415
1448
}
1416
1449
ask_question = 0 ;
1417
1450
} else if (Edit ) { // insert digit
1418
- if (what_doing <= 1 ) {
1419
- if (strlen (Edit_start ) < (what_doing == 0 && setup_cursor == 2 ? 3 : 5 * 2 )) {
1420
- memmove (Edit_pos + 1 , Edit_pos , strlen (Edit_pos ) + 1 );
1421
- * Edit_pos = '0' ;
1422
- }
1423
- } else {
1424
- FuriString * fs = Log [view_Batch ];
1425
- FuriString * ns = furi_string_alloc ();
1426
- if (ns ) {
1427
- uint16_t len = Edit_pos - (char * )furi_string_get_cstr (fs );
1428
- furi_string_set_n (ns , fs , 0 , len );
1429
- furi_string_cat_str (ns , "0" );
1430
- furi_string_cat_str (ns , Edit_pos );
1431
- furi_string_free (fs );
1432
- Log [view_Batch ] = ns ;
1433
- Edit_pos = (char * )furi_string_get_cstr (ns ) + len ;
1434
- }
1435
- }
1451
+ Edit_insert_digit ('0' );
1436
1452
} else if (what_doing == 0 ) {
1437
1453
if (setup_cursor == 0 ) { // open file
1438
1454
file_stream_close (file_stream );
@@ -1515,13 +1531,14 @@ int32_t nrf24batch_app(void* p) {
1515
1531
if (Edit ) { // delete
1516
1532
if (what_doing <= 1 ) {
1517
1533
if (strlen (Edit_start ) > 1 ) {
1518
- memmove (Edit_pos , Edit_pos + 1 , strlen (Edit_pos ) + 1 );
1534
+ memmove (Edit_pos , Edit_pos + 1 , strlen (Edit_pos ));
1519
1535
if (* Edit_pos == '\0' ) Edit_pos -- ;
1520
1536
}
1521
1537
} else {
1522
1538
FuriString * fs = Log [view_Batch ];
1523
1539
if (is_digit (Edit_pos + 1 , Edit_hex ) || (Edit_pos > Edit_start && is_digit (Edit_pos - 1 , Edit_hex ))) {
1524
1540
memmove (Edit_pos , Edit_pos + 1 , strlen (Edit_pos ));
1541
+ if (* Edit_pos == '\0' ) Edit_pos -- ;
1525
1542
furi_string_left (fs , furi_string_size (fs ) - 1 );
1526
1543
}
1527
1544
}
0 commit comments