vad7 2 лет назад
Родитель
Сommit
700ec39274
2 измененных файлов с 57 добавлено и 36 удалено
  1. 7 3
      Distr/nrf24batch/CO2_mini.txt
  2. 50 33
      nrf24batch.c

+ 7 - 3
Distr/nrf24batch/CO2_mini.txt

@@ -47,13 +47,17 @@ W: FanLSB=,i:9
 R: Send pause=19
 W: Send pause=,19
 
+R: Flags=20#
+W: Flags=,20
+
 W: Reset=,RESET,0xC1
 
-RBatch: Settings: ID;RxAddr;Ch;Send period;CO2 threshold;CO2 correct;FanLSB;nRF RETR;OSCCAL
+RBatch: Settings: ID;RxAddr;Ch;Send period;CO2 threshold;CO2 correct;FanLSB;nRF RETR;Send pause;Flags
 
-WBatch: Default: RxAddr=0xCF;Ch=122;Send period=30;CO2 threshold=1000;CO2 correct=0;FanLSB={0xC1,0};nRF RETR=0x17;Reset
+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
 WBatch: CO2: CO2 threshold=1000;CO2 correct=0
-WBatch: Fan2: FanLSB={0xC1,0,0,0,0,0,0};Reset
+WBatch: Fan: FanLSB={0xC1,0,0,0,0,0,0,0,0,0};Reset
 WBatch: RETR: nRF RETR=0x2F;Reset
 WBatch: Send pause: Send pause=30
+WBatch: Flags: Flags=0x00
 WBatch: Reset: Reset

+ 50 - 33
nrf24batch.c

@@ -173,7 +173,7 @@ static bool is_digit(char *ptr, bool hex)
 	if(hex) {
 		c &= ~0x20;
 		if(c >= 'A' && c <= 'F') return true;
-	}
+	} else if(c == '-') return true;
 	return false;
 }
 
@@ -218,6 +218,29 @@ static void add_to_str_hex_bytes(char *out, uint8_t *arr, int bytes)
 	} while(--bytes);
 }
 
+void Edit_insert_digit(char new)
+{
+	if(*Edit_pos == '-') return;
+	if(what_doing <= 1) {
+		if(strlen(Edit_start) < (what_doing == 0 && setup_cursor == 2 ? 3 : 5 * 2)) {
+			memmove(Edit_pos + 1, Edit_pos, strlen(Edit_pos) + 1);
+			*Edit_pos = new;
+		}
+	} else {
+		FuriString *fs = Log[view_Batch];
+		FuriString *ns = furi_string_alloc();
+		if(ns) {
+			uint16_t len = Edit_pos - (char*)furi_string_get_cstr(fs);
+			furi_string_set_n(ns, fs, 0, len);
+			furi_string_cat_printf(ns, "%c", new);
+			furi_string_cat_str(ns, Edit_pos);
+			furi_string_free(fs);
+			Log[view_Batch] = ns;
+			Edit_pos = (char*)furi_string_get_cstr(ns) + len;
+		}
+	}
+}
+
 int32_t get_payload_receive_field(uint8_t *var, uint8_t size)
 {
 	if(size <= 1) return *var;
@@ -361,7 +384,7 @@ static void prepare_nrf24(void)
 			NRF_INITED = 0;
 			return;
 		}
-		// EN_DYN_ACK(0x01) option for W_TX_PAYLOAD_NOACK cmd broke AA on some fake nRF24l01+ modules
+		// EN_DYN_ACK(0x01) option for W_TX_PAYLOAD_NOACK cmd broke AA on some fake nRF24l01+, i.e. set it to 0
 		nrf24_write_reg(nrf24_HANDLE, REG_FEATURE, (NRF_DPL ? 4 : 0)); // Dynamic Payload, Payload with ACK, W_TX_PAYLOAD_NOACK command
 		nrf24_write_reg(nrf24_HANDLE, REG_RF_CH, NRF_channel);
 		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) {
 					if(event.input.type == InputTypeShort || event.input.type == InputTypeRepeat) {
 						if(!ask_question) {
 							if(Edit) {
-								if(*Edit_pos < '9') (*Edit_pos)++;
-								else if(Edit_hex) {
-									if(*Edit_pos == '9') *Edit_pos = 'A';
-									else if((*Edit_pos & ~0x20) < 'F') (*Edit_pos)++;
-								} else if(Edit_pos > Edit_start && *(Edit_pos - 1) < '9') {
-									*Edit_pos = '0';
-									(*(Edit_pos - 1))++;
+								if(*Edit_pos != '-') {
+									if(*Edit_pos < '9') (*Edit_pos)++;
+									else if(Edit_hex) {
+										if(*Edit_pos == '9') *Edit_pos = 'A';
+										else if((*Edit_pos & ~0x20) < 'F') (*Edit_pos)++;
+									} else if(Edit_pos > Edit_start && *(Edit_pos - 1) < '9' && *(Edit_pos - 1) >= '0') {
+										*Edit_pos = '0';
+										(*(Edit_pos - 1))++;
+									}
 								}
 							} else if(what_doing == 0) {
 								if(addr_len) {
@@ -1316,11 +1341,19 @@ int32_t nrf24batch_app(void* p) {
 					if(event.input.type == InputTypeShort || event.input.type == InputTypeRepeat) {
 						if(!ask_question) {
 							if(Edit) {
-								if(Edit_hex && (*Edit_pos & ~0x20) == 'A') (*Edit_pos) = '9';
-								else if(*Edit_pos > '0') (*Edit_pos)--;
-								else if(!Edit_hex && Edit_pos > Edit_start && *(Edit_pos - 1) > '0') {
-									*Edit_pos = '9';
-									(*(Edit_pos - 1))--;
+								if(*Edit_pos != '-') {
+									if(Edit_hex && (*Edit_pos & ~0x20) == 'A') (*Edit_pos) = '9';
+									else if(*Edit_pos > '0') (*Edit_pos)--;
+									else if(!Edit_hex) {
+										if(Edit_pos > Edit_start) {
+											if(*(Edit_pos - 1) > '0') {
+												*Edit_pos = '9';
+												(*(Edit_pos - 1))--;
+											}
+										} else if(strlen(Edit_start) == 1) { // negative
+											Edit_insert_digit('-');
+										}
+									}
 								}
 							} else if(what_doing == 0) {
 								if(addr_len) {
@@ -1415,24 +1448,7 @@ int32_t nrf24batch_app(void* p) {
 							}
 							ask_question = 0;
 						} else if(Edit) { // insert digit
-							if(what_doing <= 1) {
-								if(strlen(Edit_start) < (what_doing == 0 && setup_cursor == 2 ? 3 : 5 * 2)) {
-									memmove(Edit_pos + 1, Edit_pos, strlen(Edit_pos) + 1);
-									*Edit_pos = '0';
-								}
-							} else {
-								FuriString *fs = Log[view_Batch];
-								FuriString *ns = furi_string_alloc();
-								if(ns) {
-									uint16_t len = Edit_pos - (char*)furi_string_get_cstr(fs);
-									furi_string_set_n(ns, fs, 0, len);
-									furi_string_cat_str(ns, "0");
-									furi_string_cat_str(ns, Edit_pos);
-									furi_string_free(fs);
-									Log[view_Batch] = ns;
-									Edit_pos = (char*)furi_string_get_cstr(ns) + len;
-								}
-							}
+							Edit_insert_digit('0');
 						} else if(what_doing == 0) {
 							if(setup_cursor == 0) { // open file
 								file_stream_close(file_stream);
@@ -1515,13 +1531,14 @@ int32_t nrf24batch_app(void* p) {
 						if(Edit) { // delete
 							if(what_doing <= 1) {
 								if(strlen(Edit_start) > 1) {
-									memmove(Edit_pos, Edit_pos + 1, strlen(Edit_pos) + 1);
+									memmove(Edit_pos, Edit_pos + 1, strlen(Edit_pos));
 									if(*Edit_pos == '\0') Edit_pos--;
 								}
 							} else {
 								FuriString *fs = Log[view_Batch];
 								if(is_digit(Edit_pos + 1, Edit_hex) || (Edit_pos > Edit_start && is_digit(Edit_pos - 1, Edit_hex))) { 
 									memmove(Edit_pos, Edit_pos + 1, strlen(Edit_pos));
+									if(*Edit_pos == '\0') Edit_pos--;
 									furi_string_left(fs, furi_string_size(fs) - 1);
 								}
 							}