barcode_utils.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include <furi.h>
  3. #include <furi_hal.h>
  4. #define NUMBER_OF_BARCODE_TYPES 6
  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. UNKNOWN
  22. } BarcodeType;
  23. typedef struct {
  24. char* name; //The name of the barcode type
  25. BarcodeType type; //The barcode type enum
  26. int min_digits; //the minimum number of digits
  27. int max_digits; //the maximum number of digits
  28. int start_pos; //where to start drawing the barcode, set to -1 to dynamically draw barcode
  29. } BarcodeTypeObj;
  30. typedef struct {
  31. BarcodeTypeObj* type_obj;
  32. int check_digit; //A place to store the check digit
  33. FuriString* raw_data; //the data directly from the file
  34. FuriString* correct_data; //the corrected/processed data
  35. bool valid; //true if the raw data is correctly formatted, such as correct num of digits, valid characters, etc.
  36. ErrorCode reason; //the reason why this barcode is invalid
  37. } BarcodeData;
  38. //All available barcode types
  39. extern BarcodeTypeObj* barcode_type_objs[NUMBER_OF_BARCODE_TYPES];
  40. void init_types();
  41. void free_types();
  42. BarcodeTypeObj* get_type(FuriString* type_string);
  43. const char* get_error_code_name(ErrorCode error_code);
  44. const char* get_error_code_message(ErrorCode error_code);