Просмотр исходного кода

Nrf24Batch: Port save, gpio, appid, hex changes

Willy-JL 2 лет назад
Родитель
Сommit
caeba44953
4 измененных файлов с 38 добавлено и 18 удалено
  1. 1 1
      nrf24batch/application.fam
  2. 16 0
      nrf24batch/lib/nrf24/nrf24.c
  3. 4 1
      nrf24batch/lib/nrf24/nrf24.h
  4. 17 16
      nrf24batch/nrf24batch.c

+ 1 - 1
nrf24batch/application.fam

@@ -1,5 +1,5 @@
 App(
-    appid="nrf24_batch",
+    appid="nrf24batch",
     name="[NRF24] Batch",
     apptype=FlipperAppType.EXTERNAL,
     entry_point="nrf24batch_app",

+ 16 - 0
nrf24batch/lib/nrf24/nrf24.c

@@ -8,6 +8,15 @@
 #include <string.h>
 
 void nrf24_init() {
+    // this is needed if multiple SPI devices are connected to the same bus but with different CS pins
+    if(xtreme_settings.spi_nrf24_handle == SpiDefault) {
+        furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull);
+        furi_hal_gpio_write(&gpio_ext_pc3, true);
+    } else if(xtreme_settings.spi_nrf24_handle == SpiExtra) {
+        furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeOutputPushPull);
+        furi_hal_gpio_write(&gpio_ext_pa4, true);
+    }
+
     furi_hal_spi_bus_handle_init(nrf24_HANDLE);
     furi_hal_spi_acquire(nrf24_HANDLE);
     furi_hal_gpio_init(nrf24_CE_PIN, GpioModeOutputPushPull, GpioPullUp, GpioSpeedVeryHigh);
@@ -19,6 +28,13 @@ void nrf24_deinit() {
     furi_hal_spi_bus_handle_deinit(nrf24_HANDLE);
     furi_hal_gpio_write(nrf24_CE_PIN, false);
     furi_hal_gpio_init(nrf24_CE_PIN, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+
+    // resetting the CS pins to floating
+    if(xtreme_settings.spi_nrf24_handle == SpiDefault) {
+        furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog);
+    } else if(xtreme_settings.spi_nrf24_handle == SpiExtra) {
+        furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeAnalog);
+    }
 }
 
 void nrf24_spi_trx(

+ 4 - 1
nrf24batch/lib/nrf24/nrf24.h

@@ -2,6 +2,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <furi_hal_spi.h>
+#include <xtreme.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -54,7 +55,9 @@ extern "C" {
 
 #define nrf24_TIMEOUT 500
 #define nrf24_CE_PIN &gpio_ext_pb2
-#define nrf24_HANDLE &furi_hal_spi_bus_handle_external
+#define nrf24_HANDLE                                                                         \
+    (xtreme_settings.spi_nrf24_handle == SpiDefault ? &furi_hal_spi_bus_handle_external : \
+                                                         &furi_hal_spi_bus_handle_external_extra)
 
 /* Low level API */
 

+ 17 - 16
nrf24batch/nrf24batch.c

@@ -16,7 +16,7 @@
 #define TAG 		"nrf24batch"
 #define VERSION		"1.9"
 
-#define SCAN_APP_PATH_FOLDER 	"/ext/nrf24batch"
+#define SCAN_APP_PATH_FOLDER 	STORAGE_APP_DATA_PATH_PREFIX
 #define LOG_FILEEXT	 			".txt"
 #define NRF_READ_TIMEOUT		300UL	// ms
 #define WORK_PERIOD				2		// ms, Timer period
@@ -73,7 +73,7 @@ uint8_t send_status = sst_none;// sst_*
 bool cmd_array = false;
 uint8_t cmd_array_idx;
 uint8_t cmd_array_cnt = 0;
-uint8_t cmd_array_type;				//  0 - auto, 1 - hex, 2 - decimal
+bool cmd_array_hex;
 uint8_t save_settings = 0;
 uint16_t view_cmd[rwt_max - 1] = {0}; // SetBatch, ReadBatch, Read, WriteBatch
 uint8_t view_x = 0;
@@ -499,16 +499,16 @@ bool nrf24_read_newpacket() {
 				char hex[9];
 				hex[0] = '\0';
 				add_to_str_hex_variable(hex, (uint8_t*)&var, size);
-				if((cmd_array && cmd_array_type == 1) || furi_string_end_with_str(str, "0x")) furi_string_cat_str(str, hex);
+				if((cmd_array && cmd_array_hex) || furi_string_end_with_str(str, "0x")) furi_string_cat_str(str, hex);
 				else {
-					if((var >= 0 && var <= 9) || cmd_array_type == 2) furi_string_cat_printf(str, "%ld", var);
+					if(var >= 0 && var <= 9) furi_string_cat_printf(str, "%ld", var);
 					else furi_string_cat_printf(str, "%ld (%s)", var, hex);
 				}
 			}
 			if(cmd_array) {
 				if(--cmd_array_cnt) {
 					furi_string_cat_str(str, ",");
-					if(cmd_array_type == 1) furi_string_cat_str(str, "0x");
+					if(cmd_array_hex) furi_string_cat_str(str, "0x");
 					payload[cmd_array_idx] += size;	// next array element
 					NRF_repeat = -1;
 					send_status = sst_sending;	// Will be send after delay_between_pkt
@@ -571,7 +571,7 @@ bool fill_payload(char *p, uint8_t *idx_i, int32_t var_n)
 			if(end) len =  end - p;
 			else {
 				len = strlen(p);
-				if(*(p + len - 1) == '#' || *(p + len - 1) == '$') len--;
+				if(*(p + len - 1) == '#') len--;
 			}
 			b = subs_constant(p, len);
 			if(b == VAR_EMPTY) {
@@ -584,7 +584,7 @@ bool fill_payload(char *p, uint8_t *idx_i, int32_t var_n)
 			}
 		} else if(end == p) {
 			idx += payload_struct[fld];
-		} else if(*p == '#' || *p == '$') { // value forced in Hex/Dec, end string
+		} else if(*p == '#') { // value in Hexadecimal, end string
 			break;
 		} else {
 			ERR = 2;
@@ -624,10 +624,9 @@ bool Run_Read_cmd(FuriString *cmd)
 	FuriString *fs = furi_string_alloc();
 	furi_string_set_strn(fs, (char*)furi_string_get_cstr(cmd), p - (char*)furi_string_get_cstr(cmd));
 	furi_string_cat_str(fs, ": ");
-	uint8_t valtype;
-	char c = *(p + strlen(p) - 1);
-	valtype = c == '#' ? 1 : c == '$' ? 2 : 0;
-	if(valtype == 1) furi_string_cat_str(fs, "0x"); // value in Hex format
+    bool hexval;
+    if((hexval = *(p + strlen(p) - 1) == '#'))
+        furi_string_cat_str(fs, "0x"); // value in Hex format
 	Log[Log_Total++] = fs;
 	p++;
 	memset(payload, 0, sizeof(payload));
@@ -640,7 +639,7 @@ bool Run_Read_cmd(FuriString *cmd)
 		if(p) {
 			cmd_array_cnt = str_to_int(p + 1);
 			if(cmd_array_cnt > 1) {
-				cmd_array_type = valtype;
+				cmd_array_hex = hexval;
 				cmd_array = true; // array
 			}
 		}
@@ -1178,22 +1177,23 @@ static void render_callback(Canvas* const canvas, void* ctx) {
 			canvas_draw_str(canvas, 0, 10, screen_buf);
 			if(ListenFields) {
 				char *p2, *p = ListenFields;
-				uint8_t valtype, len, *pld = payload_receive;
+				uint8_t hex, len, *pld = payload_receive;
 				for(uint8_t i = 0; i < 5 && *p; i++) {
+                    hex = false;
 					p2 = strchr(p, ',');
 					if(p2 == NULL) p2 = p + strlen(p);
-					valtype = *(p2 - 1) == '#' ? 1 : *(p2 - 1) == '$' ? 2 : 0;
+					if(*(p2 - 1) == '#') hex = true;
 					memcpy(screen_buf, p, len = p2 - p);
 					strcpy(screen_buf + len, ": ");
 					if(ListenNew) {
 						len = payload_struct[i];
 						int32_t n = get_payload_receive_field(pld, len);
-						if(valtype == 1) {
+						if(hex) {
 							strcat(screen_buf, "0x");
 							add_to_str_hex_variable(screen_buf, pld, len);
 						} else {
 							snprintf(screen_buf + strlen(screen_buf), 20, "%ld", n);
-							if(n > 9 && valtype == 0) {
+							if(n > 9) {
 								strcat(screen_buf, " (");
 								add_to_str_hex_variable(screen_buf, pld, len);
 								strcat(screen_buf, ")");
@@ -1403,6 +1403,7 @@ int32_t nrf24batch_app(void* p) {
 	gui_add_view_port(APP->gui, view_port, GuiLayerFullscreen);
 	APP->notification = furi_record_open(RECORD_NOTIFICATION);
 	APP->storage = furi_record_open(RECORD_STORAGE);
+    storage_common_migrate(APP->storage, EXT_PATH("nrf24batch"), SCAN_APP_PATH_FOLDER);
 	storage_common_mkdir(APP->storage, SCAN_APP_PATH_FOLDER);
 	file_stream = file_stream_alloc(APP->storage);
 	FuriTimer *work_timer = furi_timer_alloc(work_timer_callback, FuriTimerTypePeriodic, APP->plugin_state);