Skip to content

Commit 700ec39

Browse files
committed
upd
1 parent 701f85b commit 700ec39

File tree

2 files changed

+57
-36
lines changed

2 files changed

+57
-36
lines changed

Distr/nrf24batch/CO2_mini.txt

+7-3
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ W: FanLSB=,i:9
4747
R: Send pause=19
4848
W: Send pause=,19
4949

50+
R: Flags=20#
51+
W: Flags=,20
52+
5053
W: Reset=,RESET,0xC1
5154

52-
RBatch: Settings: ID;RxAddr;Ch;Send period;CO2 threshold;CO2 correct;FanLSB;nRF RETR;OSCCAL
55+
RBatch: Settings: ID;RxAddr;Ch;Send period;CO2 threshold;CO2 correct;FanLSB;nRF RETR;Send pause;Flags
5356

54-
WBatch: Default: RxAddr=0xCF;Ch=122;Send period=30;CO2 threshold=1000;CO2 correct=0;FanLSB={0xC1,0};nRF RETR=0x17;Reset
57+
WBatch: Default: RxAddr=0xCF;Ch=122;Send period=30;CO2 threshold=1000;CO2 correct=0;FanLSB={0xC1,0,0,0,0,0,0,0};nRF RETR=0x3;Send pause=1;Flags=0;Reset
5558
WBatch: CO2: CO2 threshold=1000;CO2 correct=0
56-
WBatch: Fan2: FanLSB={0xC1,0,0,0,0,0,0};Reset
59+
WBatch: Fan: FanLSB={0xC1,0,0,0,0,0,0,0,0,0};Reset
5760
WBatch: RETR: nRF RETR=0x2F;Reset
5861
WBatch: Send pause: Send pause=30
62+
WBatch: Flags: Flags=0x00
5963
WBatch: Reset: Reset

nrf24batch.c

+50-33
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static bool is_digit(char *ptr, bool hex)
173173
if(hex) {
174174
c &= ~0x20;
175175
if(c >= 'A' && c <= 'F') return true;
176-
}
176+
} else if(c == '-') return true;
177177
return false;
178178
}
179179

@@ -218,6 +218,29 @@ static void add_to_str_hex_bytes(char *out, uint8_t *arr, int bytes)
218218
} while(--bytes);
219219
}
220220

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+
221244
int32_t get_payload_receive_field(uint8_t *var, uint8_t size)
222245
{
223246
if(size <= 1) return *var;
@@ -361,7 +384,7 @@ static void prepare_nrf24(void)
361384
NRF_INITED = 0;
362385
return;
363386
}
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
365388
nrf24_write_reg(nrf24_HANDLE, REG_FEATURE, (NRF_DPL ? 4 : 0)); // Dynamic Payload, Payload with ACK, W_TX_PAYLOAD_NOACK command
366389
nrf24_write_reg(nrf24_HANDLE, REG_RF_CH, NRF_channel);
367390
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) {
12921315
if(event.input.type == InputTypeShort || event.input.type == InputTypeRepeat) {
12931316
if(!ask_question) {
12941317
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+
}
13021327
}
13031328
} else if(what_doing == 0) {
13041329
if(addr_len) {
@@ -1316,11 +1341,19 @@ int32_t nrf24batch_app(void* p) {
13161341
if(event.input.type == InputTypeShort || event.input.type == InputTypeRepeat) {
13171342
if(!ask_question) {
13181343
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+
}
13241357
}
13251358
} else if(what_doing == 0) {
13261359
if(addr_len) {
@@ -1415,24 +1448,7 @@ int32_t nrf24batch_app(void* p) {
14151448
}
14161449
ask_question = 0;
14171450
} 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');
14361452
} else if(what_doing == 0) {
14371453
if(setup_cursor == 0) { // open file
14381454
file_stream_close(file_stream);
@@ -1515,13 +1531,14 @@ int32_t nrf24batch_app(void* p) {
15151531
if(Edit) { // delete
15161532
if(what_doing <= 1) {
15171533
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));
15191535
if(*Edit_pos == '\0') Edit_pos--;
15201536
}
15211537
} else {
15221538
FuriString *fs = Log[view_Batch];
15231539
if(is_digit(Edit_pos + 1, Edit_hex) || (Edit_pos > Edit_start && is_digit(Edit_pos - 1, Edit_hex))) {
15241540
memmove(Edit_pos, Edit_pos + 1, strlen(Edit_pos));
1541+
if(*Edit_pos == '\0') Edit_pos--;
15251542
furi_string_left(fs, furi_string_size(fs) - 1);
15261543
}
15271544
}

0 commit comments

Comments
 (0)