1212
1313#define TAG "BarCodeScanner"
1414#define WORKER_TAG TAG "Worker"
15- #define FILE_BUFFER_LEN 16
15+ #define FILE_BUFFER_LEN 1
1616
1717#define SCRIPT_STATE_ERROR (-1)
1818#define SCRIPT_STATE_END (-2)
@@ -36,7 +36,7 @@ struct BarCodeScript {
3636 FuriString * file_path ;
3737 uint32_t defdelay ;
3838 FuriThread * thread ;
39- uint8_t file_buf [FILE_BUFFER_LEN + 1 ];
39+ uint8_t file_buf [FILE_BUFFER_LEN ];
4040 uint8_t buf_start ;
4141 uint8_t buf_len ;
4242 bool file_end ;
@@ -85,19 +85,18 @@ static int32_t bc_scanner_worker(void* context){
8585 BarCodeWorkerState worker_state = BarCodeStateInit ;
8686 int32_t delay_val = 0 ;
8787 UNUSED (delay_val );
88- UNUSED (is_bc_end );
8988 File * script_file = storage_file_alloc (furi_record_open (RECORD_STORAGE ));
9089
9190 FURI_LOG_I (WORKER_TAG , "Init" );
92- uint8_t buff [5 ] = {'p' , 'r' , 'i' , 'v' , 'k' };
93- uint8_t state = 99 ;
91+ // uint8_t buff[5] = {'p', 'r', 'i', 'v', 'k'};
92+ // uint8_t state = 99;
9493
9594 usb_uart_serial_init ();
9695
9796 while (1 )
9897 {
99- state = furi_hal_cdc_get_ctrl_line_state (FuriHalUartIdUSART1 );
100- FURI_LOG_I (WORKER_TAG , "STATTE: %d" , state );
98+ // state = furi_hal_cdc_get_ctrl_line_state(FuriHalUartIdUSART1);
99+ // FURI_LOG_I(WORKER_TAG, "STATTE: %d", state);
101100 if (worker_state == BarCodeStateInit )
102101 {
103102 if (storage_file_open (
@@ -131,9 +130,26 @@ static int32_t bc_scanner_worker(void* context){
131130 worker_state = BarCodeStateIdle ; // Ready to run
132131 } else if (flags & WorkerEvtToggle ) {
133132 FURI_LOG_I (WORKER_TAG , "SendUART_MSG" );
134- furi_hal_cdc_send (0 , buff , sizeof (buff ));
133+ uint16_t ret = 0 ;
134+ do {
135+ ret = storage_file_read (script_file , bc_script -> file_buf , FILE_BUFFER_LEN );
136+ if (is_bc_end ((char )bc_script -> file_buf [0 ]))
137+ {
138+ bc_script -> st .line_nb ++ ;
139+ break ;
140+ }
141+
142+ furi_hal_cdc_send (0 , bc_script -> file_buf , FILE_BUFFER_LEN );
143+ furi_delay_ms (10 );
144+ if (storage_file_eof (script_file )) {
145+ bc_script -> st .line_nb ++ ;
146+ break ;
147+ }
148+ }while (ret > 0 );
149+
135150 worker_state = BarCodeStateIdle ;
136151 bc_script -> st .state = BarCodeStateDone ;
152+ storage_file_seek (script_file , 0 , true);
137153 continue ;
138154 }
139155 bc_script -> st .state = worker_state ;
@@ -173,6 +189,7 @@ void bc_scanner_script_close(BarCodeScript* bc_script) {
173189 furi_thread_free (bc_script -> thread );
174190 furi_string_free (bc_script -> file_path );
175191 free (bc_script );
192+ FURI_LOG_D (WORKER_TAG , "bc_scanner_script_close" );
176193}
177194
178195void bc_scanner_script_toggle (BarCodeScript * bc_script ) {
0 commit comments