@@ -957,8 +957,10 @@ void display_edit_ttf_font(Canvas* const canvas, uint8_t start_x, uint8_t start_
957
957
}
958
958
959
959
static void render_callback (Canvas * const canvas , void * ctx ) {
960
- const PluginState * plugin_state = acquire_mutex ((ValueMutex * )ctx , 25 );
961
- if (plugin_state == NULL ) return ;
960
+ if (ctx == NULL ) return ;
961
+ const PluginState * plugin_state = ctx ;
962
+ if (furi_mutex_acquire (plugin_state -> mutex , 25 ) != FuriStatusOk ) return ;
963
+
962
964
//canvas_draw_frame(canvas, 0, 0, 128, 64); // border around the edge of the screen
963
965
if (what_doing == 0 ) {
964
966
canvas_set_font (canvas , FontSecondary ); // 8x10 font, 6 lines
@@ -1142,13 +1144,15 @@ static void render_callback(Canvas* const canvas, void* ctx) {
1142
1144
}
1143
1145
}
1144
1146
}
1145
- release_mutex (( ValueMutex * ) ctx , plugin_state );
1147
+ furi_mutex_release ( plugin_state -> mutex );
1146
1148
}
1147
1149
1148
1150
void work_timer_callback (void * ctx )
1149
1151
{
1150
- UNUSED (ctx ) ;
1152
+ if (ctx == NULL ) return ;
1151
1153
if (what_doing == 2 ) {
1154
+ const PluginState * plugin_state = ctx ;
1155
+ if (furi_mutex_acquire (plugin_state -> mutex , 0 ) != FuriStatusOk ) return ;
1152
1156
if (rw_type == rwt_write_batch ) {
1153
1157
if (send_status == sst_ok ) {
1154
1158
if (ERR == 0 && WriteBatch_cmd_curr < Log_Total && furi_get_tick () - NRF_time >= delay_between_pkt ) {
@@ -1197,35 +1201,36 @@ void work_timer_callback(void* ctx)
1197
1201
}
1198
1202
}
1199
1203
}
1204
+ furi_mutex_release (plugin_state -> mutex );
1200
1205
}
1201
1206
}
1202
1207
1203
1208
int32_t nrf24batch_app (void * p ) {
1204
1209
UNUSED (p );
1205
1210
APP = malloc (sizeof (nRF24Batch ));
1206
- APP -> event_queue = furi_message_queue_alloc (8 , sizeof (PluginEvent ));
1207
- APP -> plugin_state = malloc (sizeof (PluginState ));
1208
- ValueMutex state_mutex ;
1209
- if (!init_mutex ( & state_mutex , APP -> plugin_state , sizeof ( PluginState )) ) {
1210
- furi_message_queue_free (APP -> event_queue );
1211
+ FuriMessageQueue * event_queue = furi_message_queue_alloc (8 , sizeof (PluginEvent ));
1212
+ PluginState * plugin_state = malloc (sizeof (PluginState ));
1213
+ plugin_state -> mutex = furi_mutex_alloc ( FuriMutexTypeNormal ) ;
1214
+ if (!plugin_state -> mutex ) {
1215
+ furi_message_queue_free (event_queue );
1211
1216
FURI_LOG_E (TAG , "cannot create mutex" );
1212
- free (APP -> plugin_state );
1217
+ free (plugin_state );
1213
1218
return 255 ;
1214
1219
}
1215
1220
1216
1221
// Set system callbacks
1217
- APP -> view_port = view_port_alloc ();
1218
- view_port_draw_callback_set (APP -> view_port , render_callback , & state_mutex );
1219
- view_port_input_callback_set (APP -> view_port , input_callback , APP -> event_queue );
1222
+ ViewPort * view_port = view_port_alloc ();
1223
+ view_port_draw_callback_set (view_port , render_callback , plugin_state );
1224
+ view_port_input_callback_set (view_port , input_callback , event_queue );
1220
1225
1221
1226
// Open GUI and register view_port
1222
1227
APP -> gui = furi_record_open (RECORD_GUI );
1223
- gui_add_view_port (APP -> gui , APP -> view_port , GuiLayerFullscreen );
1228
+ gui_add_view_port (APP -> gui , view_port , GuiLayerFullscreen );
1224
1229
APP -> notification = furi_record_open (RECORD_NOTIFICATION );
1225
1230
APP -> storage = furi_record_open (RECORD_STORAGE );
1226
1231
storage_common_mkdir (APP -> storage , SCAN_APP_PATH_FOLDER );
1227
1232
file_stream = file_stream_alloc (APP -> storage );
1228
- FuriTimer * work_timer = furi_timer_alloc (work_timer_callback , FuriTimerTypePeriodic , NULL );
1233
+ FuriTimer * work_timer = furi_timer_alloc (work_timer_callback , FuriTimerTypePeriodic , plugin_state );
1229
1234
furi_timer_start (work_timer , WORK_PERIOD );
1230
1235
if (!furi_hal_power_is_otg_enabled ()) {
1231
1236
furi_hal_power_enable_otg ();
@@ -1236,8 +1241,8 @@ int32_t nrf24batch_app(void* p) {
1236
1241
1237
1242
PluginEvent event ;
1238
1243
for (bool processing = true; processing ;) {
1239
- FuriStatus event_status = furi_message_queue_get (APP -> event_queue , & event , 200 );
1240
- PluginState * plugin_state = ( PluginState * ) acquire_mutex_block ( & state_mutex );
1244
+ FuriStatus event_status = furi_message_queue_get (event_queue , & event , 100 );
1245
+ furi_mutex_acquire ( plugin_state -> mutex , FuriWaitForever );
1241
1246
1242
1247
static FuriLogLevel FuriLogLevel = FuriLogLevelDefault ;
1243
1248
if (furi_log_get_level () != FuriLogLevel ) {
@@ -1471,27 +1476,8 @@ int32_t nrf24batch_app(void* p) {
1471
1476
ask_question = ask_save_batch ;
1472
1477
ask_question_answer = 0 ;
1473
1478
} else if (rw_type == rwt_write_batch ) {
1474
- if (!Edit ) {
1475
- Edit = 0 ;
1476
- Edit_hex = 0 ;
1477
- char * s = (char * )furi_string_get_cstr (Log [view_Batch ]);
1478
- char * p = strchr (s , '=' );
1479
- if (p ) {
1480
- p ++ ;
1481
- if (* p == '{' ) p ++ ; // array
1482
- if (* (p + 1 ) == 'x' ) {
1483
- p += 2 ;
1484
- Edit_hex = 1 ; // hex
1485
- }
1486
- if (is_digit (p , Edit_hex )) {
1487
- Edit_start = p ;
1488
- while (is_digit (p , Edit_hex )) p ++ ;
1489
- Edit_pos = p - 1 ;
1490
- Edited = true;
1491
- Edit = 1 ;
1492
- }
1493
- }
1494
- }
1479
+ ask_question = ask_write_batch ;
1480
+ ask_question_answer = 0 ;
1495
1481
}
1496
1482
}
1497
1483
}
@@ -1525,8 +1511,27 @@ int32_t nrf24batch_app(void* p) {
1525
1511
ReadRepeat = !ReadRepeat ;
1526
1512
} else if (Log_Total ) {
1527
1513
if (rw_type == rwt_write_batch ) {
1528
- ask_question = ask_write_batch ;
1529
- ask_question_answer = 0 ;
1514
+ if (!Edit ) {
1515
+ Edit = 0 ;
1516
+ Edit_hex = 0 ;
1517
+ char * s = (char * )furi_string_get_cstr (Log [view_Batch ]);
1518
+ char * p = strchr (s , '=' );
1519
+ if (p ) {
1520
+ p ++ ;
1521
+ if (* p == '{' ) p ++ ; // array
1522
+ if (* (p + 1 ) == 'x' ) {
1523
+ p += 2 ;
1524
+ Edit_hex = 1 ; // hex
1525
+ }
1526
+ if (is_digit (p , Edit_hex )) {
1527
+ Edit_start = p ;
1528
+ while (is_digit (p , Edit_hex )) p ++ ;
1529
+ Edit_pos = p - 1 ;
1530
+ Edited = true;
1531
+ Edit = 1 ;
1532
+ }
1533
+ }
1534
+ }
1530
1535
} else if (rw_type == rwt_read_batch ) {
1531
1536
ask_question = ask_save_batch ;
1532
1537
ask_question_answer = 0 ;
@@ -1575,28 +1580,29 @@ int32_t nrf24batch_app(void* p) {
1575
1580
}
1576
1581
}
1577
1582
1578
- view_port_update (APP -> view_port );
1579
- release_mutex ( & state_mutex , plugin_state );
1583
+ view_port_update (view_port );
1584
+ furi_mutex_release ( plugin_state -> mutex );
1580
1585
}
1581
1586
nrf24_set_idle (nrf24_HANDLE );
1582
1587
nrf24_deinit ();
1583
1588
if (NRF_BOARD_POWER_5V ) furi_hal_power_disable_otg ();
1584
1589
1585
- view_port_enabled_set (APP -> view_port , false);
1586
- gui_remove_view_port (APP -> gui , APP -> view_port );
1590
+ view_port_enabled_set (view_port , false);
1591
+ gui_remove_view_port (APP -> gui , view_port );
1587
1592
furi_record_close (RECORD_GUI );
1588
1593
furi_record_close (RECORD_NOTIFICATION );
1589
1594
furi_record_close (RECORD_STORAGE );
1590
1595
if (file_stream ) {
1591
1596
file_stream_close (file_stream );
1592
1597
stream_free (file_stream );
1593
1598
}
1594
- view_port_free (APP -> view_port );
1595
- furi_message_queue_free (APP -> event_queue );
1599
+ view_port_free (view_port );
1600
+ furi_message_queue_free (event_queue );
1596
1601
free_store ();
1597
1602
furi_timer_stop (work_timer );
1598
1603
furi_timer_free (work_timer );
1599
- free (APP -> plugin_state );
1604
+ furi_mutex_free (plugin_state -> mutex );
1605
+ free (plugin_state );
1600
1606
free (APP );
1601
1607
return 0 ;
1602
1608
}
0 commit comments