barcode_utils.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include <furi.h>
  3. #include <furi_hal.h>
  4. #define NUMBER_OF_BARCODE_TYPES 7
  5. typedef enum {
  6. WrongNumberOfDigits, //There is too many or too few digits in the barcode
  7. InvalidCharacters, //The barcode contains invalid characters
  8. UnsupportedType, //the barcode type is not supported
  9. FileOpening, //A problem occurred when opening the barcode data file
  10. InvalidFileData, //One of the key in the file doesn't exist or there is a typo
  11. MissingEncodingTable, //The encoding table txt for the barcode type is missing
  12. EncodingTableError, //Something is wrong with the encoding table, probably missing data or typo
  13. OKCode
  14. } ErrorCode;
  15. typedef enum {
  16. UPCA,
  17. EAN8,
  18. EAN13,
  19. CODE39,
  20. CODE128,
  21. CODABAR,
  22. UNKNOWN
  23. } BarcodeType;
  24. typedef struct {
  25. char* name; //The name of the barcode type
  26. BarcodeType type; //The barcode type enum
  27. int min_digits; //the minimum number of digits
  28. int max_digits; //the maximum number of digits
  29. int start_pos; //where to start drawing the barcode, set to -1 to dynamically draw barcode
  30. } BarcodeTypeObj;
  31. typedef struct {
  32. BarcodeTypeObj* type_obj;
  33. int check_digit; //A place to store the check digit
  34. FuriString* raw_data; //the data directly from the file
  35. FuriString* correct_data; //the corrected/processed data
  36. bool valid; //true if the raw data is correctly formatted, such as correct num of digits, valid characters, etc.
  37. ErrorCode reason; //the reason why this barcode is invalid
  38. } BarcodeData;
  39. //All available barcode types
  40. extern BarcodeTypeObj* barcode_type_objs[NUMBER_OF_BARCODE_TYPES];
  41. void init_types();
  42. void free_types();
  43. BarcodeTypeObj* get_type(FuriString* type_string);
  44. const char* get_error_code_name(ErrorCode error_code);
  45. const char* get_error_code_message(ErrorCode error_code);