Skip to content

Commit 0696369

Browse files
committed
repeat read cmd (long press OK in received read cmd screen)
1 parent 401bed5 commit 0696369

File tree

3 files changed

+51
-29
lines changed

3 files changed

+51
-29
lines changed

Distr/nrf24batch/CO2_mini.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ DPL: 0
77
RETR: 0x0F
88
Resend: 3
99
Delay_ms: 30
10+
Read repeat: 10
1011

1112
Payload struct: 2,1,1
1213
EEPROM=0; RAM=1; PROGMEM=2; ID=3; RESET=4

lib/nrf24/nrf24.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ uint8_t nrf24_read_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t* data,
5757
}
5858

5959
uint8_t nrf24_read_register(FuriHalSpiBusHandle* handle, uint8_t reg) {
60-
uint8_t buf[] = { R_REGISTER | (REGISTER_MASK & reg), 0xFF };
60+
uint8_t buf[] = { R_REGISTER | (REGISTER_MASK & reg), 0 };
6161
nrf24_spi_trx(handle, buf, buf, 2);
6262
return buf[1];
6363
}

nrf24batch.c

+49-28
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <u8g2.h>
1515

1616
#define TAG "nrf24batch"
17-
#define VERSION "1.4"
17+
#define VERSION "1.5"
1818

1919
#define SCAN_APP_PATH_FOLDER "/ext/nrf24batch"
2020
#define LOG_FILEEXT ".txt"
@@ -42,6 +42,7 @@ const char SettingsFld_Set[] = "S:"; // Set cmd (like Write but without "Write s
4242
const char SettingsFld_ReadBatch[] = "RBatch:";
4343
const char SettingsFld_WriteBatch[] = "WBatch:";
4444
const char SettingsFld_Listen[] = "Listen:";
45+
const char SettingsFld_ReadRepeatPeriod[] = "Read repeat:";
4546
const char AskQuestion_Save[] = "SAVE BATCH?";
4647
#define Settings_i 'i'
4748
#define Settings_n 'n'
@@ -88,8 +89,10 @@ uint8_t NRF_INITED = 0; // 0 - not, 1 - rw, rwt_listen - listen
8889
bool NRF_BOARD_POWER_5V = false;
8990
uint8_t NRF_last_packet_send_st = 0;
9091
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)
9293
uint32_t NRF_time;
94+
uint16_t ReadRepeatPeriod = 10; // s
95+
bool ReadRepeat = false;
9396
uint32_t delay_between_pkt = 10;// ms
9497

9598
uint8_t addr[5]; // nRF24 address, MSB first
@@ -423,7 +426,7 @@ bool nrf24_read_newpacket() {
423426
furi_string_cat_str(str, ",");
424427
if(cmd_array_hex) furi_string_cat_str(str, "0x");
425428
payload[cmd_array_idx]++; // next array element
426-
NRF_repeat = 0;
429+
NRF_repeat = -1;
427430
send_status = sst_sending; // Will be send after delay_between_pkt
428431
} else send_status = sst_ok;
429432
} else {
@@ -768,6 +771,8 @@ static uint8_t load_settings_file() {
768771
NRF_resend = str_to_int(p + sizeof(SettingsFld_Resend));
769772
} else if(strncmp(p, SettingsFld_Delay, sizeof(SettingsFld_Delay)-1) == 0) {
770773
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));
771776
} else if(strncmp(p, SettingsFld_Payload, sizeof(SettingsFld_Payload)-1) == 0) {
772777
p += sizeof(SettingsFld_Payload);
773778
payload_fields = 0;
@@ -1013,7 +1018,10 @@ static void render_callback(Canvas* const canvas, void* ctx) {
10131018
} else { // what_doing == 2
10141019
if(rw_type == rwt_read_cmd) { // Read command
10151020
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+
}
10171025
if(NRF_ERROR) strcat(screen_buf, "nRF24 ERROR!");
10181026
else if(ERR) {
10191027
snprintf(screen_buf + strlen(screen_buf), FONT_5x7_SCREEN_WIDTH, "ERROR %d", ERR);
@@ -1155,30 +1163,29 @@ void work_timer_callback(void* ctx)
11551163
}
11561164
// ReadBatch or ReadCmd
11571165
} 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+
}
11651171
} else if(send_status == sst_receiving) { // receiving
11661172
for(uint8_t i = 0; i < 3; i++) {
1167-
bool new = nrf24_read_newpacket();
1168-
if(new) {
1173+
if(nrf24_read_newpacket()) {
11691174
if(rw_type == rwt_listen) {
11701175
ListenPrev = ListenLast;
11711176
furi_hal_rtc_get_datetime(&ListenLastTime);
11721177
ListenLast = furi_hal_rtc_datetime_to_timestamp(&ListenLastTime);
11731178
ListenNew = true;
11741179
} 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+
}
11821189
}
11831190
break;
11841191
}
@@ -1237,6 +1244,12 @@ int32_t nrf24batch_app(void* p) {
12371244
FuriLogLevel = furi_log_get_level();
12381245
if(FuriLogLevel == FuriLogLevelDebug) furi_hal_uart_set_br(FuriHalUartIdUSART1, 1843200);
12391246
}
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+
}
12401253

12411254
if(event_status == FuriStatusOk) {
12421255
// press events
@@ -1449,7 +1462,11 @@ int32_t nrf24batch_app(void* p) {
14491462
what_doing = 2;
14501463
}
14511464
} 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) {
14531470
if(rw_type == rwt_read_batch) {
14541471
ask_question = ask_save_batch;
14551472
ask_question_answer = 0;
@@ -1503,13 +1520,17 @@ int32_t nrf24batch_app(void* p) {
15031520
Edit = 1;
15041521
NRF_INITED = false;
15051522
}
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+
}
15131534
}
15141535
}
15151536
}

0 commit comments

Comments
 (0)