16
16
#define TAG "nrf24batch"
17
17
#define VERSION "1.2"
18
18
19
- #define SCAN_APP_PATH_FOLDER "/ext/nrf24batch"
20
- #define LOG_FILENAME "log"
21
- #define LOG_FILEEXT ".txt"
22
- #define NRF_READ_TIMEOUT 300UL // ms
23
- #define WORK_PERIOD 2 // ms, Timer period
19
+ #define SCAN_APP_PATH_FOLDER "/ext/nrf24batch"
20
+ #define LOG_FILEEXT ".txt"
21
+ #define NRF_READ_TIMEOUT 300UL // ms
22
+ #define WORK_PERIOD 2 // ms, Timer period
23
+ #define MAX_CHANNEL 125
24
+ #define FONT_5x7_SCREEN_WIDTH 25
24
25
25
26
const char SettingsFld_Info [] = "Info:" ;
26
27
const char SettingsFld_Ch [] = "Ch:" ;
@@ -43,7 +44,6 @@ const char AskQuestion_Save[] = "SAVE BATCH?";
43
44
#define Settings_i 'i'
44
45
#define Settings_n 'n'
45
46
#define VAR_EMPTY ((int32_t)0x80000000)
46
- #define FONT_5x7_SCREEN_WIDTH 25
47
47
48
48
nRF24Batch * APP ;
49
49
uint8_t what_doing = 0 ; // 0 - setup, 1 - cmd list, 2 - view send cmd
@@ -86,6 +86,7 @@ uint8_t NRF_last_packet_send_st = 0;
86
86
uint8_t NRF_resend = 1 ; // number of transaction attempts
87
87
uint8_t NRF_repeat = 0 ; // count number of repeated requests (until < NRF_resend)
88
88
uint32_t NRF_time ;
89
+ uint32_t delay_between_pkt = 10 ;// ms
89
90
90
91
uint8_t addr [5 ]; // nRF24 address, MSB first
91
92
uint8_t addr_len ; // 2..5
@@ -96,11 +97,12 @@ uint8_t payload_fields = 0;
96
97
uint8_t payload_size = 0 ; // bytes
97
98
uint16_t view_Batch = 0 ; // view pos in Batch or inside WriteBatch (Log[view_Batch])
98
99
uint16_t view_WriteBatch = 0 ; // view pos of WriteBatch list
99
- uint32_t delay_between_pkt = 10 ; // ms
100
+ uint8_t setup_cursor = 0 ; // cursor position on Setup scr
100
101
uint8_t Edit = 0 ;
101
102
char * Edit_pos ;
103
+ char * Edit_start ;
102
104
bool Edit_hex ; // 0 - decimal, 1 - hex
103
- bool Edited = false;
105
+ bool Edited = false; // list of cmds edited
104
106
105
107
Stream * file_stream = NULL ;
106
108
FuriString * ReadDefault = NULL ;
@@ -895,23 +897,46 @@ static void render_callback(Canvas* const canvas, void* ctx) {
895
897
//canvas_draw_frame(canvas, 0, 0, 128, 64); // border around the edge of the screen
896
898
if (what_doing == 0 ) {
897
899
canvas_set_font (canvas , FontSecondary ); // 8x10 font, 6 lines
898
- snprintf (screen_buf , sizeof (screen_buf ), "Open : %s" , file_name );
899
- canvas_draw_str (canvas , 10 , 10 , screen_buf );
900
+ snprintf (screen_buf , sizeof (screen_buf ), "%s : %s" , addr_len ? "File" : "Open " , file_name );
901
+ canvas_draw_str (canvas , 8 , 10 , screen_buf );
900
902
if (addr_len ) {
901
- canvas_draw_str (canvas , 10 , 22 , Info );
902
- strcpy (screen_buf , "Address: " );
903
- add_to_str_hex_bytes (screen_buf , addr , addr_len );
904
- canvas_draw_str (canvas , 10 , 32 , screen_buf );
905
- snprintf (screen_buf , sizeof (screen_buf ), "Ch: %d, Rate: %d" , NRF_channel , NRF_rate );
906
- canvas_draw_str (canvas , 10 , 42 , screen_buf );
903
+ if (Edit ) {
904
+ screen_buf [0 ] = * Edit_pos ; screen_buf [1 ] = '\0' ;
905
+ int n = canvas_string_width (canvas , screen_buf );
906
+ int len = Edit_pos - Edit_start ;
907
+ memcpy (screen_buf , Edit_start , len );
908
+ screen_buf [len ] = '\0' ;
909
+ int x = setup_cursor == 1 ? 45 : 55 ;
910
+ x += canvas_string_width (canvas , screen_buf );
911
+ int len2 = strlen (Edit_pos );
912
+ memcpy (screen_buf + len , Edit_pos , len2 );
913
+ screen_buf [len + len2 ] = '\0' ;
914
+ int y = 10 + setup_cursor * 10 ;
915
+ if (setup_cursor == 1 ) canvas_draw_str (canvas , 45 , 20 , screen_buf );
916
+ else if (setup_cursor == 2 ) canvas_draw_str (canvas , 55 , 30 , screen_buf );
917
+ canvas_draw_line (canvas , x + (len ? 1 : 0 ), y + 1 , x + n + (* Edit_pos == '1' && len ? 1 : 0 ), y + 1 );
918
+ }
919
+ if (!Edit || setup_cursor != 1 ) {
920
+ screen_buf [0 ] = '\0' ;
921
+ add_to_str_hex_bytes (screen_buf , addr , addr_len );
922
+ canvas_draw_str (canvas , 45 , 20 , screen_buf );
923
+ }
924
+ if (!Edit || setup_cursor != 2 ) {
925
+ snprintf (screen_buf , sizeof (screen_buf ), "%d" , NRF_channel );
926
+ canvas_draw_str (canvas , 55 , 30 , screen_buf );
927
+ }
928
+ canvas_draw_str (canvas , 8 , 20 , "Address:" );
929
+ snprintf (screen_buf , sizeof (screen_buf ), "Rate: %d, Ch:" , NRF_rate );
930
+ canvas_draw_str (canvas , 8 , 30 , screen_buf );
907
931
snprintf (screen_buf , sizeof (screen_buf ), "RB: %d, R: %d, WB: %d" , ReadBatch_cmd_Total , Read_cmd_Total , WriteBatch_cmd_Total );
908
- canvas_draw_str (canvas , 10 , 52 , screen_buf );
909
- //canvas_draw_str(canvas, 10, 60, screen_buf);
932
+ canvas_draw_str (canvas , 8 , 40 , screen_buf );
933
+ canvas_draw_str (canvas , 0 , 64 , Info );
934
+ canvas_draw_str (canvas , 0 , 10 + setup_cursor * 10 , ">" );
910
935
} else {
911
936
snprintf (screen_buf , sizeof (screen_buf ), "Ver. %s, vad7" , VERSION );
912
937
canvas_draw_str (canvas , 10 , 60 , screen_buf );
938
+ canvas_draw_str (canvas , 0 , 10 , ">" );
913
939
}
914
- canvas_draw_str (canvas , 0 , 10 , ">" );
915
940
} else if (what_doing == 1 ){
916
941
canvas_set_font (canvas , FontBatteryPercent ); // 5x7 font, 9 lines, 25 cols
917
942
if (rw_type == rwt_read_batch ) {
@@ -1111,33 +1136,45 @@ int32_t nrf24batch_app(void* p) {
1111
1136
case InputKeyUp :
1112
1137
if (event .input .type == InputTypeShort || event .input .type == InputTypeRepeat ) {
1113
1138
if (!ask_question ) {
1114
- if (what_doing == 0 ) {
1139
+ if (Edit ) {
1140
+ if (* Edit_pos < '9' ) (* Edit_pos )++ ;
1141
+ else if (Edit_hex ) {
1142
+ if (* Edit_pos == '9' ) * Edit_pos = 'A' ;
1143
+ else if ((* Edit_pos & ~0x20 ) < 'F' ) (* Edit_pos )++ ;
1144
+ } else if (Edit_pos > Edit_start && * (Edit_pos - 1 ) < '9' ) {
1145
+ * Edit_pos = '0' ;
1146
+ (* (Edit_pos - 1 ))++ ;
1147
+ }
1148
+ } else if (what_doing == 0 ) {
1149
+ if (addr_len ) {
1150
+ if (setup_cursor > 0 ) setup_cursor -- ; else setup_cursor = 2 ;
1151
+ }
1115
1152
} else if (what_doing == 1 ) {
1116
1153
if (view_cmd [rw_type ]) view_cmd [rw_type ]-- ;
1117
1154
} else if (what_doing == 2 ) {
1118
- if (Edit ) {
1119
- if (* Edit_pos < '9' ) (* Edit_pos )++ ;
1120
- else if (Edit_hex ) {
1121
- if (* Edit_pos == '9' ) * Edit_pos = 'A' ;
1122
- else if ((* Edit_pos & ~0x20 ) < 'F' ) (* Edit_pos )++ ;
1123
- }
1124
- } else if (view_Batch ) view_Batch -- ;
1155
+ if (view_Batch ) view_Batch -- ;
1125
1156
}
1126
1157
}
1127
1158
}
1128
1159
break ;
1129
1160
case InputKeyDown :
1130
1161
if (event .input .type == InputTypeShort || event .input .type == InputTypeRepeat ) {
1131
1162
if (!ask_question ) {
1132
- if (what_doing == 0 ) {
1133
- what_doing = 1 ;
1163
+ if (Edit ) {
1164
+ if (Edit_hex && (* Edit_pos & ~0x20 ) == 'A' ) (* Edit_pos ) = '9' ;
1165
+ else if (* Edit_pos > '0' ) (* Edit_pos )-- ;
1166
+ else if (!Edit_hex && Edit_pos > Edit_start && * (Edit_pos - 1 ) > '0' ) {
1167
+ * Edit_pos = '9' ;
1168
+ (* (Edit_pos - 1 ))-- ;
1169
+ }
1170
+ } else if (what_doing == 0 ) {
1171
+ if (addr_len ) {
1172
+ if (setup_cursor < 2 ) setup_cursor ++ ; else setup_cursor = 0 ;
1173
+ }
1134
1174
} else if (what_doing == 1 ) {
1135
1175
if (view_cmd [rw_type ] + 1 < (rw_type == rwt_read_batch ? ReadBatch_cmd_Total : rw_type == rwt_read_cmd ? Read_cmd_Total : WriteBatch_cmd_Total )) view_cmd [rw_type ]++ ;
1136
1176
} else if (what_doing == 2 ) {
1137
- if (Edit ) {
1138
- if (Edit_hex && (* Edit_pos & ~0x20 ) == 'A' ) (* Edit_pos ) = '9' ;
1139
- else if (* Edit_pos > '0' ) (* Edit_pos )-- ;
1140
- } else if (view_Batch < Log_Total - 1 ) view_Batch ++ ;
1177
+ if (view_Batch < Log_Total - 1 ) view_Batch ++ ;
1141
1178
}
1142
1179
}
1143
1180
}
@@ -1146,17 +1183,21 @@ int32_t nrf24batch_app(void* p) {
1146
1183
if (event .input .type == InputTypeShort || event .input .type == InputTypeRepeat ) {
1147
1184
if (ask_question ) {
1148
1185
if (event .input .type == InputTypeShort ) ask_question_answer ^= 1 ;
1186
+ } else if (Edit ) {
1187
+ if (Edit_pos > Edit_start ) {
1188
+ if (is_digit (Edit_pos - 1 , Edit_hex )) Edit_pos -- ;
1189
+ else if (* (Edit_pos - 1 ) == 'x' && * (Edit_pos - 3 ) == ',' ) Edit_pos -= 4 ;
1190
+ else if (* (Edit_pos - 1 ) == ',' ) Edit_pos -= 2 ;
1191
+ }
1149
1192
} else if (what_doing == 0 ) {
1193
+ rw_type = rwt_write_batch ;
1194
+ what_doing = 1 ;
1150
1195
} else if (what_doing == 1 ) {
1151
1196
if (event .input .type == InputTypeShort ) {
1152
1197
if (-- rw_type > rwt_write_batch ) rw_type = rwt_write_batch ;
1153
1198
} else if (view_x ) view_x -- ;
1154
1199
} else if (what_doing == 2 ) {
1155
- if (Edit ) {
1156
- if (is_digit (Edit_pos - 1 , Edit_hex )) Edit_pos -- ;
1157
- else if (* (Edit_pos - 1 ) == 'x' && * (Edit_pos - 3 ) == ',' ) Edit_pos -= 4 ;
1158
- else if (* (Edit_pos - 1 ) == ',' ) Edit_pos -= 2 ;
1159
- } else if (view_x ) view_x -- ;
1200
+ if (view_x ) view_x -- ;
1160
1201
}
1161
1202
} else if (event .input .type == InputTypeLong ) {
1162
1203
if (!ask_question && view_x == 0 && what_doing == 2 && (rw_type == rwt_write_batch || rw_type == rwt_read_batch )
@@ -1170,20 +1211,21 @@ int32_t nrf24batch_app(void* p) {
1170
1211
if (event .input .type == InputTypeShort || event .input .type == InputTypeRepeat ) {
1171
1212
if (ask_question ) {
1172
1213
ask_question_answer ^= 1 ;
1214
+ } else if (Edit ) {
1215
+ if (is_digit (Edit_pos + 1 , Edit_hex )) Edit_pos ++ ;
1216
+ else if (* (Edit_pos + 1 ) == ',' ) {
1217
+ Edit_pos += 2 ;
1218
+ if (* (Edit_pos + 1 ) == 'x' ) Edit_pos += 2 ;
1219
+ }
1173
1220
} else if (what_doing == 0 ) {
1221
+ rw_type = rwt_read_batch ;
1174
1222
what_doing = 1 ;
1175
1223
} else if (what_doing == 1 ) {
1176
1224
if (event .input .type == InputTypeShort ) {
1177
1225
if (++ rw_type > rwt_write_batch ) rw_type = rwt_read_batch ;
1178
1226
} else view_x ++ ;
1179
1227
} else if (what_doing == 2 ) {
1180
- if (Edit ) {
1181
- if (is_digit (Edit_pos + 1 , Edit_hex )) Edit_pos ++ ;
1182
- else if (* (Edit_pos + 1 ) == ',' ) {
1183
- Edit_pos += 2 ;
1184
- if (* (Edit_pos + 1 ) == 'x' ) Edit_pos += 2 ;
1185
- }
1186
- } else view_x ++ ;
1228
+ view_x ++ ;
1187
1229
}
1188
1230
}
1189
1231
break ;
@@ -1217,11 +1259,49 @@ int32_t nrf24batch_app(void* p) {
1217
1259
}
1218
1260
}
1219
1261
ask_question = 0 ;
1262
+ } else if (Edit ) { // insert digit
1263
+ if (what_doing == 0 ) {
1264
+ if (strlen (Edit_start ) < (setup_cursor == 1 ? 5 * 2 : 3 )) {
1265
+ memmove (Edit_pos + 1 , Edit_pos , strlen (Edit_pos ) + 1 );
1266
+ * Edit_pos = '0' ;
1267
+ }
1268
+ } else {
1269
+ FuriString * fs = Log [view_Batch ];
1270
+ FuriString * ns = furi_string_alloc ();
1271
+ if (ns ) {
1272
+ uint16_t len = Edit_pos - (char * )furi_string_get_cstr (fs );
1273
+ furi_string_set_n (ns , fs , 0 , len );
1274
+ furi_string_cat_str (ns , "0" );
1275
+ furi_string_cat_str (ns , Edit_pos );
1276
+ furi_string_free (fs );
1277
+ Log [view_Batch ] = ns ;
1278
+ Edit_pos = (char * )furi_string_get_cstr (ns ) + len ;
1279
+ }
1280
+ }
1220
1281
} else if (what_doing == 0 ) {
1221
- file_stream_close (file_stream );
1222
- if (select_settings_file ()) {
1223
- uint8_t err = load_settings_file ();
1224
- if (err ) snprintf (file_name , sizeof (file_name ), "LOAD ERROR #%d" , err );
1282
+ if (setup_cursor == 0 ) { // open file
1283
+ file_stream_close (file_stream );
1284
+ if (select_settings_file ()) {
1285
+ uint8_t err = load_settings_file ();
1286
+ if (err ) snprintf (file_name , sizeof (file_name ), "LOAD ERROR #%d" , err );
1287
+ }
1288
+ } else if (setup_cursor == 1 ) { // change address
1289
+ char * ebuf = (char * )payload ;
1290
+ ebuf [0 ] = '\0' ;
1291
+ add_to_str_hex_bytes (ebuf , addr , addr_len );
1292
+ Edit_hex = true;
1293
+ Edit_pos = ebuf + strlen (ebuf ) - 1 ;
1294
+ Edit_start = ebuf ;
1295
+ Edit = 1 ;
1296
+ NRF_INITED = false;
1297
+ } else if (setup_cursor == 2 ) { // change channel
1298
+ char * ebuf = (char * )payload ;
1299
+ snprintf (ebuf , sizeof (payload ), "%d" , NRF_channel );
1300
+ Edit_hex = false;
1301
+ Edit_pos = ebuf + strlen (ebuf ) - 1 ;
1302
+ Edit_start = ebuf ;
1303
+ Edit = 1 ;
1304
+ NRF_INITED = false;
1225
1305
}
1226
1306
} else if (what_doing == 1 ) {
1227
1307
if (rw_type == rwt_read_batch ) {
@@ -1256,19 +1336,7 @@ int32_t nrf24batch_app(void* p) {
1256
1336
ask_question = ask_save_batch ;
1257
1337
ask_question_answer = 0 ;
1258
1338
} else if (rw_type == rwt_write_batch ) {
1259
- if (Edit ) { // insert digit
1260
- FuriString * fs = Log [view_Batch ];
1261
- FuriString * ns = furi_string_alloc ();
1262
- if (ns ) {
1263
- uint16_t len = Edit_pos - (char * )furi_string_get_cstr (fs );
1264
- furi_string_set_n (ns , fs , 0 , len );
1265
- furi_string_cat_str (ns , "0" );
1266
- furi_string_cat_str (ns , Edit_pos );
1267
- furi_string_free (fs );
1268
- Log [view_Batch ] = ns ;
1269
- Edit_pos = (char * )furi_string_get_cstr (ns ) + len ;
1270
- }
1271
- } else {
1339
+ if (!Edit ) {
1272
1340
Edit = 1 ;
1273
1341
Edited = true;
1274
1342
Edit_hex = 0 ;
@@ -1281,25 +1349,30 @@ int32_t nrf24batch_app(void* p) {
1281
1349
p += 2 ;
1282
1350
Edit_hex = 1 ; // hex
1283
1351
}
1284
- Edit_pos = p ;
1352
+ Edit_start = Edit_pos = p ;
1285
1353
} else Edit = 0 ;
1286
1354
}
1287
1355
}
1288
1356
}
1289
1357
}
1290
1358
} else if (event .input .type == InputTypeLong ) {
1291
- if (what_doing == 2 && Log_Total ) {
1292
- if (rw_type == rwt_write_batch ) {
1293
- if (Edit ) { // delete
1294
- FuriString * fs = Log [ view_Batch ] ;
1295
- if (is_digit ( Edit_pos + 1 , Edit_hex ) || is_digit ( Edit_pos - 1 , Edit_hex )) {
1296
- memmove ( Edit_pos , Edit_pos + 1 , strlen ( Edit_pos ));
1297
- furi_string_left ( fs , furi_string_size ( fs ) - 1 );
1298
- }
1299
- } else {
1300
- ask_question = ask_write_batch ;
1301
- ask_question_answer = 0 ;
1359
+ if (Edit ) { // delete
1360
+ if (what_doing == 0 ) {
1361
+ if (strlen ( Edit_start ) > 1 ) {
1362
+ memmove ( Edit_pos , Edit_pos + 1 , strlen ( Edit_pos ) + 1 ) ;
1363
+ if (* Edit_pos == '\0' ) Edit_pos -- ;
1364
+ }
1365
+ } else {
1366
+ FuriString * fs = Log [ view_Batch ];
1367
+ if ( is_digit ( Edit_pos + 1 , Edit_hex ) || ( Edit_pos > Edit_start && is_digit ( Edit_pos - 1 , Edit_hex ))) {
1368
+ memmove ( Edit_pos , Edit_pos + 1 , strlen ( Edit_pos )) ;
1369
+ furi_string_left ( fs , furi_string_size ( fs ) - 1 ) ;
1302
1370
}
1371
+ }
1372
+ } else if (what_doing == 2 && Log_Total ) {
1373
+ if (rw_type == rwt_write_batch ) {
1374
+ ask_question = ask_write_batch ;
1375
+ ask_question_answer = 0 ;
1303
1376
} else if (rw_type == rwt_read_batch ) {
1304
1377
ask_question = ask_save_batch ;
1305
1378
ask_question_answer = 0 ;
@@ -1314,15 +1387,22 @@ int32_t nrf24batch_app(void* p) {
1314
1387
ask_question = ask_exit ;
1315
1388
} else processing = false;
1316
1389
} else if (event .input .type == InputTypeShort ) {
1317
- if (Edit ) Edit = 0 ;
1318
- else if (ask_question ) ask_question = 0 ;
1319
- else {
1390
+ if (ask_question ) ask_question = 0 ;
1391
+ else if (Edit ) {
1392
+ if (what_doing == 0 ) {
1393
+ if (setup_cursor == 1 ) {
1394
+ addr_len = ConvertHexToArray ((char * )payload , addr , 5 );
1395
+ } else if (setup_cursor == 2 ) {
1396
+ NRF_channel = str_to_int ((char * )payload );
1397
+ if (NRF_channel > MAX_CHANNEL ) NRF_channel = MAX_CHANNEL ;
1398
+ }
1399
+ }
1400
+ Edit = 0 ;
1401
+ } else {
1320
1402
if (what_doing == 2 && Edited ) {
1321
1403
ask_question = ask_return ;
1322
1404
ask_question_answer = 1 ;
1323
- } else if (what_doing == 0 ) {
1324
- processing = false;
1325
- } else {
1405
+ } else if (what_doing != 0 ) {
1326
1406
if (what_doing ) what_doing -- ;
1327
1407
if (what_doing == 0 ) rw_type = rwt_read_batch ;
1328
1408
if (what_doing <= 1 ) view_x = 0 ;
0 commit comments