Skip to content

Commit

Permalink
Merge pull request #3 from polarikus/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
polarikus authored Jan 25, 2023
2 parents 5368670 + b48fd6c commit 11994fc
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 20 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[![FAP Factory](https://fap.playmean.xyz/api/v1/polarikus/flipper-zero_bc_scanner_emulator/badge)](https://fap.playmean.xyz/polarikus/flipper-zero_bc_scanner_emulator)

1. Copy bc_scanner.fap file in Flipper SDCard (apps folder)
2. Make "/bcscanner" folder in Flipper SDCard
2. Open bc_scanner app, for creating bcscanner folder, or create a folder manually via qFlipper
3. Add bar code files (.bc) in "bcscanner" folder

## GUI
Expand All @@ -24,11 +24,12 @@ After open app - select bar code to be emulated
### Emulation
1. Click "Run" Button

![Run](https://gitlab.idcloud.space/flipper-zero/bc_scanner_e/-/wikis/uploads/2b6144eebd5e88caa8adc5e0c7514342/Runing.png)
![Run](https://user-images.githubusercontent.com/59930161/214501072-33a32970-7f1c-4f3b-b6f0-39bb4f2201ce.png)
![Work](https://user-images.githubusercontent.com/59930161/214501068-ad11e74f-b501-408b-939b-8d2d7748e542.png)

When sending completed You will see 100% on the display:

![End](https://gitlab.idcloud.space/flipper-zero/bc_scanner_e/-/wikis/uploads/676d868d7c377ef9d0f42706bcd83913/EndRun.png)
![End](https://user-images.githubusercontent.com/59930161/214501074-f567af0c-16d3-4287-81e6-a96ebb6a57f2.png)

2. If you need to resend, click "Run" again
3. To exit - press the "Back" button on the flipper
Expand Down
1 change: 1 addition & 0 deletions bc_scanner_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <gui/modules/widget.h>
#include "views/bc_scanner_view.h"

#define RECORD_STORAGE "storage"
#define BC_SCANNER_APP_PATH_FOLDER ANY_PATH("bcscanner")
#define BC_SCANNER_APP_EXTENSION ".bc"

Expand Down
20 changes: 18 additions & 2 deletions bc_scanner_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ struct BarCodeScript {
};


static void scan_sound()
{
if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(1000)) {
float frequency = 4000;
furi_hal_speaker_stop();
furi_hal_speaker_set_volume(100);
furi_hal_speaker_start(frequency, 100);
furi_delay_ms(50);
furi_hal_speaker_stop();
furi_hal_speaker_release();
}
}


static void usb_uart_serial_init() {
furi_hal_usb_unlock();
Cli* cli = furi_record_open(RECORD_CLI);
Expand Down Expand Up @@ -105,11 +119,12 @@ static int32_t bc_scanner_worker(void* context){
} else {
FURI_LOG_E(WORKER_TAG, "File empty error");
worker_state = BarCodeStateFileError;
bc_script->st.error_line = 0;
bc_script->st.error_enum = FileIsEmpty;
}
} else {
FURI_LOG_E(WORKER_TAG, "File open error");
worker_state = BarCodeStateFileError; // File open error
bc_script->st.error_enum = FileOpenError;
}
bc_script->st.state = worker_state;
}else if(worker_state == BarCodeStateIdle) { // State: ready to start
Expand All @@ -126,7 +141,8 @@ static int32_t bc_scanner_worker(void* context){
FURI_LOG_I(WORKER_TAG, "SendUART_MSG");
bc_script->st.state = BarCodeStateRunning;
bc_script->st.line_cur = 0;
furi_delay_ms(500);
furi_delay_ms(450);
scan_sound();
while(!bc_script->is_file_end){
bc_script->st.state = BarCodeStateRunning;
uint16_t size = bc_script_read_file(bc_script, script_file);
Expand Down
8 changes: 7 additions & 1 deletion bc_scanner_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ typedef enum {
BarCodeStateFileError,
} BarCodeWorkerState;

typedef enum {
FileIsEmpty,
FileOpenError
} FileError;


typedef struct {
BarCodeWorkerState state;
uint16_t line_cur;
uint16_t line_nb;
uint32_t delay_remain;
uint16_t error_line;
int error_enum;
char error[64];
} BarCodeState;

Expand Down
Binary file added icons/Scanner_27x37.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/bc_12x13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions scenes/bc_scanner_scene_file_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
static bool bc_scanner_file_select(BarCodeApp* bc_app) {
furi_assert(bc_app);

Storage* storage = furi_record_open(RECORD_STORAGE);
if(!storage_file_exists(storage, BC_SCANNER_APP_PATH_FOLDER)){
storage_common_mkdir(storage, BC_SCANNER_APP_PATH_FOLDER);//Make Folder If dir not exist
}
furi_record_close(RECORD_STORAGE);

DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(&browser_options, BC_SCANNER_APP_EXTENSION, &I_bc_10px);
browser_options.base_path = BC_SCANNER_APP_PATH_FOLDER;
Expand Down
34 changes: 20 additions & 14 deletions views/bc_scanner_view.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "bc_scanner_view.h"
#include "../bc_scanner_script.h"
#include "../bc_scanner_app_i.h"
#include <gui/elements.h>
#include <assets_icons.h>

Expand All @@ -19,6 +19,11 @@ typedef struct {
uint8_t anim_frame;
} BarCodeModel;

static char *fileErrors[] = {
"File is Empty!",
"Can’t open the file"
};


static void bc_scanner_draw_callback(Canvas* canvas, void* _model) {
BarCodeModel* model = _model;
Expand All @@ -30,7 +35,7 @@ static void bc_scanner_draw_callback(Canvas* canvas, void* _model) {
canvas_draw_str(canvas, 2, 8, furi_string_get_cstr(disp_str));
furi_string_reset(disp_str);

canvas_draw_icon(canvas, 22, 20, &I_UsbTree_48x22);
canvas_draw_icon(canvas, 4, 22, &I_Scanner_27x37);

if((model->state.state == BarCodeStateIdle) || (model->state.state == BarCodeStateDone)) {
elements_button_center(canvas, "Run");
Expand All @@ -39,30 +44,31 @@ static void bc_scanner_draw_callback(Canvas* canvas, void* _model) {
}

if(model->state.state == BarCodeStateFileError) {
canvas_draw_icon(canvas, 4, 22, &I_Error_18x18);
canvas_draw_icon(canvas, 32, 22, &I_Error_18x18);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 127, 27, AlignRight, AlignBottom, "File");
canvas_draw_str_aligned(canvas, 127, 39, AlignRight, AlignBottom, "ERROR");
canvas_draw_str_aligned(canvas, 127, 39, AlignRight, AlignBottom, "File ERROR");
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 127, 51, AlignRight, AlignBottom, fileErrors[model->state.error_enum]);
} else if(model->state.state == BarCodeStateScriptError) {
canvas_draw_icon(canvas, 4, 22, &I_Error_18x18);
canvas_draw_icon(canvas, 32, 22, &I_Error_18x18);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 127, 33, AlignRight, AlignBottom, "ERROR:");
canvas_set_font(canvas, FontSecondary);
furi_string_printf(disp_str, "line %u", model->state.error_line);
//furi_string_printf(disp_str, "line %u", model->state.er);
canvas_draw_str_aligned(
canvas, 127, 46, AlignRight, AlignBottom, furi_string_get_cstr(disp_str));
furi_string_reset(disp_str);
canvas_draw_str_aligned(canvas, 127, 56, AlignRight, AlignBottom, model->state.error);
} else if(model->state.state == BarCodeStateIdle) {
canvas_draw_icon(canvas, 4, 22, &I_Smile_18x18);
//canvas_draw_icon(canvas, 4, 22, &I_Smile_18x18);
canvas_set_font(canvas, FontBigNumbers);
canvas_draw_str_aligned(canvas, 114, 36, AlignRight, AlignBottom, "0");
canvas_draw_icon(canvas, 117, 22, &I_Percent_10x14);
} else if(model->state.state == BarCodeStateRunning) {
if(model->anim_frame == 0) {
canvas_draw_icon(canvas, 4, 19, &I_EviSmile1_18x21);
canvas_draw_icon(canvas, 32, 24, &I_bc_12x13);
} else {
canvas_draw_icon(canvas, 4, 19, &I_EviSmile2_18x21);
canvas_draw_icon(canvas, 32, 27, &I_bc_10px);
}
canvas_set_font(canvas, FontBigNumbers);
furi_string_printf(
Expand All @@ -72,16 +78,16 @@ static void bc_scanner_draw_callback(Canvas* canvas, void* _model) {
furi_string_reset(disp_str);
canvas_draw_icon(canvas, 117, 22, &I_Percent_10x14);
} else if(model->state.state == BarCodeStateDone) {
canvas_draw_icon(canvas, 4, 19, &I_EviSmile1_18x21);
//canvas_draw_icon(canvas, 4, 19, &I_EviSmile1_18x21);
canvas_set_font(canvas, FontBigNumbers);
canvas_draw_str_aligned(canvas, 114, 36, AlignRight, AlignBottom, "100");
furi_string_reset(disp_str);
canvas_draw_icon(canvas, 117, 22, &I_Percent_10x14);
} else if(model->state.state == BarCodeStateDelay) {
if(model->anim_frame == 0) {
canvas_draw_icon(canvas, 4, 19, &I_EviWaiting1_18x21);
//canvas_draw_icon(canvas, 4, 19, &I_EviWaiting1_18x21);
} else {
canvas_draw_icon(canvas, 4, 19, &I_EviWaiting2_18x21);
//canvas_draw_icon(canvas, 4, 19, &I_EviWaiting2_18x21);
}
canvas_set_font(canvas, FontBigNumbers);
furi_string_printf(
Expand All @@ -96,7 +102,7 @@ static void bc_scanner_draw_callback(Canvas* canvas, void* _model) {
canvas, 127, 46, AlignRight, AlignBottom, furi_string_get_cstr(disp_str));
furi_string_reset(disp_str);
} else {
canvas_draw_icon(canvas, 4, 22, &I_Clock_18x18);
canvas_draw_icon(canvas, 32, 22, &I_Clock_18x18);
}

furi_string_free(disp_str);
Expand Down

0 comments on commit 11994fc

Please sign in to comment.