Browse Source

upd barcode gen

MX 1 year ago
parent
commit
c4265b7387
8 changed files with 316 additions and 248 deletions
  1. 2 6
      README.md
  2. 1 1
      application.fam
  3. 78 0
      barcode_app.c
  4. 9 3
      barcode_app.h
  5. 196 195
      barcode_encoding_files/code128_encodings.txt
  6. 8 8
      barcode_utils.c
  7. 16 6
      barcode_validator.c
  8. 6 29
      views/barcode_view.c

+ 2 - 6
README.md

@@ -34,12 +34,8 @@ Note: Barcode save locations have been moved from `/barcodes` to `/apps_data/bar
 ## Building
 1) Clone the [flipperzero-firmware](https://github.com/flipperdevices/flipperzero-firmware) repository or a firmware of your choice
 2) Clone this repository and put it in the `applications_user` folder
-3) Build this app by using the command `./fbt fap_Barcode_App`
-4) Copy the `.fap` from `build\f7-firmware-D\.extapps\Barcode_App.fap` to `apps\Misc` using the qFlipper app
-5) While still in the qFlipper app, navigate to the root folder of the SD card and create the folder `apps_data`, if not already there
-6) Navigate into `apps_data` and create another folder called `barcode_data`
-7) Navigate into `barcode_data`
-8) Drag & drop the encoding txts (`code39_encodings.txt`, `code128_encodings.txt` & `codabar_encodings.txt`) from the `encoding_tables` folder in this repository into the `barcode_data` folder
+3) Build this app by using the command `./fbt fap_barcode_App`
+4) Copy the `.fap` from `build\f7-firmware-D\.extapps\Barcode_App.fap` to `apps\Tools` using the qFlipper app
 
 ## Usage
 

+ 1 - 1
application.fam

@@ -11,6 +11,6 @@ App(
     fap_file_assets="barcode_encoding_files",
     fap_author="@Kingal1337",
     fap_weburl="https://github.com/Kingal1337/flipper-barcode-generator",
-    fap_version="1.1",
+    fap_version="1.2",
     fap_description="App allows you to display various barcodes on flipper screen",
 )

+ 78 - 0
barcode_app.c

@@ -242,6 +242,10 @@ void submenu_callback(void* context, uint32_t index) {
         edit_barcode_item(app);
     } else if(index == CreateBarcodeItem) {
         create_barcode_item(app);
+    } else if(index == AboutWidgetItem) {
+        view_dispatcher_switch_to_view(app->view_dispatcher, AboutWidgetView);
+    } else if(index == ErrorCodesWidgetItem) {
+        view_dispatcher_switch_to_view(app->view_dispatcher, ErrorCodesWidgetView);
     }
 }
 
@@ -269,6 +273,12 @@ void free_app(BarcodeApp* app) {
     view_dispatcher_remove_view(app->view_dispatcher, TextInputView);
     text_input_free(app->text_input);
 
+    view_dispatcher_remove_view(app->view_dispatcher, AboutWidgetView);
+    widget_free(app->about_widget);
+
+    view_dispatcher_remove_view(app->view_dispatcher, ErrorCodesWidgetView);
+    widget_free(app->error_codes_widget);
+
     view_dispatcher_remove_view(app->view_dispatcher, MessageErrorView);
     message_view_free(app->message_view);
 
@@ -349,6 +359,74 @@ int32_t barcode_main(void* p) {
     view_dispatcher_add_view(
         app->view_dispatcher, CreateBarcodeView, create_get_view(app->create_view));
 
+    /*****************************
+     * Creating Error Codes View
+     ******************************/
+    app->error_codes_widget = widget_alloc();
+    widget_add_text_scroll_element(
+        app->error_codes_widget,
+        0,
+        0,
+        128,
+        64,
+        "\e#Error Codes\n"
+        "\e#Wrong # Of Characters\n"
+        "The barcode data has too \nmany or too few characters\n"
+        "UPC-A: 11-12 characters\n"
+        "EAN-8: 7-8 characters\n"
+        "EAN-13: 12-13 characters\n"
+        "Code128C - even # of \ncharacters\n"
+        "\n"
+        "\e#Invalid Characters\n"
+        "The barcode data has invalid \ncharacters.\n"
+        "Ex: UPC-A, EAN-8, EAN-13 barcodes can only have \nnumbers while Code128 can \nhave almost any character\n"
+        "\n"
+        "\e#Unsupported Type\n"
+        "The barcode type is not \nsupported by this application\n"
+        "\n"
+        "\e#File Opening Error\n"
+        "The barcode file could not be opened. One reason could be \nthat the file no longer exists\n"
+        "\n"
+        "\e#Invalid File Data\n"
+        "The barcode file could not find the keys \"Type\" or \"Data\". \nThis usually occurs when you edit the file manually and \naccidently change the keys\n"
+        "\n"
+        "\e#Missing Encoding Table\n"
+        "The encoding table files are \nmissing. This only occurs \nwhen you need to handle the \nencoding files manually. If you \ndownload the files from the \napp store this should not \noccur\n"
+        "\n"
+        "\e#Encoding Table Error\n"
+        "This occurs when the \nprogram cannot find a \ncharacter in the encoding \ntable, meaning that either the\ncharacter isn't supported \nor the character is missing \nfrom the encoding table\n"
+        "");
+    view_set_previous_callback(widget_get_view(app->error_codes_widget), main_menu_callback);
+    view_dispatcher_add_view(
+        app->view_dispatcher, ErrorCodesWidgetView, widget_get_view(app->error_codes_widget));
+    submenu_add_item(
+        app->main_menu, "Error Codes Info", ErrorCodesWidgetItem, submenu_callback, app);
+
+    /*****************************
+     * Creating About View
+     ******************************/
+    app->about_widget = widget_alloc();
+    widget_add_text_scroll_element(
+        app->about_widget,
+        0,
+        0,
+        128,
+        64,
+        "This is a barcode generator\n"
+        "capable of generating UPC-A,\n"
+        "EAN-8, EAN-13, Code-39,\n"
+        "Codabar, and Code-128\n"
+        "\n"
+        "author: @Kingal1337\n"
+        "\n"
+        "For more information or\n"
+        "issues, go to\n"
+        "https://github.com/Kingal1337/flipper-barcode-generator");
+    view_set_previous_callback(widget_get_view(app->about_widget), main_menu_callback);
+    view_dispatcher_add_view(
+        app->view_dispatcher, AboutWidgetView, widget_get_view(app->about_widget));
+    submenu_add_item(app->main_menu, "About", AboutWidgetItem, submenu_callback, app);
+
     /*****************************
      * Creating Barcode View
      ******************************/

+ 9 - 3
barcode_app.h

@@ -3,10 +3,12 @@
 #include <furi_hal.h>
 
 #include <gui/gui.h>
+#include <gui/elements.h>
 #include <input/input.h>
 #include <dialogs/dialogs.h>
 #include <gui/view_dispatcher.h>
 #include <gui/modules/submenu.h>
+#include <gui/modules/widget.h>
 #include <gui/modules/text_input.h>
 #include <gui/modules/text_input.h>
 
@@ -59,6 +61,8 @@ struct BarcodeApp {
     CreateView* create_view;
     Barcode* barcode_view;
 
+    Widget* about_widget;
+    Widget* error_codes_widget;
     MessageView* message_view;
     TextInput* text_input;
 };
@@ -66,16 +70,18 @@ struct BarcodeApp {
 enum SubmenuItems {
     SelectBarcodeItem,
     EditBarcodeItem,
-
-    CreateBarcodeItem
+    CreateBarcodeItem,
+    ErrorCodesWidgetItem,
+    AboutWidgetItem
 };
 
 enum Views {
     TextInputView,
+    AboutWidgetView,
+    ErrorCodesWidgetView,
     MessageErrorView,
     MainMenuView,
     CreateBarcodeView,
-
     BarcodeView
 };
 

+ 196 - 195
barcode_encoding_files/code128_encodings.txt

@@ -1,199 +1,200 @@
- : 00
-!: 01
-": 02
-#: 03
-$: 04
-%: 05
-&: 06
-': 07
-(: 08
-): 09
-*: 10
-+: 11
-,: 12
--: 13
-.: 14
-/: 15
-0: 16
-1: 17
-2: 18
-3: 19
-4: 20
-5: 21
-6: 22
-7: 23
-8: 24
-9: 25
-:: 26
-;: 27
-<: 28
-=: 29
->: 30
-?: 31
-@: 32
-A: 33
-B: 34
-C: 35
-D: 36
-E: 37
-F: 38
-G: 39
-H: 40
-I: 41
-J: 42
-K: 43
-L: 44
-M: 45
-N: 46
-O: 47
-P: 48
-Q: 49
-R: 50
-S: 51
-T: 52
-U: 53
-V: 54
-W: 55
-X: 56
-Y: 57
-Z: 58
-[: 59
-\: 60
-]: 61
-^: 62
-_: 63
-`: 64
-a: 65
-b: 66
-c: 67
-d: 68
-e: 69
-f: 70
-g: 71
-h: 72
-i: 73
-j: 74
-k: 75
-l: 76
-m: 77
-n: 78
-o: 79
-p: 80
-q: 81
-r: 82
-s: 83
-t: 84
-u: 85
-v: 86
-w: 87
-x: 88
-y: 89
-z: 90
-{: 91
-|: 92
-}: 93
-~: 94
+ : 000
+!: 001
+": 002
+H#: 003
+$: 004
+%: 005
+&: 006
+': 007
+(: 008
+): 009
+*: 010
++: 011
+,: 012
+-: 013
+.: 014
+/: 015
+0: 016
+1: 017
+2: 018
+3: 019
+4: 020
+5: 021
+6: 022
+7: 023
+8: 024
+9: 025
+:: 026
+;: 027
+<: 028
+=: 029
+>: 030
+?: 031
+@: 032
+A: 033
+B: 034
+C: 035
+D: 036
+E: 037
+F: 038
+G: 039
+H: 040
+I: 041
+J: 042
+K: 043
+L: 044
+M: 045
+N: 046
+O: 047
+P: 048
+Q: 049
+R: 050
+S: 051
+T: 052
+U: 053
+V: 054
+W: 055
+X: 056
+Y: 057
+Z: 058
+[: 059
+\: 060
+]: 061
+^: 062
+_: 063
+`: 064
+a: 065
+b: 066
+c: 067
+d: 068
+e: 069
+f: 070
+g: 071
+h: 072
+i: 073
+j: 074
+k: 075
+l: 076
+m: 077
+n: 078
+o: 079
+p: 080
+q: 081
+r: 082
+s: 083
+t: 084
+u: 085
+v: 086
+w: 087
+x: 088
+y: 089
+z: 090
+{: 091
+|: 092
+}: 093
+~: 094
 
-00: 11011001100
-01: 11001101100
-02: 11001100110
-03: 10010011000
-04: 10010001100
-05: 10001001100
-06: 10011001000
-07: 10011000100
-08: 10001100100
-09: 11001001000
-10: 11001000100
-11: 11000100100
-12: 10110011100
-13: 10011011100
-14: 10011001110
-15: 10111001100
-16: 10011101100
-17: 10011100110
-18: 11001110010
-19: 11001011100
-20: 11001001110
-21: 11011100100
-22: 11001110100
-23: 11101101110
-24: 11101001100
-25: 11100101100
-26: 11100100110
-27: 11101100100
-28: 11100110100
-29: 11100110010
-30: 11011011000
-31: 11011000110
-32: 11000110110
-33: 10100011000
-34: 10001011000
-35: 10001000110
-36: 10110001000
-37: 10001101000
-38: 10001100010
-39: 11010001000
-40: 11000101000
-41: 11000100010
-42: 10110111000
-43: 10110001110
-44: 10001101110
-45: 10111011000
-46: 10111000110
-47: 10001110110
-48: 11101110110
-49: 11010001110
-50: 11000101110
-51: 11011101000
-52: 11011100010
-53: 11011101110
-54: 11101011000
-55: 11101000110
-56: 11100010110
-57: 11101101000
-58: 11101100010
-59: 11100011010
-60: 11101111010
-61: 11001000010
-62: 11110001010
-63: 10100110000
-64: 10100001100
-65: 10010110000
-66: 10010000110
-67: 10000101100
-68: 10000100110
-69: 10110010000
-70: 10110000100
-71: 10011010000
-72: 10011000010
-73: 10000110100
-74: 10000110010
-75: 11000010010
-76: 11001010000
-77: 11110111010
-78: 11000010100
-79: 10001111010
-80: 10100111100
-81: 10010111100
-82: 10010011110
-83: 10111100100
-84: 10011110100
-85: 10011110010
-86: 11110100100
-87: 11110010100
-88: 11110010010
-89: 11011011110
-90: 11011110110
-91: 11110110110
-92: 10101111000
-93: 10100011110
-94: 10001011110
-95: 10111101000
-96: 10111100010
-97: 11110101000
-98: 11110100010
-99: 10111011110
+ENCODINGS: 000
+000: 11011001100
+001: 11001101100
+002: 11001100110
+003: 10010011000
+004: 10010001100
+005: 10001001100
+006: 10011001000
+007: 10011000100
+008: 10001100100
+009: 11001001000
+010: 11001000100
+011: 11000100100
+012: 10110011100
+013: 10011011100
+014: 10011001110
+015: 10111001100
+016: 10011101100
+017: 10011100110
+018: 11001110010
+019: 11001011100
+020: 11001001110
+021: 11011100100
+022: 11001110100
+023: 11101101110
+024: 11101001100
+025: 11100101100
+026: 11100100110
+027: 11101100100
+028: 11100110100
+029: 11100110010
+030: 11011011000
+031: 11011000110
+032: 11000110110
+033: 10100011000
+034: 10001011000
+035: 10001000110
+036: 10110001000
+037: 10001101000
+038: 10001100010
+039: 11010001000
+040: 11000101000
+041: 11000100010
+042: 10110111000
+043: 10110001110
+044: 10001101110
+045: 10111011000
+046: 10111000110
+047: 10001110110
+048: 11101110110
+049: 11010001110
+050: 11000101110
+051: 11011101000
+052: 11011100010
+053: 11011101110
+054: 11101011000
+055: 11101000110
+056: 11100010110
+057: 11101101000
+058: 11101100010
+059: 11100011010
+060: 11101111010
+061: 11001000010
+062: 11110001010
+063: 10100110000
+064: 10100001100
+065: 10010110000
+066: 10010000110
+067: 10000101100
+068: 10000100110
+069: 10110010000
+070: 10110000100
+071: 10011010000
+072: 10011000010
+073: 10000110100
+074: 10000110010
+075: 11000010010
+076: 11001010000
+077: 11110111010
+078: 11000010100
+079: 10001111010
+080: 10100111100
+081: 10010111100
+082: 10010011110
+083: 10111100100
+084: 10011110100
+085: 10011110010
+086: 11110100100
+087: 11110010100
+088: 11110010010
+089: 11011011110
+090: 11011110110
+091: 11110110110
+092: 10101111000
+093: 10100011110
+094: 10001011110
+095: 10111101000
+096: 10111100010
+097: 11110101000
+098: 11110100010
+099: 10111011110
 100: 10111101110
 101: 11101011110
 102: 11110101110

+ 8 - 8
barcode_utils.c

@@ -103,7 +103,7 @@ BarcodeTypeObj* get_type(FuriString* type_string) {
 const char* get_error_code_name(ErrorCode error_code) {
     switch(error_code) {
     case WrongNumberOfDigits:
-        return "Wrong Number Of Digits";
+        return "Wrong # Of Characters";
     case InvalidCharacters:
         return "Invalid Characters";
     case UnsupportedType:
@@ -126,19 +126,19 @@ const char* get_error_code_name(ErrorCode error_code) {
 const char* get_error_code_message(ErrorCode error_code) {
     switch(error_code) {
     case WrongNumberOfDigits:
-        return "Wrong # of characters";
+        return "The barcode has too many or\ntoo few characters.";
     case InvalidCharacters:
-        return "Invalid characters";
+        return "The barcode data has invalid\ncharacters";
     case UnsupportedType:
-        return "Unsupported barcode type";
+        return "This barcode type is not\nsupported by this application";
     case FileOpening:
-        return "Could not open file";
+        return "The barcode file could not\nbe opened";
     case InvalidFileData:
-        return "Invalid file data";
+        return "File data contains incorrect\ninformation";
     case MissingEncodingTable:
-        return "Missing encoding table";
+        return "The encoding table files are\nmissing. Please redownload \nthis app, or consult the \ngithub readme";
     case EncodingTableError:
-        return "Encoding table error";
+        return "Either the characters you\nentered are incorrect or there\nis a problem with the\nencoding table";
     case OKCode:
         return "OK";
     default:

+ 16 - 6
barcode_validator.c

@@ -273,8 +273,16 @@ void code_128_loader(BarcodeData* barcode_data) {
             char barcode_char = furi_string_get_char(barcode_data->raw_data, i);
 
             //convert a char into a string so it used in flipper_format_read_string
-            char current_character[2];
-            snprintf(current_character, 2, "%c", barcode_char);
+            char current_character[3];
+            snprintf(current_character, 3, "%c", barcode_char);
+
+            /* 
+            Checks if the character is a hashtag, if it is change the character from # to H#
+            Github Issue: #10
+            */
+            if(strcmp("#", current_character) == 0) {
+                strcpy(current_character, "H#");
+            }
 
             //get the value of the character
             if(!flipper_format_read_string(ff, current_character, value)) {
@@ -283,6 +291,7 @@ void code_128_loader(BarcodeData* barcode_data) {
                 barcode_data->valid = false;
                 break;
             }
+
             //using the value of the character, get the characters bits
             if(!flipper_format_read_string(ff, furi_string_get_cstr(value), char_bits)) {
                 FURI_LOG_E(TAG, "Could not read \"%c\" string", barcode_char);
@@ -313,12 +322,13 @@ void code_128_loader(BarcodeData* barcode_data) {
 
         //calculate the check digit and convert it into a c string for lookup in the encoding table
         final_check_digit = checksum_adder % 103;
-        int length = snprintf(NULL, 0, "%d", final_check_digit);
-        char* final_check_digit_string = malloc(length + 1);
-        snprintf(final_check_digit_string, length + 1, "%d", final_check_digit);
+        // int length = snprintf(NULL, 0, "%d", final_check_digit);
+        char* final_check_digit_string = malloc(5);
+        snprintf(final_check_digit_string, 5, "%03d", final_check_digit);
 
         //after the checksum has been calculated, add the bits to the full barcode
-        if(!flipper_format_read_string(ff, final_check_digit_string, char_bits)) {
+        if(!flipper_format_read_string(ff, "ENCODINGS", char_bits) ||
+           !flipper_format_read_string(ff, final_check_digit_string, char_bits)) {
             FURI_LOG_E(TAG, "Could not read \"%s\" string", final_check_digit_string);
             barcode_data->reason = EncodingTableError;
             barcode_data->valid = false;

+ 6 - 29
views/barcode_view.c

@@ -21,11 +21,12 @@ static void draw_bit(Canvas* canvas, int bit, int x, int y, int width, int heigh
 }
 
 /**
- * 
+ * Draws the error name and message on the screen
 */
-static void draw_error_str(Canvas* canvas, const char* error) {
+static void draw_error_str(Canvas* canvas, const char* title, const char* error) {
     canvas_clear(canvas);
-    canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignCenter, error);
+    elements_multiline_text_aligned(canvas, 0, 0, AlignLeft, AlignTop, title);
+    elements_multiline_text_aligned(canvas, 0, 12, AlignLeft, AlignTop, error);
 }
 
 /**
@@ -417,32 +418,8 @@ static void barcode_draw_callback(Canvas* canvas, void* ctx) {
             break;
         }
     } else {
-        switch(data->reason) {
-        case WrongNumberOfDigits:
-            draw_error_str(canvas, "Wrong # of characters");
-            break;
-        case InvalidCharacters:
-            draw_error_str(canvas, "Invalid characters");
-            break;
-        case UnsupportedType:
-            draw_error_str(canvas, "Unsupported barcode type");
-            break;
-        case FileOpening:
-            draw_error_str(canvas, "Could not open file");
-            break;
-        case InvalidFileData:
-            draw_error_str(canvas, "Invalid file data");
-            break;
-        case MissingEncodingTable:
-            draw_error_str(canvas, "Missing encoding table");
-            break;
-        case EncodingTableError:
-            draw_error_str(canvas, "Encoding table error");
-            break;
-        default:
-            draw_error_str(canvas, "Could not read barcode data");
-            break;
-        }
+        draw_error_str(
+            canvas, get_error_code_name(data->reason), get_error_code_message(data->reason));
     }
 }