|
14 | 14 | #include <u8g2.h>
|
15 | 15 |
|
16 | 16 | #define TAG "nrf24batch"
|
17 |
| -#define VERSION "1.4" |
| 17 | +#define VERSION "1.5" |
18 | 18 |
|
19 | 19 | #define SCAN_APP_PATH_FOLDER "/ext/nrf24batch"
|
20 | 20 | #define LOG_FILEEXT ".txt"
|
@@ -42,6 +42,7 @@ const char SettingsFld_Set[] = "S:"; // Set cmd (like Write but without "Write s
|
42 | 42 | const char SettingsFld_ReadBatch[] = "RBatch:";
|
43 | 43 | const char SettingsFld_WriteBatch[] = "WBatch:";
|
44 | 44 | const char SettingsFld_Listen[] = "Listen:";
|
| 45 | +const char SettingsFld_ReadRepeatPeriod[] = "Read repeat:"; |
45 | 46 | const char AskQuestion_Save[] = "SAVE BATCH?";
|
46 | 47 | #define Settings_i 'i'
|
47 | 48 | #define Settings_n 'n'
|
@@ -88,8 +89,10 @@ uint8_t NRF_INITED = 0; // 0 - not, 1 - rw, rwt_listen - listen
|
88 | 89 | bool NRF_BOARD_POWER_5V = false;
|
89 | 90 | uint8_t NRF_last_packet_send_st = 0;
|
90 | 91 | uint8_t NRF_resend = 1; // number of transaction attempts
|
91 |
| -uint8_t NRF_repeat = 0; // count number of repeated requests (until < NRF_resend) |
| 92 | +int8_t NRF_repeat = 0; // count number of repeated requests (until < NRF_resend) |
92 | 93 | uint32_t NRF_time;
|
| 94 | +uint16_t ReadRepeatPeriod = 10; // s |
| 95 | +bool ReadRepeat = false; |
93 | 96 | uint32_t delay_between_pkt = 10;// ms
|
94 | 97 |
|
95 | 98 | uint8_t addr[5]; // nRF24 address, MSB first
|
@@ -423,7 +426,7 @@ bool nrf24_read_newpacket() {
|
423 | 426 | furi_string_cat_str(str, ",");
|
424 | 427 | if(cmd_array_hex) furi_string_cat_str(str, "0x");
|
425 | 428 | payload[cmd_array_idx]++; // next array element
|
426 |
| - NRF_repeat = 0; |
| 429 | + NRF_repeat = -1; |
427 | 430 | send_status = sst_sending; // Will be send after delay_between_pkt
|
428 | 431 | } else send_status = sst_ok;
|
429 | 432 | } else {
|
@@ -768,6 +771,8 @@ static uint8_t load_settings_file() {
|
768 | 771 | NRF_resend = str_to_int(p + sizeof(SettingsFld_Resend));
|
769 | 772 | } else if(strncmp(p, SettingsFld_Delay, sizeof(SettingsFld_Delay)-1) == 0) {
|
770 | 773 | delay_between_pkt = str_to_int(p + sizeof(SettingsFld_Delay));
|
| 774 | + } else if(strncmp(p, SettingsFld_ReadRepeatPeriod, sizeof(SettingsFld_ReadRepeatPeriod)-1) == 0) { |
| 775 | + ReadRepeatPeriod = str_to_int(p + sizeof(SettingsFld_ReadRepeatPeriod)); |
771 | 776 | } else if(strncmp(p, SettingsFld_Payload, sizeof(SettingsFld_Payload)-1) == 0) {
|
772 | 777 | p += sizeof(SettingsFld_Payload);
|
773 | 778 | payload_fields = 0;
|
@@ -1013,7 +1018,10 @@ static void render_callback(Canvas* const canvas, void* ctx) {
|
1013 | 1018 | } else { // what_doing == 2
|
1014 | 1019 | if(rw_type == rwt_read_cmd) { // Read command
|
1015 | 1020 | canvas_set_font(canvas, FontSecondary); // 8x10 font, 6 lines
|
1016 |
| - if(!ask_fill_screen_buf()) strcpy(screen_buf, "Read cmd: "); |
| 1021 | + if(!ask_fill_screen_buf()) { |
| 1022 | + strcpy(screen_buf, "Read "); |
| 1023 | + strcat(screen_buf, ReadRepeat ? "rep: " : "cmd: "); |
| 1024 | + } |
1017 | 1025 | if(NRF_ERROR) strcat(screen_buf, "nRF24 ERROR!");
|
1018 | 1026 | else if(ERR) {
|
1019 | 1027 | snprintf(screen_buf + strlen(screen_buf), FONT_5x7_SCREEN_WIDTH, "ERROR %d", ERR);
|
@@ -1155,30 +1163,29 @@ void work_timer_callback(void* ctx)
|
1155 | 1163 | }
|
1156 | 1164 | // ReadBatch or ReadCmd
|
1157 | 1165 | } else if(send_status == sst_sending) { // sending
|
1158 |
| -// if(!NRF_last_packet_send_st) { // No ACK on last attempt |
1159 |
| - if(furi_get_tick() - NRF_time > delay_between_pkt) { |
1160 |
| - if(NRF_repeat++ < NRF_resend) { |
1161 |
| - if(cmd_array) nrf24_send_packet(); else nrf24_resend_read_packet(); |
1162 |
| - } else send_status = sst_error; // error NO_ACK |
1163 |
| - } |
1164 |
| -// } |
| 1166 | + if(furi_get_tick() - NRF_time > delay_between_pkt) { |
| 1167 | + if(NRF_repeat++ < NRF_resend) { |
| 1168 | + nrf24_resend_read_packet(); |
| 1169 | + } else send_status = sst_error; // error NO_ACK |
| 1170 | + } |
1165 | 1171 | } else if(send_status == sst_receiving) { // receiving
|
1166 | 1172 | for(uint8_t i = 0; i < 3; i++) {
|
1167 |
| - bool new = nrf24_read_newpacket(); |
1168 |
| - if(new) { |
| 1173 | + if(nrf24_read_newpacket()) { |
1169 | 1174 | if(rw_type == rwt_listen) {
|
1170 | 1175 | ListenPrev = ListenLast;
|
1171 | 1176 | furi_hal_rtc_get_datetime(&ListenLastTime);
|
1172 | 1177 | ListenLast = furi_hal_rtc_datetime_to_timestamp(&ListenLastTime);
|
1173 | 1178 | ListenNew = true;
|
1174 | 1179 | } else if(send_status != sst_receiving) break;
|
1175 |
| - } else if(rw_type != rwt_listen && furi_get_tick() - NRF_time > NRF_READ_TIMEOUT) { |
1176 |
| - if(NRF_repeat++ < NRF_resend) { |
1177 |
| - send_status = sst_sending; |
1178 |
| - nrf24_resend_read_packet(); |
1179 |
| - } else { |
1180 |
| - FURI_LOG_D(TAG, "TIMEOUT: %lu", furi_get_tick() - NRF_time); |
1181 |
| - send_status = sst_timeout; |
| 1180 | + } else { |
| 1181 | + if(rw_type != rwt_listen && furi_get_tick() - NRF_time > NRF_READ_TIMEOUT) { |
| 1182 | + if(NRF_repeat++ < NRF_resend) { |
| 1183 | + send_status = sst_sending; |
| 1184 | + nrf24_resend_read_packet(); |
| 1185 | + } else { |
| 1186 | + FURI_LOG_D(TAG, "TIMEOUT: %lu", furi_get_tick() - NRF_time); |
| 1187 | + send_status = sst_timeout; |
| 1188 | + } |
1182 | 1189 | }
|
1183 | 1190 | break;
|
1184 | 1191 | }
|
@@ -1237,6 +1244,12 @@ int32_t nrf24batch_app(void* p) {
|
1237 | 1244 | FuriLogLevel = furi_log_get_level();
|
1238 | 1245 | if(FuriLogLevel == FuriLogLevelDebug) furi_hal_uart_set_br(FuriHalUartIdUSART1, 1843200);
|
1239 | 1246 | }
|
| 1247 | + if(what_doing == 2 && rw_type == rwt_read_cmd && ReadRepeat && furi_get_tick() - NRF_time > (uint32_t)(ReadRepeatPeriod * 1000)) { |
| 1248 | + ERR = 0; |
| 1249 | + free_Log(); |
| 1250 | + Run_Read_cmd(Read_cmd[view_cmd[rwt_read_cmd]]); |
| 1251 | + notification_message(APP->notification, &sequence_blink_blue_100); |
| 1252 | + } |
1240 | 1253 |
|
1241 | 1254 | if(event_status == FuriStatusOk) {
|
1242 | 1255 | // press events
|
@@ -1449,7 +1462,11 @@ int32_t nrf24batch_app(void* p) {
|
1449 | 1462 | what_doing = 2;
|
1450 | 1463 | }
|
1451 | 1464 | } else if(what_doing == 2) {
|
1452 |
| - if(Log_Total) { |
| 1465 | + if(rw_type == rwt_read_cmd) { |
| 1466 | + ERR = 0; |
| 1467 | + free_Log(); |
| 1468 | + Run_Read_cmd(Read_cmd[view_cmd[rwt_read_cmd]]); |
| 1469 | + } else if(Log_Total) { |
1453 | 1470 | if(rw_type == rwt_read_batch) {
|
1454 | 1471 | ask_question = ask_save_batch;
|
1455 | 1472 | ask_question_answer = 0;
|
@@ -1503,13 +1520,17 @@ int32_t nrf24batch_app(void* p) {
|
1503 | 1520 | Edit = 1;
|
1504 | 1521 | NRF_INITED = false;
|
1505 | 1522 | }
|
1506 |
| - } else if(what_doing == 2 && Log_Total) { |
1507 |
| - if(rw_type == rwt_write_batch) { |
1508 |
| - ask_question = ask_write_batch; |
1509 |
| - ask_question_answer = 0; |
1510 |
| - } else if(rw_type == rwt_read_batch) { |
1511 |
| - ask_question = ask_save_batch; |
1512 |
| - ask_question_answer = 0; |
| 1523 | + } else if(what_doing == 2) { |
| 1524 | + if(rw_type == rwt_read_cmd) { |
| 1525 | + ReadRepeat = !ReadRepeat; |
| 1526 | + } else if(Log_Total) { |
| 1527 | + if(rw_type == rwt_write_batch) { |
| 1528 | + ask_question = ask_write_batch; |
| 1529 | + ask_question_answer = 0; |
| 1530 | + } else if(rw_type == rwt_read_batch) { |
| 1531 | + ask_question = ask_save_batch; |
| 1532 | + ask_question_answer = 0; |
| 1533 | + } |
1513 | 1534 | }
|
1514 | 1535 | }
|
1515 | 1536 | }
|
|
0 commit comments